summaryrefslogtreecommitdiffstats
path: root/includes/datas.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/datas.php')
-rw-r--r--includes/datas.php136
1 files changed, 135 insertions, 1 deletions
diff --git a/includes/datas.php b/includes/datas.php
index c445ca1..8c0309c 100644
--- a/includes/datas.php
+++ b/includes/datas.php
@@ -49,7 +49,8 @@ function topScores($mapid, $top = 5, $bottom = 0) {
if ($wallEmblem == '')
$wallEmblem = 'blank.png';
- $cdate = date("g:i A (T)", strtotime($cdate));
+ //$cdate = date("g:i A (T)", strtotime($cdate));
+ $cdate = relativeTime(strtotime($cdate));
$background = '#262631';
if ($i % 2 == 1)
@@ -588,6 +589,139 @@ function trackMOTDstats($mapType) {
+//Select Stats/Scores.
+function getScores($mapid, $pageNumber = 1, $pageDivide = 10) {
+ $top = $pageNumber * $pageDivide;
+ $bottom = $top - $pageDivide;
+
+ $pageRequest = 'all';
+
+ if ($pageRequest == 'all') {
+ $pageReqStart = 1;
+ $pageReqEnd = 1000;
+ } elseif (is_int($pageRequest)) {
+ $pageReqStart = $pageRequest;
+ $pageReqEnd = $pageRequest;
+ } else {
+ $tmp = explode($pageRequest, "-");
+ $pageReqStart = $tmp[0];
+ $pageReqEnd = $tmp[1];
+ }
+
+ $sql = "
+ SELECT
+ timediff(solutions.dateModified, TIMESTAMP(CURDATE())) as diff,
+ users.displayName as display,
+ solutions.moves as moves,
+ users.ID as ID,
+ IfNull(userData.displayColor, '#cccccc') as displayColor,
+ IfNull(userData.wallColor, '#666666') as wallColor,
+ IfNull(userData.wallEmblem, 'blank.png') as wallEmblem,
+ solutions.dateModified as cdate
+ FROM
+ `users`
+ JOIN `solutions`
+ ON users.ID = solutions.userID
+ LEFT JOIN `userData`
+ ON users.ID = userData.userID
+ WHERE solutions.mapID = '$mapid'
+ ORDER BY solutions.moves DESC, solutions.dateModified ASC
+ ";
+ $result = mysql_query($sql);
+ //$utime = date("g:i A (T)");
+
+ $output['updateTime'] = date("g:i A (T)");
+
+ $i = 0;
+ $foundUser = false;
+ while ($row = mysql_fetch_assoc($result)) {
+ $i++;
+
+ $moves = $row['moves'];
+ $userID = $row['ID'];
+ if ($i == 1) {
+ $bestMoves = $moves;
+ $output['bestMoves'] = $bestMoves;
+ $output['bestBy'] = $row['display'];
+ }
+
+ if ($_SESSION['userID'] == $userID) {
+ $userPosition = $i;
+ } else {
+ if ($i > $top)
+ continue;
+ if ($i <= $bottom)
+ continue;
+ }
+
+ if ($wallEmblem == '')
+ $wallEmblem = 'blank.png';
+
+ $cdate = $row['cdate'];
+ $cdate = date("g:i A (T)", strtotime($cdate));
+
+ $scoredDate = strtotime($row['cdate']);
+ $secondsSinceScored = strtotime("now") - $scoredDate ;
+
+ //Alternate background colors
+ $background = '#262631';
+ if ($i % 2 == 1)
+ $background = '#20202a';
+
+ if ($userPosition == $i) {
+ $background = '#343c57';
+ $foundUser = true;
+ }
+
+ $medal = 'none';
+ if ($moves == $bestMoves)
+ $medal = 'silver';
+ if ($i == 1)
+ $medal = 'gold';
+
+ $output['users'][$i] = $row;
+ $output['users'][$i]['scoredDate'] = $cdate;
+ $output['users'][$i]['secondsSinceScored'] = $secondsSinceScored;
+ $output['users'][$i]['background'] = $background;
+ $output['users'][$i]['medal'] = $medal;
+ $output['users'][$i]['isUser'] = $userPosition == $i;
+ $output['users'][$i]['debug'] = "Bestmoves: $bestMoves moves: $moves";
+ } // END WHILE
+
+ if ($foundUser) {
+ $userPage = ceil(($userPosition / $pageDivide));
+ $output['userPage'] = $userPage;
+ $output['userPosition'] = $userPosition;
+ }
+
+ $output['pageCount'] = ceil(($i / $pageDivide));
+
+ if ($prevPage > 0) {
+ $navi .= " <a href='javascript:scoresShowPage($mapid, 1);'>&lt;&lt;</a> ";
+ $navi .= " <a href='javascript:scoresShowPage($mapid, $prevPage);'>&lt;</a> ";
+ } else {
+ $navi .= " &lt;&lt; ";
+ $navi .= " &lt;";
+ }
+ for ($x = 1; $x <= $pageCount; $x++) {
+ if ($x < $pageNumber - 3 OR $x > $pageNumber + 3)
+ continue;
+ if ($x == $pageNumber)
+ $navi .= "<strong> $x </strong>";
+ elseif ($userPage == $x)
+ $navi .= " <a href='javascript:scoresShowPage($mapid, $x)'><i>$x</i></a> ";
+ else
+ $navi .= " <a href='javascript:scoresShowPage($mapid, $x)'>$x</a> ";
+ }
+ if ($nextPage <= $pageCount) {
+ $navi .= " <a href='javascript:scoresShowPage($mapid, $nextPage);'>&gt;</a> ";
+ $navi .= " <a href='javascript:scoresShowPage($mapid, $pageCount);'>&gt;&gt;</a> ";
+ }
+
+ return $output;
+}
+
+