Completed
Push — master ( c0278b...990a68 )
by Yannick
09:48
created
require/class.SpotterLive.php 1 patch
Indentation   +203 added lines, -203 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;
@@ -175,11 +175,11 @@  discard block
 block discarded – undo
175 175
 	}
176 176
 
177 177
 	/**
178
-	* Gets Minimal Live Spotter data
179
-	*
180
-	* @return Array the spotter information
181
-	*
182
-	*/
178
+	 * Gets Minimal Live Spotter data
179
+	 *
180
+	 * @return Array the spotter information
181
+	 *
182
+	 */
183 183
 	public function getMinLiveSpotterData($filter = array())
184 184
 	{
185 185
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
@@ -216,11 +216,11 @@  discard block
 block discarded – undo
216 216
 	}
217 217
 
218 218
 	/**
219
-	* Gets Minimal Live Spotter data since xx seconds
220
-	*
221
-	* @return Array the spotter information
222
-	*
223
-	*/
219
+	 * Gets Minimal Live Spotter data since xx seconds
220
+	 *
221
+	 * @return Array the spotter information
222
+	 *
223
+	 */
224 224
 	public function getMinLastLiveSpotterData($filter = array())
225 225
 	{
226 226
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 				AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' 
251 251
 				ORDER BY spotter_live.flightaware_id, spotter_live.date";
252 252
 			}
253
-                } else {
253
+				} else {
254 254
 			if (isset($globalArchive) && $globalArchive === TRUE) {
255 255
 				/*
256 256
 				$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 
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 				ORDER BY spotter_live.flightaware_id, spotter_live.date";
275 275
 			}
276 276
 		}
277
-    		try {
277
+			try {
278 278
 			$sth = $this->db->prepare($query);
279 279
 			$sth->execute();
280 280
 		} catch(PDOException $e) {
@@ -286,11 +286,11 @@  discard block
 block discarded – undo
286 286
 	}
287 287
 
288 288
 	/**
289
-	* Gets number of latest data entry
290
-	*
291
-	* @return String number of entry
292
-	*
293
-	*/
289
+	 * Gets number of latest data entry
290
+	 *
291
+	 * @return String number of entry
292
+	 *
293
+	 */
294 294
 	public function getLiveSpotterCount($filter = array())
295 295
 	{
296 296
 		global $globalDBdriver, $globalLiveInterval;
@@ -317,11 +317,11 @@  discard block
 block discarded – undo
317 317
 	}
318 318
 
319 319
 	/**
320
-	* Gets all the spotter information based on the latest data entry and coord
321
-	*
322
-	* @return Array the spotter information
323
-	*
324
-	*/
320
+	 * Gets all the spotter information based on the latest data entry and coord
321
+	 *
322
+	 * @return Array the spotter information
323
+	 *
324
+	 */
325 325
 	public function getLiveSpotterDatabyCoord($coord, $filter = array())
326 326
 	{
327 327
 		global $globalDBdriver, $globalLiveInterval;
@@ -346,11 +346,11 @@  discard block
 block discarded – undo
346 346
 	}
347 347
 
348 348
 	/**
349
-	* Gets all the spotter information based on the latest data entry and coord
350
-	*
351
-	* @return Array the spotter information
352
-	*
353
-	*/
349
+	 * Gets all the spotter information based on the latest data entry and coord
350
+	 *
351
+	 * @return Array the spotter information
352
+	 *
353
+	 */
354 354
 	public function getMinLiveSpotterDatabyCoord($coord, $filter = array())
355 355
 	{
356 356
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
@@ -415,11 +415,11 @@  discard block
 block discarded – undo
415 415
 	}
416 416
 
417 417
 	/**
418
-	* Gets all the spotter information based on a user's latitude and longitude
419
-	*
420
-	* @return Array the spotter information
421
-	*
422
-	*/
418
+	 * Gets all the spotter information based on a user's latitude and longitude
419
+	 *
420
+	 * @return Array the spotter information
421
+	 *
422
+	 */
423 423
 	public function getLatestSpotterForLayar($lat, $lng, $radius, $interval)
424 424
 	{
425 425
 		$Spotter = new Spotter($this->db);
@@ -429,98 +429,98 @@  discard block
 block discarded – undo
429 429
 				return false;
430 430
 			}
431 431
 		}
432
-        if ($lng != '')
433
-                {
434
-                        if (!is_numeric($lng))
435
-                        {
436
-                                return false;
437
-                        }
438
-                }
439
-
440
-                if ($radius != '')
441
-                {
442
-                        if (!is_numeric($radius))
443
-                        {
444
-                                return false;
445
-                        }
446
-                }
432
+		if ($lng != '')
433
+				{
434
+						if (!is_numeric($lng))
435
+						{
436
+								return false;
437
+						}
438
+				}
439
+
440
+				if ($radius != '')
441
+				{
442
+						if (!is_numeric($radius))
443
+						{
444
+								return false;
445
+						}
446
+				}
447 447
 		$additional_query = '';
448
-        if ($interval != '')
449
-                {
450
-                        if (!is_string($interval))
451
-                        {
452
-                                //$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date ';
453
-			        return false;
454
-                        } else {
455
-                if ($interval == '1m')
456
-                {
457
-                    $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date ';
458
-                } else if ($interval == '15m'){
459
-                    $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= spotter_live.date ';
460
-                } 
461
-            }
462
-                } else {
463
-         $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date ';   
464
-        }
465
-
466
-                $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 
448
+		if ($interval != '')
449
+				{
450
+						if (!is_string($interval))
451
+						{
452
+								//$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date ';
453
+					return false;
454
+						} else {
455
+				if ($interval == '1m')
456
+				{
457
+					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date ';
458
+				} else if ($interval == '15m'){
459
+					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= spotter_live.date ';
460
+				} 
461
+			}
462
+				} else {
463
+		 $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date ';   
464
+		}
465
+
466
+				$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 
467 467
                    WHERE spotter_live.latitude <> '' 
468 468
                                    AND spotter_live.longitude <> '' 
469 469
                    ".$additional_query."
470 470
                    HAVING distance < :radius  
471 471
                                    ORDER BY distance";
472 472
 
473
-                $spotter_array = $Spotter->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius));
473
+				$spotter_array = $Spotter->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius));
474 474
 
475
-                return $spotter_array;
476
-        }
475
+				return $spotter_array;
476
+		}
477 477
 
478 478
     
479
-        /**
480
-	* Gets all the spotter information based on a particular callsign
481
-	*
482
-	* @return Array the spotter information
483
-	*
484
-	*/
479
+		/**
480
+		 * Gets all the spotter information based on a particular callsign
481
+		 *
482
+		 * @return Array the spotter information
483
+		 *
484
+		 */
485 485
 	public function getLastLiveSpotterDataByIdent($ident)
486 486
 	{
487 487
 		$Spotter = new Spotter($this->db);
488 488
 		date_default_timezone_set('UTC');
489 489
 
490 490
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
491
-                $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';
491
+				$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';
492 492
 
493 493
 		$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident),'',true);
494 494
 
495 495
 		return $spotter_array;
496 496
 	}
497 497
 
498
-        /**
499
-	* Gets all the spotter information based on a particular callsign
500
-	*
501
-	* @return Array the spotter information
502
-	*
503
-	*/
498
+		/**
499
+		 * Gets all the spotter information based on a particular callsign
500
+		 *
501
+		 * @return Array the spotter information
502
+		 *
503
+		 */
504 504
 	public function getDateLiveSpotterDataByIdent($ident,$date)
505 505
 	{
506 506
 		$Spotter = new Spotter($this->db);
507 507
 		date_default_timezone_set('UTC');
508 508
 
509 509
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
510
-                $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';
510
+				$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';
511 511
 
512
-                $date = date('c',$date);
512
+				$date = date('c',$date);
513 513
 		$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident,':date' => $date));
514 514
 
515 515
 		return $spotter_array;
516 516
 	}
517 517
 
518
-        /**
519
-	* Gets last spotter information based on a particular callsign
520
-	*
521
-	* @return Array the spotter information
522
-	*
523
-	*/
518
+		/**
519
+		 * Gets last spotter information based on a particular callsign
520
+		 *
521
+		 * @return Array the spotter information
522
+		 *
523
+		 */
524 524
 	public function getLastLiveSpotterDataById($id)
525 525
 	{
526 526
 		$Spotter = new Spotter($this->db);
@@ -531,12 +531,12 @@  discard block
 block discarded – undo
531 531
 		return $spotter_array;
532 532
 	}
533 533
 
