Completed
Push — master ( 4ef644...1a000c )
by Yannick
37:19
created
require/class.SpotterLive.php 1 patch
Braces   +161 added lines, -54 removed lines patch added patch discarded remove patch
@@ -8,7 +8,9 @@  discard block
 block discarded – undo
8 8
 	public function __construct($dbc = null) {
9 9
 		$Connection = new Connection($dbc);
10 10
 		$this->db = $Connection->db();
11
-		if ($this->db === null) die('Error: No DB connection. (SpotterLive)');
11
+		if ($this->db === null) {
12
+			die('Error: No DB connection. (SpotterLive)');
13
+		}
12 14
 	}
13 15
 
14 16
 
@@ -30,7 +32,9 @@  discard block
 block discarded – undo
30 32
 		if (isset($filter[0]['source'])) {
31 33
 			$filters = array_merge($filters,$filter);
32 34
 		}
33
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
35
+		if (is_array($globalFilter)) {
36
+			$filter = array_merge($filter,$globalFilter);
37
+		}
34 38
 		$filter_query_join = '';
35 39
 		$filter_query_where = '';
36 40
 		foreach($filters as $flt) {
@@ -129,8 +133,11 @@  discard block
 block discarded – undo
129 133
 		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
130 134
 			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
131 135
 		}
132
-		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
133
-		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
136
+		if ($filter_query_where == '' && $where) {
137
+			$filter_query_where = ' WHERE';
138
+		} elseif ($filter_query_where != '' && $and) {
139
+			$filter_query_where .= ' AND';
140
+		}
134 141
 		if ($filter_query_where != '') {
135 142
 			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
136 143
 		}
@@ -171,9 +178,13 @@  discard block
 block discarded – undo
171 178
 				$orderby_query = ' '.$search_orderby_array[$sort]['sql'];
172 179
 			}
173 180
 		}
174
-		if ($orderby_query == '') $orderby_query = ' ORDER BY date DESC';
181
+		if ($orderby_query == '') {
182
+			$orderby_query = ' ORDER BY date DESC';
183
+		}
175 184
 
176
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
185
+		if (!isset($globalLiveInterval)) {
186
+			$globalLiveInterval = '200';
187
+		}
177 188
 		if ($globalDBdriver == 'mysql') {
178 189
 			//$query  = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate";
179 190
 			$query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query.$orderby_query;
@@ -196,7 +207,9 @@  discard block
 block discarded – undo
196 207
 		global $globalDBdriver, $globalLiveInterval, $globalArchive, $globalMap2DAircraftsLimit;
197 208
 		date_default_timezone_set('UTC');
198 209
 		$filter_query = $this->getFilter($filter,true,true);
199
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
210
+		if (!isset($globalLiveInterval)) {
211
+			$globalLiveInterval = '200';
212
+		}
200 213
 		if ($globalDBdriver == 'mysql') {
201 214
 			if (isset($globalArchive) && $globalArchive === TRUE) {
202 215
 			//	$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
@@ -258,8 +271,12 @@  discard block
 block discarded – undo
258 271
 		$id = filter_var($id,FILTER_SANITIZE_STRING);
259 272
 		$filter_query = $this->getFilter($filter,true,true);
260 273
 
261
-		if (!isset($globalLiveInterval) || $globalLiveInterval == '') $globalLiveInterval = '200';
262
-		if (!isset($globalMap3DAircraftsLimit) || $globalMap3DAircraftsLimit == '') $globalMap3DAircraftsLimit = '300';
274
+		if (!isset($globalLiveInterval) || $globalLiveInterval == '') {
275
+			$globalLiveInterval = '200';
276
+		}
277
+		if (!isset($globalMap3DAircraftsLimit) || $globalMap3DAircraftsLimit == '') {
278
+			$globalMap3DAircraftsLimit = '300';
279
+		}
263 280
 		if ($globalDBdriver == 'mysql') {
264 281
 			if (isset($globalArchive) && $globalArchive === TRUE) {
265 282
 				/*
@@ -270,25 +287,41 @@  discard block
 block discarded – undo
270 287
 				*/
271 288
 				$query  = 'SELECT * FROM (SELECT spotter_archive.ident, spotter_archive.flightaware_id, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, spotter_archive.date, spotter_archive.format_source, spotter_archive.registration 
272 289
 				FROM spotter_archive INNER JOIN (SELECT flightaware_id FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= spotter_live.date) l ON l.flightaware_id = spotter_archive.flightaware_id ";
273
-				if ($usecoord) $query .= "AND (spotter_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_archive.longitude BETWEEN ".$minlong." AND ".$maxlong.") ";
274
-				if ($id != '') $query .= "OR spotter_archive.flightaware_id = :id ";
290
+				if ($usecoord) {
291
+					$query .= "AND (spotter_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_archive.longitude BETWEEN ".$minlong." AND ".$maxlong.") ";
292
+				}
293
+				if ($id != '') {
294
+					$query .= "OR spotter_archive.flightaware_id = :id ";
295
+				}
275 296
 				$query .= "UNION
276 297
 				SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
277 298
 				FROM spotter_live".$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= spotter_live.date";
278
-				if ($usecoord) $query .= " AND (spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.")";
279
-				if ($id != '') $query .= " OR spotter_live.flightaware_id = :id";
299
+				if ($usecoord) {
300
+					$query .= " AND (spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.")";
301
+				}
302
+				if ($id != '') {
303
+					$query .= " OR spotter_live.flightaware_id = :id";
304
+				}
280 305
 				$query .= ") AS spotter 
281 306
 				WHERE latitude <> '0' AND longitude <> '0' 
282 307
 				ORDER BY flightaware_id, date";
283
-				if ($limit) $query .= " LIMIT ".$globalMap3DAircraftsLimit;
308
+				if ($limit) {
309
+					$query .= " LIMIT ".$globalMap3DAircraftsLimit;
310
+				}
284 311
 			} else {
285 312
 				$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
286 313
 				FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= spotter_live.date ";
287
-				if ($usecoord) $query .= "AND (spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.") ";
288
-				if ($id != '') $query .= "OR spotter_live.flightaware_id = :id ";
314
+				if ($usecoord) {
315
+					$query .= "AND (spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.") ";
316
+				}
317
+				if ($id != '') {
318
+					$query .= "OR spotter_live.flightaware_id = :id ";
319
+				}
289 320
 				$query .= "AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' 
290 321
 				ORDER BY spotter_live.flightaware_id, spotter_live.date";
291
-				if ($limit) $query .= " LIMIT ".$globalMap3DAircraftsLimit;
322
+				if ($limit) {
323
+					$query .= " LIMIT ".$globalMap3DAircraftsLimit;
324
+				}
292 325
 			}
