diff options
Diffstat (limited to 'includes/datas.php')
-rw-r--r-- | includes/datas.php | 244 |
1 files changed, 215 insertions, 29 deletions
diff --git a/includes/datas.php b/includes/datas.php index fa04300..6cc8f07 100644 --- a/includes/datas.php +++ b/includes/datas.php @@ -313,25 +313,25 @@ function getCompletedChallenges($userID, $mapID, $solution, $moves, $paths) { return; } - $firephp->log($mapID, "mapID"); - $firephp->log($userID, "userID"); + //$firephp->log($mapID, "mapID"); + //$firephp->log($userID, "userID"); $challengeResultset = loadChallengesForMap($mapID, $userID); $challengesCompleted = array(); while($challenge = mysql_fetch_array($challengeResultset)) { - $firephp->log("Checking a challenge"); - $firephp->log("Checking challenge number" . $challenge['challengeID']); - $firephp->log($challenge["dateSolved"], "dateCompleted"); + //$firephp->log("Checking a challenge"); + //$firephp->log("Checking challenge number" . $challenge['challengeID']); + //$firephp->log($challenge["dateSolved"], "dateCompleted"); //Skip checking challenges which have already been completed if($challenge["dateSolved"] !== NULL) { - $firephp->log('Challenge was already completed'); + //$firephp->log('Challenge was already completed'); $challengesCompleted[] = $challenge["challengeID"]; } else if(hasChallengeBeenCompleted($challenge, $solution, $moves, $paths)) { - $firephp->log('Challenge was completed!'); + //$firephp->log('Challenge was completed!'); setChallengeCompleted($challenge, $solution, $userID, $moves); $challengesCompleted[] = $challenge["challengeID"]; } @@ -368,7 +368,7 @@ function onCompletedTutorial($userID) { * Checks if the given solution meets the requirements for the given challenge */ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { - $firephp = FirePHP::getInstance(true); + //$firephp = FirePHP::getInstance(true); //Check the maze-length if($challenge['goal'] != 0) { //Er, "greater than" should really be called "greater than or equal to" :\ @@ -376,7 +376,7 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { || ($challenge['inequality'] == "less than" && $moves >= $challenge['goal']) || ($challenge['inequality'] == "equal" && $moves != $challenge['goal'])) { - $firephp->log("Failed at distance"); + //$firephp->log("Failed at distance"); return false; } } @@ -388,7 +388,7 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { $temp = count_chars($solution, 1); //$temp needed due to extreme PHP-stupidity $numWalls = $temp[ord(",")]; if($numWalls > $challenge['restrictWallCount']) { - $firephp->log("Failed at wall-count"); + //$firephp->log("Failed at wall-count"); return false; } } @@ -402,8 +402,8 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { $stringToSearchFor = "." . swapXandYCoordinates($invalidWall) . "."; if(strpos($solution,$stringToSearchFor) !== false) { - $firephp->log("Failed at wall-placement: " . $invalidWall); - $firephp->log("Solution: " . $solution); + //$firephp->log("Failed at wall-placement: " . $invalidWall); + //$firephp->log("Solution: " . $solution); return false; } } @@ -419,7 +419,7 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { if(count($usedTeleports) !== $challenge['restrictTeleportCount'] && ($challenge['restrictTeleportCount'] != 0 || $usedTeleports[0] != "")) { - $firephp->log("Failed at teleport count"); + //$firephp->log("Failed at teleport count"); return false; } } @@ -434,7 +434,7 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { //Check each path to see if it walks over that teleport if(strpos($path['path'], $usedTeleport) !== false) { - $firephp->log("Failed at teleports used"); + //$firephp->log("Failed at teleports used"); return false; } } @@ -454,7 +454,7 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { if(!$usesCorrectStartPoint) { - $firephp->log("Failed at start-point"); + //$firephp->log("Failed at start-point"); return false; } } @@ -471,13 +471,13 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) { if(!$usesCorrectEndPoint) { - $firephp->log("Failed at endpoint"); + //$firephp->log("Failed at endpoint"); return false; } } //All of the restrictions were met, meaning the challenge was completed! - $firephp->log("Succeeded!"); + //$firephp->log("Succeeded!"); return true; } @@ -504,6 +504,21 @@ function setChallengeCompleted($challenge, $solution, $userID, $moves) { mysql_query($sql); } + +function isChallengeMap($mapID) { + include_once('./includes/db.inc.php'); + $sql = "SELECT ID + FROM `maps` + WHERE + ID = '$mapID' AND `isChallenge` = true; + "; + $result = mysql_query($sql) or die(mysql_error()); + if (mysql_num_rows($result) == 0) + return false; + else + return true; +} + function applyAchievements($userID, $aType) { $amount = getAchievementCurrency($userID, $aType); @@ -768,11 +783,163 @@ function trackMOTDstats($mapType) { +//Select Members +function getMembers($order, $pageNumber = 1, $pageDivide = 50) { + + $top = $pageNumber * $pageDivide; + $bottom = $top - $pageDivide; + + $limitTop = ($pageNumber - 1) * $pageDivide; + + $sql = "SELECT COUNT(*) as 'count' FROM `users`"; + $result = mysql_query($sql) or die(mysql_error()); + $row = mysql_fetch_assoc($result); + $total = $row['count']; + + $output['pageCount'] = $total / $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 + users.ID as ID, + users.displayName as display, + IfNull( + (SELECT SUM(moves) FROM solutions + WHERE solutions.userID = users.ID AND + solutions.dateModified < CURRENT_DATE) + , 0) AS totalMoves, + IfNull( + (SELECT SUM(moves) FROM solutions + WHERE solutions.userID = users.ID AND + solutions.dateModified BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY) AND CURRENT_DATE) + , 0) AS totalMovesThisWeek, + IfNull( + (SELECT COUNT(*) FROM solutions + WHERE solutions.userID = users.ID AND + solutions.dateModified < CURRENT_DATE) + , 0) AS totalMazes, + SUM(CASE WHEN statistics.type IN (32, 33, 34, 35) THEN statistics.value ELSE 0 END) as totalWins, + SUM(CASE WHEN statistics.type IN (1, 2, 3, 4) THEN statistics.value ELSE 0 END) as totalTies, + IfNull(userData.wallColor, '#666666') as wallColor, + IfNull(userData.displayColor, '#cccccc'), + userData.wallEmblem as wallEmblem, + users.datejoined as dateJoined, + users.dateLogin as dateLogin + FROM `users` + LEFT JOIN `userData` ON users.ID = userData.userID + LEFT JOIN `statistics` ON users.ID = statistics.userID + GROUP BY users.ID + $order + LIMIT $limitTop, $pageDivide + "; + + $result = mysql_query($sql); + //$utime = date("g:i A (T)"); + + $output['updateTime'] = date("g:i A (T)"); + + $i = $limitTop; + $foundUser = false; + while ($row = mysql_fetch_assoc($result)) { + $i++; + + $moves = $row['moves']; + + $userID = $row['ID']; + 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)); + + $row['dateJoined'] = Date("Y-m-d", strtotime($row['dateJoined'])); + $row['dateLogin'] = Date("Y-m-d", strtotime($row['dateLogin'])); + + $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; + } + + // if is blind map. + // $row['moves'] = '???'; + + $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 + + //Need to look this up. + //$output['pageCount'] = ceil(($i / $pageDivide)); + //$output['pageCount'] = 5; + if ($prevPage > 0) { + $navi .= " <a href='javascript:scoresShowPage($mapid, 1);'><<</a> "; + $navi .= " <a href='javascript:scoresShowPage($mapid, $prevPage);'><</a> "; + } else { + $navi .= " << "; + $navi .= " <"; + } + 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);'>></a> "; + $navi .= " <a href='javascript:scoresShowPage($mapid, $pageCount);'>>></a> "; + } + + return $output; +} + + + //Select Stats/Scores. -function getScores($mapid, $pageNumber = 1, $pageDivide = 10) { +function getScores($mapID, $pageNumber = 1, $pageDivide = 10) { $top = $pageNumber * $pageDivide; $bottom = $top - $pageDivide; + //TODO: !! set to false before uploading. + $isBlindMap = false; + $pageRequest = 'all'; if ($pageRequest == 'all') { @@ -787,6 +954,17 @@ function getScores($mapid, $pageNumber = 1, $pageDivide = 10) { $pageReqEnd = $tmp[1]; } + $userID = $_SESSION['userID']; + $myBestMoves = 0; + if ($isBlindMap) { + $sql = "SELECT `moves` FROM `solutions` WHERE `mapID` = '$mapID' AND `userID` = '$userID'"; + $result = mysql_query($sql) or die(mysql_error()); + $row = mysql_fetch_assoc($result); + $myBestMoves = $row['moves']; + // echo "XX $myBestMoves XX "; + // echo "XX $userID XX "; + } + $sql = " SELECT timediff(solutions.dateModified, TIMESTAMP(CURDATE())) as diff, @@ -803,9 +981,10 @@ function getScores($mapid, $pageNumber = 1, $pageDivide = 10) { ON users.ID = solutions.userID LEFT JOIN `userData` ON users.ID = userData.userID - WHERE solutions.mapID = '$mapid' + WHERE solutions.mapID = '$mapID' ORDER BY solutions.moves DESC, solutions.dateModified ASC, solutions.ID DESC "; + // ORDER BY solutions.moves ASC, solutions.dateModified DESC, solutions.ID ASC $result = mysql_query($sql); //$utime = date("g:i A (T)"); @@ -813,19 +992,22 @@ function getScores($mapid, $pageNumber = 1, $pageDivide = 10) { $i = 0; $foundUser = false; + while ($row = mysql_fetch_assoc($result)) { $i++; $moves = $row['moves']; - $userID = $row['ID']; + + $requestedUserID = $row['ID']; if ($i == 1) { $bestMoves = $moves; $output['bestMoves'] = $bestMoves; $output['bestBy'] = $row['display']; } - if ($_SESSION['userID'] == $userID) { + if ($_SESSION['userID'] == $requestedUserID) { $userPosition = $i; + //$myBestMoves = $moves; } else { if ($i > $top) continue; @@ -857,6 +1039,10 @@ function getScores($mapid, $pageNumber = 1, $pageDivide = 10) { $medal = 'silver'; if ($i == 1) $medal = 'gold'; + + // if is blind map. + if ($isBlindMap AND $myBestMoves < $moves) + $row['moves'] = '???'; $output['users'][$i] = $row; $output['users'][$i]['scoredDate'] = $cdate; @@ -864,7 +1050,7 @@ function getScores($mapid, $pageNumber = 1, $pageDivide = 10) { $output['users'][$i]['background'] = $background; $output['users'][$i]['medal'] = $medal; $output['users'][$i]['isUser'] = $userPosition == $i; - $output['users'][$i]['debug'] = "Bestmoves: $bestMoves moves: $moves"; + //$output['users'][$i]['debug'] = "Bestmoves: $bestMoves moves: $moves"; } // END WHILE if ($foundUser) { @@ -876,8 +1062,8 @@ function getScores($mapid, $pageNumber = 1, $pageDivide = 10) { $output['pageCount'] = ceil(($i / $pageDivide)); if ($prevPage > 0) { - $navi .= " <a href='javascript:scoresShowPage($mapid, 1);'><<</a> "; - $navi .= " <a href='javascript:scoresShowPage($mapid, $prevPage);'><</a> "; + $navi .= " <a href='javascript:scoresShowPage($mapID, 1);'><<</a> "; + $navi .= " <a href='javascript:scoresShowPage($mapID, $prevPage);'><</a> "; } else { $navi .= " << "; $navi .= " <"; @@ -888,13 +1074,13 @@ function getScores($mapid, $pageNumber = 1, $pageDivide = 10) { if ($x == $pageNumber) $navi .= "<strong> $x </strong>"; elseif ($userPage == $x) - $navi .= " <a href='javascript:scoresShowPage($mapid, $x)'><i>$x</i></a> "; + $navi .= " <a href='javascript:scoresShowPage($mapID, $x)'><i>$x</i></a> "; else - $navi .= " <a href='javascript:scoresShowPage($mapid, $x)'>$x</a> "; + $navi .= " <a href='javascript:scoresShowPage($mapID, $x)'>$x</a> "; } if ($nextPage <= $pageCount) { - $navi .= " <a href='javascript:scoresShowPage($mapid, $nextPage);'>></a> "; - $navi .= " <a href='javascript:scoresShowPage($mapid, $pageCount);'>>></a> "; + $navi .= " <a href='javascript:scoresShowPage($mapID, $nextPage);'>></a> "; + $navi .= " <a href='javascript:scoresShowPage($mapID, $pageCount);'>>></a> "; } return $output; @@ -949,7 +1135,7 @@ function loadChallengeListing($userIdUnsanitized) { $userID = mysql_escape_string($userIdUnsanitized); $sql = " - SELECT maps.ID AS mapID, maps.challengeTier, maps.challengeName, challengeSolutions.dateSolved + SELECT maps.ID AS mapID, maps.challengeTier, maps.name, challengeSolutions.dateSolved FROM maps INNER JOIN challenges ON maps.ID = challenges.mapID LEFT JOIN challengeSolutions ON challenges.ID = challengeSolutions.challengeID |