Completed
Push — master ( abe207...090b05 )
by Yannick
07:26
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.
tracker-data.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -78,10 +78,10 @@  discard block
 block discarded – undo
78 78
 print '<div class="details">';
79 79
 print '<div><span>'._("Altitude").'</span>';
80 80
 if (isset($globalGroundAltitude) && $globalGroundAltitude) {
81
-    try {
81
+	try {
82 82
 	$groundAltitude = $Elevation->getElevation($spotter_item['latitude'],$spotter_item['longitude']);
83
-    } catch(Exception $e) {
84
-    }
83
+	} catch(Exception $e) {
84
+	}
85 85
 }
86 86
 if ((!isset($_COOKIE['unitaltitude']) && isset($globalUnitAltitude) && $globalUnitAltitude == 'feet') || (isset($_COOKIE['unitaltitude']) && $_COOKIE['unitaltitude'] == 'feet')) {
87 87
 	print $spotter_item['altitude'].' feet (FL'.$spotter_item['altitude'].')';
@@ -89,14 +89,14 @@  discard block
 block discarded – undo
89 89
 	print round($spotter_item['altitude']*0.3048).' m (FL'.round($spotter_item['altitude']/100).')';
90 90
 }
91 91
 if (isset($groundAltitude) && $groundAltitude < $spotter_item['altitude']*0.3048) {
92
-    print '<br>';
93
-    print '<span>'._("Ground Altitude").'</span>';
94
-    if ((!isset($_COOKIE['unitaltitude']) && isset($globalUnitAltitude) && $globalUnitAltitude == 'feet') || (isset($_COOKIE['unitaltitude']) && $_COOKIE['unitaltitude'] == 'feet')) {
92
+	print '<br>';
93
+	print '<span>'._("Ground Altitude").'</span>';
94
+	if ((!isset($_COOKIE['unitaltitude']) && isset($globalUnitAltitude) && $globalUnitAltitude == 'feet') || (isset($_COOKIE['unitaltitude']) && $_COOKIE['unitaltitude'] == 'feet')) {
95 95
 	print round($groundAltitude*3.28084).' feet';
96
-    } else {
96
+	} else {
97 97
 	print round($groundAltitude).' m';
98
-    }
99
-    print '</i>';
98
+	}
99
+	print '</i>';
100 100
 }
101 101
 print '</div>';
102 102
 print '<div><span>'._("Speed").'</span>';
Please login to merge, or discard this patch.
install/class.update_schema.php 1 patch
Indentation   +638 added lines, -638 removed lines patch added patch discarded remove patch
@@ -8,18 +8,18 @@  discard block
 block discarded – undo
8 8
 class update_schema {
9 9
 
10 10
 	public static function update_schedule() {
11
-	    $Connection = new Connection();
12
-	    $Schedule = new Schedule();
13
-	    $query = "SELECT * FROM schedule";
14
-            try {
15
-            	$sth = $Connection->db->prepare($query);
11
+		$Connection = new Connection();
12
+		$Schedule = new Schedule();
13
+		$query = "SELECT * FROM schedule";
14
+			try {
15
+				$sth = $Connection->db->prepare($query);
16 16
 		$sth->execute();
17
-    	    } catch(PDOException $e) {
17
+			} catch(PDOException $e) {
18 18
 		return "error : ".$e->getMessage()."\n";
19
-    	    }
20
-    	    while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
21
-    		$Schedule->addSchedule($row['ident'],$row['departure_airport_icao'],$row['departure_airport_time'],$row['arrival_airport_icao'],$row['arrival_airport_time']);
22
-    	    }
19
+			}
20
+			while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
21
+			$Schedule->addSchedule($row['ident'],$row['departure_airport_icao'],$row['departure_airport_time'],$row['arrival_airport_icao'],$row['arrival_airport_time']);
22
+			}
23 23
 	
24 24
 	}
25 25
 /*
@@ -43,198 +43,198 @@  discard block
 block discarded – undo
43 43
     	}
44 44
 */	
45 45
 	private static function update_from_1() {
46
-    		$Connection = new Connection();
47
-    		// Add new column to routes table
48
-    		//$query = "ALTER TABLE `routes` ADD `FromAirport_Time` VARCHAR(10),`ToAirport_Time` VARCHAR(10),`Source` VARCHAR(255),`date_added` DATETIME DEFAULT CURRENT TIMESTAMP,`date_modified` DATETIME,`date_lastseen` DATETIME";
46
+			$Connection = new Connection();
47
+			// Add new column to routes table
48
+			//$query = "ALTER TABLE `routes` ADD `FromAirport_Time` VARCHAR(10),`ToAirport_Time` VARCHAR(10),`Source` VARCHAR(255),`date_added` DATETIME DEFAULT CURRENT TIMESTAMP,`date_modified` DATETIME,`date_lastseen` DATETIME";
49 49
 		$query = "ALTER TABLE `routes` ADD `FromAirport_Time` VARCHAR(10) NULL , ADD `ToAirport_Time` VARCHAR(10) NULL , ADD `Source` VARCHAR(255) NULL, ADD `date_added` timestamp DEFAULT CURRENT_TIMESTAMP, ADD `date_modified` timestamp NULL, ADD `date_lastseen` timestamp NULL";
50
-        	try {
51
-            	    $sth = $Connection->db->prepare($query);
52
-		    $sth->execute();
53
-    		} catch(PDOException $e) {
54
-		    return "error (add new columns to routes table) : ".$e->getMessage()."\n";
55
-    		}
56
-    		// Copy schedules data to routes table
57
-    		self::update_schedule();
58
-    		// Delete schedule table
50
+			try {
51
+					$sth = $Connection->db->prepare($query);
52
+			$sth->execute();
53
+			} catch(PDOException $e) {
54
+			return "error (add new columns to routes table) : ".$e->getMessage()."\n";
55
+			}
56
+			// Copy schedules data to routes table
57
+			self::update_schedule();
58
+			// Delete schedule table
59 59
 		$query = "DROP TABLE `schedule`";
60
-        	try {
61
-            	    $sth = $Connection->db->prepare($query);
62
-		    $sth->execute();
63
-    		} catch(PDOException $e) {
64
-		    return "error (delete schedule table) : ".$e->getMessage()."\n";
65
-    		}
66
-    		// Add source column
67
-    		$query = "ALTER TABLE `aircraft_modes` ADD `Source` VARCHAR(255) NULL";
68
-    		try {
69
-            	    $sth = $Connection->db->prepare($query);
70
-		    $sth->execute();
71
-    		} catch(PDOException $e) {
72
-		    return "error (add source column to aircraft_modes) : ".$e->getMessage()."\n";
73
-    		}
60
+			try {
61
+					$sth = $Connection->db->prepare($query);
62
+			$sth->execute();
63
+			} catch(PDOException $e) {
64
+			return "error (delete schedule table) : ".$e->getMessage()."\n";
65
+			}
66
+			// Add source column
67
+			$query = "ALTER TABLE `aircraft_modes` ADD `Source` VARCHAR(255) NULL";
68
+			try {
69
+					$sth = $Connection->db->prepare($query);
70
+			$sth->execute();
71
+			} catch(PDOException $e) {
72
+			return "error (add source column to aircraft_modes) : ".$e->getMessage()."\n";
73
+			}
74 74
 		// Delete unused column
75 75
 		$query = "ALTER TABLE `aircraft_modes`  DROP `SerialNo`,  DROP `OperatorFlagCode`,  DROP `Manufacturer`,  DROP `Type`,  DROP `FirstRegDate`,  DROP `CurrentRegDate`,  DROP `Country`,  DROP `PreviousID`,  DROP `DeRegDate`,  DROP `Status`,  DROP `PopularName`,  DROP `GenericName`,  DROP `AircraftClass`,  DROP `Engines`,  DROP `OwnershipStatus`,  DROP `RegisteredOwners`,  DROP `MTOW`,  DROP `TotalHours`,  DROP `YearBuilt`,  DROP `CofACategory`,  DROP `CofAExpiry`,  DROP `UserNotes`,  DROP `Interested`,  DROP `UserTag`,  DROP `InfoUrl`,  DROP `PictureUrl1`,  DROP `PictureUrl2`,  DROP `PictureUrl3`,  DROP `UserBool1`,  DROP `UserBool2`,  DROP `UserBool3`,  DROP `UserBool4`,  DROP `UserBool5`,  DROP `UserString1`,  DROP `UserString2`,  DROP `UserString3`,  DROP `UserString4`,  DROP `UserString5`,  DROP `UserInt1`,  DROP `UserInt2`,  DROP `UserInt3`,  DROP `UserInt4`,  DROP `UserInt5`";
76
-    		try {
77
-            	    $sth = $Connection->db->prepare($query);
78
-		    $sth->execute();
79
-    		} catch(PDOException $e) {
80
-		    return "error (Delete unused column of aircraft_modes) : ".$e->getMessage()."\n";
81
-    		}
76
+			try {
77
+					$sth = $Connection->db->prepare($query);
78
+			$sth->execute();
79
+			} catch(PDOException $e) {
80
+			return "error (Delete unused column of aircraft_modes) : ".$e->getMessage()."\n";
81
+			}
82 82
 		// Add ModeS column
83 83
 		$query = "ALTER TABLE `spotter_output`  ADD `ModeS` VARCHAR(255) NULL";
84
-    		try {
85
-            	    $sth = $Connection->db->prepare($query);
86
-		    $sth->execute();
87
-    		} catch(PDOException $e) {
88
-		    return "error (Add ModeS column in spotter_output) : ".$e->getMessage()."\n";
89
-    		}
84
+			try {
85
+					$sth = $Connection->db->prepare($query);
86
+			$sth->execute();
87
+			} catch(PDOException $e) {
88
+			return "error (Add ModeS column in spotter_output) : ".$e->getMessage()."\n";
89
+			}
90 90
 		$query = "ALTER TABLE `spotter_live`  ADD `ModeS` VARCHAR(255)";
91
-    		try {
92
-            	    $sth = $Connection->db->prepare($query);
93
-		    $sth->execute();
94
-    		} catch(PDOException $e) {
95
-		    return "error (Add ModeS column in spotter_live) : ".$e->getMessage()."\n";
96
-    		}
97
-    		// Add auto_increment for aircraft_modes
98
-    		$query = "ALTER TABLE `aircraft_modes` CHANGE `AircraftID` `AircraftID` INT(11) NOT NULL AUTO_INCREMENT";
99
-    		try {
100
-            	    $sth = $Connection->db->prepare($query);
101
-		    $sth->execute();
102
-    		} catch(PDOException $e) {
103
-		    return "error (Add Auto increment in aircraft_modes) : ".$e->getMessage()."\n";
104
-    		}
105
-    		$error = '';
91
+			try {
92
+					$sth = $Connection->db->prepare($query);
93
+			$sth->execute();
94
+			} catch(PDOException $e) {
95
+			return "error (Add ModeS column in spotter_live) : ".$e->getMessage()."\n";
96
+			}
97
+			// Add auto_increment for aircraft_modes
98
+			$query = "ALTER TABLE `aircraft_modes` CHANGE `AircraftID` `AircraftID` INT(11) NOT NULL AUTO_INCREMENT";
99
+			try {
100
+					$sth = $Connection->db->prepare($query);
101
+			$sth->execute();
102
+			} catch(PDOException $e) {
103
+			return "error (Add Auto increment in aircraft_modes) : ".$e->getMessage()."\n";
104
+			}
105
+			$error = '';
106 106
 		$error .= create_db::import_file('../db/acars_live.sql');
107 107
 		$error .= create_db::import_file('../db/config.sql');
108 108
 		// Update schema_version to 2
109 109
 		$query = "UPDATE `config` SET `value` = '2' WHERE `name` = 'schema_version'";
110
-        	try {
111
-            	    $sth = $Connection->db->prepare($query);
112
-		    $sth->execute();
113
-    		} catch(PDOException $e) {
114
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
115
-    		}
110
+			try {
111
+					$sth = $Connection->db->prepare($query);
112
+			$sth->execute();
113
+			} catch(PDOException $e) {
114
+			return "error (update schema_version) : ".$e->getMessage()."\n";
115
+			}
116 116
 		return $error;
117
-        }
117
+		}
118 118
 
119 119
 	private static function update_from_2() {
120
-    		$Connection = new Connection();
121
-    		// Add new column decode to acars_live table
120
+			$Connection = new Connection();
121
+			// Add new column decode to acars_live table
122 122
 		$query = "ALTER TABLE `acars_live` ADD `decode` TEXT";
123
-        	try {
124
-            	    $sth = $Connection->db->prepare($query);
125
-		    $sth->execute();
126
-    		} catch(PDOException $e) {
127
-		    return "error (add new columns to routes table) : ".$e->getMessage()."\n";
128
-    		}
129
-    		$error = '';
130
-    		// Create table acars_archive
123
+			try {
124
+					$sth = $Connection->db->prepare($query);
125
+			$sth->execute();
126
+			} catch(PDOException $e) {
127
+			return "error (add new columns to routes table) : ".$e->getMessage()."\n";
128
+			}
129
+			$error = '';
130
+			// Create table acars_archive
131 131
 		$error .= create_db::import_file('../db/acars_archive.sql');
132 132
 		// Update schema_version to 3
133 133
 		$query = "UPDATE `config` SET `value` = '3' WHERE `name` = 'schema_version'";
134
-        	try {
135
-            	    $sth = $Connection->db->prepare($query);
136
-		    $sth->execute();
137
-    		} catch(PDOException $e) {
138
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
139
-    		}
134
+			try {
135
+					$sth = $Connection->db->prepare($query);
136
+			$sth->execute();
137
+			} catch(PDOException $e) {
138
+			return "error (update schema_version) : ".$e->getMessage()."\n";
139
+			}
140 140
 		return $error;
141 141
 	}
142 142
 
143 143
 	private static function update_from_3() {
144
-    		$Connection = new Connection();
145
-    		// Add default CURRENT_TIMESTAMP to aircraft_modes column FirstCreated
144
+			$Connection = new Connection();
145
+			// Add default CURRENT_TIMESTAMP to aircraft_modes column FirstCreated
146 146
 		$query = "ALTER TABLE `aircraft_modes` CHANGE `FirstCreated` `FirstCreated` timestamp DEFAULT CURRENT_TIMESTAMP";
147
-        	try {
148
-            	    $sth = $Connection->db->prepare($query);
149
-		    $sth->execute();
150
-    		} catch(PDOException $e) {
151
-		    return "error (add new columns to aircraft_modes) : ".$e->getMessage()."\n";
152
-    		}
153
-    		// Add image_source_website column to spotter_image
147
+			try {
148
+					$sth = $Connection->db->prepare($query);
149
+			$sth->execute();
150
+			} catch(PDOException $e) {
151
+			return "error (add new columns to aircraft_modes) : ".$e->getMessage()."\n";
152
+			}
153
+			// Add image_source_website column to spotter_image
154 154
 		$query = "ALTER TABLE `spotter_image` ADD `image_source_website` VARCHAR(999) NULL";
155
-        	try {
156
-            	    $sth = $Connection->db->prepare($query);
157
-		    $sth->execute();
158
-    		} catch(PDOException $e) {
159
-		    return "error (add new columns to spotter_image) : ".$e->getMessage()."\n";
160
-    		}
161
-    		$error = '';
155
+			try {
156
+					$sth = $Connection->db->prepare($query);
157
+			$sth->execute();
158
+			} catch(PDOException $e) {
159
+			return "error (add new columns to spotter_image) : ".$e->getMessage()."\n";
160
+			}
161
+			$error = '';
162 162
 		// Update schema_version to 4
163 163
 		$query = "UPDATE `config` SET `value` = '4' WHERE `name` = 'schema_version'";
164
-        	try {
165
-            	    $sth = $Connection->db->prepare($query);
166
-		    $sth->execute();
167
-    		} catch(PDOException $e) {
168
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
169
-    		}
164
+			try {
165
+					$sth = $Connection->db->prepare($query);
166
+			$sth->execute();
167
+			} catch(PDOException $e) {
168
+			return "error (update schema_version) : ".$e->getMessage()."\n";
169
+			}
170 170
 		return $error;
171 171
 	}
172 172
 	
173 173
 	private static function update_from_4() {
174
-    		$Connection = new Connection();
174
+			$Connection = new Connection();
175 175
 	
176
-    		$error = '';
177
-    		// Create table acars_label
176
+			$error = '';
177
+			// Create table acars_label
178 178
 		$error .= create_db::import_file('../db/acars_label.sql');
179 179
 		if ($error == '') {
180
-		    // Update schema_version to 5
181
-		    $query = "UPDATE `config` SET `value` = '5' WHERE `name` = 'schema_version'";
182
-        	    try {
183
-            		$sth = $Connection->db->prepare($query);
180
+			// Update schema_version to 5
181
+			$query = "UPDATE `config` SET `value` = '5' WHERE `name` = 'schema_version'";
182
+				try {
183
+					$sth = $Connection->db->prepare($query);
184 184
 			$sth->execute();
185
-    		    } catch(PDOException $e) {
185
+				} catch(PDOException $e) {
186 186
 			return "error (update schema_version) : ".$e->getMessage()."\n";
187
-    		    }
188
-    		}
187
+				}
188
+			}
189 189
 		return $error;
190 190
 	}
191 191
 
192 192
 	private static function update_from_5() {
193
-    		$Connection = new Connection();
194
-    		// Add columns to translation
193
+			$Connection = new Connection();
194
+			// Add columns to translation
195 195
 		$query = "ALTER TABLE `translation` ADD `Source` VARCHAR(255) NULL, ADD `date_added` timestamp DEFAULT CURRENT_TIMESTAMP , ADD `date_modified` timestamp DEFAULT CURRENT_TIMESTAMP ;";
196
-        	try {
197
-            	    $sth = $Connection->db->prepare($query);
198
-		    $sth->execute();
199
-    		} catch(PDOException $e) {
200
-		    return "error (add new columns to translation) : ".$e->getMessage()."\n";
201
-    		}
202
-    		// Add aircraft_shadow column to aircraft
203
-    		$query = "ALTER TABLE `aircraft` ADD `aircraft_shadow` VARCHAR(255) NULL";
204
-        	try {
205
-            	    $sth = $Connection->db->prepare($query);
206
-		    $sth->execute();
207
-    		} catch(PDOException $e) {
208
-		    return "error (add new column to aircraft) : ".$e->getMessage()."\n";
209
-    		}
210
-    		// Add aircraft_shadow column to spotter_live
211
-    		$query = "ALTER TABLE `spotter_live` ADD `aircraft_shadow` VARCHAR(255) NULL";
212
-        	try {
213
-            	    $sth = $Connection->db->prepare($query);
214
-		    $sth->execute();
215
-    		} catch(PDOException $e) {
216
-		    return "error (add new column to spotter_live) : ".$e->getMessage()."\n";
217
-    		}
218
-    		$error = '';
219
-    		// Update table aircraft
196
+			try {
197
+					$sth = $Connection->db->prepare($query);
198
+			$sth->execute();
199
+			} catch(PDOException $e) {
200
+			return "error (add new columns to translation) : ".$e->getMessage()."\n";
201
+			}
202
+			// Add aircraft_shadow column to aircraft
203
+			$query = "ALTER TABLE `aircraft` ADD `aircraft_shadow` VARCHAR(255) NULL";
204
+			try {
205
+					$sth = $Connection->db->prepare($query);
206
+			$sth->execute();
207
+			} catch(PDOException $e) {
208
+			return "error (add new column to aircraft) : ".$e->getMessage()."\n";
209
+			}
210
+			// Add aircraft_shadow column to spotter_live
211
+			$query = "ALTER TABLE `spotter_live` ADD `aircraft_shadow` VARCHAR(255) NULL";
212
+			try {
213
+					$sth = $Connection->db->prepare($query);
214
+			$sth->execute();
215
+			} catch(PDOException $e) {
216
+			return "error (add new column to spotter_live) : ".$e->getMessage()."\n";
217
+			}
218
+			$error = '';
219
+			// Update table aircraft
220 220
 		$error .= create_db::import_file('../db/aircraft.sql');
221 221
 		$error .= create_db::import_file('../db/spotter_archive.sql');
222 222
 
223 223
 		// Update schema_version to 6
224 224
 		$query = "UPDATE `config` SET `value` = '6' WHERE `name` = 'schema_version'";
225
-        	try {
226
-            	    $sth = $Connection->db->prepare($query);
227
-		    $sth->execute();
228
-    		} catch(PDOException $e) {
229
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
230
-    		}
225
+			try {
226
+					$sth = $Connection->db->prepare($query);
227
+			$sth->execute();
228
+			} catch(PDOException $e) {
229
+			return "error (update schema_version) : ".$e->getMessage()."\n";
230
+			}
231 231
 		return $error;
232 232
 	}
233 233
 
234 234
 	private static function update_from_6() {
235
-    		$Connection = new Connection();
236
-    		if (!$Connection->indexExists('spotter_output','flightaware_id')) {
237
-    		    $query = "ALTER TABLE spotter_output ADD INDEX(flightaware_id);
235
+			$Connection = new Connection();
236
+			if (!$Connection->indexExists('spotter_output','flightaware_id')) {
237
+				$query = "ALTER TABLE spotter_output ADD INDEX(flightaware_id);
238 238
 			ALTER TABLE spotter_output ADD INDEX(date);
239 239
 			ALTER TABLE spotter_output ADD INDEX(ident);
240 240
 			ALTER TABLE spotter_live ADD INDEX(flightaware_id);
@@ -247,147 +247,147 @@  discard block
 block discarded – undo
247 247
 			ALTER TABLE aircraft ADD INDEX(icao);
248 248
 			ALTER TABLE airport ADD INDEX(icao);
249 249
 			ALTER TABLE translation ADD INDEX(Operator);";
250
-        	    try {
251
-            		$sth = $Connection->db->prepare($query);
250
+				try {
251
+					$sth = $Connection->db->prepare($query);
252 252
 			$sth->execute();
253
-    		    } catch(PDOException $e) {
253
+				} catch(PDOException $e) {
254 254
 			return "error (add some indexes) : ".$e->getMessage()."\n";
255
-    		    }
256
-    		}
257
-    		$error = '';
258
-    		// Update table countries
259
-    		if ($Connection->tableExists('airspace')) {
260
-    		    $error .= update_db::update_countries();
261
-		    if ($error != '') return $error;
255
+				}
256
+			}
257
+			$error = '';
258
+			// Update table countries
259
+			if ($Connection->tableExists('airspace')) {
260
+				$error .= update_db::update_countries();
261
+			if ($error != '') return $error;
262 262
 		}
263 263
 		// Update schema_version to 7
264 264
 		$query = "UPDATE `config` SET `value` = '7' WHERE `name` = 'schema_version'";
265
-        	try {
266
-            	    $sth = $Connection->db->prepare($query);
267
-		    $sth->execute();
268
-    		} catch(PDOException $e) {
269
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
270
-    		}
265
+			try {
266
+					$sth = $Connection->db->prepare($query);
267
+			$sth->execute();
268
+			} catch(PDOException $e) {
269
+			return "error (update schema_version) : ".$e->getMessage()."\n";
270
+			}
271 271
 		return $error;
272
-    	}
272
+		}
273 273
 
