/
admin_game.php
304 lines (272 loc) · 12.8 KB
/
admin_game.php
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<?php
require("res/include.php");
if (!Auth::checkIfAuthenticated()||!Auth::checkIfAdmin()) {
header("Location: /"); /* Redirect browser */
}
$user = Auth::getCurrentUser();
$game = null;
$platform = null;
$con = \Propel\Runtime\Propel::getConnection();
if (!array_key_exists("game", $_GET) || !array_key_exists("platform", $_GET)) {
header("Location: /"); /* Redirect browser */
exit();
} else {
$con->beginTransaction();
$game = GameQuery::create()->filterByName($_GET["game"])->findOne($con);
$platform = PlatformQuery::create()->filterByName($_GET["platform"])->findOne($con);
if ($game == null || $platform == null) {
header("Location: /"); /* Redirect browser */
exit();
}
}
$header = RatingHeaderQuery::create()->filterByGame($game)->filterByPlatform($platform)->findOne($con);
$categories = CategoryQuery::create()->orderBySequence()->find($con);
$options = CategoryOptionQuery::create()->orderBySequence()->find($con);
if (array_key_exists("rating_submit", $_POST)) {
try {
if ($header == null) {
$header = new RatingHeader();
$header->setGame($game);
$header->setPlatform($platform);
$header->setCreated(new DateTime());
$header->save($con);
} else {
RatingValueQuery::create()->filterByRatingHeader($header)->delete($con);
}
$score = 0;
RatingValueQuery::create()->filterByRatingHeader($header)->delete($con);
foreach ($options as $option) {
if(array_key_exists('option_'.$option->getId(), $_POST)) {
$selected = $_POST['option_' . $option->getId()];
if($selected=="na") {
continue;
}
$value = new RatingValue();
$value->setRatingHeader($header);
$value->setCategoryOption($option);
$value->setOriginalValue($option->getValue());
if($selected=="adns") {
$value->setDoNotScore(true);
}
if(array_key_exists('comment_'.$option->getId(),$_POST)) {
$value->setComments($_POST['comment_'.$option->getId()]);
} else {
$value->setComments("");
}
$value->save($con);
if(array_key_exists('sub_option_'.$option->getId(),$_POST)) {
$sub_value = new RatingValue();
$sub_value->setRatingHeader($header);
$sub_option = CategoryOptionQuery::create()->filterById($_POST['sub_option_'.$option->getId()])->findOne($con);
if($sub_option==null) {
throw new Exception("Sub option ID not found: ".$_POST['sub_option_'.$option->getId()]);
}
$sub_value->setCategoryOption($sub_option);
$sub_value->setOriginalValue($sub_option->getValue());
$sub_value->save($con);
$score += ($sub_option->getValue());
}
if(!$value->getDoNotScore()) {
$score += ($option->getValue());
}
}
}
$header->setUpdated(new DateTime());
$header->setScore($score);
$header->save($con);
$con->commit();
header("Location: /game.php?name=" . $game->getName() . "&platform=" . $platform->getName()); /* Redirect browser */
} catch (Exception $e) {
$con->rollback();
echo $e->getMessage();
echo $e->getTraceAsString();
exit;
}
}
$current_option_array = [];
if ($header != null) {
foreach ($header->getRatingValues() as $value) {
$current_option_array[$value->getCategoryOptionId()] = $value;
}
}
?>
<!DOCTYPE html>
<!-- saved from url=(0026)http://alessandro.pw/pcmr/ -->
<html xmlns="http://www.w3.org/1999/html">
<head>
<?php include("res/head.php"); ?>
<meta charset="UTF-8"/>
<meta name="description" content="this site may come in handy to compute PCMRatings">
<meta name="author" content="/u/eur0pa">
<meta name="generator" content="skeleton css">
<!-- Mobile Specific Metas
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- FONT
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link href="./PCMR Rating System calculator_files/css" rel="stylesheet" type="text/css">
<link href="./localhost/css" rel="stylesheet" type="text/css">
<!-- CSS
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="stylesheet" href="http://localhost/css/normalize.css">
<link rel="stylesheet" href="http://localhost/css/skeleton.css">
<link rel="stylesheet" href="http://localhost/css/main.css">
<style type="text/css">
table.rating_input tr {
border-bottom: solid 1px black;
padding-top: 5px;
padding-bottom:5px;
}
table.rating_input td, table.rating_input th {
vertical-align: top;
padding:5px;
}
</style>
</head>
<body>
<?php include("res/nav.php"); ?>
<div class="container">
<h4>Game: <?php echo $game->getTitle(); ?></h4>
<h4>Platform: <?php echo $platform->getTitle(); ?></h4>
<h3>Instructions</h3>
<p>
Use the drop-down next to each option to select whether a particular option applies to the selected
game/platform.
<ul>
<li>N/A - Option is not applicable.</li>
<li>Applicable - Option is applicable.</li>
<li>Applicable (DNS) - Option is applicable, but should not contribute to the score.</li>
</ul>
<?php $rules = RatingRulesQuery::create()->orderBySequence()->find(); ?>
<h3>Rules (last updated <?= RatingRulesQuery::create()->orderByUpdated("DESC")->findOne()->getUpdated()->format('Y-m-d'); ?>)</h3>
<ol style="font-weight: bold; color:red;">
<?php foreach($rules as $rule): ?>
<li><?= $rule->getRule(); ?></li>
<?php endforeach; ?>
</ol>
</p>
<div class="row">
<form action="" method="POST">
<input type="hidden" name="rating_submit" value="1" />
<table class="u-full-width rating_input">
<thead>
<tr>
<th>Category</th>
<th>Option</th>
<th>Option Comments</th>
<th>Applicability</th>
<th>Sub-option</th>
<th>Rating Comments</th>
</tr>
</thead>
<tbody>
<?php foreach ($categories as $category): ?>
<tr>
<th class="score category" style="white-space: nowrap;"><?= $category->getTitle() ?></th>
<?php foreach ($options as $option): ?>
<?php if ($option->getCategoryId() == $category->getId() && $option->getParentId() == null): ?>
<?php
$current_value = null;
if (array_key_exists($option->getId(), $current_option_array)) {
$current_value = $current_option_array[$option->getId()];
}
?>
<th>
<?= $option->getDescription() ?>
</th>
<td>
<?php if($option->getComment()!=""): ?>
General: <?= $option->getComment() ?>
<?php endif; ?>
<?php if($option->getModComment()!=""): ?>
<b>Mod: <?= $option->getModComment() ?></b>
<?php endif; ?>
</td>
<td>
<select name="option_<?= $option->getId() ?>">
<?php if ($current_value == null): ?>
<option value="na" selected="selected">N/A</option>
<?php else: ?>
<option value="na">N/A</option>
<?php endif; ?>
<?php if ($current_value != null&& !$current_value->getDoNotScore()): ?>
<option value="a" selected="selected">Applicable</option>
<?php else: ?>
<option value="a">Applicable</option>
<?php endif; ?>
<?php if ($current_value != null&& $current_value->getDoNotScore()): ?>
<option value="adns" selected="selected">Applicable (DNS)</option>
<?php else: ?>
<option value="adns">Applicable (DNS)</option>
<?php endif; ?>
</select>
</td>
<td>
<?php $first_sub_option = true; ?>
<?php foreach ($options as $sub_option): ?>
<?php if ($sub_option->getParentId() == $option->getId()): ?>
<?php if ($first_sub_option): ?>
<select name="sub_option_<?= $option->getId() ?>">
<?php $first_sub_option = false; ?>
<?php endif; ?>
<option value="<?= $sub_option->getId() ?>"
<?php if(array_key_exists($sub_option->getId(),$current_option_array)): ?>
selected="selected"
<?php endif; ?>
><?= $sub_option->getDescription() ?></option>
<?php endif; ?>
<?php endforeach; ?>
<?php if (!$first_sub_option): ?>
</select>
<?php endif; ?>
</td>
<td>
<textarea name="comment_<?= $option->getId() ?>"><?php if($current_value!=null): ?><?= $current_value->getComments() ?><?php endif; ?></textarea>
</td>
</tr>
<tr>
<td></td>
<?php endif; ?>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<input type="submit" value="Submit"/>
</form>
</div>
<!-- Footer
________________________________________________ -->
<div class="row">
<div class="u-full-width" style="margin-top: 0%">
<footer>
<p>
<!-- Based on <a href="http://www.reddit.com/r/pcmasterrace">/r/PCMR</a> user ratings.
Credits go to <a href="http://www.reddit.com/user/BallisticGE0RGE">/u/BallisticGE0RGE</a> for the images.
Original thread <a href="http://redd.it/3b6eic">here</a> -->
</p>
</footer>
</div>
</div>
<!--
</div>
End Document
––––––––––––––––––––––––––––––––––––––––––––––––––
<table class="table">
<th>*</th><th>Individual reviews</th>
<tr><td style="width: 25px"><img src="img/badges/r_tiny.jpg" alt="R" height="20"></td><td>review by /u/pedro19</td></tr>
</table>
</div>
</div>-->
</div>
<?php include("res/footer.php"); ?>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="/js/bootstrap.js"></script>
<script src="./PCMR Rating System calculator_files/jquery.min.js"></script>
<script src="./PCMR Rating System calculator_files/main.js"></script>
<script src="js/main.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="Jquery-1.4.2-min.js"></script>
<script src="FloatingHeader.js"></script>
</body>
</html>