Completed
Push — master ( 4c247d...ce17c6 )
by Yannick
07:53
created
require/class.SpotterLive.php 2 patches
Indentation   +206 added lines, -206 removed lines patch added patch discarded remove patch
@@ -12,10 +12,10 @@  discard block
 block discarded – undo
12 12
 
13 13
 
14 14
 	/**
15
-	* Get SQL query part for filter used
16
-	* @param Array $filter the filter
17
-	* @return Array the SQL part
18
-	*/
15
+	 * Get SQL query part for filter used
16
+	 * @param Array $filter the filter
17
+	 * @return Array the SQL part
18
+	 */
19 19
 	public function getFilter($filter = array(),$where = false,$and = false) {
20 20
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
21 21
 		$filters = array();
@@ -128,11 +128,11 @@  discard block
 block discarded – undo
128 128
 	}
129 129
 
130 130
 	/**
131
-	* Gets all the spotter information based on the latest data entry
132
-	*
133
-	* @return Array the spotter information
134
-	*
135
-	*/
131
+	 * Gets all the spotter information based on the latest data entry
132
+	 *
133
+	 * @return Array the spotter information
134
+	 *
135
+	 */
136 136
 	public function getLiveSpotterData($limit = '', $sort = '', $filter = array())
137 137
 	{
138 138
 		global $globalDBdriver, $globalLiveInterval;
@@ -174,11 +174,11 @@  discard block
 block discarded – undo
174 174
 	}
175 175
 
176 176
 	/**
177
-	* Gets Minimal Live Spotter data
178
-	*
179
-	* @return Array the spotter information
180
-	*
181
-	*/
177
+	 * Gets Minimal Live Spotter data
178
+	 *
179
+	 * @return Array the spotter information
180
+	 *
181
+	 */
182 182
 	public function getMinLiveSpotterData($filter = array())
183 183
 	{
184 184
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
@@ -215,11 +215,11 @@  discard block
 block discarded – undo
215 215
 	}
216 216
 
217 217
 	/**
218
-	* Gets Minimal Live Spotter data since xx seconds
219
-	*
220
-	* @return Array the spotter information
221
-	*
222
-	*/
218
+	 * Gets Minimal Live Spotter data since xx seconds
219
+	 *
220
+	 * @return Array the spotter information
221
+	 *
222
+	 */
223 223
 	public function getMinLastLiveSpotterData($filter = array())
224 224
 	{
225 225
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 				FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= spotter_live.date AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' 
239 239
 				ORDER BY spotter_live.flightaware_id, spotter_live.date";
240 240
 			}
241
-                } else {
241
+				} else {
242 242
 			if (isset($globalArchive) && $globalArchive === TRUE) {
243 243
 				$query  = "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 
244 244
 				FROM spotter_archive INNER JOIN (SELECT flightaware_id FROM spotter_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date) l ON l.flightaware_id = spotter_archive.flightaware_id WHERE spotter_archive.latitude <> '0' AND spotter_archive.longitude <> '0' 
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 			}
251 251
 		}
252 252
 
253
-    		try {
253
+			try {
254 254
 			$sth = $this->db->prepare($query);
255 255
 			$sth->execute();
256 256
 		} catch(PDOException $e) {
@@ -262,11 +262,11 @@  discard block
 block discarded – undo
262 262
 	}
263 263
 
264 264
 	/**
265
-	* Gets number of latest data entry
266
-	*
267
-	* @return String number of entry
268
-	*
269
-	*/
265
+	 * Gets number of latest data entry
266
+	 *
267
+	 * @return String number of entry
268
+	 *
269
+	 */
270 270
 	public function getLiveSpotterCount($filter = array())
271 271
 	{
272 272
 		global $globalDBdriver, $globalLiveInterval;
@@ -293,11 +293,11 @@  discard block
 block discarded – undo
293 293
 	}
294 294
 
295 295
 	/**
296
-	* Gets all the spotter information based on the latest data entry and coord
297
-	*
298
-	* @return Array the spotter information
299
-	*
300
-	*/
296
+	 * Gets all the spotter information based on the latest data entry and coord
297
+	 *
298
+	 * @return Array the spotter information
299
+	 *
300
+	 */
301 301
 	public function getLiveSpotterDatabyCoord($coord, $filter = array())
302 302
 	{
303 303
 		global $globalDBdriver, $globalLiveInterval;
@@ -322,11 +322,11 @@  discard block
 block discarded – undo
322 322
 	}
323 323
 
324 324
 	/**
325
-	* Gets all the spotter information based on the latest data entry and coord
326
-	*
327
-	* @return Array the spotter information
328
-	*
329
-	*/
325
+	 * Gets all the spotter information based on the latest data entry and coord
326
+	 *
327
+	 * @return Array the spotter information
328
+	 *
329
+	 */
330 330
 	public function getMinLiveSpotterDatabyCoord($coord, $filter = array())
331 331
 	{
332 332
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
@@ -391,11 +391,11 @@  discard block
 block discarded – undo
391 391
 	}
392 392
 
393 393
 	/**
394
-	* Gets all the spotter information based on a user's latitude and longitude
395
-	*
396
-	* @return Array the spotter information
397
-	*
398
-	*/
394
+	 * Gets all the spotter information based on a user's latitude and longitude
395
+	 *
396
+	 * @return Array the spotter information
397
+	 *
398
+	 */
399 399
 	public function getLatestSpotterForLayar($lat, $lng, $radius, $interval)
400 400
 	{
401 401
 		$Spotter = new Spotter($this->db);
@@ -405,145 +405,145 @@  discard block
 block discarded – undo
405 405
 				return false;
406 406
 			}
407 407
 		}