274 274
 	private static function update_from_7() {
275 275
 		global $globalDBname, $globalDBdriver;
276
-    		$Connection = new Connection();
277
-    		$query="ALTER TABLE spotter_live ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL;
276
+			$Connection = new Connection();
277
+			$query="ALTER TABLE spotter_live ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL;
278 278
     			ALTER TABLE spotter_output ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL;";
279
-        	try {
280
-            	    $sth = $Connection->db->prepare($query);
281
-		    $sth->execute();
282
-    		} catch(PDOException $e) {
283
-		    return "error (add pilot column to spotter_live and spotter_output) : ".$e->getMessage()."\n";
284
-    		}
285
-    		if ($globalDBdriver == 'mysql') {
286
-    		    $query = "SELECT ENGINE FROM information_schema.TABLES where TABLE_SCHEMA = '".$globalDBname."' AND TABLE_NAME = 'spotter_archive'";
287
-		    try {
288
-            		$sth = $Connection->db->prepare($query);
289
-			$sth->execute();
290
-    		    } catch(PDOException $e) {
279
+			try {
280
+					$sth = $Connection->db->prepare($query);
281
+			$sth->execute();
282
+			} catch(PDOException $e) {
283
+			return "error (add pilot column to spotter_live and spotter_output) : ".$e->getMessage()."\n";
284
+			}
285
+			if ($globalDBdriver == 'mysql') {
286
+				$query = "SELECT ENGINE FROM information_schema.TABLES where TABLE_SCHEMA = '".$globalDBname."' AND TABLE_NAME = 'spotter_archive'";
287
+			try {
288
+					$sth = $Connection->db->prepare($query);
289
+			$sth->execute();
290
+				} catch(PDOException $e) {
291 291
 			return "error (problem when select engine for spotter_engine) : ".$e->getMessage()."\n";
292
-    		    }
293
-    		    $row = $sth->fetch(PDO::FETCH_ASSOC);
294
-    		    if ($row['engine'] == 'ARCHIVE') {
292
+				}
293
+				$row = $sth->fetch(PDO::FETCH_ASSOC);
294
+				if ($row['engine'] == 'ARCHIVE') {
295 295
 			$query = "CREATE TABLE copy LIKE spotter_archive; 
296 296
 				ALTER TABLE copy ENGINE=ARCHIVE;
297 297
 				ALTER TABLE copy ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL;
298 298
 				INSERT INTO copy SELECT *, '' as pilot_name, '' as pilot_id FROM spotter_archive ORDER BY `spotter_archive_id`;
299 299
 				DROP TABLE spotter_archive;
300 300
 				RENAME TABLE copy TO spotter_archive;";
301
-            	    } else {
302
-    			$query="ALTER TABLE spotter_archive ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL";
303
-            	    }
304
-                } else {
305
-    		    $query="ALTER TABLE spotter_archive ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL";
306
-                }
307
-        	try {
308
-            	    $sth = $Connection->db->prepare($query);
309
-		    $sth->execute();
310
-    		} catch(PDOException $e) {
311
-		    return "error (add pilot column to spotter_archive) : ".$e->getMessage()."\n";
312
-    		}
301
+					} else {
302
+				$query="ALTER TABLE spotter_archive ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL";
303
+					}
304
+				} else {
305
+				$query="ALTER TABLE spotter_archive ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL";
306
+				}
307
+			try {
308
+					$sth = $Connection->db->prepare($query);
309
+			$sth->execute();
310
+			} catch(PDOException $e) {
311
+			return "error (add pilot column to spotter_archive) : ".$e->getMessage()."\n";
312
+			}
313 313
 
314
-    		$error = '';
315
-    		// Update table aircraft
314
+			$error = '';
315
+			// Update table aircraft
316 316
 		$error .= create_db::import_file('../db/source_location.sql');
317 317
 		if ($error != '') return $error;
318 318
 		// Update schema_version to 6
319 319
 		$query = "UPDATE `config` SET `value` = '8' WHERE `name` = 'schema_version'";
320
-        	try {
321
-            	    $sth = $Connection->db->prepare($query);
322
-		    $sth->execute();
323
-    		} catch(PDOException $e) {
324
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
325
-    		}
320
+			try {
321
+					$sth = $Connection->db->prepare($query);
322
+			$sth->execute();
323
+			} catch(PDOException $e) {
324
+			return "error (update schema_version) : ".$e->getMessage()."\n";
325
+			}
326 326
 		return $error;
327 327
 	}
328 328
 
329 329
 	private static function update_from_8() {
330
-    		$Connection = new Connection();
331
-    		$error = '';
332
-    		// Update table aircraft
330
+			$Connection = new Connection();
331
+			$error = '';
332
+			// Update table aircraft
333 333
 		$error .= create_db::import_file('../db/notam.sql');
334 334
 		if ($error != '') return $error;
335 335
 		$query = "DELETE FROM config WHERE name = 'last_update_db';
336 336
                         INSERT INTO config (name,value) VALUES ('last_update_db',NOW());
337 337
                         DELETE FROM config WHERE name = 'last_update_notam_db';
338 338
                         INSERT INTO config (name,value) VALUES ('last_update_notam_db',NOW());";
339
-        	try {
340
-            	    $sth = $Connection->db->prepare($query);
341
-		    $sth->execute();
342
-    		} catch(PDOException $e) {
343
-		    return "error (insert last_update values) : ".$e->getMessage()."\n";
344
-    		}
339
+			try {
340
+					$sth = $Connection->db->prepare($query);
341
+			$sth->execute();
342
+			} catch(PDOException $e) {
343
+			return "error (insert last_update values) : ".$e->getMessage()."\n";
344
+			}
345 345
 		$query = "UPDATE `config` SET `value` = '9' WHERE `name` = 'schema_version'";
346
-        	try {
347
-            	    $sth = $Connection->db->prepare($query);
348
-		    $sth->execute();
349
-    		} catch(PDOException $e) {
350
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
351
-    		}
346
+			try {
347
+					$sth = $Connection->db->prepare($query);
348
+			$sth->execute();
349
+			} catch(PDOException $e) {
350
+			return "error (update schema_version) : ".$e->getMessage()."\n";
351
+			}
352 352
 		return $error;
353 353
 	}
354 354
 
355 355
 	private static function update_from_9() {
356
-    		$Connection = new Connection();
357
-    		$query="ALTER TABLE spotter_live ADD verticalrate INT(11) NULL;
356
+			$Connection = new Connection();
357
+			$query="ALTER TABLE spotter_live ADD verticalrate INT(11) NULL;
358 358
     			ALTER TABLE spotter_output ADD verticalrate INT(11) NULL;";
359
-        	try {
360
-            	    $sth = $Connection->db->prepare($query);
361
-		    $sth->execute();
362
-    		} catch(PDOException $e) {
363
-		    return "error (add verticalrate column to spotter_live and spotter_output) : ".$e->getMessage()."\n";
364
-    		}
359
+			try {
360
+					$sth = $Connection->db->prepare($query);
361
+			$sth->execute();
362
+			} catch(PDOException $e) {
363
+			return "error (add verticalrate column to spotter_live and spotter_output) : ".$e->getMessage()."\n";
364
+			}
365 365
 		$error = '';
366
-    		// Update table atc
366
+			// Update table atc
367 367
 		$error .= create_db::import_file('../db/atc.sql');
368 368
 		if ($error != '') return $error;
369 369
 		
370 370
 		$query = "UPDATE `config` SET `value` = '10' WHERE `name` = 'schema_version'";
371
-        	try {
372
-            	    $sth = $Connection->db->prepare($query);
373
-		    $sth->execute();
374
-    		} catch(PDOException $e) {
375
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
376
-    		}
371
+			try {
372
+					$sth = $Connection->db->prepare($query);
373
+			$sth->execute();
374
+			} catch(PDOException $e) {
375
+			return "error (update schema_version) : ".$e->getMessage()."\n";
376
+			}
377 377
 		return $error;
378 378
 	}
379 379
 
380 380
 	private static function update_from_10() {
381
-    		$Connection = new Connection();
382
-    		$query="ALTER TABLE atc CHANGE `type` `type` ENUM('Observer','Flight Information','Delivery','Tower','Approach','ACC','Departure','Ground','Flight Service Station','Control Radar or Centre') CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL";
383
-        	try {
384
-            	    $sth = $Connection->db->prepare($query);
385
-		    $sth->execute();
386
-    		} catch(PDOException $e) {
387
-		    return "error (add new enum to ATC table) : ".$e->getMessage()."\n";
388
-    		}
381
+			$Connection = new Connection();
382
+			$query="ALTER TABLE atc CHANGE `type` `type` ENUM('Observer','Flight Information','Delivery','Tower','Approach','ACC','Departure','Ground','Flight Service Station','Control Radar or Centre') CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL";
383
+			try {
384
+					$sth = $Connection->db->prepare($query);
385
+			$sth->execute();
386
+			} catch(PDOException $e) {
387
+			return "error (add new enum to ATC table) : ".$e->getMessage()."\n";
388
+			}
389 389
 		$error = '';
390
-    		// Add tables
390
+			// Add tables
391 391
 		$error .= create_db::import_file('../db/aircraft_owner.sql');
392 392
 		if ($error != '') return $error;
393 393
 		$error .= create_db::import_file('../db/metar.sql');
@@ -398,76 +398,76 @@  discard block
 block discarded – undo
398 398
 		if ($error != '') return $error;
399 399
 		
400 400
 		$query = "UPDATE `config` SET `value` = '11' WHERE `name` = 'schema_version'";
401
-        	try {
402
-            	    $sth = $Connection->db->prepare($query);
403
-		    $sth->execute();
404
-    		} catch(PDOException $e) {
405
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
406
-    		}
401
+			try {
402
+					$sth = $Connection->db->prepare($query);
403
+			$sth->execute();
404
+			} catch(PDOException $e) {
405
+			return "error (update schema_version) : ".$e->getMessage()."\n";
406
+			}
407 407
 		return $error;
408 408
 	}
409 409
 
410 410
 	private static function update_from_11() {
411 411
 		global $globalDBdriver, $globalDBname;
412
-    		$Connection = new Connection();
413
-    		$query="ALTER TABLE spotter_output ADD owner_name VARCHAR(255) NULL DEFAULT NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE, ADD last_ground BOOLEAN NOT NULL DEFAULT FALSE, ADD last_seen DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, ADD last_latitude FLOAT NULL, ADD last_longitude FLOAT NULL, ADD last_altitude INT(11) NULL, ADD last_ground_speed INT(11), ADD real_arrival_airport_icao VARCHAR(999), ADD real_arrival_airport_time VARCHAR(20),ADD real_departure_airport_icao VARCHAR(999), ADD real_departure_airport_time VARCHAR(20)";
414
-        	try {
415
-            	    $sth = $Connection->db->prepare($query);
416
-		    $sth->execute();
417
-    		} catch(PDOException $e) {
418
-		    return "error (add owner_name & format_source column to spotter_output) : ".$e->getMessage()."\n";
419
-    		}
420
-    		$query="ALTER TABLE spotter_live ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE";
421
-        	try {
422
-            	    $sth = $Connection->db->prepare($query);
423
-		    $sth->execute();
424
-    		} catch(PDOException $e) {
425
-		    return "error (format_source column to spotter_live) : ".$e->getMessage()."\n";
426
-    		}
427
-    		if ($globalDBdriver == 'mysql') {
428
-    		    $query = "SELECT ENGINE FROM information_schema.TABLES where TABLE_SCHEMA = '".$globalDBname."' AND TABLE_NAME = 'spotter_archive'";
429
-		    try {
430
-            		$sth = $Connection->db->prepare($query);
431
-			$sth->execute();
432
-    		    } catch(PDOException $e) {
412
+			$Connection = new Connection();
413
+			$query="ALTER TABLE spotter_output ADD owner_name VARCHAR(255) NULL DEFAULT NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE, ADD last_ground BOOLEAN NOT NULL DEFAULT FALSE, ADD last_seen DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, ADD last_latitude FLOAT NULL, ADD last_longitude FLOAT NULL, ADD last_altitude INT(11) NULL, ADD last_ground_speed INT(11), ADD real_arrival_airport_icao VARCHAR(999), ADD real_arrival_airport_time VARCHAR(20),ADD real_departure_airport_icao VARCHAR(999), ADD real_departure_airport_time VARCHAR(20)";
414
+			try {
415
+					$sth = $Connection->db->prepare($query);
416
+			$sth->execute();
417
+			} catch(PDOException $e) {
418
+			return "error (add owner_name & format_source column to spotter_output) : ".$e->getMessage()."\n";
419
+			}
420
+			$query="ALTER TABLE spotter_live ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE";
421
+			try {
422
+					$sth = $Connection->db->prepare($query);
423
+			$sth->execute();
424
+			} catch(PDOException $e) {
425
+			return "error (format_source column to spotter_live) : ".$e->getMessage()."\n";
426
+			}
427
+			if ($globalDBdriver == 'mysql') {
428
+				$query = "SELECT ENGINE FROM information_schema.TABLES where TABLE_SCHEMA = '".$globalDBname."' AND TABLE_NAME = 'spotter_archive'";
429
+			try {
430
+					$sth = $Connection->db->prepare($query);
431
+			$sth->execute();
432
+				} catch(PDOException $e) {
433 433
 			return "error (problem when select engine for spotter_engine) : ".$e->getMessage()."\n";
434
-    		    }
435
-    		    $row = $sth->fetch(PDO::FETCH_ASSOC);
436
-    		    if ($row['engine'] == 'ARCHIVE') {
434
+				}
435
+				$row = $sth->fetch(PDO::FETCH_ASSOC);
436
+				if ($row['engine'] == 'ARCHIVE') {
437 437
 			$query = "CREATE TABLE copy LIKE spotter_archive; 
438 438
 				ALTER TABLE copy ENGINE=ARCHIVE;
439 439
 				ALTER TABLE copy ADD verticalrate INT(11) NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE;
440 440
 				INSERT INTO copy SELECT *, '' as verticalrate, '' as format_source, '0' as ground FROM spotter_archive ORDER BY `spotter_archive_id`;
441 441
 				DROP TABLE spotter_archive;
442 442
 				RENAME TABLE copy TO spotter_archive;";
443
-            	    } else {
444
-    			$query="ALTER TABLE spotter_archive ADD verticalrate INT(11) NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE";
445
-            	    }
446
-                } else {
447
-    		    $query="ALTER TABLE spotter_archive ADD verticalrate INT(11) NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE";
448
-                }
449
-        	try {
450
-            	    $sth = $Connection->db->prepare($query);
451
-		    $sth->execute();
452
-    		} catch(PDOException $e) {
453
-		    return "error (add columns to spotter_archive) : ".$e->getMessage()."\n";
454
-    		}
443
+					} else {
444
+				$query="ALTER TABLE spotter_archive ADD verticalrate INT(11) NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE";
445
+					}
446
+				} else {
447
+				$query="ALTER TABLE spotter_archive ADD verticalrate INT(11) NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE";
448
+				}
449
+			try {
450
+					$sth = $Connection->db->prepare($query);
451
+			$sth->execute();
452
+			} catch(PDOException $e) {
453
+			return "error (add columns to spotter_archive) : ".$e->getMessage()."\n";
454
+			}
455 455
 
456 456
 		$error = '';
457 457
 		
458 458
 		$query = "UPDATE `config` SET `value` = '12' WHERE `name` = 'schema_version'";
459
-        	try {
460
-            	    $sth = $Connection->db->prepare($query);
461
-		    $sth->execute();
462
-    		} catch(PDOException $e) {
463
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
464
-    		}
459
+			try {
460
+					$sth = $Connection->db->prepare($query);
461
+			$sth->execute();
462
+			} catch(PDOException $e) {
463
+			return "error (update schema_version) : ".$e->getMessage()."\n";
464
+			}
465 465
 		return $error;
466 466
 	}
467 467
 	private static function update_from_12() {
468
-    		$Connection = new Connection();
468
+			$Connection = new Connection();
469 469
 		$error = '';
470
-    		// Add tables
470
+			// Add tables
471 471
 		$error .= create_db::import_file('../db/stats.sql');
472 472
 		if ($error != '') return $error;
473 473
 		$error .= create_db::import_file('../db/stats_aircraft.sql');
@@ -484,166 +484,166 @@  discard block
 block discarded – undo
484 484
 		if ($error != '') return $error;
485 485
 		
486 486
 		$query = "UPDATE `config` SET `value` = '13' WHERE `name` = 'schema_version'";
487
-        	try {
488
-            	    $sth = $Connection->db->prepare($query);
489
-		    $sth->execute();
490
-    		} catch(PDOException $e) {
491
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
492
-    		}
487
+			try {
488
+					$sth = $Connection->db->prepare($query);
489
+			$sth->execute();
490
+			} catch(PDOException $e) {
491
+			return "error (update schema_version) : ".$e->getMessage()."\n";
492
+			}
493 493
 		return $error;
494 494
 	}
495 495
 
496 496
 	private static function update_from_13() {
497
-    		$Connection = new Connection();
498
-    		if (!$Connection->checkColumnName('spotter_archive_output','real_departure_airport_icao')) {
499
-    			$query="ALTER TABLE spotter_archive_output ADD real_departure_airport_icao VARCHAR(20), ADD real_departure_airport_time VARCHAR(20)";
497
+			$Connection = new Connection();
498
+			if (!$Connection->checkColumnName('spotter_archive_output','real_departure_airport_icao')) {
499
+				$query="ALTER TABLE spotter_archive_output ADD real_departure_airport_icao VARCHAR(20), ADD real_departure_airport_time VARCHAR(20)";
500 500
 			try {
501 501
 				$sth = $Connection->db->prepare($query);
502 502
 				$sth->execute();
503
-	    		} catch(PDOException $e) {
503
+				} catch(PDOException $e) {
504 504
 				return "error (update spotter_archive_output) : ".$e->getMessage()."\n";
505
-    			}
505
+				}
506 506
 		}
507
-    		$error = '';
507
+			$error = '';
508 508
 		$query = "UPDATE `config` SET `value` = '14' WHERE `name` = 'schema_version'";
509
-        	try {
510
-            	    $sth = $Connection->db->prepare($query);
511
-		    $sth->execute();
512
-    		} catch(PDOException $e) {
513
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
514
-    		}
509
+			try {
510
+					$sth = $Connection->db->prepare($query);
511
+			$sth->execute();
512
+			} catch(PDOException $e) {
513
+			return "error (update schema_version) : ".$e->getMessage()."\n";
514
+			}
515 515
 		return $error;
516 516
 	}
517 517
 
518 518
 	private static function update_from_14() {
519
-    		$Connection = new Connection();
519
+			$Connection = new Connection();
520 520
 		$error = '';
521
-    		// Add tables
522
-    		if (!$Connection->tableExists('stats_flight')) {
521
+			// Add tables
522
+			if (!$Connection->tableExists('stats_flight')) {
523 523
 			$error .= create_db::import_file('../db/stats_flight.sql');
524 524
 			if ($error != '') return $error;
525 525
 		}
526 526
 		$query = "UPDATE `config` SET `value` = '15' WHERE `name` = 'schema_version'";
527
-        	try {
528
-            	    $sth = $Connection->db->prepare($query);
529
-		    $sth->execute();
530
-    		} catch(PDOException $e) {
531
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
532
-    		}
527
+			try {
528
+					$sth = $Connection->db->prepare($query);
529
+			$sth->execute();
530
+			} catch(PDOException $e) {
531
+			return "error (update schema_version) : ".$e->getMessage()."\n";
532
+			}
533 533
 		return $error;
534 534
 	}
535 535
 
536 536
 
537 537
 	private static function update_from_15() {
538
-    		$Connection = new Connection();
538
+			$Connection = new Connection();
539 539
 		$error = '';
540
-    		// Add tables
541
-    		$query="ALTER TABLE `stats` CHANGE `stats_date` `stats_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP";
542
-        	try {
543
-            	    $sth = $Connection->db->prepare($query);
544
-		    $sth->execute();
545
-    		} catch(PDOException $e) {
546
-		    return "error (update stats) : ".$e->getMessage()."\n";
547
-    		}
540
+			// Add tables
541
+			$query="ALTER TABLE `stats` CHANGE `stats_date` `stats_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP";
542
+			try {
543
+					$sth = $Connection->db->prepare($query);
544
+			$sth->execute();
545
+			} catch(PDOException $e) {
546
+			return "error (update stats) : ".$e->getMessage()."\n";
547
+			}
548 548
 		if ($error != '') return $error;
549 549
 		$query = "UPDATE `config` SET `value` = '16' WHERE `name` = 'schema_version'";
550
-        	try {
551
-            	    $sth = $Connection->db->prepare($query);
552
-		    $sth->execute();
553
-    		} catch(PDOException $e) {
554
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
555
-    		}
550
+			try {
551
+					$sth = $Connection->db->prepare($query);
552
+			$sth->execute();
553
+			} catch(PDOException $e) {
554
+			return "error (update schema_version) : ".$e->getMessage()."\n";
555
+			}
556 556
 		return $error;
557 557
 	}
558 558
 
559 559
 	private static function update_from_16() {
560
-    		$Connection = new Connection();
560
+			$Connection = new Connection();
561 561
 		$error = '';
562
-    		// Add tables
563
-    		if (!$Connection->tableExists('stats_registration')) {
562
+			// Add tables
563
+			if (!$Connection->tableExists('stats_registration')) {
564 564
 			$error .= create_db::import_file('../db/stats_registration.sql');
565 565
 		}
566
-    		if (!$Connection->tableExists('stats_callsign')) {
566
+			if (!$Connection->tableExists('stats_callsign')) {
567 567
 			$error .= create_db::import_file('../db/stats_callsign.sql');
568 568
 		}
569 569
 		if ($error != '') return $error;
570 570
 		$query = "UPDATE `config` SET `value` = '17' WHERE `name` = 'schema_version'";
571
-        	try {
572
-            	    $sth = $Connection->db->prepare($query);
573
-		    $sth->execute();
574
-    		} catch(PDOException $e) {
575
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
576
-    		}
571
+			try {
572
+					$sth = $Connection->db->prepare($query);
573
+			$sth->execute();
574
+			} catch(PDOException $e) {
575
+			return "error (update schema_version) : ".$e->getMessage()."\n";
576
+			}
577 577
 		return $error;
578 578
 	}
579 579
 
580 580
 	private static function update_from_17() {
581
-    		$Connection = new Connection();
581
+			$Connection = new Connection();
582 582
 		$error = '';
583
-    		// Add tables
584
-    		if (!$Connection->tableExists('stats_country')) {
583
+			// Add tables
584
+			if (!$Connection->tableExists('stats_country')) {
585 585
 			$error .= create_db::import_file('../db/stats_country.sql');
586 586
 		}
587 587
 		if ($error != '') return $error;
588 588
 		$query = "UPDATE `config` SET `value` = '18' WHERE `name` = 'schema_version'";
589
-        	try {
590
-            	    $sth = $Connection->db->prepare($query);
591
-		    $sth->execute();
592
-    		} catch(PDOException $e) {
593
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
594
-    		}
589
+			try {
590
+					$sth = $Connection->db->prepare($query);
591
+			$sth->execute();
592
+			} catch(PDOException $e) {
593
+			return "error (update schema_version) : ".$e->getMessage()."\n";
594
+			}
595 595
 		return $error;
596 596
 	}
597 597
 	private static function update_from_18() {
598
-    		$Connection = new Connection();
598
+			$Connection = new Connection();
599 599
 		$error = '';
600
-    		// Modify stats_airport table
601
-    		if (!$Connection->checkColumnName('stats_airport','airport_name')) {
602
-    			$query = "ALTER TABLE `stats_airport` ADD `stats_type` VARCHAR(50) NOT NULL DEFAULT 'yearly', ADD `airport_name` VARCHAR(255) NOT NULL, ADD `date` DATE NULL DEFAULT NULL, DROP INDEX `airport_icao`, ADD UNIQUE `airport_icao` (`airport_icao`, `type`, `date`)";
603
-    	        	try {
604
-	            	    $sth = $Connection->db->prepare($query);
605
-			    $sth->execute();
606
-    			} catch(PDOException $e) {
607
-			    return "error (update stats) : ".$e->getMessage()."\n";
608
-    			}
609
-    		}
600
+			// Modify stats_airport table
601
+			if (!$Connection->checkColumnName('stats_airport','airport_name')) {
602
+				$query = "ALTER TABLE `stats_airport` ADD `stats_type` VARCHAR(50) NOT NULL DEFAULT 'yearly', ADD `airport_name` VARCHAR(255) NOT NULL, ADD `date` DATE NULL DEFAULT NULL, DROP INDEX `airport_icao`, ADD UNIQUE `airport_icao` (`airport_icao`, `type`, `date`)";
603
+					try {
604
+						$sth = $Connection->db->prepare($query);
605
+				$sth->execute();
606
+				} catch(PDOException $e) {
607
+				return "error (update stats) : ".$e->getMessage()."\n";
608
+				}
609
+			}
610 610
 		if ($error != '') return $error;
611 611
 		$query = "UPDATE `config` SET `value` = '19' WHERE `name` = 'schema_version'";
612
-        	try {
613
-            	    $sth = $Connection->db->prepare($query);
614
-		    $sth->execute();
615
-    		} catch(PDOException $e) {
616
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
617
-    		}
612
+			try {
613
+					$sth = $Connection->db->prepare($query);
614
+			$sth->execute();
615
+			} catch(PDOException $e) {
616
+			return "error (update schema_version) : ".$e->getMessage()."\n";
617
+			}
618 618
 		return $error;
619 619
 	}
620 620
 
621 621
 	private static function update_from_19() {
622
-    		$Connection = new Connection();
622
+			$Connection = new Connection();
623 623
 		$error = '';
624
-    		// Update airport table
624
+			// Update airport table
625 625
 		$error .= create_db::import_file('../db/airport.sql');
626 626
 		if ($error != '') return 'Import airport.sql : '.$error;
627 627
 		// Remove primary key on Spotter_Archive
628 628
 		$query = "alter table spotter_archive drop spotter_archive_id";
629
-        	try {
630
-            	    $sth = $Connection->db->prepare($query);
631
-		    $sth->execute();
632
-    		} catch(PDOException $e) {
633
-		    return "error (remove primary key on spotter_archive) : ".$e->getMessage()."\n";
634
-    		}
629
+			try {
630
+					$sth = $Connection->db->prepare($query);
631
+			$sth->execute();
632
+			} catch(PDOException $e) {
633
+			return "error (remove primary key on spotter_archive) : ".$e->getMessage()."\n";
634
+			}
635 635
 		$query = "alter table spotter_archive add spotter_archive_id INT(11)";
636
-        	try {
637
-            	    $sth = $Connection->db->prepare($query);
638
-		    $sth->execute();
639
-    		} catch(PDOException $e) {
640
-		    return "error (add id again on spotter_archive) : ".$e->getMessage()."\n";
641
-    		}
636
+			try {
637
+					$sth = $Connection->db->prepare($query);
638
+			$sth->execute();
639
+			} catch(PDOException $e) {
640
+			return "error (add id again on spotter_archive) : ".$e->getMessage()."\n";
641
+			}
642 642
 		if (!$Connection->checkColumnName('spotter_archive','over_country')) {
643 643
 			// Add column over_country
644
-    			$query = "ALTER TABLE `spotter_archive` ADD `over_country` VARCHAR(5) NULL DEFAULT NULL";
644
+				$query = "ALTER TABLE `spotter_archive` ADD `over_country` VARCHAR(5) NULL DEFAULT NULL";
645 645
 			try {
646
-            			$sth = $Connection->db->prepare($query);
646
+						$sth = $Connection->db->prepare($query);
647 647
 				$sth->execute();
648 648
 			} catch(PDOException $e) {
649 649
 				return "error (add over_country) : ".$e->getMessage()."\n";
@@ -651,9 +651,9 @@  discard block
 block discarded – undo
651 651
 		}
652 652
 		if (!$Connection->checkColumnName('spotter_live','over_country')) {
653 653
 			// Add column over_country
654
-    			$query = "ALTER TABLE `spotter_live` ADD `over_country` VARCHAR(5) NULL DEFAULT NULL";
654
+				$query = "ALTER TABLE `spotter_live` ADD `over_country` VARCHAR(5) NULL DEFAULT NULL";
655 655
 			try {
656
-            			$sth = $Connection->db->prepare($query);
656
+						$sth = $Connection->db->prepare($query);
657 657
 				$sth->execute();
658 658
 			} catch(PDOException $e) {
659 659
 				return "error (add over_country) : ".$e->getMessage()."\n";
@@ -661,74 +661,74 @@  discard block
 block discarded – undo
661 661
 		}
662 662
 		if (!$Connection->checkColumnName('spotter_output','source_name')) {
663 663
 			// Add source_name to spotter_output, spotter_live, spotter_archive, spotter_archive_output
664
-    			$query = "ALTER TABLE `spotter_output` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`";
664
+				$query = "ALTER TABLE `spotter_output` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`";
665 665
 			try {
666 666
 				$sth = $Connection->db->prepare($query);
667 667
 				$sth->execute();
668 668
 			} catch(PDOException $e) {
669 669
 				return "error (add source_name column) : ".$e->getMessage()."\n";
670
-    			}
671
-    		}
670
+				}
671
+			}
672 672
 		if (!$Connection->checkColumnName('spotter_live','source_name')) {
673 673
 			// Add source_name to spotter_output, spotter_live, spotter_archive, spotter_archive_output
674
-    			$query = "ALTER TABLE `spotter_live` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`";
674
+				$query = "ALTER TABLE `spotter_live` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`";
675 675
 			try {
676 676
 				$sth = $Connection->db->prepare($query);
677 677
 				$sth->execute();
678 678
 			} catch(PDOException $e) {
679 679
 				return "error (add source_name column) : ".$e->getMessage()."\n";
680
-    			}
681
-    		}
680
+				}
681
+			}
682 682
 		if (!$Connection->checkColumnName('spotter_archive_output','source_name')) {
683 683
 			// Add source_name to spotter_output, spotter_live, spotter_archive, spotter_archive_output
684
-    			$query = "ALTER TABLE `spotter_archive_output` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`";
684
+				$query = "ALTER TABLE `spotter_archive_output` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`";
685 685
 			try {
686 686
 				$sth = $Connection->db->prepare($query);
687 687
 				$sth->execute();
688 688
 			} catch(PDOException $e) {
689 689
 				return "error (add source_name column) : ".$e->getMessage()."\n";
690
-    			}
691
-    		}
690
+				}
691
+			}
692 692
 		if (!$Connection->checkColumnName('spotter_archive','source_name')) {
693 693
 			// Add source_name to spotter_output, spotter_live, spotter_archive, spotter_archive_output
694
-    			$query = "ALTER TABLE `spotter_archive` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`;";
694
+				$query = "ALTER TABLE `spotter_archive` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`;";
695 695
 			try {
696 696
 				$sth = $Connection->db->prepare($query);
697 697
 				$sth->execute();
698 698
 			} catch(PDOException $e) {
699 699
 				return "error (add source_name column) : ".$e->getMessage()."\n";
700
-    			}
701
-    		}
700
+				}
701
+			}
702 702
 		if ($error != '') return $error;
