-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnewGame.php
More file actions
196 lines (171 loc) · 7.25 KB
/
newGame.php
File metadata and controls
196 lines (171 loc) · 7.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
/**
* User: Proyecto Nahual
* Date: 30/10/12
* Time: 13:46
*
* Cualquier inquietud, enviar un mail a sumate@nahual.com.ar
*
*/
error_reporting(E_ALL);
ini_set('display_errors', '1');
include_once("includes.php");
include_once("classes/GameType.php");
include_once("classes/GameTable.php");
include_once("classes/ActionType.php");
$gameTypes = GameType::getValues();
if (isset($_GET['id'])) {
$gameTable = new GameTable();
$game = $gameTable->getById($_GET['id']);
}
?>
<html>
<head>
<?php include_once("common_head.php") ?>
<script type="text/javascript">
$(function () {
jQuery.fn.reset = function () {
$(this).each(function () {
this.reset();
});
}
var $formNuevoJuego = $("#formNuevoJuego");
var $guardarJuegoButton= $("#guardarJuego");
$guardarJuegoButton.click(function (e) {
e.preventDefault();
$guardarJuegoButton.attr('disabled', 'disabled');
var name = $("#name").val();
var gameType = $("#gameType").val();
var rating = $("input[name='rating']:checked").val();
if (!rating) {
rating = 0;
}
var year = $("#year").val();
var company = $("#company").val();
var id = null;
$(".control-group", $formNuevoJuego).each(function() {
cleanup_errors(this);
});
if (!validate_form($formNuevoJuego)) {
$guardarJuegoButton.removeAttr('disabled');
return false;
}
<?php if (isset($game)) : ?>
id = <?php echo $game->getId(); ?>;
<?php endif ?>
var action = '<?php echo ActionType::ACTION_SAVE; ?>';
<?php if (isset($game)) : ?>
action = '<?php echo ActionType::ACTION_MODIFY; ?>',
<?php endif ?>
$.ajax({
type:"POST",
url:"GameAjaxController.php",
data:{
action:action,
name:name,
gameType:gameType,
rating:rating,
company: company,
id: id,
year:year
},
success:function (result) {
if (result) {
window.location.href = "index.php?<?php echo $_SESSION['v_url'] ?>";
}
else {
$guardarJuegoButton.removeAttr('disabled');
alert("Error");
}
},
error:function (objeto, error, otroobj) {
$guardarJuegoButton.removeAttr('disabled');
alert("Error inesperado. Si lo podés reproducir, no dudes en avisarnos a sumate@nahual.com.ar, y contanos como hacemos para reproducirlo. Gracias!");
}
});
})
$("#cancelGuardarJuego").click(function () {
window.location.href = "index.php?<?php echo $_SESSION['v_url'] ?>";
});
<?php if (isset($game)) : ?>
$("#name").val('<?php echo addslashes($game->getName()); ?>');
$("#gameType").val('<?php $game->getGameType(); ?>');
$("#year").val('<?php echo $game->getYear(); ?>');
$("#company").val('<?php echo addslashes($game->getCompany()); ?>');
$("input[name='rating']").rating('select', '<?php echo $game->getRating(); ?>')
<?php endif ?>
});
</script>
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<span class="brand">
elPibePlay <span id='version'></span>
</span>
<a href="http://www.youtube.com/watch?v=YF7jfH3McSA&feature=related" target="_blank"><img alt="elPibePlay" title="elPibePlay" src="resources/img/icon.png" width="32"/></a>
<ul class="nav">
<li><a href="index.php?<?php echo $_SESSION['v_url'] ?>">Juegos</a></li>
<li class="active"><a href="newGame.php">+ Nuevo Juego</a></li>
</ul>
</div>
</div>
</div>
<div id="newGameContainer" class="well">
<form id="formNuevoJuego" class="form-horizontal" accept-charset="utf-8">
<div class="control-group">
<label class="control-label" for="name">Nombre</label>
<div class="controls">
<input type="text" id="name" placeholder="Nombre jueguito" class="input-xlarge">
</div>
</div>
<div class="control-group">
<label class="control-label" for="gameType">Consola</label>
<div class="controls">
<select id="gameType">
<?php foreach ($gameTypes as $gameType) : ?>
<option value="<?php echo $gameType?>"><?php echo $gameType?></option>
<?php endforeach ?>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="gameType">Puntaje</label>
<div class="controls">
<input type="radio" class="star {split:2} required" name="rating" value="1"/>
<input type="radio" class="star {split:2}" name="rating" value="2"/>
<input type="radio" class="star {split:2}" name="rating" value="3"/>
<input type="radio" class="star {split:2}" name="rating" value="4"/>
<input type="radio" class="star {split:2}" name="rating" value="5"/>
<input type="radio" class="star {split:2}" name="rating" value="6"/>
<input type="radio" class="star {split:2}" name="rating" value="7" checked="true"/>
<input type="radio" class="star {split:2}" name="rating" value="8"/>
<input type="radio" class="star {split:2}" name="rating" value="9"/>
<input type="radio" class="star {half: true}" name="rating" value="10"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="gameType">Año</label>
<div class="controls">
<select id="year">
<?php for ($i = 1980; $i <= date('Y'); $i++) : ?>
<option value="<?php echo $i?>"><?php echo $i?></option>
<?php endfor ?>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="name">Empresa</label>
<div class="controls">
<input type="text" id="company" placeholder="Empresa que lo creó" class="input-xlarge">
</div>
</div>
<div class="form-actions" style="text-align:right">
<button type="submit" id="guardarJuego" class="btn btn-primary">Guardar juego</button>
<button type="button" id="cancelGuardarJuego" class="btn">Cancel</button>
</div>
</form>
</div>
</body>
</html>