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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
|
<?php
htmlHeader(
array('stats', 'challenge'), 'Scores',
'Score history for Pathery',
array('scores', 'dateformat')
);
include_once('./includes/maps.php');
//include('./includes/mapoftheday.php');
include_once('./includes/datas.php');
include_once('./includes/mapclass.php');
include_once('./includes/constants.php');
include_once ('./includes/sqlEmbedded.php');
$time_start = microtime(true);
$time_end = microtime(true);
//TESTCODE
$time = $time_end - $time_start;
if ($_GET['debug'] == true) echo "StatContent Rechieve: $time seconds\n";
//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.");
?>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.keystrokes.min.js"></script>
<script>
//Contra
$(document).bind('keystrokes', {
keys: ['arrow up', 'arrow up', 'arrow down', 'arrow down', 'arrow left', 'arrow right', 'arrow left', 'arrow right', 'b', 'a', 'enter']
}, function(){
alert('You unlocked awesomeness!');
});
var daysAgo = <? echo $daysAgo; ?>;
$.ajaxSetup ({
cache: false
});
var ajax_load = "<img src='images/loading.gif' alt='loading...' />";
// load() functions
var loadUrl = "ajax/load.php";
$("#load_basic").click(function(){
$("#result").html(ajax_load).load(loadUrl);
});
var loadUrl = "ajax/load.php";
$("#load_basic").click(function(){
$("#result").html(ajax_load).load(loadUrl);
});
function displayMap(mapID) {
var urlString = 'ajax/scores.ajax.php?getmap=true&mapID='+mapID;
$("#mapDisplay").fadeOut('fast');
//.html(ajax_load)
$("#mapDisplay").load(urlString, null, function() {$("#mapDisplay").fadeIn('slow');});
urlString = 'do.php?r=reqScorePage&reqPage=1&mapID='+mapID;
//$("#scoreDisplay").html(ajax_load).load(urlString);
if (!$('#'+mapID+',dspScore').length) {
var newDiv = $('<div/>', {
'id': mapID+',dspScore',
html: ''
});
$('#scoreDisplay').empty();
newDiv.prependTo('#scoreDisplay');
}
scoresShowPage(mapID, 1);
// $.ajax({
// type: "GET",
// url: "ajax/chat.ajax.php",
// data: dataString,
// success: function(data) {getChatDone(data);}
// });
// var newDiv = $('<div/>', {
// 'id': mapID+',dspScore',
// 'class': 'my-new-list',
// 'style': 'display: none',
// html: ''
// });
}
function getMaplist(request) {
// daysAgo++
switch (request) {
case "next":
if (daysAgo <= 1)
return;
daysAgo--;
break;
case "prev":
daysAgo++;
break;
case "yesterday":
if (daysAgo == 1)
return;
daysAgo = 1;
break;
}
var urlString = 'ajax/scores.ajax.php?getmaplist=true&daysago='+daysAgo;
$("#mapNavigation").fadeOut('fast');
//.html(ajax_load)
$("#mapNavigation").load(urlString, null, function() {$("#mapNavigation").fadeIn('slow');});
}
function handleJSONResponse(data) {
json = jQuery.parseJSON(data);
// $.each(json, function(key, user) {
// }
}
</script>
<body>
<?php
topbar($Links);
$todaysScoreMaps = getMapsPlayed($daysAgo);
?>
<div class="wrapper" style='width:1100px;'>
<div id='#displayDate' style='text-align:center;padding-bottom:7px;'>
<h2 title='Maps that were played during this day'><? echo $dateAsStr; ?></h2>
</div>
<div id="daynav">
<a href='javascript:getMaplist("prev");' title='Older'>< Previous Day</a>
<a href='javascript:getMaplist("next");' title='Newer'>Next Day ></a>
<a href='javascript:getMaplist("yesterday");' title='Now'>Yesterday >></a>
<div id='mapNavigation'>
<? echo getMapNavigation($todaysScoreMaps); ?>
</div>
<?
function getMapsPlayed($daysAgo) {
$sql = "
SELECT `mapID`, `code`, `mapType`
FROM `mapOfTheDay`
INNER JOIN `maps` ON `mapID` = maps.ID
WHERE DATE_ADD(CURDATE(), INTERVAL -$daysAgo DAY) =
mapDate AND
`mapType` IN (1, 2, 3, 4)
";
$result = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result) == 0)
return -1;
global $mapNamesByType;
$r = array();
while($data = mysql_fetch_array($result)) {
$code = $data['code'];
$mapID = $data['mapID'];
$mapType = $data['mapType'];
$map = new map($code);
if ($map->name == '')
$map->name = $mapNamesByType[$mapType];
$r[$mapID] = $map;
}
return $r;
}
function getMapNavigation(&$maps) {
foreach ($maps as $mapID => &$map) {
$r .= "<div class='mapThumbnail' onclick='displayMap($mapID)'>";
$r .= $map->name;
$r .= DisplayMapThumbnail($map);
$r .= "</div>";;
}
return $r;
}
$time_start = microtime(true);
$special = 'Special';
if ($specialMapName != '')
$special = $specialMapName;
?>
</div>
<div style="clear: both"></div>
<div id=\"yms-$mapType\">
<div id='scoreDisplay' class="col1">
</div>
<div id='mapDisplay' style='display:none' class="col2">
</div>
</div>
<?
//echo $statContent;
?>
<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) {
//super usefulll
//var anchor = window.location.hash.substring(1);
for (var i = 1; i <= 4; 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();
//TODO !! DELETE FUNCTIONS WHEN DONE!!
function mysql_field_array( $query ) {
$field = mysql_num_fields( $query );
for ( $i = 0; $i < $field; $i++ ) {
$names[] = mysql_field_name( $query, $i );
}
return $names;
}
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 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;
}
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);
}
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;
}
?>
|