703 703
 		$query = "UPDATE `config` SET `value` = '20' WHERE `name` = 'schema_version'";
704
-        	try {
705
-            	    $sth = $Connection->db->prepare($query);
706
-		    $sth->execute();
707
-    		} catch(PDOException $e) {
708
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
709
-    		}
704
+			try {
705
+					$sth = $Connection->db->prepare($query);
706
+			$sth->execute();
707
+			} catch(PDOException $e) {
708
+			return "error (update schema_version) : ".$e->getMessage()."\n";
709
+			}
710 710
 		return $error;
711 711
 	}
712 712
 
713 713
 	private static function update_from_20() {
714 714
 		global $globalIVAO, $globalVATSIM, $globalphpVMS;
715
-    		$Connection = new Connection();
715
+			$Connection = new Connection();
716 716
 		$error = '';
717
-    		// Update airline table
718
-    		if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS) {
717
+			// Update airline table
718
+			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS) {
719 719
 			$error .= create_db::import_file('../db/airlines.sql');
720 720
 			if ($error != '') return 'Import airlines.sql : '.$error;
721 721
 		}
722 722
 		if (!$Connection->checkColumnName('aircraft_modes','type_flight')) {
723 723
 			// Add column over_country
724
-    			$query = "ALTER TABLE `aircraft_modes` ADD `type_flight` VARCHAR(50) NULL DEFAULT NULL;";
725
-        		try {
724
+				$query = "ALTER TABLE `aircraft_modes` ADD `type_flight` VARCHAR(50) NULL DEFAULT NULL;";
725
+				try {
726 726
 				$sth = $Connection->db->prepare($query);
727 727
 				$sth->execute();
728 728
 			} catch(PDOException $e) {
729 729
 				return "error (add over_country) : ".$e->getMessage()."\n";
730
-    			}
731
-    		}
730
+				}
731
+			}
732 732
 		if ($error != '') return $error;
733 733
 		/*
734 734
     		if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS) {
@@ -738,12 +738,12 @@  discard block
 block discarded – undo
738 738
 		}
739 739
 		*/
740 740
 		$query = "UPDATE `config` SET `value` = '21' WHERE `name` = 'schema_version'";
741
-        	try {
742
-            	    $sth = $Connection->db->prepare($query);
743
-		    $sth->execute();
744
-    		} catch(PDOException $e) {
745
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
746
-    		}
741
+			try {
742
+					$sth = $Connection->db->prepare($query);
743
+			$sth->execute();
744
+			} catch(PDOException $e) {
745
+			return "error (update schema_version) : ".$e->getMessage()."\n";
746
+			}
747 747
 		return $error;
748 748
 	}
749 749
 
@@ -762,35 +762,35 @@  discard block
 block discarded – undo
762 762
 			if ($error != '') return $error;
763 763
 		}
764 764
 		$query = "UPDATE `config` SET `value` = '22' WHERE `name` = 'schema_version'";
765
-        	try {
766
-            	    $sth = $Connection->db->prepare($query);
767
-		    $sth->execute();
768
-    		} catch(PDOException $e) {
769
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
770
-    		}
765
+			try {
766
+					$sth = $Connection->db->prepare($query);
767
+			$sth->execute();
768
+			} catch(PDOException $e) {
769
+			return "error (update schema_version) : ".$e->getMessage()."\n";
770
+			}
771 771
 		return $error;
772 772
 	}
773 773
 
774 774
 	private static function update_from_22() {
775 775
 		global $globalDBdriver;
776
-    		$Connection = new Connection();
776
+			$Connection = new Connection();
777 777
 		$error = '';
778 778
 		// Add table stats polar
779
-    		if (!$Connection->tableExists('stats_source')) {
779
+			if (!$Connection->tableExists('stats_source')) {
780 780
 			if ($globalDBdriver == 'mysql') {
781
-    				$error .= create_db::import_file('../db/stats_source.sql');
781
+					$error .= create_db::import_file('../db/stats_source.sql');
782 782
 			} else {
783 783
 				$error .= create_db::import_file('../db/pgsql/stats_source.sql');
784 784
 			}
785 785
 			if ($error != '') return $error;
786 786
 		}
787 787
 		$query = "UPDATE config SET value = '23' WHERE name = 'schema_version'";
788
-        	try {
789
-            	    $sth = $Connection->db->prepare($query);
790
-		    $sth->execute();
791
-    		} catch(PDOException $e) {
792
-		    return "error (update schema_version) : ".$e->getMessage()."\n";
793
-    		}
788
+			try {
789
+					$sth = $Connection->db->prepare($query);
790
+			$sth->execute();
791
+			} catch(PDOException $e) {
792
+			return "error (update schema_version) : ".$e->getMessage()."\n";
793
+			}
794 794
 		return $error;
795 795
 	}
796 796
 
@@ -821,14 +821,14 @@  discard block
 block discarded – undo
821 821
 		}
822 822
 		if (!$Connection->checkColumnName('stats_aircraft','aircraft_manufacturer')) {
823 823
 			// Add aircraft_manufacturer to stats_aircraft
824
-    			$query = "ALTER TABLE stats_aircraft ADD aircraft_manufacturer VARCHAR(255) NULL";
824
+				$query = "ALTER TABLE stats_aircraft ADD aircraft_manufacturer VARCHAR(255) NULL";
825 825
 			try {
826 826
 				$sth = $Connection->db->prepare($query);
827 827
 				$sth->execute();
828 828
 			} catch(PDOException $e) {
829 829
 				return "error (add aircraft_manufacturer column) : ".$e->getMessage()."\n";
830
-    			}
831
-    		}
830
+				}
831
+			}
832 832
 		
833 833
 		$query = "UPDATE config SET value = '24' WHERE name = 'schema_version'";
834 834
 		try {
@@ -1176,7 +1176,7 @@  discard block
 block discarded – undo
1176 1176
 			} catch(PDOException $e) {
1177 1177
 				return "error (add index latitude,longitude on spotter_live) : ".$e->getMessage()."\n";
1178 1178
 			}
1179
-                }
1179
+				}
1180 1180
 		if (!$Connection->checkColumnName('aircraft','mfr')) {
1181 1181
 			// Add mfr to aircraft
1182 1182
 			$query = "ALTER TABLE aircraft ADD mfr VARCHAR(255) NULL";
@@ -1250,7 +1250,7 @@  discard block
 block discarded – undo
1250 1250
 			} catch(PDOException $e) {
1251 1251
 				return "error (add index ref on notam) : ".$e->getMessage()."\n";
1252 1252
 			}
1253
-                }
1253
+				}
1254 1254
 		if (!$Connection->indexExists('accidents','registration_idx')) {
1255 1255
 			// Add index key
1256 1256
 			$query = "create index registration_idx on accidents (registration)";
@@ -1260,7 +1260,7 @@  discard block
 block discarded – undo
1260 1260
 			} catch(PDOException $e) {
1261 1261
 				return "error (add index registration on accidents) : ".$e->getMessage()."\n";
1262 1262
 			}
1263
-                }
1263
+				}
1264 1264
 		if (!$Connection->indexExists('accidents','rdts')) {
1265 1265
 			// Add index key
1266 1266
 			$query = "create index rdts on accidents (registration,date,type,source)";
@@ -1270,7 +1270,7 @@  discard block
 block discarded – undo
1270 1270
 			} catch(PDOException $e) {
1271 1271
 				return "error (add index registration, date, type & source on accidents) : ".$e->getMessage()."\n";
1272 1272
 			}
1273
-                }
1273
+				}
1274 1274
 
1275 1275
 		$query = "UPDATE config SET value = '31' WHERE name = 'schema_version'";
1276 1276
 		try {
@@ -1562,7 +1562,7 @@  discard block
 block discarded – undo
1562 1562
 			} catch(PDOException $e) {
1563 1563
 				return "error (add index type on accidents) : ".$e->getMessage()."\n";
1564 1564
 			}
1565
-                }
1565
+				}
1566 1566
 		$query = "UPDATE config SET value = '36' WHERE name = 'schema_version'";
1567 1567
 		try {
1568 1568
 			$sth = $Connection->db->prepare($query);
@@ -1723,7 +1723,7 @@  discard block
 block discarded – undo
1723 1723
 			} catch(PDOException $e) {
1724 1724
 				return "error (add index flightaware_id, date on spotter_archive) : ".$e->getMessage()."\n";
1725 1725
 			}
1726
-                }
1726
+				}
1727 1727
 		$query = "UPDATE config SET value = '38' WHERE name = 'schema_version'";
