Passed
Pull Request — master (#236)
by PoUpA
02:40
created
core/process/aru.php 1 patch
Switch Indentation   +347 added lines, -347 removed lines patch added patch discarded remove patch
@@ -58,150 +58,150 @@  discard block
 block discarded – undo
58 58
 	//
59 59
 	############################
60 60
 
61
-	case 'home_update':
62
-		// Right now
63
-		// ---------
61
+		case 'home_update':
62
+			// Right now
63
+			// ---------
64 64
 
65
-		$req 		= "SELECT COUNT(*) as total FROM pokemon WHERE disappear_time >= UTC_TIMESTAMP()";
66
-		$result 	= $mysqli->query($req);
67
-		$data 		= $result->fetch_object();
65
+			$req 		= "SELECT COUNT(*) as total FROM pokemon WHERE disappear_time >= UTC_TIMESTAMP()";
66
+			$result 	= $mysqli->query($req);
67
+			$data 		= $result->fetch_object();
68 68
 
69
-		$values[] 	= $data->total;
69
+			$values[] 	= $data->total;
70 70
 
71 71
 
72
-		// Lured stops
73
-		// -----------
72
+			// Lured stops
73
+			// -----------
74 74
 
75
-		$req 		= "SELECT COUNT(*) as total FROM pokestop WHERE lure_expiration >= UTC_TIMESTAMP()";
76
-		$result 	= $mysqli->query($req);
77
-		$data 		= $result->fetch_object();
75
+			$req 		= "SELECT COUNT(*) as total FROM pokestop WHERE lure_expiration >= UTC_TIMESTAMP()";
76
+			$result 	= $mysqli->query($req);
77
+			$data 		= $result->fetch_object();
78 78
 
79
-		$values[] 	= $data->total;
79
+			$values[] 	= $data->total;
80 80
 
81 81
 
82 82
 
83
-		// Team battle
84
-		// -----------
83
+			// Team battle
84
+			// -----------
85 85
 
86
-		$req 		= "SELECT count( DISTINCT(gym_id) ) as total FROM gym";
87
-		$result 	= $mysqli->query($req);
88
-		$data 		= $result->fetch_object();
86
+			$req 		= "SELECT count( DISTINCT(gym_id) ) as total FROM gym";
87
+			$result 	= $mysqli->query($req);
88
+			$data 		= $result->fetch_object();
89 89
 
90
-		$values[] 	= $data->total;
90
+			$values[] 	= $data->total;
91 91
 
92
-		// Team
93
-		// 1 = bleu
94
-		// 2 = rouge
95
-		// 3 = jaune
92
+			// Team
93
+			// 1 = bleu
94
+			// 2 = rouge
95
+			// 3 = jaune
96 96
 
97
-		$req	= "SELECT count( DISTINCT(gym_id) ) as total FROM gym WHERE team_id = '2'  ";
98
-		$result	= $mysqli->query($req);
99
-		$data	= $result->fetch_object();
97
+			$req	= "SELECT count( DISTINCT(gym_id) ) as total FROM gym WHERE team_id = '2'  ";
98
+			$result	= $mysqli->query($req);
99
+			$data	= $result->fetch_object();
100 100
 
101
-		// Red
102
-		$values[] = $data->total;
101
+			// Red
102
+			$values[] = $data->total;
103 103
 
104 104
 
105
-		$req	= "SELECT count( DISTINCT(gym_id) ) as total FROM gym WHERE team_id = '1'  ";
106
-		$result	= $mysqli->query($req);
107
-		$data	= $result->fetch_object();
105
+			$req	= "SELECT count( DISTINCT(gym_id) ) as total FROM gym WHERE team_id = '1'  ";
106
+			$result	= $mysqli->query($req);
107
+			$data	= $result->fetch_object();
108 108
 
109
-		// Blue
110
-		$values[] = $data->total;
109
+			// Blue
110
+			$values[] = $data->total;
111 111
 
112 112
 
113
-		$req	= "SELECT count( DISTINCT(gym_id) ) as total FROM gym WHERE team_id = '3'  ";
114
-		$result	= $mysqli->query($req);
115
-		$data	= $result->fetch_object();
113
+			$req	= "SELECT count( DISTINCT(gym_id) ) as total FROM gym WHERE team_id = '3'  ";
114
+			$result	= $mysqli->query($req);
115
+			$data	= $result->fetch_object();
116 116
 
117
-		// Yellow
118
-		$values[] = $data->total;
117
+			// Yellow
118
+			$values[] = $data->total;
119 119
 
120
-		$req	= "SELECT count( DISTINCT(gym_id) ) as total FROM gym WHERE team_id = '0'  ";
121
-		$result	= $mysqli->query($req);
122
-		$data	= $result->fetch_object();
120
+			$req	= "SELECT count( DISTINCT(gym_id) ) as total FROM gym WHERE team_id = '0'  ";
121
+			$result	= $mysqli->query($req);
122
+			$data	= $result->fetch_object();
123 123
 
124
-		// Neutral
125
-		$values[] = $data->total;
124
+			// Neutral
125
+			$values[] = $data->total;
126 126
 
127 127
 
128
-		header('Content-Type: application/json');
129
-		$json = json_encode($values);
128
+			header('Content-Type: application/json');
129
+			$json = json_encode($values);
130 130
 
131
-		echo $json;
131
+			echo $json;
132 132
 
133 133
 
134
-		break;
134
+			break;
135 135
 
136 136
 
137 137
 
138
-	####################################
139
-	//
140
-	// Update latests spawn on homepage
141
-	//
142
-	####################################
138
+		####################################
139
+		//
140
+		// Update latests spawn on homepage
141
+		//
142
+		####################################
143 143
 
144
-	case 'spawnlist_update':
145
-		// Recent spawn
146
-		// ------------
147
-		$total_spawns = array();
148
-		$last_uid_param = "";
149
-		if (isset($_GET['last_uid'])) {
150
-			$last_uid_param = $_GET['last_uid'];
151
-		}
152
-		if ($config->system->recents_filter) {
153
-			// get all mythic pokemon ids
154
-			$mythic_pokemons = array();
155
-			foreach ($pokemons->pokemon as $id => $pokemon) {
156
-				if ($pokemon->spawn_rate < $config->system->recents_filter_rarity && $pokemon->rating >= $config->system->recents_filter_rating) {
157
-					$mythic_pokemons[] = $id;
158
-				}
144
+		case 'spawnlist_update':
145
+			// Recent spawn
146
+			// ------------
147
+			$total_spawns = array();
148
+			$last_uid_param = "";
149
+			if (isset($_GET['last_uid'])) {
150
+				$last_uid_param = $_GET['last_uid'];
159 151
 			}
152
+			if ($config->system->recents_filter) {
153
+				// get all mythic pokemon ids
154
+				$mythic_pokemons = array();
155
+				foreach ($pokemons->pokemon as $id => $pokemon) {
156
+					if ($pokemon->spawn_rate < $config->system->recents_filter_rarity && $pokemon->rating >= $config->system->recents_filter_rating) {
157
+						$mythic_pokemons[] = $id;
158
+					}
159
+				}
160 160
 
161
-			// get last mythic pokemon
162
-			$req		= "SELECT pokemon_id, encounter_id, disappear_time, last_modified, (CONVERT_TZ(disappear_time, '+00:00', '".$time_offset."')) as disappear_time_real, latitude, longitude, individual_attack, individual_defense, individual_stamina FROM pokemon
161
+				// get last mythic pokemon
162
+				$req		= "SELECT pokemon_id, encounter_id, disappear_time, last_modified, (CONVERT_TZ(disappear_time, '+00:00', '".$time_offset."')) as disappear_time_real, latitude, longitude, individual_attack, individual_defense, individual_stamina FROM pokemon
163 163
                         WHERE pokemon_id IN (".implode(",", $mythic_pokemons).")
164 164
                         ORDER BY last_modified DESC LIMIT 0,12";
165
-		} else {
166
-			// get last pokemon
167
-			$req		= "SELECT pokemon_id, encounter_id, disappear_time, last_modified, (CONVERT_TZ(disappear_time, '+00:00', '".$time_offset."')) as disappear_time_real, latitude, longitude, individual_attack, individual_defense, individual_stamina FROM pokemon ORDER BY last_modified DESC LIMIT 0,12";
168
-		}
169
-		$result = $mysqli->query($req);
170
-		while ($data = $result->fetch_object()) {
171
-			$new_spawn = array();
172
-			$pokeid = $data->pokemon_id;
173
-			$pokeuid = $data->encounter_id;
174
-
175
-			if ($last_uid_param != $pokeuid) {
176
-				$last_seen = strtotime($data->disappear_time_real);
177
-
178
-				$last_location = new stdClass();
179
-				$last_location->latitude = $data->latitude;
180
-				$last_location->longitude = $data->longitude;
181
-
182
-				if ($config->system->recents_show_iv) {
183
-					$iv = new stdClass();
184
-					$iv->attack = $data->individual_attack;
185
-					$iv->defense = $data->individual_defense;
186
-					$iv->stamina = $data->individual_stamina;
187
-					if (isset($iv->attack) && isset($iv->defense) && isset($iv->stamina)) {
188
-						$iv->available = true;
189
-					} else {
190
-						$iv->available = false;
165
+			} else {
166
+				// get last pokemon
167
+				$req		= "SELECT pokemon_id, encounter_id, disappear_time, last_modified, (CONVERT_TZ(disappear_time, '+00:00', '".$time_offset."')) as disappear_time_real, latitude, longitude, individual_attack, individual_defense, individual_stamina FROM pokemon ORDER BY last_modified DESC LIMIT 0,12";
168
+			}
169
+			$result = $mysqli->query($req);
170
+			while ($data = $result->fetch_object()) {
171
+				$new_spawn = array();
172
+				$pokeid = $data->pokemon_id;
173
+				$pokeuid = $data->encounter_id;
174
+
175
+				if ($last_uid_param != $pokeuid) {
176
+					$last_seen = strtotime($data->disappear_time_real);
177
+
178
+					$last_location = new stdClass();
179
+					$last_location->latitude = $data->latitude;
180
+					$last_location->longitude = $data->longitude;
181
+
182
+					if ($config->system->recents_show_iv) {
183
+						$iv = new stdClass();
184
+						$iv->attack = $data->individual_attack;
185
+						$iv->defense = $data->individual_defense;
186
+						$iv->stamina = $data->individual_stamina;
187
+						if (isset($iv->attack) && isset($iv->defense) && isset($iv->stamina)) {
188
+							$iv->available = true;
189
+						} else {
190
+							$iv->available = false;
191
+						}
191 192
 					}
192
-				}
193 193
 
194
-				$html = '
194
+					$html = '
195 195
 			    <div class="col-md-1 col-xs-4 pokemon-single" data-pokeid="'.$pokeid.'" data-pokeuid="'.$pokeuid.'" style="display: none;">
196 196
 				<a href="pokemon/'.$pokeid.'"><img src="core/pokemons/'.$pokeid.$config->system->pokeimg_suffix.'" alt="'.$pokemons->pokemon->$pokeid->name.'" class="img-responsive"></a>
197 197
 				<a href="pokemon/'.$pokeid.'"><p class="pkmn-name">'.$pokemons->pokemon->$pokeid->name.'</p></a>
198 198
 				<a href="https://maps.google.com/?q='.$last_location->latitude.','.$last_location->longitude.'&ll='.$last_location->latitude.','.$last_location->longitude.'&z=16" target="_blank">
199 199
 				    <small class="pokemon-timer">00:00:00</small>
200 200
 				</a>';
201
-				if ($config->system->recents_show_iv) {
202
-					if ($iv->available) {
203
-						if ($config->system->iv_numbers) {
204
-							$html .= '
201
+					if ($config->system->recents_show_iv) {
202
+						if ($iv->available) {
203
+							if ($config->system->iv_numbers) {
204
+								$html .= '
205 205
 							<div class="progress" style="height: 15px; margin-bottom: 0">
206 206
 								<div title="'.$locales->IV_ATTACK.': '.$iv->attack.'" class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="'.$iv->attack.'" aria-valuemin="0" aria-valuemax="45" style="width: '.(100 / 3).'%; line-height: 16px";>
207 207
 									<span class="sr-only">'.$locales->IV_ATTACK.': '.$iv->attack.'</span>'.$iv->attack .'
@@ -213,8 +213,8 @@  discard block
 block discarded – undo
213 213
 									<span class="sr-only">'.$locales->IV_STAMINA.': '.$iv->stamina.'</span>'.$iv->stamina .'
214 214
 								</div>
215 215
 							</div>';
216
-						} else {
217
-							$html .= '
216
+							} else {
217
+								$html .= '
218 218
 							<div class="progress" style="height: 6px; width: 80%; margin: 5px auto 0 auto;">
219 219
 					    		<div title="'.$locales->IV_ATTACK.': '.$iv->attack.'" class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="'.$iv->attack.'" aria-valuemin="0" aria-valuemax="45" style="width: '.(((100 / 15) * $iv->attack) / 3).'%">
220 220
 									<span class="sr-only">'.$locales->IV_ATTACK.': '.$iv->attack.'</span>
@@ -226,10 +226,10 @@  discard block
 block discarded – undo
226 226
 									<span class="sr-only">'.$locales->IV_STAMINA.': '.$iv->stamina.'</span>
227 227
 					    		</div>
228 228
 							</div>';
229
-						}
230
-					} else {
231
-						if ($config->system->iv_numbers) {
232
-							$html .= '
229
+							}
230
+						} else {
231
+							if ($config->system->iv_numbers) {
232
+								$html .= '
233 233
 							<div class="progress" style="height: 15px; margin-bottom: 0">
234 234
 								<div title="'.$locales->IV_ATTACK.': not available" class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="'.$iv->attack.'" aria-valuemin="0" aria-valuemax="45" style="width: '.(100 / 3).'%; line-height: 16px";>
235 235
 									<span class="sr-only">'.$locales->IV_ATTACK.': '.$locales->NOT_AVAILABLE.'</span>
@@ -241,129 +241,129 @@  discard block
 block discarded – undo
241 241
 									<span class="sr-only">'.$locales->IV_STAMINA.': '.$locales->NOT_AVAILABLE.'</span>
242 242
 								</div>
243 243
 							</div>';
244
-						} else {
245
-						$html .= '
244
+							} else {
245
+							$html .= '
246 246
 					    <div class="progress" style="height: 6px; width: 80%; margin: 5px auto 15px auto;">
247 247
 						    <div title="IV not available" class="progress-bar" role="progressbar" style="width: 100%; background-color: rgb(210,210,210);" aria-valuenow="1" aria-valuemin="0" aria-valuemax="1">
248 248
 							    <span class="sr-only">IV '.$locales->NOT_AVAILABLE.'</span>
249 249
 						    </div>
250 250
 					    </div>';
251
+							}
251 252
 						}
252 253
 					}
253
-				}
254
-				$html .= '
254
+					$html .= '
255 255
 			    </div>';
256
-				$new_spawn['html'] = $html;
257
-				$countdown = $last_seen - time();
258
-				$new_spawn['countdown'] = $countdown;
259
-				$new_spawn['pokemon_uid'] = $pokeuid;
260
-				$total_spawns[] = $new_spawn;
261
-			} else {
262
-				break;
256
+					$new_spawn['html'] = $html;
257
+					$countdown = $last_seen - time();
258
+					$new_spawn['countdown'] = $countdown;
259
+					$new_spawn['pokemon_uid'] = $pokeuid;
260
+					$total_spawns[] = $new_spawn;
261
+				} else {
262
+					break;
263
+				}
263 264
 			}
264
-		}
265
-		header('Content-Type: application/json');
266
-		echo json_encode($total_spawns);
267
-		break;
268
-
269
-
265
+			header('Content-Type: application/json');
266
+			echo json_encode($total_spawns);
267
+			break;
270 268
 
271
-	####################################
272
-	//
273
-	// List Pokestop
274
-	//
275
-	####################################
276 269
 
277
-	case 'pokestop':
278
-		if (!($config->system->only_lured_pokestops)) {
279
-			$req 		= "SELECT latitude, longitude, lure_expiration, UTC_TIMESTAMP() as now, (CONVERT_TZ(lure_expiration, '+00:00', '".$time_offset."')) as lure_expiration_real FROM pokestop";
280
-		} else {
281
-			$req 		= "SELECT latitude, longitude, lure_expiration, UTC_TIMESTAMP() as now, (CONVERT_TZ(lure_expiration, '+00:00', '".$time_offset."')) as lure_expiration_real FROM pokestop WHERE lure_expiration > UTC_TIMESTAMP()";
282
-		}
283
-		$result 	= $mysqli->query($req);
284 270
 
285
-		$i=0;
271
+		####################################
272
+		//
273
+		// List Pokestop
274
+		//
275
+		####################################
286 276
 
287
-		while ($data = $result->fetch_object()) {
288
-			if ($data->lure_expiration >= $data->now) {
289
-				$icon = 'pokestap_lured.png';
290
-				$text = sprintf($locales->POKESTOPS_MAP_LURED, date('H:i:s', strtotime($data->lure_expiration_real)));
277
+		case 'pokestop':
278
+			if (!($config->system->only_lured_pokestops)) {
279
+				$req 		= "SELECT latitude, longitude, lure_expiration, UTC_TIMESTAMP() as now, (CONVERT_TZ(lure_expiration, '+00:00', '".$time_offset."')) as lure_expiration_real FROM pokestop";
291 280
 			} else {
292
-				$icon = 'pokestap.png';
293
-				$text = $locales->POKESTOPS_MAP_REGULAR;
281
+				$req 		= "SELECT latitude, longitude, lure_expiration, UTC_TIMESTAMP() as now, (CONVERT_TZ(lure_expiration, '+00:00', '".$time_offset."')) as lure_expiration_real FROM pokestop WHERE lure_expiration > UTC_TIMESTAMP()";
294 282
 			}
283
+			$result 	= $mysqli->query($req);
295 284
 
296
-			$temp[$i][] = $text;
297
-			$temp[$i][] = $icon;
298
-			$temp[$i][] = $data->latitude;
299
-			$temp[$i][] = $data->longitude;
300
-			$temp[$i][] = $i;
285
+			$i=0;
301 286
 
302
-			$temp_json[] = json_encode($temp[$i]);
287
+			while ($data = $result->fetch_object()) {
288
+				if ($data->lure_expiration >= $data->now) {
289
+					$icon = 'pokestap_lured.png';
290
+					$text = sprintf($locales->POKESTOPS_MAP_LURED, date('H:i:s', strtotime($data->lure_expiration_real)));
291
+				} else {
292
+					$icon = 'pokestap.png';
293
+					$text = $locales->POKESTOPS_MAP_REGULAR;
294
+				}
303 295
 
296
+				$temp[$i][] = $text;
297
+				$temp[$i][] = $icon;
298
+				$temp[$i][] = $data->latitude;
299
+				$temp[$i][] = $data->longitude;
300
+				$temp[$i][] = $i;
304 301
 
305
-			$i++;
306
-		}
302
+				$temp_json[] = json_encode($temp[$i]);
307 303
 
308
-		$return = json_encode($temp_json);
309 304
 
310
-		echo $return;
305
+				$i++;
306
+			}
311 307
 
312
-		break;
308
+			$return = json_encode($temp_json);
313 309
 
310
+			echo $return;
314 311
 
312
+			break;
315 313
 
316
-	####################################
317
-	//
318
-	// Update data for the gym battle
319
-	//
320
-	####################################
321 314
 
322
-	case 'update_gym':
323
-		$teams			= new stdClass();
324
-		$teams->mystic 		= 1;
325
-		$teams->valor 		= 2;
326
-		$teams->instinct 	= 3;
327 315
 
316
+		####################################
317
+		//
318
+		// Update data for the gym battle
319
+		//
320
+		####################################
328 321
 
329
-		foreach ($teams as $team_name => $team_id) {
330
-			$req	= "SELECT COUNT(DISTINCT(gym_id)) as total, ROUND(AVG(gym_points),0) as average_points FROM gym WHERE team_id = '".$team_id."'  ";
331
-			$result	= $mysqli->query($req);
332
-			$data	= $result->fetch_object();
322
+		case 'update_gym':
323
+			$teams			= new stdClass();
324
+			$teams->mystic 		= 1;
325
+			$teams->valor 		= 2;
326
+			$teams->instinct 	= 3;
333 327
 
334
-			$return[] 	= $data->total;
335
-			$return[]	= $data->average_points;
336
-		}
337 328
 
338
-		$json = json_encode($return);
329
+			foreach ($teams as $team_name => $team_id) {
330
+				$req	= "SELECT COUNT(DISTINCT(gym_id)) as total, ROUND(AVG(gym_points),0) as average_points FROM gym WHERE team_id = '".$team_id."'  ";
331
+				$result	= $mysqli->query($req);
332
+				$data	= $result->fetch_object();
339 333
 
340
-		header('Content-Type: application/json');
341
-		echo $json;
334
+				$return[] 	= $data->total;
335
+				$return[]	= $data->average_points;
336
+			}
342 337
 
338
+			$json = json_encode($return);
343 339
 
344
-		break;
340
+			header('Content-Type: application/json');
341
+			echo $json;
345 342
 
346
-	####################################
347
-	//
348
-	// Get datas for the gym map
349
-	//
350
-	####################################
351 343
 
344
+			break;
352 345
 
353
-	case 'gym_map':
354
-		$req 		= "SELECT gym_id, team_id, guard_pokemon_id, gym_points, latitude, longitude, (CONVERT_TZ(last_scanned, '+00:00', '".$time_offset."')) as last_scanned FROM gym";
355
-		$result 	= $mysqli->query($req);
346
+		####################################
347
+		//
348
+		// Get datas for the gym map
349
+		//
350
+		####################################
356 351
 
357 352
 
358
-		$i=0;
353
+		case 'gym_map':
354
+			$req 		= "SELECT gym_id, team_id, guard_pokemon_id, gym_points, latitude, longitude, (CONVERT_TZ(last_scanned, '+00:00', '".$time_offset."')) as last_scanned FROM gym";
355
+			$result 	= $mysqli->query($req);
359 356
 
360
-		while ($data = $result->fetch_object()) {
361
-			// Team
362
-			// 1 = bleu
363
-			// 2 = rouge
364
-			// 3 = jaune
365 357
 
366
-			switch ($data->team_id) {
358
+			$i=0;
359
+
360
+			while ($data = $result->fetch_object()) {
361
+				// Team
362
+				// 1 = bleu
363
+				// 2 = rouge
364
+				// 3 = jaune
365
+
366
+				switch ($data->team_id) {
367 367
 				case 0:
368 368
 					$icon	= 'map_white.png';
369 369
 					$team	= 'No Team (yet)';
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
 					$team	= 'Team Instinct';
388 388
 					$color	= 'rgba(254, 217, 40, .6)';
389 389
 					break;
390
-			}
390
+				}
391 391
 
392 392
 			// Set gym level
393 393
 			$data->gym_level=0;
@@ -459,65 +459,65 @@  discard block
 block discarded – undo
459 459
 	//
460 460
 	####################################
461 461
 
462
-	case 'gym_defenders':
463
-		$gym_id = $mysqli->real_escape_string($_GET['gym_id']);
464
-		$req 		= "SELECT gymdetails.name as name, gymdetails.description as description, gym.gym_points as points, gymdetails.url as url, gym.team_id as team, (CONVERT_TZ(gym.last_scanned, '+00:00', '".$time_offset."')) as last_scanned, gym.guard_pokemon_id as guard_pokemon_id FROM gymdetails LEFT JOIN gym on gym.gym_id = gymdetails.gym_id WHERE gym.gym_id='".$gym_id."'";
465
-		$result 	= $mysqli->query($req);
466
-		$gymData['gymDetails']['gymInfos'] = false;
467
-		while ($data = $result->fetch_object()) {
468
-			$gymData['gymDetails']['gymInfos']['name'] = $data->name;
469
-			$gymData['gymDetails']['gymInfos']['description'] = $data->description;
470
-			if ($data->url == null) {
471
-				$gymData['gymDetails']['gymInfos']['url'] = '';
472
-			} else {
473
-				$gymData['gymDetails']['gymInfos']['url'] = $data->url;
474
-			}
475
-			$gymData['gymDetails']['gymInfos']['points'] = $data->points;
476
-			$gymData['gymDetails']['gymInfos']['level'] = 0;
477
-			$gymData['gymDetails']['gymInfos']['last_scanned'] = $data->last_scanned;
478
-			$gymData['gymDetails']['gymInfos']['team'] = $data->team;
479
-			$gymData['gymDetails']['gymInfos']['guardPokemonId'] = $data->guard_pokemon_id;
480
-			if ($data->points < 2000) {
481
-				$gymData['gymDetails']['gymInfos']['level']=1;
482
-			} elseif ($data->points < 4000) {
483
-				$gymData['gymDetails']['gymInfos']['level']=2;
484
-			} elseif ($data->points < 8000) {
485
-				$gymData['gymDetails']['gymInfos']['level']=3;
486
-			} elseif ($data->points < 12000) {
487
-				$gymData['gymDetails']['gymInfos']['level']=4;
488
-			} elseif ($data->points < 16000) {
489
-				$gymData['gymDetails']['gymInfos']['level']=5;
490
-			} elseif ($data->points < 20000) {
491
-				$gymData['gymDetails']['gymInfos']['level']=6;
492
-			} elseif ($data->points < 30000) {
493
-				$gymData['gymDetails']['gymInfos']['level']=7;
494
-			} elseif ($data->points < 40000) {
495
-				$gymData['gymDetails']['gymInfos']['level']=8;
496
-			} elseif ($data->points < 50000) {
497
-				$gymData['gymDetails']['gymInfos']['level']=9;
498
-			} else {
499
-				$gymData['gymDetails']['gymInfos']['level']=10;
462
+		case 'gym_defenders':
463
+			$gym_id = $mysqli->real_escape_string($_GET['gym_id']);
464
+			$req 		= "SELECT gymdetails.name as name, gymdetails.description as description, gym.gym_points as points, gymdetails.url as url, gym.team_id as team, (CONVERT_TZ(gym.last_scanned, '+00:00', '".$time_offset."')) as last_scanned, gym.guard_pokemon_id as guard_pokemon_id FROM gymdetails LEFT JOIN gym on gym.gym_id = gymdetails.gym_id WHERE gym.gym_id='".$gym_id."'";
465
+			$result 	= $mysqli->query($req);
466
+			$gymData['gymDetails']['gymInfos'] = false;
467
+			while ($data = $result->fetch_object()) {
468
+				$gymData['gymDetails']['gymInfos']['name'] = $data->name;
469
+				$gymData['gymDetails']['gymInfos']['description'] = $data->description;
470
+				if ($data->url == null) {
471
+					$gymData['gymDetails']['gymInfos']['url'] = '';
472
+				} else {
473
+					$gymData['gymDetails']['gymInfos']['url'] = $data->url;
474
+				}
475
+				$gymData['gymDetails']['gymInfos']['points'] = $data->points;
476
+				$gymData['gymDetails']['gymInfos']['level'] = 0;
477
+				$gymData['gymDetails']['gymInfos']['last_scanned'] = $data->last_scanned;
478
+				$gymData['gymDetails']['gymInfos']['team'] = $data->team;
479
+				$gymData['gymDetails']['gymInfos']['guardPokemonId'] = $data->guard_pokemon_id;
480
+				if ($data->points < 2000) {
481
+					$gymData['gymDetails']['gymInfos']['level']=1;
482
+				} elseif ($data->points < 4000) {
483
+					$gymData['gymDetails']['gymInfos']['level']=2;
484
+				} elseif ($data->points < 8000) {
485
+					$gymData['gymDetails']['gymInfos']['level']=3;
486
+				} elseif ($data->points < 12000) {
487
+					$gymData['gymDetails']['gymInfos']['level']=4;
488
+				} elseif ($data->points < 16000) {
489
+					$gymData['gymDetails']['gymInfos']['level']=5;
490
+				} elseif ($data->points < 20000) {
491
+					$gymData['gymDetails']['gymInfos']['level']=6;
492
+				} elseif ($data->points < 30000) {
493
+					$gymData['gymDetails']['gymInfos']['level']=7;
494
+				} elseif ($data->points < 40000) {
495
+					$gymData['gymDetails']['gymInfos']['level']=8;
496
+				} elseif ($data->points < 50000) {
497
+					$gymData['gymDetails']['gymInfos']['level']=9;
498
+				} else {
499
+					$gymData['gymDetails']['gymInfos']['level']=10;
500
+				}
500 501
 			}
501
-		}
502
-		//print_r($gymData);
503
-		$req 		= "SELECT DISTINCT gympokemon.pokemon_uid, "
504
-				. "pokemon_id, iv_attack, iv_defense, iv_stamina, MAX(cp) as cp, gymmember.gym_id "
505
-				. "FROM gympokemon inner join gymmember on gympokemon.pokemon_uid=gymmember.pokemon_uid "
506
-				. "GROUP BY gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, gym_id"
507
-				. " HAVING gymmember.gym_id='".$gym_id."' ORDER BY cp DESC";
508
-		$result 	= $mysqli->query($req);
509
-		$i=0;
502
+			//print_r($gymData);
503
+			$req 		= "SELECT DISTINCT gympokemon.pokemon_uid, "
504
+					. "pokemon_id, iv_attack, iv_defense, iv_stamina, MAX(cp) as cp, gymmember.gym_id "
505
+					. "FROM gympokemon inner join gymmember on gympokemon.pokemon_uid=gymmember.pokemon_uid "
506
+					. "GROUP BY gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, gym_id"
507
+					. " HAVING gymmember.gym_id='".$gym_id."' ORDER BY cp DESC";
508
+			$result 	= $mysqli->query($req);
509
+			$i=0;
510 510
 
511 511
 
512 512
 
513
-		$gymData['infoWindow'] = '
513
+			$gymData['infoWindow'] = '
514 514
 			<div class="gym_defenders">
515 515
 			';
516
-		while ($data = $result->fetch_object()) {
517
-			$gymData['gymDetails']['pokemons'][] = $data;
518
-			if ($data != false) {
519
-				if ($config->system->iv_numbers) {
520
-					$gymData['infoWindow'] .= '
516
+			while ($data = $result->fetch_object()) {
517
+				$gymData['gymDetails']['pokemons'][] = $data;
518
+				if ($data != false) {
519
+					if ($config->system->iv_numbers) {
520
+						$gymData['infoWindow'] .= '
521 521
 					<div style="text-align: center; width: 50px; display: inline-block; margin-right: 3px">
522 522
 						<a href="pokemon/'.$data->pokemon_id.'">
523 523
 						<img src="core/pokemons/'.$data->pokemon_id.$config->system->pokeimg_suffix.'" height="50" style="display:inline-block" >
@@ -535,8 +535,8 @@  discard block
 block discarded – undo
535 535
 								</div>
536 536
 							</div>
537 537
 						</div>';
538
-				} else {
539
-					$gymData['infoWindow'] .= '
538
+					} else {
539
+						$gymData['infoWindow'] .= '
540 540
 					<div style="text-align: center; width: 50px; display: inline-block; margin-right: 3px">
541 541
 						<a href="pokemon/'.$data->pokemon_id.'">
542 542
 						<img src="core/pokemons/'.$data->pokemon_id.$config->system->pokeimg_suffix.'" height="50" style="display:inline-block" >
@@ -554,50 +554,50 @@  discard block
 block discarded – undo
554 554
 							</div>
555 555
 						</div>
556 556
 					</div>'
557
-						; }
558
-			} else {
559
-				$gymData['infoWindow'] .= '
557
+							; }
558
+				} else {
559
+					$gymData['infoWindow'] .= '
560 560
 				<div style="text-align: center; width: 50px; display: inline-block; margin-right: 3px">
561 561
 					<a href="pokemon/'.$gymData['gymDetails']['gymInfos']['guardPokemonId'].'">
562 562
 					<img src="core/pokemons/'.$gymData['gymDetails']['gymInfos']['guardPokemonId'].$config->system->pokeimg_suffix.'" height="50" style="display:inline-block" >
563 563
 					</a>
564 564
 					<p class="pkmn-name">???</p>
565 565
 				</div>'
566
-				;
566
+					;
567
+				}
568
+				$i++;
567 569
 			}
568
-			$i++;
569
-		}
570
-		$gymData['infoWindow'] = $gymData['infoWindow'].'</div>';
571
-		$return = json_encode($gymData);
570
+			$gymData['infoWindow'] = $gymData['infoWindow'].'</div>';
571
+			$return = json_encode($gymData);
572 572
 
573
-		echo $return;
573
+			echo $return;
574 574
 
575 575
 
576
-		break;
576
+			break;
577 577
 
578
-	case 'trainer':
579
-		$name = "";
580
-		$page = "0";
581
-		$where = "";
582
-		$order="";
583
-		$team=0;
584
-		$ranking=0;
585
-		if (isset($_GET['name'])) {
586
-			$trainer_name = mysqli_real_escape_string($mysqli, $_GET['name']);
587
-			$where = " HAVING name LIKE '%".$trainer_name."%'";
588
-		}
589
-		if (isset($_GET['team']) && $_GET['team']!=0) {
590
-			$team = mysqli_real_escape_string($mysqli, $_GET['team']);
591
-			$where .= ($where==""?" HAVING":"AND ")." team = ".$team;
592
-		}
593
-		if (isset($_GET['page'])) {
594
-			$page = mysqli_real_escape_string($mysqli, $_GET['page']);
595
-		}
596
-		if (isset($_GET['ranking'])) {
597
-			$ranking = mysqli_real_escape_string($mysqli, $_GET['ranking']);
598
-		}
578
+		case 'trainer':
579
+			$name = "";
580
+			$page = "0";
581
+			$where = "";
582
+			$order="";
583
+			$team=0;
584
+			$ranking=0;
585
+			if (isset($_GET['name'])) {
586
+				$trainer_name = mysqli_real_escape_string($mysqli, $_GET['name']);
587
+				$where = " HAVING name LIKE '%".$trainer_name."%'";
588
+			}
589
+			if (isset($_GET['team']) && $_GET['team']!=0) {
590
+				$team = mysqli_real_escape_string($mysqli, $_GET['team']);
591
+				$where .= ($where==""?" HAVING":"AND ")." team = ".$team;
592
+			}
593
+			if (isset($_GET['page'])) {
594
+				$page = mysqli_real_escape_string($mysqli, $_GET['page']);
595
+			}
596
+			if (isset($_GET['ranking'])) {
597
+				$ranking = mysqli_real_escape_string($mysqli, $_GET['ranking']);
598
+			}
599 599
 
600
-		switch ($ranking) {
600
+			switch ($ranking) {
601 601
 			case 1:
602 602
 				$order=" ORDER BY active DESC ";
603 603
 				break;
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
 				break;
607 607
 			default:
608 608
 				$order=" ORDER BY level DESC, active DESC ";
609
-		}
609
+			}
610 610
 
611 611
 		$limit = " LIMIT ".($page*10).",10 ";
612 612
 
@@ -673,98 +673,98 @@  discard block
 block discarded – undo
673 673
 
674 674
 		break;
675 675
 
676
-	case 'pokemon_slider_init':
677
-		$req 		= "SELECT MIN(pokemon.disappear_time) as min, MAX(pokemon.disappear_time) as max from pokemon";
678
-		$result 	= $mysqli->query($req);
679
-		$data 		= $result->fetch_object();
680
-		$bounds 	= $data;
676
+		case 'pokemon_slider_init':
677
+			$req 		= "SELECT MIN(pokemon.disappear_time) as min, MAX(pokemon.disappear_time) as max from pokemon";
678
+			$result 	= $mysqli->query($req);
679
+			$data 		= $result->fetch_object();
680
+			$bounds 	= $data;
681 681
 
682
-		header('Content-Type: application/json');
683
-		$json = json_encode($bounds);
682
+			header('Content-Type: application/json');
683
+			$json = json_encode($bounds);
684 684
 
685
-		echo $json;
686
-		break;
685
+			echo $json;
686
+			break;
687 687
 
688
-	case 'pokemon_heatmap_points':
689
-		$json="";
690
-		if (isset($_GET['start'])&&isset($_GET['end']) && isset($_GET['pokemon_id'])) {
691
-			$start = Date("Y-m-d H:i",(int)$_GET['start']);
692
-			$end = Date("Y-m-d H:i",(int)$_GET['end']);
693
-			$pokemon_id = mysqli_real_escape_string($mysqli, $_GET['pokemon_id']);
694
-			$where = " WHERE pokemon.pokemon_id = ".$pokemon_id." "
695
-					. "AND pokemon.disappear_time BETWEEN '".$start."' AND '".$end."'";
696
-			$req 		= "SELECT latitude, longitude FROM pokemon".$where." ORDER BY disappear_time DESC LIMIT 10000";
697
-			$result 	= $mysqli->query($req);
698
-			$points = array();
699
-			while ($result && $data = $result->fetch_object()) {
700
-				$points[] 	= $data;
688
+		case 'pokemon_heatmap_points':
689
+			$json="";
690
+			if (isset($_GET['start'])&&isset($_GET['end']) && isset($_GET['pokemon_id'])) {
691
+				$start = Date("Y-m-d H:i",(int)$_GET['start']);
692
+				$end = Date("Y-m-d H:i",(int)$_GET['end']);
693
+				$pokemon_id = mysqli_real_escape_string($mysqli, $_GET['pokemon_id']);
694
+				$where = " WHERE pokemon.pokemon_id = ".$pokemon_id." "
695
+						. "AND pokemon.disappear_time BETWEEN '".$start."' AND '".$end."'";
696
+				$req 		= "SELECT latitude, longitude FROM pokemon".$where." ORDER BY disappear_time DESC LIMIT 10000";
697
+				$result 	= $mysqli->query($req);
698
+				$points = array();
699
+				while ($result && $data = $result->fetch_object()) {
700
+					$points[] 	= $data;
701
+				}
702
+
703
+				$json = json_encode($points);
701 704
 			}
702 705
 
703
-			$json = json_encode($points);
704
-		}
706
+			header('Content-Type: application/json');
705 707
 
706
-		header('Content-Type: application/json');
708
+			echo $json;
707 709
 
708
-		echo $json;
710
+			break;
709 711
 
710
-		break;
712
+		case 'pokedex':
713
+			$json="";
714
+			if (isset($_GET['pokemon_id'])) {
715
+				$pokemon_id = mysqli_real_escape_string($mysqli, $_GET['pokemon_id']);
716
+				$where = " WHERE pokemon.pokemon_id = ".$pokemon_id;
717
+				$req 		= "SELECT COUNT(encounter_id) as total FROM pokemon".$where;
718
+				$result 	= $mysqli->query($req);
719
+				$total = 0;
720
+				while ($result && $data = $result->fetch_object()) {
721
+					$total 	= $data;
722
+				}
711 723
 
712
-	case 'pokedex':
713
-		$json="";
714
-		if (isset($_GET['pokemon_id'])) {
715
-			$pokemon_id = mysqli_real_escape_string($mysqli, $_GET['pokemon_id']);
716
-			$where = " WHERE pokemon.pokemon_id = ".$pokemon_id;
717
-			$req 		= "SELECT COUNT(encounter_id) as total FROM pokemon".$where;
718
-			$result 	= $mysqli->query($req);
719
-			$total = 0;
720
-			while ($result && $data = $result->fetch_object()) {
721
-				$total 	= $data;
724
+				$json = json_encode($total);
722 725
 			}
723 726
 
724
-			$json = json_encode($total);
725
-		}
726
-
727
-		header('Content-Type: application/json');
727
+			header('Content-Type: application/json');
728 728
 
729
-		echo $json;
729
+			echo $json;
730 730
 
731
-		break;
731
+			break;
732 732
 
733
-	case 'pokemon_graph_data':
734
-		$json="";
735
-		if (isset($_GET['pokemon_id'])) {
736
-			$pokemon_id = mysqli_real_escape_string($mysqli, $_GET['pokemon_id']);
737
-			$req 		= "SELECT COUNT(*) as total, "
738
-					. "HOUR(CONVERT_TZ(disappear_time, '+00:00', '".$time_offset."')) as disappear_hour
733
+		case 'pokemon_graph_data':
734
+			$json="";
735
+			if (isset($_GET['pokemon_id'])) {
736
+				$pokemon_id = mysqli_real_escape_string($mysqli, $_GET['pokemon_id']);
737
+				$req 		= "SELECT COUNT(*) as total, "
738
+						. "HOUR(CONVERT_TZ(disappear_time, '+00:00', '".$time_offset."')) as disappear_hour
739 739
 			FROM (SELECT disappear_time FROM pokemon WHERE pokemon_id = '".$pokemon_id."' LIMIT 10000) as pokemonFiltered
740 740
 			GROUP BY disappear_hour
741 741
 			ORDER BY disappear_hour";
742
-			$result 	= $mysqli->query($req);
743
-			$array = array_fill(0, 24, 0);
744
-			while ($result && $data = $result->fetch_object()) {
745
-				$array[$data->disappear_hour] = $data->total;
746
-			}
747
-			// shift array because AM/PM starts at 1AM not 0:00
748
-			$array[] = $array[0];
749
-			array_shift($array);
742
+				$result 	= $mysqli->query($req);
743
+				$array = array_fill(0, 24, 0);
744
+				while ($result && $data = $result->fetch_object()) {
745
+					$array[$data->disappear_hour] = $data->total;
746
+				}
747
+				// shift array because AM/PM starts at 1AM not 0:00
748
+				$array[] = $array[0];
749
+				array_shift($array);
750 750
 
751
-			$json = json_encode($array);
752
-		}
751
+				$json = json_encode($array);
752
+			}
753 753
 
754
-		header('Content-Type: application/json');
754
+			header('Content-Type: application/json');
755 755
 
756
-		echo $json;
756
+			echo $json;
757 757
 
758
-		break;
758
+			break;
759 759
 
760
-	case 'postRequest':
761
-		break;
760
+		case 'postRequest':
761
+			break;
762 762
 
763
-	default:
764
-		echo "What do you mean?";
765
-		exit();
763
+		default:
764
+			echo "What do you mean?";
765
+			exit();
766 766
 
767
-	break;
767
+		break;
768 768
 }
769 769
 if ($postRequest!="") {
770 770
 	switch ($postRequest) {
Please login to merge, or discard this patch.