534
-        /**
535
-	* Gets last spotter information based on a particular callsign
536
-	*
537
-	* @return Array the spotter information
538
-	*
539
-	*/
534
+		/**
535
+		 * Gets last spotter information based on a particular callsign
536
+		 *
537
+		 * @return Array the spotter information
538
+		 *
539
+		 */
540 540
 	public function getDateLiveSpotterDataById($id,$date)
541 541
 	{
542 542
 		$Spotter = new Spotter($this->db);
@@ -549,21 +549,21 @@  discard block
 block discarded – undo
549 549
 		return $spotter_array;
550 550
 	}
551 551
 
552
-        /**
553
-	* Gets altitude information based on a particular callsign
554
-	*
555
-	* @return Array the spotter information
556
-	*
557
-	*/
552
+		/**
553
+		 * Gets altitude information based on a particular callsign
554
+		 *
555
+		 * @return Array the spotter information
556
+		 *
557
+		 */
558 558
 	public function getAltitudeLiveSpotterDataByIdent($ident)
559 559
 	{
560 560
 
561 561
 		date_default_timezone_set('UTC');
562 562
 
563 563
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
564
-                $query  = 'SELECT spotter_live.altitude, spotter_live.date FROM spotter_live WHERE spotter_live.ident = :ident';
564
+				$query  = 'SELECT spotter_live.altitude, spotter_live.date FROM spotter_live WHERE spotter_live.ident = :ident';
565 565
 
566
-    		try {
566
+			try {
567 567
 			
568 568
 			$sth = $this->db->prepare($query);
569 569
 			$sth->execute(array(':ident' => $ident));
@@ -576,12 +576,12 @@  discard block
 block discarded – undo
576 576
 		return $spotter_array;
577 577
 	}
578 578
 
579
-        /**
580
-	* Gets all the spotter information based on a particular id
581
-	*
582
-	* @return Array the spotter information
583
-	*
584
-	*/
579
+		/**
580
+		 * Gets all the spotter information based on a particular id
581
+		 *
582
+		 * @return Array the spotter information
583
+		 *
584
+		 */
585 585
 	public function getAllLiveSpotterDataById($id,$liveinterval = false)
586 586
 	{
587 587
 		global $globalDBdriver, $globalLiveInterval;
@@ -609,18 +609,18 @@  discard block
 block discarded – undo
609 609
 		return $spotter_array;
610 610
 	}
611 611
 
612
-        /**
613
-	* Gets all the spotter information based on a particular ident
614
-	*
615
-	* @return Array the spotter information
616
-	*
617
-	*/
612
+		/**
613
+		 * Gets all the spotter information based on a particular ident
614
+		 *
615
+		 * @return Array the spotter information
616
+		 *
617
+		 */
618 618
 	public function getAllLiveSpotterDataByIdent($ident)
619 619
 	{
620 620
 		date_default_timezone_set('UTC');
621 621
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
622 622
 		$query  = self::$global_query.' WHERE spotter_live.ident = :ident';
623
-    		try {
623
+			try {
624 624
 			
625 625
 			$sth = $this->db->prepare($query);
626 626
 			$sth->execute(array(':ident' => $ident));
@@ -634,23 +634,23 @@  discard block
 block discarded – undo
634 634
 
635 635
 
636 636
 	/**
637
-	* Deletes all info in the table
638
-	*
639
-	* @return String success or false
640
-	*
641
-	*/
637
+	 * Deletes all info in the table
638
+	 *
639
+	 * @return String success or false
640
+	 *
641
+	 */
642 642
 	public function deleteLiveSpotterData()
643 643
 	{
644 644
 		global $globalDBdriver;
645 645
 		if ($globalDBdriver == 'mysql') {
646 646
 			//$query  = "DELETE FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE) >= spotter_live.date";
647 647
 			$query  = 'DELETE FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 9 HOUR) >= spotter_live.date';
648
-            		//$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)";
648
+					//$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)";
649 649
 		} else {
650 650
 			$query  = "DELETE FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= spotter_live.date";
651 651
 		}
652 652
         
653
-    		try {
653
+			try {
654 654
 			
655 655
 			$sth = $this->db->prepare($query);
656 656
 			$sth->execute();
@@ -662,18 +662,18 @@  discard block
 block discarded – undo
662 662
 	}
663 663
 
664 664
 	/**
665
-	* Deletes all info in the table for aircraft not seen since 2 HOUR
666
-	*
667
-	* @return String success or false
668
-	*
669
-	*/
665
+	 * Deletes all info in the table for aircraft not seen since 2 HOUR
666
+	 *
667
+	 * @return String success or false
668
+	 *
669
+	 */
670 670
 	public function deleteLiveSpotterDataNotUpdated()
671 671
 	{
672 672
 		global $globalDBdriver, $globalDebug;
673 673
 		if ($globalDBdriver == 'mysql') {
674 674
 			//$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';
675
-    			$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";
676
-    			try {
675
+				$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";
676
+				try {
677 677
 				
678 678
 				$sth = $this->db->prepare($query);
679 679
 				$sth->execute();
@@ -681,8 +681,8 @@  discard block
 block discarded – undo
681 681
 				return "error";
682 682
 			}
683 683
 			$query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN (';
684
-                        $i = 0;
685
-                        $j =0;
684
+						$i = 0;
685
+						$j =0;
686 686
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
687 687
 			foreach($all as $row)
688 688
 			{
@@ -690,20 +690,20 @@  discard block
 block discarded – undo
690 690
 				$j++;
691 691
 				if ($j == 30) {
692 692
 					if ($globalDebug) echo ".";
693
-				    	try {
693
+						try {
694 694
 						
695 695
 						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
696 696
 						$sth->execute();
697 697
 					} catch(PDOException $e) {
698 698
 						return "error";
699 699
 					}
700
-                                	$query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN (';
701
-                                	$j = 0;
700
+									$query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN (';
701
+									$j = 0;
702 702
 				}
703 703
 				$query_delete .= "'".$row['flightaware_id']."',";
704 704
 			}
705 705
 			if ($i > 0) {
706
-    				try {
706
+					try {
707 707
 					
708 708
 					$sth = $this->db->prepare(substr($query_delete,0,-1).")");
709 709
 					$sth->execute();
@@ -714,9 +714,9 @@  discard block
 block discarded – undo
714 714
 			return "success";
715 715
 		} elseif ($globalDBdriver == 'pgsql') {
716 716
 			//$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";
717
-    			//$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";
718
-    			$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)";
719
-    			try {
717
+				//$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";
718
+				$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)";
719
+				try {
720 720
 				
721 721
 				$sth = $this->db->prepare($query);
722 722
 				$sth->execute();
@@ -760,17 +760,17 @@  discard block
 block discarded – undo
760 760
 	}
761 761
 
762 762
 	/**
763
-	* Deletes all info in the table for an ident
764
-	*
765
-	* @return String success or false
766
-	*
767
-	*/
763
+	 * Deletes all info in the table for an ident
764
+	 *
765
+	 * @return String success or false
766
+	 *
767
+	 */
768 768
 	public function deleteLiveSpotterDataByIdent($ident)
769 769
 	{
770 770
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
771 771
 		$query  = 'DELETE FROM spotter_live WHERE ident = :ident';
772 772
         
773
-    		try {
773
+			try {
774 774
 			
775 775
 			$sth = $this->db->prepare($query);
776 776
 			$sth->execute(array(':ident' => $ident));
@@ -782,17 +782,17 @@  discard block
 block discarded – undo
782 782
 	}
783 783
 
784 784
 	/**
785
-	* Deletes all info in the table for an id
786
-	*
787
-	* @return String success or false
788
-	*
789
-	*/
785
+	 * Deletes all info in the table for an id
786
+	 *
787
+	 * @return String success or false
788
+	 *
789
+	 */
790 790
 	public function deleteLiveSpotterDataById($id)
791 791
 	{
792 792
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
793 793
 		$query  = 'DELETE FROM spotter_live WHERE flightaware_id = :id';
794 794
         
795
-    		try {
795
+			try {
796 796
 			
797 797
 			$sth = $this->db->prepare($query);
798 798
 			$sth->execute(array(':id' => $id));
@@ -805,11 +805,11 @@  discard block
 block discarded – undo
805 805
 
806 806
 
807 807
 	/**
808
-	* Gets the aircraft ident within the last hour
809
-	*
810
-	* @return String the ident
811
-	*
812
-	*/
808
+	 * Gets the aircraft ident within the last hour
809
+	 *
810
+	 * @return String the ident
811
+	 *
812
+	 */
813 813
 	public function getIdentFromLastHour($ident)
814 814
 	{
815 815
 		global $globalDBdriver, $globalTimezone;
@@ -835,14 +835,14 @@  discard block
 block discarded – undo
835 835
 			$ident_result = $row['ident'];
836 836
 		}
837 837
 		return $ident_result;
838
-        }
838
+		}
839 839
 
840 840
 	/**
841
-	* Check recent aircraft
842
-	*
843
-	* @return String the ident
844
-	*
845
-	*/
841
+	 * Check recent aircraft
842
+	 *
843
+	 * @return String the ident
844
+	 *
845
+	 */
846 846
 	public function checkIdentRecent($ident)
847 847
 	{
848 848
 		global $globalDBdriver, $globalTimezone;
@@ -868,14 +868,14 @@  discard block
 block discarded – undo
868 868
 			$ident_result = $row['flightaware_id'];
869 869
 		}
870 870
 		return $ident_result;
871
-        }
871
+		}
872 872
 
873 873
 	/**
874
-	* Check recent aircraft by id
875
-	*
876
-	* @return String the ident
877
-	*
878
-	*/
874
+	 * Check recent aircraft by id
875
+	 *
876
+	 * @return String the ident
877
+	 *
878
+	 */
879 879
 	public function checkIdRecent($id)
880 880
 	{
881 881
 		global $globalDBdriver, $globalTimezone;
@@ -901,14 +901,14 @@  discard block
 block discarded – undo
901 901
 			$ident_result = $row['flightaware_id'];
902 902
 		}
903 903
 		return $ident_result;
904
-        }
904
+		}
905 905
 
906 906
 	/**
907
-	* Check recent aircraft by ModeS
908
-	*
909
-	* @return String the ModeS
910
-	*
911
-	*/
907
+	 * Check recent aircraft by ModeS
908
+	 *
909
+	 * @return String the ModeS
910
+	 *
911
+	 */
912 912
 	public function checkModeSRecent($modes)
913 913
 	{
914 914
 		global $globalDBdriver, $globalTimezone;
@@ -935,19 +935,19 @@  discard block
 block discarded – undo
935 935
 			$ident_result = $row['flightaware_id'];
936 936
 		}
937 937
 		return $ident_result;
938
-        }
938
+		}
939 939
 
940 940
 	/**
941
-	* Adds a new spotter data
942
-	*
943
-	* @param String $flightaware_id the ID from flightaware
944
-	* @param String $ident the flight ident
945
-	* @param String $aircraft_icao the aircraft type
946
-	* @param String $departure_airport_icao the departure airport
947
-	* @param String $arrival_airport_icao the arrival airport
948
-	* @return String success or false
949
-	*
950
-	*/
941
+	 * Adds a new spotter data
942
+	 *
943
+	 * @param String $flightaware_id the ID from flightaware
944
+	 * @param String $ident the flight ident
945
+	 * @param String $aircraft_icao the aircraft type
946
+	 * @param String $departure_airport_icao the departure airport
947
+	 * @param String $arrival_airport_icao the arrival airport
948
+	 * @return String success or false
949
+	 *
950
+	 */
951 951
 	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 = '')
952 952
 	{
953 953
 		global $globalURL, $globalArchive, $globalDebug;
@@ -1090,10 +1090,10 @@  discard block
 block discarded – undo
1090 1090
 		$arrival_airport_country = '';
1091 1091
 		
1092 1092
             	
1093
-            	if ($squawk == '' || $Common->isInteger($squawk) === false ) $squawk = NULL;
1094
-            	if ($verticalrate == '' || $Common->isInteger($verticalrate) === false ) $verticalrate = NULL;
1095
-            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
1096
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
1093
+				if ($squawk == '' || $Common->isInteger($squawk) === false ) $squawk = NULL;
1094
+				if ($verticalrate == '' || $Common->isInteger($verticalrate) === false ) $verticalrate = NULL;
1095
+				if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
1096
+				if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
1097 1097
 		
1098 1098
 		$query = '';
1099 1099
 		if ($globalArchive) {
@@ -1114,10 +1114,10 @@  discard block
 block discarded – undo
1114 1114
 			return "error : ".$e->getMessage();
1115 1115
 		}
1116 1116
 		if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) {
1117
-		    if ($globalDebug) echo '(Add to SBS archive : ';
1118
-		    $SpotterArchive = new SpotterArchive($this->db);
1119
-		    $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);
1120
-		    if ($globalDebug) echo $result.')';
1117
+			if ($globalDebug) echo '(Add to SBS archive : ';
1118
+			$SpotterArchive = new SpotterArchive($this->db);
1119
+			$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);
1120
+			if ($globalDebug) echo $result.')';
1121 1121
 		} elseif ($globalDebug && $putinarchive !== true) {
1122 1122
 			echo '(Not adding to archive)';
1123 1123
 		} elseif ($globalDebug && $noarchive === true) {
Please login to merge, or discard this patch.
require/class.SpotterImport.php 1 patch
Indentation   +422 added lines, -422 removed lines patch added patch discarded remove patch
@@ -8,20 +8,20 @@  discard block
 block discarded – undo
8 8
 require_once(dirname(__FILE__).'/class.Stats.php');
9 9
 require_once(dirname(__FILE__).'/class.Source.php');
10 10
 if (isset($globalServerAPRS) && $globalServerAPRS) {
11
-    require_once(dirname(__FILE__).'/class.APRS.php');
11
+	require_once(dirname(__FILE__).'/class.APRS.php');
12 12
 }
13 13
 
14 14
 class SpotterImport {
15
-    private $all_flights = array();
16
-    private $last_delete_hourly = 0;
17
-    private $last_delete = 0;
18
-    private $stats = array();
19
-    private $tmd = 0;
20
-    private $source_location = array();
21
-    public $db = null;
22
-    public $nb = 0;
15
+	private $all_flights = array();
16
+	private $last_delete_hourly = 0;
17
+	private $last_delete = 0;
18
+	private $stats = array();
19
+	private $tmd = 0;
20
+	private $source_location = array();
21
+	public $db = null;
22
+	public $nb = 0;
23 23
 
24
-    public function __construct($dbc = null) {
24
+	public function __construct($dbc = null) {
25 25
 	global $globalBeta, $globalServerAPRS, $APRSSpotter, $globalNoDB;
26 26
 	if (!(isset($globalNoDB) && $globalNoDB)) {
27 27
 		$Connection = new Connection($dbc);
@@ -33,14 +33,14 @@  discard block
 block discarded – undo
33 33
 		$currentdate = date('Y-m-d');
34 34
 		$sourcestat = $Stats->getStatsSource($currentdate);
35 35
 		if (!empty($sourcestat)) {
36
-		    foreach($sourcestat as $srcst) {
37
-		    	$type = $srcst['stats_type'];
36
+			foreach($sourcestat as $srcst) {
37
+				$type = $srcst['stats_type'];
38 38
 			if ($type == 'polar' || $type == 'hist') {
39
-			    $source = $srcst['source_name'];
40
-			    $data = $srcst['source_data'];
41
-			    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
42
-	    		}
43
-		    }
39
+				$source = $srcst['source_name'];
40
+				$data = $srcst['source_data'];
41
+				$this->stats[$currentdate][$source][$type] = json_decode($data,true);
42
+				}
43
+			}
44 44
 		}
45 45
 	}
46 46
 	if (isset($globalServerAPRS) && $globalServerAPRS) {
@@ -48,9 +48,9 @@  discard block
 block discarded – undo
48 48
 		//$APRSSpotter->connect();
49 49
 	}
50 50
 
51
-    }
51
+	}
52 52
 
53
-    public function get_Schedule($id,$ident) {
53
+	public function get_Schedule($id,$ident) {
54 54
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
55 55
 	// Get schedule here, so it's done only one time
56 56
 	
@@ -70,42 +70,42 @@  discard block
 block discarded – undo
70 70
 	$operator = $Spotter->getOperator($ident);
71 71
 	$scheduleexist = false;
72 72
 	if ($Schedule->checkSchedule($operator) == 0) {
73
-	    $operator = $Translation->checkTranslation($ident);
74
-	    if ($Schedule->checkSchedule($operator) == 0) {
73
+		$operator = $Translation->checkTranslation($ident);
74
+		if ($Schedule->checkSchedule($operator) == 0) {
75 75
 		$schedule = $Schedule->fetchSchedule($operator);
76 76
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
77
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
78
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
79
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
80
-		    // Should also check if route schedule = route from DB
81
-		    if ($schedule['DepartureAirportIATA'] != '') {
77
+			if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
78
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
79
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
80
+			// Should also check if route schedule = route from DB
81
+			if ($schedule['DepartureAirportIATA'] != '') {
82 82
 			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
83
-			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
84
-			    if (trim($airport_icao) != '') {
83
+				$airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
84
+				if (trim($airport_icao) != '') {
85 85
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
86 86
 				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
87
-			    }
87
+				}
88
+			}
88 89
 			}
89
-		    }
90
-		    if ($schedule['ArrivalAirportIATA'] != '') {
90
+			if ($schedule['ArrivalAirportIATA'] != '') {
91 91
 			if ($this->all_flights[$id]['arrival_airport'] != $Spotter->getAirportIcao($schedule['ArrivalAirportIATA'])) {
92
-			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
93
-			    if (trim($airport_icao) != '') {
92
+				$airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
93
+				if (trim($airport_icao) != '') {
94 94
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
95 95
 				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
96
-			    }
96
+				}
97 97
 			}
98
-		    }
99
-		    $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
98
+			}
99
+			$Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
100 100
 		}
101
-	    } else $scheduleexist = true;
101
+		} else $scheduleexist = true;
102 102
 	} else $scheduleexist = true;
103 103
 	// close connection, at least one way will work ?
104
-       if ($scheduleexist) {
104
+	   if ($scheduleexist) {
105 105
 		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
106
-    		$sch = $Schedule->getSchedule($operator);
106
+			$sch = $Schedule->getSchedule($operator);
107 107
 		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time']));
108
-       }
108
+	   }
109 109
 	$Spotter->db = null;
110 110
 	$Schedule->db = null;
111 111
 	$Translation->db = null;
@@ -120,78 +120,78 @@  discard block
 block discarded – undo
120 120
 	}
121 121
 	  */
122 122
 	}
123
-    }
123
+	}
124 124
 
125
-    public function checkAll() {
125
+	public function checkAll() {
126 126
 	global $globalDebug, $globalNoImport;
127 127
 	if ($globalDebug) echo "Update last seen flights data...\n";
128 128
 	if (!isset($globalNoImport) || $globalNoImport === FALSE) {
129
-	    foreach ($this->all_flights as $key => $flight) {
129
+		foreach ($this->all_flights as $key => $flight) {
130 130
 		if (isset($this->all_flights[$key]['id'])) {
131
-		    //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
132
-    		    $Spotter = new Spotter($this->db);
133
-        	    $real_arrival = $this->arrival($key);
134
-        	    if (isset($this->all_flights[$key]['altitude'])) $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
135
-        	}
136
-	    }
131
+			//echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
132
+				$Spotter = new Spotter($this->db);
133
+				$real_arrival = $this->arrival($key);
134
+				if (isset($this->all_flights[$key]['altitude'])) $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
135
+			}
136
+		}
137
+	}
137 138
 	}
138
-    }
139 139
 
140
-    public function arrival($key) {
140
+	public function arrival($key) {
141 141
 	global $globalClosestMinDist, $globalDebug;
142 142
 	if ($globalDebug) echo 'Update arrival...'."\n";
143 143
 	$Spotter = new Spotter($this->db);
144
-        $airport_icao = '';
145
-        $airport_time = '';
146
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
144
+		$airport_icao = '';
145
+		$airport_time = '';
146
+		if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
147 147
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
148
-	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
149
-    	    if (isset($closestAirports[0])) {
150
-        	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
151
-        	    $airport_icao = $closestAirports[0]['icao'];
152
-        	    $airport_time = $this->all_flights[$key]['datetime'];
153
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
154
-        	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
155
-        	    foreach ($closestAirports as $airport) {
156
-        		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
157
-        		    $airport_icao = $airport['icao'];
158
-        		    $airport_time = $this->all_flights[$key]['datetime'];
159
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
160
-        		    break;
161
-        		}
162
-        	    }
163
-        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
164
-        		$airport_icao = $closestAirports[0]['icao'];
165
-        		$airport_time = $this->all_flights[$key]['datetime'];
166
-        	} else {
167
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
168
-        	}
169
-    	    } else {
170
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
171
-    	    }
148
+		$closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
149
+			if (isset($closestAirports[0])) {
150
+			if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
151
+				$airport_icao = $closestAirports[0]['icao'];
152
+				$airport_time = $this->all_flights[$key]['datetime'];
153
+				if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
154
+			} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
155
+				foreach ($closestAirports as $airport) {
156
+				if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
157
+					$airport_icao = $airport['icao'];
158
+					$airport_time = $this->all_flights[$key]['datetime'];
159
+					if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
160
+					break;
161
+				}
162
+				}
163
+			} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
164
+				$airport_icao = $closestAirports[0]['icao'];
165
+				$airport_time = $this->all_flights[$key]['datetime'];
166
+			} else {
167
+				if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
168
+			}
169
+			} else {
170
+				if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
171
+			}
172 172
 
173
-        } else {
174
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
175
-        }
176
-        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
177
-    }
173
+		} else {
174
+			if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
175
+		}
176
+		return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
177
+	}
178 178
 
