diff options
author | Patrick Davison <snapwilliam@gmail.com> | 2013-04-18 01:57:33 -0700 |
---|---|---|
committer | Patrick Davison <snapwilliam@gmail.com> | 2013-04-18 01:57:33 -0700 |
commit | 472b605532b16e1b429ab6300b98be7a41e0ba7a (patch) | |
tree | 586da77279ca6bd8991789c609b3459df1a3504c /ajax/challenges.ajax.php | |
parent | e37234b2da5075409d12d345d7cd73b6ea803f5f (diff) | |
download | pathery-472b605532b16e1b429ab6300b98be7a41e0ba7a.tar.xz |
Challenges AJAX style - progress.
Diffstat (limited to 'ajax/challenges.ajax.php')
-rw-r--r-- | ajax/challenges.ajax.php | 75 |
1 files changed, 64 insertions, 11 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 |