summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--css/challenge.css14
-rw-r--r--do.php1
-rw-r--r--includes/datas.php38
-rw-r--r--pages/challenge.php17
-rw-r--r--pages/challengelist.php24
-rw-r--r--pages/memberlist.php2
6 files changed, 61 insertions, 35 deletions
diff --git a/css/challenge.css b/css/challenge.css
index ff0589a..143da08 100644
--- a/css/challenge.css
+++ b/css/challenge.css
@@ -54,12 +54,14 @@
width: 32px;
height: 32px;
background-image: url("../images/challenge_complete.png");
- float: left;
}
.challengelist_incomplete {
width: 32px;
height: 32px;
background-image: url("../images/challenge_incomplete.png");
+}
+.challengelist_map .challengelist_complete,
+.challengelist_map .challengelist_incomplete {
float: left;
}
.challengelist_map {
@@ -77,8 +79,14 @@
border-width: 0px 0px 1px 1px;
}
.challengelist_nexttier {
-
+ text-align: center;
+ margin-bottom: 10px; /*Must be same as .challengelist_nexttier .challengelist_complete top */
}
.challengelist_nexttier_requirement {
-} \ No newline at end of file
+}
+.challengelist_nexttier .challengelist_complete {
+ display: inline-block;
+ position: relative;
+ top: 10px;
+}
diff --git a/do.php b/do.php
index 3b3d8d6..b989da8 100644
--- a/do.php
+++ b/do.php
@@ -212,6 +212,7 @@ if ($_GET['r'] == 'getpath') {
if ($_GET['isChallenge'] == 'true' AND isChallengeMap($mapID)) {
// $firephp->log('Calling challenges');
+ $json['info'][] = 'Executed as a challenge';
$json['completedChallenges'] = getCompletedChallenges($userID, $mapID, $solution, $moves, $json['path']);
// $firephp->log('Challenges called!');
die(json_encode($json));
diff --git a/includes/datas.php b/includes/datas.php
index 11a130c..e8e24a3 100644
--- a/includes/datas.php
+++ b/includes/datas.php
@@ -304,12 +304,15 @@ function applyCareerMazesAchievements($userID) {
*/
function getCompletedChallenges($userID, $mapID, $solution, $moves, $paths) {
//mapID 5 is the tutorial, and is treated specially
- if($mapID <= 10) {
+
+ //TODO: Fix / depreciate this. Re-adapt tutorial
+ // Temporary Hack to complete the tutorial...
+ // if($mapID <= 10) {
if ($mapID == 5 && $moves == 75) {
onCompletedTutorial($userID);
}
- return;
- }
+ // return;
+ // }
$challengeResultset = loadChallengesForMap($mapID, $userID);
$challengesCompleted = array();
@@ -510,9 +513,9 @@ function setChallengeCompleted($challenge, $solution, $userID, $moves) {
function isChallengeMap($mapID) {
$sql = "SELECT ID
- FROM `maps`
+ FROM `challengeMaps`
WHERE
- ID = '$mapID' AND `isChallenge` = true;
+ ID = '$mapID';
";
$result = mysql_query($sql) or die(mysql_error());
return (mysql_num_rows($result) != 0);
@@ -1045,6 +1048,8 @@ function getScores($mapID, $pageNumber = 1, $pageDivide = 10) {
* Returns true if the given user has completed the tutorial, false otherwise
*/
function hasCompletedTutorial($userID) {
+ $userID = mysql_escape_string($userID);
+
$sql = "SELECT `level` FROM `achievements`
WHERE `type` = 32 AND `userID` = '$userID'
LIMIT 1";
@@ -1089,18 +1094,17 @@ function loadChallengeListing($userIdUnsanitized)
{
$userID = mysql_escape_string($userIdUnsanitized);
- $sql = " SELECT maps.ID AS mapID, maps.challengeTier, maps.name AS name,
+ $sql = "SELECT challengeMaps.ID AS challengeMapID, challengeMaps.challengeTier, challengeMaps.name AS name,
challengeSolutions.dateSolved, challengeSolutions.challengeID AS challengeID,
- maps.challengeSuborder, challenges.ordering
+ challengeMaps.challengeSuborder, challenges.ordering, challengeMaps.code as mapCode
FROM challenges
- INNER JOIN maps ON challenges.mapID = maps.ID
+ 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 maps.challengeTier <= (SELECT challengeTier FROM users WHERE ID = '$userID')
- ORDER BY maps.challengeTier, maps.challengeSuborder, challenges.ordering";
+ AND challengeMaps.challengeTier <= (SELECT challengeTier FROM users WHERE ID = '$userID' LIMIT 1)
+ ORDER BY challengeMaps.challengeTier, challengeMaps.challengeSuborder, challenges.ordering";
- $result = mysql_query($sql);
- echo mysql_error();
+ $result = mysql_query($sql) OR die(mysql_error()."SQL: $sql");
if (mysql_num_rows($result) >= 1)
return $result;
return NULL;
@@ -1109,13 +1113,13 @@ function loadChallengeListing($userIdUnsanitized)
/**
* Returns the map "code" for the given mapId
*/
-function loadMapCode($mapIdUnsanitized)
+function loadChallengeMapCode($mapIdUnsanitized)
{
- $mapID = mysql_escape_string($mapIdUnsanitized);
+ $ID = mysql_escape_string($mapIdUnsanitized);
$sql = "
- SELECT maps.code as code
- FROM maps
- WHERE ID = '$mapID' AND isChallenge = 1
+ SELECT challengeMaps.code as code
+ FROM challengeMaps
+ WHERE ID = '$ID'
LIMIT 1
";
diff --git a/pages/challenge.php b/pages/challenge.php
index e5fcd45..84b401b 100644
--- a/pages/challenge.php
+++ b/pages/challenge.php
@@ -80,24 +80,25 @@ if (!hasCompletedTutorial($userID)) {
return;
}
-if(!isset($_GET["mapID"]))
+if(!isset($_GET["challengeMapID"]) OR !is_int($_GET["challengeMapID"] + 0))
{
redirectToChallengeListing();
return;
}
-$mapCode = loadMapCode($_GET["mapID"]);
+$mapCode = loadChallengeMapCode($_GET["challengeMapID"]);
if($mapCode === NULL)
{
redirectToChallengeListing();
return;
}
-// TODO: !! Sanitize mapid
-$mapID = $_GET["mapID"];
+$challengeMapID = $_GET["challengeMapID"] + 0;
+if (!is_int($challengeMapID))
+ return;
-$mapContent = displayMap(GenerateMapByCode($mapCode), $_GET["mapID"]);
-$challengeResultset = loadChallengesForMap($mapID, $userID);
+$mapContent = displayMap(GenerateMapByCode($mapCode), $_GET["challengeMapID"]);
+$challengeResultset = loadChallengesForMap($challengeMapID, $userID);
if($challengeResultset === NULL)
{
redirectToChallengeListing();
@@ -134,13 +135,13 @@ function displayChallenges($challengeResultset)
echo '<div id="challenges_listing"><ul class="challenge_ulist">';
while($challenge = mysql_fetch_array($challengeResultset))
{
- $mapID = $_GET["mapID"];
+ $challengeMapID = $_GET["challengeMapID"];
$challengeId = $challenge["challengeID"];
if($challenge["dateSolved"] !== NULL)
$cssClass = "challenge_complete";
else
$cssClass = "challenge_incomplete";
- $loadSolutionString = "<a href='javascript:requestChallengeSolution(\"$mapID\", \"$challengeId\");'> Load this solution</a>";
+ $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>";
diff --git a/pages/challengelist.php b/pages/challengelist.php
index d6e6d2f..ade47b6 100644
--- a/pages/challengelist.php
+++ b/pages/challengelist.php
@@ -26,8 +26,15 @@ if (!$accepted) {
htmlFooter();
return;
}
+
$userID = $_SESSION['userID'];
+if (!hasCompletedTutorial($userID)) {
+ echo "<center>Please <a href='tutorial'>complete the tutorial</a> to unlock Challenge mode!</div>";
+ htmlFooter();
+ return;
+}
+
//TODO: Uncomment
//if (!hasCompletedTutorial($userID)) {
// echo "<center>Please <a href='tutorial'>complete the tutorial</a> to unlock Challenge mode!</div>";
@@ -72,13 +79,14 @@ function getChallengeListHtml($challengeListResultset) {
foreach ($challengeMap as $challengeSuborder => $challenge) {
//Hack to get the first element of the array:
$firstChallenge = $challenge[key($challenge)];
- $mapid = $firstChallenge['mapID'];
+ $challengeMapID = $firstChallenge['challengeMapID'];
- $mapCode = getMapCode($mapid);
+ //$mapCode = getMapCode($mapid);
+ $mapCode = $firstChallenge['mapCode'];
$map = new map($mapCode);
$thumbnail = DisplayMapThumbnail($map);
- $r .= "<div class='challengelist_map' onclick='document.location.href=\"challenge?mapID=$mapid\"'>";
+ $r .= "<div class='challengelist_map' onclick='document.location.href=\"challenge?challengeMapID=$challengeMapID\"'>";
$r .= "$map->name";
$r .= $thumbnail;
@@ -107,7 +115,7 @@ function getChallengeListHtml($challengeListResultset) {
function getNextChallengeTierHtml($numCompletedChallenges)
{
- global $tierChallengeRequirements;
+ global $tierChallengeRequirements, $userID;
for($nextTier = 0; $nextTier < count($tierChallengeRequirements); $nextTier++)
{
@@ -130,20 +138,24 @@ function getNextChallengeTierHtml($numCompletedChallenges)
return "<div class='challengelist_nexttier>All tiers have been unlocked!</div>";
return "<div class='challengelist_nexttier'>Next tier unlocked in <span class='challengelist_nexttier_requirement'>$numChallengesForNextTier</span>"
- . "<span class='challengelist_complete'></span>!</div>";
+ . "<span class='challengelist_complete'></span></div>";
}
function numChallengesRemainingForTier($tier, $numCompletedChallenges)
{
+ global $tierChallengeRequirements;
+
if($tier >= maxTier())
return -1;
if($tierChallengeRequirements[$tier] <= $numCompletedChallenges)
return 0;
- return ($numCompletedChallenges - $tierChallengeRequirements[$tier]);
+ return ($tierChallengeRequirements[$tier] - $numCompletedChallenges);
}
function maxTier()
{
+ global $tierChallengeRequirements;
+
return (count($tierChallengeRequirements) - 1);
}
diff --git a/pages/memberlist.php b/pages/memberlist.php
index 99f81ca..6e71dea 100644
--- a/pages/memberlist.php
+++ b/pages/memberlist.php
@@ -36,7 +36,7 @@ $json = json_encode($data);
?>
<div class='wrapper'>
-
+ <h2>Members</h2>
<form class='memberListForm'>
<select id="membersPerPage" onChange="membersPageDivide=this.options[this.selectedIndex].value;membersShowPage(1,false,true);">
<option value="10">10</option>