179 179
 
180 180
 
181
-    public function del() {
181
+	public function del() {
182 182
 	global $globalDebug, $globalNoImport, $globalNoDB;
183 183
 	// Delete old infos
184 184
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
185 185
 	foreach ($this->all_flights as $key => $flight) {
186
-	    if (isset($flight['lastupdate'])) {
186
+		if (isset($flight['lastupdate'])) {
187 187
 		if ($flight['lastupdate'] < (time()-5900)) {
188
-		    $this->delKey($key);
188
+			$this->delKey($key);
189 189
 		}
190
-	    }
190
+		}
191
+	}
191 192
 	}
192
-    }
193 193
 
194
-    public function delKey($key) {
194
+	public function delKey($key) {
195 195
 	global $globalDebug, $globalNoImport, $globalNoDB;
196 196
 	// Delete old infos
197 197
 	if (isset($this->all_flights[$key]['id'])) {
@@ -206,9 +206,9 @@  discard block
 block discarded – undo
206 206
 		}
207 207
 	}
208 208
 	unset($this->all_flights[$key]);
209
-    }
209
+	}
210 210
 
211
-    public function add($line) {
211
+	public function add($line) {
212 212
 	global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights, $globalServerAPRS, $APRSSpotter, $globalNoImport, $globalNoDB, $globalVA, $globalAircraftMaxUpdate, $globalAircraftMinUpdate, $globalLiveInterval;
213 213
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
214 214
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
@@ -234,20 +234,20 @@  discard block
 block discarded – undo
234 234
 	
235 235
 	// SBS format is CSV format
236 236
 	if(is_array($line) && (isset($line['hex']) || isset($line['id']))) {
237
-	    //print_r($line);
238
-	    if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']);
239
-  	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
237
+		//print_r($line);
238
+		if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']);
239
+  		if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
240 240
 
241 241
 		// Increment message number
242 242
 		if (isset($line['sourcestats']) && $line['sourcestats'] === TRUE) {
243
-		    $current_date = date('Y-m-d');
244
-		    if (isset($line['source_name'])) $source = $line['source_name'];
245
-		    else $source = '';
246
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
247
-		    if (!isset($this->stats[$current_date][$source]['msg'])) {
248
-		    	$this->stats[$current_date][$source]['msg']['date'] = time();
249
-		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
250
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
243
+			$current_date = date('Y-m-d');
244
+			if (isset($line['source_name'])) $source = $line['source_name'];
245
+			else $source = '';
246
+			if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
247
+			if (!isset($this->stats[$current_date][$source]['msg'])) {
248
+				$this->stats[$current_date][$source]['msg']['date'] = time();
249
+				$this->stats[$current_date][$source]['msg']['nb'] = 1;
250
+			} else $this->stats[$current_date][$source]['msg']['nb'] += 1;
251 251
 		}
252 252
 		
253 253
 		/*
@@ -263,54 +263,54 @@  discard block
 block discarded – undo
263 263
 		//$this->db = $dbc;
264 264
 
265 265
 		//$hex = trim($line['hex']);
266
-	        if (!isset($line['id'])) $id = trim($line['hex']);
267
-	        else $id = trim($line['id']);
266
+			if (!isset($line['id'])) $id = trim($line['hex']);
267
+			else $id = trim($line['id']);
268 268
 		
269 269
 		if (!isset($this->all_flights[$id])) {
270
-		    if ($globalDebug) echo 'New flight...'."\n";
271
-		    $this->all_flights[$id] = array();
272
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
273
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '','altitude_previous' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
274
-		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
275
-		    if (!isset($line['id'])) {
270
+			if ($globalDebug) echo 'New flight...'."\n";
271
+			$this->all_flights[$id] = array();
272
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
273
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '','altitude_previous' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
274
+			if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
275
+			if (!isset($line['id'])) {
276 276
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
277 277
 //			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
278 278
 //			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
279 279
 			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
280
-		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
281
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
282
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
280
+				//else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
281
+			 } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
282
+			if ($globalAllFlights !== FALSE) $dataFound = true;
283 283
 		}
284 284
 		if (isset($line['source_type']) && $line['source_type'] != '') {
285
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
285
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
286 286
 		}
287 287
 		
288 288
 		//print_r($this->all_flights);
289 289
 		if (isset($line['hex']) && !isset($this->all_flights[$id]['hex']) && ctype_xdigit($line['hex'])) {
290
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
291
-		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
290
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
291
+			//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
292 292
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
293
-		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
294
-		    if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????') && $line['format_source'] != 'whazzup' && $line['format_source'] != 'vatsimtxt' && $line['format_source'] != 'pireps' && $line['format_source'] != 'phpvmacars' && $line['format_source'] != 'vam' && $line['format_source'] != 'flightgearsp' && $line['format_source'] != 'flightgearmp') {
293
+			//} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
294
+			if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????') && $line['format_source'] != 'whazzup' && $line['format_source'] != 'vatsimtxt' && $line['format_source'] != 'pireps' && $line['format_source'] != 'phpvmacars' && $line['format_source'] != 'vam' && $line['format_source'] != 'flightgearsp' && $line['format_source'] != 'flightgearmp') {
295 295
 			$timeelapsed = microtime(true);
296 296
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
297
-			    $Spotter = new Spotter($this->db);
298
-			    if (isset($this->all_flights[$id]['source_type'])) {
297
+				$Spotter = new Spotter($this->db);
298
+				if (isset($this->all_flights[$id]['source_type'])) {
299 299
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']),$this->all_flights[$id]['source_type']);
300
-			    } else {
300
+				} else {
301 301
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
302
-			    }
303
-			    $Spotter->db = null;
304
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
305
-			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
302
+				}
303
+				$Spotter->db = null;
304
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
305
+				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
306 306
 			}
307
-		    }
308
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
309
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
307
+			}
308
+			if ($globalAllFlights !== FALSE) $dataFound = true;
309
+			if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
310 310
 		}
311
-	        if (isset($line['id']) && !isset($line['hex'])) {
312
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
313
-	        }
311
+			if (isset($line['id']) && !isset($line['hex'])) {
312
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
313
+			}
314 314
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
315 315
 			$icao = $line['aircraft_icao'];
316 316
 			$Spotter = new Spotter($this->db);
@@ -339,9 +339,9 @@  discard block
 block discarded – undo
339 339
 		}
340 340
 		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
341 341
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60 && strtotime($line['datetime']) < time()+20*60) {
342
-		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
342
+			if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
343 343
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
344
-		    } else {
344
+			} else {
345 345
 				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
346 346
 				elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
347 347
 				/*
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
 				print_r($line);
351 351
 				*/
352 352
 				return '';
353
-		    }
353
+			}
354 354
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) {
355 355
 			if ($globalDebug) echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n";
356 356
 			return '';
@@ -367,21 +367,21 @@  discard block
 block discarded – undo
367 367
 		}
368 368
 
369 369
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') {
370
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
370
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
371 371
 		}