408
-        if ($lng != '')
409
-                {
410
-                        if (!is_numeric($lng))
411
-                        {
412
-                                return false;
413
-                        }
414
-                }
415
-
416
-                if ($radius != '')
417
-                {
418
-                        if (!is_numeric($radius))
419
-                        {
420
-                                return false;
421
-                        }
422
-                }
408
+		if ($lng != '')
409
+				{
410
+						if (!is_numeric($lng))
411
+						{
412
+								return false;
413
+						}
414
+				}
415
+
416
+				if ($radius != '')
417
+				{
418
+						if (!is_numeric($radius))
419
+						{
420
+								return false;
421
+						}
422
+				}
423 423
 		$additional_query = '';
424
-        if ($interval != '')
425
-                {
426
-                        if (!is_string($interval))
427
-                        {
428
-                                //$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date ';
429
-			        return false;
430
-                        } else {
431
-                if ($interval == '1m')
432
-                {
433
-                    $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date ';
434
-                } else if ($interval == '15m'){
435
-                    $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= spotter_live.date ';
436
-                } 
437
-            }
438
-                } else {
439
-         $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date ';   
440
-        }
441
-
442
-                $query  = "SELECT spotter_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM spotter_live 
424
+		if ($interval != '')
425
+				{
426
+						if (!is_string($interval))
427
+						{
428
+								//$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date ';
429
+					return false;
430
+						} else {
431
+				if ($interval == '1m')
432
+				{
433
+					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date ';
434
+				} else if ($interval == '15m'){
435
+					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= spotter_live.date ';
436
+				} 
437
+			}
438
+				} else {
439
+		 $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date ';   
440
+		}
441
+
442
+				$query  = "SELECT spotter_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM spotter_live 
443 443
                    WHERE spotter_live.latitude <> '' 
444 444
                                    AND spotter_live.longitude <> '' 
445 445
                    ".$additional_query."
446 446
                    HAVING distance < :radius  
447 447
                                    ORDER BY distance";
448 448
 
449
-                $spotter_array = $Spotter->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius));
449
+				$spotter_array = $Spotter->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius));
450 450
 
451
-                return $spotter_array;
452
-        }
451
+				return $spotter_array;
452
+		}
453 453
 
454 454
     
455
-        /**
456
-	* Gets all the spotter information based on a particular callsign
457
-	*
458
-	* @return Array the spotter information
459
-	*
460
-	*/
455
+		/**
456
+		 * Gets all the spotter information based on a particular callsign
457
+		 *
458
+		 * @return Array the spotter information
459
+		 *
460
+		 */
461 461
 	public function getLastLiveSpotterDataByIdent($ident)
462 462
 	{
463 463
 		$Spotter = new Spotter($this->db);
464 464
 		date_default_timezone_set('UTC');
465 465
 
466 466
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
467
-                $query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC';
467
+				$query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC';
468 468
 
469 469
 		$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident),'',true);
470 470
 
471 471
 		return $spotter_array;
472 472
 	}
473 473
 
474
-        /**
475
-	* Gets all the spotter information based on a particular callsign
476
-	*
477
-	* @return Array the spotter information
478
-	*
479
-	*/
474
+		/**
475
+		 * Gets all the spotter information based on a particular callsign
476
+		 *
477
+		 * @return Array the spotter information
478
+		 *
479
+		 */
480 480
 	public function getDateLiveSpotterDataByIdent($ident,$date)