1728 1728
 		try {
1729 1729
 			$sth = $Connection->db->prepare($query);
@@ -2088,201 +2088,201 @@  discard block
 block discarded – undo
2088 2088
 
2089 2089
 
2090 2090
 
2091
-    	public static function check_version($update = false) {
2092
-    	    global $globalDBname;
2093
-    	    $version = 0;
2094
-    	    $Connection = new Connection();
2095
-    	    if ($Connection->tableExists('aircraft')) {
2096
-    		if (!$Connection->tableExists('config')) {
2097
-    		    $version = '1';
2098
-    		    if ($update) return self::update_from_1();
2099
-    		    else return $version;
2091
+		public static function check_version($update = false) {
2092
+			global $globalDBname;
2093
+			$version = 0;
2094
+			$Connection = new Connection();
2095
+			if ($Connection->tableExists('aircraft')) {
2096
+			if (!$Connection->tableExists('config')) {
2097
+				$version = '1';
2098
+				if ($update) return self::update_from_1();
2099
+				else return $version;
2100 2100
 		} else {
2101
-    		    $Connection = new Connection();
2102
-		    $query = "SELECT value FROM config WHERE name = 'schema_version' LIMIT 1";
2103
-		    try {
2104
-            		$sth = $Connection->db->prepare($query);
2105
-		        $sth->execute();
2106
-		    } catch(PDOException $e) {
2101
+				$Connection = new Connection();
2102
+			$query = "SELECT value FROM config WHERE name = 'schema_version' LIMIT 1";
2103
+			try {
2104
+					$sth = $Connection->db->prepare($query);
2105
+				$sth->execute();
2106
+			} catch(PDOException $e) {
2107 2107
 			return "error : ".$e->getMessage()."\n";
2108
-    		    }
2109
-    		    $result = $sth->fetch(PDO::FETCH_ASSOC);
2110
-    		    if ($update) {
2111
-    			if ($result['value'] == '2') {
2112
-    			    $error = self::update_from_2();
2113
-    			    if ($error != '') return $error;
2114
-    			    else return self::check_version(true);
2115
-    			} elseif ($result['value'] == '3') {
2116
-    			    $error = self::update_from_3();
2117
-    			    if ($error != '') return $error;
2118
-    			    else return self::check_version(true);
2119
-    			} elseif ($result['value'] == '4') {
2120
-    			    $error = self::update_from_4();
2121
-    			    if ($error != '') return $error;
2122
-    			    else return self::check_version(true);
2123
-    			} elseif ($result['value'] == '5') {
2124
-    			    $error = self::update_from_5();
2125
-    			    if ($error != '') return $error;
2126
-    			    else return self::check_version(true);
2127
-    			} elseif ($result['value'] == '6') {
2128
-    			    $error = self::update_from_6();
2129
-    			    if ($error != '') return $error;
2130
-    			    else return self::check_version(true);
2131
-    			} elseif ($result['value'] == '7') {
2132
-    			    $error = self::update_from_7();
2133
-    			    if ($error != '') return $error;
2134
-    			    else return self::check_version(true);
2135
-    			} elseif ($result['value'] == '8') {
2136
-    			    $error = self::update_from_8();
2137
-    			    if ($error != '') return $error;
2138
-    			    else return self::check_version(true);
2139
-    			} elseif ($result['value'] == '9') {
2140
-    			    $error = self::update_from_9();
2141
-    			    if ($error != '') return $error;
2142
-    			    else return self::check_version(true);
2143
-    			} elseif ($result['value'] == '10') {
2144
-    			    $error = self::update_from_10();
2145
-    			    if ($error != '') return $error;
2146
-    			    else return self::check_version(true);
2147
-    			} elseif ($result['value'] == '11') {
2148
-    			    $error = self::update_from_11();
2149
-    			    if ($error != '') return $error;
2150
-    			    else return self::check_version(true);
2151
-    			} elseif ($result['value'] == '12') {
2152
-    			    $error = self::update_from_12();
2153
-    			    if ($error != '') return $error;
2154
-    			    else return self::check_version(true);
2155
-    			} elseif ($result['value'] == '13') {
2156
-    			    $error = self::update_from_13();
2157
-    			    if ($error != '') return $error;
2158
-    			    else return self::check_version(true);
2159
-    			} elseif ($result['value'] == '14') {
2160
-    			    $error = self::update_from_14();
2161
-    			    if ($error != '') return $error;
2162
-    			    else return self::check_version(true);
2163
-    			} elseif ($result['value'] == '15') {
2164
-    			    $error = self::update_from_15();
2165
-    			    if ($error != '') return $error;
2166
-    			    else return self::check_version(true);
2167
-    			} elseif ($result['value'] == '16') {
2168
-    			    $error = self::update_from_16();
2169
-    			    if ($error != '') return $error;
2170
-    			    else return self::check_version(true);
2171
-    			} elseif ($result['value'] == '17') {
2172
-    			    $error = self::update_from_17();
2173
-    			    if ($error != '') return $error;
2174
-    			    else return self::check_version(true);
2175
-    			} elseif ($result['value'] == '18') {
2176
-    			    $error = self::update_from_18();
2177
-    			    if ($error != '') return $error;
2178
-    			    else return self::check_version(true);
2179
-    			} elseif ($result['value'] == '19') {
2180
-    			    $error = self::update_from_19();
2181
-    			    if ($error != '') return $error;
2182
-    			    else return self::check_version(true);
2183
-    			} elseif ($result['value'] == '20') {
2184
-    			    $error = self::update_from_20();
2185
-    			    if ($error != '') return $error;
2186
-    			    else return self::check_version(true);
2187
-    			} elseif ($result['value'] == '21') {
2188
-    			    $error = self::update_from_21();
2189
-    			    if ($error != '') return $error;
2190
-    			    else return self::check_version(true);
2191
-    			} elseif ($result['value'] == '22') {
2192
-    			    $error = self::update_from_22();
2193
-    			    if ($error != '') return $error;
2194
-    			    else return self::check_version(true);
2195
-    			} elseif ($result['value'] == '23') {
2196
-    			    $error = self::update_from_23();
2197
-    			    if ($error != '') return $error;
2198
-    			    else return self::check_version(true);
2199
-    			} elseif ($result['value'] == '24') {
2200
-    			    $error = self::update_from_24();
2201
-    			    if ($error != '') return $error;
2202
-    			    else return self::check_version(true);
2203
-    			} elseif ($result['value'] == '25') {
2204
-    			    $error = self::update_from_25();
2205
-    			    if ($error != '') return $error;
2206
-    			    else return self::check_version(true);
2207
-    			} elseif ($result['value'] == '26') {
2208
-    			    $error = self::update_from_26();
2209
-    			    if ($error != '') return $error;
2210
-    			    else return self::check_version(true);
2211
-    			} elseif ($result['value'] == '27') {
2212
-    			    $error = self::update_from_27();
2213
-    			    if ($error != '') return $error;
2214
-    			    else return self::check_version(true);
2215
-    			} elseif ($result['value'] == '28') {
2216
-    			    $error = self::update_from_28();
2217
-    			    if ($error != '') return $error;
2218
-    			    else return self::check_version(true);
2219
-    			} elseif ($result['value'] == '29') {
2220
-    			    $error = self::update_from_29();
2221
-    			    if ($error != '') return $error;
2222
-    			    else return self::check_version(true);
2223
-    			} elseif ($result['value'] == '30') {
2224
-    			    $error = self::update_from_30();
2225
-    			    if ($error != '') return $error;
2226
-    			    else return self::check_version(true);
2227
-    			} elseif ($result['value'] == '31') {
2228
-    			    $error = self::update_from_31();
2229
-    			    if ($error != '') return $error;
2230
-    			    else return self::check_version(true);
2231
-    			} elseif ($result['value'] == '32') {
2232
-    			    $error = self::update_from_32();
2233
-    			    if ($error != '') return $error;
2234
-    			    else return self::check_version(true);
2235
-    			} elseif ($result['value'] == '33') {
2236
-    			    $error = self::update_from_33();
2237
-    			    if ($error != '') return $error;
2238
-    			    else return self::check_version(true);
2239
-    			} elseif ($result['value'] == '34') {
2240
-    			    $error = self::update_from_34();
2241
-    			    if ($error != '') return $error;
2242
-    			    else return self::check_version(true);
2243
-    			} elseif ($result['value'] == '35') {
2244
-    			    $error = self::update_from_35();
2245
-    			    if ($error != '') return $error;
2246
-    			    else return self::check_version(true);
2247
-    			} elseif ($result['value'] == '36') {
2248
-    			    $error = self::update_from_36();
2249
-    			    if ($error != '') return $error;
2250
-    			    else return self::check_version(true);
2251
-    			} elseif ($result['value'] == '37') {
2252
-    			    $error = self::update_from_37();
2253
-    			    if ($error != '') return $error;
2254
-    			    else return self::check_version(true);
2255
-    			} elseif ($result['value'] == '38') {
2256
-    			    $error = self::update_from_38();
2257
-    			    if ($error != '') return $error;
2258
-    			    else return self::check_version(true);
2259
-    			} elseif ($result['value'] == '39') {
2260
-    			    $error = self::update_from_39();
2261
-    			    if ($error != '') return $error;
2262
-    			    else return self::check_version(true);
2263
-    			} elseif ($result['value'] == '40') {
2264
-    			    $error = self::update_from_40();
2265
-    			    if ($error != '') return $error;
2266
-    			    else return self::check_version(true);
2267
-    			} elseif ($result['value'] == '41') {
2268
-    			    $error = self::update_from_41();
2269
-    			    if ($error != '') return $error;
2270
-    			    else return self::check_version(true);
2271
-    			} elseif ($result['value'] == '42') {
2272
-    			    $error = self::update_from_42();
2273
-    			    if ($error != '') return $error;
2274
-    			    else return self::check_version(true);
2275
-    			} elseif ($result['value'] == '43') {
2276
-    			    $error = self::update_from_43();
2277
-    			    if ($error != '') return $error;
2278
-    			    else return self::check_version(true);
2279
-    			} else return '';
2280
-    		    }
2281
-    		    else return $result['value'];
2108
+				}
2109
+				$result = $sth->fetch(PDO::FETCH_ASSOC);
2110
+				if ($update) {
2111
+				if ($result['value'] == '2') {
2112
+					$error = self::update_from_2();
2113
+					if ($error != '') return $error;
2114
+					else return self::check_version(true);
2115
+				} elseif ($result['value'] == '3') {
2116
+					$error = self::update_from_3();
2117
+					if ($error != '') return $error;
2118
+					else return self::check_version(true);
2119
+				} elseif ($result['value'] == '4') {
2120
+					$error = self::update_from_4();
2121
+					if ($error != '') return $error;
2122
+					else return self::check_version(true);
2123
+				} elseif ($result['value'] == '5') {
2124
+					$error = self::update_from_5();
2125
+					if ($error != '') return $error;
2126
+					else return self::check_version(true);
2127
+				} elseif ($result['value'] == '6') {
2128
+					$error = self::update_from_6();
2129
+					if ($error != '') return $error;
2130
+					else return self::check_version(true);
2131
+				} elseif ($result['value'] == '7') {
2132
+					$error = self::update_from_7();
2133
+					if ($error != '') return $error;
2134
+					else return self::check_version(true);
2135
+				} elseif ($result['value'] == '8') {
2136
+					$error = self::update_from_8();
2137
+					if ($error != '') return $error;
2138
+					else return self::check_version(true);
2139
+				} elseif ($result['value'] == '9') {
2140
+					$error = self::update_from_9();
2141
+					if ($error != '') return $error;
2142
+					else return self::check_version(true);
2143
+				} elseif ($result['value'] == '10') {
2144
+					$error = self::update_from_10();
2145
+					if ($error != '') return $error;
2146
+					else return self::check_version(true);
2147
+				} elseif ($result['value'] == '11') {
2148
+					$error = self::update_from_11();
2149
+					if ($error != '') return $error;
2150
+					else return self::check_version(true);
2151
+				} elseif ($result['value'] == '12') {
2152
+					$error = self::update_from_12();
2153
+					if ($error != '') return $error;
2154
+					else return self::check_version(true);
2155
+				} elseif ($result['value'] == '13') {
2156
+					$error = self::update_from_13();
2157
+					if ($error != '') return $error;
2158
+					else return self::check_version(true);
2159
+				} elseif ($result['value'] == '14') {
2160
+					$error = self::update_from_14();
2161
+					if ($error != '') return $error;
2162
+					else return self::check_version(true);
2163
+				} elseif ($result['value'] == '15') {
2164
+					$error = self::update_from_15();
2165
+					if ($error != '') return $error;
2166
+					else return self::check_version(true);
2167
+				} elseif ($result['value'] == '16') {
2168
+					$error = self::update_from_16();
2169
+					if ($error != '') return $error;
2170
+					else return self::check_version(true);
2171
+				} elseif ($result['value'] == '17') {
2172
+					$error = self::update_from_17();
2173
+					if ($error != '') return $error;
2174
+					else return self::check_version(true);
2175
+				} elseif ($result['value'] == '18') {
2176
+					$error = self::update_from_18();
2177
+					if ($error != '') return $error;
2178
+					else return self::check_version(true);
2179
+				} elseif ($result['value'] == '19') {
2180
+					$error = self::update_from_19();
2181
+					if ($error != '') return $error;
2182
+					else return self::check_version(true);
2183
+				} elseif ($result['value'] == '20') {
2184
+					$error = self::update_from_20();
2185
+					if ($error != '') return $error;
2186
+					else return self::check_version(true);
2187
+				} elseif ($result['value'] == '21') {
2188
+					$error = self::update_from_21();
2189
+					if ($error != '') return $error;
2190
+					else return self::check_version(true);
2191
+				} elseif ($result['value'] == '22') {
2192
+					$error = self::update_from_22();
2193
+					if ($error != '') return $error;
2194
+					else return self::check_version(true);
2195
+				} elseif ($result['value'] == '23') {
2196
+					$error = self::update_from_23();
2197
+					if ($error != '') return $error;
2198
+					else return self::check_version(true);
2199
+				} elseif ($result['value'] == '24') {
2200
+					$error = self::update_from_24();
2201
+					if ($error != '') return $error;
2202
+					else return self::check_version(true);
2203
+				} elseif ($result['value'] == '25') {
2204
+					$error = self::update_from_25();
2205
+					if ($error != '') return $error;
2206
+					else return self::check_version(true);
2207
+				} elseif ($result['value'] == '26') {
2208
+					$error = self::update_from_26();
2209
+					if ($error != '') return $error;
2210
+					else return self::check_version(true);
2211
+				} elseif ($result['value'] == '27') {
2212
+					$error = self::update_from_27();
2213
+					if ($error != '') return $error;
2214
+					else return self::check_version(true);
2215
+				} elseif ($result['value'] == '28') {
2216
+					$error = self::update_from_28();
2217
+					if ($error != '') return $error;
2218
+					else return self::check_version(true);
2219
+				} elseif ($result['value'] == '29') {
2220
+					$error = self::update_from_29();
2221
+					if ($error != '') return $error;
2222
+					else return self::check_version(true);
2223
+				} elseif ($result['value'] == '30') {
2224
+					$error = self::update_from_30();
2225
+					if ($error != '') return $error;
2226
+					else return self::check_version(true);
2227
+				} elseif ($result['value'] == '31') {
2228
+					$error = self::update_from_31();
2229
+					if ($error != '') return $error;
2230
+					else return self::check_version(true);
2231
+				} elseif ($result['value'] == '32') {
2232
+					$error = self::update_from_32();
2233
+					if ($error != '') return $error;
2234
+					else return self::check_version(true);
2235
+				} elseif ($result['value'] == '33') {
2236
+					$error = self::update_from_33();
2237
+					if ($error != '') return $error;
2238
+					else return self::check_version(true);
2239
+				} elseif ($result['value'] == '34') {
2240
+					$error = self::update_from_34();
2241
+					if ($error != '') return $error;
2242
+					else return self::check_version(true);
2243
+				} elseif ($result['value'] == '35') {
2244
+					$error = self::update_from_35();
2245
+					if ($error != '') return $error;
2246
+					else return self::check_version(true);
2247
+				} elseif ($result['value'] == '36') {
2248
+					$error = self::update_from_36();
2249
+					if ($error != '') return $error;
2250
+					else return self::check_version(true);
2251
+				} elseif ($result['value'] == '37') {
2252
+					$error = self::update_from_37();
2253
+					if ($error != '') return $error;
2254
+					else return self::check_version(true);
2255
+				} elseif ($result['value'] == '38') {
2256
+					$error = self::update_from_38();
2257
+					if ($error != '') return $error;
2258
+					else return self::check_version(true);
2259
+				} elseif ($result['value'] == '39') {
2260
+					$error = self::update_from_39();
2261
+					if ($error != '') return $error;
2262
+					else return self::check_version(true);
2263
+				} elseif ($result['value'] == '40') {
2264
+					$error = self::update_from_40();
2265
+					if ($error != '') return $error;
2266
+					else return self::check_version(true);
2267
+				} elseif ($result['value'] == '41') {
2268
+					$error = self::update_from_41();
2269
+					if ($error != '') return $error;
2270
+					else return self::check_version(true);
2271
+				} elseif ($result['value'] == '42') {
2272
+					$error = self::update_from_42();
2273
+					if ($error != '') return $error;
2274
+					else return self::check_version(true);
2275
+				} elseif ($result['value'] == '43') {
2276
+					$error = self::update_from_43();
2277
+					if ($error != '') return $error;
2278
+					else return self::check_version(true);
2279
+				} else return '';
2280
+				}
2281
+				else return $result['value'];
2282 2282
 		}
2283 2283
 		
2284
-	    } else return $version;
2285
-    	}
2284
+		} else return $version;
2285
+		}
2286 2286
     	
2287 2287
 }
2288 2288
 //echo update_schema::check_version();
Please login to merge, or discard this patch.
require/class.Connection.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -7,35 +7,35 @@  discard block
 block discarded – undo
7 7
 	public $latest_schema = 44;
8 8
 	
9 9
 	public function __construct($dbc = null,$dbname = null,$user = null,$pass = null) {
10
-	    global $globalDBdriver, $globalNoDB;
11
-	    if (isset($globalNoDB) && $globalNoDB === TRUE) {
10
+		global $globalDBdriver, $globalNoDB;
11
+		if (isset($globalNoDB) && $globalNoDB === TRUE) {
12 12
 		$this->db = null;
13
-	    } else {
13
+		} else {
14 14
 		if ($dbc === null) {
15
-		    if ($this->db === null && $dbname === null) {
15
+			if ($this->db === null && $dbname === null) {
16 16
 			if ($user === null && $pass === null) {
17
-			    $this->createDBConnection();
17
+				$this->createDBConnection();
18 18
 			} else {
19
-			    $this->createDBConnection(null,$user,$pass);
19
+				$this->createDBConnection(null,$user,$pass);
20 20
 			}
21
-		    } else {
21
+			} else {
22 22
 			$this->createDBConnection($dbname);
23
-		    }
23
+			}
24 24
 		} elseif ($dbname === null || $dbname === 'default') {
25
-	    	    $this->db = $dbc;
26
-	    	    if ($this->connectionExists() === false) {
25
+				$this->db = $dbc;
26
+				if ($this->connectionExists() === false) {
27 27
 			/*
28 28
 			echo 'Restart Connection !!!'."\n";
29 29
 			$e = new \Exception;
30 30
 			var_dump($e->getTraceAsString());
31 31
 			*/
32 32
 			$this->createDBConnection();
33
-		    }
33
+			}
34 34
 		} else {
35
-		    //$this->connectionExists();
36
-		    $this->dbs[$dbname] = $dbc;
35
+			//$this->connectionExists();
36
+			$this->dbs[$dbname] = $dbc;
37
+		}
37 38
 		}
38
-	    }
39 39
 	}
40 40
 
41 41
 	public function db() {
@@ -56,11 +56,11 @@  discard block
 block discarded – undo
56 56
 	}
57 57
 
58 58
 	/**
59
-	* Creates the database connection
60
-	*
61
-	* @return Boolean of the database connection
62
-	*
63
-	*/
59
+	 * Creates the database connection
60
+	 *
61
+	 * @return Boolean of the database connection
62
+	 *
63
+	 */
64 64
 
65 65
 	public function createDBConnection($DBname = null, $user = null, $pass = null)
66 66
 	{
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 			return false;
158 158
 		}
159 159
 		if($results->rowCount()>0) {
160
-		    return true; 
160
+			return true; 
161 161
 		}
162 162
 		else return false;
163 163
 	}
@@ -174,14 +174,14 @@  discard block
 block discarded – undo
174 174
 				$sum = $sum->fetchColumn(0);
175 175
 			} else $sum = 0;
176 176
 			if (intval($sum) !== 2) {
177
-			     return false;
177
+				 return false;
178 178
 			}
179 179
 			
180 180
 		} catch(PDOException $e) {
181 181
 			if($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) {
182
-            			throw $e;
183
-	                }
184
-	                //echo 'error ! '.$e->getMessage();
182
+						throw $e;
183
+					}
184
+					//echo 'error ! '.$e->getMessage();
185 185
 			return false;
186 186
 		}
187 187
 		return true; 
@@ -285,8 +285,8 @@  discard block
 block discarded – undo
285 285
 		$version = 0;
286 286
 		if ($this->tableExists('aircraft')) {
287 287
 			if (!$this->tableExists('config')) {
288
-	    			$version = '1';
289
-	    			return $version;
288
+					$version = '1';
289
+					return $version;
290 290
 			} else {
291 291
 				$query = "SELECT value FROM config WHERE name = 'schema_version' LIMIT 1";
292 292
 				try {
@@ -307,10 +307,10 @@  discard block
 block discarded – undo
307 307
 	* @return Boolean if latest version or not
308 308
 	*/
309 309
 	public function latest() {
310
-	    global $globalNoDB;
311
-	    if (isset($globalNoDB) && $globalNoDB === TRUE) return true;
312
-	    if ($this->check_schema_version() == $this->latest_schema) return true;
313
-	    else return false;
310
+		global $globalNoDB;
311
+		if (isset($globalNoDB) && $globalNoDB === TRUE) return true;
312
+		if ($this->check_schema_version() == $this->latest_schema) return true;
313
+		else return false;
314 314
 	}
315 315
 
316 316
 }
Please login to merge, or discard this patch.
require/class.TrackerImport.php 1 patch
Indentation   +174 added lines, -174 removed lines patch added patch discarded remove patch
@@ -7,16 +7,16 @@  discard block
 block discarded – undo
7 7
 require_once(dirname(__FILE__).'/class.Source.php');
8 8
 
9 9
 class TrackerImport {
10
-    private $all_tracked = array();
11
-    private $last_delete_hourly = 0;
12
-    private $last_delete = 0;
13
-    private $stats = array();
14
-    private $tmd = 0;
15
-    private $source_location = array();
16
-    public $db = null;
17
-    public $nb = 0;
10
+	private $all_tracked = array();
11
+	private $last_delete_hourly = 0;
12
+	private $last_delete = 0;
13
+	private $stats = array();
14
+	private $tmd = 0;
15
+	private $source_location = array();
16
+	public $db = null;
17
+	public $nb = 0;
18 18
 
19
-    public function __construct($dbc = null) {
19
+	public function __construct($dbc = null) {
20 20
 	global $globalBeta;
21 21
 	$Connection = new Connection($dbc);
22 22
 	$this->db = $Connection->db();
@@ -38,50 +38,50 @@  discard block
 block discarded – undo
38 38
 	    }
39 39
 	}
40 40
 	*/
41
-    }
41
+	}
42 42
 
43
-    public function checkAll() {
43
+	public function checkAll() {
44 44
 	global $globalDebug;
45 45
 	if ($globalDebug) echo "Update last seen tracked data...\n";
46 46
 	foreach ($this->all_tracked as $key => $flight) {
47
-	    if (isset($this->all_tracked[$key]['id'])) {
47
+		if (isset($this->all_tracked[$key]['id'])) {
48 48
 		//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
49
-    		$Tracker = new Tracker($this->db);
50
-        	$Tracker->updateLatestTrackerData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['altitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
51
-            }
49
+			$Tracker = new Tracker($this->db);
50
+			$Tracker->updateLatestTrackerData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['altitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
51
+			}
52
+	}
52 53
 	}
53
-    }
54 54
 
55
-    public function del() {
55
+	public function del() {
56 56
 	global $globalDebug;
57 57
 	// Delete old infos
58 58
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
59 59
 	foreach ($this->all_tracked as $key => $flight) {
60
-    	    if (isset($flight['lastupdate'])) {
61
-        	if ($flight['lastupdate'] < (time()-3000)) {
62
-            	    if (isset($this->all_tracked[$key]['id'])) {
63
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
60
+			if (isset($flight['lastupdate'])) {
61
+			if ($flight['lastupdate'] < (time()-3000)) {
62
+					if (isset($this->all_tracked[$key]['id'])) {
63
+					if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
64 64
 			/*
65 65
 			$TrackerLive = new TrackerLive();
66 66
             		$TrackerLive->deleteLiveTrackerDataById($this->all_tracked[$key]['id']);
67 67
 			$TrackerLive->db = null;
68 68
 			*/
69
-            		//$real_arrival = $this->arrival($key);
70
-            		$Tracker = new Tracker($this->db);
71
-            		if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
69
+					//$real_arrival = $this->arrival($key);
70
+					$Tracker = new Tracker($this->db);
71
+					if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
72 72
 				$result = $Tracker->updateLatestTrackerData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['altitude'],$this->all_tracked[$key]['speed']);
73 73
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
74 74
 			}
75 75
 			// Put in archive
76 76
 //			$Tracker->db = null;
77
-            	    }
78
-            	    unset($this->all_tracked[$key]);
79
-    	        }
80
-	    }
81
-        }
82
-    }
77
+					}
78
+					unset($this->all_tracked[$key]);
79
+				}
80
+		}
81
+		}
82
+	}
83 83
 
84
-    public function add($line) {
84
+	public function add($line) {
85 85
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked;
86 86
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
87 87
 	date_default_timezone_set('UTC');
@@ -90,47 +90,47 @@  discard block
 block discarded – undo
90 90
 	
91 91
 	// SBS format is CSV format
92 92
 	if(is_array($line) && isset($line['ident'])) {
93
-	    //print_r($line);
94
-  	    if (isset($line['ident'])) {
93
+		//print_r($line);
94
+  		if (isset($line['ident'])) {
95 95
 
96 96
 		
97 97
 		// Increment message number
98 98
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
99
-		    $current_date = date('Y-m-d');
100
-		    if (isset($line['source_name'])) $source = $line['source_name'];
101
-		    else $source = '';
102
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
103
-		    if (!isset($this->stats[$current_date][$source]['msg'])) {
104
-		    	$this->stats[$current_date][$source]['msg']['date'] = time();
105
-		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
106
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
99
+			$current_date = date('Y-m-d');
100
+			if (isset($line['source_name'])) $source = $line['source_name'];
101
+			else $source = '';
102
+			if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
103
+			if (!isset($this->stats[$current_date][$source]['msg'])) {
104
+				$this->stats[$current_date][$source]['msg']['date'] = time();
105
+				$this->stats[$current_date][$source]['msg']['nb'] = 1;
106
+			} else $this->stats[$current_date][$source]['msg']['nb'] += 1;
107 107
 		}
108 108
 		
109 109
 		
110 110
 		$Common = new Common();
111
-	        if (!isset($line['id'])) $id = trim($line['ident']);
112
-	        else $id = trim($line['id']);
111
+			if (!isset($line['id'])) $id = trim($line['ident']);
112
+			else $id = trim($line['id']);
113 113
 		
114 114
 		if (!isset($this->all_tracked[$id])) {
115
-		    $this->all_tracked[$id] = array();
116
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedTracker' => 0));
117
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','noarchive' => false,'putinarchive' => true,'over_country' => ''));
118
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
119
-		    if (!isset($line['id'])) {
115
+			$this->all_tracked[$id] = array();
116
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedTracker' => 0));
117
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','noarchive' => false,'putinarchive' => true,'over_country' => ''));
118
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
119
+			if (!isset($line['id'])) {
120 120
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
121 121
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
122
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
123
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
122
+			 } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
123
+			if ($globalAllTracked !== FALSE) $dataFound = true;
124 124
 		}
125 125
 		
126 126
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60 && strtotime($line['datetime']) < time()+20*60) {
127
-		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_tracked[$id]['datetime'])) {
127
+			if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_tracked[$id]['datetime'])) {
128 128
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
129
-		    } else {
129
+			} else {
130 130
 				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['ident']." - format : ".$line['format_source']."\n";
131 131
 				elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['ident']." - format : ".$line['format_source']."\n";
132 132
 				return '';
133
-		    }
133
+			}
134 134
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) {
135 135
 			if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['ident']." - format : ".$line['format_source']."!!!";
136 136
 			return '';
@@ -147,38 +147,38 @@  discard block
 block discarded – undo
147 147
 		
148 148
 		//if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9-]+$/', $line['ident'])) {
149 149
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
150
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
151
-		    if ($this->all_tracked[$id]['addedTracker'] == 1) {
150
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
151
+			if ($this->all_tracked[$id]['addedTracker'] == 1) {
152 152
 			$timeelapsed = microtime(true);
153
-            		$Tracker = new Tracker($this->db);
154
-            		$fromsource = NULL;
155
-            		$result = $Tracker->updateIdentTrackerData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
153
+					$Tracker = new Tracker($this->db);
154
+					$fromsource = NULL;
155
+					$result = $Tracker->updateIdentTrackerData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
156 156
 			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
157 157
 			$Tracker->db = null;
158 158
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
159
-		    }
160
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
159
+			}
160
+			if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
161 161
 		}
162 162
 
163 163
 		if (isset($line['speed']) && $line['speed'] != '') {
164
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
165
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
164
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
165
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
166 166
 		} else if (!isset($this->all_tracked[$id]['speed_fromsrc']) && isset($this->all_tracked[$id]['time_last_coord']) && $this->all_tracked[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
167
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
168
-		    if ($distance > 100 && $distance < 10000) {
167
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
168
+			if ($distance > 100 && $distance < 10000) {
169 169
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
170 170
 			$speed = $speed*3.6;
171 171
 			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
172 172
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['ident']." : ".$speed." - distance : ".$distance."\n";
173
-		    }
173
+			}
174 174
 		}
175 175
 
176
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
177
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
178
-	    	    else unset($timediff);
179
-	    	    if ($this->tmd > 5 || !isset($timediff) || $timediff > 100 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) {
176
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
177
+				if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
178
+				else unset($timediff);
179
+				if ($this->tmd > 5 || !isset($timediff) || $timediff > 100 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) {
180 180
 			if (isset($this->all_tracked[$id]['archive_latitude']) && isset($this->all_tracked[$id]['archive_longitude']) && isset($this->all_tracked[$id]['livedb_latitude']) && isset($this->all_tracked[$id]['livedb_longitude'])) {
181
-			    if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
181
+				if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
182 182
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
183 183
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
184 184
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -192,160 +192,160 @@  discard block
 block discarded – undo
192 192
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
193 193
 				$this->tmd = 0;
194 194
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
195
-			    }
195
+				}
196 196
 			}
197 197
 
198 198
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
199 199
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
200 200
 				if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
201
-				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
202
-				    $dataFound = true;
203
-				    $this->all_tracked[$id]['time_last_coord'] = time();
201
+					$this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
202
+					$dataFound = true;
203
+					$this->all_tracked[$id]['time_last_coord'] = time();
204 204
 				}
205 205
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
206 206
 			}
207 207
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
208
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
208
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
209 209
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
210 210
 				if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
211
-				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
212
-				    $dataFound = true;
213
-				    $this->all_tracked[$id]['time_last_coord'] = time();
211
+					$this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
212
+					$dataFound = true;
213
+					$this->all_tracked[$id]['time_last_coord'] = time();
214 214
 				}
215 215
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
216 216
 			}
217 217
 
218
-		    } else if ($globalDebug && $timediff > 20) {
218
+			} else if ($globalDebug && $timediff > 20) {
219 219
 			$this->tmd = $this->tmd + 1;
220 220
 			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
221 221
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
222 222
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
223 223
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
224
-		    }
224
+			}
225 225
 		}
226 226
 		if (isset($line['last_update']) && $line['last_update'] != '') {
227
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
228
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
227
+			if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
228
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
229 229
 		}
230 230
 		if (isset($line['format_source']) && $line['format_source'] != '') {
231
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
231
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
232 232
 		}
233 233
 		if (isset($line['source_name']) && $line['source_name'] != '') {
234
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
234
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
235 235
 		}
236 236
 		if (isset($line['comment']) && $line['comment'] != '') {
237
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('comment' => $line['comment']));
238
-		    //$dataFound = true;
237
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('comment' => $line['comment']));
238
+			//$dataFound = true;
239 239
 		}
240 240
 		if (isset($line['type']) && $line['type'] != '') {
241
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
242
-		    //$dataFound = true;
241
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
242
+			//$dataFound = true;
243 243
 		}
244 244
 
245 245
 		if (isset($line['altitude']) && $line['altitude'] != '') {
246
-		    //if (!isset($this->all_tracked[$id]['altitude']) || $this->all_tracked[$id]['altitude'] == '' || ($this->all_tracked[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
246
+			//if (!isset($this->all_tracked[$id]['altitude']) || $this->all_tracked[$id]['altitude'] == '' || ($this->all_tracked[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
247 247
 			if (is_int($this->all_tracked[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_tracked[$id]['altitude']) > 3) $this->all_tracked[$id]['putinarchive'] = true;
248 248
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('altitude' => $line['altitude']));
249 249
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('altitude_real' => $line['altitude']));
250 250
 			//$dataFound = true;