372 372
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
373
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
373
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
374 374
 		}
375 375
 		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
376
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => trim($line['pilot_id'])));
376
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => trim($line['pilot_id'])));
377 377
 		}
378 378
 		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
379
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => trim($line['pilot_name'])));
379
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => trim($line['pilot_name'])));
380 380
 		}
381 381
  
382 382
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) {
383 383
 
384
-		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
384
+			if ($this->all_flights[$id]['addedSpotter'] == 1) {
385 385
 			if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
386 386
 				if ($globalDebug) echo '---!!!! New ident, reset aircraft data...'."\n";
387 387
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
@@ -390,23 +390,23 @@  discard block
 block discarded – undo
390 390
 				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
391 391
 				elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
392 392
 			} else {
393
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
394
-			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
393
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
394
+				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
395 395
 				$timeelapsed = microtime(true);
396
-            			$Spotter = new Spotter($this->db);
397
-            			$fromsource = NULL;
398
-            			if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
399
-            			elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
396
+						$Spotter = new Spotter($this->db);
397
+						$fromsource = NULL;
398
+						if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
399
+						elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
400 400
 				elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
401 401
 				elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
402 402
 				elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
403
-            			$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
403
+						$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
404 404
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
405 405
 				$Spotter->db = null;
406 406
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
407
-			    }
407
+				}
408 408
 			}