293 326
 		} else {
294 327
 			if (isset($globalArchive) && $globalArchive === TRUE) {
@@ -305,28 +338,46 @@  discard block
 block discarded – undo
305 338
 				    SELECT flightaware_id 
306 339
 				    FROM spotter_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date";
307 340
 				$query.= ") l ON l.flightaware_id = spotter_archive.flightaware_id ";
308
-				if ($usecoord) $query .= "AND (spotter_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_archive.longitude BETWEEN ".$minlong." AND ".$maxlong.") ";
309
-				if ($id != '') $query .= "OR spotter_archive.flightaware_id = :id ";
341
+				if ($usecoord) {
342
+					$query .= "AND (spotter_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_archive.longitude BETWEEN ".$minlong." AND ".$maxlong.") ";
343
+				}
344
+				if ($id != '') {
345
+					$query .= "OR spotter_archive.flightaware_id = :id ";
346
+				}
310 347
 				$query .= "UNION
311 348
 				    SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
312 349
 				    FROM spotter_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date";
313
-				if ($usecoord) $query .= " AND (spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.")";
314
-				if ($id != '') $query .= " OR spotter_live.flightaware_id = :id";
350
+				if ($usecoord) {
351
+					$query .= " AND (spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.")";
352
+				}
353
+				if ($id != '') {
354
+					$query .= " OR spotter_live.flightaware_id = :id";
355
+				}
315 356
 				$query .= ") AS spotter WHERE latitude <> '0' AND longitude <> '0' ";
316 357
 				$query .= "ORDER BY flightaware_id, date";
317
-				if ($limit) $query .= " LIMIT ".$globalMap3DAircraftsLimit;
358
+				if ($limit) {
359
+					$query .= " LIMIT ".$globalMap3DAircraftsLimit;
360
+				}
318 361
 			} else {
319 362
 				$query  = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
320 363
 				FROM spotter_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date ";
321
-				if ($usecoord) $query .= "AND (spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.") ";
322
-				if ($id != '') $query .= "OR spotter_live.flightaware_id = :id ";
364
+				if ($usecoord) {
365
+					$query .= "AND (spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.") ";
366
+				}
367
+				if ($id != '') {
368
+					$query .= "OR spotter_live.flightaware_id = :id ";
369
+				}
323 370
 				$query .= "AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' 
