summaryrefslogtreecommitdiffstats
path: root/pages/admin.php
blob: d825ebc6f25cf27c5ccdb96be7e152c75d080e0c (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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
htmlHeader();
?>

<body>
<?php
topbar($Links);

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

//$motd = MapOfTheDay(3);
//$mapID = $motd['id'];

$pastMap = pastMap(3, 1);
$mapID = $pastMap;

echo $mapID;

//$mapID = '38';
$mapcode = getMapCode($mapID);
$map = GenerateMapByCode($mapcode);

$sql = "SELECT `moves`, `displayName`, `solution`
	FROM `solutions`, `users`
	WHERE `mapID` = '$mapID' AND 
	`userID` = users.ID
	ORDER BY `moves` DESC, `dateModified` ASC
	LIMIT 1";

$result = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result) > 0) {
	list($bestMoves, $byName, $solution) = mysql_fetch_row($result);
	echo "<br />Best solution for this map: $bestMoves by $byName";
	
	//$map = MergeMapSolution($motd['map'], $solution);
	$map = MergeMapSolution($map, $solution);
	echo DisplayMap($map, $mapID);
    
	echo "<br />";
	echo "<br />Is Current:";
	$is = isCurrentMap(77);
	echo "<br />$is";
	$is = isCurrentMap(20);
	echo "<br />$is";
	$is = isCurrentMap(76);
	echo "<br />$is";
	$is = isCurrentMap(75);
	echo "<br />$is";
	$is = isCurrentMap(74);
	echo "<br />$is";
	echo "<br />";
    
}

function isCurrentMap($mapID) {
	include_once('./includes/db.inc.php');
	$sql = "SELECT `ID` FROM `mapOfTheDay`
	WHERE `mapDate` = CURDATE() AND
		`mapID` = '$mapID'
	";
	$result = mysql_query($sql) or die(mysql_error());
	if (mysql_num_rows($result) == 0) 
		return false;
	else 
		return true;
}



echo "<br />";
echo "<br />";
echo "<br />Solution before";
echo "<br />";
echo $solution;
echo "<br />";
echo "<br />Solution after";
echo "<br />";
$solution = formSolution($solution);
echo $solution;
echo "<br />";
echo "<br />";
echo "<br />";
// echo "<center><b> The map for today: 
// <br />Once logged in your best solutions for the map(s) are saved.
// <br />- Soon i'll fix it so you can see those solutions, and compare them with others.
// <br />- New maps are generated daily, at 9:00 PM Pacific Standard. (for now...)
// </b></center>";
// echo DisplayMap($motd['map'], $motd['id']);