409
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
409
+			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
410 410
 		    
411 411
 /*
412 412
 		    if (!isset($line['id'])) {
@@ -416,63 +416,63 @@  discard block
 block discarded – undo
416 416
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
417 417
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
418 418
   */
419
-		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
419
+			if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
420 420
 
421
-		    //$putinarchive = true;
422
-		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
421
+			//$putinarchive = true;
422
+			if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
423 423
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
424
-		    }
425
-		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
424
+			}
425
+			if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
426 426
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
427
-		    }
428
-		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
429
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
430
-		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
427
+			}
428
+			if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
429
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
430
+			} elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
431 431
 			$timeelapsed = microtime(true);
432 432
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
433 433
 				$Spotter = new Spotter($this->db);
434 434
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
435 435
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
436
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
436
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
437 437
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
438
-                        }
439
-		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
438
+						}
439
+			} elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
440 440
 			$timeelapsed = microtime(true);
441 441
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
442
-			    $Spotter = new Spotter($this->db);
443
-			    $route = $Spotter->getRouteInfo(trim($line['ident']));
444
-			    if (!isset($route['fromairport_icao']) && !isset($route['toairport_icao'])) {
442
+				$Spotter = new Spotter($this->db);
443
+				$route = $Spotter->getRouteInfo(trim($line['ident']));
444
+				if (!isset($route['fromairport_icao']) && !isset($route['toairport_icao'])) {
445 445
 				$Translation = new Translation($this->db);
446 446
 				$ident = $Translation->checkTranslation(trim($line['ident']));
447 447
 				$route = $Spotter->getRouteInfo($ident);
448 448
 				$Translation->db = null;
449
-			    }
450
-			    $Spotter->db = null;
451
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
452
-                    	}
449
+				}
450
+				$Spotter->db = null;
451
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
452
+						}
453 453
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
454
-			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
455
-			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
454
+				//if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
455
+				if ($route['fromairport_icao'] != $route['toairport_icao']) {
456 456
 				//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['FromAirport_ICAO'],'arrival_airport' => $route['ToAirport_ICAO'],'route_stop' => $route['RouteStop']));
457
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
458
-		    	    }
457
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
458
+					}
459 459
 			}
460 460
 			if (!isset($globalFork)) $globalFork = TRUE;
461 461
 			if (!$globalVA && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
462 462
 				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
463 463
 			}
464
-		    }
464
+			}
465 465
 		}
466 466
 