481 481
 	{
482 482
 		$Spotter = new Spotter($this->db);
483 483
 		date_default_timezone_set('UTC');
484 484
 
485 485
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
486
-                $query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC';
486
+				$query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC';
487 487
 
488
-                $date = date('c',$date);
488
+				$date = date('c',$date);
489 489
 		$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident,':date' => $date));
490 490
 
491 491
 		return $spotter_array;
492 492
 	}
493 493
 
494
-        /**
495
-	* Gets last spotter information based on a particular callsign
496
-	*
497
-	* @return Array the spotter information
498
-	*
499
-	*/
494
+		/**
495
+		 * Gets last spotter information based on a particular callsign
496
+		 *
497
+		 * @return Array the spotter information
498
+		 *
499
+		 */
500 500
 	public function getLastLiveSpotterDataById($id)
501 501
 	{
502 502
 		$Spotter = new Spotter($this->db);
503 503
 		date_default_timezone_set('UTC');
504 504
 
505 505
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
506
-                $query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.flightaware_id = :id GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC';
506
+				$query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.flightaware_id = :id GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC';
507 507
 
508 508
 		$spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id),'',true);
509 509
 
510 510
 		return $spotter_array;
511 511
 	}
512 512
 
513
-        /**
514
-	* Gets last spotter information based on a particular callsign
515
-	*
516
-	* @return Array the spotter information
517
-	*
518
-	*/
513
+		/**
514
+		 * Gets last spotter information based on a particular callsign
515
+		 *
516
+		 * @return Array the spotter information
517
+		 *
518
+		 */
519 519
 	public function getDateLiveSpotterDataById($id,$date)
520 520
 	{
521 521
 		$Spotter = new Spotter($this->db);
522 522
 		date_default_timezone_set('UTC');
523 523
 
524 524
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
525
-                $query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.flightaware_id = :id AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC';
526
-                $date = date('c',$date);
525
+				$query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.flightaware_id = :id AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC';
526
+				$date = date('c',$date);
527 527
 		$spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id,':date' => $date),'',true);
528 528
 
529 529
 		return $spotter_array;
530 530
 	}
531 531
 
532
-        /**
533
-	* Gets altitude information based on a particular callsign
534
-	*
535
-	* @return Array the spotter information
536
-	*
537
-	*/
532
+		/**
533
+		 * Gets altitude information based on a particular callsign
534
+		 *
535
+		 * @return Array the spotter information
536
+		 *
537
+		 */
538 538
 	public function getAltitudeLiveSpotterDataByIdent($ident)
