From f83929347be13726a9e7728868c8120fdc86a188 Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Fri, 25 Jan 2013 16:57:18 -0800 Subject: `challengeMaps` table added; start of the required code changes. --- do.php | 1 + includes/datas.php | 39 ++++++++++++++++++++------------------- pages/challenge.php | 17 +++++++++-------- pages/challengelist.php | 7 ++++--- pages/memberlist.php | 2 +- 5 files changed, 35 insertions(+), 31 deletions(-) diff --git a/do.php b/do.php index 3b3d8d6..b989da8 100644 --- a/do.php +++ b/do.php @@ -212,6 +212,7 @@ if ($_GET['r'] == 'getpath') { if ($_GET['isChallenge'] == 'true' AND isChallengeMap($mapID)) { // $firephp->log('Calling challenges'); + $json['info'][] = 'Executed as a challenge'; $json['completedChallenges'] = getCompletedChallenges($userID, $mapID, $solution, $moves, $json['path']); // $firephp->log('Challenges called!'); die(json_encode($json)); diff --git a/includes/datas.php b/includes/datas.php index 62f664e..8814625 100644 --- a/includes/datas.php +++ b/includes/datas.php @@ -305,12 +305,14 @@ function getCompletedChallenges($userID, $mapID, $solution, $moves, $paths) { //mapID 5 is the tutorial, and is treated specially //$firephp = FirePHP::getInstance(true); //$firephp->log("In challenges"); - if($mapID <= 10) { - if ($mapID == 5 && $moves == 75) { - onCompletedTutorial($userID); - } - return; - } + + //TODO: !! Get rid of this + // if($mapID <= 10) { + // if ($mapID == 5 && $moves == 75) { + // onCompletedTutorial($userID); + // } + // return; + // } //$firephp->log($mapID, "mapID"); //$firephp->log($userID, "userID"); @@ -521,9 +523,9 @@ function setChallengeCompleted($challenge, $solution, $userID, $moves) { function isChallengeMap($mapID) { include_once('./includes/sqlEmbedded.php'); $sql = "SELECT ID - FROM `maps` + FROM `challengeMaps` WHERE - ID = '$mapID' AND `isChallenge` = true; + ID = '$mapID'; "; $result = mysql_query($sql) or die(mysql_error()); return (mysql_num_rows($result) != 0); @@ -1075,17 +1077,16 @@ function loadChallengeListing($userIdUnsanitized) { $userID = mysql_escape_string($userIdUnsanitized); - $sql = " SELECT maps.ID AS mapID, maps.challengeTier, maps.name AS name, + $sql = " SELECT challengeMaps.ID AS challengeMapID, challengeMaps.challengeTier, challengeMaps.name AS name, challengeSolutions.dateSolved, challengeSolutions.challengeID AS challengeID, - maps.challengeSuborder, challenges.ordering + challengeMaps.challengeSuborder, challenges.ordering, challengeMaps.code as mapCode FROM challenges - LEFT JOIN maps ON challenges.mapID = maps.ID + LEFT JOIN challengeMaps ON challenges.mapID = challengeMaps.ID LEFT JOIN challengeSolutions ON challenges.ID = challengeSolutions.challengeID AND challengeSolutions.userID = '$userID' WHERE challenges.enabled = 1 - ORDER BY maps.challengeTier, maps.challengeSuborder, challenges.ordering"; + ORDER BY challengeMaps.challengeTier, challengeMaps.challengeSuborder, challenges.ordering"; - $result = mysql_query($sql); - echo mysql_error(); + $result = mysql_query($sql) OR die(mysql_error()."SQL: $sql"); if (mysql_num_rows($result) >= 1) return $result; return NULL; @@ -1094,13 +1095,13 @@ function loadChallengeListing($userIdUnsanitized) /** * Returns the map "code" for the given mapId */ -function loadMapCode($mapIdUnsanitized) +function loadChallengeMapCode($mapIdUnsanitized) { - $mapID = mysql_escape_string($mapIdUnsanitized); + $ID = mysql_escape_string($mapIdUnsanitized); $sql = " - SELECT maps.code as code - FROM maps - WHERE ID = '$mapID' AND isChallenge = 1 + SELECT challengeMaps.code as code + FROM challengeMaps + WHERE ID = '$ID' LIMIT 1 "; diff --git a/pages/challenge.php b/pages/challenge.php index ceefebe..4e5c50c 100644 --- a/pages/challenge.php +++ b/pages/challenge.php @@ -80,24 +80,25 @@ if (!$accepted) { // return; //} -if(!isset($_GET["mapID"])) +if(!isset($_GET["challengeMapID"]) OR !is_int($_GET["challengeMapID"] + 0)) { redirectToChallengeListing(); return; } -$mapCode = loadMapCode($_GET["mapID"]); +$mapCode = loadChallengeMapCode($_GET["challengeMapID"]); if($mapCode === NULL) { redirectToChallengeListing(); return; } -// TODO: !! Sanitize mapid -$mapID = $_GET["mapID"]; +$challengeMapID = $_GET["challengeMapID"] + 0; +if (!is_int($challengeMapID)) + return; -$mapContent = displayMap(GenerateMapByCode($mapCode), $_GET["mapID"]); -$challengeResultset = loadChallengesForMap($mapID, $userID); +$mapContent = displayMap(GenerateMapByCode($mapCode), $_GET["challengeMapID"]); +$challengeResultset = loadChallengesForMap($challengeMapID, $userID); if($challengeResultset === NULL) { redirectToChallengeListing(); @@ -134,13 +135,13 @@ function displayChallenges($challengeResultset) echo '
"; diff --git a/pages/challengelist.php b/pages/challengelist.php index db20081..364209f 100644 --- a/pages/challengelist.php +++ b/pages/challengelist.php @@ -70,13 +70,14 @@ function ChallengeList($challengeListResultset) { foreach ($challengeMap as $challengeSuborder => $challenge) { //Hack to get the first element of the array: $firstChallenge = $challenge[key($challenge)]; - $mapid = $firstChallenge['mapID']; + $challengeMapID = $firstChallenge['challengeMapID']; - $mapCode = getMapCode($mapid); + //$mapCode = getMapCode($mapid); + $mapCode = $firstChallenge['mapCode']; $map = new map($mapCode); $thumbnail = DisplayMapThumbnail($map); - $r .= "
"; + $r .= "
"; $r .= "$map->name"; $r .= $thumbnail; diff --git a/pages/memberlist.php b/pages/memberlist.php index 99f81ca..6e71dea 100644 --- a/pages/memberlist.php +++ b/pages/memberlist.php @@ -36,7 +36,7 @@ $json = json_encode($data); ?>
- +

Members