251
-		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
251
+			//} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
252 252
   		}
253 253
 
254 254
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
255
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
255
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
256 256
 		}
257 257
 		
258 258
 		if (isset($line['heading']) && $line['heading'] != '') {
259
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
260
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
261
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
262
-		    //$dataFound = true;
259
+			if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
260
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
261
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
262
+			//$dataFound = true;
263 263
   		} elseif (!isset($this->all_tracked[$id]['heading_fromsrc']) && isset($this->all_tracked[$id]['archive_latitude']) && $this->all_tracked[$id]['archive_latitude'] != $this->all_tracked[$id]['latitude'] && isset($this->all_tracked[$id]['archive_longitude']) && $this->all_tracked[$id]['archive_longitude'] != $this->all_tracked[$id]['longitude']) {
264
-  		    $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
265
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
266
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
267
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
264
+  			$heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
265
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
266
+			if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
267
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
268 268
   		}
269 269
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
270 270
 
271 271
 		if ($dataFound === true && isset($this->all_tracked[$id]['ident'])) {
272
-		    $this->all_tracked[$id]['lastupdate'] = time();
273
-		    if ($this->all_tracked[$id]['addedTracker'] == 0) {
274
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == ''  || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
275
-			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
272
+			$this->all_tracked[$id]['lastupdate'] = time();
273
+			if ($this->all_tracked[$id]['addedTracker'] == 0) {
274
+				if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == ''  || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
275
+				if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
276 276
 				if ($globalDebug) echo "Check if aircraft is already in DB...";
277 277
 				$timeelapsed = microtime(true);
278 278
 				$TrackerLive = new TrackerLive($this->db);
279 279
 				if (isset($line['id'])) {
280
-				    $recent_ident = $TrackerLive->checkIdRecent($line['id']);
281
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
280
+					$recent_ident = $TrackerLive->checkIdRecent($line['id']);
281
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
282 282
 				} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
283
-				    $recent_ident = $TrackerLive->checkIdentRecent($this->all_tracked[$id]['ident']);
284
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
283
+					$recent_ident = $TrackerLive->checkIdentRecent($this->all_tracked[$id]['ident']);
284
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
285 285
 				} else $recent_ident = '';
286 286
 				$TrackerLive->db=null;
287 287
 
288 288
 				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
289 289
 				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
290
-			    } else {
290
+				} else {
291 291
 				$recent_ident = '';
292 292
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
293
-			    }
294
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
295
-			    if($recent_ident == "")
296
-			    {
293
+				}
294
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
295
+				if($recent_ident == "")
296
+				{
297 297
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." in archive DB : ";
298 298
 				//adds the spotter data for the archive
299
-				    $highlight = '';
300
-				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'].'-'.date('YmdHi')));
301
-				    $timeelapsed = microtime(true);
302
-				    $Tracker = new Tracker($this->db);
303
-				    $result = $Tracker->addTrackerData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['altitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['comment'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
304
-				    $Tracker->db = null;
305
-				    if ($globalDebug && isset($result)) echo $result."\n";
306
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
299
+					$highlight = '';
300
+					if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'].'-'.date('YmdHi')));
301
+					$timeelapsed = microtime(true);
302
+					$Tracker = new Tracker($this->db);
303
+					$result = $Tracker->addTrackerData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['altitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['comment'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
304
+					$Tracker->db = null;
305
+					if ($globalDebug && isset($result)) echo $result."\n";
306
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
307 307
 				    
308 308
 				    
309
-				    // Add source stat in DB
310
-				    $Stats = new Stats($this->db);
311
-				    if (!empty($this->stats)) {
309
+					// Add source stat in DB
310
+					$Stats = new Stats($this->db);
311
+					if (!empty($this->stats)) {
312 312
 					if ($globalDebug) echo 'Add source stats : ';
313
-				        foreach($this->stats as $date => $data) {
314
-					    foreach($data as $source => $sourced) {
315
-					        //print_r($sourced);
316
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_tracker',$date);
317
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_tracker',$date);
318
-				    		if (isset($sourced['msg'])) {
319
-				    		    if (time() - $sourced['msg']['date'] > 10) {
320
-				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
321
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg_tracker',$date);
322
-			    			        unset($this->stats[$date][$source]['msg']);
323
-			    			    }
324
-			    			}
325
-			    		    }
326
-			    		    if ($date != date('Y-m-d')) {
327
-			    			unset($this->stats[$date]);
328
-			    		    }
329
-				    	}
330
-				    	if ($globalDebug) echo 'Done'."\n";
313
+						foreach($this->stats as $date => $data) {
314
+						foreach($data as $source => $sourced) {
315
+							//print_r($sourced);
316
+								if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_tracker',$date);
317
+								if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_tracker',$date);
318
+							if (isset($sourced['msg'])) {
319
+								if (time() - $sourced['msg']['date'] > 10) {
320
+									$nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
321
+									echo $Stats->addStatSource($nbmsg,$source,'msg_tracker',$date);
322
+									unset($this->stats[$date][$source]['msg']);
323
+								}
324
+							}
325
+							}
326
+							if ($date != date('Y-m-d')) {
327
+							unset($this->stats[$date]);
328
+							}
329
+						}
330
+						if ($globalDebug) echo 'Done'."\n";
331 331
 
332
-				    }
333
-				    $Stats->db = null;
332
+					}
333
+					$Stats->db = null;
334 334
 				    
335
-				    $this->del();
335
+					$this->del();
336 336
 				//$ignoreImport = false;
337 337
 				$this->all_tracked[$id]['addedTracker'] = 1;
338 338
 				//print_r($this->all_tracked[$id]);
339 339
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
340
-				    if ($globalDebug) echo "---- Deleting Live Tracker data older than 9 hours...";
341
-				    //TrackerLive->deleteLiveTrackerDataNotUpdated();
342
-				    $TrackerLive = new TrackerLive($this->db);
343
-				    $TrackerLive->deleteLiveTrackerData();
344
-				    $TrackerLive->db=null;
345
-				    if ($globalDebug) echo " Done\n";
346
-				    $this->last_delete = time();
340
+					if ($globalDebug) echo "---- Deleting Live Tracker data older than 9 hours...";
341
+					//TrackerLive->deleteLiveTrackerDataNotUpdated();
342
+					$TrackerLive = new TrackerLive($this->db);
343
+					$TrackerLive->deleteLiveTrackerData();
344
+					$TrackerLive->db=null;
345
+					if ($globalDebug) echo " Done\n";
346
+					$this->last_delete = time();
347 347
 				}
348
-			    } else {
348
+				} else {
349 349
 				$this->all_tracked[$id]['id'] = $recent_ident;
350 350
 				$this->all_tracked[$id]['addedTracker'] = 1;
351 351
 				if (isset($globalDaemon) && !$globalDaemon) {
@@ -354,16 +354,16 @@  discard block
 block discarded – undo
354 354
 					$Tracker->db = null;
355 355
 				}
356 356
 				
357
-			    }
357
+				}
358 358
 			}
359
-		    }
360
-		    //adds the spotter LIVE data
361
-		    if ($globalDebug) {
359
+			}
360
+			//adds the spotter LIVE data
361
+			if ($globalDebug) {
362 362
 			echo 'DATA : ident : '.$this->all_tracked[$id]['ident'].' - type : '.$this->all_tracked[$id]['type'].' - Latitude : '.$this->all_tracked[$id]['latitude'].' - Longitude : '.$this->all_tracked[$id]['longitude'].' - Altitude : '.$this->all_tracked[$id]['altitude'].' - Heading : '.$this->all_tracked[$id]['heading'].' - Speed : '.$this->all_tracked[$id]['speed']."\n";
363
-		    }
364
-		    $ignoreImport = false;
363
+			}
364
+			$ignoreImport = false;
365 365
 
366
-		    if (!$ignoreImport) {
366
+			if (!$ignoreImport) {
367 367
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
368 368
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
369 369
 				$timeelapsed = microtime(true);
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
 					if ($stats_heading == 16) $stats_heading = 0;
402 402
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
403 403
 						for ($i=0;$i<=15;$i++) {
404
-						    $this->stats[$current_date][$source]['polar'][$i] = 0;
404
+							$this->stats[$current_date][$source]['polar'][$i] = 0;
405 405
 						}
406 406
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
407 407
 					} else {
@@ -414,11 +414,11 @@  discard block
 block discarded – undo
414 414
 					//var_dump($this->stats);
415 415
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
416 416
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
417
-						    end($this->stats[$current_date][$source]['hist']);
418
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
417
+							end($this->stats[$current_date][$source]['hist']);
418
+							$mini = key($this->stats[$current_date][$source]['hist'])+10;
419 419
 						} else $mini = 0;
420 420
 						for ($i=$mini;$i<=$distance;$i+=10) {
421
-						    $this->stats[$current_date][$source]['hist'][$i] = 0;
421
+							$this->stats[$current_date][$source]['hist'][$i] = 0;
422 422
 						}
423 423
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
424 424
 					} else {
@@ -434,22 +434,22 @@  discard block
 block discarded – undo
434 434
 			
435 435
 			
436 436
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
437
-			    if ($globalDebug) echo "---- Deleting Live Tracker data Not updated since 2 hour...";
438
-			    $TrackerLive = new TrackerLive($this->db);
439
-			    $TrackerLive->deleteLiveTrackerDataNotUpdated();
440
-			    $TrackerLive->db = null;
441
-			    //TrackerLive->deleteLiveTrackerData();
442
-			    if ($globalDebug) echo " Done\n";
443
-			    $this->last_delete_hourly = time();
437
+				if ($globalDebug) echo "---- Deleting Live Tracker data Not updated since 2 hour...";
438
+				$TrackerLive = new TrackerLive($this->db);
439
+				$TrackerLive->deleteLiveTrackerDataNotUpdated();
440
+				$TrackerLive->db = null;
441
+				//TrackerLive->deleteLiveTrackerData();
442
+				if ($globalDebug) echo " Done\n";
443
+				$this->last_delete_hourly = time();
444 444
 			}
445 445
 			
446
-		    }
447
-		    //$ignoreImport = false;
446
+			}
447
+			//$ignoreImport = false;
448 448
 		}
449 449
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
450 450
 		if ($send) return $this->all_tracked[$id];
451
-	    }
451
+		}
452
+	}
452 453
 	}
453
-    }
454 454
 }
455 455
 ?>
Please login to merge, or discard this patch.
footer.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,12 +6,12 @@
 block discarded – undo
6 6
 </div>
7 7
 <footer class="container">
8 8
 	<?php
9
-	    if (isset($sql_time)) {
9
+		if (isset($sql_time)) {
10 10
 	?>
11 11
 	<i><?php echo _("Page generated in").' '.round($sql_time+$page_time,2); ?>s (<?php print round($page_time,2); ?>ms PHP - <?php print round($sql_time,2); ?>ms SQL)</i>
12 12
 	<br />
13 13
 	<?php
14
-	    }
14
+		}
15 15
 	?>
16 16
 	<span>Developed in Barrie by <a href="http://mtru.nz/" target="_blank">Mario Trunz</a> & at <a href="http://www.zugaina.com" target="_blank">Zugaina</a> by Ycarus</span> - <span><a href="<?php if (isset($globalURL)) print $globalURL; ?>/about#source">Source &amp; Credits</a></span> - <span><a href="https://www.flightairmap.fr/" target="_blank">Get source code</a></span>
17 17
 </footer>
Please login to merge, or discard this patch.
scripts/daemon-spotter.php 1 patch
Indentation   +898 added lines, -898 removed lines patch added patch discarded remove patch
@@ -16,8 +16,8 @@  discard block
 block discarded – undo
16 16
 require_once(dirname(__FILE__).'/../require/class.Common.php');
17 17
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
18 18
 if (isset($globalMarine) && $globalMarine) {
19
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
20
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
19
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
20
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
21 21
 }
22 22
 
23 23
 if (!isset($globalDebug)) $globalDebug = FALSE;
@@ -25,42 +25,42 @@  discard block
 block discarded – undo
25 25
 // Check if schema is at latest version
26 26
 $Connection = new Connection();
27 27
 if ($Connection->latest() === false) {
28
-    echo "You MUST update to latest schema. Run install/index.php";
29
-    exit();
28
+	echo "You MUST update to latest schema. Run install/index.php";
29
+	exit();
30 30
 }
31 31
 if (PHP_SAPI != 'cli') {
32
-    echo "This script MUST be called from console, not a web browser.";
32
+	echo "This script MUST be called from console, not a web browser.";
33 33
 //    exit();
34 34
 }
35 35
 
36 36
 // This is to be compatible with old version of settings.php
37 37
 if (!isset($globalSources)) {
38
-    if (isset($globalSBS1Hosts)) {
39
-        //$hosts = $globalSBS1Hosts;
40
-        foreach ($globalSBS1Hosts as $host) {
41
-	    $globalSources[] = array('host' => $host);
42
-    	}
43
-    } else {
44
-        if (!isset($globalSBS1Host)) {
45
-	    echo '$globalSources MUST be defined !';
46
-	    die;
38
+	if (isset($globalSBS1Hosts)) {
39
+		//$hosts = $globalSBS1Hosts;
40
+		foreach ($globalSBS1Hosts as $host) {
41
+		$globalSources[] = array('host' => $host);
42
+		}
43
+	} else {
44
+		if (!isset($globalSBS1Host)) {
45
+		echo '$globalSources MUST be defined !';
46
+		die;
47 47
 	}
48 48
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
49 49
 	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
50
-    }
50
+	}
51 51
 }
52 52
 
53 53
 $options = getopt('s::',array('source::','server','nodaemon','idsource::','aprsserverssid::','aprsserverpass::','aprsserverhost::','aprsserverport::','format::','noaprsserver'));
54 54
 //if (isset($options['s'])) $hosts = array($options['s']);
55 55
 //elseif (isset($options['source'])) $hosts = array($options['source']);
56 56
 if (isset($options['s'])) {
57
-    $globalSources = array();
58
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
59
-    else $globalSources[] = array('host' => $options['s']);
57
+	$globalSources = array();
58
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
59
+	else $globalSources[] = array('host' => $options['s']);
60 60
 } elseif (isset($options['source'])) {
61
-    $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
63
-    else $globalSources[] = array('host' => $options['source']);
61
+	$globalSources = array();
62
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
63
+	else $globalSources[] = array('host' => $options['source']);
64 64
 }
65 65
 if (isset($options['aprsserverhost'])) {
66 66
 	$globalServerAPRS = TRUE;
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
 if (isset($options['idsource'])) $id_source = $options['idsource'];
76 76
 else $id_source = 1;
77 77
 if (isset($globalServer) && $globalServer) {
78
-    if ($globalDebug) echo "Using Server Mode\n";
79
-    $SI=new SpotterServer();
78
+	if ($globalDebug) echo "Using Server Mode\n";
79
+	$SI=new SpotterServer();
80 80
 /*
81 81
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
82 82
     $SI = new adsb2aprs();
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
 } else $SI=new SpotterImport($Connection->db);
86 86
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
87 87
 if (isset($globalMarine) && $globalMarine) {
88
-    $AIS = new AIS();
89
-    $MI = new MarineImport($Connection->db);
88
+	$AIS = new AIS();
89
+	$MI = new MarineImport($Connection->db);
90 90
 }
91 91
 //$APRS=new APRS($Connection->db);
92 92
 $SBS=new SBS();
@@ -97,12 +97,12 @@  discard block
 block discarded – undo
97 97
 //$servertz = system('date +%Z');
98 98
 // signal handler - playing nice with sockets and dump1090
99 99
 if (function_exists('pcntl_fork')) {
100
-    pcntl_signal(SIGINT,  function() {
101
-        global $sockets;
102
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
103
-        die("Bye!\n");
104
-    });
105
-    pcntl_signal_dispatch();
100
+	pcntl_signal(SIGINT,  function() {
101
+		global $sockets;
102
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
103
+		die("Bye!\n");
104
+	});
105
+	pcntl_signal_dispatch();
106 106
 }
107 107
 
108 108
 // let's try and connect
@@ -112,36 +112,36 @@  discard block
 block discarded – undo
112 112
 $reset = 0;
113 113
 
114 114
 function connect_all($hosts) {
115
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
116
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
117
-    $reset++;
118
-    if ($globalDebug) echo 'Connect to all...'."\n";
119
-    foreach ($hosts as $id => $value) {
115
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
116
+	global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
117
+	$reset++;
118
+	if ($globalDebug) echo 'Connect to all...'."\n";
119
+	foreach ($hosts as $id => $value) {
120 120
 	$host = $value['host'];
121 121
 	$globalSources[$id]['last_exec'] = 0;
122 122
 	// Here we check type of source(s)
123 123
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
124
-            if (preg_match('/deltadb.txt$/i',$host)) {
125
-        	//$formats[$id] = 'deltadbtxt';
126
-        	$globalSources[$id]['format'] = 'deltadbtxt';
127
-        	//$last_exec['deltadbtxt'] = 0;
128
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
129
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
130
-        	//$formats[$id] = 'vatsimtxt';
131
-        	$globalSources[$id]['format'] = 'vatsimtxt';
132
-        	//$last_exec['vatsimtxt'] = 0;
133
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
134
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
135
-        	//$formats[$id] = 'aircraftlistjson';
136
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
137
-        	//$last_exec['aircraftlistjson'] = 0;
138
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
139
-    	    } else if (preg_match('/opensky/i',$host)) {
140
-        	//$formats[$id] = 'aircraftlistjson';
141
-        	$globalSources[$id]['format'] = 'opensky';
142
-        	//$last_exec['aircraftlistjson'] = 0;
143
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
144
-    	    /*
124
+			if (preg_match('/deltadb.txt$/i',$host)) {
125
+			//$formats[$id] = 'deltadbtxt';
126
+			$globalSources[$id]['format'] = 'deltadbtxt';
127
+			//$last_exec['deltadbtxt'] = 0;
128
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
129
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
130
+			//$formats[$id] = 'vatsimtxt';
131
+			$globalSources[$id]['format'] = 'vatsimtxt';
132
+			//$last_exec['vatsimtxt'] = 0;
133
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
134
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
135
+			//$formats[$id] = 'aircraftlistjson';
136
+			$globalSources[$id]['format'] = 'aircraftlistjson';
137
+			//$last_exec['aircraftlistjson'] = 0;
138
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
139
+			} else if (preg_match('/opensky/i',$host)) {
140
+			//$formats[$id] = 'aircraftlistjson';
141
+			$globalSources[$id]['format'] = 'opensky';
142
+			//$last_exec['aircraftlistjson'] = 0;
143
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
144
+			/*
145 145
     	    // Disabled for now, site change source format
146 146
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
147 147
         	//$formats[$id] = 'radarvirtueljson';
@@ -153,118 +153,118 @@  discard block
 block discarded – undo
153 153
         	    exit(0);
154 154
         	}
155 155
     	    */
156
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
157
-        	//$formats[$id] = 'planeupdatefaa';
158
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
159
-        	//$last_exec['planeupdatefaa'] = 0;
160
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
161
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
162
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
163
-        	    exit(0);
164
-        	}
165
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
166
-        	//$formats[$id] = 'phpvmacars';
167
-        	$globalSources[$id]['format'] = 'phpvmacars';
168
-        	//$last_exec['phpvmacars'] = 0;
169
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
170
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
171
-        	//$formats[$id] = 'phpvmacars';
172
-        	$globalSources[$id]['format'] = 'vam';
173
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
174
-            } else if (preg_match('/whazzup/i',$host)) {
175
-        	//$formats[$id] = 'whazzup';
176
-        	$globalSources[$id]['format'] = 'whazzup';
177
-        	//$last_exec['whazzup'] = 0;
178
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
179
-            } else if (preg_match('/airwhere/i',$host)) {
180
-        	$globalSources[$id]['format'] = 'airwhere';
181
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
182
-            } else if (preg_match('/recentpireps/i',$host)) {
183
-        	//$formats[$id] = 'pirepsjson';
184
-        	$globalSources[$id]['format'] = 'pirepsjson';
185
-        	//$last_exec['pirepsjson'] = 0;
186
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
187
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
188
-        	//$formats[$id] = 'fr24json';
189
-        	$globalSources[$id]['format'] = 'fr24json';
190
-        	//$last_exec['fr24json'] = 0;
191
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
192
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
193
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
194
-        	    exit(0);
195
-        	}
196
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
197
-        	//$formats[$id] = 'fr24json';
198
-        	$globalSources[$id]['format'] = 'myshiptracking';
199
-        	//$last_exec['fr24json'] = 0;
200
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
201
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
202
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
203
-        	    exit(0);
204
-        	}
205
-            //} else if (preg_match('/10001/',$host)) {
206
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
207
-        	//$formats[$id] = 'tsv';
208
-        	$globalSources[$id]['format'] = 'tsv';
209
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
210
-            }
211
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
212
-    		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
213
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
214
-    		    if ($idf !== false) {
215
-    			$httpfeeds[$id] = $idf;
216
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
217
-    		    }
218
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
219
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
220
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
221
-	    $hostport = explode(':',$host);
222
-	    if (isset($hostport[1])) {
156
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
157
+			//$formats[$id] = 'planeupdatefaa';
158
+			$globalSources[$id]['format'] = 'planeupdatefaa';
159
+			//$last_exec['planeupdatefaa'] = 0;
160
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
161
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
162
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
163
+				exit(0);
164
+			}
165
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
166
+			//$formats[$id] = 'phpvmacars';
167
+			$globalSources[$id]['format'] = 'phpvmacars';
168
+			//$last_exec['phpvmacars'] = 0;
169
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
170
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
171
+			//$formats[$id] = 'phpvmacars';
172
+			$globalSources[$id]['format'] = 'vam';
173
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
174
+			} else if (preg_match('/whazzup/i',$host)) {
175
+			//$formats[$id] = 'whazzup';
176
+			$globalSources[$id]['format'] = 'whazzup';
177
+			//$last_exec['whazzup'] = 0;
178
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
179
+			} else if (preg_match('/airwhere/i',$host)) {
180
+			$globalSources[$id]['format'] = 'airwhere';
181
+			if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
182
+			} else if (preg_match('/recentpireps/i',$host)) {
183
+			//$formats[$id] = 'pirepsjson';
184
+			$globalSources[$id]['format'] = 'pirepsjson';
185
+			//$last_exec['pirepsjson'] = 0;
186
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
187
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
188
+			//$formats[$id] = 'fr24json';
189
+			$globalSources[$id]['format'] = 'fr24json';
190
+			//$last_exec['fr24json'] = 0;
191
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
192
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
193
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
194
+				exit(0);
195
+			}
196
+			} else if (preg_match(':myshiptracking.com/:i',$host)) {
197
+			//$formats[$id] = 'fr24json';
198
+			$globalSources[$id]['format'] = 'myshiptracking';
199
+			//$last_exec['fr24json'] = 0;
200
+			if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
201
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
202
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
203
+				exit(0);
204
+			}
205
+			//} else if (preg_match('/10001/',$host)) {
206
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
207
+			//$formats[$id] = 'tsv';
208
+			$globalSources[$id]['format'] = 'tsv';
209
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
210
+			}
211
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
212
+			if ($globalSources[$id]['format'] == 'aisnmeahttp') {
213
+				$idf = fopen($globalSources[$id]['host'],'r',false,$context);
214
+				if ($idf !== false) {
215
+				$httpfeeds[$id] = $idf;
216
+				if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
217
+				}
218
+				elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
219
+			} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
220
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
221
+		$hostport = explode(':',$host);
222
+		if (isset($hostport[1])) {
223 223
 		$port = $hostport[1];
224 224
 		$hostn = $hostport[0];
225
-	    } else {
225
+		} else {
226 226
 		$port = $globalSources[$id]['port'];
227 227
 		$hostn = $globalSources[$id]['host'];
228
-	    }
229
-	    $Common = new Common();
230
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
231
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
232
-    	    } else {
233
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
234
-	    }
235
-	    if ($s) {
236
-    	        $sockets[$id] = $s;
237
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
238
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
228
+		}
229
+		$Common = new Common();
230
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
231
+			$s = $Common->create_socket($hostn,$port, $errno, $errstr);
232
+			} else {
233
+			$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
234
+		}
235
+		if ($s) {
236
+				$sockets[$id] = $s;
237
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
238
+			if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
239 239
 			//$formats[$id] = 'aprs';
240 240
 			$globalSources[$id]['format'] = 'aprs';
241 241
 			//$aprs_connect = 0;
242 242
 			//$use_aprs = true;
243
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
243
+			} elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
244 244
 			$globalSources[$id]['format'] = 'vrstcp';
