";
$r .= "";
}
$aAry = getAchievementsArray($aType);
$nextLevelRequired = $aAry[($aLevel + 1)][0];
$currentLevelRequired = $aAry[($aLevel)][0];
if ($currency) {
$currentLevelRequired = number_format($currentLevelRequired);
$r .= "You have $currentLevelRequired $currency
";
}
if ($nextLevelRequired >= 1) {
$nextLevelRequired = number_format($nextLevelRequired);
$r .= "Next level at $nextLevelRequired
";
}
// Item ID List
$aIDList[] = "'$aID'";
}
$r .= "
Go select unlocks now";
// ---------- Mark that we have notified the user
$aIDListStr = implode(',', $aIDList);
$sql = "UPDATE `achievements`
SET `notified` = 1
WHERE `ID` IN ($aIDListStr)";
mysql_query($sql);
return $r;
// ---------- Done!
}
//Returns true when an achievement is applied.
// Usage example: applyCareerAchievement($userID);
// TODO: DEPRECIATED
function applyCareerPathAchievements($userID) {
$sql = "SELECT
SUM(solutions.moves) as totalMoves
FROM `solutions`
WHERE userID = '$userID'";
$result = mysql_query($sql);
// --------- User hasn't played yet.
if (mysql_num_rows($result) != 1)
return false;
list($uTotalMoves) = mysql_fetch_row($result);
// ------- Select the highest level they've achieved.
$sql = "SELECT `level`
FROM `achievements`
WHERE `userID` = '$userID'
AND `type` = 1
ORDER BY `level` DESC
LIMIT 1";
$result = mysql_query($sql);
// --------- No achievements yet?
if (mysql_num_rows($result) == 1)
list($aLevel) = mysql_fetch_row($result);
else
$aLevel = 0;
$cp = getCareerPathArray();
//Is there a next level for this?
$aNextLevel = $aLevel + 1;
if (!isset($cp[$aNextLevel]))
return false;
list($required, $unlockType, $unlockValue, $unlockName) = $cp[$aNextLevel];
if ($uTotalMoves < $required)
return false;
$sql = "INSERT INTO `achievements`
(`userID`, `type`, `level`)
VALUES ('$userID', 1, '$aNextLevel')";
mysql_query($sql);
$aID = mysql_insert_id();
// ------- User gets unlock. (unlocks plural is possible here)
$sql = "INSERT INTO `unlocks`
(`userID`, `achievementID`, `type`, `subtype`, `name`, `value`)
VALUES ('$userID', '$aID', '$unlockType', NULL, '$unlockName', '$unlockValue')";
mysql_query($sql);
return true;
}
//Almost a duplicate of applyCareerPathAchievements
// TODO: DEPRECIATED
function applyCareerMazesAchievements($userID) {
$sql = "SELECT
COUNT(*) as totalSolutions
FROM `solutions`
WHERE userID = '$userID'";
$result = mysql_query($sql);
// --------- User hasn't played yet.
if (mysql_num_rows($result) != 1)
return false;
list($uTotalSolutions) = mysql_fetch_row($result);
// ------- Select the highest level they've achieved.
$sql = "SELECT `level`
FROM `achievements`
WHERE `userID` = '$userID'
AND `type` = 2
ORDER BY `level` DESC
LIMIT 1";
$result = mysql_query($sql);
// --------- No achievements yet?
if (mysql_num_rows($result) == 1)
list($aLevel) = mysql_fetch_row($result);
else
$aLevel = 0;
$cm = getCareerMazesArray();
//Is there a next level for this?
$aNextLevel = $aLevel + 1;
if (!isset($cm[$aNextLevel]))
return false;
list($required, $unlockType, $unlockValue, $unlockName) = $cm[$aNextLevel];
if ($uTotalSolutions < $required)
return false;
$sql = "INSERT INTO `achievements`
(`userID`, `type`, `level`)
VALUES ('$userID', 2, '$aNextLevel')";
mysql_query($sql);
$aID = mysql_insert_id();
// ------- User gets unlock. (unlocks plural is possible here)
$sql = "INSERT INTO `unlocks`
(`userID`, `achievementID`, `type`, `subtype`, `name`, `value`)
VALUES ('$userID', '$aID', '$unlockType', NULL, '$unlockName', '$unlockValue')";
mysql_query($sql);
return true;
}
/**
* Called when a user completes a challenge
* @param type $userID User who did the challenge
* @param type $mapID Map to check for challenges
* @param type $solution The final placement of towers, as a string of .-separated x,y pairs.
* Begins and ends with "." as well
* @param type $moves The total number of moves in the solution, for all paths
* @param type $paths An array of path-objects, each as returned by routePath().
*/
function checkForCompletedChallenges($userID, $mapID, $solution, $moves, $paths) {
//mapID 5 is the tutorial, and is treated specially
if($mapID == 5) {
if ($moves == 75) {
onCompletedTutorial($userID);
}
return;
}
$challengeResultset = loadChallengesForMap($mapID, $userID);
while($challenge = mysql_fetch_array($challengeResultset))
{
//Skip checking challenges which have already been completed
if($challenge["dateCompleted"] !== NULL)
continue;
else if(hasChallengeBeenCompleted($challenge, $solution, $moves, $paths))
setChallengeCompleted($challenge, $solution, $userID, $moves);
}
}
/**
* Called when a user completes the tutorial
*/
function onCompletedTutorial($userID) {
//have they previously completed the tutorial?
if(hasCompletedTutorial($userID))
return false;
// -------- This is the first time they've completed the tutorial!
$sql = "INSERT INTO `achievements`
(`userID`, `type`, `level`)
VALUES ('$userID', 32, '1')";
mysql_query($sql);
$aID = mysql_insert_id();
// ------- User gets unlock. (unlocks plural is possible here)
$sql = "INSERT INTO `unlocks`
(`userID`, `achievementID`, `type`, `subtype`, `name`, `value`)
VALUES ('$userID', '$aID', '1', 0, 'Blue', '#4444ff')";
mysql_query($sql);
return true;
}
/**
* Checks if the given solution meets the requirements for the given challenge
*/
function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) {
//Check the maze-length
if($challenge['goal'] != 0) {
//Er, "greater than" should really be called "greater than or equal to" :\
if(($challenge['inequality'] == "greater than" && $moves < $challenge['goal'])
|| ($challenge['inequality'] == "less than" && $moves >= $challenge['goal'])
|| ($challenge['inequality'] == "equal" && $moves != $challenge['goal']))
{
return false;
}
}
//Check wall-count restriction
if($challenge['restrictWallCount'] !== NULL)
{
//The number of walls is equal to the number of "," characters in the $solution string
$temp = count_chars($solution, 1); //$temp needed due to extreme PHP-stupidity
$numWalls = $temp[ord(",")];
if($numWalls > $challenge['restrictWallCount']) {
return false;
}
}
//Check wall-placement restriction
if($challenge['restrictWallPlacement'] !== NULL)
{
$invalidWalls = explode(".", $challenge['restrictWallPlacement']);
foreach($invalidWalls as $invalidWall)
{
if(strpos($solution,$invalidWall) !== false)
{
return false;
}
}
}
//TODO: This portion probably needs to be rewritten due to the weird way paths are saved
if($challenge['restrictTeleportCount'] !== NULL || $challenge['restrictTeleportsUsed'] !== NULL)
{
//Check teleport count
$usedTeleports = explode(".", getUsedTeleports($paths));
if($challenge['restrictTeleportCount'] !== NULL)
{
if(count($usedTeleports) !== $challenge['restrictTeleportCount'] &&
($challenge['restrictTeleportCount'] != 0 || $usedTeleports[0] != ""))
{
return false;
}
}
//Check teleports used
if($challenge['restrictTeleportsUsed'] !== NULL)
{
foreach($usedTeleports as $usedTeleport)
{
foreach($paths as $path)
{
//Check each path to see if it walks over that teleport
if(strpos($path['path'], $usedTeleport) !== false)
{
return false;
}
}
}
}
}
//Check start points
if($challenge['restrictStartPoint'] !== NULL)
{
$usesCorrectStartPoint = false;
foreach($paths as $path)
{
if($path['start'] == $challenge['restrictStartPoint'])
$usesCorrectStartPoint = true;
}
if(!$usesCorrectStartPoint)
return false;
}
//Check end points
if($challenge['restrictEndPoint'] !== NULL)
{
$usesCorrectEndPoint = false;
foreach($paths as $path)
{
if($path['end'] == $challenge['restrictEndPoint'])
$usesCorrectEndPoint = true;
}
if(!$usesCorrectEndPoint)
return false;
}
//All of the restrictions were met, meaning the challenge was completed!
return true;
}
/**
* Sets the given challenge as completed by the user in the database
*/
function setChallengeCompleted($challenge, $solution, $userID, $moves) {
$solution = mysql_escape_string($solution);
$userID = mysql_escape_string($userID);
$challengeID = $challenge["challengeID"];
$sql = "INSERT INTO `challengeSolutions`
(`userID`, `challengeID`, `solution`, `moves`, `dateSolved`)
VALUES ('$userID', '$challengeID', '$solution', $moves, NOW())";
mysql_query($sql);
}
function applyAchievements($userID, $aType) {
$amount = getAchievementCurrency($userID, $aType);
$aLevel = getAchievementLevel($userID, $aType);
$aArray = getAchievementsArray($aType);
//Is there a next level for this?
$aNextLevel = $aLevel + 1;
if (!isset($aArray[$aNextLevel]))
return false;
list($required, $unlockType, $unlockValue, $unlockName, $unlockSubtype) = $aArray[$aNextLevel];
if ($amount < $required)
return false;
$sql = "INSERT INTO `achievements`
(`userID`, `type`, `level`)
VALUES ('$userID', $aType, '$aNextLevel')";
mysql_query($sql);
$aID = mysql_insert_id();
// ------- User gets unlock. (TODO: unlocks plural is possible here)
$sql = "INSERT INTO `unlocks`
(`userID`, `achievementID`, `type`, `subtype`, `name`, `value`)
VALUES ('$userID', '$aID', '$unlockType', '$unlockSubtype', '$unlockName', '$unlockValue')";
mysql_query($sql);
return true;
}
function getAchievementCurrency($userID, $aType) {
// 1, Total Moves "Path Career" //Backdated
// 2, Total Solutions (Total maps played) "Mazes Career" //Backdated
// 3, Tie Top-Score on a map "Maze Mastery" //Tracked (no backdate)
// 4, Rank#1 Win Top-Score on a map "Wins" //Tracked
$r = 0;
$sql = '';
switch ($aType) {
case 1:
$sql = "SELECT
SUM(solutions.moves) as t
FROM `solutions`
WHERE userID = '$userID'";
break;
case 2:
$sql = "SELECT
COUNT(*) as t
FROM `solutions`
WHERE userID = '$userID'";
break;
case 3:
$sql = "SELECT
SUM(`value`) as t
FROM `statistics`
WHERE `userID` = '$userID'
AND `type` IN (1, 2, 3, 4)";
break;
case 4:
$sql = "SELECT
SUM(`value`) as t
FROM `statistics`
WHERE `userID` = '$userID'
AND `type` IN (32, 33, 34, 35)";
break;
}
if ($sql == '')
return false;
$result = mysql_query($sql);
if (mysql_num_rows($result) == 1)
list($r) = mysql_fetch_row($result);
return $r;
}
function getAchievementLevel($userID, $aType) {
// ------- Select the highest level they've achieved.
$r = 0;
$sql = "SELECT `level`
FROM `achievements`
WHERE `userID` = '$userID'
AND `type` = '$aType'
ORDER BY `level` DESC
LIMIT 1";
$result = mysql_query($sql);
if (mysql_num_rows($result) == 1)
list($r) = mysql_fetch_row($result);
return $r;
}
function getAchievementsArray($type) {
if ($type == 1)
return getCareerPathArray();
if ($type == 2)
return getCareerMazesArray();
if ($type == 3)
return getMazeMasteryArray();
if ($type == 4)
return getWinsArray();
//Tutorial
if ($type == 32) {
$r[1] = array(1, 1, '#4444ff', 'Blue');
return $r;
}
return array();
}
//TYPE 1
function getCareerPathArray() {
//$cp[0] = array(requiredmoves, type, 'value', 'name');
// Note that the description is followed by " wall color"
$cp[1] = array(100, 1, '#229922', 'Green');
$cp[2] = array(1000, 1, '#9922ff', 'Purple');
$cp[3] = array(5000, 2, 'CircleSmall_W.png', 'Light Small Circle', 0);
$cp[4] = array(10000, 2, 'DiamondSmall_B.png', 'Dark Small Diamond', 0);
$cp[5] = array(20000, 3, '#a9b1f6', 'Steel Blue');
$cp[6] = array(32000, 2, 'DiagonalCover_W.png', 'Light Diagonal Cover', 0);
$cp[7] = array(50000, 2, 'DiamondLargeDonut_B_I.png', 'Inverted Dark Annulated Diamond', 0);
$cp[8] = array(75000, 3, '#ffffaa', 'Yellow');
$cp[9] = array(100000, 3, '#ffbb77', 'Orange');
$cp[10] = array(130000, 2, 'OffsetStripesVertical_W.png', 'Light Vertical Stripes', 0);
$cp[11] = array(165000, 2, 'CircleSmall_B.png', 'Dark Small Circle', 0);
$cp[12] = array(200000, 3, '#ee77ff', 'Purple');
$cp[13] = array(250000, 1, '#ffff22', 'Yellow', 1);
$cp[14] = array(300000, 2, 'DiagonalCover_B_I.png', 'Inverted Dark Diagonal Cover', 0);
$cp[15] = array(350000, 1, '#333377', 'Navy Blue', 0);
$cp[16] = array(400000, 2, 'RacingStripes_W.png', 'Light Racing Stripes', 0);
return $cp;
}
//TYPE 2
function getCareerMazesArray() {
//$cp[0] = array(requiredmazes, type, 'value', 'name');
$cm[1] = array(5, 1, '#eeeeee', 'Silver', 1);
$cm[2] = array(15, 1, '#ff9922', 'Orange', 1);
$cm[3] = array(30, 2, 'DiamondLargeDonut_W.png', 'Light Annulated Diamond', 0);
$cm[4] = array(50, 1, '#aaaa22', 'Chartreuse');
$cm[5] = array(85, 2, 'CrossXL_W.png', 'Light Large Present', 0);
$cm[6] = array(150, 1, '#cc22aa', 'Magenta', 0);
$cm[7] = array(250, 1, '#ff3344', 'Red');
$cm[8] = array(375, 1, '#ffdd88', 'Gold', 1);
$cm[9] = array(550, 2, 'ConvexCover_W.png', 'Light Dome Cover', 0);
$cm[10] = array(750, 2, 'OffsetStripesVertical_B.png', 'Dark Vertical Stripes', 0);
$cm[11] = array(1000, 3, '#ff95b0', 'Pink');
$cm[12] = array(1400, 1, '#ff95b0', 'Pink', 1);
$cm[13] = array(2000, 2, 'StarsR_W.png', 'Bright Stars', 0);
$cm[14] = array(2750, 2, 'Stars1_B.png', 'Dark Single Star', 0);
$cm[15] = array(3500, 2, 'CircleSmall_B_I.png', 'Inverted Dark Small Circle', 0);
return $cm;
}
//TYPE 3
function getMazeMasteryArray() {
//$cp[0] = array(requiredmazestied, type, 'value', 'name');
$r[1] = array(1, 2, 'OffsetStripesDiagonal_W.png', 'Light Diagonal Stripes', 0);
$r[2] = array(5, 2, 'OffsetStripesVertical_B_I.png', 'Inverted Dark Vertical Stripes', 0);
$r[3] = array(15, 2, 'DiagonalCover_W_I.png', 'Inverted Light Diagonal Cover', 0);
$r[4] = array(30, 3, '#aafcbb', 'Green');
$r[5] = array(50, 2, 'DiamondLarge_W.png', 'Light Large Diamond', 0);
$r[6] = array(75, 2, 'CrossXL_B.png', 'Dark Large Present', 0);
$r[7] = array(100, 2, 'CircleLargeDonut_W.png', 'Light Annulated Circle', 0);
$r[8] = array(150, 2, 'CrossXL_W_I.png', 'Inverted Bright Large Present', 0);
$r[9] = array(225, 2, 'CircleLarge_W_I.png', 'Inverted Bright Large Circle', 0);
$r[10] = array(300, 2, 'DiamondSmall_B_I.png', 'Inverted Dark Small Diamond', 0);
$r[11] = array(400, 2, 'CircleLargeDonut_B.png', 'Dark Annulated Circle', 0);
$r[12] = array(550, 2, 'CrossXL_B_I.png', 'Inverted Dark Large Present', 0);
//$cp[4] = array(10000, 2, 'DiamondSmall_B.png', 'Dark Small Diamond', 0);
return $r;
}
//TYPE 4
function getWinsArray() {
//$cp[0] = array(requiredmazewins, type, 'value', 'name');
$r[1] = array(1, 2, 'DiagonalCover_B.png', 'Light Diagnol Cover', 0);
$r[2] = array(5, 1, '#22aaaa', 'Teal');
$r[3] = array(15, 2, 'OffsetStripesDiagonal_B.png', 'Dark Diagonal Stripes', 0);
$r[4] = array(30, 2, 'DiamondLargeDonut_W_I.png', 'Inverted Light Annulated Diamond', 0);
$r[5] = array(50, 2, 'StarsR_B.png', 'Dark Stars', 0);
$r[6] = array(75, 2, 'OffsetStripesHorizontal_B_I.png', 'Inverted Dark Horizontal Stripes', 0);
$r[7] = array(100, 2, 'CrossXLDonut_B_I.png', 'Inverted Dark Large Intersection', 0);
$r[8] = array(150, 2, 'DiamondLarge_B.png', 'Dark Large Diamond', 0);
$r[9] = array(225, 1, '#22ff22', 'Neon Lime', 1);
//$r[7] = array(75, 2, 'CircleSmall_W_I.png', 'Inverted Bright Small Circle', 0);
return $r;
}
//Used to track statistics on who wins or ties maps at the end of a day.
function trackMOTDstats($mapType) {
// Our rather massive query to get the data we need.
$sql = "SELECT
users.ID as userID,
SUM(solutions.moves) as Moves,
timediff(MAX(dateModified), maps.dateCreated) as Timetaken
FROM `maps`
JOIN `solutions`
ON maps.ID = solutions.mapID
JOIN `users`
ON solutions.userID = users.ID
JOIN `mapOfTheDay`
ON maps.ID = mapOfTheDay.mapID
WHERE
DATE_ADD(CURDATE(), INTERVAL -1 DAY) =
DATE_FORMAT(solutions.dateModified,'%Y-%m-%d')
AND DATE_ADD(CURDATE(), INTERVAL -1 DAY) =
DATE_FORMAT(maps.dateCreated,'%Y-%m-%d')
AND `mapType` = '$mapType'
GROUP BY solutions.userID
ORDER BY Moves DESC, MAX(dateModified) ASC
";
$mainResult = mysql_query($sql);
if ($mainResult) {
$first = true;
while (list($userID, $uMoves, $uTimeTaken) = mysql_fetch_row($mainResult)) {
//echo "$first : userID: $userID uMoves: $uMoves uTimeTaken: $uTimeTaken mapType: $mapType
";
do {
//If it's the rank #1 user, we need to repeat to also award him the tie stat.
$repeatThis = false;
$sType = $mapType;
if ($first) {
$bestMoves = $uMoves;
$sType = 31 + $mapType;
$repeatThis = true;
}
if ($uMoves == $bestMoves) {
$sql = "SELECT `ID` FROM `statistics`
WHERE `userID` = '$userID' AND `type` = '$sType'";
$result = mysql_query($sql);
if (mysql_num_rows($result) == 0) {
$sql = "INSERT INTO `statistics` (`userID`, `type`, `value`)
VALUES ('$userID', '$sType', 1)";
$result = mysql_query($sql);
if (!$result)
return false;
} else {
$sql = "UPDATE `statistics`
SET `value` = `value` + 1
WHERE `userID` = '$userID' AND `type` = '$sType'";
$result = mysql_query($sql);
if (!$result)
return false;
}
} else {
break 2;
}
$first = false;
} while ($repeatThis);
}
}
return true;
}
//Select Stats/Scores.
function getScores($mapid, $pageNumber = 1, $pageDivide = 10) {
$top = $pageNumber * $pageDivide;
$bottom = $top - $pageDivide;
$pageRequest = 'all';
if ($pageRequest == 'all') {
$pageReqStart = 1;
$pageReqEnd = 1000;
} elseif (is_int($pageRequest)) {
$pageReqStart = $pageRequest;
$pageReqEnd = $pageRequest;
} else {
$tmp = explode($pageRequest, "-");
$pageReqStart = $tmp[0];
$pageReqEnd = $tmp[1];
}
$sql = "
SELECT
timediff(solutions.dateModified, TIMESTAMP(CURDATE())) as diff,
users.displayName as display,
solutions.moves as moves,
users.ID as ID,
IfNull(userData.displayColor, '#cccccc') as displayColor,
IfNull(userData.wallColor, '#666666') as wallColor,
IfNull(userData.wallEmblem, 'blank.png') as wallEmblem,
solutions.dateModified as cdate
FROM
`users`
JOIN `solutions`
ON users.ID = solutions.userID
LEFT JOIN `userData`
ON users.ID = userData.userID
WHERE solutions.mapID = '$mapid'
ORDER BY solutions.moves DESC, solutions.dateModified ASC
";
$result = mysql_query($sql);
//$utime = date("g:i A (T)");
$output['updateTime'] = date("g:i A (T)");
$i = 0;
$foundUser = false;
while ($row = mysql_fetch_assoc($result)) {
$i++;
$moves = $row['moves'];
$userID = $row['ID'];
if ($i == 1) {
$bestMoves = $moves;
$output['bestMoves'] = $bestMoves;
$output['bestBy'] = $row['display'];
}
if ($_SESSION['userID'] == $userID) {
$userPosition = $i;
} else {
if ($i > $top)
continue;
if ($i <= $bottom)
continue;
}
if ($wallEmblem == '')
$wallEmblem = 'blank.png';
$cdate = $row['cdate'];
$cdate = date("g:i A (T)", strtotime($cdate));
$scoredDate = strtotime($row['cdate']);
$secondsSinceScored = strtotime("now") - $scoredDate ;
//Alternate background colors
$background = '#262631';
if ($i % 2 == 1)
$background = '#20202a';
if ($userPosition == $i) {
$background = '#343c57';
$foundUser = true;
}
$medal = 'none';
if ($moves == $bestMoves)
$medal = 'silver';
if ($i == 1)
$medal = 'gold';
$output['users'][$i] = $row;
$output['users'][$i]['scoredDate'] = $cdate;
$output['users'][$i]['secondsSinceScored'] = $secondsSinceScored;
$output['users'][$i]['background'] = $background;
$output['users'][$i]['medal'] = $medal;
$output['users'][$i]['isUser'] = $userPosition == $i;
$output['users'][$i]['debug'] = "Bestmoves: $bestMoves moves: $moves";
} // END WHILE
if ($foundUser) {
$userPage = ceil(($userPosition / $pageDivide));
$output['userPage'] = $userPage;
$output['userPosition'] = $userPosition;
}
$output['pageCount'] = ceil(($i / $pageDivide));
if ($prevPage > 0) {
$navi .= "
<< ";
$navi .= "
< ";
} else {
$navi .= " << ";
$navi .= " <";
}
for ($x = 1; $x <= $pageCount; $x++) {
if ($x < $pageNumber - 3 OR $x > $pageNumber + 3)
continue;
if ($x == $pageNumber)
$navi .= "
$x ";
elseif ($userPage == $x)
$navi .= "
$x ";
else
$navi .= "
$x ";
}
if ($nextPage <= $pageCount) {
$navi .= "
> ";
$navi .= "
>> ";
}
return $output;
}
/**
* Returns true if the given user has completed the tutorial, false otherwise
*/
function hasCompletedTutorial($userID) {
$sql = "SELECT `level` FROM `achievements`
WHERE `type` = 32 AND `userID` = '$userID'
LIMIT 1";
$result = mysql_query($sql);
return (mysql_num_rows($result) >= 1);
}
/**
* 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
";
$result = mysql_query($sql);
echo mysql_error();
if (mysql_num_rows($result) >= 1)
return $result;
return NULL;
}
/**
* Returns the map "code" for the given mapId
*/
function loadMapCode($mapIdUnsanitized)
{
$mapID = mysql_escape_string($mapIdUnsanitized);
$sql = "
SELECT maps.code as code
FROM maps
WHERE ID = '$mapID' AND isChallenge = 1
LIMIT 1
";
$result = mysql_query($sql);
if (mysql_num_rows($result) >= 1)
{
$temp = mysql_fetch_row($result);
return $temp[0];
}
return NULL;
}
?>