467 467
 		if (isset($line['speed']) && $line['speed'] != '' && $line['speed'] != 0) {
468 468
 		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
469
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
470
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
471
-		    //$dataFound = true;
469
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
470
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
471
+			//$dataFound = true;
472 472
 		} else if (!isset($this->all_flights[$id]['speed_fromsrc']) && isset($this->all_flights[$id]['time_last_coord']) && $this->all_flights[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
473
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
474
-		    if ($distance > 1000 && $distance < 10000) {
475
-		    // use datetime
473
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
474
+			if ($distance > 1000 && $distance < 10000) {
475
+			// use datetime
476 476
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
477 477
 			$speed = $speed*3.6;
478 478
 			if ($speed < 1000) {
@@ -481,48 +481,48 @@  discard block
 block discarded – undo
481 481
 	  		} else {
482 482
 	  			if ($globalDebug) echo "ø IGNORED : Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
483 483
 	  		}
484
-		    }
484
+			}
485 485
 		}
486 486
 
487 487
 
488 488
 
489
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
490
-	    	    if (ctype_digit(strval($line['latitude'])) || ctype_digit(strval($line['longitude']))) {
491
-	    	    	if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
492
-	    	    	return false;
493
-	    	    }
494
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
495
-	    	    else unset($timediff);
496
-	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
497
-	    	    else unset($timediff_archive);
498
-	    	    if ($this->tmd > 5
499
-	    	        || (isset($line['format_source']) 
500
-	    	    	    && $line['format_source'] == 'airwhere' 
501
-	    	    	    && ((!isset($this->all_flights[$id]['latitude']) 
502
-	    	    		|| !isset($this->all_flights[$id]['longitude'])) 
503
-	    	    		|| (isset($this->all_flights[$id]['latitude']) 
504
-	    	    		    && isset($this->all_flights[$id]['longitude']) 
505
-	    	    		    && $this->all_flights[$id]['latitude'] != $line['latitude'] 
506
-	    	    		    && $this->all_flights[$id]['longitude'] != $line['longitude']
507
-	    	    		)
508
-	    	    	    )
509
-	    	    	)
510
-	    		|| (isset($globalVA) && $globalVA) 
511
-	    	    	|| (isset($globalIVAO) && $globalIVAO)
512
-	    	    	|| (isset($globalVATSIM) && $globalVATSIM)
513
-	    	    	|| (isset($globalphpVMS) && $globalphpVMS)
514
-	    	    	|| (isset($globalVAM) && $globalVAM)
515
-	    	    	|| !isset($timediff)
516
-	    	    	|| $timediff > $globalLiveInterval
517
-	    	    	|| ($timediff > 30 
518
-	    	    	    && isset($this->all_flights[$id]['latitude']) 
519
-	    	    	    && isset($this->all_flights[$id]['longitude']) 
520
-	    	    	    && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'))
521
-	    	    	    )
522
-	    	    	) {
489
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
490
+				if (ctype_digit(strval($line['latitude'])) || ctype_digit(strval($line['longitude']))) {
491
+					if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
492
+					return false;
493
+				}
494
+				if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
495
+				else unset($timediff);
496
+				if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
497
+				else unset($timediff_archive);
498
+				if ($this->tmd > 5
499
+					|| (isset($line['format_source']) 
500
+						&& $line['format_source'] == 'airwhere' 
501
+						&& ((!isset($this->all_flights[$id]['latitude']) 
502
+						|| !isset($this->all_flights[$id]['longitude'])) 
503
+						|| (isset($this->all_flights[$id]['latitude']) 
504
+							&& isset($this->all_flights[$id]['longitude']) 
505
+							&& $this->all_flights[$id]['latitude'] != $line['latitude'] 
506
+							&& $this->all_flights[$id]['longitude'] != $line['longitude']
507
+						)
508
+						)
509
+					)
510
+				|| (isset($globalVA) && $globalVA) 
511
+					|| (isset($globalIVAO) && $globalIVAO)
512
+					|| (isset($globalVATSIM) && $globalVATSIM)
513
+					|| (isset($globalphpVMS) && $globalphpVMS)
514
+					|| (isset($globalVAM) && $globalVAM)
515
+					|| !isset($timediff)
516
+					|| $timediff > $globalLiveInterval
517
+					|| ($timediff > 30 
518
+						&& isset($this->all_flights[$id]['latitude']) 
519
+						&& isset($this->all_flights[$id]['longitude']) 
520
+						&& $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'))
521
+						)
522
+					) {
523 523
 
524 524
 			if ((isset($timediff) && !isset($timediff_archive)) || (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude']))) {
525
-			    if ((isset($timediff_archive) && $timediff_archive > $globalAircraftMaxUpdate)
525
+				if ((isset($timediff_archive) && $timediff_archive > $globalAircraftMaxUpdate)
526 526
 				|| (isset($line['format_source']) && $line['format_source'] == 'airwhere') 
527 527
 				|| !$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
528 528
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
@@ -530,9 +530,9 @@  discard block
 block discarded – undo
530 530
 				$this->all_flights[$id]['putinarchive'] = true;
531 531
 				$this->tmd = 0;
532 532
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
533
-				    if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
534
-				    $timeelapsed = microtime(true);
535
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
533
+					if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
534
+					$timeelapsed = microtime(true);
535
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
536 536
 					$Spotter = new Spotter($this->db);
537 537
 					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
538 538
 					if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
@@ -540,11 +540,11 @@  discard block
 block discarded – undo
540 540
 					$Spotter->db = null;
541 541
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
542 542
 					if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
543
-				    }
543
+					}
544 544
 				}
545 545
 				$this->all_flights[$id]['time_last_archive_coord'] = time();
546
-			    } 
547
-			    /*
546
+				} 
547
+				/*
548 548
 			    else {
549 549
 				if (!isset($timediff)) echo 'NO TIMEDIFF';
550 550
 				else {
@@ -558,16 +558,16 @@  discard block
 block discarded – undo
558 558
 			}
559 559
 
560 560
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
561
-			    //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
561
+				//if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
562 562
 				if (!isset($this->all_flights[$id]['archive_latitude'])) {
563 563
 					$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
564 564
 					$this->all_flights[$id]['time_last_coord'] = time();
565 565
 				}
566 566
 				//if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs' || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > 0.0001)) {
567 567
 				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > 0.0001)) {
568
-				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
569
-				    $dataFound = true;
570
-				    $this->all_flights[$id]['time_last_coord'] = time();
568
+					$this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
569
+					$dataFound = true;
570
+					$this->all_flights[$id]['time_last_coord'] = time();
571 571
 				}
572 572
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
573 573
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
@@ -578,24 +578,24 @@  discard block
 block discarded – undo
578 578
 				    //$putinarchive = true;
579 579
 				}
580 580
 				*/
581
-			    /*
581
+				/*
582 582
 			    } elseif (isset($this->all_flights[$id]['latitude'])) {
583 583
 				if ($globalDebug) echo '!!! Strange latitude value - diff : '.abs($this->all_flights[$id]['latitude']-$line['latitude']).'- previous lat : '.$this->all_flights[$id]['latitude'].'- new lat : '.$line['latitude']."\n";
584 584
 			    }
585 585
 			    */
586 586
 			}
587 587
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
588
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
589
-			    //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
588
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
589
+				//if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
590 590
 				if (!isset($this->all_flights[$id]['archive_longitude'])) {
591 591
 					$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
592 592
 					$this->all_flights[$id]['time_last_coord'] = time();
593 593
 				}
594 594
 				//if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs' || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > 0.0001)) {
595 595
 				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > 0.0001)) {
596
-				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
597
-				    $dataFound = true;
598
-				    $this->all_flights[$id]['time_last_coord'] = time();
596
+					$this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
597
+					$dataFound = true;
598
+					$this->all_flights[$id]['time_last_coord'] = time();
599 599
 				}
600 600
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
601 601
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
@@ -613,77 +613,77 @@  discard block
 block discarded – undo
613 613
 			    */
614 614
 			}
615 615
 
616
-		    } else if ($globalDebug && $timediff > 30) {
616
+			} else if ($globalDebug && $timediff > 30) {
617 617
 			$this->tmd = $this->tmd + 1;
618 618
 			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
619 619
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
620 620
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
621 621
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
622
-		    }
622
+			}
623 623
 		}
624 624
 		if (isset($line['last_update']) && $line['last_update'] != '') {
625
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
626
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
625
+			if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
626
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
627 627
 		}
628 628
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
629
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
630
-		    //$dataFound = true;
629
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
630
+			//$dataFound = true;
631 631
 		}
632 632
 		if (isset($line['format_source']) && $line['format_source'] != '') {
633
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
633
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
634 634
 		}
635 635
 		if (isset($line['source_name']) && $line['source_name'] != '') {
636
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
636
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
637 637
 		}
638 638
 		if (isset($line['emergency']) && $line['emergency'] != '') {
639
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
640
-		    //$dataFound = true;
639
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
640
+			//$dataFound = true;
641 641
 		}
642 642
 		if (isset($line['ground']) && $line['ground'] != '') {
643
-		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
643
+			if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
644 644
 			// Here we force archive of flight because after ground it's a new one (or should be)
645 645
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
646 646
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
647 647
 			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
648
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
648
+				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
649 649
 			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
650
-		    }
651
-		    if ($line['ground'] != 1) $line['ground'] = 0;
652
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
653
-		    //$dataFound = true;
650
+			}
651
+			if ($line['ground'] != 1) $line['ground'] = 0;
652
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
653
+			//$dataFound = true;
654 654
 		}
