summaryrefslogtreecommitdiffstats
path: root/pages/challengelist.php
blob: e3f057a37750f10e3a668f5228f2bf92e89c39da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
ob_start("ob_gzhandler");
htmlHeader(
	array('tutorial', 'challenge'), 'Pathery Challenges', 
	'Challenges', array('scores', 'dateformat')
);

include_once ('./includes/maps.php');
include_once ('./includes/mapoftheday.php');
include_once ('./includes/db.inc.php');
include_once ('./includes/datas.php');

topbar($Links);
?>

<div id="challengelist_wrapper" class="wrapper">

<?

//Check that the user is allowed to do the challenges
if (!$accepted) {
	echo "<center>Please <a href='login'>login</a> to do the challenges!</div>";
	htmlFooter();
	return;
}
$userID = $_SESSION['userID'];

//TODO: Uncomment
//if (!hasCompletedTutorial($userID)) {
//	echo "<center>Please <a href='tutorial'>complete the tutorial</a> to unlock Challenge mode!</div>";
//	htmlFooter();
//	return;
//}

?>
	<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>
	</noscript>
<?

//Display the actual challenge list
$challengeListResultset = loadChallengeListing($userID);
displayChallengeList($challengeListResultset);

?>
</div>

<div id="copy" style='width:100%;clear: both'>
	Copyright &copy; 2011-2012 pathery.com
</div>

<?php
htmlFooter();
?>

<?php
/**
 * Outputs the list of all challenges to the page
 */
function displayChallengeList($challengeListResultset)
{
	echo '<div id="challengelist">';
	$currentTier = -1;
	$currentMap = -1;
	while($challenge = mysql_fetch_array($challengeListResultset))
	{
		//Each challenge gets its own header/table
		if($challenge["challengeTier"] != $currentTier)
		{
			if($currentTier >= 0)
			{
				echo '</table>';
			}
			$currentTier = $challenge["challengeTier"];
			echo "<div class='challengelist_tier'>Tier $currentTier</div>";
			echo "<table class='challengelist_table'>";
		}
		
		//Each map gets it own row
		if($challenge["mapID"] != $currentMap)
		{
			if($currentMap >= 0)
			{
				echo '</td></tr>';
			}
			$currentMap = $challenge["mapID"];
			$mapName = $challenge["challengeName"];
			if($mapName == NULL || $mapName == "")
				$mapName = "(unknown)";
			echo "<tr><td class='challengelist_link'><a href='challenge?mapID=$currentMap'>$mapName</a></td>";
			echo "<td class='challengelist_stars'>";
		}
		
		//Each challenge gets its own star
		if($challenge["dateSolved"] !== NULL)
			$cssClass = "challengelist_complete";
		else
			$cssClass = "challengelist_incomplete";
		echo "<div class='$cssClass'></div>";
	}
	echo "</td></tr></table>";
}
?>