324 371
 				ORDER BY spotter_live.flightaware_id, spotter_live.date";
325
-				if ($limit) $query .= " LIMIT ".$globalMap3DAircraftsLimit;
372
+				if ($limit) {
373
+					$query .= " LIMIT ".$globalMap3DAircraftsLimit;
374
+				}
326 375
 			}
327 376
 		}
328 377
 		$query_values = array();
329
-		if ($id != '') $query_values = array(':id' => $id);
378
+		if ($id != '') {
379
+			$query_values = array(':id' => $id);
380
+		}
330 381
 		try {
331 382
 			$sth = $this->db->prepare($query);
332 383
 			$sth->execute($query_values);
@@ -351,8 +402,12 @@  discard block
 block discarded – undo
351 402
 		$id = filter_var($id,FILTER_SANITIZE_STRING);
352 403
 		$filter_query = $this->getFilter($filter,true,true);
353 404
 
354
-		if (!isset($globalLiveInterval) || $globalLiveInterval == '') $globalLiveInterval = '200';
355
-		if (!isset($globalMap3DAircraftsLimit) || $globalMap3DAircraftsLimit == '') $globalMap3DAircraftsLimit = '300';
405
+		if (!isset($globalLiveInterval) || $globalLiveInterval == '') {
406
+			$globalLiveInterval = '200';
407
+		}
408
+		if (!isset($globalMap3DAircraftsLimit) || $globalMap3DAircraftsLimit == '') {
409
+			$globalMap3DAircraftsLimit = '300';
410
+		}
356 411
 		if ($globalDBdriver == 'mysql') {
357 412
 			if (isset($globalArchive) && $globalArchive === TRUE) {
358 413
 				$query  = 'SELECT * FROM (SELECT spotter_archive.ident, spotter_archive.flightaware_id, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, spotter_archive.date, spotter_archive.format_source, spotter_archive.registration 
@@ -363,13 +418,17 @@  discard block
 block discarded – undo
363 418
 				$query .= ") AS spotter 
364 419
 				WHERE latitude <> '0' AND longitude <> '0' 
365 420
 				ORDER BY flightaware_id, date";
366
-				if ($limit) $query .= " LIMIT ".$globalMap3DAircraftsLimit;
421
+				if ($limit) {
422
+					$query .= " LIMIT ".$globalMap3DAircraftsLimit;
423
+				}
367 424
 			} else {
368 425
 				$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
369 426
 				FROM spotter_live'.$filter_query.' spotter_live.flightaware_id = :id ';
370 427
 				$query .= "AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' 
371 428
 				ORDER BY spotter_live.flightaware_id, spotter_live.date";
372
-				if ($limit) $query .= " LIMIT ".$globalMap3DAircraftsLimit;
429
+				if ($limit) {
430
+					$query .= " LIMIT ".$globalMap3DAircraftsLimit;
431
+				}
373 432
 			}
374 433
 		} else {
375 434
 			if (isset($globalArchive) && $globalArchive === TRUE) {
@@ -385,13 +444,17 @@  discard block
 block discarded – undo
385 444
 				    FROM spotter_live".$filter_query." spotter_live.flightaware_id = :id";
386 445
 				$query .= ") AS spotter WHERE latitude <> '0' AND longitude <> '0' ";
387 446
 				$query .= "ORDER BY flightaware_id, date";
388
-				if ($limit) $query .= " LIMIT ".$globalMap3DAircraftsLimit;
447
+				if ($limit) {
448
+					$query .= " LIMIT ".$globalMap3DAircraftsLimit;
449
+				}
389 450
 			} else {
390 451
 				$query  = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
391 452
 				FROM spotter_live".$filter_query." spotter_live.flightaware_id = :id ";
392 453
 				$query .= "AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' 
393 454
 				ORDER BY spotter_live.flightaware_id, spotter_live.date";
394
-				if ($limit) $query .= " LIMIT ".$globalMap3DAircraftsLimit;
455
+				if ($limit) {
456
+					$query .= " LIMIT ".$globalMap3DAircraftsLimit;
457
+				}
395 458
 			}
396 459
 		}
397 460
 		$query_values = array();
@@ -418,7 +481,9 @@  discard block
 block discarded – undo
418 481
 		global $globalDBdriver, $globalLiveInterval;
419 482
 		$filter_query = $this->getFilter($filter,true,true);
420 483
 
421
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
484
+		if (!isset($globalLiveInterval)) {
485
+			$globalLiveInterval = '200';
486
+		}
422 487
 		if ($globalDBdriver == 'mysql') {
423 488
 			//$query  = 'SELECT COUNT(*) as nb FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query;
424 489
 			$query = 'SELECT COUNT(DISTINCT spotter_live.flightaware_id) as nb FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
@@ -448,7 +513,9 @@  discard block
 block discarded – undo
448 513
 	{
449 514
 		global $globalDBdriver, $globalLiveInterval;
450 515
 		$Spotter = new Spotter($this->db);
451
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
516
+		if (!isset($globalLiveInterval)) {
517
+			$globalLiveInterval = '200';
518
+		}
452 519
 		$filter_query = $this->getFilter($filter);
453 520
 
454 521
 		if (is_array($coord)) {
@@ -456,7 +523,9 @@  discard block
 block discarded – undo
456 523
 			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
457 524
 			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
458 525
 			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
459
-		} else return array();
526
+		} else {
527
+			return array();
528
+		}
460 529
 		if ($globalDBdriver == 'mysql') {
461 530
 			$query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND spotter_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND spotter_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.' GROUP BY spotter_live.flightaware_id'.$filter_query;
462 531
 		} else {
@@ -477,7 +546,9 @@  discard block
 block discarded – undo
477 546
 	{
478 547
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
479 548
 		$Spotter = new Spotter($this->db);
480
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
549
+		if (!isset($globalLiveInterval)) {
550
+			$globalLiveInterval = '200';
551
+		}
481 552
 		$filter_query = $this->getFilter($filter,true,true);
482 553
 
483 554
 		if (is_array($coord)) {
@@ -485,7 +556,9 @@  discard block
 block discarded – undo
485 556
 			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
486 557
 			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
487 558
 			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
488
-		} else return array();
559
+		} else {
560
+			return array();
561
+		}
489 562
 		if ($globalDBdriver == 'mysql') {
490 563
 			if (isset($globalArchive) && $globalArchive === TRUE) {
491 564
 				$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration 
@@ -712,11 +785,15 @@  discard block
 block discarded – undo
712 785
 		//$query  = self::$global_query.' WHERE spotter_live.flightaware_id = :id ORDER BY date';
713 786
 		if ($globalDBdriver == 'mysql') {
714 787
 			$query = 'SELECT spotter_live.* FROM spotter_live WHERE spotter_live.flightaware_id = :id';
715
-			if ($liveinterval) $query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
788
+			if ($liveinterval) {
789
+				$query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
790
+			}
716 791
 			$query .= ' ORDER BY date';
717 792
 		} else {
718 793
 			$query = 'SELECT spotter_live.* FROM spotter_live WHERE spotter_live.flightaware_id = :id';
719
-			if ($liveinterval) $query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
794
+			if ($liveinterval) {
795
+				$query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
796
+			}
720 797
 			$query .= ' ORDER BY date';
721 798
 		}
722 799
 
@@ -811,7 +888,9 @@  discard block
 block discarded – undo
811 888
 				$i++;
812 889
 				$j++;
813 890
 				if ($j == 30) {
814
-					if ($globalDebug) echo ".";
891
+					if ($globalDebug) {
892
+						echo ".";
893
+					}
815 894
 				    	try {
816 895
 						
817 896
 						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
@@ -1164,7 +1243,9 @@  discard block
 block discarded – undo
1164 1243
 			{
1165 1244
 				return false;
1166 1245
 			}
1167
-		} else return '';
1246
+		} else {
1247
+			return '';
1248
+		}
1168 1249
 
1169 1250
 		if ($longitude != '')
1170 1251
 		{
@@ -1172,7 +1253,9 @@  discard block
 block discarded – undo
1172 1253
 			{
1173 1254
 				return false;
1174 1255
 			}
1175
-		} else return '';
1256
+		} else {
1257
+			return '';
1258
+		}
1176 1259
 
1177 1260
 		if ($waypoints != '')
1178 1261
 		{
@@ -1188,14 +1271,18 @@  discard block
 block discarded – undo
1188 1271
 			{
1189 1272
 				return false;
1190 1273
 			}
1191
-		} else $altitude = 0;
1274
+		} else {
1275
+			$altitude = 0;
1276
+		}
1192 1277
 		if ($altitude_real != '')
1193 1278
 		{
1194 1279
 			if (!is_numeric($altitude_real))
1195 1280
 			{
1196 1281
 				return false;
1197 1282
 			}
1198
-		} else $altitude_real = 0;
1283
+		} else {
1284
+			$altitude_real = 0;
1285
+		}
1199 1286
 
1200 1287
 		if ($heading != '')
1201 1288
 		{
@@ -1203,7 +1290,9 @@  discard block
 block discarded – undo
1203 1290
 			{
1204 1291
 				return false;
1205 1292
 			}
1206
-		} else $heading = 0;
1293
+		} else {
1294
+			$heading = 0;
1295
+		}
1207 1296
 
1208 1297
 		if ($groundspeed != '')
1209 1298
 		{
@@ -1211,9 +1300,13 @@  discard block
 block discarded – undo
1211 1300
 			{
1212 1301
 				return false;
1213 1302
 			}
1214
-		} else $groundspeed = 0;
1303
+		} else {
1304
+			$groundspeed = 0;
1305
+		}
1215 1306
 		date_default_timezone_set('UTC');
