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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
|
<?php
htmlHeader(array('stats'), 'Pathery Scores', 'Score history for Pathery');
?>
<?php
topbar($headerLinks);
include('./includes/maps.php');
//include('./includes/mapoftheday.php');
include('./includes/datas.php');
include_once ('./includes/sqlEmbedded.php');
function day_diff($date1, $date2) {
$current = $date1;
$datetime2 = date_create($date2);
$count = 0;
while(date_create($current) < $datetime2){
$current = gmdate("Y-m-d", strtotime("+1 day", strtotime($current)));
$count++;
}
return $count;
}
//The date to display
$dateDisplay = date('Y-m-d', strtotime("-1 days"));
//This is only used in a strtotime function, so this should be safe.
if (isset($_GET['date'])) {
$dateLookup = $_GET['date'];
if (!strtotime($dateLookup))
$dateLookup = $dateDisplay;
} else
$dateLookup = $dateDisplay;
$daysAgo = day_diff($dateLookup, date('Y-m-d'));
$dateAgo = strtotime("-$daysAgo days");
$dateAsStr = date('l F jS Y', $dateAgo);
$dateNextDay = date('Y-m-d', strtotime("+1 day", $dateAgo));
$datePrevDay = date('Y-m-d', strtotime("-1 day", $dateAgo));
//No cheater cheaters
if ($daysAgo < 1)
die("You must specify a date previous to today.");
$time_start = microtime(true);
$tStats = getStat(1, $daysAgo);
$yStats = getStat(2, $daysAgo);
$wStats = getStat(3, $daysAgo);
$mStats = getStat(4, $daysAgo);
$time_end = microtime(true);
$time = $time_end - $time_start;
if ($_GET['debug'] == true) echo "XX StatContent getStat Rechieve: $time seconds XX\n";
function getStat ($type, $daysAgo = 1) {
switch ($type) {
//Todays
case 1:
$where = "
DATE_ADD(CURDATE(), INTERVAL -0 DAY) =
DATE_FORMAT(solutions.dateModified,'%Y-%m-%d')
AND DATE_ADD(CURDATE(), INTERVAL -0 DAY) =
DATE_FORMAT(maps.dateCreated,'%Y-%m-%d')
";
$statname = "Today's Best Overall:";
break;
//Yesterdays
case 2:
$where = "
DATE_ADD(CURDATE(), INTERVAL -$daysAgo DAY) =
DATE_FORMAT(solutions.dateModified,'%Y-%m-%d')
AND DATE_ADD(CURDATE(), INTERVAL -$daysAgo DAY) =
DATE_FORMAT(maps.dateCreated,'%Y-%m-%d')
";
$statname = "Yesterday's Best Overall:";
if ($daysAgo > 1) {
$statname = "$daysAgo days ago's Best Overall.";
}
break;
case 3:
$where = "
YEARweek(solutions.dateModified) = YEARweek(CURRENT_DATE)
";
$statname = "This week, starting Sunday";
break;
case 4:
$where = "
( month(solutions.dateModified) = month(CURRENT_DATE) AND year(solutions.dateModified) = year(CURRENT_DATE) )
";
$statname = "This month's Best";
break;
}
$sql = "SELECT
users.displayName as Name,
SUM(solutions.moves) as Moves,
timediff(MAX(dateModified), maps.dateCreated) as Timetaken,
users.wallColor,
users.wallEmblem,
users.displayColor,
users.ID as userID,
SUM(CASE WHEN solutions.dateModified < CURDATE()
THEN solutions.championPointsWorth
ELSE 0 END) AS championPointsWorth
FROM `maps`
JOIN `solutions`
ON maps.ID = solutions.mapID
JOIN `users`
ON solutions.userID = users.ID
WHERE $where
GROUP BY solutions.userID
ORDER BY Moves DESC, MAX(dateModified) ASC
";
$result = mysql_query($sql);
return displayStats($result, $statname);
}
?>
<div class="wrapper">
<div style='text-align:center;padding-bottom:7px;'>
<strong>12-28-12. I plan on making considerable changes to this page in the near future.
<br />Thank you for your patience!</strong>
<br />
<br />Showing scores for the maps played on <? echo $dateAsStr; ?>
</div>
<div id="daynav">
<?
if ($daysAgo > 1) {
echo "<a href='leaderboard?date=$dateDisplay' title='Now'>Current Day</a>";
echo "<a href='leaderboard?date=$dateNextDay' title='Newer'>Next Day</a>";
}
echo "<a href='leaderboard?date=$datePrevDay' title='Older'>Previous Day</a>";
$time_start = microtime(true);
$statContent .= displayPastMaze(1, 'Simple', $daysAgo);
$statContent .= displayPastMaze(2, 'Normal', $daysAgo);
$statContent .= displayPastMaze(3, 'Complex', $daysAgo);
$statContent .= displayPastMaze(4, 'Special', $daysAgo);
$time_end = microtime(true);
$time = $time_end - $time_start;
if ($_GET['debug'] == true) echo "StatContent Rechieve: $time seconds\n";
$special = 'Special';
if ($specialMapName != '')
$special = $specialMapName;
?>
</div>
<div id="difficulties">
<a href="javascript:showStats(1)" id="dl-1">Simple</a>
<a href="javascript:showStats(2)" id="dl-2">Normal</a>
<a href="javascript:showStats(3)" id="dl-3">Complex</a>
<a href="javascript:showStats(4)" id="dl-4"><? echo $special; ?></a>
<a href="javascript:showStats(5)" id="dl-5">Overall</a>
<a href="javascript:showStats(6)" id="dl-6">Week/Month</a>
</div>
<?
echo $statContent;
function displayPastMaze($mapType, $name, $daysAgo = 1) {
//Ensure no cheating
if ($daysAgo < 1)
return;
$pastMap = pastMap($mapType, $daysAgo);
$mapID = $pastMap;
$mapcode = getMapCode($mapID);
$map = GenerateMapByCode($mapcode);
$sql = "SELECT
maps.ID as mapID,
solution,
users.displayName as Name,
SUM(solutions.moves) as Moves,
timediff(solutions.dateModified, maps.dateCreated) as Timetaken,
users.wallColor,
users.wallEmblem,
users.displayColor,
users.ID as userID,
solutions.championPointsWorth
FROM `maps`
JOIN `solutions`
ON maps.ID = solutions.mapID
JOIN `users`
ON solutions.userID = users.ID
JOIN `mapOfTheDay`
ON maps.ID = mapOfTheDay.mapID
WHERE
maps.ID = '$mapID'
GROUP BY solutions.userID
ORDER BY Moves DESC, `dateModified` ASC
";
$result = mysql_query($sql) or die(mysql_error());
$statname = "Yesterday's Best $name:";
if ($daysAgo > 1) {
$statname = "$daysAgo days ago's Best $name:";
}
$stats = displayStats($result, $statname);
//Sucky temporary solution:
$GLOBALS['specialMapName'] = $map[0][6];
$sql = "SELECT `moves`, `displayName`, `solution`
FROM `solutions`
LEFT JOIN `users`
ON solutions.userID = users.ID
WHERE `mapID` = '$mapID'
ORDER BY `moves` DESC, `dateModified` ASC
LIMIT 1";
$result = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result) > 0) {
list($bestMoves, $byName, $solution) = mysql_fetch_row($result);
}
$r = '';
$r .= '<div style="clear: both"></div>';
$r .= "<div id=\"yms-$mapType\">";
$r .= '<div class="col1">';
$r .= $stats;
$r .= '</div>';
$r .= '<div class="col2">';
$r .= "Best solution for this map: <b>$bestMoves by $byName </b>";
$r .= DisplayMap($map, $mapID, 'normal', 2);
$r .= '</div>';
$r .= '</div>';
return $r;
}
function displaystats($result, $caption = NULL) {
//Get names.
$headers = "<tr class='leaderboardHeaders'>";
$headers .= "<th class='leaderboardHeadersRank'>Rank</th>";
$headers .= "<th class='leaderboardHeadersName'>Name</th>";
$headers .= "<th class='leaderboardHeadersMoves'>Moves</th>";
$headers .= "<th class='leaderboardHeadersTime'>Time taken</th>";
$headers .= "</th>";
//Start table
//$r .= "<table style='border:1px solid #FFF'>";
//$r .= "<caption>$caption</caption>";
//Headers on the top. including Rank.
//$r .= "<tr>";
//$r .= $headers;
//$r .= "</tr>";
$i = 1;
$championPoints = null;
while ($row = mysql_fetch_assoc($result)) {
$rowcontent = '';
$mapid = $row['mapID'];
$solution = $row['solution'];
$wallColor = $row['wallColor'];
$wallEmblem = $row['wallEmblem'];
$displayColor = $row['displayColor'];
$displayName = $row['Name'];
$userID = $row['userID'];
//Default
if ($wallColor == '')
$wallColor = '#666666';
$x = "<tr class='lbrow' onmouseover='changeWallEmblem(\"$wallEmblem\"); changeWallColor(\"$wallColor\"); loadSol(\"$mapid:$solution\");'>\n";
$x .= "<td>$i</td>";
$x .= "<td class='leaderboardName'><span title='UserID: $userID'><a href='achievements?id=$userID' style='color:$displayColor'>$displayName</a></span></td>";
//$x .= "<td style='color:$displayColor';>" . $row['Name'] . '</td>';
$x .= '<td><a href="javascript:void(0)">' . $row['Moves'] . '</a></td>';
$x .= '<td>' . $row['Timetaken'] . '</td>';
$x .= "</tr>";
if ($userID == $_SESSION['userID']) {
$promotedContent .= $x;
$championPoints = $row['championPointsWorth'];
} else {
$content .= $x;
}
$i++;
}
$r = '';
if($championPoints != null && $championPoints > 0)
{
$r .= "<div class='myPoints'>Points earned: <span class='myPointsValue'>$championPoints</span> <img src='../images/championpoints.png' width='16px' height='16px'></img></div>";
}
$r .= "<table style='border:1px solid #FFF'>";
$r .= "<caption>$caption</caption>";
$r .= $headers;
$r .= $promotedContent;
$r .= $content;
$r .= "</table>";
return $r;
}
function mysql_field_array( $query ) {
$field = mysql_num_fields( $query );
for ( $i = 0; $i < $field; $i++ ) {
$names[] = mysql_field_name( $query, $i );
}
return $names;
}
?>
<div style="clear: both"></div>
<div id="yms-5">
<div class="col1">
<? echo $tStats;?>
</div>
<div class="col2">
<? echo $yStats;?>
</div>
</div>
<div id="yms-6">
<div class="col1">
<? echo $wStats;?>
</div>
<div class="col2">
<? echo $mStats;?>
</div>
</div>
<br class="clear">
</div>
<script>
function showStats(type) {
for (var i = 1; i <= 6; i++) {
var elem = document.getElementById("yms-" + i);
if (elem.className.indexOf('hidden-stats') < 0)
elem.className += 'hidden-stats';
elem = document.getElementById("dl-" + i);
elem.className = elem.className.replace('selected', '');
}
elem = document.getElementById("yms-" + type);
elem.className = elem.className.replace('hidden-stats', '');
elem = document.getElementById("dl-" + type);
if (elem.className.indexOf('selected') < 0)
elem.className += 'selected';
}
showStats(1);
</script>
<script src="sounds/script/soundmanager.js"></script>
<script type="text/javascript">soundManagerInit();</script>
<?php
htmlFooter();
?>
|