0) { list($map) = mysql_fetch_row($result); return $map; } } function getChallengesByTier($tierUnsanitized, $userIdUnsanitized) { include_once('../includes/sqlEmbedded.php'); $userID = mysql_escape_string($userIdUnsanitized); $tier = mysql_escape_string($tierUnsanitized); $sql = "SELECT challengeMaps.ID AS challengeMapID, challengeMaps.challengeTier, challengeMaps.name AS name, challengeSolutions.dateSolved, challengeSolutions.challengeID AS challengeID, challengeMaps.challengeSuborder, challenges.ordering, challengeMaps.code as mapCode FROM challenges INNER JOIN challengeMaps ON challenges.mapID = challengeMaps.ID LEFT JOIN challengeSolutions ON challenges.ID = challengeSolutions.challengeID AND challengeSolutions.userID = '$userID' WHERE challenges.enabled = 1 AND challengeMaps.challengeTier = '$tier' ORDER BY challengeMaps.challengeTier, challengeMaps.challengeSuborder, challenges.ordering"; //AND challengeMaps.challengeTier <= (SELECT challengeTier FROM users WHERE ID = '$userID' LIMIT 1) OR 1 $result = mysql_query($sql) OR die(mysql_error()."SQL: $sql"); if (mysql_num_rows($result) >= 1) { $i = 0; //$layer['x'] = ''; while($data = mysql_fetch_assoc($result)) { $i++; //echo $data['challengeMapID']; $tier = $data['challengeTier']; $challengeSuborder = $data['challengeSuborder']; $ordering = $data['ordering']; $challenges[$tier][$challengeSuborder][$ordering] = $data; //$data['mapObject'] = $challenge; $challengeMapID = $data['challengeMapID']; $challengeID = $data['challengeID']; $mapObj = new map($data['mapCode']); $mapObj->ID = $challengeMapID; $layer['CM'.$data['challengeMapID']][$challengeID] = $data; $layer['CM'.$data['challengeMapID']]['mapObject'] = $mapObj; $challenges = getChallenges($data['challengeMapID'], $userID); $layer['CM'.$data['challengeMapID']]['challenges'] = $challenges; //$layer[] = $data; } return json_encode($layer); } return NULL; } function getChallenges($mapIdUnsanitized, $userIdUnsanitized) { $result = loadChallengesForMap($mapIdUnsanitized, $userIdUnsanitized); while($challenge = mysql_fetch_assoc($result)) { $data[] = $challenge; } return $data; } /** * Returns a MySQL resultset for all challenges for the given mapID * @param $mapIdUnsanitized The mapID to load. Assumed to be unsanitized. * @param $userID The userID. Assumed to be unsanitized * @return Returns a MySQL resultset with the columns listed in the code, or NULL if nothing found */ function loadChallengesForMap($mapIdUnsanitized, $userIdUnsanitized) { $mapID = mysql_escape_string($mapIdUnsanitized); $userID = mysql_escape_string($userIdUnsanitized); $sql = " SELECT challenges.ID AS challengeID, challenges.inequality, challenges.goal, challenges.hint, challenges.restrictWallCount, challenges.restrictWallPlacement, challenges.restrictTeleportCount, challenges.restrictTeleportsUsed, challenges.restrictStartPoint, challenges.restrictEndPoint, challengeSolutions.dateSolved, challenges.dialogStart, challenges.dialogFail, challenges.dialogSuccess FROM challenges LEFT JOIN challengeSolutions ON challenges.ID = challengeSolutions.challengeID AND challengeSolutions.userID = '$userID' WHERE challenges.mapID = '$mapID' AND challenges.enabled = 1 ORDER BY challenges.ordering "; $result = mysql_query($sql); echo mysql_error(); if (mysql_num_rows($result) >= 1) return $result; return NULL; } ?>