From dfa9d2bc563a3e8c7bde21eb0da888589456991f Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Tue, 23 Apr 2013 02:23:49 -0700 Subject: Continue work on Ajaxifying challenges --- ajax/challenges.ajax.php | 71 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 4 deletions(-) (limited to 'ajax') diff --git a/ajax/challenges.ajax.php b/ajax/challenges.ajax.php index b08698b..77a788d 100644 --- a/ajax/challenges.ajax.php +++ b/ajax/challenges.ajax.php @@ -3,10 +3,10 @@ ob_start("ob_gzhandler"); include('../includes/mapclass.php'); include('../includes/maps.php'); - +include_once('../includes/sqlEmbedded.php'); if ($_GET['getChallengeIDs'] == 'true') { - return getChallengesByTier($_GET['userID']); + echo getChallengesByTier($_GET['userID']); exit; } @@ -15,6 +15,11 @@ if ($_GET['getChallengeMap'] == 'true') { exit; } +if ($_GET['getChallenges'] == 'true') { + echo displayChallenges($_GET['challengeMapID']); + exit; +} + function getChallengeMapByID($challengeMapID) { //62 days $expires = 62*24*60*60; @@ -32,7 +37,6 @@ function getChallengeMapByID($challengeMapID) { } function getChallengeCode($challengeID) { - include_once('../includes/sqlEmbedded.php'); $sql = "SELECT `code` FROM `challengeMaps` WHERE `ID` = '$challengeID' @@ -79,10 +83,69 @@ function getChallengesByTier($userIdUnsanitized) { $layer[$data['challengeMapID']]['mapObject'] = $mapObj; //$layer[] = $data; } - echo json_encode($layer); + 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 '
'; + echo '
Challenges
'; + echo '
    '; + while($challenge = mysql_fetch_array($challengeResultset)) + { + $challengeMapID = $_GET["challengeMapID"]; + $challengeId = $challenge["challengeID"]; + if($challenge["dateSolved"] !== NULL) + $cssClass = "challenge_complete"; + else + $cssClass = "challenge_incomplete"; + $loadSolutionString = " Load this solution"; + echo "
  • " . getChallengeDisplayString($challenge) . " $loadSolutionString
  • "; + } + echo "
"; +} + + + +/** + * 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 + 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; +} + + + ?> \ No newline at end of file -- cgit v1.2.3