245
-    		    } elseif ($port == '10001') {
246
-        		//$formats[$id] = 'tsv';
247
-        		$globalSources[$id]['format'] = 'tsv';
248
-		    } elseif ($port == '30002') {
249
-        		//$formats[$id] = 'raw';
250
-        		$globalSources[$id]['format'] = 'raw';
251
-		    } elseif ($port == '5001') {
252
-        		//$formats[$id] = 'raw';
253
-        		$globalSources[$id]['format'] = 'flightgearmp';
254
-		    } elseif ($port == '30005') {
245
+				} elseif ($port == '10001') {
246
+				//$formats[$id] = 'tsv';
247
+				$globalSources[$id]['format'] = 'tsv';
248
+			} elseif ($port == '30002') {
249
+				//$formats[$id] = 'raw';
250
+				$globalSources[$id]['format'] = 'raw';
251
+			} elseif ($port == '5001') {
252
+				//$formats[$id] = 'raw';
253
+				$globalSources[$id]['format'] = 'flightgearmp';
254
+			} elseif ($port == '30005') {
255 255
 			// Not yet supported
256
-        		//$formats[$id] = 'beast';
257
-        		$globalSources[$id]['format'] = 'beast';
258
-		    //} else $formats[$id] = 'sbs';
259
-		    } else $globalSources[$id]['format'] = 'sbs';
260
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
256
+				//$formats[$id] = 'beast';
257
+				$globalSources[$id]['format'] = 'beast';
258
+			//} else $formats[$id] = 'sbs';
259
+			} else $globalSources[$id]['format'] = 'sbs';
260
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
261 261
 		}
262 262
 		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
263
-            } else {
263
+			} else {
264 264
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
265
-    	    }
266
-        }
267
-    }
265
+			}
266
+		}
267
+	}
268 268
 }
269 269
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
270 270
 
@@ -287,9 +287,9 @@  discard block
 block discarded – undo
287 287
 //connect_all($globalSources);
288 288
 
289 289
 if (isset($globalProxy) && $globalProxy) {
290
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
290
+	$context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
291 291
 } else {
292
-    $context = stream_context_create(array('http' => array('timeout' => $timeout)));
292
+	$context = stream_context_create(array('http' => array('timeout' => $timeout)));
293 293
 }
294 294
 
295 295
 // APRS Configuration
@@ -298,18 +298,18 @@  discard block
 block discarded – undo
298 298
 	die;
299 299
 }
300 300
 foreach ($globalSources as $key => $source) {
301
-    if (!isset($source['format'])) {
302
-        $globalSources[$key]['format'] = 'auto';
303
-    }
301
+	if (!isset($source['format'])) {
302
+		$globalSources[$key]['format'] = 'auto';
303
+	}
304 304
 }
305 305
 connect_all($globalSources);
306 306
 foreach ($globalSources as $key => $source) {
307
-    if (isset($source['format']) && $source['format'] == 'aprs') {
307
+	if (isset($source['format']) && $source['format'] == 'aprs') {
308 308
 	$aprs_connect = 0;
309 309
 	$use_aprs = true;
310 310
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
311 311
 	break;
312
-    }
312
+	}
313 313
 }
314 314
 
315 315
 if ($use_aprs) {
@@ -350,115 +350,115 @@  discard block
 block discarded – undo
350 350
 
351 351
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
352 352
 while ($i > 0) {
353
-    if (!$globalDaemon) $i = $endtime-time();
354
-    // Delete old ATC
355
-    if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
353
+	if (!$globalDaemon) $i = $endtime-time();
354
+	// Delete old ATC
355
+	if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
356 356
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
357
-        $ATC->deleteOldATC();
358
-    }
357
+		$ATC->deleteOldATC();
358
+	}
359 359
     
360
-    if (count($last_exec) == count($globalSources)) {
360
+	if (count($last_exec) == count($globalSources)) {
361 361
 	$max = $globalMinFetch;
362 362
 	foreach ($last_exec as $last) {
363
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
363
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
364 364
 	}
365 365
 	if ($max != $globalMinFetch) {
366
-	    if ($globalDebug) echo 'Sleeping...'."\n";
367
-	    sleep($globalMinFetch-$max+2);
366
+		if ($globalDebug) echo 'Sleeping...'."\n";
367
+		sleep($globalMinFetch-$max+2);
368
+	}
368 369
 	}
369
-    }
370 370
 
371 371
     
372
-    //foreach ($formats as $id => $value) {
373
-    foreach ($globalSources as $id => $value) {
372
+	//foreach ($formats as $id => $value) {
373
+	foreach ($globalSources as $id => $value) {
374 374
 	date_default_timezone_set('UTC');
375 375
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
376 376
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
377
-	    //$buffer = $Common->getData($hosts[$id]);
378
-	    $buffer = $Common->getData($value['host']);
379
-	    if ($buffer != '') $reset = 0;
380
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
381
-	    $buffer = explode('\n',$buffer);
382
-	    foreach ($buffer as $line) {
383
-    		if ($line != '' && count($line) > 7) {
384
-    		    $line = explode(',', $line);
385
-	            $data = array();
386
-	            $data['hex'] = $line[1]; // hex
387
-	            $data['ident'] = $line[2]; // ident
388
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
389
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
390
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
391
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
392
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
393
-	            $data['verticalrate'] = ''; // vertical rate
394
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
395
-	            $data['emergency'] = ''; // emergency
396
-		    $data['datetime'] = date('Y-m-d H:i:s');
397
-		    $data['format_source'] = 'deltadbtxt';
398
-    		    $data['id_source'] = $id_source;
399
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
400
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
401
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
402
-    		    $SI->add($data);
403
-		    unset($data);
404
-    		}
405
-    	    }
406
-    	    $last_exec[$id]['last'] = time();
377
+		//$buffer = $Common->getData($hosts[$id]);
378
+		$buffer = $Common->getData($value['host']);
379
+		if ($buffer != '') $reset = 0;
380
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
381
+		$buffer = explode('\n',$buffer);
382
+		foreach ($buffer as $line) {
383
+			if ($line != '' && count($line) > 7) {
384
+				$line = explode(',', $line);
385
+				$data = array();
386
+				$data['hex'] = $line[1]; // hex
387
+				$data['ident'] = $line[2]; // ident
388
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
389
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
390
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
391
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
392
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
393
+				$data['verticalrate'] = ''; // vertical rate
394
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
395
+				$data['emergency'] = ''; // emergency
396
+			$data['datetime'] = date('Y-m-d H:i:s');
397
+			$data['format_source'] = 'deltadbtxt';
398
+				$data['id_source'] = $id_source;
399
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
400
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
401
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
402
+				$SI->add($data);
403
+			unset($data);
404
+			}
405
+			}
406
+			$last_exec[$id]['last'] = time();
407 407
 	} elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
408
-	    date_default_timezone_set('CET');
409
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
410
-	    date_default_timezone_set('UTC');
411
-	    if ($buffer != '') $reset = 0;
412
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
413
-	    $buffer = explode('\n',$buffer);
414
-	    foreach ($buffer as $line) {
408
+		date_default_timezone_set('CET');
409
+		$buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
410
+		date_default_timezone_set('UTC');
411
+		if ($buffer != '') $reset = 0;
412
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
413
+		$buffer = explode('\n',$buffer);
414
+		foreach ($buffer as $line) {
415 415
 		if ($line != '') {
416
-		    echo "'".$line."'\n";
417
-		    $add = false;
418
-		    $ais_data = $AIS->parse_line(trim($line));
419
-		    $data = array();
420
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
421
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
422
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
423
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
424
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
425
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
426
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
427
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
428
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
429
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
430
-		    if (isset($ais_data['timestamp'])) {
416
+			echo "'".$line."'\n";
417
+			$add = false;
418
+			$ais_data = $AIS->parse_line(trim($line));
419
+			$data = array();
420
+			if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
421
+			if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
422
+			if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
423
+			if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
424
+			if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
425
+			if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
426
+			if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
427
+			if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
428
+			if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
429
+			if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
430
+			if (isset($ais_data['timestamp'])) {
431 431
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
432 432
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
433
-			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
434
-			    $add = true;
433
+				$last_exec[$id]['timestamp'] = $ais_data['timestamp'];
434
+				$add = true;
435 435
 			}
436
-		    } else {
436
+			} else {
437 437
 			$data['datetime'] = date('Y-m-d H:i:s');
438 438
 			$add = true;
439
-		    }
440
-		    $data['format_source'] = 'aisnmeatxt';
441
-    		    $data['id_source'] = $id_source;
442
-		    //print_r($data);
443
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
444
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
445
-		    unset($data);
439
+			}
440
+			$data['format_source'] = 'aisnmeatxt';
441
+				$data['id_source'] = $id_source;
442
+			//print_r($data);
443
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
444
+			if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
445
+			unset($data);
446 446
 		}
447
-    	    }
448
-    	    $last_exec[$id]['last'] = time();
447
+			}
448
+			$last_exec[$id]['last'] = time();
449 449
 	} elseif ($value['format'] == 'aisnmeahttp') {
450
-	    $arr = $httpfeeds;
451
-	    $w = $e = null;
450
+		$arr = $httpfeeds;
451
+		$w = $e = null;
452 452
 	    
453
-	    if (isset($arr[$id])) {
453
+		if (isset($arr[$id])) {
454 454
 		$nn = stream_select($arr,$w,$e,$timeout);
455 455
 		if ($nn > 0) {
456
-		    foreach ($httpfeeds as $feed) {
456
+			foreach ($httpfeeds as $feed) {
457 457
 			$buffer = stream_get_line($feed,2000,"\n");
458 458
 			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
459 459
 			$buffer = explode('\n',$buffer);
460 460
 			foreach ($buffer as $line) {
461
-			    if ($line != '') {
461
+				if ($line != '') {
462 462
 				$ais_data = $AIS->parse_line(trim($line));
463 463
 				$data = array();
464 464
 				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
@@ -476,96 +476,96 @@  discard block
 block discarded – undo
476 476
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
477 477
 				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
478 478
 				if (isset($ais_data['timestamp'])) {
479
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
479
+					$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
480 480
 				} else {
481
-				    $data['datetime'] = date('Y-m-d H:i:s');
481
+					$data['datetime'] = date('Y-m-d H:i:s');
482 482
 				}
483 483
 				$data['format_source'] = 'aisnmeahttp';
484 484
 				$data['id_source'] = $id_source;
485 485
 				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
486 486
 				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
487 487
 				unset($data);
488
-			    }
488
+				}
489
+			}
489 490
 			}
490
-		    }
491 491
 		} else {
492
-		    $format = $value['format'];
493
-		    if (isset($tt[$format])) $tt[$format]++;
494
-		    else $tt[$format] = 0;
495
-		    if ($tt[$format] > 30) {
492
+			$format = $value['format'];
493
+			if (isset($tt[$format])) $tt[$format]++;
494
+			else $tt[$format] = 0;
495
+			if ($tt[$format] > 30) {
496 496
 			if ($globalDebug) echo 'Reconnect...'."\n";
497 497
 			sleep(2);
498 498
 			$sourceeen[] = $value;
499 499
 			connect_all($sourceeen);
500 500
 			$sourceeen = array();
501
-		    }
501
+			}
502
+		}
502 503
 		}
503
-	    }
504 504
 	} elseif ($value['format'] == 'myshiptracking' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
505
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
506
-	    if ($buffer != '') {
505
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
506
+		if ($buffer != '') {
507 507
 		//echo $buffer;
508 508
 		$all_data = json_decode($buffer,true);
509 509
 		//print_r($all_data);
510 510
 		if (isset($all_data[0]['DATA'])) {
511
-		    foreach ($all_data[0]['DATA'] as $line) {
511
+			foreach ($all_data[0]['DATA'] as $line) {
512 512
 			if ($line != '') {
513
-			    $data = array();
514
-			    $data['ident'] = $line['NAME'];
515
-			    $data['mmsi'] = $line['MMSI'];
516
-			    $data['speed'] = $line['SOG'];
517
-			    $data['heading'] = $line['COG'];
518
-			    $data['latitude'] = $line['LAT'];
519
-			    $data['longitude'] = $line['LNG'];
520
-			    //    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
521
-			    $data['imo'] = $line['IMO'];
522
-			    //$data['arrival_code'] = $ais_data['destination'];
523
-			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
524
-			    $data['format_source'] = 'myshiptracking';
525
-			    $data['id_source'] = $id_source;
526
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
527
-			    $MI->add($data);
528
-			    unset($data);
513
+				$data = array();
514
+				$data['ident'] = $line['NAME'];
515
+				$data['mmsi'] = $line['MMSI'];
516
+				$data['speed'] = $line['SOG'];
517
+				$data['heading'] = $line['COG'];
518
+				$data['latitude'] = $line['LAT'];
519
+				$data['longitude'] = $line['LNG'];
520
+				//    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
521
+				$data['imo'] = $line['IMO'];
522
+				//$data['arrival_code'] = $ais_data['destination'];
523
+				$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
524
+				$data['format_source'] = 'myshiptracking';
525
+				$data['id_source'] = $id_source;
526
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
527
+				$MI->add($data);
528
+				unset($data);
529
+			}
529 530
 			}
530
-		    }
531 531
 		}
532
-	    }
533
-	    $last_exec[$id]['last'] = time();
532
+		}
533
+		$last_exec[$id]['last'] = time();
534 534
 	} elseif ($value['format'] == 'boatbeaconapp' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
535
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
536
-	    if ($buffer != '') {
535
+		$buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
536
+		if ($buffer != '') {
537 537
 		$all_data = json_decode($buffer,true);
538 538
 		if (isset($all_data[0]['mmsi'])) {
539
-		    foreach ($all_data as $line) {
539
+			foreach ($all_data as $line) {
540 540
 			if ($line != '') {
541
-			    $data = array();
542
-			    $data['ident'] = $line['shipname'];
543
-			    $data['callsign'] = $line['callsign'];
544
-			    $data['mmsi'] = $line['mmsi'];
545
-			    $data['speed'] = $line['sog'];
546
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
547
-			    $data['latitude'] = $line['latitude'];
548
-			    $data['longitude'] = $line['longitude'];
549
-			    $data['type_id'] = $line['shiptype'];
550
-			    $data['arrival_code'] = $line['destination'];
551
-			    $data['datetime'] = $line['time'];
552
-			    $data['format_source'] = 'boatbeaconapp';
553
-			    $data['id_source'] = $id_source;
554
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
555
-			    $MI->add($data);
556
-			    unset($data);
541
+				$data = array();
542
+				$data['ident'] = $line['shipname'];
543
+				$data['callsign'] = $line['callsign'];
544
+				$data['mmsi'] = $line['mmsi'];
545
+				$data['speed'] = $line['sog'];
546
+				if ($line['heading'] != '511') $data['heading'] = $line['heading'];
547
+				$data['latitude'] = $line['latitude'];
548
+				$data['longitude'] = $line['longitude'];
549
+				$data['type_id'] = $line['shiptype'];
550
+				$data['arrival_code'] = $line['destination'];
551
+				$data['datetime'] = $line['time'];
552
+				$data['format_source'] = 'boatbeaconapp';
553
+				$data['id_source'] = $id_source;
554
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
555
+				$MI->add($data);
556
+				unset($data);
557
+			}
557 558
 			}
558
-		    }
559 559
 		}
560 560
 		
561
-	    }
562
-    	    $last_exec[$id]['last'] = time();
561
+		}
562
+			$last_exec[$id]['last'] = time();
563 563
 	} elseif ($value['format'] == 'boatnerd' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
564
-	    $buffer = $Common->getData($value['host']);
565
-	    if ($buffer != '') {
564
+		$buffer = $Common->getData($value['host']);
565
+		if ($buffer != '') {
566 566
 		$all_data = json_decode($buffer,true);
567 567
 		if (isset($all_data['features'][0]['id'])) {
568
-		    foreach ($all_data['features'] as $line) {
568
+			foreach ($all_data['features'] as $line) {
569 569
 			$data = array();
570 570
 			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
571 571
 			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
@@ -584,59 +584,59 @@  discard block
 block discarded – undo
584 584
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
585 585
 			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
586 586
 			unset($data);
587
-		    }
587
+			}
588 588
 		}
589 589
 		
590
-	    }
591
-    	    $last_exec[$id]['last'] = time();
590
+		}
591
+			$last_exec[$id]['last'] = time();
592 592
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
593
-	    echo 'download...';
594
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
595
-	    echo 'done !'."\n";
596
-	    if ($buffer != '') $reset = 0;
597
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
598
-	    $buffer = explode('\n',$buffer);
599
-	    foreach ($buffer as $line) {
593
+		echo 'download...';
594
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
595
+		echo 'done !'."\n";
596
+		if ($buffer != '') $reset = 0;
597
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
598
+		$buffer = explode('\n',$buffer);
599
+		foreach ($buffer as $line) {
600 600
 		if ($line != '') {
601
-		    $data = array();
602
-		    $data['mmsi'] = (int)substr($line,0,9);
603
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
604
-		    //$data['status'] = substr($line,21,2);
605
-		    //$data['type'] = substr($line,24,3);
606
-		    $data['latitude'] = substr($line,29,9);
607
-		    $data['longitude'] = substr($line,41,9);
608
-		    $data['speed'] = round(substr($line,51,5));
609
-		    //$data['course'] = substr($line,57,5);
610
-		    $data['heading'] = round(substr($line,63,3));
611
-		    //$data['draft'] = substr($line,67,4);
612
-		    //$data['length'] = substr($line,72,3);
613
-		    //$data['beam'] = substr($line,76,2);
614
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
615
-		    //$data['callsign'] = trim(substr($line,100,7);
616
-		    //$data['dest'] = substr($line,108,20);
617
-		    //$data['etaDate'] = substr($line,129,5);
618
-		    //$data['etaTime'] = substr($line,135,5);
619
-		    $data['format_source'] = 'shipplotter';
620
-    		    $data['id_source'] = $id_source;
621
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
622
-		    //print_r($data);
623
-		    echo 'Add...'."\n";
624
-		    $MI->add($data);
625
-		    unset($data);
601
+			$data = array();
602
+			$data['mmsi'] = (int)substr($line,0,9);
603
+			$data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
604
+			//$data['status'] = substr($line,21,2);
605
+			//$data['type'] = substr($line,24,3);
606
+			$data['latitude'] = substr($line,29,9);
607
+			$data['longitude'] = substr($line,41,9);
608
+			$data['speed'] = round(substr($line,51,5));
609
+			//$data['course'] = substr($line,57,5);
610
+			$data['heading'] = round(substr($line,63,3));
611
+			//$data['draft'] = substr($line,67,4);
612
+			//$data['length'] = substr($line,72,3);
613
+			//$data['beam'] = substr($line,76,2);
614
+			$data['ident'] = trim(utf8_encode(substr($line,79,20)));
615
+			//$data['callsign'] = trim(substr($line,100,7);
616
+			//$data['dest'] = substr($line,108,20);
617
+			//$data['etaDate'] = substr($line,129,5);
618
+			//$data['etaTime'] = substr($line,135,5);
619
+			$data['format_source'] = 'shipplotter';
620
+				$data['id_source'] = $id_source;
621
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
622
+			//print_r($data);
623
+			echo 'Add...'."\n";
624
+			$MI->add($data);
625
+			unset($data);
626 626
 		}
627
-    	    }
628
-    	    $last_exec[$id]['last'] = time();
627
+			}
628
+			$last_exec[$id]['last'] = time();
629 629
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
630 630
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
631
-	    //$buffer = $Common->getData($hosts[$id]);
632
-	    $buffer = $Common->getData($value['host']);
633
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
634
-	    $buffer = explode('\n',$buffer);
635
-	    $reset = 0;
636
-	    foreach ($buffer as $line) {
637
-    		if ($line != '') {
638
-    		    $line = explode(':', $line);
639
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
631
+		//$buffer = $Common->getData($hosts[$id]);
632
+		$buffer = $Common->getData($value['host']);
633
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
634
+		$buffer = explode('\n',$buffer);
635
+		$reset = 0;
636
+		foreach ($buffer as $line) {
637
+			if ($line != '') {
638
+				$line = explode(':', $line);
639
+				if (count($line) > 30 && $line[0] != 'callsign') {
640 640
 			$data = array();
641 641
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
642 642
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -649,37 +649,37 @@  discard block
 block discarded – undo
649 649
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
650 650
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
651 651
 			$data['latitude'] = $line[5]; // lat
652
-	        	$data['longitude'] = $line[6]; // long
653
-	        	$data['verticalrate'] = ''; // vertical rate
654
-	        	$data['squawk'] = ''; // squawk
655
-	        	$data['emergency'] = ''; // emergency
656
-	        	$data['waypoints'] = $line[30];
652
+				$data['longitude'] = $line[6]; // long
653
+				$data['verticalrate'] = ''; // vertical rate
654
+				$data['squawk'] = ''; // squawk
655
+				$data['emergency'] = ''; // emergency
656
+				$data['waypoints'] = $line[30];
657 657
 			$data['datetime'] = date('Y-m-d H:i:s');
658 658
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
659 659
 			//if (isset($line[37])) $data['last_update'] = $line[37];
660
-		        $data['departure_airport_icao'] = $line[11];
661
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
662
-		        $data['arrival_airport_icao'] = $line[13];
660
+				$data['departure_airport_icao'] = $line[11];
661
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
662
+				$data['arrival_airport_icao'] = $line[13];
663 663
 			$data['frequency'] = $line[4];
664 664
 			$data['type'] = $line[18];
665 665
 			$data['range'] = $line[19];
666 666
 			if (isset($line[35])) $data['info'] = $line[35];
667
-    			$data['id_source'] = $id_source;
668
-	    		//$data['arrival_airport_time'] = ;
669
-	    		if ($line[9] != '') {
670
-	    		    $aircraft_data = explode('/',$line[9]);
671
-	    		    if (isset($aircraft_data[1])) {
672
-	    			$data['aircraft_icao'] = $aircraft_data[1];
673
-	    		    }
674
-        		}
675
-	    		/*
667
+				$data['id_source'] = $id_source;
668
+				//$data['arrival_airport_time'] = ;
669
+				if ($line[9] != '') {
670
+					$aircraft_data = explode('/',$line[9]);
671
+					if (isset($aircraft_data[1])) {
672
+					$data['aircraft_icao'] = $aircraft_data[1];
673
+					}
674
+				}
675
+				/*
676 676
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
677 677
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
678 678
 	    		*/
679
-	    		$data['format_source'] = $value['format'];
679
+				$data['format_source'] = $value['format'];
680 680
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
681 681
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
682
-    			if ($line[3] == 'PILOT') $SI->add($data);
682
+				if ($line[3] == 'PILOT') $SI->add($data);
683 683
 			elseif ($line[3] == 'ATC') {
684 684
 				//print_r($data);
685 685
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -700,16 +700,16 @@  discard block
 block discarded – undo
700 700
 					else echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
701 701
 				}
702 702
 			}
703
-    			unset($data);
704
-    		    }
705
-    		}
706
-    	    }
707
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
708
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
709
-    	    $last_exec[$id]['last'] = time();
710
-    	} elseif ($value['format'] == 'airwhere' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
711
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
712
-	    if ($buffer != '') {
703
+				unset($data);
704
+				}
705
+			}
706
+			}
707
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
708
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
709
+			$last_exec[$id]['last'] = time();
710
+		} elseif ($value['format'] == 'airwhere' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
711
+		$buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
712
+		if ($buffer != '') {
713 713
 		$all_data = simplexml_load_string($buffer);
714 714
 		foreach($all_data->children() as $childdata) {
715 715
 			$data = array();
@@ -730,10 +730,10 @@  discard block
 block discarded – undo
730 730
 			$SI->add($data);
731 731
 			unset($data);
732 732
 		}
733
-	    }
734
-	    $Source->deleteOldLocationByType('gs');
735
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
736
-	    if ($buffer != '') {
733
+		}
734
+		$Source->deleteOldLocationByType('gs');
735
+		$buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
736
+		if ($buffer != '') {
737 737
 		$all_data = simplexml_load_string($buffer);
738 738
 		foreach($all_data->children() as $childdata) {
739 739
 			$data = array();
@@ -750,249 +750,249 @@  discard block
 block discarded – undo
750 750
 			}
751 751
 			unset($data);
752 752
 		}
753
-	    }
754
-	    $last_exec[$id]['last'] = time();
753
+		}
754
+		$last_exec[$id]['last'] = time();
755 755
 	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
