summaryrefslogtreecommitdiffstats
path: root/pages/challengelist.php
blob: 364209fc59950e1aff02201a9f14a5cd1ca3883e (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
htmlHeader(
	array('tutorial', 'challenge'), 'Pathery Challenges', 
	'Challenges', array('scores', 'dateformat')
);

include_once ('./includes/maps.php');
include_once ('./includes/mapoftheday.php');
include_once ('./includes/sqlEmbedded.php');
include_once ('./includes/datas.php');
include_once ('./includes/mapclass.php');

topbar($Links);
?>


<div id="challengelist_wrapper" class="wrapper" style='overflow: auto;'>

<?

//Check that the user is allowed to do the challenges
if (!$accepted) {
	echo "<center>Please <a href='javascript:showSignin();'>login</a> to do the challenges!</center>";
	echo "<br /><br /></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);
echo ChallengeList($challengeListResultset);

?>

</div>

<?php
htmlFooter();
?>

<?php

function ChallengeList($challengeListResultset) {
	//First gather data to a more useful form.
	$r = '';
	while($data = mysql_fetch_array($challengeListResultset)) {
		$tier = $data['challengeTier'];
		$challengeSuborder = $data['challengeSuborder'];
		$ordering = $data['ordering'];
		$challenges[$tier][$challengeSuborder][$ordering] = $data;
	}
	
	foreach ($challenges as $tier => $challengeMap) {
		$r .= "<b>Section $tier</b> levels:<div class='challengelist_tier' style='border: 1px solid yellow; overflow: auto;'>";
		foreach ($challengeMap as $challengeSuborder => $challenge) {
			//Hack to get the first element of the array:
			$firstChallenge = $challenge[key($challenge)];
			$challengeMapID = $firstChallenge['challengeMapID'];

			//$mapCode = getMapCode($mapid);
			$mapCode = $firstChallenge['mapCode'];
			$map = new map($mapCode);
			$thumbnail = DisplayMapThumbnail($map);
			
			$r .= "<div class='challengelist_map' onclick='document.location.href=\"challenge?challengeMapID=$challengeMapID\"'>";
			$r .= "$map->name";
			$r .= $thumbnail;
			
			foreach ($challenge as $ordering => $content) {
				//Each challenge gets its own star
				if($content["dateSolved"] !== NULL)
					$cssClass = "challengelist_complete";
				else
					$cssClass = "challengelist_incomplete";
				$r .= "<div class='$cssClass'></div>";
			}
			$r .= "</div>";
			//$r .= "END MAP";
		}
		$r .= "</div>";
	}
	return $r;
}

// TODO: !! Depreciate
/**
 * 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
		// echo "<br>L: $currentTier<br>N: ";
		// echo $challenge["challengeTier"];
		// echo "<br>";
		if($challenge["challengeTier"] != $currentTier)
		{
			if($currentTier >= 0)
			{
				echo '</div>';
			}
			$currentTier = $challenge["challengeTier"];
			echo "<div class='challengelist_tier'>Tier $currentTier</div>";
			echo "<div class='challengelist_table'>\n";
		}
		
		//Each map gets it own row
		if($challenge["mapID"] != $currentMap)
		{
			if($currentMap >= 0)
			{
				echo '</div>';
			}
			$currentMap = $challenge["mapID"];
			
			$mapCode = getMapCode($currentMap);
			$map = new map($mapCode);
			$thumbnail = DisplayMapThumbnail($map);
			
			$mapName = $map->name;
			if($mapName == NULL || $mapName == "")
				$mapName = "(unknown)";
			
			echo "<div style='border:1px solid yellow; float:left; padding:5px; background-color: #222;'>
				<div class='challengelist_link' style='cursor:pointer' onclick='document.location.href=\"challenge?mapID=$currentMap\"'>
					
					<a href='challenge?mapID=$currentMap'>$mapName</a>
					$thumbnail
					
				</div>";
			echo "<div 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 "</div></div>";
	echo "</div>";
}
?>