ob_start("ob_gzhandler"); include('../includes/mapclass.php'); include('../includes/maps.php'); include_once('../includes/sqlEmbedded.php'); if ($_GET['getChallengeIDs'] == 'true') { echo getChallengesByTier($_GET['userID']); exit; } if ($_GET['getChallengeMap'] == 'true') { echo getChallengeMapByID($_GET['challengeMapID']); exit; } if ($_GET['getChallenges'] == 'true') { echo displayChallenges($_GET['challengeMapID']); exit; } function getChallengeMapByID($challengeMapID) { //62 days $expires = 62*24*60*60; // header("Cache-Control: public, maxage=".$expires); // header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT'); // header("Content-type: text/javascript"); //Remove the ending .js $tmp = explode(".", $challengeMapID); $challengeID = $tmp[0] * 1; if (!is_int($challengeID)) exit; $map = new map(getChallengeCode($challengeID), $challengeID); return json_encode($map); } function getChallengeCode($challengeID) { $sql = "SELECT `code` FROM `challengeMaps` WHERE `ID` = '$challengeID' "; $result = mysql_query($sql); if (mysql_num_rows($result) > 0) { list($map) = mysql_fetch_row($result); return $map; } } function getChallengesByTier($userIdUnsanitized) { include_once('../includes/sqlEmbedded.php'); $userID = mysql_escape_string($userIdUnsanitized); $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 <= (SELECT challengeTier FROM users WHERE ID = '$userID' LIMIT 1) OR 1 ORDER BY challengeMaps.challengeTier, challengeMaps.challengeSuborder, challenges.ordering"; $result = mysql_query($sql) OR die(mysql_error()."SQL: $sql"); if (mysql_num_rows($result) >= 1) { while($data = mysql_fetch_array($result)) { //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[$data['challengeMapID']][$challengeID] = $data; $layer[$data['challengeMapID']]['mapObject'] = $mapObj; //$layer[] = $data; } return json_encode($layer); } return NULL; } function displayChallenges($mapIdUnsanitized) { $result = loadChallengesForMap($mapIdUnsanitized, 3); while($challenge = mysql_fetch_array($result)) { $data[] = $challenge; } return $data; } function displayChallengesHTML($challengeResultset) { echo '