Passed
Pull Request — master (#192)
by PoUpA
02:32
created
core/process/aru.php 1 patch
Switch Indentation   +340 added lines, -340 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="Attack IV: '. $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">Attack IV: '. $iv->attack .'</span>'. $iv->attack .'
@@ -213,8 +213,8 @@  discard block
 block discarded – undo
213 213
 									<span class="sr-only">Stamina IV: '. $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="Attack IV: '. $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">Attack IV: '. $iv->attack .'</span>
@@ -226,10 +226,10 @@  discard block
 block discarded – undo
226 226
 									<span class="sr-only">Stamina IV: '. $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="Attack IV: 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">Attack IV: not available</span>?
@@ -241,125 +241,125 @@  discard block
 block discarded – undo
241 241
 									<span class="sr-only">Stamina IV: 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 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;
265
+			header('Content-Type: application/json');
266
+			echo json_encode($total_spawns);
267
+			break;
268 268
 
269 269
 
270 270
 
271
-	####################################
272
-	//
273
-	// List Pokestop
274
-	//
275
-	####################################
271
+		####################################
272
+		//
273
+		// List Pokestop
274
+		//
275
+		####################################
276 276
 
277
-	case 'pokestop':
278
-		$req 		= "SELECT latitude, longitude, lure_expiration, UTC_TIMESTAMP() as now, (CONVERT_TZ(lure_expiration, '+00:00', '".$time_offset."')) as lure_expiration_real FROM pokestop";
279
-		$result 	= $mysqli->query($req);
277
+		case 'pokestop':
278
+			$req 		= "SELECT latitude, longitude, lure_expiration, UTC_TIMESTAMP() as now, (CONVERT_TZ(lure_expiration, '+00:00', '".$time_offset."')) as lure_expiration_real FROM pokestop";
279
+			$result 	= $mysqli->query($req);
280 280
 
281
-		$i=0;
281
+			$i=0;
282 282
 
283
-		while ($data = $result->fetch_object()) {
284
-			if ($data->lure_expiration >= $data->now) {
285
-				$icon = 'pokestap_lured.png';
286
-				$text = 'Lured expire @ '.date('H:i:s', strtotime($data->lure_expiration_real)) ;
287
-			} else {
288
-				$icon = 'pokestap.png';
289
-				$text = 'Normal stop';
290
-			}
283
+			while ($data = $result->fetch_object()) {
284
+				if ($data->lure_expiration >= $data->now) {
285
+					$icon = 'pokestap_lured.png';
286
+					$text = 'Lured expire @ '.date('H:i:s', strtotime($data->lure_expiration_real)) ;
287
+				} else {
288
+					$icon = 'pokestap.png';
289
+					$text = 'Normal stop';
290
+				}
291 291
 
292
-			$temp[$i][] = $text;
293
-			$temp[$i][] = $icon;
294
-			$temp[$i][] = $data->latitude;
295
-			$temp[$i][] = $data->longitude;
296
-			$temp[$i][] = $i;
292
+				$temp[$i][] = $text;
293
+				$temp[$i][] = $icon;
294
+				$temp[$i][] = $data->latitude;
295
+				$temp[$i][] = $data->longitude;
296
+				$temp[$i][] = $i;
297 297
 
298
-			$temp_json[] = json_encode($temp[$i]);
298
+				$temp_json[] = json_encode($temp[$i]);
299 299
 
300 300
 
301
-			$i++;
302
-		}
301
+				$i++;
302
+			}
303 303
 
304
-		$return = json_encode($temp_json);
304
+			$return = json_encode($temp_json);
305 305
 
306
-		echo $return;
306
+			echo $return;
307 307
 
308
-		break;
308
+			break;
309 309
 
310 310
 
311 311
 
312
-	####################################
313
-	//
314
-	// Update data for the gym battle
315
-	//
316
-	####################################
312
+		####################################
313
+		//
314
+		// Update data for the gym battle
315
+		//
316
+		####################################
317 317
 
318
-	case 'update_gym':
319
-		$teams			= new stdClass();
320
-		$teams->mystic 		= 1;
321
-		$teams->valor 		= 2;
322
-		$teams->instinct 	= 3;
318
+		case 'update_gym':
319
+			$teams			= new stdClass();
320
+			$teams->mystic 		= 1;
321
+			$teams->valor 		= 2;
322
+			$teams->instinct 	= 3;
323 323
 
324 324
 
325
-		foreach ($teams as $team_name => $team_id) {
326
-			$req	= "SELECT COUNT(DISTINCT(gym_id)) as total, ROUND(AVG(gym_points),0) as average_points FROM gym WHERE team_id = '".$team_id."'  ";
327
-			$result	= $mysqli->query($req);
328
-			$data	= $result->fetch_object();
325
+			foreach ($teams as $team_name => $team_id) {
326
+				$req	= "SELECT COUNT(DISTINCT(gym_id)) as total, ROUND(AVG(gym_points),0) as average_points FROM gym WHERE team_id = '".$team_id."'  ";
327
+				$result	= $mysqli->query($req);
328
+				$data	= $result->fetch_object();
329 329
 
330
-			$return[] 	= $data->total;
331
-			$return[]	= $data->average_points;
332
-		}
330
+				$return[] 	= $data->total;
331
+				$return[]	= $data->average_points;
332
+			}
333 333
 
334
-		$json = json_encode($return);
334
+			$json = json_encode($return);
335 335
 
336
-		header('Content-Type: application/json');
337
-		echo $json;
336
+			header('Content-Type: application/json');
337
+			echo $json;
338 338
 
339 339
 
340
-		break;
340
+			break;
341 341
 
342
-	####################################
343
-	//
344
-	// Get datas for the gym map
345
-	//
346
-	####################################
342
+		####################################
343
+		//
344
+		// Get datas for the gym map
345
+		//
346
+		####################################
347 347
 
348 348
 
349
-	case 'gym_map':
350
-		$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";
351
-		$result 	= $mysqli->query($req);
349
+		case 'gym_map':
350
+			$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";
351
+			$result 	= $mysqli->query($req);
352 352
 
353 353
 
354
-		$i=0;
354
+			$i=0;
355 355
 
356
-		while ($data = $result->fetch_object()) {
357
-			// Team
358
-			// 1 = bleu
359
-			// 2 = rouge
360
-			// 3 = jaune
356
+			while ($data = $result->fetch_object()) {
357
+				// Team
358
+				// 1 = bleu
359
+				// 2 = rouge
360
+				// 3 = jaune
361 361
 
362
-			switch ($data->team_id) {
362
+				switch ($data->team_id) {
363 363
 				case 0:
364 364
 					$icon	= 'map_white.png';
365 365
 					$team	= 'No Team (yet)';
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 					$team	= 'Team Instinct';
384 384
 					$color	= 'rgba(254, 217, 40, .6)';
385 385
 					break;
386
-			}
386
+				}
387 387
 
388 388
 			// Set gym level
389 389
 			$data->gym_level=0;
@@ -455,65 +455,65 @@  discard block
 block discarded – undo
455 455
 	//
456 456
 	####################################
457 457
 
458
-	case 'gym_defenders':
459
-		$gym_id = $mysqli->real_escape_string($_GET['gym_id']);
460
-		$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."'";
461
-		$result 	= $mysqli->query($req);
462
-		$gymData['gymDetails']['gymInfos'] = false;
463
-		while ($data = $result->fetch_object()) {
464
-			$gymData['gymDetails']['gymInfos']['name'] = $data->name;
465
-			$gymData['gymDetails']['gymInfos']['description'] = $data->description;
466
-			if ($data->url == null) {
467
-				$gymData['gymDetails']['gymInfos']['url'] = '';
468
-			} else {
469
-				$gymData['gymDetails']['gymInfos']['url'] = $data->url;
470
-			}
471
-			$gymData['gymDetails']['gymInfos']['points'] = $data->points;
472
-			$gymData['gymDetails']['gymInfos']['level'] = 0;
473
-			$gymData['gymDetails']['gymInfos']['last_scanned'] = $data->last_scanned;
474
-			$gymData['gymDetails']['gymInfos']['team'] = $data->team;
475
-			$gymData['gymDetails']['gymInfos']['guardPokemonId'] = $data->guard_pokemon_id;
476
-			if ($data->points < 2000) {
477
-				$gymData['gymDetails']['gymInfos']['level']=1;
478
-			} elseif ($data->points < 4000) {
479
-				$gymData['gymDetails']['gymInfos']['level']=2;
480
-			} elseif ($data->points < 8000) {
481
-				$gymData['gymDetails']['gymInfos']['level']=3;
482
-			} elseif ($data->points < 12000) {
483
-				$gymData['gymDetails']['gymInfos']['level']=4;
484
-			} elseif ($data->points < 16000) {
485
-				$gymData['gymDetails']['gymInfos']['level']=5;
486
-			} elseif ($data->points < 20000) {
487
-				$gymData['gymDetails']['gymInfos']['level']=6;
488
-			} elseif ($data->points < 30000) {
489
-				$gymData['gymDetails']['gymInfos']['level']=7;
490
-			} elseif ($data->points < 40000) {
491
-				$gymData['gymDetails']['gymInfos']['level']=8;
492
-			} elseif ($data->points < 50000) {
493
-				$gymData['gymDetails']['gymInfos']['level']=9;
494
-			} else {
495
-				$gymData['gymDetails']['gymInfos']['level']=10;
458
+		case 'gym_defenders':
459
+			$gym_id = $mysqli->real_escape_string($_GET['gym_id']);
460
+			$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."'";
461
+			$result 	= $mysqli->query($req);
462
+			$gymData['gymDetails']['gymInfos'] = false;
463
+			while ($data = $result->fetch_object()) {
464
+				$gymData['gymDetails']['gymInfos']['name'] = $data->name;
465
+				$gymData['gymDetails']['gymInfos']['description'] = $data->description;
466
+				if ($data->url == null) {
467
+					$gymData['gymDetails']['gymInfos']['url'] = '';
468
+				} else {
469
+					$gymData['gymDetails']['gymInfos']['url'] = $data->url;
470
+				}
471
+				$gymData['gymDetails']['gymInfos']['points'] = $data->points;
472
+				$gymData['gymDetails']['gymInfos']['level'] = 0;
473
+				$gymData['gymDetails']['gymInfos']['last_scanned'] = $data->last_scanned;
474
+				$gymData['gymDetails']['gymInfos']['team'] = $data->team;
475
+				$gymData['gymDetails']['gymInfos']['guardPokemonId'] = $data->guard_pokemon_id;
476
+				if ($data->points < 2000) {
477
+					$gymData['gymDetails']['gymInfos']['level']=1;
478
+				} elseif ($data->points < 4000) {
479
+					$gymData['gymDetails']['gymInfos']['level']=2;
480
+				} elseif ($data->points < 8000) {
481
+					$gymData['gymDetails']['gymInfos']['level']=3;
482
+				} elseif ($data->points < 12000) {
483
+					$gymData['gymDetails']['gymInfos']['level']=4;
484
+				} elseif ($data->points < 16000) {
485
+					$gymData['gymDetails']['gymInfos']['level']=5;
486
+				} elseif ($data->points < 20000) {
487
+					$gymData['gymDetails']['gymInfos']['level']=6;
488
+				} elseif ($data->points < 30000) {
489
+					$gymData['gymDetails']['gymInfos']['level']=7;
490
+				} elseif ($data->points < 40000) {
491
+					$gymData['gymDetails']['gymInfos']['level']=8;
492
+				} elseif ($data->points < 50000) {
493
+					$gymData['gymDetails']['gymInfos']['level']=9;
494
+				} else {
495
+					$gymData['gymDetails']['gymInfos']['level']=10;
496
+				}
496 497
 			}
497
-		}
498
-		//print_r($gymData);
499
-		$req 		= "SELECT DISTINCT gympokemon.pokemon_uid, "
500
-				. "pokemon_id, iv_attack, iv_defense, iv_stamina, MAX(cp) as cp, gymmember.gym_id "
501
-				. "FROM gympokemon inner join gymmember on gympokemon.pokemon_uid=gymmember.pokemon_uid "
502
-				. "GROUP BY gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, gym_id"
503
-				. " HAVING gymmember.gym_id='".$gym_id."' ORDER BY cp DESC";
504
-		$result 	= $mysqli->query($req);
505
-		$i=0;
498
+			//print_r($gymData);
499
+			$req 		= "SELECT DISTINCT gympokemon.pokemon_uid, "
500
+					. "pokemon_id, iv_attack, iv_defense, iv_stamina, MAX(cp) as cp, gymmember.gym_id "
501
+					. "FROM gympokemon inner join gymmember on gympokemon.pokemon_uid=gymmember.pokemon_uid "
502
+					. "GROUP BY gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, gym_id"
503
+					. " HAVING gymmember.gym_id='".$gym_id."' ORDER BY cp DESC";
504
+			$result 	= $mysqli->query($req);
505
+			$i=0;
506 506
 
507 507
 
508 508
 
509
-		$gymData['infoWindow'] = '
509
+			$gymData['infoWindow'] = '
510 510
 			<div class="gym_defenders">
511 511
 			';
512
-		while ($data = $result->fetch_object()) {
513
-			$gymData['gymDetails']['pokemons'][] = $data;
514
-			if ($data != false) {
515
-				if ($config->system->iv_numbers) {
516
-					$gymData['infoWindow'] .= '
512
+			while ($data = $result->fetch_object()) {
513
+				$gymData['gymDetails']['pokemons'][] = $data;
514
+				if ($data != false) {
515
+					if ($config->system->iv_numbers) {
516
+						$gymData['infoWindow'] .= '
517 517
 					<div style="text-align: center; width: 50px; display: inline-block; margin-right: 3px">
518 518
 						<a href="pokemon/'.$data->pokemon_id.'">
519 519
 						<img src="core/pokemons/'.$data->pokemon_id.$config->system->pokeimg_suffix.'" height="50" style="display:inline-block" >
@@ -531,9 +531,9 @@  discard block
 block discarded – undo
531 531
 								</div>
532 532
 							</div>
533 533
 						</div>';
534
-				}
535
-				else {
536
-					$gymData['infoWindow'] .= '
534
+					}
535
+					else {
536
+						$gymData['infoWindow'] .= '
537 537
 					<div style="text-align: center; width: 50px; display: inline-block; margin-right: 3px">
538 538
 						<a href="pokemon/'.$data->pokemon_id.'">
539 539
 						<img src="core/pokemons/'.$data->pokemon_id.$config->system->pokeimg_suffix.'" height="50" style="display:inline-block" >
@@ -551,50 +551,50 @@  discard block
 block discarded – undo
551 551
 							</div>
552 552
 						</div>
553 553
 					</div>'
554
-						; }
555
-			} else {
556
-				$gymData['infoWindow'] .= '
554
+							; }
555
+				} else {
556
+					$gymData['infoWindow'] .= '
557 557
 				<div style="text-align: center; width: 50px; display: inline-block; margin-right: 3px">
558 558
 					<a href="pokemon/'.$gymData['gymDetails']['gymInfos']['guardPokemonId'].'">
559 559
 					<img src="core/pokemons/'.$gymData['gymDetails']['gymInfos']['guardPokemonId'].$config->system->pokeimg_suffix.'" height="50" style="display:inline-block" >
560 560
 					</a>
561 561
 					<p class="pkmn-name">???</p>
562 562
 				</div>'
563
-				;
563
+					;
564
+				}
565
+				$i++;
564 566
 			}
565
-			$i++;
566
-		}
567
-		$gymData['infoWindow'] = $gymData['infoWindow'].'</div>';
568
-		$return = json_encode($gymData);
567
+			$gymData['infoWindow'] = $gymData['infoWindow'].'</div>';
568
+			$return = json_encode($gymData);
569 569
 
570
-		echo $return;
570
+			echo $return;
571 571
 
572 572
 
573
-		break;
573
+			break;
574 574
 
575
-	case 'trainer':
576
-		$name = "";
577
-		$page = "0";
578
-		$where = "";
579
-		$order="";
580
-		$team=0;
581
-		$ranking=0;
582
-		if (isset($_GET['name'])) {
583
-			$trainer_name = mysqli_real_escape_string($mysqli, $_GET['name']);
584
-			$where = " HAVING name LIKE '%".$trainer_name."%'";
585
-		}
586
-		if (isset($_GET['team']) && $_GET['team']!=0) {
587
-			$team = mysqli_real_escape_string($mysqli, $_GET['team']);
588
-			$where .= ($where==""?" HAVING":"AND ")." team = ".$team;
589
-		}
590
-		if (isset($_GET['page'])) {
591
-			$page = mysqli_real_escape_string($mysqli, $_GET['page']);
592
-		}
593
-		if (isset($_GET['ranking'])) {
594
-			$ranking = mysqli_real_escape_string($mysqli, $_GET['ranking']);
595
-		}
575
+		case 'trainer':
576
+			$name = "";
577
+			$page = "0";
578
+			$where = "";
579
+			$order="";
580
+			$team=0;
581
+			$ranking=0;
582
+			if (isset($_GET['name'])) {
583
+				$trainer_name = mysqli_real_escape_string($mysqli, $_GET['name']);
584
+				$where = " HAVING name LIKE '%".$trainer_name."%'";
585
+			}
586
+			if (isset($_GET['team']) && $_GET['team']!=0) {
587
+				$team = mysqli_real_escape_string($mysqli, $_GET['team']);
588
+				$where .= ($where==""?" HAVING":"AND ")." team = ".$team;
589
+			}
590
+			if (isset($_GET['page'])) {
591
+				$page = mysqli_real_escape_string($mysqli, $_GET['page']);
592
+			}
593
+			if (isset($_GET['ranking'])) {
594
+				$ranking = mysqli_real_escape_string($mysqli, $_GET['ranking']);
595
+			}
596 596
 
597
-		switch ($ranking) {
597
+			switch ($ranking) {
598 598
 			case 1:
599 599
 				$order=" ORDER BY active DESC ";
600 600
 				break;
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
 				break;
604 604
 			default:
605 605
 				$order=" ORDER BY level DESC, active DESC ";
606
-		}
606
+			}
607 607
 
608 608
 		$limit = " LIMIT ".($page*10).",10 ";
609 609
 
@@ -660,100 +660,100 @@  discard block
 block discarded – undo
660 660
 
661 661
 		break;
662 662
 
663
-	case 'pokemon_slider_init':
664
-		$req 		= "SELECT MIN(pokemon.disappear_time) as min, MAX(pokemon.disappear_time) as max from pokemon";
665
-		$result 	= $mysqli->query($req);
666
-		$data 		= $result->fetch_object();
667
-		$bounds 	= $data;
663
+		case 'pokemon_slider_init':
664
+			$req 		= "SELECT MIN(pokemon.disappear_time) as min, MAX(pokemon.disappear_time) as max from pokemon";
665
+			$result 	= $mysqli->query($req);
666
+			$data 		= $result->fetch_object();
667
+			$bounds 	= $data;
668 668
 
669
-		header('Content-Type: application/json');
670
-		$json = json_encode($bounds);
669
+			header('Content-Type: application/json');
670
+			$json = json_encode($bounds);
671 671
 
672
-		echo $json;
673
-		break;
672
+			echo $json;
673
+			break;
674 674
 
675
-	case 'pokemon_heatmap_points':
676
-		$json="";
677
-		if (isset($_GET['start'])&&isset($_GET['end']) && isset($_GET['pokemon_id'])) {
678
-			$start = Date("Y-m-d H:i",(int)$_GET['start']);
679
-			$end = Date("Y-m-d H:i",(int)$_GET['end']);
680
-			$pokemon_id = mysqli_real_escape_string($mysqli, $_GET['pokemon_id']);
681
-			$where = " WHERE pokemon.pokemon_id = ".$pokemon_id." "
682
-					. "AND pokemon.disappear_time BETWEEN '".$start."' AND '".$end."'";
683
-			$req 		= "SELECT latitude, longitude FROM pokemon".$where." ORDER BY disappear_time DESC LIMIT 10000";
684
-			$result 	= $mysqli->query($req);
685
-			$points = array();
686
-			while ($result && $data = $result->fetch_object()) {
687
-				$points[] 	= $data;
675
+		case 'pokemon_heatmap_points':
676
+			$json="";
677
+			if (isset($_GET['start'])&&isset($_GET['end']) && isset($_GET['pokemon_id'])) {
678
+				$start = Date("Y-m-d H:i",(int)$_GET['start']);
679
+				$end = Date("Y-m-d H:i",(int)$_GET['end']);
680
+				$pokemon_id = mysqli_real_escape_string($mysqli, $_GET['pokemon_id']);
681
+				$where = " WHERE pokemon.pokemon_id = ".$pokemon_id." "
682
+						. "AND pokemon.disappear_time BETWEEN '".$start."' AND '".$end."'";
683
+				$req 		= "SELECT latitude, longitude FROM pokemon".$where." ORDER BY disappear_time DESC LIMIT 10000";
684
+				$result 	= $mysqli->query($req);
685
+				$points = array();
686
+				while ($result && $data = $result->fetch_object()) {
687
+					$points[] 	= $data;
688
+				}
689
+
690
+				$json = json_encode($points);
688 691
 			}
689 692
 
690
-			$json = json_encode($points);
691
-		}
693
+			header('Content-Type: application/json');
692 694
 
693
-		header('Content-Type: application/json');
695
+			echo $json;
694 696
 
695
-		echo $json;
697
+			break;
696 698
 
697
-		break;
699
+		case 'pokedex':
700
+			$json="";
701
+			if (isset($_GET['pokemon_id'])) {
702
+				$pokemon_id = mysqli_real_escape_string($mysqli, $_GET['pokemon_id']);
703
+				$where = " WHERE pokemon.pokemon_id = ".$pokemon_id;
704
+				$req 		= "SELECT COUNT(encounter_id) as total FROM pokemon".$where;
705
+				$result 	= $mysqli->query($req);
706
+				$total = 0;
707
+				while ($result && $data = $result->fetch_object()) {
708
+					$total 	= $data;
709
+				}
698 710
 
699
-	case 'pokedex':
700
-		$json="";
701
-		if (isset($_GET['pokemon_id'])) {
702
-			$pokemon_id = mysqli_real_escape_string($mysqli, $_GET['pokemon_id']);
703
-			$where = " WHERE pokemon.pokemon_id = ".$pokemon_id;
704
-			$req 		= "SELECT COUNT(encounter_id) as total FROM pokemon".$where;
705
-			$result 	= $mysqli->query($req);
706
-			$total = 0;
707
-			while ($result && $data = $result->fetch_object()) {
708
-				$total 	= $data;
711
+				$json = json_encode($total);
709 712
 			}
710 713
 
711
-			$json = json_encode($total);
712
-		}
713
-
714
-		header('Content-Type: application/json');
714
+			header('Content-Type: application/json');
715 715
 
716
-		echo $json;
716
+			echo $json;
717 717
 
718
-		break;
718
+			break;
719 719
 
720 720
 		case 'postRequest':
721 721
 		break;
722 722
 
723
-	case 'pokemon_graph_data':
724
-		$json="";
725
-		if (isset($_GET['pokemon_id'])) {
726
-			$pokemon_id = mysqli_real_escape_string($mysqli, $_GET['pokemon_id']);
727
-			$where = " WHERE pokemonFiltered.pokemon_id = ".$pokemon_id;
728
-			$req 		= "SELECT COUNT(*) as total, "
729
-					. "HOUR(CONVERT_TZ(disappear_time, '+00:00', '".$time_offset."')) as disappear_hour
723
+		case 'pokemon_graph_data':
724
+			$json="";
725
+			if (isset($_GET['pokemon_id'])) {
726
+				$pokemon_id = mysqli_real_escape_string($mysqli, $_GET['pokemon_id']);
727
+				$where = " WHERE pokemonFiltered.pokemon_id = ".$pokemon_id;
728
+				$req 		= "SELECT COUNT(*) as total, "
729
+						. "HOUR(CONVERT_TZ(disappear_time, '+00:00', '".$time_offset."')) as disappear_hour
730 730
 			FROM (SELECT * FROM pokemon WHERE pokemon_id = '".$pokemon_id."' LIMIT 10000) as pokemonFiltered
731 731
 			GROUP BY disappear_hour
732 732
 			ORDER BY disappear_hour";
733
-			$result 	= $mysqli->query($req);
734
-			$array = array();
735
-			while ($result && $data = $result->fetch_object()) {
736
-				$array[] = $data->total;
733
+				$result 	= $mysqli->query($req);
734
+				$array = array();
735
+				while ($result && $data = $result->fetch_object()) {
736
+					$array[] = $data->total;
737
+				}
738
+				$array[] = array_shift($array);
739
+				$json = json_encode($array);
737 740
 			}
738
-			$array[] = array_shift($array);
739
-			$json = json_encode($array);
740
-		}
741 741
 
742
-		header('Content-Type: application/json');
742
+			header('Content-Type: application/json');
743 743
 
744
-		echo $json;
744
+			echo $json;
745 745
 
746
-		break;
746
+			break;
747 747
 
748 748
 		case 'postRequest':
749 749
 		break;
750 750
 
751 751
 
752
-	default:
753
-		echo "What do you mean?";
754
-		exit();
752
+		default:
753
+			echo "What do you mean?";
754
+			exit();
755 755
 
756
-	break;
756
+		break;
757 757
 }
758 758
 if ($postRequest!=""){
759 759
 	switch ($postRequest) {
Please login to merge, or discard this patch.