1216
-		if ($date == '') $date = date("Y-m-d H:i:s", time());
1307
+		if ($date == '') {
1308
+			$date = date("Y-m-d H:i:s", time());
1309
+		}
1217 1310
 
1218 1311
         
1219 1312
 		$flightaware_id = filter_var($flightaware_id,FILTER_SANITIZE_STRING);
@@ -1258,14 +1351,24 @@  discard block
 block discarded – undo
1258 1351
 		$arrival_airport_country = '';
1259 1352
 		
1260 1353
             	
1261
-            	if ($squawk == '' || $Common->isInteger($squawk) === false ) $squawk = NULL;
1262
-            	if ($verticalrate == '' || $Common->isInteger($verticalrate) === false ) $verticalrate = NULL;
1263
-            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
1264
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
1354
+            	if ($squawk == '' || $Common->isInteger($squawk) === false ) {
1355
+            		$squawk = NULL;
1356
+            	}
1357
+            	if ($verticalrate == '' || $Common->isInteger($verticalrate) === false ) {
1358
+            		$verticalrate = NULL;
1359
+            	}
1360
+            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) {
1361
+            		$groundspeed = 0;
1362
+            	}
1363
+            	if ($heading == '' || $Common->isInteger($heading) === false ) {
1364
+            		$heading = 0;
1365
+            	}
1265 1366
 		