function createThumbnail($mapMatrix, $idprefix, $width, $height) {
	//Iterate through $mapMatrix and generate the html
	
	$maptable = "";		//The string to return to the database.
	$index = 0;		//The current number of tiles from the last tile saved.
	
	for( $i = 1; $i < count($mapMatrix); $i++)
	{
      $maptable .= "<tr>";
		for( $j = 0; $j < count($mapMatrix[$i]); $j++)
		{
		//==
		$index++;
		
		$handle = "$idprefix,$i,$j";
		 switch($mapMatrix[$i][$j])
         {
            case 's': $maptable .= "<td class='grid_td_start' id='$handle' ></td>"; break;
            case 'f': $maptable .= "<td class='grid_td_finish' id='$handle' ></td>"; break;
            case 't': $maptable .= "<td class='grid_td_tp1_in' id='$handle' ></td>"; break;
            //case 't': $maptable .= "<td class='grid_td_tp1_in' id='$handle' ><img class='grid_img' src='images/OverlayTeleport.png' /></td>"; break;
            case 'u': $maptable .= "<td class='grid_td_tp1_out' id='$handle' ></td>"; break;
            case 'm': $maptable .= "<td class='grid_td_tp2_in' id='$handle' ></td>"; break;
            case 'n': $maptable .= "<td class='grid_td_tp2_out' id='$handle' ></td>"; break;
				
            case 'a': $maptable .= "<td class='grid_td_cpa' id='$handle' ></td>"; break;
            case 'b': $maptable .= "<td class='grid_td_cpb' id='$handle' ></td>"; break;
            case 'c': $maptable .= "<td class='grid_td_cpc' id='$handle' ></td>"; break;
            case 'd': $maptable .= "<td class='grid_td_cpd' id='$handle' ></td>"; break;
            case 'e': $maptable .= "<td class='grid_td_cpe' id='$handle' ></td>"; break;
				
            case 'r': $maptable .= "<td class='grid_td_rocks' id='$handle' ></td>"; break;  //rock
            case 'w': $maptable .= "<td class='grid_td_walls' id='$handle' onClick='grid_click(this)' ></td>"; break;  //wall
            //default: $maptable .= "<td class='grid_td' id='$handle' onClick='grid_click(this)' >".$index."</td>";
            default: $maptable .= "<td class='grid_td' id='$handle' onClick='grid_click(this)' ></td>";
            //default: $maptable .= "<td class='grid_td' id='$handle' onClick='grid_click(this)' >".$mapMatrix[$i][$j]."</td>";
         }
		}
      $maptable .= "</tr>";
	}
	//Prepare mapdata.
	$mapdata['height'] = $mapMatrix[0][0];
   $mapdata['width'] = $mapMatrix[0][1];
   $mapdata['points'] = $mapMatrix[0][2];
   $mapdata['rocks'] = $mapMatrix[0][3];
   $mapdata['walls'] = $mapMatrix[0][4];
   $mapdata['teleports'] = $mapMatrix[0][5];
   $mapdata['example'] = $example;
   $mapdata['mapid'] = $idprefix;
	
	$path = routePath($mapMatrix, '');
	$mapdata['code'] = GenerateMapCode($mapMatrix);
	
	$width = (($j * 35) + 2).'px';
	//$width = (($j * 23) + 2).'px';
	$i -= 1;
	$height = (($i * 35)).'px';
	//$height = (($i * 22) + 2).'px';
	
	$jsonmap = json_encode($mapdata);
   $mapdatadiv .= "<div id='$idprefix,mapdata' style='visibility:hidden;display:none'>";
	$mapdatadiv .=  $jsonmap;
	$mapdatadiv .=  '</div>';
	
   $maptable = "<table style='width:$width;height:$height;' class='grid_table'>
   $maptable
   </table>";
	
	if ($example) {
		$output = $maptable;
		$output .= "<input id='$idprefix,btn' type='button' onclick='doSend($idprefix)' value='Test path' />";
		$output .= "
		<div style='display:none;'>
		<input type='radio' name='$idprefix,speed' id='$idprefix,spdslow' checked=true />
		<input type='radio' name='$idprefix,speed' id='$idprefix,spdmed' />
		<input type='radio' name='$idprefix,speed' id='$idprefix,spdfast' />
		<input type='checkbox' id='$idprefix,mute' checked=true />
		</div>
		";
		$output .= $mapdatadiv;
		$output = "<div style='width:$width;height:$height;'>
		$output
		</div>";
		return $output;
	}
	
   $output = "
<div id='$idprefix,outer' class='grid_outer' style='width:".($width+30)."px;height:".($height+60)."px;'>
	
	<div class='grid_dsp_left dsp_60'>
		<div id='$idprefix,dspID' class='grid_dsp_data' title='MapID: $idprefix'> 
			MapID: $idprefix
		</div>
	</div>
	
	<div id='$idprefix,dsptl' class='grid_dsp_mid dsp_24'> 
		<a href='javascript:resetwalls($idprefix)'>Reset</a> 
	</div>

	
	<div id='$idprefix,dsptr' class='grid_dsp_right dsp_24'>
		<div id='$idprefix,dspWalls' class='grid_dsp_data'> 
			".$mapdata['walls']." walls
		</div>
	</div>
	
	$maptable
	
	<div id='$idprefix,dspbl' class='grid_dsp_left dsp_49'> 
		<input id='$idprefix,btn' type='button' onclick='doSend($idprefix)' value='Test path' />

		<label><input type='radio' name='$idprefix,speed' id='$idprefix,spdslow' />slow</label>
		<label><input type='radio' name='$idprefix,speed' id='$idprefix,spdmed' checked=true />med</label>
		<label><input type='radio' name='$idprefix,speed' id='$idprefix,spdfast' />fast</label>
	</div>
	
	<div class='grid_dsp_mid dsp_16'>
		<label><input type='checkbox' id='$idprefix,mute' />Mute</label>
	</div>
	
	<div id='$idprefix,dspbr' class='grid_dsp_right dsp_33'> 
		<div id='$idprefix,dspCount' class='grid_dsp_data'> 
			".$path['moves']." moves 
		</div>
   </div>
	
	$mapdatadiv
</div>
	";
	
	return $output;
}

htmlFooter();
?>