756
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
757
-	    if ($buffer != '') {
758
-	    $all_data = json_decode($buffer,true);
759
-	    if (isset($all_data['acList'])) {
756
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
757
+		if ($buffer != '') {
758
+		$all_data = json_decode($buffer,true);
759
+		if (isset($all_data['acList'])) {
760 760
 		$reset = 0;
761 761
 		foreach ($all_data['acList'] as $line) {
762
-		    $data = array();
763
-		    $data['hex'] = $line['Icao']; // hex
764
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
765
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
766
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
767
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
768
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
769
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
770
-		    //$data['verticalrate'] = $line['']; // verticale rate
771
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
772
-		    $data['emergency'] = ''; // emergency
773
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
762
+			$data = array();
763
+			$data['hex'] = $line['Icao']; // hex
764
+			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
765
+			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
766
+			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
767
+			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
768
+			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
769
+			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
770
+			//$data['verticalrate'] = $line['']; // verticale rate
771
+			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
772
+			$data['emergency'] = ''; // emergency
773
+			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
774 774
 		    
775
-		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
776
-		    else $data['datetime'] = date('Y-m-d H:i:s');
775
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
776
+			else $data['datetime'] = date('Y-m-d H:i:s');
777 777
 		    
778
-		    //$data['datetime'] = date('Y-m-d H:i:s');
779
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
780
-	    	    $data['format_source'] = 'aircraftlistjson';
781
-		    $data['id_source'] = $id_source;
782
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
783
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
784
-		    if (isset($data['latitude'])) $SI->add($data);
785
-		    unset($data);
778
+			//$data['datetime'] = date('Y-m-d H:i:s');
779
+			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
780
+				$data['format_source'] = 'aircraftlistjson';
781
+			$data['id_source'] = $id_source;
782
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
783
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
784
+			if (isset($data['latitude'])) $SI->add($data);
785
+			unset($data);
786 786
 		}
787
-	    } elseif (is_array($all_data)) {
787
+		} elseif (is_array($all_data)) {
788 788
 		$reset = 0;
789 789
 		foreach ($all_data as $line) {
790
-		    $data = array();
791
-		    $data['hex'] = $line['hex']; // hex
792
-		    $data['ident'] = $line['flight']; // ident
793
-		    $data['altitude'] = $line['altitude']; // altitude
794
-		    $data['speed'] = $line['speed']; // speed
795
-		    $data['heading'] = $line['track']; // heading
796
-		    $data['latitude'] = $line['lat']; // lat
797
-		    $data['longitude'] = $line['lon']; // long
798
-		    $data['verticalrate'] = $line['vrt']; // verticale rate
799
-		    $data['squawk'] = $line['squawk']; // squawk
800
-		    $data['emergency'] = ''; // emergency
801
-		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
802
-		    else $data['datetime'] = date('Y-m-d H:i:s');
803
-	    	    $data['format_source'] = 'aircraftlistjson';
804
-    		    $data['id_source'] = $id_source;
805
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
806
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
807
-		    $SI->add($data);
808
-		    unset($data);
790
+			$data = array();
791
+			$data['hex'] = $line['hex']; // hex
792
+			$data['ident'] = $line['flight']; // ident
793
+			$data['altitude'] = $line['altitude']; // altitude
794
+			$data['speed'] = $line['speed']; // speed
795
+			$data['heading'] = $line['track']; // heading
796
+			$data['latitude'] = $line['lat']; // lat
797
+			$data['longitude'] = $line['lon']; // long
798
+			$data['verticalrate'] = $line['vrt']; // verticale rate
799
+			$data['squawk'] = $line['squawk']; // squawk
800
+			$data['emergency'] = ''; // emergency
801
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
802
+			else $data['datetime'] = date('Y-m-d H:i:s');
803
+				$data['format_source'] = 'aircraftlistjson';
804
+				$data['id_source'] = $id_source;
805
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
806
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
807
+			$SI->add($data);
808
+			unset($data);
809
+		}
810
+		}
809 811
 		}
810
-	    }
811
-	    }
812
-    	    //$last_exec['aircraftlistjson'] = time();
813
-    	    $last_exec[$id]['last'] = time();
814
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
815
-    	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
816
-	    $buffer = $Common->getData($value['host']);
817
-	    $all_data = json_decode($buffer,true);
818
-	    if (isset($all_data['planes'])) {
812
+			//$last_exec['aircraftlistjson'] = time();
813
+			$last_exec[$id]['last'] = time();
814
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
815
+		} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
816
+		$buffer = $Common->getData($value['host']);
817
+		$all_data = json_decode($buffer,true);
818
+		if (isset($all_data['planes'])) {
819 819
 		$reset = 0;
820 820
 		foreach ($all_data['planes'] as $key => $line) {
821
-		    $data = array();
822
-		    $data['hex'] = $key; // hex
823
-		    $data['ident'] = $line[3]; // ident
824
-		    $data['altitude'] = $line[6]; // altitude
825
-		    $data['speed'] = $line[8]; // speed
826
-		    $data['heading'] = $line[7]; // heading
827
-		    $data['latitude'] = $line[4]; // lat
828
-		    $data['longitude'] = $line[5]; // long
829
-		    //$data['verticalrate'] = $line[]; // verticale rate
830
-		    $data['squawk'] = $line[10]; // squawk
831
-		    $data['emergency'] = ''; // emergency
832
-		    $data['registration'] = $line[2];
833
-		    $data['aircraft_icao'] = $line[0];
834
-		    $deparr = explode('-',$line[1]);
835
-		    if (count($deparr) == 2) {
821
+			$data = array();
822
+			$data['hex'] = $key; // hex
823
+			$data['ident'] = $line[3]; // ident
824
+			$data['altitude'] = $line[6]; // altitude
825
+			$data['speed'] = $line[8]; // speed
826
+			$data['heading'] = $line[7]; // heading
827
+			$data['latitude'] = $line[4]; // lat
828
+			$data['longitude'] = $line[5]; // long
829
+			//$data['verticalrate'] = $line[]; // verticale rate
830
+			$data['squawk'] = $line[10]; // squawk
831
+			$data['emergency'] = ''; // emergency
832
+			$data['registration'] = $line[2];
833
+			$data['aircraft_icao'] = $line[0];
834
+			$deparr = explode('-',$line[1]);
835
+			if (count($deparr) == 2) {
836 836
 			$data['departure_airport_icao'] = $deparr[0];
837 837
 			$data['arrival_airport_icao'] = $deparr[1];
838
-		    }
839
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
840
-	    	    $data['format_source'] = 'planeupdatefaa';
841
-    		    $data['id_source'] = $id_source;
842
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
843
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
844
-		    $SI->add($data);
845
-		    unset($data);
838
+			}
839
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
840
+				$data['format_source'] = 'planeupdatefaa';
841
+				$data['id_source'] = $id_source;
842
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
843
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
844
+			$SI->add($data);
845
+			unset($data);
846
+		}
846 847
 		}
847
-	    }
848
-    	    //$last_exec['planeupdatefaa'] = time();
849
-    	    $last_exec[$id]['last'] = time();
850
-    	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
851
-	    $buffer = $Common->getData($value['host']);
852
-	    $all_data = json_decode($buffer,true);
853
-	    if (isset($all_data['states'])) {
848
+			//$last_exec['planeupdatefaa'] = time();
849
+			$last_exec[$id]['last'] = time();
850
+		} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
851
+		$buffer = $Common->getData($value['host']);
852
+		$all_data = json_decode($buffer,true);
853
+		if (isset($all_data['states'])) {
854 854
 		$reset = 0;
855 855
 		foreach ($all_data['states'] as $key => $line) {
856
-		    $data = array();
857
-		    $data['hex'] = $line[0]; // hex
858
-		    $data['ident'] = trim($line[1]); // ident
859
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
860
-		    $data['speed'] = round($line[9]*1.94384); // speed
861
-		    $data['heading'] = round($line[10]); // heading
862
-		    $data['latitude'] = $line[6]; // lat
863
-		    $data['longitude'] = $line[5]; // long
864
-		    $data['verticalrate'] = $line[11]; // verticale rate
865
-		    //$data['squawk'] = $line[10]; // squawk
866
-		    //$data['emergency'] = ''; // emergency
867
-		    //$data['registration'] = $line[2];
868
-		    //$data['aircraft_icao'] = $line[0];
869
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
870
-	    	    $data['format_source'] = 'opensky';
871
-    		    $data['id_source'] = $id_source;
872
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
873
-		    $SI->add($data);
874
-		    unset($data);
856
+			$data = array();
857
+			$data['hex'] = $line[0]; // hex
858
+			$data['ident'] = trim($line[1]); // ident
859
+			$data['altitude'] = round($line[7]*3.28084); // altitude
860
+			$data['speed'] = round($line[9]*1.94384); // speed
861
+			$data['heading'] = round($line[10]); // heading
862
+			$data['latitude'] = $line[6]; // lat
863
+			$data['longitude'] = $line[5]; // long
864
+			$data['verticalrate'] = $line[11]; // verticale rate
865
+			//$data['squawk'] = $line[10]; // squawk
866
+			//$data['emergency'] = ''; // emergency
867
+			//$data['registration'] = $line[2];
868
+			//$data['aircraft_icao'] = $line[0];
869
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
870
+				$data['format_source'] = 'opensky';
871
+				$data['id_source'] = $id_source;
872
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
873
+			$SI->add($data);
874
+			unset($data);
875 875
 		}
876
-	    }
877
-    	    //$last_exec['planeupdatefaa'] = time();
878
-    	    $last_exec[$id]['last'] = time();
879
-    	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
880
-    	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
881
-	    //$buffer = $Common->getData($hosts[$id]);
882
-	    $buffer = $Common->getData($value['host']);
883
-	    $all_data = json_decode($buffer,true);
884
-	    if (!empty($all_data)) $reset = 0;
885
-	    foreach ($all_data as $key => $line) {
876
+		}
877
+			//$last_exec['planeupdatefaa'] = time();
878
+			$last_exec[$id]['last'] = time();
879
+		//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
880
+		} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
881
+		//$buffer = $Common->getData($hosts[$id]);
882
+		$buffer = $Common->getData($value['host']);
883
+		$all_data = json_decode($buffer,true);
884
+		if (!empty($all_data)) $reset = 0;
885
+		foreach ($all_data as $key => $line) {
886 886
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
887
-		    $data = array();
888
-		    $data['hex'] = $line[0];
889
-		    $data['ident'] = $line[16]; //$line[13]
890
-	    	    $data['altitude'] = $line[4]; // altitude
891
-	    	    $data['speed'] = $line[5]; // speed
892
-	    	    $data['heading'] = $line[3]; // heading
893
-	    	    $data['latitude'] = $line[1]; // lat
894
-	    	    $data['longitude'] = $line[2]; // long
895
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
896
-	    	    $data['squawk'] = $line[6]; // squawk
897
-	    	    $data['aircraft_icao'] = $line[8];
898
-	    	    $data['registration'] = $line[9];
899
-		    $data['departure_airport_iata'] = $line[11];
900
-		    $data['arrival_airport_iata'] = $line[12];
901
-	    	    $data['emergency'] = ''; // emergency
902
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
903
-	    	    $data['format_source'] = 'fr24json';
904
-    		    $data['id_source'] = $id_source;
905
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
906
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
907
-		    $SI->add($data);
908
-		    unset($data);
887
+			$data = array();
888
+			$data['hex'] = $line[0];
889
+			$data['ident'] = $line[16]; //$line[13]
890
+				$data['altitude'] = $line[4]; // altitude
891
+				$data['speed'] = $line[5]; // speed
892
+				$data['heading'] = $line[3]; // heading
893
+				$data['latitude'] = $line[1]; // lat
894
+				$data['longitude'] = $line[2]; // long
895
+				$data['verticalrate'] = $line[15]; // verticale rate
896
+				$data['squawk'] = $line[6]; // squawk
897
+				$data['aircraft_icao'] = $line[8];
898
+				$data['registration'] = $line[9];
899
+			$data['departure_airport_iata'] = $line[11];
900
+			$data['arrival_airport_iata'] = $line[12];
901
+				$data['emergency'] = ''; // emergency
902
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
903
+				$data['format_source'] = 'fr24json';
904
+				$data['id_source'] = $id_source;
905
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
906
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
907
+			$SI->add($data);
908
+			unset($data);
909
+		}
909 910
 		}
910
-	    }
911
-    	    //$last_exec['fr24json'] = time();
912
-    	    $last_exec[$id]['last'] = time();
913
-    	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
914
-    	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
915
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
916
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
917
-	    //echo $buffer;
918
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
919
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
920
-	    $all_data = json_decode($buffer,true);
921
-	    if (json_last_error() != JSON_ERROR_NONE) {
911
+			//$last_exec['fr24json'] = time();
912
+			$last_exec[$id]['last'] = time();
913
+		//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
914
+		} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
915
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
916
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
917
+		//echo $buffer;
918
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
919
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
920
+		$all_data = json_decode($buffer,true);
921
+		if (json_last_error() != JSON_ERROR_NONE) {
922 922
 		die(json_last_error_msg());
923
-	    }
924
-	    if (isset($all_data['mrkrs'])) {
923
+		}
924
+		if (isset($all_data['mrkrs'])) {
925 925
 		$reset = 0;
926 926
 		foreach ($all_data['mrkrs'] as $key => $line) {
927
-		    if (isset($line['inf'])) {
927
+			if (isset($line['inf'])) {
928 928
 			$data = array();
929 929
 			$data['hex'] = $line['inf']['ia'];
930 930
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
931
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
932
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
933
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
934
-	    		$data['latitude'] = $line['pt'][0]; // lat
935
-	    		$data['longitude'] = $line['pt'][1]; // long
936
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
937
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
938
-	    		//$data['aircraft_icao'] = $line[8];
939
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
931
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
932
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
933
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
934
+				$data['latitude'] = $line['pt'][0]; // lat
935
+				$data['longitude'] = $line['pt'][1]; // long
936
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
937
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
938
+				//$data['aircraft_icao'] = $line[8];
939
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
940 940
 			//$data['departure_airport_iata'] = $line[11];
941 941
 			//$data['arrival_airport_iata'] = $line[12];
942
-	    		//$data['emergency'] = ''; // emergency
942
+				//$data['emergency'] = ''; // emergency
943 943
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
944
-	    		$data['format_source'] = 'radarvirtueljson';
945
-    			$data['id_source'] = $id_source;
944
+				$data['format_source'] = 'radarvirtueljson';
945
+				$data['id_source'] = $id_source;
946 946
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
947 947
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
948 948
 			$SI->add($data);
949 949
 			unset($data);
950
-		    }
950
+			}
951 951
 		}
952
-	    }
953
-    	    //$last_exec['radarvirtueljson'] = time();
954
-    	    $last_exec[$id]['last'] = time();
955
-    	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
956
-    	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
957
-	    //$buffer = $Common->getData($hosts[$id]);
958
-	    $buffer = $Common->getData($value['host'].'?'.time());
959
-	    $all_data = json_decode(utf8_encode($buffer),true);
952
+		}
953
+			//$last_exec['radarvirtueljson'] = time();
954
+			$last_exec[$id]['last'] = time();
955
+		//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
956
+		} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
957
+		//$buffer = $Common->getData($hosts[$id]);
958
+		$buffer = $Common->getData($value['host'].'?'.time());
959
+		$all_data = json_decode(utf8_encode($buffer),true);
960 960
 	    