1266 1367
 		$query = '';
1267 1368
 		if ($globalArchive) {
1268
-			if ($globalDebug) echo '-- Delete previous data -- ';
1369
+			if ($globalDebug) {
1370
+				echo '-- Delete previous data -- ';
1371
+			}
1269 1372
 			$query .= 'DELETE FROM spotter_live WHERE flightaware_id = :flightaware_id;';
1270 1373
 		}
1271 1374
 
@@ -1282,10 +1385,14 @@  discard block
 block discarded – undo
1282 1385
 			return "error : ".$e->getMessage();
1283 1386
 		}
1284 1387
 		if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) {
1285
-		    if ($globalDebug) echo '(Add to SBS archive : ';
1388
+		    if ($globalDebug) {
1389
+		    	echo '(Add to SBS archive : ';
1390
+		    }
1286 1391
 		    $SpotterArchive = new SpotterArchive($this->db);
1287 1392
 		    $result =  $SpotterArchive->addSpotterArchiveData($flightaware_id, $ident, $registration, $airline_name, $airline_icao, $airline_country, $airline_type, $aircraft_icao, $aircraft_shadow, $aircraft_name, $aircraft_manufacturer, $departure_airport_icao, $departure_airport_name, $departure_airport_city, $departure_airport_country, $departure_airport_time,$arrival_airport_icao, $arrival_airport_name, $arrival_airport_city, $arrival_airport_country, $arrival_airport_time, $route_stop, $date,$latitude, $longitude, $waypoints, $altitude, $altitude_real,$heading, $groundspeed, $squawk, $ModeS, $pilot_id, $pilot_name,$verticalrate,$format_source,$source_name, $over_country);
1288
-		    if ($globalDebug) echo $result.')';
1393
+		    if ($globalDebug) {
1394
+		    	echo $result.')';
1395
+		    }
1289 1396
 		} elseif ($globalDebug && $putinarchive !== true) {
1290 1397
 			echo '(Not adding to archive)';
1291 1398
 		} elseif ($globalDebug && $noarchive === true) {
Please login to merge, or discard this patch.