summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Davison <snapwilliam@gmail.com>2013-04-23 02:23:49 -0700
committerPatrick Davison <snapwilliam@gmail.com>2013-04-23 02:23:49 -0700
commitdfa9d2bc563a3e8c7bde21eb0da888589456991f (patch)
treedee3f2aa568c43a7c0d7fb9bd9e4a4cbfdcee7a9
parentd028f04c2213bb03af98ba5e9357ae18b9ae2a65 (diff)
downloadpathery-dfa9d2bc563a3e8c7bde21eb0da888589456991f.tar.xz
Continue work on Ajaxifying challenges
-rw-r--r--ajax/challenges.ajax.php71
1 files changed, 67 insertions, 4 deletions
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 '<div id="challenges">';
+ echo '<div id="challenges_title">Challenges</div>';
+ echo '<div id="challenges_listing"><ul class="challenge_ulist">';
+ while($challenge = mysql_fetch_array($challengeResultset))
+ {
+ $challengeMapID = $_GET["challengeMapID"];
+ $challengeId = $challenge["challengeID"];
+ if($challenge["dateSolved"] !== NULL)
+ $cssClass = "challenge_complete";
+ else
+ $cssClass = "challenge_incomplete";
+ $loadSolutionString = "<a href='javascript:requestChallengeSolution(\"$challengeMapID\", \"$challengeId\");'> Load this solution</a>";
+ echo "<li class='$cssClass' id='challenge_id_$challengeId'>" . getChallengeDisplayString($challenge) . " $loadSolutionString </li>";
+ }
+ echo "</ul></div></div>";
+}
+
+
+
+/**
+ * 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