539 539
 	{
540 540
 
541 541
 		date_default_timezone_set('UTC');
542 542
 
543 543
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
544
-                $query  = 'SELECT spotter_live.altitude, spotter_live.date FROM spotter_live WHERE spotter_live.ident = :ident';
544
+				$query  = 'SELECT spotter_live.altitude, spotter_live.date FROM spotter_live WHERE spotter_live.ident = :ident';
545 545
 
546
-    		try {
546
+			try {
547 547
 			
548 548
 			$sth = $this->db->prepare($query);
549 549
 			$sth->execute(array(':ident' => $ident));
@@ -556,12 +556,12 @@  discard block
 block discarded – undo
556 556
 		return $spotter_array;
557 557
 	}
558 558
 
559
-        /**
560
-	* Gets all the spotter information based on a particular id
561
-	*
562
-	* @return Array the spotter information
563
-	*
564
-	*/
559
+		/**
560
+		 * Gets all the spotter information based on a particular id
561
+		 *
562
+		 * @return Array the spotter information
563
+		 *
564
+		 */
565 565
 	public function getAllLiveSpotterDataById($id,$liveinterval = false)
566 566
 	{
567 567
 		global $globalDBdriver, $globalLiveInterval;
@@ -589,18 +589,18 @@  discard block
 block discarded – undo
589 589
 		return $spotter_array;
590 590
 	}
591 591
 
592
-        /**
593
-	* Gets all the spotter information based on a particular ident
594
-	*
595
-	* @return Array the spotter information
596
-	*
597
-	*/
592
+		/**
593
+		 * Gets all the spotter information based on a particular ident
594
+		 *
595
+		 * @return Array the spotter information
596
+		 *
597
+		 */
598 598
 	public function getAllLiveSpotterDataByIdent($ident)
599 599
 	{
600 600
 		date_default_timezone_set('UTC');
601 601
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
602 602
 		$query  = self::$global_query.' WHERE spotter_live.ident = :ident';
603
-    		try {
603
+			try {
604 604
 			
605 605
 			$sth = $this->db->prepare($query);
606 606
 			$sth->execute(array(':ident' => $ident));
@@ -614,23 +614,23 @@  discard block
 block discarded – undo
614 614
 
615 615
 
616 616
 	/**
617
-	* Deletes all info in the table
618
-	*
619
-	* @return String success or false
620
-	*
621
-	*/
617
+	 * Deletes all info in the table
618
+	 *
619
+	 * @return String success or false
620
+	 *
621
+	 */
622 622
 	public function deleteLiveSpotterData()
623 623
 	{
624 624
 		global $globalDBdriver;
625 625
 		if ($globalDBdriver == 'mysql') {
626 626
 			//$query  = "DELETE FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE) >= spotter_live.date";
627 627
 			$query  = 'DELETE FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 9 HOUR) >= spotter_live.date';
628
-            		//$query  = "DELETE FROM spotter_live WHERE spotter_live.id IN (SELECT spotter_live.id FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= spotter_live.date)";
628
+					//$query  = "DELETE FROM spotter_live WHERE spotter_live.id IN (SELECT spotter_live.id FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= spotter_live.date)";
629 629
 		} else {
630 630
 			$query  = "DELETE FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= spotter_live.date";
631 631
 		}
632 632
         
633
-    		try {
633
+			try {
634 634
 			
635 635
 			$sth = $this->db->prepare($query);
636 636
 			$sth->execute();
@@ -642,18 +642,18 @@  discard block
 block discarded – undo
642 642
 	}
643 643
 
644 644
 	/**
645
-	* Deletes all info in the table for aircraft not seen since 2 HOUR
646
-	*
647
-	* @return String success or false
648
-	*
649
-	*/
645
+	 * Deletes all info in the table for aircraft not seen since 2 HOUR
646
+	 *
647
+	 * @return String success or false
648
+	 *
649
+	 */
650 650
 	public function deleteLiveSpotterDataNotUpdated()
651 651
 	{
652 652
 		global $globalDBdriver, $globalDebug;
653 653
 		if ($globalDBdriver == 'mysql') {
654 654
 			//$query = 'SELECT flightaware_id FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) >= spotter_live.date AND spotter_live.flightaware_id NOT IN (SELECT flightaware_id FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) < spotter_live.date) LIMIT 800 OFFSET 0';
655
-    			$query = "SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 2000 OFFSET 0";
656
-    			try {
655
+				$query = "SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 2000 OFFSET 0";
656
+				try {
657 657
 				
658 658
 				$sth = $this->db->prepare($query);
659 659
 				$sth->execute();
@@ -661,8 +661,8 @@  discard block
 block discarded – undo
661 661
 				return "error";
662 662
 			}
663 663
 			$query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN (';
664
-                        $i = 0;
665
-                        $j =0;
664
+						$i = 0;
665
+						$j =0;
666 666
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
667 667
 			foreach($all as $row)
668 668
 			{
@@ -670,20 +670,20 @@  discard block
 block discarded – undo
670 670
 				$j++;
671 671
 				if ($j == 30) {
672 672
 					if ($globalDebug) echo ".";
673
-				    	try {
673
+						try {
674 674
 						
675 675
 						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
676 676
 						$sth->execute();
677 677
 					} catch(PDOException $e) {
678 678
 						return "error";
679 679
 					}
680
-                                	$query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN (';
681
-                                	$j = 0;
680
+									$query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN (';
681
+									$j = 0;
682 682
 				}
683 683
 				$query_delete .= "'".$row['flightaware_id']."',";
684 684
 			}
685 685
 			if ($i > 0) {
686
-    				try {
686
+					try {
687 687
 					
688 688
 					$sth = $this->db->prepare(substr($query_delete,0,-1).")");
689 689
 					$sth->execute();
@@ -694,9 +694,9 @@  discard block
 block discarded – undo
694 694
 			return "success";
695 695
 		} elseif ($globalDBdriver == 'pgsql') {
696 696
 			//$query = "SELECT flightaware_id FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= spotter_live.date AND spotter_live.flightaware_id NOT IN (SELECT flightaware_id FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' < spotter_live.date) LIMIT 800 OFFSET 0";
697
-    			//$query = "SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0";
698
-    			$query = "DELETE FROM spotter_live WHERE flightaware_id IN (SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 2000 OFFSET 0)";
699
-    			try {
697
+				//$query = "SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0";
698
+				$query = "DELETE FROM spotter_live WHERE flightaware_id IN (SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 2000 OFFSET 0)";
699
+				try {
700 700
 				
701 701
 				$sth = $this->db->prepare($query);
702 702
 				$sth->execute();
@@ -740,17 +740,17 @@  discard block
 block discarded – undo
740 740
 	}
741 741
 
742 742
 	/**
743
-	* Deletes all info in the table for an ident
744
-	*
745
-	* @return String success or false
746
-	*
747
-	*/
743
+	 * Deletes all info in the table for an ident
744
+	 *
745
+	 * @return String success or false
746
+	 *
747
+	 */
748 748
 	public function deleteLiveSpotterDataByIdent($ident)
749 749
 	{
750 750
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
751 751
 		$query  = 'DELETE FROM spotter_live WHERE ident = :ident';
752 752
         
753
-    		try {
753
+			try {
754 754
 			
755 755
 			$sth = $this->db->prepare($query);
756 756
 			$sth->execute(array(':ident' => $ident));
@@ -762,17 +762,17 @@  discard block
 block discarded – undo
762 762
 	}
763 763
 
764 764
 	/**
765
-	* Deletes all info in the table for an id
766
-	*
767
-	* @return String success or false
768
-	*
769
-	*/
765
+	 * Deletes all info in the table for an id
766
+	 *
767
+	 * @return String success or false
768
+	 *
769
+	 */
770 770
 	public function deleteLiveSpotterDataById($id)
771 771
 	{
772 772
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
773 773
 		$query  = 'DELETE FROM spotter_live WHERE flightaware_id = :id';
774 774
         
775
-    		try {
775
+			try {
776 776
 			
777 777
 			$sth = $this->db->prepare($query);
778 778
 			$sth->execute(array(':id' => $id));
@@ -785,11 +785,11 @@  discard block
 block discarded – undo
785 785
 
786 786
 
787 787
 	/**
788
-	* Gets the aircraft ident within the last hour
789
-	*
790
-	* @return String the ident
791
-	*
792
-	*/
788
+	 * Gets the aircraft ident within the last hour
789
+	 *
790
+	 * @return String the ident
791
+	 *
792
+	 */
793 793
 	public function getIdentFromLastHour($ident)
794 794
 	{
795 795
 		global $globalDBdriver, $globalTimezone;
@@ -815,14 +815,14 @@  discard block
 block discarded – undo
815 815
 			$ident_result = $row['ident'];
816 816
 		}
817 817
 		return $ident_result;
818
-        }
818
+		}
819 819
 
820 820
 	/**
821
-	* Check recent aircraft
822
-	*
823
-	* @return String the ident
824
-	*
825
-	*/
821
+	 * Check recent aircraft
822
+	 *
823
+	 * @return String the ident
824
+	 *
825
+	 */
826 826
 	public function checkIdentRecent($ident)
827 827
 	{
828 828
 		global $globalDBdriver, $globalTimezone;
@@ -848,14 +848,14 @@  discard block
 block discarded – undo
848 848
 			$ident_result = $row['flightaware_id'];
849 849
 		}
850 850
 		return $ident_result;
851
-        }
851
+		}
852 852
 
853 853
 	/**
854
-	* Check recent aircraft by id
855
-	*
856
-	* @return String the ident
857
-	*
858
-	*/
854
+	 * Check recent aircraft by id
855
+	 *
856
+	 * @return String the ident
857
+	 *
858
+	 */
859 859
 	public function checkIdRecent($id)
860 860
 	{
861 861
 		global $globalDBdriver, $globalTimezone;
@@ -881,14 +881,14 @@  discard block
 block discarded – undo
881 881
 			$ident_result = $row['flightaware_id'];
882 882
 		}
883 883
 		return $ident_result;
884
-        }
884
+		}
885 885
 
886 886
 	/**
887
-	* Check recent aircraft by ModeS
888
-	*
889
-	* @return String the ModeS
890
-	*
891
-	*/
887
+	 * Check recent aircraft by ModeS
888
+	 *
889
+	 * @return String the ModeS
890
+	 *
891
+	 */
892 892
 	public function checkModeSRecent($modes)
893 893
 	{
894 894
 		global $globalDBdriver, $globalTimezone;
@@ -915,19 +915,19 @@  discard block
 block discarded – undo
915 915
 			$ident_result = $row['flightaware_id'];
916 916
 		}
917 917
 		return $ident_result;
918
-        }
918
+		}
919 919
 
920 920
 	/**
921
-	* Adds a new spotter data
922
-	*
923
-	* @param String $flightaware_id the ID from flightaware
924
-	* @param String $ident the flight ident
925
-	* @param String $aircraft_icao the aircraft type
926
-	* @param String $departure_airport_icao the departure airport
927
-	* @param String $arrival_airport_icao the arrival airport
928
-	* @return String success or false
929
-	*
930
-	*/
921
+	 * Adds a new spotter data
922
+	 *
923
+	 * @param String $flightaware_id the ID from flightaware
924
+	 * @param String $ident the flight ident
925
+	 * @param String $aircraft_icao the aircraft type
926
+	 * @param String $departure_airport_icao the departure airport
927
+	 * @param String $arrival_airport_icao the arrival airport
928
+	 * @return String success or false
929
+	 *
930
+	 */
931 931
 	public function addLiveSpotterData($flightaware_id = '', $ident = '', $aircraft_icao = '', $departure_airport_icao = '', $arrival_airport_icao = '', $latitude = '', $longitude = '', $waypoints = '', $altitude = '', $altitude_real = '',$heading = '', $groundspeed = '', $date = '',$departure_airport_time = '', $arrival_airport_time = '', $squawk = '', $route_stop = '', $ModeS = '', $putinarchive = false,$registration = '',$pilot_id = '', $pilot_name = '', $verticalrate = '', $noarchive = false, $ground = false,$format_source = '', $source_name = '', $over_country = '')
932 932
 	{
933 933
 		global $globalURL, $globalArchive, $globalDebug;
@@ -1062,10 +1062,10 @@  discard block
 block discarded – undo
1062 1062
 		$arrival_airport_country = '';
1063 1063
 		
1064 1064
             	
1065
-            	if ($squawk == '' || $Common->isInteger($squawk) === false ) $squawk = NULL;
1066
-            	if ($verticalrate == '' || $Common->isInteger($verticalrate) === false ) $verticalrate = NULL;
1067
-            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
1068
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
1065
+				if ($squawk == '' || $Common->isInteger($squawk) === false ) $squawk = NULL;
1066
+				if ($verticalrate == '' || $Common->isInteger($verticalrate) === false ) $verticalrate = NULL;
1067
+				if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
1068
+				if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
1069 1069
 		
1070 1070
 		$query = '';
1071 1071
 		if ($globalArchive) {
@@ -1086,10 +1086,10 @@  discard block
 block discarded – undo
1086 1086
 			return "error : ".$e->getMessage();
1087 1087
 		}
1088 1088
 		if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) {
1089
-		    if ($globalDebug) echo '(Add to SBS archive : ';
1090
-		    $SpotterArchive = new SpotterArchive($this->db);
1091
-		    $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, $heading, $groundspeed, $squawk, $ModeS, $pilot_id, $pilot_name,$verticalrate,$format_source,$source_name, $over_country);
1092
-		    if ($globalDebug) echo $result.')';
1089
+			if ($globalDebug) echo '(Add to SBS archive : ';
1090
+			$SpotterArchive = new SpotterArchive($this->db);
1091
+			$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, $heading, $groundspeed, $squawk, $ModeS, $pilot_id, $pilot_name,$verticalrate,$format_source,$source_name, $over_country);
1092
+			if ($globalDebug) echo $result.')';
1093 1093
 		}
1094 1094
 		return "success";
1095 1095
 
Please login to merge, or discard this patch.
Braces   +80 added lines, -27 removed lines patch added patch discarded remove patch
@@ -29,7 +29,9 @@  discard block
 block discarded – undo
29 29
 		if (isset($filter[0]['source'])) {
30 30
 			$filters = array_merge($filters,$filter);
31 31
 		}
32
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
32
+		if (is_array($globalFilter)) {
33
+			$filter = array_merge($filter,$globalFilter);
34
+		}
33 35
 		$filter_query_join = '';
34 36
 		$filter_query_where = '';
35 37
 		foreach($filters as $flt) {
@@ -118,8 +120,11 @@  discard block
 block discarded – undo
118 120
 		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
119 121
 			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
120 122
 		}
121
-		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
122
-		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
123
+		if ($filter_query_where == '' && $where) {
124
+			$filter_query_where = ' WHERE';
125
+		} elseif ($filter_query_where != '' && $and) {
126
+			$filter_query_where .= ' AND';
127
+		}
123 128
 		if ($filter_query_where != '') {
124 129
 			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
125 130
 		}
@@ -161,7 +166,9 @@  discard block
 block discarded – undo
161 166
 			}
162 167
 		}
163 168
 
164
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
169
+		if (!isset($globalLiveInterval)) {
170
+			$globalLiveInterval = '200';
171
+		}
165 172
 		if ($globalDBdriver == 'mysql') {
166 173
 			//$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";
167 174
 			$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;
@@ -184,7 +191,9 @@  discard block
 block discarded – undo
184 191
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
185 192
 		date_default_timezone_set('UTC');
186 193
 		$filter_query = $this->getFilter($filter,true,true);
187
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
194
+		if (!isset($globalLiveInterval)) {
195
+			$globalLiveInterval = '200';
196
+		}
188 197
 		if ($globalDBdriver == 'mysql') {
189 198
 			if (isset($globalArchive) && $globalArchive === TRUE) {
190 199
 				$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 
@@ -227,7 +236,9 @@  discard block
 block discarded – undo
227 236
 
228 237
 		$filter_query = $this->getFilter($filter,true,true);
229 238
 
230
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
239
+		if (!isset($globalLiveInterval)) {
240
+			$globalLiveInterval = '200';
241
+		}
231 242
 		if ($globalDBdriver == 'mysql') {
232 243
 			if (isset($globalArchive) && $globalArchive === TRUE) {
233 244
 				$query  = '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 
@@ -272,7 +283,9 @@  discard block
 block discarded – undo
272 283
 		global $globalDBdriver, $globalLiveInterval;
273 284
 		$filter_query = $this->getFilter($filter,true,true);
274 285
 
275
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
286
+		if (!isset($globalLiveInterval)) {
287
+			$globalLiveInterval = '200';
288
+		}
276 289
 		if ($globalDBdriver == 'mysql') {
277 290
 			//$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;
278 291
 			$query = 'SELECT COUNT(DISTINCT spotter_live.flightaware_id) as nb FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
@@ -302,7 +315,9 @@  discard block
 block discarded – undo
302 315
 	{
303 316
 		global $globalDBdriver, $globalLiveInterval;
304 317
 		$Spotter = new Spotter($this->db);
305
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
318
+		if (!isset($globalLiveInterval)) {
319
+			$globalLiveInterval = '200';
320
+		}
306 321
 		$filter_query = $this->getFilter($filter);
307 322
 
308 323
 		if (is_array($coord)) {
@@ -310,7 +325,9 @@  discard block
 block discarded – undo
310 325
 			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
311 326
 			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
312 327
 			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
313
-		} else return array();
328
+		} else {
329
+			return array();
330
+		}
314 331
 		if ($globalDBdriver == 'mysql') {
315 332
 			$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;
316 333
 		} else {
@@ -331,7 +348,9 @@  discard block
 block discarded – undo
331 348
 	{
332 349
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
333 350
 		$Spotter = new Spotter($this->db);
334
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
351
+		if (!isset($globalLiveInterval)) {
352
+			$globalLiveInterval = '200';
353
+		}
335 354
 		$filter_query = $this->getFilter($filter,true,true);
336 355
 
337 356
 		if (is_array($coord)) {
@@ -339,7 +358,9 @@  discard block
 block discarded – undo
339 358
 			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
340 359
 			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
341 360
 			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
342
-		} else return array();
361
+		} else {
362
+			return array();
363
+		}
343 364
 		if ($globalDBdriver == 'mysql') {
344 365
 			if (isset($globalArchive) && $globalArchive === TRUE) {
345 366
 				$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 
@@ -570,11 +591,15 @@  discard block
 block discarded – undo
570 591
 		//$query  = self::$global_query.' WHERE spotter_live.flightaware_id = :id ORDER BY date';
571 592
 		if ($globalDBdriver == 'mysql') {
572 593
 			$query = 'SELECT spotter_live.* FROM spotter_live WHERE spotter_live.flightaware_id = :id';
573
-			if ($liveinterval) $query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
594
+			if ($liveinterval) {
595
+				$query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
596
+			}
574 597
 			$query .= ' ORDER BY date';
575 598
 		} else {
576 599
 			$query = 'SELECT spotter_live.* FROM spotter_live WHERE spotter_live.flightaware_id = :id';
577
-			if ($liveinterval) $query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
600
+			if ($liveinterval) {
601
+				$query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
602
+			}
578 603
 			$query .= ' ORDER BY date';
579 604
 		}
580 605
 
@@ -669,7 +694,9 @@  discard block
 block discarded – undo
669 694
 				$i++;
670 695
 				$j++;
671 696
 				if ($j == 30) {
672
-					if ($globalDebug) echo ".";
697
+					if ($globalDebug) {
698
+						echo ".";
699
+					}
673 700
 				    	try {
674 701
 						
675 702
 						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
@@ -976,7 +1003,9 @@  discard block
 block discarded – undo
976 1003
 			{
977 1004
 				return false;
978 1005
 			}
979
-		} else return '';
1006
+		} else {
1007
+			return '';
1008
+		}
980 1009
 
981 1010
 		if ($longitude != '')
982 1011
 		{
@@ -984,7 +1013,9 @@  discard block
 block discarded – undo
984 1013
 			{
985 1014
 				return false;
986 1015
 			}
987
-		} else return '';
1016
+		} else {
1017
+			return '';
1018
+		}
988 1019
 
989 1020
 		if ($waypoints != '')
990 1021
 		{
@@ -1000,7 +1031,9 @@  discard block
 block discarded – undo
1000 1031
 			{
1001 1032
 				return false;
1002 1033
 			}
1003
-		} else $altitude = 0;
1034
+		} else {
1035
+			$altitude = 0;
1036
+		}
1004 1037
 
1005 1038
 		if ($heading != '')
1006 1039
 		{
@@ -1008,7 +1041,9 @@  discard block
 block discarded – undo
1008 1041
 			{
1009 1042
 				return false;
1010 1043
 			}
1011
-		} else $heading = 0;
1044
+		} else {
1045
+			$heading = 0;
1046
+		}
1012 1047
 
1013 1048
 		if ($groundspeed != '')
1014 1049
 		{
@@ -1016,9 +1051,13 @@  discard block
 block discarded – undo
1016 1051
 			{
1017 1052
 				return false;
1018 1053
 			}
1019
-		} else $groundspeed = 0;
1054
+		} else {
1055
+			$groundspeed = 0;
1056
+		}
1020 1057
 		date_default_timezone_set('UTC');
1021
-		if ($date == '') $date = date("Y-m-d H:i:s", time());
1058
+		if ($date == '') {
1059
+			$date = date("Y-m-d H:i:s", time());
1060
+		}
1022 1061
 
1023 1062
         
1024 1063
 		$flightaware_id = filter_var($flightaware_id,FILTER_SANITIZE_STRING);
@@ -1062,14 +1101,24 @@  discard block
 block discarded – undo
1062 1101
 		$arrival_airport_country = '';
1063 1102
 		
1064 1103
             	
1065
-            	if ($squawk == '' || $Common->isInteger($squawk) === false ) $squawk = NULL;
1066
-            	if ($verticalrate == '' || $Common->isInteger($verticalrate) === false ) $verticalrate = NULL;
1067
-            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
1068
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
1104
+            	if ($squawk == '' || $Common->isInteger($squawk) === false ) {
1105
+            		$squawk = NULL;
1106
+            	}
1107
+            	if ($verticalrate == '' || $Common->isInteger($verticalrate) === false ) {
1108
+            		$verticalrate = NULL;
1109
+            	}
1110
+            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) {
1111
+            		$groundspeed = 0;
1112
+            	}
1113
+            	if ($heading == '' || $Common->isInteger($heading) === false ) {
1114
+            		$heading = 0;
1115
+            	}
1069 1116
 		
1070 1117
 		$query = '';
1071 1118
 		if ($globalArchive) {
1072
-			if ($globalDebug) echo '-- Delete previous data -- ';
1119
+			if ($globalDebug) {
1120
+				echo '-- Delete previous data -- ';
1121
+			}
1073 1122
 			$query .= 'DELETE FROM spotter_live WHERE flightaware_id = :flightaware_id;';
1074 1123
 		}
1075 1124
 
@@ -1086,10 +1135,14 @@  discard block
 block discarded – undo
1086 1135
 			return "error : ".$e->getMessage();
1087 1136
 		}
1088 1137
 		if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) {
1089
-		    if ($globalDebug) echo '(Add to SBS archive : ';
1138
+		    if ($globalDebug) {
1139
+		    	echo '(Add to SBS archive : ';
1140
+		    }
1090 1141
 		    $SpotterArchive = new SpotterArchive($this->db);
1091 1142
 		    $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, $heading, $groundspeed, $squawk, $ModeS, $pilot_id, $pilot_name,$verticalrate,$format_source,$source_name, $over_country);
1092
-		    if ($globalDebug) echo $result.')';
1143
+		    if ($globalDebug) {
1144
+		    	echo $result.')';
1145
+		    }
1093 1146
 		}
1094 1147
 		return "success";
1095 1148
 
Please login to merge, or discard this patch.