961
-	    if (isset($all_data['pireps'])) {
961
+		if (isset($all_data['pireps'])) {
962 962
 		$reset = 0;
963
-	        foreach ($all_data['pireps'] as $line) {
964
-		    $data = array();
965
-		    $data['id'] = $line['id'];
966
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
967
-		    $data['ident'] = $line['callsign']; // ident
968
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
969
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
970
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
971
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
972
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
973
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
974
-		    $data['latitude'] = $line['lat']; // lat
975
-		    $data['longitude'] = $line['lon']; // long
976
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
977
-		    //$data['squawk'] = $line['squawk']; // squawk
978
-		    //$data['emergency'] = ''; // emergency
979
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
980
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
981
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
982
-		    //$data['arrival_airport_time'] = $line['arrtime'];
983
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
984
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
985
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
986
-		    else $data['info'] = '';
987
-		    $data['format_source'] = 'pireps';
988
-    		    $data['id_source'] = $id_source;
989
-		    $data['datetime'] = date('Y-m-d H:i:s');
990
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
991
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
992
-		    if ($line['icon'] == 'plane') {
963
+			foreach ($all_data['pireps'] as $line) {
964
+			$data = array();
965
+			$data['id'] = $line['id'];
966
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
967
+			$data['ident'] = $line['callsign']; // ident
968
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
969
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
970
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
971
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
972
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
973
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
974
+			$data['latitude'] = $line['lat']; // lat
975
+			$data['longitude'] = $line['lon']; // long
976
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
977
+			//$data['squawk'] = $line['squawk']; // squawk
978
+			//$data['emergency'] = ''; // emergency
979
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
980
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
981
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
982
+			//$data['arrival_airport_time'] = $line['arrtime'];
983
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
984
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
985
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
986
+			else $data['info'] = '';
987
+			$data['format_source'] = 'pireps';
988
+				$data['id_source'] = $id_source;
989
+			$data['datetime'] = date('Y-m-d H:i:s');
990
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
991
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
992
+			if ($line['icon'] == 'plane') {
993 993
 			$SI->add($data);
994
-		    //    print_r($data);
995
-    		    } elseif ($line['icon'] == 'ct') {
994
+			//    print_r($data);
995
+				} elseif ($line['icon'] == 'ct') {
996 996
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
997 997
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
998 998
 			$typec = substr($data['ident'],-3);
@@ -1007,199 +1007,199 @@  discard block
 block discarded – undo
1007 1007
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
1008 1008
 			else $data['type'] = 'Observer';
1009 1009
 			if (isset($ATC)) echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);
1010
-		    }
1011
-		    unset($data);
1010
+			}
1011
+			unset($data);
1012 1012
 		}
1013
-	    }
1014
-    	    //$last_exec['pirepsjson'] = time();
1015
-    	    $last_exec[$id]['last'] = time();
1016
-    	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
1017
-    	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
1018
-	    //$buffer = $Common->getData($hosts[$id]);
1019
-	    if ($globalDebug) echo 'Get Data...'."\n";
1020
-	    $buffer = $Common->getData($value['host']);
1021
-	    $all_data = json_decode($buffer,true);
1022
-	    if ($buffer != '' && is_array($all_data)) {
1013
+		}
1014
+			//$last_exec['pirepsjson'] = time();
1015
+			$last_exec[$id]['last'] = time();
1016
+		//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
1017
+		} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
1018
+		//$buffer = $Common->getData($hosts[$id]);
1019
+		if ($globalDebug) echo 'Get Data...'."\n";
1020
+		$buffer = $Common->getData($value['host']);
1021
+		$all_data = json_decode($buffer,true);
1022
+		if ($buffer != '' && is_array($all_data)) {
1023 1023
 		$reset = 0;
1024 1024
 		foreach ($all_data as $line) {
1025
-	    	    $data = array();
1026
-	    	    //$data['id'] = $line['id']; // id not usable
1027
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1028
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1029
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1030
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1031
-	    	    $data['ident'] = $line['flightnum']; // ident
1032
-	    	    $data['altitude'] = $line['alt']; // altitude
1033
-	    	    $data['speed'] = $line['gs']; // speed
1034
-	    	    $data['heading'] = $line['heading']; // heading
1035
-	    	    $data['latitude'] = $line['lat']; // lat
1036
-	    	    $data['longitude'] = $line['lng']; // long
1037
-	    	    $data['verticalrate'] = ''; // verticale rate
1038
-	    	    $data['squawk'] = ''; // squawk
1039
-	    	    $data['emergency'] = ''; // emergency
1040
-	    	    //$data['datetime'] = $line['lastupdate'];
1041
-	    	    //$data['last_update'] = $line['lastupdate'];
1042
-		    $data['datetime'] = date('Y-m-d H:i:s');
1043
-	    	    $data['departure_airport_icao'] = $line['depicao'];
1044
-	    	    $data['departure_airport_time'] = $line['deptime'];
1045
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
1046
-    		    $data['arrival_airport_time'] = $line['arrtime'];
1047
-    		    $data['registration'] = $line['aircraft'];
1048
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1049
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1050
-		    if (isset($line['aircraftname'])) {
1025
+				$data = array();
1026
+				//$data['id'] = $line['id']; // id not usable
1027
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1028
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1029
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1030
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1031
+				$data['ident'] = $line['flightnum']; // ident
1032
+				$data['altitude'] = $line['alt']; // altitude
1033
+				$data['speed'] = $line['gs']; // speed
1034
+				$data['heading'] = $line['heading']; // heading
1035
+				$data['latitude'] = $line['lat']; // lat
1036
+				$data['longitude'] = $line['lng']; // long
1037
+				$data['verticalrate'] = ''; // verticale rate
1038
+				$data['squawk'] = ''; // squawk
1039
+				$data['emergency'] = ''; // emergency
1040
+				//$data['datetime'] = $line['lastupdate'];
1041
+				//$data['last_update'] = $line['lastupdate'];
1042
+			$data['datetime'] = date('Y-m-d H:i:s');
1043
+				$data['departure_airport_icao'] = $line['depicao'];
1044
+				$data['departure_airport_time'] = $line['deptime'];
1045
+				$data['arrival_airport_icao'] = $line['arricao'];
1046
+				$data['arrival_airport_time'] = $line['arrtime'];
1047
+				$data['registration'] = $line['aircraft'];
1048
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1049
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1050
+			if (isset($line['aircraftname'])) {
1051 1051
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1052 1052
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1053
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1054
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1055
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1056
-	    		else {
1057
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1058
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1059
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1060
-	    		}
1061
-	    	    }
1062
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1063
-    		    $data['id_source'] = $id_source;
1064
-	    	    $data['format_source'] = 'phpvmacars';
1065
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1066
-		    $SI->add($data);
1067
-		    unset($data);
1053
+				$aircraft_data = explode('-',$line['aircraftname']);
1054
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1055
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1056
+				else {
1057
+					$aircraft_data = explode(' ',$line['aircraftname']);
1058
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1059
+					else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1060
+				}
1061
+				}
1062
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
1063
+				$data['id_source'] = $id_source;
1064
+				$data['format_source'] = 'phpvmacars';
1065
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1066
+			$SI->add($data);
1067
+			unset($data);
1068 1068
 		}
1069 1069
 		if ($globalDebug) echo 'No more data...'."\n";
1070 1070
 		unset($buffer);
1071 1071
 		unset($all_data);
1072
-	    }
1073
-    	    //$last_exec['phpvmacars'] = time();
1074
-    	    $last_exec[$id]['last'] = time();
1075
-    	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
1076
-	    //$buffer = $Common->getData($hosts[$id]);
1077
-	    if ($globalDebug) echo 'Get Data...'."\n";
1078
-	    $buffer = $Common->getData($value['host']);
1079
-	    $all_data = json_decode($buffer,true);
1080
-	    if ($buffer != '' && is_array($all_data)) {
1072
+		}
1073
+			//$last_exec['phpvmacars'] = time();
1074
+			$last_exec[$id]['last'] = time();
1075
+		} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
1076
+		//$buffer = $Common->getData($hosts[$id]);
1077
+		if ($globalDebug) echo 'Get Data...'."\n";
1078
+		$buffer = $Common->getData($value['host']);
1079
+		$all_data = json_decode($buffer,true);
1080
+		if ($buffer != '' && is_array($all_data)) {
1081 1081
 		$reset = 0;
1082 1082
 		foreach ($all_data as $line) {
1083
-	    	    $data = array();
1084
-	    	    //$data['id'] = $line['id']; // id not usable
1085
-	    	    $data['id'] = trim($line['flight_id']);
1086
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1087
-	    	    $data['pilot_name'] = $line['pilot_name'];
1088
-	    	    $data['pilot_id'] = $line['pilot_id'];
1089
-	    	    $data['ident'] = trim($line['callsign']); // ident
1090
-	    	    $data['altitude'] = $line['altitude']; // altitude
1091
-	    	    $data['speed'] = $line['gs']; // speed
1092
-	    	    $data['heading'] = $line['heading']; // heading
1093
-	    	    $data['latitude'] = $line['latitude']; // lat
1094
-	    	    $data['longitude'] = $line['longitude']; // long
1095
-	    	    $data['verticalrate'] = ''; // verticale rate
1096
-	    	    $data['squawk'] = ''; // squawk
1097
-	    	    $data['emergency'] = ''; // emergency
1098
-	    	    //$data['datetime'] = $line['lastupdate'];
1099
-	    	    $data['last_update'] = $line['last_update'];
1100
-		    $data['datetime'] = date('Y-m-d H:i:s');
1101
-	    	    $data['departure_airport_icao'] = $line['departure'];
1102
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
1103
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
1104
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
1105
-    		    //$data['registration'] = $line['aircraft'];
1106
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1107
-	    	    $data['aircraft_icao'] = $line['plane_type'];
1108
-    		    $data['id_source'] = $id_source;
1109
-	    	    $data['format_source'] = 'vam';
1110
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1111
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1112
-		    $SI->add($data);
1113
-		    unset($data);
1083
+				$data = array();
1084
+				//$data['id'] = $line['id']; // id not usable
1085
+				$data['id'] = trim($line['flight_id']);
1086
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1087
+				$data['pilot_name'] = $line['pilot_name'];
1088
+				$data['pilot_id'] = $line['pilot_id'];
1089
+				$data['ident'] = trim($line['callsign']); // ident
1090
+				$data['altitude'] = $line['altitude']; // altitude
1091
+				$data['speed'] = $line['gs']; // speed
1092
+				$data['heading'] = $line['heading']; // heading
1093
+				$data['latitude'] = $line['latitude']; // lat
1094
+				$data['longitude'] = $line['longitude']; // long
1095
+				$data['verticalrate'] = ''; // verticale rate
1096
+				$data['squawk'] = ''; // squawk
1097
+				$data['emergency'] = ''; // emergency
1098
+				//$data['datetime'] = $line['lastupdate'];
1099
+				$data['last_update'] = $line['last_update'];
1100
+			$data['datetime'] = date('Y-m-d H:i:s');
1101
+				$data['departure_airport_icao'] = $line['departure'];
1102
+				//$data['departure_airport_time'] = $line['departure_time'];
1103
+				$data['arrival_airport_icao'] = $line['arrival'];
1104
+				//$data['arrival_airport_time'] = $line['arrival_time'];
1105
+				//$data['registration'] = $line['aircraft'];
1106
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1107
+				$data['aircraft_icao'] = $line['plane_type'];
1108
+				$data['id_source'] = $id_source;
1109
+				$data['format_source'] = 'vam';
1110
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1111
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1112
+			$SI->add($data);
1113
+			unset($data);
1114 1114
 		}
1115 1115
 		if ($globalDebug) echo 'No more data...'."\n";
1116 1116
 		unset($buffer);
1117 1117
 		unset($all_data);
1118
-	    }
1119
-    	    //$last_exec['phpvmacars'] = time();
1120
-    	    $last_exec[$id]['last'] = time();
1118
+		}
1119
+			//$last_exec['phpvmacars'] = time();
1120
+			$last_exec[$id]['last'] = time();
1121 1121
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1122 1122
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'famaprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais' || $value['format'] == 'vrstcp') {
1123
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1124
-    	    //$last_exec[$id]['last'] = time();
1123
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1124
+			//$last_exec[$id]['last'] = time();
1125 1125
 
1126
-	    //$read = array( $sockets[$id] );
1127
-	    $read = $sockets;
1128
-	    $write = NULL;
1129
-	    $e = NULL;
1130
-	    $n = socket_select($read, $write, $e, $timeout);
1131
-	    if ($e != NULL) var_dump($e);
1132
-	    if ($n > 0) {
1126
+		//$read = array( $sockets[$id] );
1127
+		$read = $sockets;
1128
+		$write = NULL;
1129
+		$e = NULL;
1130
+		$n = socket_select($read, $write, $e, $timeout);
1131
+		if ($e != NULL) var_dump($e);
1132
+		if ($n > 0) {
1133 1133
 		$reset = 0;
1134 1134
 		foreach ($read as $nb => $r) {
1135
-		    //$value = $formats[$nb];
1136
-		    $format = $globalSources[$nb]['format'];
1137
-		    if ($format == 'sbs' || $format == 'aprs' || $format == 'famaprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1135
+			//$value = $formats[$nb];
1136
+			$format = $globalSources[$nb]['format'];
1137
+			if ($format == 'sbs' || $format == 'aprs' || $format == 'famaprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1138 1138
 			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1139
-		    } elseif ($format == 'vrstcp') {
1139
+			} elseif ($format == 'vrstcp') {
1140 1140
 			$buffer = @socket_read($r, 6000);
1141
-		    } else {
1141
+			} else {
1142 1142
 			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1143
-		    }
1144
-		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1145
-		    //echo $buffer."\n";
1146
-		    // lets play nice and handle signals such as ctrl-c/kill properly
1147
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1148
-		    $error = false;
1149
-		    //$SI::del();
1150
-		    if ($format == 'vrstcp') {
1143
+			}
1144
+			//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1145
+			//echo $buffer."\n";
1146
+			// lets play nice and handle signals such as ctrl-c/kill properly
1147
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1148
+			$error = false;
1149
+			//$SI::del();
1150
+			if ($format == 'vrstcp') {
1151 1151
 			$buffer = explode('},{',$buffer);
1152
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1153
-		    // SBS format is CSV format
1154
-		    if ($buffer !== FALSE && $buffer != '') {
1152
+			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1153
+			// SBS format is CSV format
1154
+			if ($buffer !== FALSE && $buffer != '') {
1155 1155
 			$tt[$format] = 0;
1156 1156
 			if ($format == 'acarssbs3') {
1157
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1158
-			    $ACARS->add(trim($buffer));
1159
-			    $ACARS->deleteLiveAcarsData();
1157
+				if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1158
+				$ACARS->add(trim($buffer));
1159
+				$ACARS->deleteLiveAcarsData();
1160 1160
 			} elseif ($format == 'raw') {
1161
-			    // AVR format
1162
-			    $data = $SBS->parse($buffer);
1163
-			    if (is_array($data)) {
1161
+				// AVR format
1162
+				$data = $SBS->parse($buffer);
1163
+				if (is_array($data)) {
1164 1164
 				$data['datetime'] = date('Y-m-d H:i:s');
1165 1165
 				$data['format_source'] = 'raw';
1166 1166
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1167 1167
 				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1168 1168
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1169 1169
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1170
-			    }
1170
+				}
1171 1171
 			} elseif ($format == 'ais') {
1172
-			    $ais_data = $AIS->parse_line(trim($buffer));
1173
-			    $data = array();
1174
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1175
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1176
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1177
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1178
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1179
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1180
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1181
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1182
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1183
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1184
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1185
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1186
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1187
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1188
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1189
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1172
+				$ais_data = $AIS->parse_line(trim($buffer));
1173
+				$data = array();
1174
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1175
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1176
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1177
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1178
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1179
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1180
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1181
+				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1182
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1183
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1184
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1185
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1186
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1187
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1188
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1189
+				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1190 1190
 
1191
-			    if (isset($ais_data['timestamp'])) {
1191
+				if (isset($ais_data['timestamp'])) {
1192 1192
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1193
-			    } else {
1193
+				} else {
1194 1194
 				$data['datetime'] = date('Y-m-d H:i:s');
1195
-			    }
1196
-			    $data['format_source'] = 'aisnmea';
1197
-    			    $data['id_source'] = $id_source;
1198
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1199
-			    unset($data);
1200
-                        } elseif ($format == 'flightgearsp') {
1201
-                    	    //echo $buffer."\n";
1202
-                    	    if (strlen($buffer) > 5) {
1195
+				}
1196
+				$data['format_source'] = 'aisnmea';
1197
+					$data['id_source'] = $id_source;
1198
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1199
+				unset($data);
1200
+						} elseif ($format == 'flightgearsp') {
1201
+							//echo $buffer."\n";
1202
+							if (strlen($buffer) > 5) {
1203 1203
 				$line = explode(',',$buffer);
1204 1204
 				$data = array();
1205 1205
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1216,38 +1216,38 @@  discard block
 block discarded – undo
1216 1216
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1217 1217
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1218 1218
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1219
-			    }
1220
-                        } elseif ($format == 'acars') {
1221
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1222
-			    $ACARS->add(trim($buffer));
1223
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1224
-			    $ACARS->deleteLiveAcarsData();
1219
+				}
1220
+						} elseif ($format == 'acars') {
1221
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1222
+				$ACARS->add(trim($buffer));
1223
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1224
+				$ACARS->deleteLiveAcarsData();
1225 1225
 			} elseif ($format == 'flightgearmp') {
1226
-			    if (substr($buffer,0,1) != '#') {
1226
+				if (substr($buffer,0,1) != '#') {
1227 1227
 				$data = array();
1228 1228
 				//echo $buffer."\n";
1229 1229
 				$line = explode(' ',$buffer);
1230 1230
 				if (count($line) == 11) {
1231
-				    $userserver = explode('@',$line[0]);
1232
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1233
-				    $data['ident'] = $userserver[0];
1234
-				    $data['registration'] = $userserver[0];
1235
-				    $data['latitude'] = $line[4];
1236
-				    $data['longitude'] = $line[5];
1237
-				    $data['altitude'] = $line[6];
1238
-				    $data['datetime'] = date('Y-m-d H:i:s');
1239
-				    $aircraft_type = $line[10];
1240
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1241
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1242
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1243
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1231
+					$userserver = explode('@',$line[0]);
1232
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1233
+					$data['ident'] = $userserver[0];
1234
+					$data['registration'] = $userserver[0];
1235
+					$data['latitude'] = $line[4];
1236
+					$data['longitude'] = $line[5];
1237
+					$data['altitude'] = $line[6];
1238
+					$data['datetime'] = date('Y-m-d H:i:s');
1239
+					$aircraft_type = $line[10];
1240
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1241
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1242
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1243
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1244
+				}
1244 1245
 				}
1245
-			    }
1246 1246
 			} elseif ($format == 'beast') {
1247
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1248
-			    die;
1247
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1248
+				die;
1249 1249
 			} elseif ($format == 'vrstcp') {
1250
-			    foreach($buffer as $all_data) {
1250
+				foreach($buffer as $all_data) {
1251 1251
 				$line = json_decode('{'.$all_data.'}',true);
1252 1252
 				$data = array();
1253 1253
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
@@ -1267,114 +1267,114 @@  discard block
 block discarded – undo
1267 1267
 				*/
1268 1268
 				$data['datetime'] = date('Y-m-d H:i:s');
1269 1269
 				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1270
-		    		$data['format_source'] = 'vrstcp';
1270
+					$data['format_source'] = 'vrstcp';
1271 1271
 				$data['id_source'] = $id_source;
1272 1272
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1273 1273
 				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1274 1274
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1275 1275
 				unset($data);
1276
-			    }
1276
+				}
1277 1277
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1278
-			    $line = explode("\t", $buffer);
1279
-			    for($k = 0; $k < count($line); $k=$k+2) {
1278
+				$line = explode("\t", $buffer);
1279
+				for($k = 0; $k < count($line); $k=$k+2) {
1280 1280
 				$key = $line[$k];
1281
-			        $lined[$key] = $line[$k+1];
1282
-			    }
1283
-    			    if (count($lined) > 3) {
1284
-    				$data['hex'] = $lined['hexid'];
1285
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1286
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1287
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1288
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1289
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1290
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1291
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1292
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1293
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1294
-    				$data['id_source'] = $id_source;
1295
-    				$data['format_source'] = 'tsv';
1296
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1297
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1281
+					$lined[$key] = $line[$k+1];
1282
+				}
1283
+					if (count($lined) > 3) {
1284
+					$data['hex'] = $lined['hexid'];
1285
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1286
+					$data['datetime'] = date('Y-m-d H:i:s');;
1287
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1288
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1289
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1290
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1291
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1292
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1293
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1294
+					$data['id_source'] = $id_source;
1295
+					$data['format_source'] = 'tsv';
1296
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1297
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1298 1298
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1299
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1300
-    				unset($lined);
1301
-    				unset($data);
1302
-    			    } else $error = true;
1299
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1300
+					unset($lined);
1301
+					unset($data);
1302
+					} else $error = true;
1303 1303
 			} elseif ($format == 'aprs' && $use_aprs) {
1304
-			    if ($aprs_connect == 0) {
1304
+				if ($aprs_connect == 0) {
1305 1305
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1306 1306
 				$aprs_connect = 1;
1307
-			    }
1307
+				}
1308 1308
 			    
1309
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1309
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1310 1310
 				$aprs_last_tx = time();
1311 1311
 				$data_aprs = "# Keep alive";
1312 1312
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1313
-			    }
1313
+				}
1314 1314
 			    
1315
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1316
-			    //echo 'APRS data : '.$buffer."\n";
1317
-			    $buffer = str_replace('APRS <- ','',$buffer);
1318
-			    $buffer = str_replace('APRS -> ','',$buffer);
1319
-			    //echo $buffer."\n";
1320
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1315
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1316
+				//echo 'APRS data : '.$buffer."\n";
1317
+				$buffer = str_replace('APRS <- ','',$buffer);
1318
+				$buffer = str_replace('APRS -> ','',$buffer);
1319
+				//echo $buffer."\n";
1320
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1321 1321
 				$line = $APRS->parse($buffer);
1322 1322
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1323 1323
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
1324
-				    $aprs_last_tx = time();
1325
-				    $data = array();
1326
-				    //print_r($line);
1327
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1328
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1329
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1330
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1331
-				    if (isset($line['arrival_code'])) $data['arrical_code'] = $line['arrival_code'];
1332
-				    if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1333
-				    if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1334
-				    if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1335
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1336
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1337
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1338
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1339
-				    $data['latitude'] = $line['latitude'];
1340
-				    $data['longitude'] = $line['longitude'];
1341
-				    //$data['verticalrate'] = $line[16];
1342
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1343
-				    //else $data['speed'] = 0;
1344
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1345
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1346
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1347
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1348
-				    //else $data['heading'] = 0;
1349
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1350
-				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1351
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1352
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1353
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1354
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1355
-    				    $data['id_source'] = $id_source;
1356
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1357
-				    else $data['format_source'] = 'aprs';
1358
-				    $data['source_name'] = $line['source'];
1359
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1360
-				    else $data['source_type'] = 'flarm';
1361
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1362
-				    $currentdate = date('Y-m-d H:i:s');
1363
-				    $aprsdate = strtotime($data['datetime']);
1364
-				    // Accept data if time <= system time + 20s
1365
-				    //if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1366
-				    if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1324
+					$aprs_last_tx = time();
1325
+					$data = array();
1326
+					//print_r($line);
1327
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1328
+					if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1329
+					if (isset($line['imo'])) $data['imo'] = $line['imo'];
1330
+					if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1331
+					if (isset($line['arrival_code'])) $data['arrical_code'] = $line['arrival_code'];
1332
+					if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1333
+					if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1334
+					if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1335
+					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1336
+					else $data['datetime'] = date('Y-m-d H:i:s');
1337
+					//$data['datetime'] = date('Y-m-d H:i:s');
1338
+					if (isset($line['ident'])) $data['ident'] = $line['ident'];
1339
+					$data['latitude'] = $line['latitude'];
1340
+					$data['longitude'] = $line['longitude'];
1341
+					//$data['verticalrate'] = $line[16];
1342
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1343
+					//else $data['speed'] = 0;
1344
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1345
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1346
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1347
+					if (isset($line['heading'])) $data['heading'] = $line['heading'];
1348
+					//else $data['heading'] = 0;
1349
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1350
+					//if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1351
+					if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1352
+					elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1353
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1354
+					elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1355
+						$data['id_source'] = $id_source;
1356
+						if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1357
+					else $data['format_source'] = 'aprs';
1358
+					$data['source_name'] = $line['source'];
1359
+					if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1360
+					else $data['source_type'] = 'flarm';
1361
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1362
+					$currentdate = date('Y-m-d H:i:s');
1363
+					$aprsdate = strtotime($data['datetime']);
1364
+					// Accept data if time <= system time + 20s
1365
+					//if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1366
+					if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1367 1367
 					$send = $SI->add($data);
1368
-				    } elseif ($data['source_type'] == 'ais') {
1368
+					} elseif ($data['source_type'] == 'ais') {
1369 1369
 					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
1370
-				    } elseif (isset($line['stealth'])) {
1370
+					} elseif (isset($line['stealth'])) {
1371 1371
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1372 1372
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1373
-				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1374
-				    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1373
+					//} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1374
+					} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1375 1375
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1376 1376
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1377
-				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1377
+					} elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1378 1378
 					if (!isset($data['altitude'])) $data['altitude'] = 0;
1379 1379
 					$Source->deleteOldLocationByType('gs');
1380 1380
 					if (count($Source->getLocationInfoByName($data['ident'])) > 0) {
@@ -1382,11 +1382,11 @@  discard block
 block discarded – undo
1382 1382
 					} else {
1383 1383
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1384 1384
 					}
1385
-				    } else {
1386
-				    	echo '/!\ Not added'."\n";
1387
-				    	print_r($line);
1388
-				    }
1389
-				    unset($data);
1385
+					} else {
1386
+						echo '/!\ Not added'."\n";
1387
+						print_r($line);
1388
+					}
1389
+					unset($data);
1390 1390
 				} 
1391 1391
 				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1392 1392
 					echo '!! Weather Station not yet supported'."\n";
@@ -1402,12 +1402,12 @@  discard block
 block discarded – undo
1402 1402
 				*/
1403 1403
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1404 1404
 				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1405
-			    }
1405
+				}
1406 1406
 			} else {
1407
-			    $line = explode(',', $buffer);
1408
-    			    if (count($line) > 20) {
1409
-    			    	$data['hex'] = $line[4];
1410
-    				/*
1407
+				$line = explode(',', $buffer);
1408
+					if (count($line) > 20) {
1409
+						$data['hex'] = $line[4];
1410
+					/*
1411 1411
     				$data['datetime'] = $line[6].' '.$line[7];
1412 1412
     					date_default_timezone_set($globalTimezone);
1413 1413
     					$datetime = new DateTime($data['datetime']);
@@ -1415,30 +1415,30 @@  discard block
 block discarded – undo
1415 1415
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1416 1416
     					date_default_timezone_set('UTC');
1417 1417
     				*/
1418
-    				// Force datetime to current UTC datetime
1419
-    				date_default_timezone_set('UTC');
1420
-    				$data['datetime'] = date('Y-m-d H:i:s');
1421
-    				$data['ident'] = trim($line[10]);
1422
-    				$data['latitude'] = $line[14];
1423
-    				$data['longitude'] = $line[15];
1424
-    				$data['verticalrate'] = $line[16];
1425
-    				$data['emergency'] = $line[20];
1426
-    				$data['speed'] = $line[12];
1427
-    				$data['squawk'] = $line[17];
1428
-    				$data['altitude'] = $line[11];
1429
-    				$data['heading'] = $line[13];
1430
-    				$data['ground'] = $line[21];
1431
-    				$data['emergency'] = $line[19];
1432
-    				$data['format_source'] = 'sbs';
1418
+					// Force datetime to current UTC datetime
1419
+					date_default_timezone_set('UTC');
1420
+					$data['datetime'] = date('Y-m-d H:i:s');
1421
+					$data['ident'] = trim($line[10]);
1422
+					$data['latitude'] = $line[14];
1423
+					$data['longitude'] = $line[15];
1424
+					$data['verticalrate'] = $line[16];
1425
+					$data['emergency'] = $line[20];
1426
+					$data['speed'] = $line[12];
1427
+					$data['squawk'] = $line[17];
1428
+					$data['altitude'] = $line[11];
1429
+					$data['heading'] = $line[13];
1430
+					$data['ground'] = $line[21];
1431
+					$data['emergency'] = $line[19];
1432
+					$data['format_source'] = 'sbs';
1433 1433
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1434
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1434
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1435 1435
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1436
-    				$data['id_source'] = $id_source;
1437
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1438
-    				else $error = true;
1439
-    				unset($data);
1440
-    			    } else $error = true;
1441
-			    if ($error) {
1436
+					$data['id_source'] = $id_source;
1437
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1438
+					else $error = true;
1439
+					unset($data);
1440
+					} else $error = true;
1441
+				if ($error) {
1442 1442
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1443 1443
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1444 1444
 				} else {
@@ -1454,13 +1454,13 @@  discard block
 block discarded – undo
1454 1454
 					connect_all($sourceer);
1455 1455
 					$sourceer = array();
1456 1456
 				}
1457
-			    }
1457
+				}
1458 1458
 			}
1459 1459
 			// Sleep for xxx microseconds
1460 1460
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1461
-		    } else {
1461
+			} else {
1462 1462
 			if ($format == 'flightgearmp') {
1463
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1463
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1464 1464
 				//@socket_close($r);
1465 1465
 				sleep($globalMinFetch);
1466 1466
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1469,9 +1469,9 @@  discard block
 block discarded – undo
1469 1469
 				break;
1470 1470
 				
1471 1471
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1472
-			    if (isset($tt[$format])) $tt[$format]++;
1473
-			    else $tt[$format] = 0;
1474
-			    if ($tt[$format] > 30) {
1472
+				if (isset($tt[$format])) $tt[$format]++;
1473
+				else $tt[$format] = 0;
1474
+				if ($tt[$format] > 30) {
1475 1475
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1476 1476
 				//@socket_close($r);
1477 1477
 				sleep(2);
@@ -1482,23 +1482,23 @@  discard block
 block discarded – undo
1482 1482
 				//connect_all($globalSources);
1483 1483
 				$tt[$format]=0;
1484 1484
 				break;
1485
-			    }
1485
+				}
1486
+			}
1486 1487
 			}
1487
-		    }
1488 1488
 		}
1489
-	    } else {
1489
+		} else {
1490 1490
 		$error = socket_strerror(socket_last_error());
1491 1491
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1492 1492
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1493 1493
 			if (isset($globalDebug)) echo "Restarting...\n";
1494 1494
 			// Restart the script if possible
1495 1495
 			if (is_array($sockets)) {
1496
-			    if ($globalDebug) echo "Shutdown all sockets...";
1496
+				if ($globalDebug) echo "Shutdown all sockets...";
1497 1497
 			    
1498
-			    foreach ($sockets as $sock) {
1498
+				foreach ($sockets as $sock) {
1499 1499
 				@socket_shutdown($sock,2);
1500 1500
 				@socket_close($sock);
1501
-			    }
1501
+				}
1502 1502
 			    
1503 1503
 			}
1504 1504
 			if ($globalDebug) echo "Waiting...";
@@ -1513,13 +1513,13 @@  discard block
 block discarded – undo
1513 1513
 			if ($globalDebug) echo "Restart all connections...";
1514 1514
 			connect_all($globalSources);
1515 1515
 		}
1516
-	    }
1516
+		}
1517 1517
 	}
1518 1518
 	if ($globalDaemon === false) {
1519
-	    if ($globalDebug) echo 'Check all...'."\n";
1520
-	    $SI->checkAll();
1519
+		if ($globalDebug) echo 'Check all...'."\n";
1520
+		$SI->checkAll();
1521
+	}
1521 1522
 	}
1522
-    }
1523 1523
 }
1524 1524
 
1525 1525
 ?>
Please login to merge, or discard this patch.