655 655
 		if (isset($line['squawk']) && $line['squawk'] != '') {
656
-		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
657
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
658
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
659
-			    $highlight = '';
660
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
661
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
662
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
663
-			    if ($highlight != '') {
656
+			if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
657
+				if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
658
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
659
+				$highlight = '';
660
+				if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
661
+				if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
662
+				if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
663
+				if ($highlight != '') {
664 664
 				$timeelapsed = microtime(true);
665 665
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
666
-				    $Spotter = new Spotter($this->db);
667
-				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
668
-				    $Spotter->db = null;
669
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
666
+					$Spotter = new Spotter($this->db);
667
+					$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
668
+					$Spotter->db = null;
669
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
670 670
 				}
671 671
 				//$putinarchive = true;
672 672
 				//$highlight = '';
673
-			    }
673
+				}
674 674
 			    
675
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
676
-		    //$dataFound = true;
675
+			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
676
+			//$dataFound = true;
677 677
 		}
678 678
 
679 679
 		if (isset($line['altitude']) && $line['altitude'] != '') {
680
-		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
680
+			//if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
681 681
 			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
682 682
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
683 683
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
684 684
 			//$dataFound = true;
685
-		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
686
-		    if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
685
+			//} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
686
+			if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
687 687
 			if (isset($this->all_flights[$id]['over_country']) && $this->all_flights[$id]['over_country'] != '' && isset($this->all_flights[$id]['altitude_previous']) && $this->all_flights[$id]['altitude_previous'] != '' && $this->all_flights[$id]['altitude_previous'] < $this->all_flights[$id]['altitude_real'] && isset($this->all_flights[$id]['lastupdate']) && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
688 688
 				if ($globalDebug) echo '--- Reset because of altitude'."\n";
689 689
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
@@ -692,27 +692,27 @@  discard block
 block discarded – undo
692 692
 				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
693 693
 				elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
694 694
 			}
695
-		    }
696
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
695
+			}
696
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
697 697
 		}
698 698
 
699 699
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
700
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
700
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
701 701
 		}
702 702
 		
703 703
 		if (isset($line['heading']) && $line['heading'] != '') {
704
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
705
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
706
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
707
-		    //$dataFound = true;
704
+			if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
705
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
706
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
707
+			//$dataFound = true;
708 708
   		} elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) {
709
-  		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
710
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
711
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
712
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['id']." : ".$heading."\n";
709
+  			$heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
710
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
711
+			if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
712
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['id']." : ".$heading."\n";
713 713
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
714
-  		    // If not enough messages and ACARS set heading to 0
715
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
714
+  			// If not enough messages and ACARS set heading to 0
715
+  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
716 716
   		}
717 717
 		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
718 718
 		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
@@ -725,125 +725,125 @@  discard block
 block discarded – undo
725 725
 		//if ($dataFound === true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['heading'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
726 726
 		//if ($dataFound === true && isset($this->all_flights[$id]['hex'])) {
727 727
 		if ($dataFound === true && isset($this->all_flights[$id]['id'])) {
728
-		    $this->all_flights[$id]['lastupdate'] = time();
729
-		    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
730
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
731
-			    //print_r($this->all_flights);
732
-			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
733
-			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
734
-			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
728
+			$this->all_flights[$id]['lastupdate'] = time();
729
+			if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
730
+				if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
731
+				//print_r($this->all_flights);
732
+				//echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
733
+				//$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
734
+				if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
735 735
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
736
-				    if ($globalDebug) echo "Check if aircraft is already in DB...";
737
-				    $timeelapsed = microtime(true);
738
-				    $SpotterLive = new SpotterLive($this->db);
739
-				    if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
736
+					if ($globalDebug) echo "Check if aircraft is already in DB...";
737
+					$timeelapsed = microtime(true);
738
+					$SpotterLive = new SpotterLive($this->db);
739
+					if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
740 740
 					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
741 741
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
742
-				    } elseif (isset($line['id'])) {
742
+					} elseif (isset($line['id'])) {
743 743
 					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
744 744
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
745
-				    } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
745
+					} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
746 746
 					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
747 747
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
748
-				    } else $recent_ident = '';
749
-				    $SpotterLive->db=null;
750
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
751
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
748
+					} else $recent_ident = '';
749
+					$SpotterLive->db=null;
750
+					if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
751
+					elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
752 752
 				} else $recent_ident = '';
753
-			    } else {
753
+				} else {
754 754
 				$recent_ident = '';
755 755
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
756
-			    }
757
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
758
-			    if($recent_ident == "")
759
-			    {
756
+				}
757
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
758
+				if($recent_ident == "")
759
+				{
760 760
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
761 761
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
762 762
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
763 763
 				//adds the spotter data for the archive
764 764
 				$ignoreImport = false;
765 765
 				foreach($globalAirportIgnore as $airportIgnore) {
766
-				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
766
+					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
767 767
 					$ignoreImport = true;
768
-				    }
768
+					}
769 769
 				}
770 770
 				if (count($globalAirportAccept) > 0) {
771
-				    $ignoreImport = true;
772
-				    foreach($globalAirportIgnore as $airportIgnore) {
771
+					$ignoreImport = true;
772
+					foreach($globalAirportIgnore as $airportIgnore) {
773 773
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
774
-					    $ignoreImport = false;
774
+						$ignoreImport = false;
775
+					}
775 776
 					}
776
-				    }
777 777
 				}
778 778
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
779
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
779
+					foreach($globalAirlineIgnore as $airlineIgnore) {
780 780
 					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
781
-					    $ignoreImport = true;
781
+						$ignoreImport = true;
782
+					}
782 783
 					}
783
-				    }
784 784
 				}
785 785
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
786
-				    $ignoreImport = true;
787
-				    foreach($globalAirlineAccept as $airlineAccept) {
786
+					$ignoreImport = true;
787
+					foreach($globalAirlineAccept as $airlineAccept) {
788 788
 					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
789
-					    $ignoreImport = false;
789
+						$ignoreImport = false;
790
+					}
790 791
 					}
791
-				    }
792 792
 				}
793 793
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
794
-				    $ignoreImport = true;
795
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
794
+					$ignoreImport = true;
795
+					foreach($globalPilotIdAccept as $pilotIdAccept) {
796 796
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
797
-					    $ignoreImport = false;
797
+						$ignoreImport = false;
798
+					}
798 799
 					}
799
-				    }
800 800
 				}
801 801
 				
802 802
 				if (!$ignoreImport) {
803
-				    $highlight = '';
804
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
805
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
806
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
807
-				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
808
-				    $timeelapsed = microtime(true);
809
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
803
+					$highlight = '';
804
+					if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
805
+					if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
806
+					if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
807
+					if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
808
+					$timeelapsed = microtime(true);
809
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
810 810
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
811
-					    $Spotter = new Spotter($this->db);
812
-					    $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']);
813
-					    $Spotter->db = null;
814
-					    if ($globalDebug && isset($result)) echo $result."\n";
811
+						$Spotter = new Spotter($this->db);
812
+						$result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']);
813
+						$Spotter->db = null;
814
+						if ($globalDebug && isset($result)) echo $result."\n";
815 815
 					}
816
-				    }
817
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
818
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
816
+					}
817
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
818
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
819 819
 
820
-				    // Add source stat in DB
821
-				    $Stats = new Stats($this->db);
822
-				    if (!empty($this->stats)) {
820
+					// Add source stat in DB
821
+					$Stats = new Stats($this->db);
822
+					if (!empty($this->stats)) {
823 823
 					if ($globalDebug) echo 'Add source stats : ';
824
-				        foreach($this->stats as $date => $data) {
825
-					    foreach($data as $source => $sourced) {
826
-					        //print_r($sourced);
827
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
828
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
829
-				    		if (isset($sourced['msg'])) {
830
-				    		    if (time() - $sourced['msg']['date'] > 10) {
831
-				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
832
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
833
-			    			        unset($this->stats[$date][$source]['msg']);
834
-			    			    }
835
-			    			}
836
-			    		    }
837
-			    		    if ($date != date('Y-m-d')) {
838
-			    			unset($this->stats[$date]);
839
-			    		    }
840
-				    	}
841
-				    	if ($globalDebug) echo 'Done'."\n";
824
+						foreach($this->stats as $date => $data) {
825
+						foreach($data as $source => $sourced) {
826
+							//print_r($sourced);
827
+								if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
828
+								if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
829
+							if (isset($sourced['msg'])) {
830
+								if (time() - $sourced['msg']['date'] > 10) {
831
+									$nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
832
+									echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
833
+									unset($this->stats[$date][$source]['msg']);
834
+								}
835
+							}
836
+							}
837
+							if ($date != date('Y-m-d')) {
838
+							unset($this->stats[$date]);
839
+							}
840
+						}
841
+						if ($globalDebug) echo 'Done'."\n";
842 842
 
843
-				    }
844
-				    $Stats->db = null;
845
-				    }
846
-				    $this->del();
843
+					}
844
+					$Stats->db = null;
845
+					}
846
+					$this->del();
847 847
 				} elseif ($globalDebug) echo 'Ignore data'."\n";
