From 472b605532b16e1b429ab6300b98be7a41e0ba7a Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Thu, 18 Apr 2013 01:57:33 -0700 Subject: Challenges AJAX style - progress. --- ajax/challenges.ajax.php | 75 ++++++++++++++++++++++++++++++++------ pages/challengelist.php | 93 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 154 insertions(+), 14 deletions(-) diff --git a/ajax/challenges.ajax.php b/ajax/challenges.ajax.php index 68d6ae3..b08698b 100644 --- a/ajax/challenges.ajax.php +++ b/ajax/challenges.ajax.php @@ -4,13 +4,32 @@ ob_start("ob_gzhandler"); include('../includes/mapclass.php'); include('../includes/maps.php'); -//Remove the ending .js -$tmp = explode(".", $_GET['challengeid']); -$challengeID = $tmp[0] * 1; -if (!is_int($challengeID)) exit; -$map = new map(getChallengeCode($challengeID), $challengeID); +if ($_GET['getChallengeIDs'] == 'true') { + return getChallengesByTier($_GET['userID']); + exit; +} + +if ($_GET['getChallengeMap'] == 'true') { + echo getChallengeMapByID($_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) { include_once('../includes/sqlEmbedded.php'); @@ -25,11 +44,45 @@ function getChallengeCode($challengeID) { } } -//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"); -echo json_encode($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; + } + echo json_encode($layer); + } + return NULL; +} + ?> \ No newline at end of file diff --git a/pages/challengelist.php b/pages/challengelist.php index 51c8f69..1e199d7 100644 --- a/pages/challengelist.php +++ b/pages/challengelist.php @@ -1,6 +1,6 @@ + +
+

Challenges - Pre-Beta, AKA Alpha.

+ + +
+
+ Easy +
+
+ Normal +
+
+ Hard +
+
+ +
+ + +
$challengeMap) { $r .= "Section $tier levels:
"; @@ -229,4 +314,6 @@ function displayChallengeList($challengeListResultset) echo "
"; echo ""; } + + ?> \ No newline at end of file -- cgit v1.2.3