diff options
-rw-r--r-- | ajax/challenges.ajax.php | 75 | ||||
-rw-r--r-- | 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 @@ <?php htmlHeader( - array('tutorial', 'challenge'), 'Pathery Challenges', + array('tutorial', 'challenge', 'stats'), 'Pathery Challenges', 'Challenges', array('scores', 'dateformat') ); @@ -11,13 +11,98 @@ include_once ('./includes/datas.php'); include_once ('./includes/mapclass.php'); include_once ('./includes/constants.php'); +echo soundManager2(); topbar($Links); ?> +<script> +// -display sections labeled.. +// -*click +// -display levels +// -*click +// -display map. +// -*finish map: +// -highlight 'Next' + + +function navShowChallengeTiers() { + +} + +function navShowLevels(tier) { + $('#t') + .hide() + .html("") + .slideDown('fast'); + + var urlString = 'http://www.mazetd.4xg.net/ajax/challenges.ajax.php?getChallengeIDs=true&userID=3'; + $.ajax({ + type: "GET", + url: urlString, + cache: true, + data: '', + fail: function() { alert("ajax error - if this persists check your connection."); }, + complete: function(data) {showLevelsResponse(data.responseText);} + }); +} + +function showLevelsResponse(response) { + var json = decryptJSON(response); + $.each(json, function(key, challengeObj) { + console.log("tests", key, challengeObj); + //$("#thumb_"+mapID).html(formatMapThumbForNav(data.responseText)).show(); + $("#t").append(formatChallengeThumbnail(challengeObj.mapObject)).show(); + mapdata[key] = challengeObj.mapObject; + }); + $("#t").append('<div style="float:left; margin:12px; width:200px; height:200px;" class="mapThumbnail">Grayed out Obscured Map Here.</div>').show(); + $("#t").append('<div style="float:left; margin:12px; width:200px; height:200px;" class="mapThumbnail">Grayed out Obscured Map Here.</div>').show(); + $("#t").append('<div style="float:left; margin:12px; width:200px; height:200px;" class="mapThumbnail">Grayed out Obscured Map Here.</div>').show(); +} + +function formatChallengeThumbnail(map) { + return '<div onclick="displayChallengeMap('+map.ID+')" style="float:left; margin:12px;" class="mapThumbnail">'+mapThumbnailHTML(map, 200, false)+'</div>'; +} + +function displayChallengeMap(challengeMapID) { + $("#t").html(mapAsHTML(mapdata[challengeMapID])); +} + +function hideNav() { + +} +function showNav() { + +} + + + +</script> + <div id="challengelist_wrapper" class="wrapper" style='overflow: auto;'> +<h3>Challenges - Pre-Beta, AKA Alpha.</h3> + +<div id='backBtn'><a href=''>Back Btn</a></div> +<div id='t' style='border:1px solid red; width:99%;overflow: hidden;'> + <div onclick='navShowLevels(1);' style='float:left; margin:10px; border:10px solid white;padding:20px'> + Easy + </div> + <div style='float:left; margin:10px; border:10px solid gray;padding:20px'> + Normal + </div> + <div style='float:left; margin:10px; border:10px solid gray;padding:20px'> + Hard + </div> +</div> + +<div style='clear:both'></div> + + +</div> <? +htmlFooter(); +exit; //Check that the user is allowed to do the challenges if (!$accepted) { @@ -44,7 +129,7 @@ if (!hasCompletedTutorial($userID)) { ?> <noscript>Sorry, this game requires scripts to run. Please enable javascript and <a href='home'>Reload this site</a> - <br />This game is best viewed in <a href='http://www.google.com/chrome'>Google Chrome</a> + <br />This game is best played in <a href='http://www.google.com/chrome'>Google Chrome</a> </noscript> <? @@ -65,7 +150,6 @@ htmlFooter(); function getChallengeListHtml($challengeListResultset) { //First gather data to a more useful form. - $r = ''; while($data = mysql_fetch_array($challengeListResultset)) { $tier = $data['challengeTier']; $challengeSuborder = $data['challengeSuborder']; @@ -73,6 +157,7 @@ function getChallengeListHtml($challengeListResultset) { $challenges[$tier][$challengeSuborder][$ordering] = $data; } + $r = ''; $numCompletedChallenges = 0; foreach ($challenges as $tier => $challengeMap) { $r .= "<b>Section $tier</b> levels:<div class='challengelist_tier' style='border: 1px solid yellow; overflow: auto;'>"; @@ -229,4 +314,6 @@ function displayChallengeList($challengeListResultset) echo "</div></div>"; echo "</div>"; } + + ?>
\ No newline at end of file |