848 848
 				//$ignoreImport = false;
849 849
 				$this->all_flights[$id]['addedSpotter'] = 1;
@@ -861,41 +861,41 @@  discard block
 block discarded – undo
861 861
 			*/
862 862
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
863 863
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
864
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
865
-				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
866
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
864
+					if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
865
+					//SpotterLive->deleteLiveSpotterDataNotUpdated();
866
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
867 867
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
868
-					    $SpotterLive = new SpotterLive($this->db);
869
-					    $SpotterLive->deleteLiveSpotterData();
870
-					    $SpotterLive->db=null;
868
+						$SpotterLive = new SpotterLive($this->db);
869
+						$SpotterLive->deleteLiveSpotterData();
870
+						$SpotterLive->db=null;
871 871
 					}
872
-				    }
873
-				    if ($globalDebug) echo " Done\n";
874
-				    $this->last_delete = time();
872
+					}
873
+					if ($globalDebug) echo " Done\n";
874
+					$this->last_delete = time();
875 875
 				}
876
-			    } else {
876
+				} else {
877 877
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt'|| $line['format_source'] === 'planeupdatefaa'  || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'famaprs' || $line['format_source'] === 'airwhere')) {
878
-				    $this->all_flights[$id]['id'] = $recent_ident;
879
-				    $this->all_flights[$id]['addedSpotter'] = 1;
878
+					$this->all_flights[$id]['id'] = $recent_ident;
879
+					$this->all_flights[$id]['addedSpotter'] = 1;
880 880
 				}
881 881
 				if (isset($globalDaemon) && !$globalDaemon) {
882
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
882
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
883 883
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
884
-					    $Spotter = new Spotter($this->db);
885
-					    $Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']);
886
-					    $Spotter->db = null;
884
+						$Spotter = new Spotter($this->db);
885
+						$Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']);
886
+						$Spotter->db = null;
887
+					}
887 888
 					}
888
-				    }
889 889
 				}
890 890
 				
891
-			    }
891
+				}
892 892
 			}
893
-		    }
894
-		    //adds the spotter LIVE data
895
-		    //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
896
-		    //echo "\nAdd in Live !! \n";
897
-		    //echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n";
898
-		    if ($globalDebug) {
893
+			}
894
+			//adds the spotter LIVE data
895
+			//SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
896
+			//echo "\nAdd in Live !! \n";
897
+			//echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n";
898
+			if ($globalDebug) {
899 899
 			if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
900 900
 				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";
901 901
 				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
@@ -903,60 +903,60 @@  discard block
 block discarded – undo
903 903
 				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";
904 904
 				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";
905 905
 			}
906
-		    }
907
-		    $ignoreImport = false;
908
-		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
909
-		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
906
+			}
907
+			$ignoreImport = false;
908
+			if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
909
+			if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
910 910
 
911
-		    foreach($globalAirportIgnore as $airportIgnore) {
912
-		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
913
-			    $ignoreImport = true;
911
+			foreach($globalAirportIgnore as $airportIgnore) {
912
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
913
+				$ignoreImport = true;
914
+			}
914 915
 			}
915
-		    }
916
-		    if (count($globalAirportAccept) > 0) {
917
-		        $ignoreImport = true;
918
-		        foreach($globalAirportIgnore as $airportIgnore) {
919
-			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
916
+			if (count($globalAirportAccept) > 0) {
917
+				$ignoreImport = true;
918
+				foreach($globalAirportIgnore as $airportIgnore) {
919
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
920 920
 				$ignoreImport = false;
921
-			    }
921
+				}
922 922
 			}
923
-		    }
924
-		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
923
+			}
924
+			if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
925 925
 			foreach($globalAirlineIgnore as $airlineIgnore) {
926
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
926
+				if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
927 927
 				$ignoreImport = true;
928
-			    }
928
+				}
929 929
 			}
930
-		    }
931
-		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
930
+			}
931
+			if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
932 932
 			$ignoreImport = true;
933 933
 			foreach($globalAirlineAccept as $airlineAccept) {
934
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
934
+				if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
935 935
 				$ignoreImport = false;
936
-			    }
936
+				}
937
+			}
937 938
 			}
938
-		    }
939
-		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
939
+			if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
940 940
 			$ignoreImport = true;
941 941
 			foreach($globalPilotIdAccept as $pilotIdAccept) {
942
-			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
943
-			        $ignoreImport = false;
944
-			    }
942
+				if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
943
+					$ignoreImport = false;
944
+				}
945
+			}
945 946
 			}
946
-		    }
947 947
 
948
-		    if (!$ignoreImport) {
948
+			if (!$ignoreImport) {
949 949
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
950 950
 				if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
951 951
 				$timeelapsed = microtime(true);
952 952
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
953
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
953
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
954 954
 					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
955 955
 					$SpotterLive = new SpotterLive($this->db);
956 956
 					$result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
957 957
 					$SpotterLive->db = null;
958 958
 					if ($globalDebug) echo $result."\n";
959
-				    }
959
+					}
960 960
 				}
961 961
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) {
962 962
 					$APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
@@ -968,7 +968,7 @@  discard block
 block discarded – undo
968 968
 				//if ($line['format_source'] != 'aprs') {
969 969
 				//if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt')) {
970 970
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
971
-				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
971
+					if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
972 972
 					$source = $this->all_flights[$id]['source_name'];
973 973
 					if ($source == '') $source = $this->all_flights[$id]['format_source'];
974 974
 					if (!isset($this->source_location[$source])) {
@@ -994,7 +994,7 @@  discard block
 block discarded – undo
994 994
 					if ($stats_heading == 16) $stats_heading = 0;
995 995
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
996 996
 						for ($i=0;$i<=15;$i++) {
997
-						    $this->stats[$current_date][$source]['polar'][$i] = 0;
997
+							$this->stats[$current_date][$source]['polar'][$i] = 0;
998 998
 						}
999 999
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
1000 1000
 					} else {
@@ -1007,17 +1007,17 @@  discard block
 block discarded – undo
1007 1007
 					//var_dump($this->stats);
1008 1008
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
1009 1009
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
1010
-						    end($this->stats[$current_date][$source]['hist']);
1011
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
1010
+							end($this->stats[$current_date][$source]['hist']);
1011
+							$mini = key($this->stats[$current_date][$source]['hist'])+10;
1012 1012
 						} else $mini = 0;
1013 1013
 						for ($i=$mini;$i<=$distance;$i+=10) {
1014
-						    $this->stats[$current_date][$source]['hist'][$i] = 0;
1014
+							$this->stats[$current_date][$source]['hist'][$i] = 0;
1015 1015
 						}
1016 1016
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
1017 1017
 					} else {
1018 1018
 						$this->stats[$current_date][$source]['hist'][$distance] += 1;
1019 1019
 					}
1020
-				    }
1020
+					}
1021 1021
 				}
1022 1022
 
1023 1023
 				$this->all_flights[$id]['lastupdate'] = time();
@@ -1027,7 +1027,7 @@  discard block
 block discarded – undo
1027 1027
 			//$this->del();
1028 1028
 			
1029 1029
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
1030
-			    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
1030
+				if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
1031 1031
 				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1032 1032
 				$SpotterLive = new SpotterLive($this->db);
1033 1033
 				$SpotterLive->deleteLiveSpotterDataNotUpdated();
@@ -1035,19 +1035,19 @@  discard block
 block discarded – undo
1035 1035
 				//SpotterLive->deleteLiveSpotterData();
1036 1036
 				if ($globalDebug) echo " Done\n";
1037 1037
 				$this->last_delete_hourly = time();
1038
-			    } else {
1038
+				} else {
1039 1039
 				$this->del();
1040 1040
 				$this->last_delete_hourly = time();
1041
-			    }
1041
+				}
1042 1042
 			}
1043 1043
 			
1044
-		    }
1045
-		    //$ignoreImport = false;
1044
+			}
1045
+			//$ignoreImport = false;
1046 1046
 		}
1047 1047
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
1048 1048
 		if ($send) return $this->all_flights[$id];
1049
-	    }
1049
+		}
1050
+	}
1050 1051
 	}
1051
-    }
1052 1052
 }
1053 1053
 ?>
Please login to merge, or discard this patch.