Completed
Push — master ( a5e6e0...888a86 )
by Yannick
93:31 queued 61:39
created
require/class.Scheduler.php 3 patches
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -27,16 +27,16 @@  discard block
 block discarded – undo
27 27
 		if ($this->db === null) die('Error: No DB connection.');
28 28
 	}
29 29
 
30
-    /**
31
-     * Add schedule data to database
32
-     * @param String $ident aircraft ident
33
-     * @param String $departure_airport_icao departure airport icao
34
-     * @param String $departure_airport_time departure airport time
35
-     * @param String $arrival_airport_icao arrival airport icao
36
-     * @param String $arrival_airport_time arrival airport time
37
-     * @param String $source source of data
38
-     * @return string
39
-     */
30
+	/**
31
+	 * Add schedule data to database
32
+	 * @param String $ident aircraft ident
33
+	 * @param String $departure_airport_icao departure airport icao
34
+	 * @param String $departure_airport_time departure airport time
35
+	 * @param String $arrival_airport_icao arrival airport icao
36
+	 * @param String $arrival_airport_time arrival airport time
37
+	 * @param String $source source of data
38
+	 * @return string
39
+	 */
40 40
 	public function addSchedule($ident,$departure_airport_icao,$departure_airport_time,$arrival_airport_icao,$arrival_airport_time,$source = 'website') {
41 41
 		date_default_timezone_set('UTC');
42 42
 		$date = date("Y-m-d H:i:s",time());
@@ -52,18 +52,18 @@  discard block
 block discarded – undo
52 52
 		}
53 53
 		if ($sth->fetchColumn() > 0) {
54 54
 			if ($departure_airport_time == '' && $arrival_airport_time == '') {
55
-			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao";
56
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao);
55
+				$query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao";
56
+				$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao);
57 57
 			} elseif ($arrival_airport_time == '') {
58
-			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao";
59
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao);
58
+				$query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao";
59
+				$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao);
60 60
 			} elseif ($departure_airport_time == '') {
61
-			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time";
62
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time);
61
+				$query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time";
62
+				$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time);
63 63
 			} else {
64
-			    //$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident AND departure_airport_icao = :departure_airport_icao AND departure_airport_time = :departure_airport_time AND arrival_airport_icao = :arrival_airport_icao AND arrival_airport_time = :arrival_airport_time";
65
-			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time";
66
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time);
64
+				//$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident AND departure_airport_icao = :departure_airport_icao AND departure_airport_time = :departure_airport_time AND arrival_airport_icao = :arrival_airport_icao AND arrival_airport_time = :arrival_airport_time";
65
+				$query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time";
66
+				$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time);
67 67
 			}
68 68
 			try {
69 69
 				$sth = $this->db->prepare($query);
@@ -151,15 +151,15 @@  discard block
 block discarded – undo
151 151
 	*/
152 152
 	public function checkSchedule($ident) {
153 153
 		global $globalDBdriver;
154
-	        //$query = "SELECT COUNT(*) as nb FROM schedule WHERE ident = :ident AND date_added > DATE_SUB(CURDATE(), INTERVAL 8 DAY) - 8 LIMIT 1";
155
-	        if ($globalDBdriver == 'mysql') {
154
+			//$query = "SELECT COUNT(*) as nb FROM schedule WHERE ident = :ident AND date_added > DATE_SUB(CURDATE(), INTERVAL 8 DAY) - 8 LIMIT 1";
155
+			if ($globalDBdriver == 'mysql') {
156 156
 			$query = "SELECT COUNT(*) as nb FROM routes WHERE FromAirport_ICAO <> '' AND ToAirport_ICAO <> '' AND CallSign = :ident AND ((date_added BETWEEN DATE(DATE_SUB(CURDATE(), INTERVAL 1 MONTH)) AND DATE(NOW()) and date_modified IS NULL) OR (date_modified BETWEEN DATE(DATE_SUB(CURDATE(), INTERVAL 15 DAY)) AND DATE(NOW()))) LIMIT 1";
157 157
 		} else {
158 158
 			$query = "SELECT COUNT(*) as nb FROM routes WHERE FromAirport_ICAO <> '' AND ToAirport_ICAO <> '' AND CallSign = :ident 
159 159
 			AND ((date_added::timestamp BETWEEN CURRENT_TIMESTAMP - INTERVAL '1 MONTH' AND CURRENT_TIMESTAMP) and date_modified::timestamp IS NULL)
160 160
 			     OR (date_modified::timestamp BETWEEN CURRENT_TIMESTAMP - INTERVAL '1 MONTH' AND CURRENT_TIMESTAMP) LIMIT 1";
161 161
 		}
162
-	        $query_values = array(':ident' => $ident);
162
+			$query_values = array(':ident' => $ident);
163 163
 		 try {
164 164
 			$sth = $this->db->prepare($query);
165 165
 			$sth->execute($query_values);
@@ -171,13 +171,13 @@  discard block
 block discarded – undo
171 171
 		return $row['nb'];
172 172
 	}
173 173
 
174
-    /**
175
-     * Get flight info from Air France
176
-     * @param String $callsign The callsign
177
-     * @param String $date date we want flight number info
178
-     * @param String $carrier IATA code
179
-     * @return array departure and arrival airports and time
180
-     */
174
+	/**
175
+	 * Get flight info from Air France
176
+	 * @param String $callsign The callsign
177
+	 * @param String $date date we want flight number info
178
+	 * @param String $carrier IATA code
179
+	 * @return array departure and arrival airports and time
180
+	 */
181 181
 	public function getAirFrance($callsign, $date = 'NOW',$carrier = 'AF') {
182 182
 		$Common = new Common();
183 183
 		$check_date = new Datetime($date);
@@ -212,12 +212,12 @@  discard block
 block discarded – undo
212 212
 		} else return array();
213 213
 	}
214 214
 
215
-    /**
216
-     * Get flight info from EasyJet
217
-     * @param String $callsign The callsign
218
-     * @param String $date date we want flight number info
219
-     * @return array departure and arrival airports and time
220
-     */
215
+	/**
216
+	 * Get flight info from EasyJet
217
+	 * @param String $callsign The callsign
218
+	 * @param String $date date we want flight number info
219
+	 * @return array departure and arrival airports and time
220
+	 */
221 221
 	private function getEasyJet($callsign, $date = 'NOW') {
222 222
 		global $globalTimezone;
223 223
 		$Common = new Common();
@@ -240,11 +240,11 @@  discard block
 block discarded – undo
240 240
 		} else return array();
241 241
 	}
242 242
 
243
-    /**
244
-     * Get flight info from Ryanair
245
-     * @param String $callsign The callsign
246
-     * @return array Flight departure and arrival airports and time
247
-     */
243
+	/**
244
+	 * Get flight info from Ryanair
245
+	 * @param String $callsign The callsign
246
+	 * @return array Flight departure and arrival airports and time
247
+	 */
248 248
 	private function getRyanair($callsign) {
249 249
 		$Common = new Common();
250 250
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
@@ -267,10 +267,10 @@  discard block
 block discarded – undo
267 267
 	}
268 268
 
269 269
 	/**
270
-	* Get flight info from Swiss
271
-	* @param string $callsign The callsign
272
-	* @return array Flight departure and arrival airports and time
273
-	*/
270
+	 * Get flight info from Swiss
271
+	 * @param string $callsign The callsign
272
+	 * @return array Flight departure and arrival airports and time
273
+	 */
274 274
 	private function getSwiss($callsign) {
275 275
 		$Common = new Common();
276 276
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
@@ -299,11 +299,11 @@  discard block
 block discarded – undo
299 299
 	}
300 300
 	
301 301
 	/**
302
-	* Get flight info from British Airways API
303
-	* @param String $callsign The callsign
304
-	* @param String $date date we want flight number info
305
-	* @return array Flight departure and arrival airports and time
306
-	*/
302
+	 * Get flight info from British Airways API
303
+	 * @param String $callsign The callsign
304
+	 * @param String $date date we want flight number info
305
+	 * @return array Flight departure and arrival airports and time
306
+	 */
307 307
 	public function getBritishAirways($callsign, $date = 'NOW') {
308 308
 		global $globalBritishAirwaysKey;
309 309
 		$Common = new Common();
@@ -327,11 +327,11 @@  discard block
 block discarded – undo
327 327
 	}
328 328
 
329 329
 	/**
330
-	* Get flight info from Lutfhansa API
331
-	* @param String $callsign The callsign
332
-	* @param String $date date we want flight number info
333
-	* @return array Flight departure and arrival airports and time
334
-	*/
330
+	 * Get flight info from Lutfhansa API
331
+	 * @param String $callsign The callsign
332
+	 * @param String $date date we want flight number info
333
+	 * @return array Flight departure and arrival airports and time
334
+	 */
335 335
 	public function getLufthansa($callsign, $date = 'NOW') {
336 336
 		global $globalLufthansaKey;
337 337
 		$Common = new Common();
@@ -361,11 +361,11 @@  discard block
 block discarded – undo
361 361
 	}
362 362
 
363 363
 	/**
364
-	* Get flight info from Transavia API
365
-	* @param string $callsign The callsign
366
-	* @param string $date date we want flight number info
367
-	* @return array Flight departure and arrival airports and time
368
-	*/
364
+	 * Get flight info from Transavia API
365
+	 * @param string $callsign The callsign
366
+	 * @param string $date date we want flight number info
367
+	 * @return array Flight departure and arrival airports and time
368
+	 */
369 369
 	public function getTransavia($callsign, $date = 'NOW') {
370 370
 		global $globalTransaviaKey;
371 371
 		$Common = new Common();
@@ -391,10 +391,10 @@  discard block
 block discarded – undo
391 391
 	}
392 392
 
393 393
 	/**
394
-	* Get flight info from Tunisair
395
-	* @param string $callsign The callsign
396
-	* @return array Flight departure and arrival airports and time
397
-	*/
394
+	 * Get flight info from Tunisair
395
+	 * @param string $callsign The callsign
396
+	 * @return array Flight departure and arrival airports and time
397
+	 */
398 398
 	public function getTunisair($callsign) {
399 399
 		$Common = new Common();
400 400
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
@@ -410,12 +410,12 @@  discard block
 block discarded – undo
410 410
 		return array();
411 411
 	}
412 412
 
413
-    /**
414
-     * Get flight info from Vueling
415
-     * @param String $callsign The callsign
416
-     * @param string $date
417
-     * @return array Flight departure and arrival airports and time
418
-     */
413
+	/**
414
+	 * Get flight info from Vueling
415
+	 * @param String $callsign The callsign
416
+	 * @param string $date
417
+	 * @return array Flight departure and arrival airports and time
418
+	 */
419 419
 	public function getVueling($callsign,$date = 'NOW') {
420 420
 		$Common = new Common();
421 421
 		$check_date = new Datetime($date);
@@ -437,11 +437,11 @@  discard block
 block discarded – undo
437 437
 	}
438 438
 
439 439
 	/**
440
-	* Get flight info from Iberia
441
-	* @param String $callsign The callsign
442
-	* @param String $date date we want flight number info
443
-	* @return array Flight departure and arrival airports and time
444
-	*/
440
+	 * Get flight info from Iberia
441
+	 * @param String $callsign The callsign
442
+	 * @param String $date date we want flight number info
443
+	 * @return array Flight departure and arrival airports and time
444
+	 */
445 445
 	public function getIberia($callsign, $date = 'NOW') {
446 446
 		$Common = new Common();
447 447
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
@@ -470,13 +470,13 @@  discard block
 block discarded – undo
470 470
 		return array();
471 471
 	}
472 472
 
473
-    /**
474
-     * Get flight info from Star Alliance
475
-     * @param String $callsign The callsign
476
-     * @param String $date date we want flight number info
477
-     * @param string $carrier
478
-     * @return array Flight departure and arrival airports and time
479
-     */
473
+	/**
474
+	 * Get flight info from Star Alliance
475
+	 * @param String $callsign The callsign
476
+	 * @param String $date date we want flight number info
477
+	 * @param string $carrier
478
+	 * @return array Flight departure and arrival airports and time
479
+	 */
480 480
 
481 481
 	private function getStarAlliance($callsign, $date = 'NOW',$carrier = '') {
482 482
 		$Common = new Common();
@@ -508,11 +508,11 @@  discard block
 block discarded – undo
508 508
 
509 509
 
510 510
 	/**
511
-	* Get flight info from Alitalia
512
-	* @param String $callsign The callsign
513
-	* @param String $date date we want flight number info
514
-	* @return array Flight departure and arrival airports and time
515
-	*/
511
+	 * Get flight info from Alitalia
512
+	 * @param String $callsign The callsign
513
+	 * @param String $date date we want flight number info
514
+	 * @return array Flight departure and arrival airports and time
515
+	 */
516 516
 	private function getAlitalia($callsign, $date = 'NOW') {
517 517
 		$Common = new Common();
518 518
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
@@ -532,11 +532,11 @@  discard block
 block discarded – undo
532 532
 	}
533 533
 
534 534
 	/**
535
-	* Get flight info from Brussels airlines
536
-	* @param String $callsign The callsign
537
-	* @param String $date date we want flight number info
538
-	* @return array Flight departure and arrival airports and time
539
-	*/
535
+	 * Get flight info from Brussels airlines
536
+	 * @param String $callsign The callsign
537
+	 * @param String $date date we want flight number info
538
+	 * @return array Flight departure and arrival airports and time
539
+	 */
540 540
 	private function getBrussels($callsign, $date = 'NOW') {
541 541
 		$Common = new Common();
542 542
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
@@ -546,25 +546,25 @@  discard block
 block discarded – undo
546 546
 		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
547 547
 		$data = $Common->getData($url);
548 548
 		if ($data != '') {
549
-		    //echo $data;
550
-		    $parsed_json = json_decode($data,true);
551
-		    if (isset($parsed_json[0]['FromAirportCode'])) {
549
+			//echo $data;
550
+			$parsed_json = json_decode($data,true);
551
+			if (isset($parsed_json[0]['FromAirportCode'])) {
552 552
 			$DepartureAirportIata = $parsed_json[0]['FromAirportCode'];
553 553
 			$ArrivalAirportIata = $parsed_json[0]['ToAirportCode'];
554 554
 			$departureTime = date('H:i',strtotime($parsed_json[0]['ScheduledDepatureDate']));
555 555
 			$arrivalTime = date('H:i',strtotime($parsed_json[0]['ScheduledArrivalDate']));
556 556
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_brussels');
557
-		    }
557
+			}
558 558
 		}
559 559
 		return array();
560 560
 	}
561 561
 
562 562
 	/**
563
-	* Get flight info from FlightRadar24
564
-	* @param String $callsign The callsign
565
-	* @param String $date date we want flight number info
566
-	* @return array Flight departure and arrival airports and time
567
-	*/
563
+	 * Get flight info from FlightRadar24
564
+	 * @param String $callsign The callsign
565
+	 * @param String $date date we want flight number info
566
+	 * @return array Flight departure and arrival airports and time
567
+	 */
568 568
 /*
569 569
 	public function getFlightRadar24($callsign, $date = 'NOW') {
570 570
 		$Common = new Common();
@@ -593,11 +593,11 @@  discard block
 block discarded – undo
593 593
 	}
594 594
   */
595 595
 	/**
596
-	* Get flight info from Lufthansa
597
-	* @param String $callsign The callsign
598
-	* @param String $date date we want flight number info
599
-	* @return array Flight departure and arrival airports and time
600
-	*/
596
+	 * Get flight info from Lufthansa
597
+	 * @param String $callsign The callsign
598
+	 * @param String $date date we want flight number info
599
+	 * @return array Flight departure and arrival airports and time
600
+	 */
601 601
 
602 602
 /*	private function getLufthansa($callsign, $date = 'NOW') {
603 603
 		$Common = new Common();
@@ -625,10 +625,10 @@  discard block
 block discarded – undo
625 625
 	}
626 626
   */
627 627
 	/**
628
-	* Get flight info from flytap
629
-	* @param String $callsign The callsign
630
-	* @return array Flight departure and arrival airports and time
631
-	*/
628
+	 * Get flight info from flytap
629
+	 * @param String $callsign The callsign
630
+	 * @return array Flight departure and arrival airports and time
631
+	 */
632 632
 	private function getFlyTap($callsign) {
633 633
 		$Common = new Common();
634 634
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
@@ -651,10 +651,10 @@  discard block
 block discarded – undo
651 651
 	}
652 652
 
653 653
 	/**
654
-	* Get flight info from flightmapper
655
-	* @param String $callsign The callsign
656
-	* @return array Flight departure and arrival airports and time
657
-	*/
654
+	 * Get flight info from flightmapper
655
+	 * @param String $callsign The callsign
656
+	 * @return array Flight departure and arrival airports and time
657
+	 */
658 658
 	public function getFlightMapper($callsign) {
659 659
 		$Common = new Common();
660 660
 		$airline_icao = '';
@@ -682,11 +682,11 @@  discard block
 block discarded – undo
682 682
 				$aarr = '';
683 683
 				$n = sscanf($sched,'%*s %5[0-9:] %*[^()] (%3[A-Z]) %5[0-9:] %*[^()] (%3[A-Z])',$dhour,$darr,$ahour,$aarr);
684 684
 				if ($n == 7) {
685
-				    $departureTime = $dhour;
686
-				    $arrivalTime = $ahour;
687
-				    $DepartureAirportIata = str_replace(array('(',')'),'',$darr);
688
-				    $ArrivalAirportIata = str_replace(array('(',')'),'',$aarr);
689
-				    return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightmapper');
685
+					$departureTime = $dhour;
686
+					$arrivalTime = $ahour;
687
+					$DepartureAirportIata = str_replace(array('(',')'),'',$darr);
688
+					$ArrivalAirportIata = str_replace(array('(',')'),'',$aarr);
689
+					return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightmapper');
690 690
 				}
691 691
 			}
692 692
 		}
@@ -694,10 +694,10 @@  discard block
 block discarded – undo
694 694
 	}
695 695
 
696 696
 	/**
697
-	* Get flight info from flightaware
698
-	* @param String $callsign The callsign
699
-	* @return array Flight departure and arrival airports and time
700
-	*/
697
+	 * Get flight info from flightaware
698
+	 * @param String $callsign The callsign
699
+	 * @return array Flight departure and arrival airports and time
700
+	 */
701 701
 	public function getFlightAware($callsign) {
702 702
 		global $globalFlightAwareUsername, $globalFlightAwarePassword;
703 703
 		date_default_timezone_set('UTC');
@@ -722,11 +722,11 @@  discard block
 block discarded – undo
722 722
 				$flight = $result['FlightInfoStatusResult']['flights'][0];
723 723
 				if (isset($flight['origin'])) {
724 724
 					return array(
725
-					    'DepartureAirportIATA' => $flight['origin']['alternate_ident'],
726
-					    'DepartureTime' => $flight['filed_departure_time']['time'],
727
-					    'ArrivalAirportIATA' => $flight['destination']['alternate_ident'],
728
-					    'ArrivalTime' => $flight['filed_arrival_time']['time'],
729
-					    'Source' => 'website_flightaware');
725
+						'DepartureAirportIATA' => $flight['origin']['alternate_ident'],
726
+						'DepartureTime' => $flight['filed_departure_time']['time'],
727
+						'ArrivalAirportIATA' => $flight['destination']['alternate_ident'],
728
+						'ArrivalTime' => $flight['filed_arrival_time']['time'],
729
+						'Source' => 'website_flightaware');
730 730
 				}
731 731
 			}
732 732
 		}
@@ -739,21 +739,21 @@  discard block
 block discarded – undo
739 739
 			$flight = reset($flights['flights']);
740 740
 			if (isset($flight['activityLog']['flights'][0]['origin'])) {
741 741
 				return array(
742
-				    'DepartureAirportIATA' => $flight['activityLog']['flights'][0]['origin']['iata'],
743
-				    'DepartureTime' => date('H:i',$flight['activityLog']['flights'][0]['takeoffTimes']['scheduled']),
744
-				    'ArrivalAirportIATA' => $flight['activityLog']['flights'][0]['destination']['iata'],
745
-				    'ArrivalTime' => date('H:i',$flight['activityLog']['flights'][0]['landingTimes']['scheduled']),
746
-				    'Source' => 'website_flightaware');
742
+					'DepartureAirportIATA' => $flight['activityLog']['flights'][0]['origin']['iata'],
743
+					'DepartureTime' => date('H:i',$flight['activityLog']['flights'][0]['takeoffTimes']['scheduled']),
744
+					'ArrivalAirportIATA' => $flight['activityLog']['flights'][0]['destination']['iata'],
745
+					'ArrivalTime' => date('H:i',$flight['activityLog']['flights'][0]['landingTimes']['scheduled']),
746
+					'Source' => 'website_flightaware');
747 747
 			}
748 748
 		}
749 749
 		return array();
750 750
 	}
751 751
 
752 752
 	/**
753
-	* Get flight info from CostToTravel
754
-	* @param String $callsign The callsign
755
-	* @return array Flight departure and arrival airports and time
756
-	*/
753
+	 * Get flight info from CostToTravel
754
+	 * @param String $callsign The callsign
755
+	 * @return array Flight departure and arrival airports and time
756
+	 */
757 757
 	public function getCostToTravel($callsign) {
758 758
 		$Common = new Common();
759 759
 		$url= "http://www.costtotravel.com/flight-number/".$callsign;
@@ -776,11 +776,11 @@  discard block
 block discarded – undo
776 776
 	}
777 777
 
778 778
 	/**
779
-	* Get flight info from Air Canada
780
-	* @param string $callsign The callsign
781
-	* @param string $date date we want flight number info
782
-	* @return array Flight departure and arrival airports and time
783
-	*/
779
+	 * Get flight info from Air Canada
780
+	 * @param string $callsign The callsign
781
+	 * @param string $date date we want flight number info
782
+	 * @return array Flight departure and arrival airports and time
783
+	 */
784 784
 	private function getAirCanada($callsign,$date = 'NOW') {
785 785
 		$Common = new Common();
786 786
 		if (class_exists("DomDocument") === FALSE) return array();
@@ -805,11 +805,11 @@  discard block
 block discarded – undo
805 805
 	}
806 806
 
807 807
 	/**
808
-	* Get flight info from Vietnam Airlines
809
-	* @param String $callsign The callsign
810
-	* @param String $date date we want flight number info
811
-	* @return array Flight departure and arrival airports and time
812
-	*/
808
+	 * Get flight info from Vietnam Airlines
809
+	 * @param String $callsign The callsign
810
+	 * @param String $date date we want flight number info
811
+	 * @return array Flight departure and arrival airports and time
812
+	 */
813 813
 	private function getVietnamAirlines($callsign, $date = 'NOW') {
814 814
 		$Common = new Common();
815 815
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
@@ -832,12 +832,12 @@  discard block
 block discarded – undo
832 832
 	}
833 833
 
834 834
 	/**
835
-	* Get flight info from Air Berlin
836
-	* @param String $callsign The callsign
837
-	* @param String $date date we want flight number info
838
-	* @param String $carrier airline code
839
-	* @return array Flight departure and arrival airports and time
840
-	*/
835
+	 * Get flight info from Air Berlin
836
+	 * @param String $callsign The callsign
837
+	 * @param String $date date we want flight number info
838
+	 * @param String $carrier airline code
839
+	 * @return array Flight departure and arrival airports and time
840
+	 */
841 841
 	private function getAirBerlin($callsign, $date = 'NOW',$carrier = 'AB') {
842 842
 		$Common = new Common();
843 843
 		date_default_timezone_set('UTC');
@@ -866,11 +866,11 @@  discard block
 block discarded – undo
866 866
 			$table = $Common->table2array($data);
867 867
 			$flight = $table;
868 868
 			if (isset($flight[5][4])) {
869
-			    $arrivalTime = $flight[5][4];
870
-			    $arrivalAirport = $flight[5][3];
869
+				$arrivalTime = $flight[5][4];
870
+				$arrivalAirport = $flight[5][3];
871 871
 			} else {
872
-			    $arrivalTime = '';
873
-			    $arrivalAirport = '';
872
+				$arrivalTime = '';
873
+				$arrivalAirport = '';
874 874
 			}
875 875
 		} else return array();
876 876
 		$url = 'http://www.airberlin.com/en-US/site/json/suggestAirport.php?searchfor=departures&searchflightid=0&departures%5B%5D=&suggestsource%5B0%5D=activeairports&withcountries=0&withoutroutings=0&promotion%5Bid%5D=&promotion%5Btype%5D=&routesource%5B0%5D=airberlin&routesource%5B1%5D=partner';
Please login to merge, or discard this patch.
Spacing   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -37,9 +37,9 @@  discard block
 block discarded – undo
37 37
      * @param String $source source of data
38 38
      * @return string
39 39
      */
40
-	public function addSchedule($ident,$departure_airport_icao,$departure_airport_time,$arrival_airport_icao,$arrival_airport_time,$source = 'website') {
40
+	public function addSchedule($ident, $departure_airport_icao, $departure_airport_time, $arrival_airport_icao, $arrival_airport_time, $source = 'website') {
41 41
 		date_default_timezone_set('UTC');
42
-		$date = date("Y-m-d H:i:s",time());
42
+		$date = date("Y-m-d H:i:s", time());
43 43
 		//if ($departure_airport_time == '' && $arrival_airport_time == '') exit;
44 44
 		//$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident";
45 45
 		$query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident";
@@ -47,69 +47,69 @@  discard block
 block discarded – undo
47 47
 		 try {
48 48
 			$sth = $this->db->prepare($query);
49 49
 			$sth->execute($query_values);
50
-		} catch(PDOException $e) {
50
+		} catch (PDOException $e) {
51 51
 			return "error : ".$e->getMessage();
52 52
 		}
53 53
 		if ($sth->fetchColumn() > 0) {
54 54
 			if ($departure_airport_time == '' && $arrival_airport_time == '') {
55 55
 			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao";
56
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao);
56
+			    $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':arrival_airport_icao' => $arrival_airport_icao);
57 57
 			} elseif ($arrival_airport_time == '') {
58 58
 			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao";
59
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao);
59
+			    $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao);
60 60
 			} elseif ($departure_airport_time == '') {
61 61
 			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time";
62
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time);
62
+			    $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time);
63 63
 			} else {
64 64
 			    //$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident AND departure_airport_icao = :departure_airport_icao AND departure_airport_time = :departure_airport_time AND arrival_airport_icao = :arrival_airport_icao AND arrival_airport_time = :arrival_airport_time";
65 65
 			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time";
66
-			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time);
66
+			    $query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time);
67 67
 			}
68 68
 			try {
69 69
 				$sth = $this->db->prepare($query);
70 70
 				$sth->execute($query_values);
71
-			} catch(PDOException $e) {
71
+			} catch (PDOException $e) {
72 72
 				return "error : ".$e->getMessage();
73 73
 			}
74 74
 			if ($sth->fetchColumn() == 0) {
75 75
 				//$query = 'UPDATE schedule SET departure_airport_icao = :departure_airport_icao, departure_airport_time = :departure_airport_time, arrival_airport_icao = :arrival_airport_icao, arrival_airport_time = :arrival_airport_time, date_modified = :date, source = :source WHERE ident = :ident';
76 76
 				if ($departure_airport_time == '' && $arrival_airport_time == '') {
77 77
 					$query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident';
78
-					$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
78
+					$query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
79 79
 				} elseif ($arrival_airport_time == '') {
80 80
 					$query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident';
81
-					$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
81
+					$query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
82 82
 				} elseif ($departure_airport_time == '') {
83 83
 					$query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident';
84
-					$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
84
+					$query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
85 85
 				} else {
86 86
 					$query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident';
87
-					$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
87
+					$query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
88 88
 				}
89 89
 				try {
90 90
 					$sth = $this->db->prepare($query);
91 91
 					$sth->execute($query_values);
92
-				} catch(PDOException $e) {
92
+				} catch (PDOException $e) {
93 93
 					return "error : ".$e->getMessage();
94 94
 				}
95 95
 			} else {
96 96
 				//$query = 'UPDATE schedule SET date_lastseen = :date WHERE ident = :ident';
97 97
 				$query = 'UPDATE routes SET date_lastseen = :date WHERE CallSign = :ident';
98
-				$query_values = array(':ident' => $ident,':date' => $date);
98
+				$query_values = array(':ident' => $ident, ':date' => $date);
99 99
 				try {
100 100
 					$sth = $this->db->prepare($query);
101 101
 					$sth->execute($query_values);
102
-				} catch(PDOException $e) {
102
+				} catch (PDOException $e) {
103 103
 					return "error : ".$e->getMessage();
104 104
 				}
105 105
 			}
106 106
 		} else {
107 107
 			$query = 'INSERT INTO  routes (CallSign,FromAirport_ICAO, FromAirport_Time, ToAirport_ICAO, ToAirport_Time,date_added,source)  VALUES (:ident,:departure_airport_icao,:departure_airport_time,:arrival_airport_icao,:arrival_airport_time,:date,:source)';
108
-			$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
108
+			$query_values = array(':ident' => $ident, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
109 109
 			 try {
110 110
 				$sth = $this->db->prepare($query);
111 111
 				$sth->execute($query_values);
112
-			} catch(PDOException $e) {
112
+			} catch (PDOException $e) {
113 113
 				return "error : ".$e->getMessage();
114 114
 			}
115 115
 		}
@@ -123,10 +123,10 @@  discard block
 block discarded – undo
123 123
 	*/
124 124
 	public function getSchedule($ident) {
125 125
 		$Translation = new Translation($this->db);
126
-		$operator = $Translation->checkTranslation($ident,false);
126
+		$operator = $Translation->checkTranslation($ident, false);
127 127
 		if ($ident != $operator) {
128 128
 			$query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE FromAirport_ICAO <> '' AND ToAirport_ICAO <> '' AND CallSign = :operator OR CallSign = :ident LIMIT 1";
129
-			$query_values = array(':ident' => $ident,'operator' => $operator);
129
+			$query_values = array(':ident' => $ident, 'operator' => $operator);
130 130
 		} else {
131 131
 			$query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE FromAirport_ICAO <> '' AND ToAirport_ICAO <> '' AND CallSign = :ident LIMIT 1";
132 132
 			$query_values = array(':ident' => $ident);
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 		 try {
135 135
 			$sth = $this->db->prepare($query);
136 136
 			$sth->execute($query_values);
137
-		} catch(PDOException $e) {
137
+		} catch (PDOException $e) {
138 138
 			return "error : ".$e->getMessage();
139 139
 		}
140 140
 		$row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 		 try {
164 164
 			$sth = $this->db->prepare($query);
165 165
 			$sth->execute($query_values);
166
-		} catch(PDOException $e) {
166
+		} catch (PDOException $e) {
167 167
 			return "error : ".$e->getMessage();
168 168
 		}
169 169
 		$row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -178,16 +178,16 @@  discard block
 block discarded – undo
178 178
      * @param String $carrier IATA code
179 179
      * @return array departure and arrival airports and time
180 180
      */
181
-	public function getAirFrance($callsign, $date = 'NOW',$carrier = 'AF') {
181
+	public function getAirFrance($callsign, $date = 'NOW', $carrier = 'AF') {
182 182
 		$Common = new Common();
183 183
 		$check_date = new Datetime($date);
184
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
185
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
184
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
185
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
186 186
 		$url = "http://www.airfrance.fr/cgi-bin/AF/FR/fr/local/resainfovol/infovols/detailsVolJson.do?codeCompagnie[0]=".$carrier."&numeroVol[0]=".$numvol."&dayFlightDate=".$check_date->format('d')."&yearMonthFlightDate=".$check_date->format('Ym');
187 187
 		$json = $Common->getData($url);
188 188
 		var_dump($json);
189 189
 		$parsed_json = json_decode($json);
190
-		if (property_exists($parsed_json,'errors') === false) {
190
+		if (property_exists($parsed_json, 'errors') === false) {
191 191
 			//$originLong = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'originLong'};
192 192
 			$originShort = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'originShort'};
193 193
 			//$departureDateMedium = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'departureDateMedium'};
@@ -197,9 +197,9 @@  discard block
 block discarded – undo
197 197
 			//$arrivalDateMedium = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'arrivalDateMedium'};
198 198
 			$arrivalTime = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'arrivalTime'};
199 199
 
200
-			preg_match('/\((.*?)\)/',$originShort,$originiata);
200
+			preg_match('/\((.*?)\)/', $originShort, $originiata);
201 201
 			$DepartureAirportIata = $originiata[1];
202
-			preg_match('/\((.*?)\)/',$destinationShort,$destinationiata);
202
+			preg_match('/\((.*?)\)/', $destinationShort, $destinationiata);
203 203
 			$ArrivalAirportIata = $destinationiata[1];
204 204
 
205 205
 			/*
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 			$arrivalTime = gmdate('H:i',strtotime($arrivalTime));
209 209
 			*/
210 210
 		
211
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airfrance');
211
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_airfrance');
212 212
 		} else return array();
213 213
 	}
214 214
 
@@ -223,8 +223,8 @@  discard block
 block discarded – undo
223 223
 		$Common = new Common();
224 224
 		date_default_timezone_set($globalTimezone);
225 225
 		$check_date = new Datetime($date);
226
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
227
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
226
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
227
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
228 228
 		$url = "http://www.easyjet.com/ft/api/flights?date=".$check_date->format('Y-m-d')."&fn=".$callsign;
229 229
 		$json = $Common->getData($url);
230 230
 		$parsed_json = json_decode($json);
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
 			$departureTime = $parsed_json->{'flights'}[0]->{'dates'}->{'fstd'};
237 237
 			$arrivalTime = $parsed_json->{'flights'}[0]->{'dates'}->{'fsta'};
238 238
 
239
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_easyjet');
239
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_easyjet');
240 240
 		} else return array();
241 241
 	}
242 242
 
@@ -247,12 +247,12 @@  discard block
 block discarded – undo
247 247
      */
248 248
 	private function getRyanair($callsign) {
249 249
 		$Common = new Common();
250
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
251
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
250
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
251
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
252 252
 		$url = "http://www.ryanair.com/fr/api/2/flight-info/0/50/";
253 253
 		$post = '{"flight":"'.$numvol.'","minDepartureTime":"00:00","maxDepartureTime":"23:59"}';
254
-		$headers = array('Content-Type: application/json','Content-Length: ' . strlen($post));
255
-		$json = $Common->getData($url,'post',$post,$headers);
254
+		$headers = array('Content-Type: application/json', 'Content-Length: '.strlen($post));
255
+		$json = $Common->getData($url, 'post', $post, $headers);
256 256
 		$parsed_json = json_decode($json);
257 257
 		if (isset($parsed_json->{'flightInfo'})) {
258 258
 			$flights = $parsed_json->{'flightInfo'};
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 				$ArrivalAirportIata = $parsed_json->{'flightInfo'}[0]->{'arrivalAirport'}->{'iata'}; //name
262 262
 				$departureTime = $parsed_json->{'flightInfo'}[0]->{'departureTime'};
263 263
 				$arrivalTime = $parsed_json->{'flightInfo'}[0]->{'arrivalTime'};
264
-				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime, 'Source' => 'website_ryanair');
264
+				return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_ryanair');
265 265
 			} else return array();
266 266
 		} else return array();
267 267
 	}
@@ -273,8 +273,8 @@  discard block
 block discarded – undo
273 273
 	*/
274 274
 	private function getSwiss($callsign) {
275 275
 		$Common = new Common();
276
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
277
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
276
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
277
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
278 278
 		$url = "http://www.world-of-swiss.com/fr/routenetwork.json";
279 279
 		$json = $Common->getData($url);
280 280
 		$parsed_json = json_decode($json);
@@ -288,12 +288,12 @@  discard block
 block discarded – undo
288 288
 				if ($flight->{'no'} == "Vol LX ".$numvol) {
289 289
 					$DepartureAirportIata = $flight->{'from'}->{'code'}; //city
290 290
 					$ArrivalAirportIata = $flight->{'to'}->{'code'}; //city
291
-					$departureTime = substr($flight->{'from'}->{'hour'},0,5);
292
-					$arrivalTime = substr($flight->{'to'}->{'hour'},0,5);
291
+					$departureTime = substr($flight->{'from'}->{'hour'},0, 5);
292
+					$arrivalTime = substr($flight->{'to'}->{'hour'},0, 5);
293 293
 				}
294 294
 			}
295 295
 			if (isset($DepartureAirportIata) && isset($ArrivalAirportIata)) {
296
-				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_swiss');
296
+				return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_swiss');
297 297
 			} else return array();
298 298
 		} else return array();
299 299
 	}
@@ -308,21 +308,21 @@  discard block
 block discarded – undo
308 308
 		global $globalBritishAirwaysKey;
309 309
 		$Common = new Common();
310 310
 		$check_date = new Datetime($date);
311
-		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
312
-		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
311
+		$numvol = sprintf('%04d', preg_replace('/^[A-Z]*/', '', $callsign));
312
+		if (!filter_var(preg_replace('/^[A-Z]*/', '', $callsign), FILTER_VALIDATE_INT)) return array();
313 313
 		if ($globalBritishAirwaysKey == '') return array();
314 314
 		$url = "https://api.ba.com/rest-v1/v1/flights;flightNumber=".$numvol.";scheduledDepartureDate=".$check_date->format('Y-m-d').".json";
315 315
 		$headers = array('Client-Key: '.$globalBritishAirwaysKey);
316
-		$json = $Common->getData($url,'get','',$headers);
316
+		$json = $Common->getData($url, 'get', '', $headers);
317 317
 		if ($json == '') return array();
318 318
 		$parsed_json = json_decode($json);
319 319
 		$flights = $parsed_json->{'FlightsResponse'};
320 320
 		if (count($flights) > 0) {
321 321
 			$DepartureAirportIata = $parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'DepartureAirport'};
322 322
 			$ArrivalAirportIata = $parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ArrivalAirport'};
323
-			$departureTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledDepartureDateTime'}));
324
-			$arrivalTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledArrivalDateTime'}));
325
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_britishairways');
323
+			$departureTime = date('H:i', strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledDepartureDateTime'}));
324
+			$arrivalTime = date('H:i', strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledArrivalDateTime'}));
325
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_britishairways');
326 326
 		} else return array();
327 327
 	}
328 328
 
@@ -336,27 +336,27 @@  discard block
 block discarded – undo
336 336
 		global $globalLufthansaKey;
337 337
 		$Common = new Common();
338 338
 		$check_date = new Datetime($date);
339
-		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
340
-		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
339
+		$numvol = sprintf('%04d', preg_replace('/^[A-Z]*/', '', $callsign));
340
+		if (!filter_var(preg_replace('/^[A-Z]*/', '', $callsign), FILTER_VALIDATE_INT)) return array();
341 341
 		if (!isset($globalLufthansaKey) || $globalLufthansaKey == '' || !isset($globalLufthansaKey['key']) || $globalLufthansaKey['key'] == '') return array();
342 342
 		$url = "https://api.lufthansa.com/v1/oauth/token";
343
-		$post = array('client_id' => $globalLufthansaKey['key'],'client_secret' => $globalLufthansaKey['secret'],'grant_type' => 'client_credentials');
344
-		$data = $Common->getData($url,'post',$post);
343
+		$post = array('client_id' => $globalLufthansaKey['key'], 'client_secret' => $globalLufthansaKey['secret'], 'grant_type' => 'client_credentials');
344
+		$data = $Common->getData($url, 'post', $post);
345 345
 		$parsed_data = json_decode($data);
346 346
 		if (!isset($parsed_data->{'access_token'})) return array();
347 347
 		$token = $parsed_data->{'access_token'};
348 348
 		
349 349
 		$url = "https://api.lufthansa.com/v1/operations/flightstatus/LH".$numvol."/".$check_date->format('Y-m-d');
350
-		$headers = array('Authorization: Bearer '.$token,'Accept: application/json');
351
-		$json = $Common->getData($url,'get','',$headers);
350
+		$headers = array('Authorization: Bearer '.$token, 'Accept: application/json');
351
+		$json = $Common->getData($url, 'get', '', $headers);
352 352
 		if ($json == '') return array();
353 353
 		$parsed_json = json_decode($json);
354 354
 		if (isset($parsed_json->{'FlightStatusResource'}) && count($parsed_json->{'FlightStatusResource'}) > 0) {
355 355
 			$DepartureAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'AirportCode'};
356
-			$departureTime = date('H:i',strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'ScheduledTimeLocal'}->{'DateTime'}));
356
+			$departureTime = date('H:i', strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'ScheduledTimeLocal'}->{'DateTime'}));
357 357
 			$ArrivalAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'AirportCode'};
358
-			$arrivalTime = date('H:i',strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'ScheduledTimeLocal'}->{'DateTime'}));
359
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_lufthansa');
358
+			$arrivalTime = date('H:i', strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'ScheduledTimeLocal'}->{'DateTime'}));
359
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_lufthansa');
360 360
 		} else return array();
361 361
 	}
362 362
 
@@ -370,23 +370,23 @@  discard block
 block discarded – undo
370 370
 		global $globalTransaviaKey;
371 371
 		$Common = new Common();
372 372
 		$check_date = new Datetime($date);
373
-		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
374
-		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
373
+		$numvol = sprintf('%04d', preg_replace('/^[A-Z]*/', '', $callsign));
374
+		if (!filter_var(preg_replace('/^[A-Z]*/', '', $callsign), FILTER_VALIDATE_INT)) return array();
375 375
 		if ($globalTransaviaKey == '') return array();
376 376
 		$url = "https://tst.api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol;
377 377
 		//$url = "https://api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol;
378 378
 		$headers = array('apikey: '.$globalTransaviaKey);
379
-		$json = $Common->getData($url,'get','',$headers);
379
+		$json = $Common->getData($url, 'get', '', $headers);
380 380
 		//echo 'result : '.$json;
381 381
 		if ($json == '') return array();
382 382
 		$parsed_json = json_decode($json);
383 383
 		
384 384
 		if (isset($parsed_json->{'data'}[0])) {
385 385
 			$DepartureAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'departureAirport'}->{'locationCode'};
386
-			$departureTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'departureDateTime'}));
386
+			$departureTime = date('H:i', strtotime($parsed_json->{'data'}[0]->{'flight'}->{'departureDateTime'}));
387 387
 			$ArrivalAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'arrivalAirport'}->{'locationCode'};
388
-			$arrivalTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'arrivalDateTime'}));
389
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_transavia');
388
+			$arrivalTime = date('H:i', strtotime($parsed_json->{'data'}[0]->{'flight'}->{'arrivalDateTime'}));
389
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_transavia');
390 390
 		} else return array();
391 391
 	}
392 392
 
@@ -397,14 +397,14 @@  discard block
 block discarded – undo
397 397
 	*/
398 398
 	public function getTunisair($callsign) {
399 399
 		$Common = new Common();
400
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
401
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
400
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
401
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
402 402
 		$url = "http://www.tunisair.com/site/publish/module/Volj/fr/Flight_List.asp";
403 403
 		$data = $Common->getData($url);
404 404
 		$table = $Common->table2array($data);
405 405
 		foreach ($table as $flight) {
406
-			if (isset($flight[1]) && $flight[1] == "TU ".sprintf('%04d',$numvol)) {
407
-				return array('DepartureAirportIATA' => $flight[2],'DepartureTime' => str_replace('.',':',$flight[5]),'ArrivalAirportIATA' => $flight[3],'ArrivalTime' => str_replace('.',':',$flight[6]),'Source' => 'website_tunisair');
406
+			if (isset($flight[1]) && $flight[1] == "TU ".sprintf('%04d', $numvol)) {
407
+				return array('DepartureAirportIATA' => $flight[2], 'DepartureTime' => str_replace('.', ':', $flight[5]), 'ArrivalAirportIATA' => $flight[3], 'ArrivalTime' => str_replace('.', ':', $flight[6]), 'Source' => 'website_tunisair');
408 408
 			}
409 409
 		}
410 410
 		return array();
@@ -416,21 +416,21 @@  discard block
 block discarded – undo
416 416
      * @param string $date
417 417
      * @return array Flight departure and arrival airports and time
418 418
      */
419
-	public function getVueling($callsign,$date = 'NOW') {
419
+	public function getVueling($callsign, $date = 'NOW') {
420 420
 		$Common = new Common();
421 421
 		$check_date = new Datetime($date);
422
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
423
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
424
-		$final_date = str_replace('/','%2F',$check_date->format('d/m/Y'));
422
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
423
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
424
+		$final_date = str_replace('/', '%2F', $check_date->format('d/m/Y'));
425 425
 		$url = "http://www.vueling.com/Base/BaseProxy/RenderMacro/?macroalias=FlightStatusResult&searchBy=bycode&date=".$final_date."&flightNumber=".$numvol."&idioma=en-GB";
426 426
 		$data = $Common->getData($url);
427
-		$data=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$data));
427
+		$data = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $data));
428 428
 		if ($data != '') {
429
-			preg_match('/flightOri=[A-Z]{3}/',$data,$result);
430
-			$DepartureAirportIata = str_replace('flightOri=','',$result[0]);
431
-			preg_match('/flightDest=[A-Z]{3}/',$data,$result);
432
-			$ArrivalAirportIata = str_replace('flightDest=','',$result[0]);
433
-			if ($DepartureAirportIata != '' && $ArrivalAirportIata != '') return array('DepartureAirportIATA' => $DepartureAirportIata,'ArrivalAirportIATA' => $ArrivalAirportIata,'Source' => 'website_vueling');
429
+			preg_match('/flightOri=[A-Z]{3}/', $data, $result);
430
+			$DepartureAirportIata = str_replace('flightOri=', '', $result[0]);
431
+			preg_match('/flightDest=[A-Z]{3}/', $data, $result);
432
+			$ArrivalAirportIata = str_replace('flightDest=', '', $result[0]);
433
+			if ($DepartureAirportIata != '' && $ArrivalAirportIata != '') return array('DepartureAirportIATA' => $DepartureAirportIata, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'Source' => 'website_vueling');
434 434
 			else return array();
435 435
 		}
436 436
 		return array();
@@ -444,27 +444,27 @@  discard block
 block discarded – undo
444 444
 	*/
445 445
 	public function getIberia($callsign, $date = 'NOW') {
446 446
 		$Common = new Common();
447
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
447
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
448 448
 		$check_date = new Datetime($date);
449
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
449
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
450 450
 		$url = "https://www.iberia.com/web/flightDetail.do";
451
-		$post = array('numvuelo' => $numvol,'fecha' => $check_date->format('Ymd'),'airlineID' => 'IB');
452
-		$data = $Common->getData($url,'post',$post);
451
+		$post = array('numvuelo' => $numvol, 'fecha' => $check_date->format('Ymd'), 'airlineID' => 'IB');
452
+		$data = $Common->getData($url, 'post', $post);
453 453
 		if ($data != '') {
454 454
 			$table = $Common->table2array($data);
455 455
 			//print_r($table);
456 456
 			if (count($table) > 0) {
457 457
 				$flight = $table;
458
-				preg_match('/([A-Z]{3})/',$flight[3][0],$DepartureAirportIataMatch);
459
-				preg_match('/([A-Z]{3})/',$flight[5][0],$ArrivalAirportIataMatch);
458
+				preg_match('/([A-Z]{3})/', $flight[3][0], $DepartureAirportIataMatch);
459
+				preg_match('/([A-Z]{3})/', $flight[5][0], $ArrivalAirportIataMatch);
460 460
 				$DepartureAirportIata = $DepartureAirportIataMatch[0];
461 461
 				$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
462
-				$departureTime = substr(trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[3][2]))),0,5);
463
-				$arrivalTime = trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[5][1])));
462
+				$departureTime = substr(trim(str_replace(' lunes', '', str_replace('&nbsp;', '', $flight[3][2]))), 0, 5);
463
+				$arrivalTime = trim(str_replace(' lunes', '', str_replace('&nbsp;', '', $flight[5][1])));
464 464
 				if ($arrivalTime == 'Hora estimada de llegada') {
465
-					$arrivalTime = substr(trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[5][2]))),0,5);
466
-				} else $arrivalTime = substr($arrivalTime,0,5);
467
-				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_iberia');
465
+					$arrivalTime = substr(trim(str_replace(' lunes', '', str_replace('&nbsp;', '', $flight[5][2]))), 0, 5);
466
+				} else $arrivalTime = substr($arrivalTime, 0, 5);
467
+				return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_iberia');
468 468
 			}
469 469
 		}
470 470
 		return array();
@@ -478,11 +478,11 @@  discard block
 block discarded – undo
478 478
      * @return array Flight departure and arrival airports and time
479 479
      */
480 480
 
481
-	private function getStarAlliance($callsign, $date = 'NOW',$carrier = '') {
481
+	private function getStarAlliance($callsign, $date = 'NOW', $carrier = '') {
482 482
 		$Common = new Common();
483
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
483
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
484 484
 		$check_date = new Datetime($date);
485
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
485
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
486 486
 		$url = "http://www.staralliance.com/flifoQueryAction.do?myAirline=&airlineCode=".$carrier."&flightNo=".$numvol."&day=".$check_date->format('d')."&month=".$check_date->format('m')."&year=".$check_date->format('Y')."&departuredate=".$check_date->format('d-M-Y');
487 487
 		$data = $Common->getData($url);
488 488
 		if ($data != '') {
@@ -491,13 +491,13 @@  discard block
 block discarded – undo
491 491
 				$flight = $table;
492 492
 				//print_r($table);
493 493
 				if (isset($flight[25]) && isset($flight[29])) {
494
-					preg_match('/([A-Z]{3})/',$flight[25][1],$DepartureAirportIataMatch);
495
-					preg_match('/([A-Z]{3})/',$flight[25][3],$ArrivalAirportIataMatch);
494
+					preg_match('/([A-Z]{3})/', $flight[25][1], $DepartureAirportIataMatch);
495
+					preg_match('/([A-Z]{3})/', $flight[25][3], $ArrivalAirportIataMatch);
496 496
 					$DepartureAirportIata = $DepartureAirportIataMatch[0];
497 497
 					$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
498
-					$departureTime = substr(trim(str_replace('Scheduled: ','',$flight[29][0])),0,5);
499
-					$arrivalTime = substr(trim(str_replace('Scheduled: ','',$flight[29][1])),0,5);
500
-					return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_staralliance');
498
+					$departureTime = substr(trim(str_replace('Scheduled: ', '', $flight[29][0])), 0, 5);
499
+					$arrivalTime = substr(trim(str_replace('Scheduled: ', '', $flight[29][1])), 0, 5);
500
+					return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_staralliance');
501 501
 				} else return array();
502 502
 			}
503 503
 			
@@ -515,10 +515,10 @@  discard block
 block discarded – undo
515 515
 	*/
516 516
 	private function getAlitalia($callsign, $date = 'NOW') {
517 517
 		$Common = new Common();
518
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
518
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
519 519
 		$check_date = new Datetime($date);
520
-		$url= "http://booking.alitalia.com/FlightStatus/fr_fr/FlightInfo?Brand=az&NumeroVolo=".$numvol."&DataCompleta=".$check_date->format('d/m/Y');
521
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
520
+		$url = "http://booking.alitalia.com/FlightStatus/fr_fr/FlightInfo?Brand=az&NumeroVolo=".$numvol."&DataCompleta=".$check_date->format('d/m/Y');
521
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
522 522
 		$data = $Common->getData($url);
523 523
 		if ($data != '') {
524 524
 			$table = $Common->text2array($data);
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
 			$ArrivalAirportIata = '';
527 527
 			$departureTime = $table[4];
528 528
 			$arrivalTime = $table[5];
529
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_alitalia');
529
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_alitalia');
530 530
 		}
531 531
 		return array();
532 532
 	}
@@ -539,21 +539,21 @@  discard block
 block discarded – undo
539 539
 	*/
540 540
 	private function getBrussels($callsign, $date = 'NOW') {
541 541
 		$Common = new Common();
542
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
542
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
543 543
 		$check_date = new Datetime($date);
544
-		$url= "http://www.brusselsairlines.com/api/flightstatus/getresults?from=NA&to=NA&date=".$check_date->format('d/m/Y')."&hour=NA&lookup=flightnumber&flightnumber=".$numvol."&publicationID=302";
544
+		$url = "http://www.brusselsairlines.com/api/flightstatus/getresults?from=NA&to=NA&date=".$check_date->format('d/m/Y')."&hour=NA&lookup=flightnumber&flightnumber=".$numvol."&publicationID=302";
545 545
 		//http://www.brusselsairlines.com/fr-fr/informations-pratiques/statut-de-votre-vol/resultat.aspx?flightnumber=".$numvol."&date=".$check_date->format('d/m/Y')."&lookup=flightnumber";
546
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
546
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
547 547
 		$data = $Common->getData($url);
548 548
 		if ($data != '') {
549 549
 		    //echo $data;
550
-		    $parsed_json = json_decode($data,true);
550
+		    $parsed_json = json_decode($data, true);
551 551
 		    if (isset($parsed_json[0]['FromAirportCode'])) {
552 552
 			$DepartureAirportIata = $parsed_json[0]['FromAirportCode'];
553 553
 			$ArrivalAirportIata = $parsed_json[0]['ToAirportCode'];
554
-			$departureTime = date('H:i',strtotime($parsed_json[0]['ScheduledDepatureDate']));
555
-			$arrivalTime = date('H:i',strtotime($parsed_json[0]['ScheduledArrivalDate']));
556
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_brussels');
554
+			$departureTime = date('H:i', strtotime($parsed_json[0]['ScheduledDepatureDate']));
555
+			$arrivalTime = date('H:i', strtotime($parsed_json[0]['ScheduledArrivalDate']));
556
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_brussels');
557 557
 		    }
558 558
 		}
559 559
 		return array();
@@ -631,21 +631,21 @@  discard block
 block discarded – undo
631 631
 	*/
632 632
 	private function getFlyTap($callsign) {
633 633
 		$Common = new Common();
634
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
635
-		$url= "http://www.flytap.com/France/fr/PlanifierEtReserver/Outils/DepartsEtArrivees";
634
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
635
+		$url = "http://www.flytap.com/France/fr/PlanifierEtReserver/Outils/DepartsEtArrivees";
636 636
 		//$check_date = new Datetime($date);
637
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
638
-		$post = array('arrivalsdepartures_content' => 'number','arrivalsdepartures_tp' => $numvol,'arrivalsdepartures_trk' => 'ARR','arrivalsdepartures_date_trk' => '1','aptCode' => '','arrivalsdepartures' => 'DEP','arrivalsdepartures_date' => '1','aptCodeFrom' => '','aptCodeTo' => '','arrivalsdepartures2' => 'DEP','arrivalsdepartures_date2' => '1');
639
-		$data = $Common->getData($url,'post',$post);
637
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
638
+		$post = array('arrivalsdepartures_content' => 'number', 'arrivalsdepartures_tp' => $numvol, 'arrivalsdepartures_trk' => 'ARR', 'arrivalsdepartures_date_trk' => '1', 'aptCode' => '', 'arrivalsdepartures' => 'DEP', 'arrivalsdepartures_date' => '1', 'aptCodeFrom' => '', 'aptCodeTo' => '', 'arrivalsdepartures2' => 'DEP', 'arrivalsdepartures_date2' => '1');
639
+		$data = $Common->getData($url, 'post', $post);
640 640
 		if ($data != '') {
641 641
 			$table = $Common->table2array($data);
642
-			$departureTime = trim(substr($table[15][0],0,5));
643
-			$arrivalTime = trim(substr($table[35][0],0,5));
644
-			preg_match('/([A-Z]{3})/',$table[11][0],$DepartureAirportIataMatch);
645
-			preg_match('/([A-Z]{3})/',$table[31][0],$ArrivalAirportIataMatch);
642
+			$departureTime = trim(substr($table[15][0], 0, 5));
643
+			$arrivalTime = trim(substr($table[35][0], 0, 5));
644
+			preg_match('/([A-Z]{3})/', $table[11][0], $DepartureAirportIataMatch);
645
+			preg_match('/([A-Z]{3})/', $table[31][0], $ArrivalAirportIataMatch);
646 646
 			$DepartureAirportIata = $DepartureAirportIataMatch[0];
647 647
 			$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
648
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flytap');
648
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_flytap');
649 649
 		}
650 650
 		return array();
651 651
 	}
@@ -667,10 +667,10 @@  discard block
 block discarded – undo
667 667
 			} 
668 668
 		}
669 669
 		if ($airline_icao == '') return array();
670
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
671
-		$url= "http://info.flightmapper.net/flight/".$airline_icao.'_'.$numvol;
670
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
671
+		$url = "http://info.flightmapper.net/flight/".$airline_icao.'_'.$numvol;
672 672
 		//$check_date = new Datetime($date);
673
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
673
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
674 674
 		$data = $Common->getData($url);
675 675
 		if ($data != '') {
676 676
 			$table = $Common->table2array($data);
@@ -680,13 +680,13 @@  discard block
 block discarded – undo
680 680
 				$darr = '';
681 681
 				$ahour = '';
682 682
 				$aarr = '';
683
-				$n = sscanf($sched,'%*s %5[0-9:] %*[^()] (%3[A-Z]) %5[0-9:] %*[^()] (%3[A-Z])',$dhour,$darr,$ahour,$aarr);
683
+				$n = sscanf($sched, '%*s %5[0-9:] %*[^()] (%3[A-Z]) %5[0-9:] %*[^()] (%3[A-Z])', $dhour, $darr, $ahour, $aarr);
684 684
 				if ($n == 7) {
685 685
 				    $departureTime = $dhour;
686 686
 				    $arrivalTime = $ahour;
687
-				    $DepartureAirportIata = str_replace(array('(',')'),'',$darr);
688
-				    $ArrivalAirportIata = str_replace(array('(',')'),'',$aarr);
689
-				    return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightmapper');
687
+				    $DepartureAirportIata = str_replace(array('(', ')'), '', $darr);
688
+				    $ArrivalAirportIata = str_replace(array('(', ')'), '', $aarr);
689
+				    return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_flightmapper');
690 690
 				}
691 691
 			}
692 692
 		}
@@ -718,7 +718,7 @@  discard block
 block discarded – undo
718 718
 			$url = 'http://'.$globalFlightAwareUsername.':'.$globalFlightAwarePassword.'@flightxml.flightaware.com/json/FlightXML3/FlightInfoStatus?ident='.$callsign;
719 719
 			$data = $Common->getData($url);
720 720
 			if ($data != '') {
721
-				$result = json_decode($data,true);
721
+				$result = json_decode($data, true);
722 722
 				$flight = $result['FlightInfoStatusResult']['flights'][0];
723 723
 				if (isset($flight['origin'])) {
724 724
 					return array(
@@ -731,18 +731,18 @@  discard block
 block discarded – undo
731 731
 			}
732 732
 		}
733 733
 		
734
-		$url= "http://flightaware.com/live/flight/".$callsign;
734
+		$url = "http://flightaware.com/live/flight/".$callsign;
735 735
 		$data = $Common->getData($url);
736 736
 		if ($data != '') {
737
-			preg_match(':<script>var trackpollBootstrap = (.*?);</script>:',$data,$result);
738
-			$flights = json_decode($result[1],true);
737
+			preg_match(':<script>var trackpollBootstrap = (.*?);</script>:', $data, $result);
738
+			$flights = json_decode($result[1], true);
739 739
 			$flight = reset($flights['flights']);
740 740
 			if (isset($flight['activityLog']['flights'][0]['origin'])) {
741 741
 				return array(
742 742
 				    'DepartureAirportIATA' => $flight['activityLog']['flights'][0]['origin']['iata'],
743
-				    'DepartureTime' => date('H:i',$flight['activityLog']['flights'][0]['takeoffTimes']['scheduled']),
743
+				    'DepartureTime' => date('H:i', $flight['activityLog']['flights'][0]['takeoffTimes']['scheduled']),
744 744
 				    'ArrivalAirportIATA' => $flight['activityLog']['flights'][0]['destination']['iata'],
745
-				    'ArrivalTime' => date('H:i',$flight['activityLog']['flights'][0]['landingTimes']['scheduled']),
745
+				    'ArrivalTime' => date('H:i', $flight['activityLog']['flights'][0]['landingTimes']['scheduled']),
746 746
 				    'Source' => 'website_flightaware');
747 747
 			}
748 748
 		}
@@ -756,20 +756,20 @@  discard block
 block discarded – undo
756 756
 	*/
757 757
 	public function getCostToTravel($callsign) {
758 758
 		$Common = new Common();
759
-		$url= "http://www.costtotravel.com/flight-number/".$callsign;
759
+		$url = "http://www.costtotravel.com/flight-number/".$callsign;
760 760
 		//$check_date = new Datetime($date);
761 761
 		//if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
762 762
 		$data = $Common->getData($url);
763 763
 		if ($data != '') {
764 764
 			$table = $Common->table2array($data);
765 765
 			if (isset($table[11][1])) {
766
-				if (is_numeric(substr($table[11][1],0,1))) $departureTime = substr($table[11][1],0,5);
766
+				if (is_numeric(substr($table[11][1], 0, 1))) $departureTime = substr($table[11][1], 0, 5);
767 767
 				else $departureTime = '';
768
-				if (is_numeric(substr($table[17][1],0,1))) $arrivalTime = substr($table[17][1],0,5);
768
+				if (is_numeric(substr($table[17][1], 0, 1))) $arrivalTime = substr($table[17][1], 0, 5);
769 769
 				else $arrivalTime = '';
770
-				$DepartureAirportIata = substr($table[13][1],0,3);
771
-				$ArrivalAirportIata = substr($table[15][1],0,3);
772
-				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_costtotravel');
770
+				$DepartureAirportIata = substr($table[13][1], 0, 3);
771
+				$ArrivalAirportIata = substr($table[15][1], 0, 3);
772
+				return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_costtotravel');
773 773
 			}
774 774
 		}
775 775
 		return array();
@@ -781,14 +781,14 @@  discard block
 block discarded – undo
781 781
 	* @param string $date date we want flight number info
782 782
 	* @return array Flight departure and arrival airports and time
783 783
 	*/
784
-	private function getAirCanada($callsign,$date = 'NOW') {
784
+	private function getAirCanada($callsign, $date = 'NOW') {
785 785
 		$Common = new Common();
786 786
 		if (class_exists("DomDocument") === FALSE) return array();
787 787
 		date_default_timezone_set('UTC');
788 788
 		$check_date = new Datetime($date);
789
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
790
-		$url= "http://services.aircanada.com/portal/rest/getFlightsByFlightNumber?forceTimetable=true&flightNumber=".$numvol."&carrierCode=AC&date=".$check_date->format('m-d-Y')."&app_key=AE919FDCC80311DF9BABC975DFD72085&cache=74249";
791
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
789
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
790
+		$url = "http://services.aircanada.com/portal/rest/getFlightsByFlightNumber?forceTimetable=true&flightNumber=".$numvol."&carrierCode=AC&date=".$check_date->format('m-d-Y')."&app_key=AE919FDCC80311DF9BABC975DFD72085&cache=74249";
791
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
792 792
 		$data = $Common->getData($url);
793 793
 		$dom = new DomDocument();
794 794
 		$dom->loadXML($data);
@@ -796,11 +796,11 @@  discard block
 block discarded – undo
796 796
 		$departure = $dom->getElementsByTagName('DepartureStationInfo')->item(0);
797 797
 		if (isset($departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue)) {
798 798
 			$DepartureAirportIata = $departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue;
799
-			$departureTime = date('H:i',strtotime($departure->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
799
+			$departureTime = date('H:i', strtotime($departure->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
800 800
 			$arrival = $dom->getElementsByTagName('ArrivalStationInfo')->item(0);
801 801
 			$ArrivalAirportIata = $arrival->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue;
802
-			$arrivalTime = date('H:i',strtotime($arrival->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
803
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_aircanada');
802
+			$arrivalTime = date('H:i', strtotime($arrival->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
803
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_aircanada');
804 804
 		} else return array();
805 805
 	}
806 806
 
@@ -812,21 +812,21 @@  discard block
 block discarded – undo
812 812
 	*/
813 813
 	private function getVietnamAirlines($callsign, $date = 'NOW') {
814 814
 		$Common = new Common();
815
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
815
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
816 816
 		$check_date = new Datetime($date);
817
-		$url= "https://cat.sabresonicweb.com/SSWVN/meridia?posid=VNVN&page=flifoFlightInfoDetailsMessage_learn&action=flightInfoDetails&airline=VN&language=fr&depDay=".$check_date->format('j')."&depMonth=".strtoupper($check_date->format('M'))."&=&flight=".$numvol."&";
818
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
817
+		$url = "https://cat.sabresonicweb.com/SSWVN/meridia?posid=VNVN&page=flifoFlightInfoDetailsMessage_learn&action=flightInfoDetails&airline=VN&language=fr&depDay=".$check_date->format('j')."&depMonth=".strtoupper($check_date->format('M'))."&=&flight=".$numvol."&";
818
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
819 819
 		$data = $Common->getData($url);
820 820
 		if ($data != '') {
821 821
 			$table = $Common->table2array($data);
822 822
 			$flight = $table;
823
-			preg_match('/([A-Z]{3})/',$flight[3][0],$DepartureAirportIataMatch);
824
-			preg_match('/([A-Z]{3})/',$flight[21][0],$ArrivalAirportIataMatch);
823
+			preg_match('/([A-Z]{3})/', $flight[3][0], $DepartureAirportIataMatch);
824
+			preg_match('/([A-Z]{3})/', $flight[21][0], $ArrivalAirportIataMatch);
825 825
 			$DepartureAirportIata = $DepartureAirportIataMatch[0];
826 826
 			$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
827 827
 			$departureTime = $flight[5][1];
828 828
 			$arrivalTime = $flight[23][1];
829
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_vietnamairlines');
829
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_vietnamairlines');
830 830
 		}
831 831
 		return array();
832 832
 	}
@@ -838,16 +838,16 @@  discard block
 block discarded – undo
838 838
 	* @param String $carrier airline code
839 839
 	* @return array Flight departure and arrival airports and time
840 840
 	*/
841
-	private function getAirBerlin($callsign, $date = 'NOW',$carrier = 'AB') {
841
+	private function getAirBerlin($callsign, $date = 'NOW', $carrier = 'AB') {
842 842
 		$Common = new Common();
843 843
 		date_default_timezone_set('UTC');
844 844
 		//AB = airberlin, HG/NLY = NIKI, 4T/BHP = Belair 
845
-		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
845
+		$numvol = preg_replace('/^[A-Z]*/', '', $callsign);
846 846
 		$check_date = new Datetime($date);
847
-		$url= "http://www.airberlin.com/en-US/site/aims.php";
848
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
849
-		$post = array('type' => 'departure','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => $carrier);
850
-		$data = $Common->getData($url,'post',$post);
847
+		$url = "http://www.airberlin.com/en-US/site/aims.php";
848
+		if (!filter_var($numvol, FILTER_VALIDATE_INT)) return array();
849
+		$post = array('type' => 'departure', 'searchFlightNo' => '1', 'requestsent' => 'true', 'flightno' => $numvol, 'date' => $check_date->format('Y-m-d'), 'carrier' => $carrier);
850
+		$data = $Common->getData($url, 'post', $post);
851 851
 		//echo $data;
852 852
 		$DepartureAirportIata = '';
853 853
 		$ArrivalAirportIata = '';
@@ -860,8 +860,8 @@  discard block
 block discarded – undo
860 860
 			if (isset($flight[5][2])) $departureAirport = $flight[5][2];
861 861
 			else $departureAirport = '';
862 862
 		} else return array();
863
-		$post = array('type' => 'arrival','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => 'AB');
864
-		$data = $Common->getData($url,'post',$post);
863
+		$post = array('type' => 'arrival', 'searchFlightNo' => '1', 'requestsent' => 'true', 'flightno' => $numvol, 'date' => $check_date->format('Y-m-d'), 'carrier' => 'AB');
864
+		$data = $Common->getData($url, 'post', $post);
865 865
 		if ($data != '') {
866 866
 			$table = $Common->table2array($data);
867 867
 			$flight = $table;
@@ -889,7 +889,7 @@  discard block
 block discarded – undo
889 889
 			}
890 890
 		}
891 891
 		if (isset($DepartureAirportIata)) {
892
-			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airberlin');
892
+			return array('DepartureAirportIATA' => $DepartureAirportIata, 'DepartureTime' => $departureTime, 'ArrivalAirportIATA' => $ArrivalAirportIata, 'ArrivalTime' => $arrivalTime, 'Source' => 'website_airberlin');
893 893
 		} else return array();
894 894
 	}
895 895
 
@@ -899,7 +899,7 @@  discard block
 block discarded – undo
899 899
 	 * @param String $date Date
900 900
 	 * @return array Schedules info
901 901
 	*/
902
-	public function fetchSchedule($ident,$date = 'NOW') {
902
+	public function fetchSchedule($ident, $date = 'NOW') {
903 903
 		global $globalSchedulesSources, $globalSchedulesFetch, $globalOffline, $globalFlightAwareUsername;
904 904
 		//$Common = new Common();
905 905
 		if ($globalSchedulesFetch === FALSE || (isset($globalOffline) && $globalOffline === TRUE)) return array();
@@ -969,7 +969,7 @@  discard block
 block discarded – undo
969 969
 				// Brussels Airlines
970 970
 				case "BEL":
971 971
 				case "SN":
972
-					return $this->getBrussels($ident,$date);
972
+					return $this->getBrussels($ident, $date);
973 973
 /*
974 974
 				// Copa Airlines
975 975
 				case "CMP":
@@ -1068,7 +1068,7 @@  discard block
 block discarded – undo
1068 1068
 				case "DS":
1069 1069
 				case "EZY":
1070 1070
 				case "EZS":
1071
-					return $this->getEasyJet($ident,$date);
1071
+					return $this->getEasyJet($ident, $date);
1072 1072
 				// Ryanair
1073 1073
 				case "FR":
1074 1074
 				case "RYR":
@@ -1120,19 +1120,19 @@  discard block
 block discarded – undo
1120 1120
 					return $this->getIberia($ident);
1121 1121
 				// Vietnam Airlines
1122 1122
 				case "HVN":
1123
-					return $this->getVietnamAirlines($ident,$date);
1123
+					return $this->getVietnamAirlines($ident, $date);
1124 1124
 				// Air Berlin
1125 1125
 				case "AB":
1126 1126
 				case "BER":
1127
-					return $this->getAirBerlin($ident,$date,'AB');
1127
+					return $this->getAirBerlin($ident, $date, 'AB');
1128 1128
 				// NIKI
1129 1129
 				case "HG":
1130 1130
 				case "NLY":
1131
-					return $this->getAirBerlin($ident,$date,'HG');
1131
+					return $this->getAirBerlin($ident, $date, 'HG');
1132 1132
 				// BelAir
1133 1133
 				case "4T":
1134 1134
 				case "BHP":
1135
-					return $this->getAirBerlin($ident,$date,'4T');
1135
+					return $this->getAirBerlin($ident, $date, '4T');
1136 1136
 				default:
1137 1137
 					if (strlen($airline_icao) == 3) {
1138 1138
 						$Spotter = new Spotter($this->db);
@@ -1141,9 +1141,9 @@  discard block
 block discarded – undo
1141 1141
 					}
1142 1142
 					// Randomly use a generic function to get hours
1143 1143
 					if (strlen($airline_icao) == 2) {
1144
-						if (!isset($globalSchedulesSources)) $globalSchedulesSources = array('flightmapper','costtotravel','flightaware');
1144
+						if (!isset($globalSchedulesSources)) $globalSchedulesSources = array('flightmapper', 'costtotravel', 'flightaware');
1145 1145
 						if (count($globalSchedulesSources) > 0) {
1146
-							$rand = mt_rand(0,count($globalSchedulesSources)-1);
1146
+							$rand = mt_rand(0, count($globalSchedulesSources) - 1);
1147 1147
 							$source = $globalSchedulesSources[$rand];
1148 1148
 							if ($source == 'flightmapper') return $this->getFlightMapper($ident);
1149 1149
 							elseif ($source == 'costtotravel') return $this->getCostToTravel($ident);
Please login to merge, or discard this patch.
Braces   +180 added lines, -62 removed lines patch added patch discarded remove patch
@@ -24,7 +24,9 @@  discard block
 block discarded – undo
24 24
 	public function __construct($dbc = null) {
25 25
 		$Connection = new Connection($dbc);
26 26
 		$this->db = $Connection->db();
27
-		if ($this->db === null) die('Error: No DB connection.');
27
+		if ($this->db === null) {
28
+			die('Error: No DB connection.');
29
+		}
28 30
 	}
29 31
 
30 32
     /**
@@ -141,7 +143,9 @@  discard block
 block discarded – undo
141 143
 		$sth->closeCursor();
142 144
 		if (is_array($row) && count($row) > 0) {
143 145
 			return $row;
144
-		} else return array();
146
+		} else {
147
+			return array();
148
+		}
145 149
 	}
146 150
 
147 151
 	/*
@@ -182,7 +186,9 @@  discard block
 block discarded – undo
182 186
 		$Common = new Common();
183 187
 		$check_date = new Datetime($date);
184 188
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
185
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
189
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
190
+			return array();
191
+		}
186 192
 		$url = "http://www.airfrance.fr/cgi-bin/AF/FR/fr/local/resainfovol/infovols/detailsVolJson.do?codeCompagnie[0]=".$carrier."&numeroVol[0]=".$numvol."&dayFlightDate=".$check_date->format('d')."&yearMonthFlightDate=".$check_date->format('Ym');
187 193
 		$json = $Common->getData($url);
188 194
 		var_dump($json);
@@ -209,7 +215,9 @@  discard block
 block discarded – undo
209 215
 			*/
210 216
 		
211 217
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airfrance');
212
-		} else return array();
218
+		} else {
219
+			return array();
220
+		}
213 221
 	}
214 222
 
215 223
     /**
@@ -224,7 +232,9 @@  discard block
 block discarded – undo
224 232
 		date_default_timezone_set($globalTimezone);
225 233
 		$check_date = new Datetime($date);
226 234
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
227
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
235
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
236
+			return array();
237
+		}
228 238
 		$url = "http://www.easyjet.com/ft/api/flights?date=".$check_date->format('Y-m-d')."&fn=".$callsign;
229 239
 		$json = $Common->getData($url);
230 240
 		$parsed_json = json_decode($json);
@@ -237,7 +247,9 @@  discard block
 block discarded – undo
237 247
 			$arrivalTime = $parsed_json->{'flights'}[0]->{'dates'}->{'fsta'};
238 248
 
239 249
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_easyjet');
240
-		} else return array();
250
+		} else {
251
+			return array();
252
+		}
241 253
 	}
242 254
 
243 255
     /**
@@ -248,7 +260,9 @@  discard block
 block discarded – undo
248 260
 	private function getRyanair($callsign) {
249 261
 		$Common = new Common();
250 262
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
251
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
263
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
264
+			return array();
265
+		}
252 266
 		$url = "http://www.ryanair.com/fr/api/2/flight-info/0/50/";
253 267
 		$post = '{"flight":"'.$numvol.'","minDepartureTime":"00:00","maxDepartureTime":"23:59"}';
254 268
 		$headers = array('Content-Type: application/json','Content-Length: ' . strlen($post));
@@ -262,8 +276,12 @@  discard block
 block discarded – undo
262 276
 				$departureTime = $parsed_json->{'flightInfo'}[0]->{'departureTime'};
263 277
 				$arrivalTime = $parsed_json->{'flightInfo'}[0]->{'arrivalTime'};
264 278
 				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime, 'Source' => 'website_ryanair');
265
-			} else return array();
266
-		} else return array();
279
+			} else {
280
+				return array();
281
+			}
282
+		} else {
283
+			return array();
284
+		}
267 285
 	}
268 286
 
269 287
 	/**
@@ -274,7 +292,9 @@  discard block
 block discarded – undo
274 292
 	private function getSwiss($callsign) {
275 293
 		$Common = new Common();
276 294
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
277
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
295
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
296
+			return array();
297
+		}
278 298
 		$url = "http://www.world-of-swiss.com/fr/routenetwork.json";
279 299
 		$json = $Common->getData($url);
280 300
 		$parsed_json = json_decode($json);
@@ -294,8 +314,12 @@  discard block
 block discarded – undo
294 314
 			}
295 315
 			if (isset($DepartureAirportIata) && isset($ArrivalAirportIata)) {
296 316
 				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_swiss');
297
-			} else return array();
298
-		} else return array();
317
+			} else {
318
+				return array();
319
+			}
320
+		} else {
321
+			return array();
322
+		}
299 323
 	}
300 324
 	
301 325
 	/**
@@ -309,12 +333,18 @@  discard block
 block discarded – undo
309 333
 		$Common = new Common();
310 334
 		$check_date = new Datetime($date);
311 335
 		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
312
-		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
313
-		if ($globalBritishAirwaysKey == '') return array();
336
+		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) {
337
+			return array();
338
+		}
339
+		if ($globalBritishAirwaysKey == '') {
340
+			return array();
341
+		}
314 342
 		$url = "https://api.ba.com/rest-v1/v1/flights;flightNumber=".$numvol.";scheduledDepartureDate=".$check_date->format('Y-m-d').".json";
315 343
 		$headers = array('Client-Key: '.$globalBritishAirwaysKey);
316 344
 		$json = $Common->getData($url,'get','',$headers);
317
-		if ($json == '') return array();
345
+		if ($json == '') {
346
+			return array();
347
+		}
318 348
 		$parsed_json = json_decode($json);
319 349
 		$flights = $parsed_json->{'FlightsResponse'};
320 350
 		if (count($flights) > 0) {
@@ -323,7 +353,9 @@  discard block
 block discarded – undo
323 353
 			$departureTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledDepartureDateTime'}));
324 354
 			$arrivalTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledArrivalDateTime'}));
325 355
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_britishairways');
326
-		} else return array();
356
+		} else {
357
+			return array();
358
+		}
327 359
 	}
328 360
 
329 361
 	/**
@@ -337,19 +369,27 @@  discard block
 block discarded – undo
337 369
 		$Common = new Common();
338 370
 		$check_date = new Datetime($date);
339 371
 		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
340
-		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
341
-		if (!isset($globalLufthansaKey) || $globalLufthansaKey == '' || !isset($globalLufthansaKey['key']) || $globalLufthansaKey['key'] == '') return array();
372
+		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) {
373
+			return array();
374
+		}
375
+		if (!isset($globalLufthansaKey) || $globalLufthansaKey == '' || !isset($globalLufthansaKey['key']) || $globalLufthansaKey['key'] == '') {
376
+			return array();
377
+		}
342 378
 		$url = "https://api.lufthansa.com/v1/oauth/token";
343 379
 		$post = array('client_id' => $globalLufthansaKey['key'],'client_secret' => $globalLufthansaKey['secret'],'grant_type' => 'client_credentials');
344 380
 		$data = $Common->getData($url,'post',$post);
345 381
 		$parsed_data = json_decode($data);
346
-		if (!isset($parsed_data->{'access_token'})) return array();
382
+		if (!isset($parsed_data->{'access_token'})) {
383
+			return array();
384
+		}
347 385
 		$token = $parsed_data->{'access_token'};
348 386
 		
349 387
 		$url = "https://api.lufthansa.com/v1/operations/flightstatus/LH".$numvol."/".$check_date->format('Y-m-d');
350 388
 		$headers = array('Authorization: Bearer '.$token,'Accept: application/json');
351 389
 		$json = $Common->getData($url,'get','',$headers);
352
-		if ($json == '') return array();
390
+		if ($json == '') {
391
+			return array();
392
+		}
353 393
 		$parsed_json = json_decode($json);
354 394
 		if (isset($parsed_json->{'FlightStatusResource'}) && count($parsed_json->{'FlightStatusResource'}) > 0) {
355 395
 			$DepartureAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'AirportCode'};
@@ -357,7 +397,9 @@  discard block
 block discarded – undo
357 397
 			$ArrivalAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'AirportCode'};
358 398
 			$arrivalTime = date('H:i',strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'ScheduledTimeLocal'}->{'DateTime'}));
359 399
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_lufthansa');
360
-		} else return array();
400
+		} else {
401
+			return array();
402
+		}
361 403
 	}
362 404
 
363 405
 	/**
@@ -371,14 +413,20 @@  discard block
 block discarded – undo
371 413
 		$Common = new Common();
372 414
 		$check_date = new Datetime($date);
373 415
 		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
374
-		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
375
-		if ($globalTransaviaKey == '') return array();
416
+		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) {
417
+			return array();
418
+		}
419
+		if ($globalTransaviaKey == '') {
420
+			return array();
421
+		}
376 422
 		$url = "https://tst.api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol;
377 423
 		//$url = "https://api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol;
378 424
 		$headers = array('apikey: '.$globalTransaviaKey);
379 425
 		$json = $Common->getData($url,'get','',$headers);
380 426
 		//echo 'result : '.$json;
381
-		if ($json == '') return array();
427
+		if ($json == '') {
428
+			return array();
429
+		}
382 430
 		$parsed_json = json_decode($json);
383 431
 		
384 432
 		if (isset($parsed_json->{'data'}[0])) {
@@ -387,7 +435,9 @@  discard block
 block discarded – undo
387 435
 			$ArrivalAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'arrivalAirport'}->{'locationCode'};
388 436
 			$arrivalTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'arrivalDateTime'}));
389 437
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_transavia');
390
-		} else return array();
438
+		} else {
439
+			return array();
440
+		}
391 441
 	}
392 442
 
393 443
 	/**
@@ -398,7 +448,9 @@  discard block
 block discarded – undo
398 448
 	public function getTunisair($callsign) {
399 449
 		$Common = new Common();
400 450
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
401
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
451
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
452
+			return array();
453
+		}
402 454
 		$url = "http://www.tunisair.com/site/publish/module/Volj/fr/Flight_List.asp";
403 455
 		$data = $Common->getData($url);
404 456
 		$table = $Common->table2array($data);
@@ -420,7 +472,9 @@  discard block
 block discarded – undo
420 472
 		$Common = new Common();
421 473
 		$check_date = new Datetime($date);
422 474
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
423
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
475
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
476
+			return array();
477
+		}
424 478
 		$final_date = str_replace('/','%2F',$check_date->format('d/m/Y'));
425 479
 		$url = "http://www.vueling.com/Base/BaseProxy/RenderMacro/?macroalias=FlightStatusResult&searchBy=bycode&date=".$final_date."&flightNumber=".$numvol."&idioma=en-GB";
426 480
 		$data = $Common->getData($url);
@@ -430,8 +484,11 @@  discard block
 block discarded – undo
430 484
 			$DepartureAirportIata = str_replace('flightOri=','',$result[0]);
431 485
 			preg_match('/flightDest=[A-Z]{3}/',$data,$result);
432 486
 			$ArrivalAirportIata = str_replace('flightDest=','',$result[0]);
433
-			if ($DepartureAirportIata != '' && $ArrivalAirportIata != '') return array('DepartureAirportIATA' => $DepartureAirportIata,'ArrivalAirportIATA' => $ArrivalAirportIata,'Source' => 'website_vueling');
434
-			else return array();
487
+			if ($DepartureAirportIata != '' && $ArrivalAirportIata != '') {
488
+				return array('DepartureAirportIATA' => $DepartureAirportIata,'ArrivalAirportIATA' => $ArrivalAirportIata,'Source' => 'website_vueling');
489
+			} else {
490
+				return array();
491
+			}
435 492
 		}
436 493
 		return array();
437 494
 	}
@@ -446,7 +503,9 @@  discard block
 block discarded – undo
446 503
 		$Common = new Common();
447 504
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
448 505
 		$check_date = new Datetime($date);
449
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
506
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
507
+			return array();
508
+		}
450 509
 		$url = "https://www.iberia.com/web/flightDetail.do";
451 510
 		$post = array('numvuelo' => $numvol,'fecha' => $check_date->format('Ymd'),'airlineID' => 'IB');
452 511
 		$data = $Common->getData($url,'post',$post);
@@ -463,7 +522,9 @@  discard block
 block discarded – undo
463 522
 				$arrivalTime = trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[5][1])));
464 523
 				if ($arrivalTime == 'Hora estimada de llegada') {
465 524
 					$arrivalTime = substr(trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[5][2]))),0,5);
466
-				} else $arrivalTime = substr($arrivalTime,0,5);
525
+				} else {
526
+					$arrivalTime = substr($arrivalTime,0,5);
527
+				}
467 528
 				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_iberia');
468 529
 			}
469 530
 		}
@@ -482,7 +543,9 @@  discard block
 block discarded – undo
482 543
 		$Common = new Common();
483 544
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
484 545
 		$check_date = new Datetime($date);
485
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
546
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
547
+			return array();
548
+		}
486 549
 		$url = "http://www.staralliance.com/flifoQueryAction.do?myAirline=&airlineCode=".$carrier."&flightNo=".$numvol."&day=".$check_date->format('d')."&month=".$check_date->format('m')."&year=".$check_date->format('Y')."&departuredate=".$check_date->format('d-M-Y');
487 550
 		$data = $Common->getData($url);
488 551
 		if ($data != '') {
@@ -498,7 +561,9 @@  discard block
 block discarded – undo
498 561
 					$departureTime = substr(trim(str_replace('Scheduled: ','',$flight[29][0])),0,5);
499 562
 					$arrivalTime = substr(trim(str_replace('Scheduled: ','',$flight[29][1])),0,5);
500 563
 					return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_staralliance');
501
-				} else return array();
564
+				} else {
565
+					return array();
566
+				}
502 567
 			}
503 568
 			
504 569
 
@@ -518,7 +583,9 @@  discard block
 block discarded – undo
518 583
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
519 584
 		$check_date = new Datetime($date);
520 585
 		$url= "http://booking.alitalia.com/FlightStatus/fr_fr/FlightInfo?Brand=az&NumeroVolo=".$numvol."&DataCompleta=".$check_date->format('d/m/Y');
521
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
586
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
587
+			return array();
588
+		}
522 589
 		$data = $Common->getData($url);
523 590
 		if ($data != '') {
524 591
 			$table = $Common->text2array($data);
@@ -543,7 +610,9 @@  discard block
 block discarded – undo
543 610
 		$check_date = new Datetime($date);
544 611
 		$url= "http://www.brusselsairlines.com/api/flightstatus/getresults?from=NA&to=NA&date=".$check_date->format('d/m/Y')."&hour=NA&lookup=flightnumber&flightnumber=".$numvol."&publicationID=302";
545 612
 		//http://www.brusselsairlines.com/fr-fr/informations-pratiques/statut-de-votre-vol/resultat.aspx?flightnumber=".$numvol."&date=".$check_date->format('d/m/Y')."&lookup=flightnumber";
546
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
613
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
614
+			return array();
615
+		}
547 616
 		$data = $Common->getData($url);
548 617
 		if ($data != '') {
549 618
 		    //echo $data;
@@ -634,7 +703,9 @@  discard block
 block discarded – undo
634 703
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
635 704
 		$url= "http://www.flytap.com/France/fr/PlanifierEtReserver/Outils/DepartsEtArrivees";
636 705
 		//$check_date = new Datetime($date);
637
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
706
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
707
+			return array();
708
+		}
638 709
 		$post = array('arrivalsdepartures_content' => 'number','arrivalsdepartures_tp' => $numvol,'arrivalsdepartures_trk' => 'ARR','arrivalsdepartures_date_trk' => '1','aptCode' => '','arrivalsdepartures' => 'DEP','arrivalsdepartures_date' => '1','aptCodeFrom' => '','aptCodeTo' => '','arrivalsdepartures2' => 'DEP','arrivalsdepartures_date2' => '1');
639 710
 		$data = $Common->getData($url,'post',$post);
640 711
 		if ($data != '') {
@@ -666,11 +737,15 @@  discard block
 block discarded – undo
666 737
 				$airline_icao = substr($callsign, 0, 3);
667 738
 			} 
668 739
 		}
669
-		if ($airline_icao == '') return array();
740
+		if ($airline_icao == '') {
741
+			return array();
742
+		}
670 743
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
671 744
 		$url= "http://info.flightmapper.net/flight/".$airline_icao.'_'.$numvol;
672 745
 		//$check_date = new Datetime($date);
673
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
746
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
747
+			return array();
748
+		}
674 749
 		$data = $Common->getData($url);
675 750
 		if ($data != '') {
676 751
 			$table = $Common->table2array($data);
@@ -763,10 +838,16 @@  discard block
 block discarded – undo
763 838
 		if ($data != '') {
764 839
 			$table = $Common->table2array($data);
765 840
 			if (isset($table[11][1])) {
766
-				if (is_numeric(substr($table[11][1],0,1))) $departureTime = substr($table[11][1],0,5);
767
-				else $departureTime = '';
768
-				if (is_numeric(substr($table[17][1],0,1))) $arrivalTime = substr($table[17][1],0,5);
769
-				else $arrivalTime = '';
841
+				if (is_numeric(substr($table[11][1],0,1))) {
842
+					$departureTime = substr($table[11][1],0,5);
843
+				} else {
844
+					$departureTime = '';
845
+				}
846
+				if (is_numeric(substr($table[17][1],0,1))) {
847
+					$arrivalTime = substr($table[17][1],0,5);
848
+				} else {
849
+					$arrivalTime = '';
850
+				}
770 851
 				$DepartureAirportIata = substr($table[13][1],0,3);
771 852
 				$ArrivalAirportIata = substr($table[15][1],0,3);
772 853
 				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_costtotravel');
@@ -783,16 +864,22 @@  discard block
 block discarded – undo
783 864
 	*/
784 865
 	private function getAirCanada($callsign,$date = 'NOW') {
785 866
 		$Common = new Common();
786
-		if (class_exists("DomDocument") === FALSE) return array();
867
+		if (class_exists("DomDocument") === FALSE) {
868
+			return array();
869
+		}
787 870
 		date_default_timezone_set('UTC');
788 871
 		$check_date = new Datetime($date);
789 872
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
790 873
 		$url= "http://services.aircanada.com/portal/rest/getFlightsByFlightNumber?forceTimetable=true&flightNumber=".$numvol."&carrierCode=AC&date=".$check_date->format('m-d-Y')."&app_key=AE919FDCC80311DF9BABC975DFD72085&cache=74249";
791
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
874
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
875
+			return array();
876
+		}
792 877
 		$data = $Common->getData($url);
793 878
 		$dom = new DomDocument();
794 879
 		$dom->loadXML($data);
795
-		if ($dom->getElementsByTagName('DepartureStationInfo')->length == 0) return array();
880
+		if ($dom->getElementsByTagName('DepartureStationInfo')->length == 0) {
881
+			return array();
882
+		}
796 883
 		$departure = $dom->getElementsByTagName('DepartureStationInfo')->item(0);
797 884
 		if (isset($departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue)) {
798 885
 			$DepartureAirportIata = $departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue;
@@ -801,7 +888,9 @@  discard block
 block discarded – undo
801 888
 			$ArrivalAirportIata = $arrival->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue;
802 889
 			$arrivalTime = date('H:i',strtotime($arrival->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
803 890
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_aircanada');
804
-		} else return array();
891
+		} else {
892
+			return array();
893
+		}
805 894
 	}
806 895
 
807 896
 	/**
@@ -815,7 +904,9 @@  discard block
 block discarded – undo
815 904
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
816 905
 		$check_date = new Datetime($date);
817 906
 		$url= "https://cat.sabresonicweb.com/SSWVN/meridia?posid=VNVN&page=flifoFlightInfoDetailsMessage_learn&action=flightInfoDetails&airline=VN&language=fr&depDay=".$check_date->format('j')."&depMonth=".strtoupper($check_date->format('M'))."&=&flight=".$numvol."&";
818
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
907
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
908
+			return array();
909
+		}
819 910
 		$data = $Common->getData($url);
820 911
 		if ($data != '') {
821 912
 			$table = $Common->table2array($data);
@@ -845,7 +936,9 @@  discard block
 block discarded – undo
845 936
 		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
846 937
 		$check_date = new Datetime($date);
847 938
 		$url= "http://www.airberlin.com/en-US/site/aims.php";
848
-		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
939
+		if (!filter_var($numvol,FILTER_VALIDATE_INT)) {
940
+			return array();
941
+		}
849 942
 		$post = array('type' => 'departure','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => $carrier);
850 943
 		$data = $Common->getData($url,'post',$post);
851 944
 		//echo $data;
@@ -855,11 +948,19 @@  discard block
 block discarded – undo
855 948
 		if ($data != '') {
856 949
 			$table = $Common->table2array($data);
857 950
 			$flight = $table;
858
-			if (isset($flight[5][4])) $departureTime = $flight[5][4];
859
-			else $departureTime = '';
860
-			if (isset($flight[5][2])) $departureAirport = $flight[5][2];
861
-			else $departureAirport = '';
862
-		} else return array();
951
+			if (isset($flight[5][4])) {
952
+				$departureTime = $flight[5][4];
953
+			} else {
954
+				$departureTime = '';
955
+			}
956
+			if (isset($flight[5][2])) {
957
+				$departureAirport = $flight[5][2];
958
+			} else {
959
+				$departureAirport = '';
960
+			}
961
+		} else {
962
+			return array();
963
+		}
863 964
 		$post = array('type' => 'arrival','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => 'AB');
864 965
 		$data = $Common->getData($url,'post',$post);
865 966
 		if ($data != '') {
@@ -872,10 +973,14 @@  discard block
 block discarded – undo
872 973
 			    $arrivalTime = '';
873 974
 			    $arrivalAirport = '';
874 975
 			}
875
-		} else return array();
976
+		} else {
977
+			return array();
978
+		}
876 979
 		$url = 'http://www.airberlin.com/en-US/site/json/suggestAirport.php?searchfor=departures&searchflightid=0&departures%5B%5D=&suggestsource%5B0%5D=activeairports&withcountries=0&withoutroutings=0&promotion%5Bid%5D=&promotion%5Btype%5D=&routesource%5B0%5D=airberlin&routesource%5B1%5D=partner';
877 980
 		$json = $Common->getData($url);
878
-		if ($json == '') return array();
981
+		if ($json == '') {
982
+			return array();
983
+		}
879 984
 		$parsed_json = json_decode($json);
880 985
 		$airports = $parsed_json->{'suggestList'};
881 986
 		if (count($airports) > 0) {
@@ -890,7 +995,9 @@  discard block
 block discarded – undo
890 995
 		}
891 996
 		if (isset($DepartureAirportIata)) {
892 997
 			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airberlin');
893
-		} else return array();
998
+		} else {
999
+			return array();
1000
+		}
894 1001
 	}
895 1002
 
896 1003
 	/*
@@ -902,7 +1009,9 @@  discard block
 block discarded – undo
902 1009
 	public function fetchSchedule($ident,$date = 'NOW') {
903 1010
 		global $globalSchedulesSources, $globalSchedulesFetch, $globalOffline, $globalFlightAwareUsername;
904 1011
 		//$Common = new Common();
905
-		if ($globalSchedulesFetch === FALSE || (isset($globalOffline) && $globalOffline === TRUE)) return array();
1012
+		if ($globalSchedulesFetch === FALSE || (isset($globalOffline) && $globalOffline === TRUE)) {
1013
+			return array();
1014
+		}
906 1015
 		$airline_icao = '';
907 1016
 		if (!is_numeric(substr($ident, 0, 3)))
908 1017
 		{
@@ -1137,18 +1246,27 @@  discard block
 block discarded – undo
1137 1246
 					if (strlen($airline_icao) == 3) {
1138 1247
 						$Spotter = new Spotter($this->db);
1139 1248
 						$airline_info = $Spotter->getAllAirlineInfo($airline_icao);
1140
-						if (isset($airline_info[0]['iata'])) $airline_icao = $airline_info[0]['iata'];
1249
+						if (isset($airline_info[0]['iata'])) {
1250
+							$airline_icao = $airline_info[0]['iata'];
1251
+						}
1141 1252
 					}
1142 1253
 					// Randomly use a generic function to get hours
1143 1254
 					if (strlen($airline_icao) == 2) {
1144
-						if (!isset($globalSchedulesSources)) $globalSchedulesSources = array('flightmapper','costtotravel','flightaware');
1255
+						if (!isset($globalSchedulesSources)) {
1256
+							$globalSchedulesSources = array('flightmapper','costtotravel','flightaware');
1257
+						}
1145 1258
 						if (count($globalSchedulesSources) > 0) {
1146 1259
 							$rand = mt_rand(0,count($globalSchedulesSources)-1);
1147 1260
 							$source = $globalSchedulesSources[$rand];
1148
-							if ($source == 'flightmapper') return $this->getFlightMapper($ident);
1149
-							elseif ($source == 'costtotravel') return $this->getCostToTravel($ident);
1261
+							if ($source == 'flightmapper') {
1262
+								return $this->getFlightMapper($ident);
1263
+							} elseif ($source == 'costtotravel') {
1264
+								return $this->getCostToTravel($ident);
1265
+							}
1150 1266
 							//elseif ($source == 'flightradar24') return $this->getFlightRadar24($ident,$date);
1151
-							elseif ($source == 'flightaware' && $globalFlightAwareUsername != '') return $this->getFlightAware($ident);
1267
+							elseif ($source == 'flightaware' && $globalFlightAwareUsername != '') {
1268
+								return $this->getFlightAware($ident);
1269
+							}
1152 1270
 						}
1153 1271
 					}
1154 1272
 			}
Please login to merge, or discard this patch.
require/class.Accident.php 3 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -36,12 +36,12 @@  discard block
 block discarded – undo
36 36
 	}
37 37
 
38 38
 	/**
39
-	* Get Accidents data from DB
40
-	* @param String $limit Limit
41
-	* @param String $type Set type accident or incident
42
-	* @param String $date get data for a date
43
-	* @return array Return Accidents data in array
44
-	*/
39
+	 * Get Accidents data from DB
40
+	 * @param String $limit Limit
41
+	 * @param String $type Set type accident or incident
42
+	 * @param String $date get data for a date
43
+	 * @return array Return Accidents data in array
44
+	 */
45 45
 	public function getAccidentData($limit = '',$type = '',$date = '') {
46 46
 		global $globalDBdriver;
47 47
 		$Image = new Image($this->db);
@@ -384,11 +384,11 @@  discard block
 block discarded – undo
384 384
 		return $row['nb'];
385 385
 	}
386 386
 
387
-    /**
388
-     * Check if lastest accident update date is older than 1 day
389
-     * @return bool|string
390
-     */
391
-    public static function check_last_accidents_update() {
387
+	/**
388
+	 * Check if lastest accident update date is older than 1 day
389
+	 * @return bool|string
390
+	 */
391
+	public static function check_last_accidents_update() {
392 392
 		global $globalDBdriver;
393 393
 		if ($globalDBdriver == 'mysql') {
394 394
 			$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_accident_db' AND value > DATE_SUB(NOW(), INTERVAL 1 DAY)";
@@ -407,11 +407,11 @@  discard block
 block discarded – undo
407 407
 		else return true;
408 408
 	}
409 409
 
410
-    /**
411
-     * Insert accident update date
412
-     * @return string
413
-     */
414
-    public static function insert_last_accidents_update() {
410
+	/**
411
+	 * Insert accident update date
412
+	 * @return string
413
+	 */
414
+	public static function insert_last_accidents_update() {
415 415
 		$query = "DELETE FROM config WHERE name = 'last_update_accident_db';
416 416
 		    INSERT INTO config (name,value) VALUES ('last_update_accident_db',NOW());";
417 417
 		try {
Please login to merge, or discard this patch.
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -42,20 +42,20 @@  discard block
 block discarded – undo
42 42
 	* @param String $date get data for a date
43 43
 	* @return array Return Accidents data in array
44 44
 	*/
45
-	public function getAccidentData($limit = '',$type = '',$date = '') {
45
+	public function getAccidentData($limit = '', $type = '', $date = '') {
46 46
 		global $globalDBdriver;
47 47
 		$Image = new Image($this->db);
48 48
 		$Spotter = new Spotter($this->db);
49 49
 		$Translation = new Translation($this->db);
50
-		$date = filter_var($date,FILTER_SANITIZE_STRING);
50
+		$date = filter_var($date, FILTER_SANITIZE_STRING);
51 51
 		date_default_timezone_set('UTC');
52 52
 		$result = array();
53 53
 		$limit_query = '';
54 54
 		if ($limit != "")
55 55
 		{
56 56
 			$limit_array = explode(",", $limit);
57
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
58
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
57
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
58
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
59 59
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
60 60
 			{
61 61
 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
@@ -64,29 +64,29 @@  discard block
 block discarded – undo
64 64
 
65 65
 		if ($type != '') {
66 66
 			if ($date != '') {
67
-				if (preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/",$date)) {
67
+				if (preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/", $date)) {
68 68
 					$query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND date = :date GROUP BY registration) ORDER BY accidents.date DESC".$limit_query;
69 69
 					//$query = "SELECT accidents.registration, accidents.ident, accidents.date, accidents.url, accidents.country, accidents.place, accidents.title, accidents.fatalities, accidents.type, accidents.ident, accidents.aircraft_manufacturer, accidents.aircraft_name, accidents.airline_name, accidents.airline_icao, spotter_output.flightaware_id FROM accidents LEFT OUTER JOIN spotter_output ON accidents.registration = spotter_output.registration WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND date = :date GROUP BY registration) ORDER BY accidents.date DESC".$limit_query;
70
-					$query_values = array(':type' => $type,':date' => $date);
71
-				} elseif (preg_match("/^[0-9]{4}-[0-9]{2}$/",$date)) {
70
+					$query_values = array(':type' => $type, ':date' => $date);
71
+				} elseif (preg_match("/^[0-9]{4}-[0-9]{2}$/", $date)) {
72 72
 					$query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND date BETWEEN :dated AND :datef GROUP BY registration) ORDER BY accidents.date DESC".$limit_query;
73
-					$query_values = array(':type' => $type,':dated' => $date.'-01', ':datef' => $date.'-31');
74
-				} elseif (preg_match("/^[0-9]{4}$/",$date)) {
73
+					$query_values = array(':type' => $type, ':dated' => $date.'-01', ':datef' => $date.'-31');
74
+				} elseif (preg_match("/^[0-9]{4}$/", $date)) {
75 75
 					if ($globalDBdriver == 'mysql') {
76 76
 						$query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND YEAR(date) = :date GROUP BY registration) ORDER BY accidents.date DESC".$limit_query;
77 77
 					} else {
78 78
 						$query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND EXTRACT(YEAR FROM date) = :date GROUP BY registration) ORDER BY accidents.date DESC".$limit_query;
79 79
 					}
80
-					$query_values = array(':type' => $type,':date' => $date);
80
+					$query_values = array(':type' => $type, ':date' => $date);
81 81
 				} else {
82 82
 					$date = $date.'%';
83 83
 					if ($globalDBdriver == 'mysql') {
84 84
 						$query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND DATE_FORMAT(date,'%Y-%m-%d') LIKE :date GROUP BY registration) ORDER BY accidents.date DESC".$limit_query;
85
-						$query_values = array(':type' => $type,':date' => $date);
85
+						$query_values = array(':type' => $type, ':date' => $date);
86 86
 					} else {
87 87
 						$query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND to_char(date,'YYYY-MM-DD') LIKE :date GROUP BY registration) ORDER BY accidents.date DESC".$limit_query;
88 88
 						//$query = "SELECT accidents.registration, accidents.ident, accidents.date, accidents.url, accidents.country, accidents.place, accidents.title, accidents.fatalities, accidents.type, accidents.ident, accidents.aircraft_manufacturer, accidents.aircraft_name, accidents.airline_name, accidents.airline_icao, spotter_output.flightaware_id FROM accidents LEFT OUTER JOIN spotter_output ON accidents.registration = spotter_output.registration WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND to_char(date,'YYYY-MM-DD') LIKE :date GROUP BY registration) ORDER BY accidents.date DESC".$limit_query;
89
-						$query_values = array(':type' => $type,':date' => $date);
89
+						$query_values = array(':type' => $type, ':date' => $date);
90 90
 					}
91 91
 				}
92 92
 			} else {
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 			}
98 98
 		} else {
99 99
 			if ($date != '') {
100
-				if (preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/",$date)) {
100
+				if (preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/", $date)) {
101 101
 					$query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE date = :date GROUP BY registration) ORDER BY accidents.date DESC".$limit_query;
102 102
 					//$query = "SELECT accidents.registration, accidents.ident, accidents.date, accidents.url, accidents.country, accidents.place, accidents.title, accidents.fatalities, accidents.type, accidents.ident, accidents.aircraft_manufacturer, accidents.aircraft_name, accidents.airline_name, accidents.airline_icao, spotter_output.flightaware_id FROM accidents LEFT OUTER JOIN spotter_output ON accidents.registration = spotter_output.registration WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE date = :date GROUP BY registration) ORDER BY accidents.date DESC".$limit_query;
103 103
 				} else {
@@ -116,18 +116,18 @@  discard block
 block discarded – undo
116 116
 		try {
117 117
 			$sth = $this->db->prepare($query);
118 118
 			$sth->execute($query_values);
119
-		} catch(PDOException $e) {
119
+		} catch (PDOException $e) {
120 120
 			echo "error : ".$e->getMessage();
121 121
 			return array();
122 122
 		}
123 123
 		$i = 0;
124 124
 		while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
125
-			if (preg_match('/^[\w\-]+$/',$row['registration'])) {
125
+			if (preg_match('/^[\w\-]+$/', $row['registration'])) {
126 126
 				$data = array();
127 127
 				if ($row['registration'] != '') {
128 128
 					$image_array = $Image->getSpotterImage($row['registration']);
129
-					if (count($image_array) > 0) $data = array_merge($data,array('image' => $image_array[0]['image'],'image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website']));
130
-					else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
129
+					if (count($image_array) > 0) $data = array_merge($data, array('image' => $image_array[0]['image'], 'image_thumbnail' => $image_array[0]['image_thumbnail'], 'image_copyright' => $image_array[0]['image_copyright'], 'image_source' => $image_array[0]['image_source'], 'image_source_website' => $image_array[0]['image_source_website']));
130
+					else $data = array_merge($data, array('image' => '', 'image_thumbnail' => '', 'image_copyright' => '', 'image_source' => '', 'image_source_website' => ''));
131 131
 					$aircraft_type = $Spotter->getAllAircraftTypeByRegistration($row['registration']);
132 132
 					$aircraft_info = $Spotter->getAllAircraftInfo($aircraft_type);
133 133
 					if (!empty($aircraft_info)) {
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 						$data['aircraft_name'] = $aircraft_info[0]['type'];
136 136
 						$data['aircraft_manufacturer'] = $aircraft_info[0]['manufacturer'];
137 137
 					} else {
138
-						$data = array_merge($data,array('aircraft_type' => 'NA'));
138
+						$data = array_merge($data, array('aircraft_type' => 'NA'));
139 139
 					}
140 140
 					$owner_data = $Spotter->getAircraftOwnerByRegistration($row['registration']);
141 141
 					if (!empty($owner_data)) {
@@ -143,18 +143,18 @@  discard block
 block discarded – undo
143 143
 						$data['aircraft_base'] = $owner_data['base'];
144 144
 						$data['aircraft_date_first_reg'] = $owner_data['date_first_reg'];
145 145
 					}
146
-				} else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
146
+				} else $data = array_merge($data, array('image' => '', 'image_thumbnail' => '', 'image_copyright' => '', 'image_source' => '', 'image_source_website' => ''));
147 147
 				if ($row['registration'] == '') $row['registration'] = 'NA';
148 148
 				if ($row['ident'] == '') $row['ident'] = 'NA';
149
-				$identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,3));
149
+				$identicao = $Spotter->getAllAirlineInfo(substr($row['ident'], 0, 3));
150 150
 				if (isset($identicao[0])) {
151
-					if (substr($row['ident'],0,2) == 'AF') {
152
-						if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident'];
153
-						else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
154
-					} else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
155
-					$data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name']));
151
+					if (substr($row['ident'], 0, 2) == 'AF') {
152
+						if (filter_var(substr($row['ident'], 2), FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident'];
153
+						else $icao = 'AFR'.ltrim(substr($row['ident'], 2), '0');
154
+					} else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'], 2), '0');
155
+					$data = array_merge($data, array('airline_icao' => $identicao[0]['icao'], 'airline_name' => $identicao[0]['name']));
156 156
 				} else $icao = $row['ident'];
157
-				$icao = $Translation->checkTranslation($icao,false);
157
+				$icao = $Translation->checkTranslation($icao, false);
158 158
 				//$data = array_merge($data,array('registration' => $row['registration'], 'date' => $row['date'], 'ident' => $icao,'url' => $row['url']));
159 159
 				if ($row['airline_name'] != '' && !isset($data['airline_name'])) {
160 160
 					//echo 'Check airline info... for '.$row['airline_name'].' ';
@@ -163,16 +163,16 @@  discard block
 block discarded – undo
163 163
 					if (!empty($airline_info)) {
164 164
 						//echo 'data found !'."\n";
165 165
 						//print_r($airline_info);
166
-						$data = array_merge($data,$airline_info);
166
+						$data = array_merge($data, $airline_info);
167 167
 					} 
168 168
 					//else echo 'No data...'."\n";
169 169
 				}
170
-				$data = array_merge($row,$data);
170
+				$data = array_merge($row, $data);
171 171
 				if ($data['ident'] == null) $data['ident'] = $icao;
172 172
 				if ($data['title'] == null) {
173 173
 					$data['message'] = $row['type'].' of '.$row['registration'].' at '.$row['place'].','.$row['country'];
174 174
 				} else $data['message'] = strtolower($data['title']);
175
-				$ids = $Spotter->getAllIDByRegistration($data['registration'],true);
175
+				$ids = $Spotter->getAllIDByRegistration($data['registration'], true);
176 176
 				$date = $data['date'];
177 177
 				if (isset($ids[$date])) {
178 178
 					$data['spotted'] = TRUE;
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 		try {
205 205
 			$sth = $this->db->prepare($query);
206 206
 			$sth->execute();
207
-		} catch(PDOException $e) {
207
+		} catch (PDOException $e) {
208 208
 			echo "Error : ".$e->getMessage();
209 209
 			return array();
210 210
 		}
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 		try {
226 226
 			$sth = $this->db->prepare($query);
227 227
 			$sth->execute();
228
-		} catch(PDOException $e) {
228
+		} catch (PDOException $e) {
229 229
 			echo "Error : ".$e->getMessage();
230 230
 			return array();
231 231
 		}
@@ -241,15 +241,15 @@  discard block
 block discarded – undo
241 241
 		if ($globalDebug) echo 'Import '.$file."\n";
242 242
 		$result = array();
243 243
 		if (file_exists($file)) {
244
-			if (($handle = fopen($file,'r')) !== FALSE) {
245
-				while (($data = fgetcsv($handle,2000,",")) !== FALSE) {
244
+			if (($handle = fopen($file, 'r')) !== FALSE) {
245
+				while (($data = fgetcsv($handle, 2000, ",")) !== FALSE) {
246 246
 					if (isset($data[1]) && $data[1] != '0000-00-00 00:00:00') {
247
-						$result[] = array('registration' => $data[0],'date' => strtotime($data[1]),'url' => $data[2],'country' => $data[3],'place' => $data[4],'title' => $data[5],'fatalities' => $data[6],'latitude' => $data[7],'longitude' => $data[8],'type' => $data[9],'ident' => $data[10],'aircraft_manufacturer' => $data[11],'aircraft_name' => $data[12],'operator' => $data[13],'source' => 'website_fam');
247
+						$result[] = array('registration' => $data[0], 'date' => strtotime($data[1]), 'url' => $data[2], 'country' => $data[3], 'place' => $data[4], 'title' => $data[5], 'fatalities' => $data[6], 'latitude' => $data[7], 'longitude' => $data[8], 'type' => $data[9], 'ident' => $data[10], 'aircraft_manufacturer' => $data[11], 'aircraft_name' => $data[12], 'operator' => $data[13], 'source' => 'website_fam');
248 248
 					}
249 249
 				}
250 250
 				fclose($handle);
251 251
 			}
252
-			if (!empty($result)) $this->add($result,true);
252
+			if (!empty($result)) $this->add($result, true);
253 253
 			elseif ($globalDebug) echo 'Nothing to import';
254 254
 		}
255 255
 	}
@@ -265,8 +265,8 @@  discard block
 block discarded – undo
265 265
 		$all_md5_new = array();
266 266
 		if (file_exists(dirname(__FILE__).'/../install/tmp/cr-all.md5')) {
267 267
 			if ($this->check_accidents_nb() > 0) {
268
-				if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5','r')) !== FALSE) {
269
-					while (($data = fgetcsv($handle,2000,"\t")) !== FALSE) {
268
+				if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5', 'r')) !== FALSE) {
269
+					while (($data = fgetcsv($handle, 2000, "\t")) !== FALSE) {
270 270
 						if (isset($data[1])) {
271 271
 							$year = $data[0];
272 272
 							$all_md5[$year] = $data[1];
@@ -276,10 +276,10 @@  discard block
 block discarded – undo
276 276
 				}
277 277
 			}
278 278
 		}
279
-		$Common->download('http://data.flightairmap.fr/data/cr/cr-all.md5',dirname(__FILE__).'/../install/tmp/cr-all.md5');
279
+		$Common->download('http://data.flightairmap.fr/data/cr/cr-all.md5', dirname(__FILE__).'/../install/tmp/cr-all.md5');
280 280
 		if (file_exists(dirname(__FILE__).'/../install/tmp/cr-all.md5')) {
281
-			if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5','r')) !== FALSE) {
282
-				while (($data = fgetcsv($handle,2000,"\t")) !== FALSE) {
281
+			if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5', 'r')) !== FALSE) {
282
+				while (($data = fgetcsv($handle, 2000, "\t")) !== FALSE) {
283 283
 					if (isset($data[1])) {
284 284
 						$year = $data[0];
285 285
 						$all_md5_new[$year] = $data[1];
@@ -288,10 +288,10 @@  discard block
 block discarded – undo
288 288
 				fclose($handle);
289 289
 			} elseif ($globalDebug) echo "Can't open ".dirname(__FILE__).'/../install/tmp/cr-all.md5';
290 290
 		} elseif ($globalDebug) echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.';
291
-		$result = $Common->arr_diff($all_md5_new,$all_md5);
291
+		$result = $Common->arr_diff($all_md5_new, $all_md5);
292 292
 		if (empty($result) && $globalDebug) echo 'Nothing to update';
293 293
 		foreach ($result as $file => $md5) {
294
-			$Common->download('http://data.flightairmap.fr/data/cr/'.$file,dirname(__FILE__).'/../install/tmp/'.$file);
294
+			$Common->download('http://data.flightairmap.fr/data/cr/'.$file, dirname(__FILE__).'/../install/tmp/'.$file);
295 295
 			if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) $this->import(dirname(__FILE__).'/../install/tmp/'.$file);
296 296
 			elseif ($globalDebug) echo 'Download '.$file.' failed';
297 297
 		}
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 	* Add data to DB
302 302
 	* @param Array $crash An array with accidents/incidents data
303 303
 	*/
304
-	public function add($crash,$new = false) {
304
+	public function add($crash, $new = false) {
305 305
 		global $globalTransaction, $globalDebug, $globalAircraftImageFetch;
306 306
 		require_once('class.Connection.php');
307 307
 		require_once('class.Image.php');
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 			$sthd->execute(array(':source' => $crash[0]['source']));
318 318
 		}
319 319
 		if ($globalTransaction) $Connection->db->beginTransaction();
320
-		$initial_array = array('ident' => null,'type' => 'accident','url' => null,'registration' => null, 'date' => null, 'place' => null,'country' => null, 'latitude' => null, 'longitude' => null, 'fatalities' => null, 'title' => '','source' => '','aircraft_manufacturer' => null,'aircraft_name' => null,'operator' => null);
320
+		$initial_array = array('ident' => null, 'type' => 'accident', 'url' => null, 'registration' => null, 'date' => null, 'place' => null, 'country' => null, 'latitude' => null, 'longitude' => null, 'fatalities' => null, 'title' => '', 'source' => '', 'aircraft_manufacturer' => null, 'aircraft_name' => null, 'operator' => null);
321 321
 		$query_check = 'SELECT COUNT(*) as nb FROM accidents WHERE registration = :registration AND date = :date AND type = :type AND source = :source';
322 322
 		$sth_check = $Connection->db->prepare($query_check);
323 323
 		$query = 'INSERT INTO accidents (aircraft_manufacturer,aircraft_name,ident,registration,date,url,country,place,title,fatalities,latitude,longitude,type,airline_name,source) VALUES (:aircraft_manufacturer,:aircraft_name,:ident,:registration,:date,:url,:country,:place,:title,:fatalities,:latitude,:longitude,:type,:airline_name,:source)';
@@ -330,15 +330,15 @@  discard block
 block discarded – undo
330 330
 				$cr = array_map(function($value) {
331 331
 					return $value === "" ? NULL : $value;
332 332
 				}, $cr);
333
-				if ($cr['date'] != '' && $cr['registration'] != null && $cr['registration'] != '' && $cr['registration'] != '?' && $cr['registration'] != '-' && strtolower($cr['registration']) != 'unknown' && $cr['date'] < time() && !preg_match('/\s/',$cr['registration'])) {
334
-					if (strpos($cr['registration'],'-') === FALSE) $cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']);
335
-					$query_check_values = array(':registration' => $cr['registration'],':date' => date('Y-m-d',$cr['date']),':type' => $cr['type'],':source' => $cr['source']);
333
+				if ($cr['date'] != '' && $cr['registration'] != null && $cr['registration'] != '' && $cr['registration'] != '?' && $cr['registration'] != '-' && strtolower($cr['registration']) != 'unknown' && $cr['date'] < time() && !preg_match('/\s/', $cr['registration'])) {
334
+					if (strpos($cr['registration'], '-') === FALSE) $cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']);
335
+					$query_check_values = array(':registration' => $cr['registration'], ':date' => date('Y-m-d', $cr['date']), ':type' => $cr['type'], ':source' => $cr['source']);
336 336
 					$sth_check->execute($query_check_values);
337 337
 					$result_check = $sth_check->fetchAll(PDO::FETCH_ASSOC);
338 338
 					if ($result_check[0]['nb'] == 0) {
339
-						$query_values = array(':registration' => trim($cr['registration']),':date' => date('Y-m-d',$cr['date']),':url' => $cr['url'],':country' => $cr['country'],':place' => $cr['place'],':title' => $cr['title'],':fatalities' => $cr['fatalities'],':latitude' => $cr['latitude'],':longitude' => $cr['longitude'],':type' => $cr['type'],':source' => $cr['source'],':ident' => $cr['ident'],':aircraft_manufacturer' => $cr['aircraft_manufacturer'],':aircraft_name' => $cr['aircraft_name'],':airline_name' => $cr['operator']);
339
+						$query_values = array(':registration' => trim($cr['registration']), ':date' => date('Y-m-d', $cr['date']), ':url' => $cr['url'], ':country' => $cr['country'], ':place' => $cr['place'], ':title' => $cr['title'], ':fatalities' => $cr['fatalities'], ':latitude' => $cr['latitude'], ':longitude' => $cr['longitude'], ':type' => $cr['type'], ':source' => $cr['source'], ':ident' => $cr['ident'], ':aircraft_manufacturer' => $cr['aircraft_manufacturer'], ':aircraft_name' => $cr['aircraft_name'], ':airline_name' => $cr['operator']);
340 340
 						$sth->execute($query_values);
341
-						if ($cr['date'] > time()-(30*86400)) {
341
+						if ($cr['date'] > time() - (30*86400)) {
342 342
 							if ($globalAircraftImageFetch) {
343 343
 								$imgchk = $Image->getSpotterImage($cr['registration']);
344 344
 								if (empty($imgchk)) {
@@ -349,17 +349,17 @@  discard block
 block discarded – undo
349 349
 								// elseif ($globalDebug) echo 'Image already in DB'."\n";
350 350
 							}
351 351
 							if ($cr['title'] == '') $cr['title'] = $cr['registration'].' '.$cr['type'];
352
-							$Spotter->setHighlightFlightByRegistration($cr['registration'],$cr['title'],date('Y-m-d',$cr['date']));
352
+							$Spotter->setHighlightFlightByRegistration($cr['registration'], $cr['title'], date('Y-m-d', $cr['date']));
353 353
 						}
354 354
 					}
355 355
 				}
356
-				if ($globalTransaction && $j % 1000 == 0) {
356
+				if ($globalTransaction && $j%1000 == 0) {
357 357
 					$Connection->db->commit();
358 358
 					$Connection->db->beginTransaction();
359 359
 				}
360 360
 			}
361 361
 			if ($globalTransaction) $Connection->db->commit();
362
-		} catch(PDOException $e) {
362
+		} catch (PDOException $e) {
363 363
 			if ($globalTransaction) $Connection->db->rollBack();
364 364
 			echo $e->getMessage();
365 365
 		}
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
 			$Connection = new Connection();
378 378
 			$sth = $Connection->db->prepare($query);
379 379
 			$sth->execute();
380
-		} catch(PDOException $e) {
380
+		} catch (PDOException $e) {
381 381
 			return "error : ".$e->getMessage();
382 382
 		}
383 383
 		$row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
 			$Connection = new Connection();
400 400
 			$sth = $Connection->db->prepare($query);
401 401
 			$sth->execute();
402
-		} catch(PDOException $e) {
402
+		} catch (PDOException $e) {
403 403
 			return "error : ".$e->getMessage();
404 404
 		}
405 405
 		$row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
 			$Connection = new Connection();
419 419
 			$sth = $Connection->db->prepare($query);
420 420
 			$sth->execute();
421
-		} catch(PDOException $e) {
421
+		} catch (PDOException $e) {
422 422
 			return "error : ".$e->getMessage();
423 423
 		}
424 424
 		return '';
Please login to merge, or discard this patch.
Braces   +87 added lines, -31 removed lines patch added patch discarded remove patch
@@ -20,7 +20,9 @@  discard block
 block discarded – undo
20 20
 	public function __construct($dbc = null) {
21 21
 		$Connection = new Connection($dbc);
22 22
 		$this->db = $Connection->db();
23
-		if ($this->db === null) die('Error: No DB connection. (Accident)');
23
+		if ($this->db === null) {
24
+			die('Error: No DB connection. (Accident)');
25
+		}
24 26
 	}
25 27
 
26 28
 	/*
@@ -126,8 +128,11 @@  discard block
 block discarded – undo
126 128
 				$data = array();
127 129
 				if ($row['registration'] != '') {
128 130
 					$image_array = $Image->getSpotterImage($row['registration']);
129
-					if (count($image_array) > 0) $data = array_merge($data,array('image' => $image_array[0]['image'],'image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website']));
130
-					else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
131
+					if (count($image_array) > 0) {
132
+						$data = array_merge($data,array('image' => $image_array[0]['image'],'image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website']));
133
+					} else {
134
+						$data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
135
+					}
131 136
 					$aircraft_type = $Spotter->getAllAircraftTypeByRegistration($row['registration']);
132 137
 					$aircraft_info = $Spotter->getAllAircraftInfo($aircraft_type);
133 138
 					if (!empty($aircraft_info)) {
@@ -143,17 +148,30 @@  discard block
 block discarded – undo
143 148
 						$data['aircraft_base'] = $owner_data['base'];
144 149
 						$data['aircraft_date_first_reg'] = $owner_data['date_first_reg'];
145 150
 					}
146
-				} else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
147
-				if ($row['registration'] == '') $row['registration'] = 'NA';
148
-				if ($row['ident'] == '') $row['ident'] = 'NA';
151
+				} else {
152
+					$data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
153
+				}
154
+				if ($row['registration'] == '') {
155
+					$row['registration'] = 'NA';
156
+				}
157
+				if ($row['ident'] == '') {
158
+					$row['ident'] = 'NA';
159
+				}
149 160
 				$identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,3));
150 161
 				if (isset($identicao[0])) {
151 162
 					if (substr($row['ident'],0,2) == 'AF') {
152
-						if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident'];
153
-						else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
154
-					} else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
163
+						if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) {
164
+							$icao = $row['ident'];
165
+						} else {
166
+							$icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
167
+						}
168
+					} else {
169
+						$icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
170
+					}
155 171
 					$data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name']));
156
-				} else $icao = $row['ident'];
172
+				} else {
173
+					$icao = $row['ident'];
174
+				}
157 175
 				$icao = $Translation->checkTranslation($icao,false);
158 176
 				//$data = array_merge($data,array('registration' => $row['registration'], 'date' => $row['date'], 'ident' => $icao,'url' => $row['url']));
159 177
 				if ($row['airline_name'] != '' && !isset($data['airline_name'])) {
@@ -168,10 +186,14 @@  discard block
 block discarded – undo
168 186
 					//else echo 'No data...'."\n";
169 187
 				}
170 188
 				$data = array_merge($row,$data);
171
-				if ($data['ident'] == null) $data['ident'] = $icao;
189
+				if ($data['ident'] == null) {
190
+					$data['ident'] = $icao;
191
+				}
172 192
 				if ($data['title'] == null) {
173 193
 					$data['message'] = $row['type'].' of '.$row['registration'].' at '.$row['place'].','.$row['country'];
174
-				} else $data['message'] = strtolower($data['title']);
194
+				} else {
195
+					$data['message'] = strtolower($data['title']);
196
+				}
175 197
 				$ids = $Spotter->getAllIDByRegistration($data['registration'],true);
176 198
 				$date = $data['date'];
177 199
 				if (isset($ids[$date])) {
@@ -190,8 +212,9 @@  discard block
 block discarded – undo
190 212
 		if (isset($result)) {
191 213
 			$result[0]['query_number_rows'] = $i;
192 214
 			return $result;
215
+		} else {
216
+			return array();
193 217
 		}
194
-		else return array();
195 218
 	}
196 219
 
197 220
 	/*
@@ -238,7 +261,9 @@  discard block
 block discarded – undo
238 261
 	*/
239 262
 	public function import($file) {
240 263
 		global $globalDebug;
241
-		if ($globalDebug) echo 'Import '.$file."\n";
264
+		if ($globalDebug) {
265
+			echo 'Import '.$file."\n";
266
+		}
242 267
 		$result = array();
243 268
 		if (file_exists($file)) {
244 269
 			if (($handle = fopen($file,'r')) !== FALSE) {
@@ -249,8 +274,11 @@  discard block
 block discarded – undo
249 274
 				}
250 275
 				fclose($handle);
251 276
 			}
252
-			if (!empty($result)) $this->add($result,true);
253
-			elseif ($globalDebug) echo 'Nothing to import';
277
+			if (!empty($result)) {
278
+				$this->add($result,true);
279
+			} elseif ($globalDebug) {
280
+				echo 'Nothing to import';
281
+			}
254 282
 		}
255 283
 	}
256 284
 
@@ -286,14 +314,23 @@  discard block
 block discarded – undo
286 314
 					}
287 315
 				}
288 316
 				fclose($handle);
289
-			} elseif ($globalDebug) echo "Can't open ".dirname(__FILE__).'/../install/tmp/cr-all.md5';
290
-		} elseif ($globalDebug) echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.';
317
+			} elseif ($globalDebug) {
318
+				echo "Can't open ".dirname(__FILE__).'/../install/tmp/cr-all.md5';
319
+			}
320
+		} elseif ($globalDebug) {
321
+			echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.';
322
+		}
291 323
 		$result = $Common->arr_diff($all_md5_new,$all_md5);
292
-		if (empty($result) && $globalDebug) echo 'Nothing to update';
324
+		if (empty($result) && $globalDebug) {
325
+			echo 'Nothing to update';
326
+		}
293 327
 		foreach ($result as $file => $md5) {
294 328
 			$Common->download('http://data.flightairmap.fr/data/cr/'.$file,dirname(__FILE__).'/../install/tmp/'.$file);
295
-			if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) $this->import(dirname(__FILE__).'/../install/tmp/'.$file);
296
-			elseif ($globalDebug) echo 'Download '.$file.' failed';
329
+			if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) {
330
+				$this->import(dirname(__FILE__).'/../install/tmp/'.$file);
331
+			} elseif ($globalDebug) {
332
+				echo 'Download '.$file.' failed';
333
+			}
297 334
 		}
298 335
 	}
299 336
 
@@ -310,13 +347,17 @@  discard block
 block discarded – undo
310 347
 		$Image = new Image($this->db);
311 348
 		$Spotter = new Spotter($this->db);
312 349
 
313
-		if (empty($crash)) return false;
350
+		if (empty($crash)) {
351
+			return false;
352
+		}
314 353
 		if ($new === false) {
315 354
 			$query_delete = 'DELETE FROM accidents WHERE source = :source';
316 355
 			$sthd = $Connection->db->prepare($query_delete);
317 356
 			$sthd->execute(array(':source' => $crash[0]['source']));
318 357
 		}
319
-		if ($globalTransaction) $Connection->db->beginTransaction();
358
+		if ($globalTransaction) {
359
+			$Connection->db->beginTransaction();
360
+		}
320 361
 		$initial_array = array('ident' => null,'type' => 'accident','url' => null,'registration' => null, 'date' => null, 'place' => null,'country' => null, 'latitude' => null, 'longitude' => null, 'fatalities' => null, 'title' => '','source' => '','aircraft_manufacturer' => null,'aircraft_name' => null,'operator' => null);
321 362
 		$query_check = 'SELECT COUNT(*) as nb FROM accidents WHERE registration = :registration AND date = :date AND type = :type AND source = :source';
322 363
 		$sth_check = $Connection->db->prepare($query_check);
@@ -331,7 +372,9 @@  discard block
 block discarded – undo
331 372
 					return $value === "" ? NULL : $value;
332 373
 				}, $cr);
333 374
 				if ($cr['date'] != '' && $cr['registration'] != null && $cr['registration'] != '' && $cr['registration'] != '?' && $cr['registration'] != '-' && strtolower($cr['registration']) != 'unknown' && $cr['date'] < time() && !preg_match('/\s/',$cr['registration'])) {
334
-					if (strpos($cr['registration'],'-') === FALSE) $cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']);
375
+					if (strpos($cr['registration'],'-') === FALSE) {
376
+						$cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']);
377
+					}
335 378
 					$query_check_values = array(':registration' => $cr['registration'],':date' => date('Y-m-d',$cr['date']),':type' => $cr['type'],':source' => $cr['source']);
336 379
 					$sth_check->execute($query_check_values);
337 380
 					$result_check = $sth_check->fetchAll(PDO::FETCH_ASSOC);
@@ -342,13 +385,19 @@  discard block
 block discarded – undo
342 385
 							if ($globalAircraftImageFetch) {
343 386
 								$imgchk = $Image->getSpotterImage($cr['registration']);
344 387
 								if (empty($imgchk)) {
345
-									if ($globalDebug) echo "\t".'Get image for '.$cr['registration'].'...';
388
+									if ($globalDebug) {
389
+										echo "\t".'Get image for '.$cr['registration'].'...';
390
+									}
346 391
 									$Image->addSpotterImage($cr['registration']);
347
-									if ($globalDebug) echo "\t".'Done'."\n";
392
+									if ($globalDebug) {
393
+										echo "\t".'Done'."\n";
394
+									}
348 395
 								}
349 396
 								// elseif ($globalDebug) echo 'Image already in DB'."\n";
350 397
 							}
351
-							if ($cr['title'] == '') $cr['title'] = $cr['registration'].' '.$cr['type'];
398
+							if ($cr['title'] == '') {
399
+								$cr['title'] = $cr['registration'].' '.$cr['type'];
400
+							}
352 401
 							$Spotter->setHighlightFlightByRegistration($cr['registration'],$cr['title'],date('Y-m-d',$cr['date']));
353 402
 						}
354 403
 					}
@@ -358,9 +407,13 @@  discard block
 block discarded – undo
358 407
 					$Connection->db->beginTransaction();
359 408
 				}
360 409
 			}
361
-			if ($globalTransaction) $Connection->db->commit();
410
+			if ($globalTransaction) {
411
+				$Connection->db->commit();
412
+			}
362 413
 		} catch(PDOException $e) {
363
-			if ($globalTransaction) $Connection->db->rollBack();
414
+			if ($globalTransaction) {
415
+				$Connection->db->rollBack();
416
+			}
364 417
 			echo $e->getMessage();
365 418
 		}
366 419
 		$sth_check->closeCursor();
@@ -403,8 +456,11 @@  discard block
 block discarded – undo
403 456
 			return "error : ".$e->getMessage();
404 457
 		}
405 458
 		$row = $sth->fetch(PDO::FETCH_ASSOC);
406
-		if ($row['nb'] > 0) return false;
407
-		else return true;
459
+		if ($row['nb'] > 0) {
460
+			return false;
461
+		} else {
462
+			return true;
463
+		}
408 464
 	}
409 465
 
410 466
     /**
Please login to merge, or discard this patch.
require/class.ACARS.php 3 patches
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -32,11 +32,11 @@  discard block
 block discarded – undo
32 32
 	}
33 33
 
34 34
 	/**
35
-	* Change IATA to ICAO value for ident
36
-	*
37
-	* @param String $ident ident
38
-	* @return String the icao
39
-	*/
35
+	 * Change IATA to ICAO value for ident
36
+	 *
37
+	 * @param String $ident ident
38
+	 * @return String the icao
39
+	 */
40 40
 	public function ident2icao($ident) {
41 41
 		if (substr($ident,0,2) == 'AF') {
42 42
 			if (filter_var(substr($ident,2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $ident;
@@ -52,11 +52,11 @@  discard block
 block discarded – undo
52 52
 	}
53 53
 
54 54
 	/**
55
-	* Deletes all info in the live table
56
-	*
57
-	* @return String success or false
58
-	*
59
-	*/
55
+	 * Deletes all info in the live table
56
+	 *
57
+	 * @return String success or false
58
+	 *
59
+	 */
60 60
 	public function deleteLiveAcarsData()
61 61
 	{
62 62
 		global $globalDBdriver;
@@ -76,11 +76,11 @@  discard block
 block discarded – undo
76 76
 	}
77 77
 
78 78
 	/**
79
-	* Deletes all info in the archive table
80
-	*
81
-	* @return String success or false
82
-	*
83
-	*/
79
+	 * Deletes all info in the archive table
80
+	 *
81
+	 * @return String success or false
82
+	 *
83
+	 */
84 84
 	public function deleteArchiveAcarsData()
85 85
 	{
86 86
 		global $globalACARSArchiveKeepMonths, $globalDBdriver;
@@ -100,13 +100,13 @@  discard block
 block discarded – undo
100 100
 	}
101 101
 
102 102
 
103
-    /**
104
-     * Parse ACARS data
105
-     *
106
-     * @param String ACARS data in acarsdec data
107
-     *
108
-     * @return array
109
-     */
103
+	/**
104
+	 * Parse ACARS data
105
+	 *
106
+	 * @param String ACARS data in acarsdec data
107
+	 *
108
+	 * @return array
109
+	 */
110 110
 	public function parse($data) {
111 111
 		global $globalDebug;
112 112
 		//$Image = new Image($this->db);
@@ -736,11 +736,11 @@  discard block
 block discarded – undo
736 736
 	}
737 737
 
738 738
 	/**
739
-	* Add ACARS data
740
-	*
741
-	* @param String ACARS data in acarsdec data
742
-	*
743
-	*/
739
+	 * Add ACARS data
740
+	 *
741
+	 * @param String ACARS data in acarsdec data
742
+	 *
743
+	 */
744 744
 	public function add($data,$message = array()) {
745 745
 		global $globalDebug, $globalACARSArchive;
746 746
 		$Image = new Image($this->db);
@@ -787,18 +787,18 @@  discard block
 block discarded – undo
787 787
 		}
788 788
 	}
789 789
 
790
-    /**
791
-     * Add Live ACARS data in DB
792
-     *
793
-     * @param String $ident ident
794
-     * @param String $registration Registration of the aircraft
795
-     * @param String $label Label of the ACARS message
796
-     * @param String $block_id Block id of the ACARS message
797
-     * @param String $msg_no Number of the ACARS message
798
-     * @param String $message ACARS message
799
-     * @param string $decode
800
-     * @return bool
801
-     */
790
+	/**
791
+	 * Add Live ACARS data in DB
792
+	 *
793
+	 * @param String $ident ident
794
+	 * @param String $registration Registration of the aircraft
795
+	 * @param String $label Label of the ACARS message
796
+	 * @param String $block_id Block id of the ACARS message
797
+	 * @param String $msg_no Number of the ACARS message
798
+	 * @param String $message ACARS message
799
+	 * @param string $decode
800
+	 * @return bool
801
+	 */
802 802
 	public function addLiveAcarsData($ident,$registration,$label,$block_id,$msg_no,$message,$decode = '') {
803 803
 		global $globalDebug;
804 804
 		date_default_timezone_set('UTC');
@@ -836,18 +836,18 @@  discard block
 block discarded – undo
836 836
 		return false;
837 837
 	}
838 838
 
839
-    /**
840
-     * Add Archive ACARS data in DB
841
-     *
842
-     * @param String $ident ident
843
-     * @param String $registration Registration of the aircraft
844
-     * @param String $label Label of the ACARS message
845
-     * @param String $block_id Block id of the ACARS message
846
-     * @param String $msg_no Number of the ACARS message
847
-     * @param String $message ACARS message
848
-     * @param string $decode
849
-     * @return string
850
-     */
839
+	/**
840
+	 * Add Archive ACARS data in DB
841
+	 *
842
+	 * @param String $ident ident
843
+	 * @param String $registration Registration of the aircraft
844
+	 * @param String $label Label of the ACARS message
845
+	 * @param String $block_id Block id of the ACARS message
846
+	 * @param String $msg_no Number of the ACARS message
847
+	 * @param String $message ACARS message
848
+	 * @param string $decode
849
+	 * @return string
850
+	 */
851 851
 	public function addArchiveAcarsData($ident,$registration,$label,$block_id,$msg_no,$message,$decode = '') {
852 852
 		global $globalDebug;
853 853
 		date_default_timezone_set('UTC');
@@ -879,11 +879,11 @@  discard block
 block discarded – undo
879 879
 	}
880 880
 
881 881
 	/**
882
-	* Get Message title from label from DB
883
-	*
884
-	* @param String $label
885
-	* @return String Return ACARS title
886
-	*/
882
+	 * Get Message title from label from DB
883
+	 *
884
+	 * @param String $label
885
+	 * @return String Return ACARS title
886
+	 */
887 887
 	public function getTitlefromLabel($label) {
888 888
 		$Connection = new Connection($this->db);
889 889
 		$this->db = $Connection->db;
@@ -902,10 +902,10 @@  discard block
 block discarded – undo
902 902
 	}
903 903
 
904 904
 	/**
905
-	* List all Message title & label from DB
906
-	*
907
-	* @return array Return ACARS data in array
908
-	*/
905
+	 * List all Message title & label from DB
906
+	 *
907
+	 * @return array Return ACARS data in array
908
+	 */
909 909
 	public function getAllTitleLabel() {
910 910
 		$query = "SELECT * FROM acars_label ORDER BY title";
911 911
 		$query_values = array();
@@ -922,11 +922,11 @@  discard block
 block discarded – undo
922 922
 	}
923 923
 
924 924
 	/**
925
-	* Get Live ACARS data from DB
926
-	*
927
-	* @param String $ident
928
-	* @return array Return ACARS data in array
929
-	*/
925
+	 * Get Live ACARS data from DB
926
+	 *
927
+	 * @param String $ident
928
+	 * @return array Return ACARS data in array
929
+	 */
930 930
 	public function getLiveAcarsData($ident) {
931 931
 		$query = "SELECT * FROM acars_live WHERE ident = :ident ORDER BY acars_live_id DESC";
932 932
 		$query_values = array(':ident' => $ident);
@@ -942,13 +942,13 @@  discard block
 block discarded – undo
942 942
 		else return array();
943 943
 	}
944 944
 
945
-    /**
946
-     * Get Latest ACARS data from DB
947
-     *
948
-     * @param string $limit
949
-     * @param string $label
950
-     * @return array Return ACARS data in array
951
-     */
945
+	/**
946
+	 * Get Latest ACARS data from DB
947
+	 *
948
+	 * @param string $limit
949
+	 * @param string $label
950
+	 * @return array Return ACARS data in array
951
+	 */
952 952
 	public function getLatestAcarsData($limit = '',$label = '') {
953 953
 		global $globalURL;
954 954
 		$Image = new Image($this->db);
@@ -1036,13 +1036,13 @@  discard block
 block discarded – undo
1036 1036
 		else return array();
1037 1037
 	}
1038 1038
 
1039
-    /**
1040
-     * Get Archive ACARS data from DB
1041
-     *
1042
-     * @param string $limit
1043
-     * @param string $label
1044
-     * @return array Return ACARS data in array
1045
-     */
1039
+	/**
1040
+	 * Get Archive ACARS data from DB
1041
+	 *
1042
+	 * @param string $limit
1043
+	 * @param string $label
1044
+	 * @return array Return ACARS data in array
1045
+	 */
1046 1046
 	public function getArchiveAcarsData($limit = '',$label = '') {
1047 1047
 		global $globalURL;
1048 1048
 		$Image = new Image($this->db);
@@ -1131,17 +1131,17 @@  discard block
 block discarded – undo
1131 1131
 		} else return array();
1132 1132
 	}
1133 1133
 
1134
-    /**
1135
-     * Add ModeS data to DB
1136
-     *
1137
-     * @param String $ident ident
1138
-     * @param String $registration Registration of the aircraft
1139
-     * @param String $icao
1140
-     * @param String $ICAOTypeCode
1141
-     * @param string $latitude
1142
-     * @param string $longitude
1143
-     * @return string
1144
-     */
1134
+	/**
1135
+	 * Add ModeS data to DB
1136
+	 *
1137
+	 * @param String $ident ident
1138
+	 * @param String $registration Registration of the aircraft
1139
+	 * @param String $icao
1140
+	 * @param String $ICAOTypeCode
1141
+	 * @param string $latitude
1142
+	 * @param string $longitude
1143
+	 * @return string
1144
+	 */
1145 1145
 	public function addModeSData($ident,$registration,$icao = '',$ICAOTypeCode = '',$latitude = '', $longitude = '') {
1146 1146
 		global $globalDebug, $globalDBdriver;
1147 1147
 		$ident = trim($ident);
Please login to merge, or discard this patch.
Spacing   +258 added lines, -258 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	/*
22 22
 	 * Initialize DB connection
23 23
 	*/
24
-	public function __construct($dbc = null,$fromACARSscript = false) {
24
+	public function __construct($dbc = null, $fromACARSscript = false) {
25 25
 		$Connection = new Connection($dbc);
26 26
 		$this->db = $Connection->db();
27 27
 		if ($this->db === null) die('Error: No DB connection. (ACARS)');
@@ -38,14 +38,14 @@  discard block
 block discarded – undo
38 38
 	* @return String the icao
39 39
 	*/
40 40
 	public function ident2icao($ident) {
41
-		if (substr($ident,0,2) == 'AF') {
42
-			if (filter_var(substr($ident,2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $ident;
43
-			else $icao = 'AFR'.ltrim(substr($ident,2),'0');
41
+		if (substr($ident, 0, 2) == 'AF') {
42
+			if (filter_var(substr($ident, 2), FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $ident;
43
+			else $icao = 'AFR'.ltrim(substr($ident, 2), '0');
44 44
 		} else {
45 45
 			$Spotter = new Spotter($this->db);
46
-			$identicao = $Spotter->getAllAirlineInfo(substr($ident,0,2));
46
+			$identicao = $Spotter->getAllAirlineInfo(substr($ident, 0, 2));
47 47
 			if (isset($identicao[0])) {
48
-				$icao = $identicao[0]['icao'].ltrim(substr($ident,2),'0');
48
+				$icao = $identicao[0]['icao'].ltrim(substr($ident, 2), '0');
49 49
 			} else $icao = $ident;
50 50
 		}
51 51
 		return $icao;
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 
70 70
 			$sth = $this->db->prepare($query);
71 71
 			$sth->execute();
72
-		} catch(PDOException $e) {
72
+		} catch (PDOException $e) {
73 73
 			return "error";
74 74
 		}
75 75
 		return "success";
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 
94 94
 			$sth = $this->db->prepare($query);
95 95
 			$sth->execute();
96
-		} catch(PDOException $e) {
96
+		} catch (PDOException $e) {
97 97
 			return "error";
98 98
 		}
99 99
 		return "success";
@@ -119,13 +119,13 @@  discard block
 block discarded – undo
119 119
 		$ident = '';
120 120
 		$message = '';
121 121
 		$result = array();
122
-		$n = sscanf($data,'%*[0-9a-z.] %*d %*02d/%*02d/%*04d %*02d:%*02d:%*02d %*d %*[0-9-] %*[A-Z0-9] %7s %*c %2[0-9a-zA-Z_] %d %4[0-9A-Z] %6[0-9A-Z] %[^\r\n]',$registration,$label,$block_id,$msg_no,$ident,$message);
123
-		if ($n == 0) $n = sscanf($data,'AC%*c %7s %*c %2[0-9a-zA-Z_] %d %4[0-9A-Z] %6[0-9A-Z] %[^\r\n]',$registration,$label,$block_id,$msg_no,$ident,$message);
124
-		if ($n == 0) $n = sscanf($data,'%*04d-%*02d-%*02d,%*02d:%*02d:%*02d,%*7s,%*c,%6[0-9A-Z-],%*c,%2[0-9a-zA-Z_],%d,%4[0-9A-Z],%6[0-9A-Z],%[^\r\n]',$registration,$label,$block_id,$msg_no,$ident,$message);
125
-		if ($n == 0) $n = sscanf($data,'%*04d-%*02d-%*02d,%*02d:%*02d:%*02d,%*7s,%*c,%5[0-9A-Z],%*c,%2[0-9a-zA-Z_],%d,%4[0-9A-Z],%6[0-9A-Z],%[^\r\n]',$registration,$label,$block_id,$msg_no,$ident,$message);
122
+		$n = sscanf($data, '%*[0-9a-z.] %*d %*02d/%*02d/%*04d %*02d:%*02d:%*02d %*d %*[0-9-] %*[A-Z0-9] %7s %*c %2[0-9a-zA-Z_] %d %4[0-9A-Z] %6[0-9A-Z] %[^\r\n]', $registration, $label, $block_id, $msg_no, $ident, $message);
123
+		if ($n == 0) $n = sscanf($data, 'AC%*c %7s %*c %2[0-9a-zA-Z_] %d %4[0-9A-Z] %6[0-9A-Z] %[^\r\n]', $registration, $label, $block_id, $msg_no, $ident, $message);
124
+		if ($n == 0) $n = sscanf($data, '%*04d-%*02d-%*02d,%*02d:%*02d:%*02d,%*7s,%*c,%6[0-9A-Z-],%*c,%2[0-9a-zA-Z_],%d,%4[0-9A-Z],%6[0-9A-Z],%[^\r\n]', $registration, $label, $block_id, $msg_no, $ident, $message);
125
+		if ($n == 0) $n = sscanf($data, '%*04d-%*02d-%*02d,%*02d:%*02d:%*02d,%*7s,%*c,%5[0-9A-Z],%*c,%2[0-9a-zA-Z_],%d,%4[0-9A-Z],%6[0-9A-Z],%[^\r\n]', $registration, $label, $block_id, $msg_no, $ident, $message);
126 126
 		if ($n != 0 && ($registration != '' || $ident != '' || $label != '' || $block_id != '' || $msg_no != '')) {
127
-			$registration = str_replace('.','',$registration);
128
-			$result = array('registration' => $registration, 'ident' => $ident,'label' => $label, 'block_id' => $block_id,'msg_no' => $msg_no,'message' => $message);
127
+			$registration = str_replace('.', '', $registration);
128
+			$result = array('registration' => $registration, 'ident' => $ident, 'label' => $label, 'block_id' => $block_id, 'msg_no' => $msg_no, 'message' => $message);
129 129
 			if ($globalDebug) echo "Reg. : ".$registration." - Ident : ".$ident." - Label : ".$label." - Message : ".$message."\n";
130 130
 		} else $message = $data;
131 131
 		$decode = array();
@@ -145,14 +145,14 @@  discard block
 block discarded – undo
145 145
 				$temp = '';
146 146
 				$n = sscanf($message, "FST01%4c%4c%c%06d%c%07d%03d%*8[0-9a-zA-Z ]-%02dC", $dair, $darr, $lac, $la, $lnc, $ln, $alt, $temp);
147 147
 				if ($n > 5 && ($lac == 'N' || $lac == 'S') && ($lnc == 'E' || $lnc == 'W')) {
148
-					$latitude = $la / 10000.0;
149
-					$longitude = $ln / 10000.0;
148
+					$latitude = $la/10000.0;
149
+					$longitude = $ln/10000.0;
150 150
 					if ($lac == 'S') $latitude = '-'.$latitude;
151 151
 					if ($lnc == 'W') $longitude = '-'.$longitude;
152 152
 					// Temp not always available
153 153
 					if ($globalDebug) echo 'latitude : '.$latitude.' - longitude : '.$longitude.' - airport depart : '.$dair.' - airport arrival : '.$darr.' - température : '.$temp."°C\n";
154
-					if ($temp == '') $decode = array('Latitude' => $latitude, 'Longitude' =>  $longitude, 'Departure airport' => $dair, 'Arrival airport' => $darr,'Altitude' => $alt);
155
-					else $decode = array('Latitude' => $latitude, 'Longitude' =>  $longitude, 'Departure airport' => $dair, 'Arrival airport' => $darr, 'Altitude' => 'FL'.$alt,'Temperature' => $temp.'°C');
154
+					if ($temp == '') $decode = array('Latitude' => $latitude, 'Longitude' =>  $longitude, 'Departure airport' => $dair, 'Arrival airport' => $darr, 'Altitude' => $alt);
155
+					else $decode = array('Latitude' => $latitude, 'Longitude' =>  $longitude, 'Departure airport' => $dair, 'Arrival airport' => $darr, 'Altitude' => 'FL'.$alt, 'Temperature' => $temp.'°C');
156 156
 
157 157
 					//$icao = $Translation->checkTranslation($ident);
158 158
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
@@ -164,19 +164,19 @@  discard block
 block discarded – undo
164 164
 				$dhour = '';
165 165
 				$darr = '';
166 166
 				$ahour = '';
167
-				$n = sscanf($message, "ARR01 %4[A-Z]%4d %4[A-Z]%4d", $dair, $dhour, $darr,$ahour);
167
+				$n = sscanf($message, "ARR01 %4[A-Z]%4d %4[A-Z]%4d", $dair, $dhour, $darr, $ahour);
168 168
 				if ($n == 4 && strlen($darr) == 4) {
169
-					if ($dhour != '') $dhour = substr(sprintf('%04d',$dhour),0,2).':'.substr(sprintf('%04d',$dhour),2);
170
-					if ($ahour != '') $ahour = substr(sprintf('%04d',$ahour),0,2).':'.substr(sprintf('%04d',$ahour),2);
171
-					if ($globalDebug) echo 'departure airport : '.$dair.' - arrival airport : '. $darr.' - departure hour : '. $dhour.' - arrival hour : '.$ahour."\n";
169
+					if ($dhour != '') $dhour = substr(sprintf('%04d', $dhour), 0, 2).':'.substr(sprintf('%04d', $dhour), 2);
170
+					if ($ahour != '') $ahour = substr(sprintf('%04d', $ahour), 0, 2).':'.substr(sprintf('%04d', $ahour), 2);
171
+					if ($globalDebug) echo 'departure airport : '.$dair.' - arrival airport : '.$darr.' - departure hour : '.$dhour.' - arrival hour : '.$ahour."\n";
172 172
 					//$icao = ACARS->ident2icao($ident);
173 173
 					//$icao = $Translation->checkTranslation($ident);
174 174
 					//$Schedule->addSchedule($icao,$dair,$dhour,$darr,$ahour,'ACARS');
175 175
 					$decode = array('Departure airport' => $dair, 'Departure hour' => $dhour, 'Arrival airport' => $darr, 'Arrival hour' => $ahour);
176 176
 					$found = true;
177 177
 				}
178
-				elseif ($n == 2 || $n  == 4) {
179
-					if ($dhour != '') $dhour = substr(sprintf('%04d',$dhour),0,2).':'.substr(sprintf('%04d',$dhour),2);
178
+				elseif ($n == 2 || $n == 4) {
179
+					if ($dhour != '') $dhour = substr(sprintf('%04d', $dhour), 0, 2).':'.substr(sprintf('%04d', $dhour), 2);
180 180
 					if ($globalDebug) echo 'airport arrival : '.$dair.' - arrival hour : '.$dhour."\n";
181 181
 					//$icao = ACARS->ident2icao($ident);
182 182
 					//$icao = $Translation->checkTranslation($ident);
@@ -234,11 +234,11 @@  discard block
 block discarded – undo
234 234
 				$ahour = '';
235 235
 				$aair = '';
236 236
 				$apiste = '';
237
-				$n = sscanf(str_replace(array("\r\n", "\n", "\r"),'',$message), "%*[0-9A-Z]/%*3d/%4s/%*cSCH/%6[0-9A-Z ]/%4c/%4c/%5s/%4d%*3c/%4d/%4c/%[0-9A-Z ]/", $airicao,$aident,$dair, $darr, $ddate, $dhour,$ahour, $aair, $apiste);
237
+				$n = sscanf(str_replace(array("\r\n", "\n", "\r"), '', $message), "%*[0-9A-Z]/%*3d/%4s/%*cSCH/%6[0-9A-Z ]/%4c/%4c/%5s/%4d%*3c/%4d/%4c/%[0-9A-Z ]/", $airicao, $aident, $dair, $darr, $ddate, $dhour, $ahour, $aair, $apiste);
238 238
 				if ($n > 8) {
239
-					if ($globalDebug) echo 'airicao : '. $airicao.' - ident : '.$aident.' - departure airport : '.$dair.' - arrival airport : '. $darr.' - date depart : '.$ddate.' - departure hour : '. $dhour.' - arrival hour : '.$ahour.' - arrival airport : '.$aair.' - arrival piste : '.$apiste."\n";
240
-					if ($dhour != '') $dhour = substr(sprintf('%04d',$dhour),0,2).':'.substr(sprintf('%04d',$dhour),2);
241
-					if ($ahour != '') $ahour = substr(sprintf('%04d',$ahour),0,2).':'.substr(sprintf('%04d',$ahour),2);
239
+					if ($globalDebug) echo 'airicao : '.$airicao.' - ident : '.$aident.' - departure airport : '.$dair.' - arrival airport : '.$darr.' - date depart : '.$ddate.' - departure hour : '.$dhour.' - arrival hour : '.$ahour.' - arrival airport : '.$aair.' - arrival piste : '.$apiste."\n";
240
+					if ($dhour != '') $dhour = substr(sprintf('%04d', $dhour), 0, 2).':'.substr(sprintf('%04d', $dhour), 2);
241
+					if ($ahour != '') $ahour = substr(sprintf('%04d', $ahour), 0, 2).':'.substr(sprintf('%04d', $ahour), 2);
242 242
 					$icao = trim($aident);
243 243
 
244 244
 					//$decode = 'Departure airport : '.$dair.' ('.$ddate.' at '.$dhour.') - Arrival Airport : '.$aair.' (at '.$ahour.') way '.$apiste;
@@ -263,8 +263,8 @@  discard block
 block discarded – undo
263 263
 				if ($n == 10 && ($lac == 'N' || $lac == 'S') && ($lnc == 'E' || $lnc == 'W')) {
264 264
 					$las = $las.'.'.$lass;
265 265
 					$lns = $lns.'.'.$lns;
266
-					$latitude = $las / 1000.0;
267
-					$longitude = $lns / 1000.0;
266
+					$latitude = $las/1000.0;
267
+					$longitude = $lns/1000.0;
268 268
 					if ($lac == 'S') $latitude = '-'.$latitude;
269 269
 					if ($lnc == 'W') $longitude = '-'.$longitude;
270 270
 					if ($globalDebug) echo 'latitude : '.$latitude.' - longitude : '.$longitude."\n";
@@ -359,17 +359,17 @@  discard block
 block discarded – undo
359 359
 				$alt = '';
360 360
 				$fuel = '';
361 361
 				$speed = '';
362
-				$n = sscanf(str_replace(array("\r\n", "\n", "\r"),'',$message), "#DFB(POS-%s -%4d%c%5d%c/%*d F%dRMK/FUEL %f M%f", $aident, $las, $lac, $lns, $lnc, $alt, $fuel, $speed);
362
+				$n = sscanf(str_replace(array("\r\n", "\n", "\r"), '', $message), "#DFB(POS-%s -%4d%c%5d%c/%*d F%dRMK/FUEL %f M%f", $aident, $las, $lac, $lns, $lnc, $alt, $fuel, $speed);
363 363
 				if ($n == 9) {
364 364
 					//if (self->$debug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
365 365
 					$icao = trim($aident);
366 366
 					$decode['icao'] = $icao;
367
-					$latitude = $las / 100.0;
368
-					$longitude = $lns / 100.0;
367
+					$latitude = $las/100.0;
368
+					$longitude = $lns/100.0;
369 369
 					if ($lac == 'S') $latitude = '-'.$latitude;
370 370
 					if ($lnc == 'W') $longitude = '-'.$longitude;
371 371
 
372
-					$decode = array('Latitude' => $latitude,'Longitude' => $longitude,'Altitude' => 'FL'.$alt,'Fuel' => $fuel,'speed' => $speed);
372
+					$decode = array('Latitude' => $latitude, 'Longitude' => $longitude, 'Altitude' => 'FL'.$alt, 'Fuel' => $fuel, 'speed' => $speed);
373 373
 					$found = true;
374 374
 				}
375 375
 			}
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
 					if ($lac == 'S') $latitude = '-'.$latitude;
389 389
 					if ($lnc == 'W') $longitude = '-'.$longitude;
390 390
 
391
-					$decode = array('Latitude' => $latitude,'Longitude' => $longitude);
391
+					$decode = array('Latitude' => $latitude, 'Longitude' => $longitude);
392 392
 					$found = true;
393 393
 				}
394 394
 			}
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
 				$dair = '';
422 422
 				$darr = '';
423 423
 				$aident = '';
424
-				$n = sscanf(str_replace(array("\r\n", "\n", "\r"),'',$message), "%*[0-9A-Z],,%*[0-9A-Z],%*[0-9A-Z],%4s,%4s,.%*6s,%*4[A-Z],%[0-9A-Z],", $dair, $darr, $aident);
424
+				$n = sscanf(str_replace(array("\r\n", "\n", "\r"), '', $message), "%*[0-9A-Z],,%*[0-9A-Z],%*[0-9A-Z],%4s,%4s,.%*6s,%*4[A-Z],%[0-9A-Z],", $dair, $darr, $aident);
425 425
 				if ($n == 8) {
426 426
 					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
427 427
 					$icao = trim($aident);
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
 				*/
454 454
 				$dair = '';
455 455
 				$darr = '';
456
-				$n = sscanf($message,'%4[A-Z]%4[A-Z]%*4d',$dair,$darr);
456
+				$n = sscanf($message, '%4[A-Z]%4[A-Z]%*4d', $dair, $darr);
457 457
 				if ($n == 3) {
458 458
 					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
459 459
 					//$icao = $Translation->checkTranslation($ident);
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
 				*/
469 469
 				$dair = '';
470 470
 				$darr = '';
471
-				$n = sscanf($message,'3J01 DSPTCH %*d/%*d %4s/%4s .%*6s',$dair,$darr);
471
+				$n = sscanf($message, '3J01 DSPTCH %*d/%*d %4s/%4s .%*6s', $dair, $darr);
472 472
 				if ($n == 3) {
473 473
 					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
474 474
 					//$icao = $Translation->checkTranslation($ident);
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
 				}
479 479
 			}
480 480
 			if (!$found) {
481
-				$n = sscanf($message,'MET01%4c',$airport);
481
+				$n = sscanf($message, 'MET01%4c', $airport);
482 482
 				if ($n == 1) {
483 483
 					if ($globalDebug) echo 'airport name : '.$airport;
484 484
 					$decode = array('Airport/Waypoint name' => $airport);
@@ -486,241 +486,241 @@  discard block
 block discarded – undo
486 486
 				}
487 487
 			}
488 488
 			if ($label == 'H1') {
489
-				if (preg_match('/^#CFBFLR/',$message) || preg_match('/^#CFBWRN/',$message)) {
490
-					$decode = array_merge(array('Message nature' => 'Equipment failure'),$decode);
489
+				if (preg_match('/^#CFBFLR/', $message) || preg_match('/^#CFBWRN/', $message)) {
490
+					$decode = array_merge(array('Message nature' => 'Equipment failure'), $decode);
491 491
 				}
492
-				elseif (preg_match('/^#DFB\*TKO/',$message) || preg_match('/^#DFBTKO/',$message)) {
493
-					$decode = array_merge(array('Message nature' => 'Take off performance data'),$decode);
492
+				elseif (preg_match('/^#DFB\*TKO/', $message) || preg_match('/^#DFBTKO/', $message)) {
493
+					$decode = array_merge(array('Message nature' => 'Take off performance data'), $decode);
494 494
 				}
495
-				elseif (preg_match('/^#DFB\*CRZ/',$message) || preg_match('/^#DFBCRZ/',$message)) {
496
-					$decode = array_merge(array('Message nature' => 'Cruise performance data'),$decode);
495
+				elseif (preg_match('/^#DFB\*CRZ/', $message) || preg_match('/^#DFBCRZ/', $message)) {
496
+					$decode = array_merge(array('Message nature' => 'Cruise performance data'), $decode);
497 497
 				}
498
-				elseif (preg_match('/^#DFB\*WOB/',$message) || preg_match('/^#DFBWOB/',$message)) {
499
-					$decode = array_merge(array('Message nature' => 'Weather observation'),$decode);
498
+				elseif (preg_match('/^#DFB\*WOB/', $message) || preg_match('/^#DFBWOB/', $message)) {
499
+					$decode = array_merge(array('Message nature' => 'Weather observation'), $decode);
500 500
 				}
501
-				elseif (preg_match(':^#DFB/PIREP:',$message)) {
502
-					$decode = array_merge(array('Message nature' => 'Pilot Report'),$decode);
501
+				elseif (preg_match(':^#DFB/PIREP:', $message)) {
502
+					$decode = array_merge(array('Message nature' => 'Pilot Report'), $decode);
503 503
 				}
504
-				elseif (preg_match('/^#DFBEDA/',$message) || preg_match('/^#DFBENG/',$message)) {
505
-					$decode = array_merge(array('Message nature' => 'Engine Data'),$decode);
504
+				elseif (preg_match('/^#DFBEDA/', $message) || preg_match('/^#DFBENG/', $message)) {
505
+					$decode = array_merge(array('Message nature' => 'Engine Data'), $decode);
506 506
 				}
507
-				elseif (preg_match(':^#M1AAEP:',$message)) {
508
-					$decode = array_merge(array('Message nature' => 'Position/Weather Report'),$decode);
507
+				elseif (preg_match(':^#M1AAEP:', $message)) {
508
+					$decode = array_merge(array('Message nature' => 'Position/Weather Report'), $decode);
509 509
 				}
510
-				elseif (preg_match(':^#M2APWD:',$message)) {
511
-					$decode = array_merge(array('Message nature' => 'Flight plan predicted wind data'),$decode);
510
+				elseif (preg_match(':^#M2APWD:', $message)) {
511
+					$decode = array_merge(array('Message nature' => 'Flight plan predicted wind data'), $decode);
512 512
 				}
513
-				elseif (preg_match(':^#M1BREQPWI:',$message)) {
514
-					$decode = array_merge(array('Message nature' => 'Predicted wind info request'),$decode);
513
+				elseif (preg_match(':^#M1BREQPWI:', $message)) {
514
+					$decode = array_merge(array('Message nature' => 'Predicted wind info request'), $decode);
515 515
 				}
516
-				elseif (preg_match(':^#CF:',$message)) {
517
-					$decode = array_merge(array('Message nature' => 'Central Fault Display'),$decode);
516
+				elseif (preg_match(':^#CF:', $message)) {
517
+					$decode = array_merge(array('Message nature' => 'Central Fault Display'), $decode);
518 518
 				}
519
-				elseif (preg_match(':^#DF:',$message)) {
520
-					$decode = array_merge(array('Message nature' => 'Digital Flight Data Acquisition Unit'),$decode);
519
+				elseif (preg_match(':^#DF:', $message)) {
520
+					$decode = array_merge(array('Message nature' => 'Digital Flight Data Acquisition Unit'), $decode);
521 521
 				}
522
-				elseif (preg_match(':^#EC:',$message)) {
523
-					$decode = array_merge(array('Message nature' => 'Engine Display System'),$decode);
522
+				elseif (preg_match(':^#EC:', $message)) {
523
+					$decode = array_merge(array('Message nature' => 'Engine Display System'), $decode);
524 524
 				}
525
-				elseif (preg_match(':^#EI:',$message)) {
526
-					$decode = array_merge(array('Message nature' => 'Engine Report'),$decode);
525
+				elseif (preg_match(':^#EI:', $message)) {
526
+					$decode = array_merge(array('Message nature' => 'Engine Report'), $decode);
527 527
 				}
528
-				elseif (preg_match(':^#H1:',$message)) {
529
-					$decode = array_merge(array('Message nature' => 'HF Data Radio - Left'),$decode);
528
+				elseif (preg_match(':^#H1:', $message)) {
529
+					$decode = array_merge(array('Message nature' => 'HF Data Radio - Left'), $decode);
530 530
 				}
531
-				elseif (preg_match(':^#H2:',$message)) {
532
-					$decode = array_merge(array('Message nature' => 'HF Data Radio - Right'),$decode);
531
+				elseif (preg_match(':^#H2:', $message)) {
532
+					$decode = array_merge(array('Message nature' => 'HF Data Radio - Right'), $decode);
533 533
 				}
534
-				elseif (preg_match(':^#HD:',$message)) {
535
-					$decode = array_merge(array('Message nature' => 'HF Data Radio - Selected'),$decode);
534
+				elseif (preg_match(':^#HD:', $message)) {
535
+					$decode = array_merge(array('Message nature' => 'HF Data Radio - Selected'), $decode);
536 536
 				}
537
-				elseif (preg_match(':^#M1:',$message)) {
538
-					$decode = array_merge(array('Message nature' => 'Flight Management Computer - Left'),$decode);
537
+				elseif (preg_match(':^#M1:', $message)) {
538
+					$decode = array_merge(array('Message nature' => 'Flight Management Computer - Left'), $decode);
539 539
 				}
540
-				elseif (preg_match(':^#M2:',$message)) {
541
-					$decode = array_merge(array('Message nature' => 'Flight Management Computer - Right'),$decode);
540
+				elseif (preg_match(':^#M2:', $message)) {
541
+					$decode = array_merge(array('Message nature' => 'Flight Management Computer - Right'), $decode);
542 542
 				}
543
-				elseif (preg_match(':^#M3:',$message)) {
544
-					$decode = array_merge(array('Message nature' => 'Flight Management Computer - Center'),$decode);
543
+				elseif (preg_match(':^#M3:', $message)) {
544
+					$decode = array_merge(array('Message nature' => 'Flight Management Computer - Center'), $decode);
545 545
 				}
546
-				elseif (preg_match(':^#MD:',$message)) {
547
-					$decode = array_merge(array('Message nature' => 'Flight Management Computer - Selected'),$decode);
546
+				elseif (preg_match(':^#MD:', $message)) {
547
+					$decode = array_merge(array('Message nature' => 'Flight Management Computer - Selected'), $decode);
548 548
 				}
549
-				elseif (preg_match(':^#PS:',$message)) {
550
-					$decode = array_merge(array('Message nature' => 'Keyboard/Display Unit'),$decode);
549
+				elseif (preg_match(':^#PS:', $message)) {
550
+					$decode = array_merge(array('Message nature' => 'Keyboard/Display Unit'), $decode);
551 551
 				}
552
-				elseif (preg_match(':^#S1:',$message)) {
553
-					$decode = array_merge(array('Message nature' => 'SDU - Left'),$decode);
552
+				elseif (preg_match(':^#S1:', $message)) {
553
+					$decode = array_merge(array('Message nature' => 'SDU - Left'), $decode);
554 554
 				}
555
-				elseif (preg_match(':^#S2:',$message)) {
556
-					$decode = array_merge(array('Message nature' => 'SDU - Right'),$decode);
555
+				elseif (preg_match(':^#S2:', $message)) {
556
+					$decode = array_merge(array('Message nature' => 'SDU - Right'), $decode);
557 557
 				}
558
-				elseif (preg_match(':^#SD:',$message)) {
559
-					$decode = array_merge(array('Message nature' => 'SDU - Selected'),$decode);
558
+				elseif (preg_match(':^#SD:', $message)) {
559
+					$decode = array_merge(array('Message nature' => 'SDU - Selected'), $decode);
560 560
 				}
561
-				elseif (preg_match(':^#T[0-8]:',$message)) {
562
-					$decode = array_merge(array('Message nature' => 'Cabin Terminal Messages'),$decode);
561
+				elseif (preg_match(':^#T[0-8]:', $message)) {
562
+					$decode = array_merge(array('Message nature' => 'Cabin Terminal Messages'), $decode);
563 563
 				}
564
-				elseif (preg_match(':^#WO:',$message)) {
565
-					$decode = array_merge(array('Message nature' => 'Weather Observation Report'),$decode);
564
+				elseif (preg_match(':^#WO:', $message)) {
565
+					$decode = array_merge(array('Message nature' => 'Weather Observation Report'), $decode);
566 566
 				}
567
-				elseif (preg_match(':^#A1:',$message)) {
568
-					$decode = array_merge(array('Message nature' => 'Oceanic Clearance'),$decode);
567
+				elseif (preg_match(':^#A1:', $message)) {
568
+					$decode = array_merge(array('Message nature' => 'Oceanic Clearance'), $decode);
569 569
 				}
570
-				elseif (preg_match(':^#A3:',$message)) {
571
-					$decode = array_merge(array('Message nature' => 'Departure Clearance Response'),$decode);
570
+				elseif (preg_match(':^#A3:', $message)) {
571
+					$decode = array_merge(array('Message nature' => 'Departure Clearance Response'), $decode);
572 572
 				}
573
-				elseif (preg_match(':^#A4:',$message)) {
574
-					$decode = array_merge(array('Message nature' => 'Flight Systems Message'),$decode);
573
+				elseif (preg_match(':^#A4:', $message)) {
574
+					$decode = array_merge(array('Message nature' => 'Flight Systems Message'), $decode);
575 575
 				}
576
-				elseif (preg_match(':^#A6:',$message)) {
577
-					$decode = array_merge(array('Message nature' => 'Request ADS Reports'),$decode);
576
+				elseif (preg_match(':^#A6:', $message)) {
577
+					$decode = array_merge(array('Message nature' => 'Request ADS Reports'), $decode);
578 578
 				}
579
-				elseif (preg_match(':^#A8:',$message)) {
580
-					$decode = array_merge(array('Message nature' => 'Deliver Departure Slot'),$decode);
579
+				elseif (preg_match(':^#A8:', $message)) {
580
+					$decode = array_merge(array('Message nature' => 'Deliver Departure Slot'), $decode);
581 581
 				}
582
-				elseif (preg_match(':^#A9:',$message)) {
583
-					$decode = array_merge(array('Message nature' => 'ATIS report'),$decode);
582
+				elseif (preg_match(':^#A9:', $message)) {
583
+					$decode = array_merge(array('Message nature' => 'ATIS report'), $decode);
584 584
 				}
585
-				elseif (preg_match(':^#A0:',$message)) {
586
-					$decode = array_merge(array('Message nature' => 'ATIS Facility Notification (AFN)'),$decode);
585
+				elseif (preg_match(':^#A0:', $message)) {
586
+					$decode = array_merge(array('Message nature' => 'ATIS Facility Notification (AFN)'), $decode);
587 587
 				}
588
-				elseif (preg_match(':^#AA:',$message)) {
589
-					$decode = array_merge(array('Message nature' => 'ATCComm'),$decode);
588
+				elseif (preg_match(':^#AA:', $message)) {
589
+					$decode = array_merge(array('Message nature' => 'ATCComm'), $decode);
590 590
 				}
591
-				elseif (preg_match(':^#AB:',$message)) {
592
-					$decode = array_merge(array('Message nature' => 'TWIP Report'),$decode);
591
+				elseif (preg_match(':^#AB:', $message)) {
592
+					$decode = array_merge(array('Message nature' => 'TWIP Report'), $decode);
593 593
 				}
594
-				elseif (preg_match(':^#AC:',$message)) {
595
-					$decode = array_merge(array('Message nature' => 'Pushback Clearance'),$decode);
594
+				elseif (preg_match(':^#AC:', $message)) {
595
+					$decode = array_merge(array('Message nature' => 'Pushback Clearance'), $decode);
596 596
 				}
597
-				elseif (preg_match(':^#AD:',$message)) {
598
-					$decode = array_merge(array('Message nature' => 'Expected Taxi Clearance'),$decode);
597
+				elseif (preg_match(':^#AD:', $message)) {
598
+					$decode = array_merge(array('Message nature' => 'Expected Taxi Clearance'), $decode);
599 599
 				}
600
-				elseif (preg_match(':^#AF:',$message)) {
601
-					$decode = array_merge(array('Message nature' => 'CPC Command/Response'),$decode);
600
+				elseif (preg_match(':^#AF:', $message)) {
601
+					$decode = array_merge(array('Message nature' => 'CPC Command/Response'), $decode);
602 602
 				}
603
-				elseif (preg_match(':^#B1:',$message)) {
604
-					$decode = array_merge(array('Message nature' => 'Request Oceanic Clearance'),$decode);
603
+				elseif (preg_match(':^#B1:', $message)) {
604
+					$decode = array_merge(array('Message nature' => 'Request Oceanic Clearance'), $decode);
605 605
 				}
606
-				elseif (preg_match(':^#B2:',$message)) {
607
-					$decode = array_merge(array('Message nature' => 'Oceanic Clearance Readback'),$decode);
606
+				elseif (preg_match(':^#B2:', $message)) {
607
+					$decode = array_merge(array('Message nature' => 'Oceanic Clearance Readback'), $decode);
608 608
 				}
609
-				elseif (preg_match(':^#B3:',$message)) {
610
-					$decode = array_merge(array('Message nature' => 'Request Departure Clearance'),$decode);
609
+				elseif (preg_match(':^#B3:', $message)) {
610
+					$decode = array_merge(array('Message nature' => 'Request Departure Clearance'), $decode);
611 611
 				}
612
-				elseif (preg_match(':^#B4:',$message)) {
613
-					$decode = array_merge(array('Message nature' => 'Departure Clearance Readback'),$decode);
612
+				elseif (preg_match(':^#B4:', $message)) {
613
+					$decode = array_merge(array('Message nature' => 'Departure Clearance Readback'), $decode);
614 614
 				}
615
-				elseif (preg_match(':^#B6:',$message)) {
616
-					$decode = array_merge(array('Message nature' => 'Provide ADS Report'),$decode);
615
+				elseif (preg_match(':^#B6:', $message)) {
616
+					$decode = array_merge(array('Message nature' => 'Provide ADS Report'), $decode);
617 617
 				}
618
-				elseif (preg_match(':^#B8:',$message)) {
619
-					$decode = array_merge(array('Message nature' => 'Request Departure Slot'),$decode);
618
+				elseif (preg_match(':^#B8:', $message)) {
619
+					$decode = array_merge(array('Message nature' => 'Request Departure Slot'), $decode);
620 620
 				}
621
-				elseif (preg_match(':^#B9:',$message)) {
622
-					$decode = array_merge(array('Message nature' => 'Request ATIS Report'),$decode);
621
+				elseif (preg_match(':^#B9:', $message)) {
622
+					$decode = array_merge(array('Message nature' => 'Request ATIS Report'), $decode);
623 623
 				}
624
-				elseif (preg_match(':^#B0:',$message)) {
625
-					$decode = array_merge(array('Message nature' => 'ATS Facility Notification'),$decode);
624
+				elseif (preg_match(':^#B0:', $message)) {
625
+					$decode = array_merge(array('Message nature' => 'ATS Facility Notification'), $decode);
626 626
 				}
627
-				elseif (preg_match(':^#BA:',$message)) {
628
-					$decode = array_merge(array('Message nature' => 'ATCComm'),$decode);
627
+				elseif (preg_match(':^#BA:', $message)) {
628
+					$decode = array_merge(array('Message nature' => 'ATCComm'), $decode);
629 629
 				}
630
-				elseif (preg_match(':^#BB:',$message)) {
631
-					$decode = array_merge(array('Message nature' => 'Request TWIP Report'),$decode);
630
+				elseif (preg_match(':^#BB:', $message)) {
631
+					$decode = array_merge(array('Message nature' => 'Request TWIP Report'), $decode);
632 632
 				}
633
-				elseif (preg_match(':^#BC:',$message)) {
634
-					$decode = array_merge(array('Message nature' => 'Pushback Clearance Request'),$decode);
633
+				elseif (preg_match(':^#BC:', $message)) {
634
+					$decode = array_merge(array('Message nature' => 'Pushback Clearance Request'), $decode);
635 635
 				}
636
-				elseif (preg_match(':^#BD:',$message)) {
637
-					$decode = array_merge(array('Message nature' => 'Expected Taxi Clearance Request'),$decode);
636
+				elseif (preg_match(':^#BD:', $message)) {
637
+					$decode = array_merge(array('Message nature' => 'Expected Taxi Clearance Request'), $decode);
638 638
 				}
639
-				elseif (preg_match(':^#BE:',$message)) {
640
-					$decode = array_merge(array('Message nature' => 'CPC Aircraft Log-On/Off Request'),$decode);
639
+				elseif (preg_match(':^#BE:', $message)) {
640
+					$decode = array_merge(array('Message nature' => 'CPC Aircraft Log-On/Off Request'), $decode);
641 641
 				}
642
-				elseif (preg_match(':^#BF:',$message)) {
643
-					$decode = array_merge(array('Message nature' => 'CPC WILCO/UNABLE Response'),$decode);
642
+				elseif (preg_match(':^#BF:', $message)) {
643
+					$decode = array_merge(array('Message nature' => 'CPC WILCO/UNABLE Response'), $decode);
644 644
 				}
645
-				elseif (preg_match(':^#H3:',$message)) {
646
-					$decode = array_merge(array('Message nature' => 'Icing Report'),$decode);
645
+				elseif (preg_match(':^#H3:', $message)) {
646
+					$decode = array_merge(array('Message nature' => 'Icing Report'), $decode);
647 647
 				}
648 648
 			}
649 649
 			if ($label == '10') {
650
-				if (preg_match(':^DTO01:',$message)) {
651
-					$decode = array_merge(array('Message nature' => 'Delayed Takeoff Report'),$decode);
650
+				if (preg_match(':^DTO01:', $message)) {
651
+					$decode = array_merge(array('Message nature' => 'Delayed Takeoff Report'), $decode);
652 652
 				}
653
-				elseif (preg_match(':^AIS01:',$message)) {
654
-					$decode = array_merge(array('Message nature' => 'AIS Request'),$decode);
653
+				elseif (preg_match(':^AIS01:', $message)) {
654
+					$decode = array_merge(array('Message nature' => 'AIS Request'), $decode);
655 655
 				}
656
-				elseif (preg_match(':^FTX01:',$message)) {
657
-					$decode = array_merge(array('Message nature' => 'Free Text Downlink'),$decode);
656
+				elseif (preg_match(':^FTX01:', $message)) {
657
+					$decode = array_merge(array('Message nature' => 'Free Text Downlink'), $decode);
658 658
 				}
659
-				elseif (preg_match(':^FPL01:',$message)) {
660
-					$decode = array_merge(array('Message nature' => 'Flight Plan Request'),$decode);
659
+				elseif (preg_match(':^FPL01:', $message)) {
660
+					$decode = array_merge(array('Message nature' => 'Flight Plan Request'), $decode);
661 661
 				}
662
-				elseif (preg_match(':^WAB01:',$message)) {
663
-					$decode = array_merge(array('Message nature' => 'Weight & Balance Request'),$decode);
662
+				elseif (preg_match(':^WAB01:', $message)) {
663
+					$decode = array_merge(array('Message nature' => 'Weight & Balance Request'), $decode);
664 664
 				}
665
-				elseif (preg_match(':^MET01:',$message)) {
666
-					$decode = array_merge(array('Message nature' => 'Weather Data Request'),$decode);
665
+				elseif (preg_match(':^MET01:', $message)) {
666
+					$decode = array_merge(array('Message nature' => 'Weather Data Request'), $decode);
667 667
 				}
668
-				elseif (preg_match(':^WAB02:',$message)) {
669
-					$decode = array_merge(array('Message nature' => 'Weight and Balance Acknowledgement'),$decode);
668
+				elseif (preg_match(':^WAB02:', $message)) {
669
+					$decode = array_merge(array('Message nature' => 'Weight and Balance Acknowledgement'), $decode);
670 670
 				}
671 671
 			}
672 672
 			if ($label == '15') {
673
-				if (preg_match(':^FST01:',$message)) {
674
-					$decode = array_merge(array('Message nature' => 'Flight Status Report'),$decode);
673
+				if (preg_match(':^FST01:', $message)) {
674
+					$decode = array_merge(array('Message nature' => 'Flight Status Report'), $decode);
675 675
 				}
676 676
 			}
677 677
 			if (!$found && $label == 'SA') {
678
-				$n = sscanf($message, "%d%c%c%6[0-9]", $version,$state,$type,$at);
678
+				$n = sscanf($message, "%d%c%c%6[0-9]", $version, $state, $type, $at);
679 679
 				if ($n == 4) {
680 680
 					$vsta = array('Version' => $version);
681 681
 					if ($state == 'E') {
682
-						$vsta = array_merge($vsta,array('Link state' => 'Established'));
682
+						$vsta = array_merge($vsta, array('Link state' => 'Established'));
683 683
 					}
684 684
 					elseif ($state == 'L') {
685
-						$vsta = array_merge($vsta,array('Link state' => 'Lost'));
685
+						$vsta = array_merge($vsta, array('Link state' => 'Lost'));
686 686
 					}
687 687
 					else {
688
-						$vsta = array_merge($vsta,array('Link state' => 'Unknown'));
688
+						$vsta = array_merge($vsta, array('Link state' => 'Unknown'));
689 689
 					}
690 690
 					if ($type == 'V') {
691
-						$vsta = array_merge($vsta,array('Link type' => 'VHF ACARS'));
691
+						$vsta = array_merge($vsta, array('Link type' => 'VHF ACARS'));
692 692
 					}
693 693
 					elseif ($type == 'S') {
694
-						$vsta = array_merge($vsta,array('Link type' => 'Generic SATCOM'));
694
+						$vsta = array_merge($vsta, array('Link type' => 'Generic SATCOM'));
695 695
 					}
696 696
 					elseif ($type == 'H') {
697
-						$vsta = array_merge($vsta,array('Link type' => 'HF'));
697
+						$vsta = array_merge($vsta, array('Link type' => 'HF'));
698 698
 					}
699 699
 					elseif ($type == 'G') {
700
-						$vsta = array_merge($vsta,array('Link type' => 'GlobalStar SATCOM'));
700
+						$vsta = array_merge($vsta, array('Link type' => 'GlobalStar SATCOM'));
701 701
 					}
702 702
 					elseif ($type == 'C') {
703
-						$vsta = array_merge($vsta,array('Link type' => 'ICO SATCOM'));
703
+						$vsta = array_merge($vsta, array('Link type' => 'ICO SATCOM'));
704 704
 					}
705 705
 					elseif ($type == '2') {
706
-						$vsta = array_merge($vsta,array('Link type' => 'VDL Mode 2'));
706
+						$vsta = array_merge($vsta, array('Link type' => 'VDL Mode 2'));
707 707
 					}
708 708
 					elseif ($type == 'X') {
709
-						$vsta = array_merge($vsta,array('Link type' => 'Inmarsat Aero'));
709
+						$vsta = array_merge($vsta, array('Link type' => 'Inmarsat Aero'));
710 710
 					}
711 711
 					elseif ($type == 'I') {
712
-						$vsta = array_merge($vsta,array('Link type' => 'Irridium SATCOM'));
712
+						$vsta = array_merge($vsta, array('Link type' => 'Irridium SATCOM'));
713 713
 					}
714 714
 					else {
715
-						$vsta = array_merge($vsta,array('Link type' => 'Unknown'));
715
+						$vsta = array_merge($vsta, array('Link type' => 'Unknown'));
716 716
 					}
717
-					$vsta = array_merge($vsta,array('Event occured at' => implode(':',str_split($at,2))));
718
-					$decode = array_merge($vsta,$decode);
717
+					$vsta = array_merge($vsta, array('Event occured at' => implode(':', str_split($at, 2))));
718
+					$decode = array_merge($vsta, $decode);
719 719
 				}
720 720
 			}
721 721
 
722 722
 			$title = $this->getTitlefromLabel($label);
723
-			if ($title != '') $decode = array_merge(array('Message title' => $title),$decode);
723
+			if ($title != '') $decode = array_merge(array('Message title' => $title), $decode);
724 724
 			/*
725 725
 			// Business jets always use GS0001
726 726
 			if ($ident != 'GS0001') $info = $this->addModeSData($ident,$registration,$icao,$airicao,$latitude,$longitude);
@@ -741,21 +741,21 @@  discard block
 block discarded – undo
741 741
 	* @param String ACARS data in acarsdec data
742 742
 	*
743 743
 	*/
744
-	public function add($data,$message = array()) {
744
+	public function add($data, $message = array()) {
745 745
 		global $globalDebug, $globalACARSArchive;
746 746
 		$Image = new Image($this->db);
747 747
 		$Schedule = new Schedule($this->db);
748 748
 		$Translation = new Translation($this->db);
749 749
 
750
-		$message = array_merge($message,$this->parse($data));
750
+		$message = array_merge($message, $this->parse($data));
751 751
 		if (isset($message['registration']) && $message['registration'] != '' && $message['ident'] != '' && $message['registration'] != '!') {
752
-			$ident = (string)$message['ident'];
752
+			$ident = (string) $message['ident'];
753 753
 			$label = $message['label'];
754 754
 			$block_id = $message['block_id'];
755 755
 			$msg_no = $message['msg_no'];
756 756
 			$msg = $message['message'];
757 757
 			$decode = $message['decode'];
758
-			$registration = (string)$message['registration'];
758
+			$registration = (string) $message['registration'];
759 759
 			if (isset($decode['latitude'])) $latitude = $decode['latitude'];
760 760
 			else $latitude = '';
761 761
 			if (isset($decode['longitude'])) $longitude = $decode['longitude'];
@@ -769,20 +769,20 @@  discard block
 block discarded – undo
769 769
 				$Image->addSpotterImage($registration);
770 770
 			}
771 771
 			// Business jets always use GS0001
772
-			if ($ident != 'GS0001') $info = $this->addModeSData($ident,$registration,$icao,$airicao,$latitude,$longitude);
772
+			if ($ident != 'GS0001') $info = $this->addModeSData($ident, $registration, $icao, $airicao, $latitude, $longitude);
773 773
 			if ($globalDebug && isset($info) && $info != '') echo $info;
774 774
 			if (count($decode) > 0) $decode_json = json_encode($decode);
775 775
 			else $decode_json = '';
776 776
 			if (isset($decode['Departure airport']) && isset($decode['Departure hour']) && isset($decode['Arrival airport']) && isset($decode['Arrival hour'])) {
777
-				$Schedule->addSchedule($icao,$decode['Departure airport'],$decode['Departure hour'],$decode['Arrival airport'],$decode['Arrival hour'],'ACARS');
777
+				$Schedule->addSchedule($icao, $decode['Departure airport'], $decode['Departure hour'], $decode['Arrival airport'], $decode['Arrival hour'], 'ACARS');
778 778
 			} elseif (isset($decode['Departure airport']) && isset($decode['Arrival airport'])) {
779
-				$Schedule->addSchedule($icao,$decode['Departure airport'],'',$decode['Arrival airport'],'','ACARS');
779
+				$Schedule->addSchedule($icao, $decode['Departure airport'], '', $decode['Arrival airport'], '', 'ACARS');
780 780
 			}
781
-			$result = $this->addLiveAcarsData($ident,$registration,$label,$block_id,$msg_no,$msg,$decode_json);
782
-			if (!isset($globalACARSArchive)) $globalACARSArchive = array('10','80','81','82','3F');
783
-			if ($result && in_array($label,$globalACARSArchive)) $this->addArchiveAcarsData($ident,$registration,$label,$block_id,$msg_no,$msg,$decode_json);
781
+			$result = $this->addLiveAcarsData($ident, $registration, $label, $block_id, $msg_no, $msg, $decode_json);
782
+			if (!isset($globalACARSArchive)) $globalACARSArchive = array('10', '80', '81', '82', '3F');
783
+			if ($result && in_array($label, $globalACARSArchive)) $this->addArchiveAcarsData($ident, $registration, $label, $block_id, $msg_no, $msg, $decode_json);
784 784
 			if ($globalDebug && count($decode) > 0) {
785
-				echo "Human readable data : ".implode(' - ',$decode)."\n";
785
+				echo "Human readable data : ".implode(' - ', $decode)."\n";
786 786
 			}
787 787
 		}
788 788
 	}
@@ -799,7 +799,7 @@  discard block
 block discarded – undo
799 799
      * @param string $decode
800 800
      * @return bool
801 801
      */
802
-	public function addLiveAcarsData($ident,$registration,$label,$block_id,$msg_no,$message,$decode = '') {
802
+	public function addLiveAcarsData($ident, $registration, $label, $block_id, $msg_no, $message, $decode = '') {
803 803
 		global $globalDebug;
804 804
 		date_default_timezone_set('UTC');
805 805
 		if ($label != 'SQ' && $label != 'Q0' && $label != '_d' && $message != '') {
@@ -807,22 +807,22 @@  discard block
 block discarded – undo
807 807
 			$this->db = $Connection->db;
808 808
 			if ($globalDebug) echo "Test if not already in Live ACARS table...";
809 809
 			$query_test = "SELECT COUNT(*) as nb FROM acars_live WHERE ident = :ident AND registration = :registration AND message = :message";
810
-			$query_test_values = array(':ident' => $ident,':registration' => $registration, ':message' => $message);
810
+			$query_test_values = array(':ident' => $ident, ':registration' => $registration, ':message' => $message);
811 811
 			try {
812 812
 				$stht = $this->db->prepare($query_test);
813 813
 				$stht->execute($query_test_values);
814
-			} catch(PDOException $e) {
814
+			} catch (PDOException $e) {
815 815
 				echo "error : ".$e->getMessage();
816 816
 				return false;
817 817
 			}
818 818
 			if ($stht->fetchColumn() == 0) {
819 819
 				if ($globalDebug) echo "Add Live ACARS data...";
820 820
 				$query = "INSERT INTO acars_live (ident,registration,label,block_id,msg_no,message,decode,date) VALUES (:ident,:registration,:label,:block_id,:msg_no,:message,:decode,:date)";
821
-				$query_values = array(':ident' => $ident,':registration' => $registration, ':label' => $label,':block_id' => $block_id, ':msg_no' => $msg_no, ':message' => $message, ':decode' => $decode,':date' => date("Y-m-d H:i:s"));
821
+				$query_values = array(':ident' => $ident, ':registration' => $registration, ':label' => $label, ':block_id' => $block_id, ':msg_no' => $msg_no, ':message' => $message, ':decode' => $decode, ':date' => date("Y-m-d H:i:s"));
822 822
 				try {
823 823
 					$sth = $this->db->prepare($query);
824 824
 					$sth->execute($query_values);
825
-				} catch(PDOException $e) {
825
+				} catch (PDOException $e) {
826 826
 					echo "error : ".$e->getMessage();
827 827
 					return false;
828 828
 				}
@@ -848,10 +848,10 @@  discard block
 block discarded – undo
848 848
      * @param string $decode
849 849
      * @return string
850 850
      */
851
-	public function addArchiveAcarsData($ident,$registration,$label,$block_id,$msg_no,$message,$decode = '') {
851
+	public function addArchiveAcarsData($ident, $registration, $label, $block_id, $msg_no, $message, $decode = '') {
852 852
 		global $globalDebug;
853 853
 		date_default_timezone_set('UTC');
854
-		if ($label != 'SQ' && $label != 'Q0' && $label != '_d' && $message != '' && preg_match('/^MET0/',$message) === 0 && preg_match('/^ARR0/',$message) === 0 && preg_match('/^ETA/',$message) === 0 && preg_match('/^WXR/',$message) === 0 && preg_match('/^FTX01.FIC/',$message) === 0) {
854
+		if ($label != 'SQ' && $label != 'Q0' && $label != '_d' && $message != '' && preg_match('/^MET0/', $message) === 0 && preg_match('/^ARR0/', $message) === 0 && preg_match('/^ETA/', $message) === 0 && preg_match('/^WXR/', $message) === 0 && preg_match('/^FTX01.FIC/', $message) === 0) {
855 855
 			/*
856 856
 				    if ($globalDebug) echo "Test if not already in Archive ACARS table...";
857 857
 			    	    $query_test = "SELECT COUNT(*) as nb FROM acars_archive WHERE ident = :ident AND registration = :registration AND message = :message";
@@ -866,11 +866,11 @@  discard block
 block discarded – undo
866 866
 			*/
867 867
 			if ($globalDebug) echo "Add Live ACARS data...";
868 868
 			$query = "INSERT INTO acars_archive (ident,registration,label,block_id,msg_no,message,decode) VALUES (:ident,:registration,:label,:block_id,:msg_no,:message,:decode)";
869
-			$query_values = array(':ident' => $ident,':registration' => $registration, ':label' => $label,':block_id' => $block_id, ':msg_no' => $msg_no, ':message' => $message, ':decode' => $decode);
869
+			$query_values = array(':ident' => $ident, ':registration' => $registration, ':label' => $label, ':block_id' => $block_id, ':msg_no' => $msg_no, ':message' => $message, ':decode' => $decode);
870 870
 			try {
871 871
 				$sth = $this->db->prepare($query);
872 872
 				$sth->execute($query_values);
873
-			} catch(PDOException $e) {
873
+			} catch (PDOException $e) {
874 874
 				return "error : ".$e->getMessage();
875 875
 			}
876 876
 			if ($globalDebug) echo "Done\n";
@@ -892,7 +892,7 @@  discard block
 block discarded – undo
892 892
 		try {
893 893
 			$sth = $this->db->prepare($query);
894 894
 			$sth->execute($query_values);
895
-		} catch(PDOException $e) {
895
+		} catch (PDOException $e) {
896 896
 			echo "error : ".$e->getMessage();
897 897
 			return '';
898 898
 		}
@@ -912,7 +912,7 @@  discard block
 block discarded – undo
912 912
 		try {
913 913
 			$sth = $this->db->prepare($query);
914 914
 			$sth->execute($query_values);
915
-		} catch(PDOException $e) {
915
+		} catch (PDOException $e) {
916 916
 			echo "error : ".$e->getMessage();
917 917
 			return array();
918 918
 		}
@@ -933,7 +933,7 @@  discard block
 block discarded – undo
933 933
 		try {
934 934
 			$sth = $this->db->prepare($query);
935 935
 			$sth->execute($query_values);
936
-		} catch(PDOException $e) {
936
+		} catch (PDOException $e) {
937 937
 			echo "error : ".$e->getMessage();
938 938
 			return array();
939 939
 		}
@@ -949,7 +949,7 @@  discard block
 block discarded – undo
949 949
      * @param string $label
950 950
      * @return array Return ACARS data in array
951 951
      */
952
-	public function getLatestAcarsData($limit = '',$label = '') {
952
+	public function getLatestAcarsData($limit = '', $label = '') {
953 953
 		global $globalURL;
954 954
 		$Image = new Image($this->db);
955 955
 		$Spotter = new Spotter($this->db);
@@ -960,8 +960,8 @@  discard block
 block discarded – undo
960 960
 		if ($limit != "")
961 961
 		{
962 962
 			$limit_array = explode(",", $limit);
963
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
964
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
963
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
964
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
965 965
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
966 966
 			{
967 967
 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
@@ -977,7 +977,7 @@  discard block
 block discarded – undo
977 977
 		try {
978 978
 			$sth = $this->db->prepare($query);
979 979
 			$sth->execute($query_values);
980
-		} catch(PDOException $e) {
980
+		} catch (PDOException $e) {
981 981
 			echo "error : ".$e->getMessage();
982 982
 			return array();
983 983
 		}
@@ -985,39 +985,39 @@  discard block
 block discarded – undo
985 985
 		while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
986 986
 			$data = array();
987 987
 			if ($row['registration'] != '') {
988
-				$row['registration'] = str_replace('.','',$row['registration']);
988
+				$row['registration'] = str_replace('.', '', $row['registration']);
989 989
 				$image_array = $Image->getSpotterImage($row['registration']);
990
-				if (count($image_array) > 0) $data = array_merge($data,array('image' => $image_array[0]['image'],'image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website']));
991
-				else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
992
-			} else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
990
+				if (count($image_array) > 0) $data = array_merge($data, array('image' => $image_array[0]['image'], 'image_thumbnail' => $image_array[0]['image_thumbnail'], 'image_copyright' => $image_array[0]['image_copyright'], 'image_source' => $image_array[0]['image_source'], 'image_source_website' => $image_array[0]['image_source_website']));
991
+				else $data = array_merge($data, array('image' => '', 'image_thumbnail' => '', 'image_copyright' => '', 'image_source' => '', 'image_source_website' => ''));
992
+			} else $data = array_merge($data, array('image' => '', 'image_thumbnail' => '', 'image_copyright' => '', 'image_source' => '', 'image_source_website' => ''));
993 993
 			if ($row['registration'] == '') $row['registration'] = 'NA';
994 994
 			if ($row['ident'] == '') $row['ident'] = 'NA';
995
-			$identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,2));
995
+			$identicao = $Spotter->getAllAirlineInfo(substr($row['ident'], 0, 2));
996 996
 			if (isset($identicao[0])) {
997
-				if (substr($row['ident'],0,2) == 'AF') {
998
-					if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident'];
999
-					else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
1000
-				} else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
1001
-				$data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name']));
997
+				if (substr($row['ident'], 0, 2) == 'AF') {
998
+					if (filter_var(substr($row['ident'], 2), FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident'];
999
+					else $icao = 'AFR'.ltrim(substr($row['ident'], 2), '0');
1000
+				} else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'], 2), '0');
1001
+				$data = array_merge($data, array('airline_icao' => $identicao[0]['icao'], 'airline_name' => $identicao[0]['name']));
1002 1002
 			} else $icao = $row['ident'];
1003
-			$icao = $Translation->checkTranslation($icao,false);
1004
-			$decode = json_decode($row['decode'],true);
1003
+			$icao = $Translation->checkTranslation($icao, false);
1004
+			$decode = json_decode($row['decode'], true);
1005 1005
 			$found = false;
1006
-			if ($decode != '' && array_key_exists('Departure airport',$decode)) {
1006
+			if ($decode != '' && array_key_exists('Departure airport', $decode)) {
1007 1007
 				$airport_info = $Spotter->getAllAirportInfo($decode['Departure airport']);
1008 1008
 				if (isset($airport_info[0]['icao'])) {
1009 1009
 					$decode['Departure airport'] = '<a href="'.$globalURL.'/airport/'.$airport_info[0]['icao'].'">'.$airport_info[0]['city'].','.$airport_info[0]['country'].' ('.$airport_info[0]['icao'].')</a>';
1010 1010
 					$found = true;
1011 1011
 				}
1012 1012
 			}
1013
-			if ($decode != '' && array_key_exists('Arrival airport',$decode)) {
1013
+			if ($decode != '' && array_key_exists('Arrival airport', $decode)) {
1014 1014
 				$airport_info = $Spotter->getAllAirportInfo($decode['Arrival airport']);
1015 1015
 				if (isset($airport_info[0]['icao'])) {
1016 1016
 					$decode['Arrival airport'] = '<a href="'.$globalURL.'/airport/'.$airport_info[0]['icao'].'">'.$airport_info[0]['city'].','.$airport_info[0]['country'].' ('.$airport_info[0]['icao'].')</a>';
1017 1017
 					$found = true;
1018 1018
 				}
1019 1019
 			}
1020
-			if ($decode != '' && array_key_exists('Airport/Waypoint name',$decode)) {
1020
+			if ($decode != '' && array_key_exists('Airport/Waypoint name', $decode)) {
1021 1021
 				$airport_info = $Spotter->getAllAirportInfo($decode['Airport/Waypoint name']);
1022 1022
 				if (isset($airport_info[0]['icao'])) {
1023 1023
 					$decode['Airport/Waypoint name'] = '<a href="'.$globalURL.'/airport/'.$airport_info[0]['icao'].'">'.$airport_info[0]['city'].','.$airport_info[0]['country'].' ('.$airport_info[0]['icao'].')</a>';
@@ -1025,7 +1025,7 @@  discard block
 block discarded – undo
1025 1025
 				}
1026 1026
 			}
1027 1027
 			if ($found) $row['decode'] = json_encode($decode);
1028
-			$data = array_merge($data,array('registration' => $row['registration'],'message' => $row['message'], 'date' => $row['date'], 'ident' => $icao, 'decode' => $row['decode']));
1028
+			$data = array_merge($data, array('registration' => $row['registration'], 'message' => $row['message'], 'date' => $row['date'], 'ident' => $icao, 'decode' => $row['decode']));
1029 1029
 			$result[] = $data;
1030 1030
 			$i++;
1031 1031
 		}
@@ -1043,7 +1043,7 @@  discard block
 block discarded – undo
1043 1043
      * @param string $label
1044 1044
      * @return array Return ACARS data in array
1045 1045
      */
1046
-	public function getArchiveAcarsData($limit = '',$label = '') {
1046
+	public function getArchiveAcarsData($limit = '', $label = '') {
1047 1047
 		global $globalURL;
1048 1048
 		$Image = new Image($this->db);
1049 1049
 		$Spotter = new Spotter($this->db);
@@ -1053,8 +1053,8 @@  discard block
 block discarded – undo
1053 1053
 		if ($limit != "")
1054 1054
 		{
1055 1055
 			$limit_array = explode(",", $limit);
1056
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
1057
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
1056
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
1057
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
1058 1058
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
1059 1059
 			{
1060 1060
 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
@@ -1075,45 +1075,45 @@  discard block
 block discarded – undo
1075 1075
 		try {
1076 1076
 			$sth = $this->db->prepare($query);
1077 1077
 			$sth->execute($query_values);
1078
-		} catch(PDOException $e) {
1078
+		} catch (PDOException $e) {
1079 1079
 			echo "error : ".$e->getMessage();
1080 1080
 			return array();
1081 1081
 		}
1082
-		$i=0;
1082
+		$i = 0;
1083 1083
 		$result = array();
1084 1084
 		while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
1085 1085
 			$data = array();
1086 1086
 			if ($row['registration'] != '') {
1087
-				$row['registration'] = str_replace('.','',$row['registration']);
1087
+				$row['registration'] = str_replace('.', '', $row['registration']);
1088 1088
 				$image_array = $Image->getSpotterImage($row['registration']);
1089
-				if (count($image_array) > 0) $data = array_merge($data,array('image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website']));
1090
-				else $data = array_merge($data,array('image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
1091
-			} else $data = array_merge($data,array('image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
1089
+				if (count($image_array) > 0) $data = array_merge($data, array('image_thumbnail' => $image_array[0]['image_thumbnail'], 'image_copyright' => $image_array[0]['image_copyright'], 'image_source' => $image_array[0]['image_source'], 'image_source_website' => $image_array[0]['image_source_website']));
1090
+				else $data = array_merge($data, array('image_thumbnail' => '', 'image_copyright' => '', 'image_source' => '', 'image_source_website' => ''));
1091
+			} else $data = array_merge($data, array('image_thumbnail' => '', 'image_copyright' => '', 'image_source' => '', 'image_source_website' => ''));
1092 1092
 			$icao = '';
1093 1093
 			if ($row['registration'] == '') $row['registration'] = 'NA';
1094 1094
 			if ($row['ident'] == '') $row['ident'] = 'NA';
1095
-			$identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,2));
1095
+			$identicao = $Spotter->getAllAirlineInfo(substr($row['ident'], 0, 2));
1096 1096
 			if (isset($identicao[0])) {
1097
-				if (substr($row['ident'],0,2) == 'AF') {
1098
-					if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident'];
1099
-					else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
1100
-				} else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
1101
-				$data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name']));
1097
+				if (substr($row['ident'], 0, 2) == 'AF') {
1098
+					if (filter_var(substr($row['ident'], 2), FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident'];
1099
+					else $icao = 'AFR'.ltrim(substr($row['ident'], 2), '0');
1100
+				} else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'], 2), '0');
1101
+				$data = array_merge($data, array('airline_icao' => $identicao[0]['icao'], 'airline_name' => $identicao[0]['name']));
1102 1102
 			} else $icao = $row['ident'];
1103 1103
 			$icao = $Translation->checkTranslation($icao);
1104
-			$decode = json_decode($row['decode'],true);
1104
+			$decode = json_decode($row['decode'], true);
1105 1105
 			$found = false;
1106
-			if ($decode != '' && array_key_exists('Departure airport',$decode)) {
1106
+			if ($decode != '' && array_key_exists('Departure airport', $decode)) {
1107 1107
 				$airport_info = $Spotter->getAllAirportInfo($decode['Departure airport']);
1108 1108
 				if (isset($airport_info[0]['icao'])) $decode['Departure airport'] = '<a href="'.$globalURL.'/airport/'.$airport_info[0]['icao'].'">'.$airport_info[0]['city'].','.$airport_info[0]['country'].' ('.$airport_info[0]['icao'].')</a>';
1109 1109
 				$found = true;
1110 1110
 			}
1111
-			if ($decode != '' && array_key_exists('Arrival airport',$decode)) {
1111
+			if ($decode != '' && array_key_exists('Arrival airport', $decode)) {
1112 1112
 				$airport_info = $Spotter->getAllAirportInfo($decode['Arrival airport']);
1113 1113
 				if (isset($airport_info[0]['icao'])) $decode['Arrival airport'] = '<a href="'.$globalURL.'/airport/'.$airport_info[0]['icao'].'">'.$airport_info[0]['city'].','.$airport_info[0]['country'].' ('.$airport_info[0]['icao'].')</a>';
1114 1114
 				$found = true;
1115 1115
 			}
1116
-			if ($decode != '' && array_key_exists('Airport/Waypoint name',$decode)) {
1116
+			if ($decode != '' && array_key_exists('Airport/Waypoint name', $decode)) {
1117 1117
 				$airport_info = $Spotter->getAllAirportInfo($decode['Airport/Waypoint name']);
1118 1118
 				if (isset($airport_info[0]['icao'])) {
1119 1119
 					$decode['Airport/Waypoint name'] = '<a href="'.$globalURL.'/airport/'.$airport_info[0]['icao'].'">'.$airport_info[0]['city'].','.$airport_info[0]['country'].' ('.$airport_info[0]['icao'].')</a>';
@@ -1121,7 +1121,7 @@  discard block
 block discarded – undo
1121 1121
 				}
1122 1122
 			}
1123 1123
 			if ($found) $row['decode'] = json_encode($decode);
1124
-			$data = array_merge($data,array('registration' => $row['registration'],'message' => $row['message'], 'date' => $row['date'], 'ident' => $icao, 'decode' => $row['decode']));
1124
+			$data = array_merge($data, array('registration' => $row['registration'], 'message' => $row['message'], 'date' => $row['date'], 'ident' => $icao, 'decode' => $row['decode']));
1125 1125
 			$result[] = $data;
1126 1126
 			$i++;
1127 1127
 		}
@@ -1142,7 +1142,7 @@  discard block
 block discarded – undo
1142 1142
      * @param string $longitude
1143 1143
      * @return string
1144 1144
      */
1145
-	public function addModeSData($ident,$registration,$icao = '',$ICAOTypeCode = '',$latitude = '', $longitude = '') {
1145
+	public function addModeSData($ident, $registration, $icao = '', $ICAOTypeCode = '', $latitude = '', $longitude = '') {
1146 1146
 		global $globalDebug, $globalDBdriver;
1147 1147
 		$ident = trim($ident);
1148 1148
 		$Translation = new Translation($this->db);
@@ -1155,7 +1155,7 @@  discard block
 block discarded – undo
1155 1155
 			if ($globalDebug) echo "Ident or registration null, exit\n";
1156 1156
 			return '';
1157 1157
 		}
1158
-		$registration = str_replace('.','',$registration);
1158
+		$registration = str_replace('.', '', $registration);
1159 1159
 		$ident = $Translation->ident2icao($ident);
1160 1160
 		// Check if a flight with same registration is flying now, if ok check if callsign = name in ACARS, else add it to translation
1161 1161
 		if ($globalDebug) echo "Check if needed to add translation ".$ident.'... ';
@@ -1164,7 +1164,7 @@  discard block
 block discarded – undo
1164 1164
 		try {
1165 1165
 			$sthsi = $this->db->prepare($querysi);
1166 1166
 			$sthsi->execute($querysi_values);
1167
-		} catch(PDOException $e) {
1167
+		} catch (PDOException $e) {
1168 1168
 			if ($globalDebug) echo $e->getMessage();
1169 1169
 			return "error : ".$e->getMessage();
1170 1170
 		}
@@ -1174,8 +1174,8 @@  discard block
 block discarded – undo
1174 1174
 			$Translation = new Translation($this->db);
1175 1175
 			$trans_ident = $Translation->getOperator($resultsi['ident']);
1176 1176
 			if ($globalDebug) echo 'Add translation to table : '.$ident.' -> '.$resultsi['ident'].' ';
1177
-			if ($ident != $trans_ident) $Translation->addOperator($resultsi['ident'],$ident,'ACARS');
1178
-			elseif ($trans_ident == $ident) $Translation->updateOperator($resultsi['ident'],$ident,'ACARS');
1177
+			if ($ident != $trans_ident) $Translation->addOperator($resultsi['ident'], $ident, 'ACARS');
1178
+			elseif ($trans_ident == $ident) $Translation->updateOperator($resultsi['ident'], $ident, 'ACARS');
1179 1179
 		} else {
1180 1180
 			if ($registration != '' && $latitude != '' && $longitude != '') {
1181 1181
 				$query = "SELECT ModeS FROM aircraft_modes WHERE Registration = :registration LIMIT 1";
@@ -1183,7 +1183,7 @@  discard block
 block discarded – undo
1183 1183
 				try {
1184 1184
 					$sth = $this->db->prepare($query);
1185 1185
 					$sth->execute($query_values);
1186
-				} catch(PDOException $e) {
1186
+				} catch (PDOException $e) {
1187 1187
 					if ($globalDebug) echo $e->getMessage();
1188 1188
 					return "error : ".$e->getMessage();
1189 1189
 				}
@@ -1191,7 +1191,7 @@  discard block
 block discarded – undo
1191 1191
 				$sth->closeCursor();
1192 1192
 				if (isset($result['modes'])) $hex = $result['modes'];
1193 1193
 				else $hex = '';
1194
-				$SI_data = array('hex' => $hex,'ident' => $ident,'aircraft_icao' => $ICAOTypeCode,'registration' => $registration,'latitude' => $latitude,'$longitude' => $longitude,'format_source' => 'ACARS');
1194
+				$SI_data = array('hex' => $hex, 'ident' => $ident, 'aircraft_icao' => $ICAOTypeCode, 'registration' => $registration, 'latitude' => $latitude, '$longitude' => $longitude, 'format_source' => 'ACARS');
1195 1195
 				if ($this->fromACARSscript) $this->SI->add($SI_data);
1196 1196
 			}
1197 1197
 		}
@@ -1201,7 +1201,7 @@  discard block
 block discarded – undo
1201 1201
 		try {
1202 1202
 			$sth = $this->db->prepare($query);
1203 1203
 			$sth->execute($query_values);
1204
-		} catch(PDOException $e) {
1204
+		} catch (PDOException $e) {
1205 1205
 			if ($globalDebug) echo $e->getMessage();
1206 1206
 			return "error : ".$e->getMessage();
1207 1207
 		}
@@ -1211,7 +1211,7 @@  discard block
 block discarded – undo
1211 1211
 			if (isset($result['ModeS'])) $ModeS = $result['ModeS'];
1212 1212
 			else $ModeS = '';
1213 1213
 			if ($ModeS == '') {
1214
-				$id = explode('-',$result['flightaware_id']);
1214
+				$id = explode('-', $result['flightaware_id']);
1215 1215
 				$ModeS = $id[0];
1216 1216
 			}
1217 1217
 			if ($ModeS != '') {
@@ -1221,20 +1221,20 @@  discard block
 block discarded – undo
1221 1221
 				try {
1222 1222
 					$sthc = $this->db->prepare($queryc);
1223 1223
 					$sthc->execute($queryc_values);
1224
-				} catch(PDOException $e) {
1224
+				} catch (PDOException $e) {
1225 1225
 					if ($globalDebug) echo $e->getMessage();
1226 1226
 					return "error : ".$e->getMessage();
1227 1227
 				}
1228 1228
 				$row = $sthc->fetch(PDO::FETCH_ASSOC);
1229 1229
 				$sthc->closeCursor();
1230
-				if (count($row) ==  0) {
1230
+				if (count($row) == 0) {
1231 1231
 					if ($globalDebug) echo " Add to ModeS table - ";
1232 1232
 					$queryi = "INSERT INTO aircraft_modes (ModeS,ModeSCountry,Registration,ICAOTypeCode,Source) VALUES (:ModeS,:ModeSCountry,:Registration, :ICAOTypeCode,'ACARS')";
1233
-					$queryi_values = array(':ModeS' => $ModeS,':ModeSCountry' => $country,':Registration' => $registration, ':ICAOTypeCode' => $ICAOTypeCode);
1233
+					$queryi_values = array(':ModeS' => $ModeS, ':ModeSCountry' => $country, ':Registration' => $registration, ':ICAOTypeCode' => $ICAOTypeCode);
1234 1234
 					try {
1235 1235
 						$sthi = $this->db->prepare($queryi);
1236 1236
 						$sthi->execute($queryi_values);
1237
-					} catch(PDOException $e) {
1237
+					} catch (PDOException $e) {
1238 1238
 						if ($globalDebug) echo $e->getMessage();
1239 1239
 						return "error : ".$e->getMessage();
1240 1240
 					}
@@ -1242,15 +1242,15 @@  discard block
 block discarded – undo
1242 1242
 					if ($globalDebug) echo " Update ModeS table - ";
1243 1243
 					if ($ICAOTypeCode != '') {
1244 1244
 						$queryi = "UPDATE aircraft_modes SET ModeSCountry = :ModeSCountry,Registration = :Registration,ICAOTypeCode = :ICAOTypeCode,Source = 'ACARS',LastModified = NOW() WHERE ModeS = :ModeS";
1245
-						$queryi_values = array(':ModeS' => $ModeS,':ModeSCountry' => $country,':Registration' => $registration, ':ICAOTypeCode' => $ICAOTypeCode);
1245
+						$queryi_values = array(':ModeS' => $ModeS, ':ModeSCountry' => $country, ':Registration' => $registration, ':ICAOTypeCode' => $ICAOTypeCode);
1246 1246
 					} else {
1247 1247
 						$queryi = "UPDATE aircraft_modes SET ModeSCountry = :ModeSCountry,Registration = :Registration,Source = 'ACARS',LastModified = NOW() WHERE ModeS = :ModeS";
1248
-						$queryi_values = array(':ModeS' => $ModeS,':ModeSCountry' => $country,':Registration' => $registration);
1248
+						$queryi_values = array(':ModeS' => $ModeS, ':ModeSCountry' => $country, ':Registration' => $registration);
1249 1249
 					}
1250 1250
 					try {
1251 1251
 						$sthi = $this->db->prepare($queryi);
1252 1252
 						$sthi->execute($queryi_values);
1253
-					} catch(PDOException $e) {
1253
+					} catch (PDOException $e) {
1254 1254
 						if ($globalDebug) echo $e->getMessage();
1255 1255
 						return "error : ".$e->getMessage();
1256 1256
 					}
@@ -1287,12 +1287,12 @@  discard block
 block discarded – undo
1287 1287
 					elseif ($globalDBdriver == 'pgsql') {
1288 1288
 						$queryi = "UPDATE spotter_output SET registration = :Registration WHERE ident = :ident AND date >= NOW() AT TIME ZONE 'UTC' - INTERVAL '1 HOUR'";
1289 1289
 					}
1290
-					$queryi_values = array(':Registration' => $registration,':ident' => $icao);
1290
+					$queryi_values = array(':Registration' => $registration, ':ident' => $icao);
1291 1291
 				}
1292 1292
 				try {
1293 1293
 					$sthi = $this->db->prepare($queryi);
1294 1294
 					$sthi->execute($queryi_values);
1295
-				} catch(PDOException $e) {
1295
+				} catch (PDOException $e) {
1296 1296
 					if ($globalDebug) echo $e->getMessage();
1297 1297
 					return "error : ".$e->getMessage();
1298 1298
 				}
Please login to merge, or discard this patch.
Braces   +415 added lines, -263 removed lines patch added patch discarded remove patch
@@ -24,7 +24,9 @@  discard block
 block discarded – undo
24 24
 	public function __construct($dbc = null,$fromACARSscript = false) {
25 25
 		$Connection = new Connection($dbc);
26 26
 		$this->db = $Connection->db();
27
-		if ($this->db === null) die('Error: No DB connection. (ACARS)');
27
+		if ($this->db === null) {
28
+			die('Error: No DB connection. (ACARS)');
29
+		}
28 30
 		if ($fromACARSscript) {
29 31
 			$this->fromACARSscript = true;
30 32
 			$this->SI = new SpotterImport($this->db);
@@ -39,14 +41,19 @@  discard block
 block discarded – undo
39 41
 	*/
40 42
 	public function ident2icao($ident) {
41 43
 		if (substr($ident,0,2) == 'AF') {
42
-			if (filter_var(substr($ident,2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $ident;
43
-			else $icao = 'AFR'.ltrim(substr($ident,2),'0');
44
+			if (filter_var(substr($ident,2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) {
45
+				$icao = $ident;
46
+			} else {
47
+				$icao = 'AFR'.ltrim(substr($ident,2),'0');
48
+			}
44 49
 		} else {
45 50
 			$Spotter = new Spotter($this->db);
46 51
 			$identicao = $Spotter->getAllAirlineInfo(substr($ident,0,2));
47 52
 			if (isset($identicao[0])) {
48 53
 				$icao = $identicao[0]['icao'].ltrim(substr($ident,2),'0');
49
-			} else $icao = $ident;
54
+			} else {
55
+				$icao = $ident;
56
+			}
50 57
 		}
51 58
 		return $icao;
52 59
 	}
@@ -120,14 +127,24 @@  discard block
 block discarded – undo
120 127
 		$message = '';
121 128
 		$result = array();
122 129
 		$n = sscanf($data,'%*[0-9a-z.] %*d %*02d/%*02d/%*04d %*02d:%*02d:%*02d %*d %*[0-9-] %*[A-Z0-9] %7s %*c %2[0-9a-zA-Z_] %d %4[0-9A-Z] %6[0-9A-Z] %[^\r\n]',$registration,$label,$block_id,$msg_no,$ident,$message);
123
-		if ($n == 0) $n = sscanf($data,'AC%*c %7s %*c %2[0-9a-zA-Z_] %d %4[0-9A-Z] %6[0-9A-Z] %[^\r\n]',$registration,$label,$block_id,$msg_no,$ident,$message);
124
-		if ($n == 0) $n = sscanf($data,'%*04d-%*02d-%*02d,%*02d:%*02d:%*02d,%*7s,%*c,%6[0-9A-Z-],%*c,%2[0-9a-zA-Z_],%d,%4[0-9A-Z],%6[0-9A-Z],%[^\r\n]',$registration,$label,$block_id,$msg_no,$ident,$message);
125
-		if ($n == 0) $n = sscanf($data,'%*04d-%*02d-%*02d,%*02d:%*02d:%*02d,%*7s,%*c,%5[0-9A-Z],%*c,%2[0-9a-zA-Z_],%d,%4[0-9A-Z],%6[0-9A-Z],%[^\r\n]',$registration,$label,$block_id,$msg_no,$ident,$message);
130
+		if ($n == 0) {
131
+			$n = sscanf($data,'AC%*c %7s %*c %2[0-9a-zA-Z_] %d %4[0-9A-Z] %6[0-9A-Z] %[^\r\n]',$registration,$label,$block_id,$msg_no,$ident,$message);
132
+		}
133
+		if ($n == 0) {
134
+			$n = sscanf($data,'%*04d-%*02d-%*02d,%*02d:%*02d:%*02d,%*7s,%*c,%6[0-9A-Z-],%*c,%2[0-9a-zA-Z_],%d,%4[0-9A-Z],%6[0-9A-Z],%[^\r\n]',$registration,$label,$block_id,$msg_no,$ident,$message);
135
+		}
136
+		if ($n == 0) {
137
+			$n = sscanf($data,'%*04d-%*02d-%*02d,%*02d:%*02d:%*02d,%*7s,%*c,%5[0-9A-Z],%*c,%2[0-9a-zA-Z_],%d,%4[0-9A-Z],%6[0-9A-Z],%[^\r\n]',$registration,$label,$block_id,$msg_no,$ident,$message);
138
+		}
126 139
 		if ($n != 0 && ($registration != '' || $ident != '' || $label != '' || $block_id != '' || $msg_no != '')) {
127 140
 			$registration = str_replace('.','',$registration);
128 141
 			$result = array('registration' => $registration, 'ident' => $ident,'label' => $label, 'block_id' => $block_id,'msg_no' => $msg_no,'message' => $message);
129
-			if ($globalDebug) echo "Reg. : ".$registration." - Ident : ".$ident." - Label : ".$label." - Message : ".$message."\n";
130
-		} else $message = $data;
142
+			if ($globalDebug) {
143
+				echo "Reg. : ".$registration." - Ident : ".$ident." - Label : ".$label." - Message : ".$message."\n";
144
+			}
145
+		} else {
146
+			$message = $data;
147
+		}
131 148
 		$decode = array();
132 149
 		$found = false;
133 150
 //		if ($registration != '' && $ident != '' && $registration != '!') {
@@ -147,12 +164,21 @@  discard block
 block discarded – undo
147 164
 				if ($n > 5 && ($lac == 'N' || $lac == 'S') && ($lnc == 'E' || $lnc == 'W')) {
148 165
 					$latitude = $la / 10000.0;
149 166
 					$longitude = $ln / 10000.0;
150
-					if ($lac == 'S') $latitude = '-'.$latitude;
151
-					if ($lnc == 'W') $longitude = '-'.$longitude;
167
+					if ($lac == 'S') {
168
+						$latitude = '-'.$latitude;
169
+					}
170
+					if ($lnc == 'W') {
171
+						$longitude = '-'.$longitude;
172
+					}
152 173
 					// Temp not always available
153
-					if ($globalDebug) echo 'latitude : '.$latitude.' - longitude : '.$longitude.' - airport depart : '.$dair.' - airport arrival : '.$darr.' - température : '.$temp."°C\n";
154
-					if ($temp == '') $decode = array('Latitude' => $latitude, 'Longitude' =>  $longitude, 'Departure airport' => $dair, 'Arrival airport' => $darr,'Altitude' => $alt);
155
-					else $decode = array('Latitude' => $latitude, 'Longitude' =>  $longitude, 'Departure airport' => $dair, 'Arrival airport' => $darr, 'Altitude' => 'FL'.$alt,'Temperature' => $temp.'°C');
174
+					if ($globalDebug) {
175
+						echo 'latitude : '.$latitude.' - longitude : '.$longitude.' - airport depart : '.$dair.' - airport arrival : '.$darr.' - température : '.$temp."°C\n";
176
+					}
177
+					if ($temp == '') {
178
+						$decode = array('Latitude' => $latitude, 'Longitude' =>  $longitude, 'Departure airport' => $dair, 'Arrival airport' => $darr,'Altitude' => $alt);
179
+					} else {
180
+						$decode = array('Latitude' => $latitude, 'Longitude' =>  $longitude, 'Departure airport' => $dair, 'Arrival airport' => $darr, 'Altitude' => 'FL'.$alt,'Temperature' => $temp.'°C');
181
+					}
156 182
 
157 183
 					//$icao = $Translation->checkTranslation($ident);
158 184
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
@@ -166,25 +192,35 @@  discard block
 block discarded – undo
166 192
 				$ahour = '';
167 193
 				$n = sscanf($message, "ARR01 %4[A-Z]%4d %4[A-Z]%4d", $dair, $dhour, $darr,$ahour);
168 194
 				if ($n == 4 && strlen($darr) == 4) {
169
-					if ($dhour != '') $dhour = substr(sprintf('%04d',$dhour),0,2).':'.substr(sprintf('%04d',$dhour),2);
170
-					if ($ahour != '') $ahour = substr(sprintf('%04d',$ahour),0,2).':'.substr(sprintf('%04d',$ahour),2);
171
-					if ($globalDebug) echo 'departure airport : '.$dair.' - arrival airport : '. $darr.' - departure hour : '. $dhour.' - arrival hour : '.$ahour."\n";
195
+					if ($dhour != '') {
196
+						$dhour = substr(sprintf('%04d',$dhour),0,2).':'.substr(sprintf('%04d',$dhour),2);
197
+					}
198
+					if ($ahour != '') {
199
+						$ahour = substr(sprintf('%04d',$ahour),0,2).':'.substr(sprintf('%04d',$ahour),2);
200
+					}
201
+					if ($globalDebug) {
202
+						echo 'departure airport : '.$dair.' - arrival airport : '. $darr.' - departure hour : '. $dhour.' - arrival hour : '.$ahour."\n";
203
+					}
172 204
 					//$icao = ACARS->ident2icao($ident);
173 205
 					//$icao = $Translation->checkTranslation($ident);
174 206
 					//$Schedule->addSchedule($icao,$dair,$dhour,$darr,$ahour,'ACARS');
175 207
 					$decode = array('Departure airport' => $dair, 'Departure hour' => $dhour, 'Arrival airport' => $darr, 'Arrival hour' => $ahour);
176 208
 					$found = true;
177
-				}
178
-				elseif ($n == 2 || $n  == 4) {
179
-					if ($dhour != '') $dhour = substr(sprintf('%04d',$dhour),0,2).':'.substr(sprintf('%04d',$dhour),2);
180
-					if ($globalDebug) echo 'airport arrival : '.$dair.' - arrival hour : '.$dhour."\n";
209
+				} elseif ($n == 2 || $n  == 4) {
210
+					if ($dhour != '') {
211
+						$dhour = substr(sprintf('%04d',$dhour),0,2).':'.substr(sprintf('%04d',$dhour),2);
212
+					}
213
+					if ($globalDebug) {
214
+						echo 'airport arrival : '.$dair.' - arrival hour : '.$dhour."\n";
215
+					}
181 216
 					//$icao = ACARS->ident2icao($ident);
182 217
 					//$icao = $Translation->checkTranslation($ident);
183 218
 					$decode = array('Arrival airport' => $dair, 'Arrival hour' => $dhour);
184 219
 					$found = true;
185
-				}
186
-				elseif ($n == 1) {
187
-					if ($globalDebug) echo 'airport arrival : '.$darr."\n";
220
+				} elseif ($n == 1) {
221
+					if ($globalDebug) {
222
+						echo 'airport arrival : '.$darr."\n";
223
+					}
188 224
 					//$icao = ACARS->ident2icao($ident);
189 225
 					//$icao = $Translation->checkTranslation($ident);
190 226
 					$decode = array('Arrival airport' => $darr);
@@ -202,7 +238,9 @@  discard block
 block discarded – undo
202 238
 				$darr = '';
203 239
 				$n = sscanf($message, "%4c,%4c,%*7s,%*d", $dair, $darr);
204 240
 				if ($n == 4) {
205
-					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
241
+					if ($globalDebug) {
242
+						echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
243
+					}
206 244
 					//$icao = ACARS->ident2icao($ident);
207 245
 					//$icao = $Translation->checkTranslation($ident);
208 246
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
@@ -236,14 +274,23 @@  discard block
 block discarded – undo
236 274
 				$apiste = '';
237 275
 				$n = sscanf(str_replace(array("\r\n", "\n", "\r"),'',$message), "%*[0-9A-Z]/%*3d/%4s/%*cSCH/%6[0-9A-Z ]/%4c/%4c/%5s/%4d%*3c/%4d/%4c/%[0-9A-Z ]/", $airicao,$aident,$dair, $darr, $ddate, $dhour,$ahour, $aair, $apiste);
238 276
 				if ($n > 8) {
239
-					if ($globalDebug) echo 'airicao : '. $airicao.' - ident : '.$aident.' - departure airport : '.$dair.' - arrival airport : '. $darr.' - date depart : '.$ddate.' - departure hour : '. $dhour.' - arrival hour : '.$ahour.' - arrival airport : '.$aair.' - arrival piste : '.$apiste."\n";
240
-					if ($dhour != '') $dhour = substr(sprintf('%04d',$dhour),0,2).':'.substr(sprintf('%04d',$dhour),2);
241
-					if ($ahour != '') $ahour = substr(sprintf('%04d',$ahour),0,2).':'.substr(sprintf('%04d',$ahour),2);
277
+					if ($globalDebug) {
278
+						echo 'airicao : '. $airicao.' - ident : '.$aident.' - departure airport : '.$dair.' - arrival airport : '. $darr.' - date depart : '.$ddate.' - departure hour : '. $dhour.' - arrival hour : '.$ahour.' - arrival airport : '.$aair.' - arrival piste : '.$apiste."\n";
279
+					}
280
+					if ($dhour != '') {
281
+						$dhour = substr(sprintf('%04d',$dhour),0,2).':'.substr(sprintf('%04d',$dhour),2);
282
+					}
283
+					if ($ahour != '') {
284
+						$ahour = substr(sprintf('%04d',$ahour),0,2).':'.substr(sprintf('%04d',$ahour),2);
285
+					}
242 286
 					$icao = trim($aident);
243 287
 
244 288
 					//$decode = 'Departure airport : '.$dair.' ('.$ddate.' at '.$dhour.') - Arrival Airport : '.$aair.' (at '.$ahour.') way '.$apiste;
245
-					if ($ahour == '') $decode = array('Departure airport' => $dair, 'Departure date' => $ddate, 'Departure hour' => $dhour, 'Arrival airport' => $darr);
246
-					else $decode = array('Departure airport' => $dair, 'Departure date' => $ddate, 'Departure hour' => $dhour, 'Arrival airport' => $darr, 'Arrival hour' => $ahour, 'Arrival way' => $apiste);
289
+					if ($ahour == '') {
290
+						$decode = array('Departure airport' => $dair, 'Departure date' => $ddate, 'Departure hour' => $dhour, 'Arrival airport' => $darr);
291
+					} else {
292
+						$decode = array('Departure airport' => $dair, 'Departure date' => $ddate, 'Departure hour' => $dhour, 'Arrival airport' => $darr, 'Arrival hour' => $ahour, 'Arrival way' => $apiste);
293
+					}
247 294
 					//$Schedule->addSchedule($icao,$dair,$dhour,$darr,$ahour,'ACARS');
248 295
 					$decode['icao'] = $icao;
249 296
 					$found = true;
@@ -265,9 +312,15 @@  discard block
 block discarded – undo
265 312
 					$lns = $lns.'.'.$lns;
266 313
 					$latitude = $las / 1000.0;
267 314
 					$longitude = $lns / 1000.0;
268
-					if ($lac == 'S') $latitude = '-'.$latitude;
269
-					if ($lnc == 'W') $longitude = '-'.$longitude;
270
-					if ($globalDebug) echo 'latitude : '.$latitude.' - longitude : '.$longitude."\n";
315
+					if ($lac == 'S') {
316
+						$latitude = '-'.$latitude;
317
+					}
318
+					if ($lnc == 'W') {
319
+						$longitude = '-'.$longitude;
320
+					}
321
+					if ($globalDebug) {
322
+						echo 'latitude : '.$latitude.' - longitude : '.$longitude."\n";
323
+					}
271 324
 					$decode = array('Latitude' => $latitude, 'Longitude' => $longitude);
272 325
 					$found = true;
273 326
 				}
@@ -285,7 +338,9 @@  discard block
 block discarded – undo
285 338
 				$darr = '';
286 339
 				$n = sscanf($message, "%*[0-9A-Z ]/%*s %4c/%4c .", $dair, $darr);
287 340
 				if ($n == 4) {
288
-					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
341
+					if ($globalDebug) {
342
+						echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
343
+					}
289 344
 					//$icao = $Translation->checkTranslation($ident);
290 345
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
291 346
 					$decode = array('Departure airport' => $dair, 'Arrival airport' => $darr);
@@ -298,7 +353,9 @@  discard block
 block discarded – undo
298 353
 				$darr = '';
299 354
 				$n = sscanf($message, "%*[0-9],%4c,%4c,", $dair, $darr);
300 355
 				if ($n == 4) {
301
-					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
356
+					if ($globalDebug) {
357
+						echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
358
+					}
302 359
 					//$icao = $Translation->checkTranslation($ident);
303 360
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
304 361
 					$decode = array('Departure airport' => $dair, 'Arrival airport' => $darr);
@@ -311,7 +368,9 @@  discard block
 block discarded – undo
311 368
 				$darr = '';
312 369
 				$n = sscanf($message, "002AF %4c %4c ", $dair, $darr);
313 370
 				if ($n == 2) {
314
-					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
371
+					if ($globalDebug) {
372
+						echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
373
+					}
315 374
 					//$icao = $Translation->checkTranslation($ident);
316 375
 					$decode = array('Departure airport' => $dair, 'Arrival airport' => $darr);
317 376
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
@@ -325,7 +384,9 @@  discard block
 block discarded – undo
325 384
 				$darr = '';
326 385
 				$n = sscanf($message, "#DFBA%*02d/%*[A-Z-],%*[0-9A-Z],%*d,%4c,%4c", $dair, $darr);
327 386
 				if ($n == 6) {
328
-					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
387
+					if ($globalDebug) {
388
+						echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
389
+					}
329 390
 					//$icao = $Translation->checkTranslation($ident);
330 391
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
331 392
 					$decode = array('Departure airport' => $dair, 'Arrival airport' => $darr);
@@ -338,7 +399,9 @@  discard block
 block discarded – undo
338 399
 				$darr = '';
339 400
 				$n = sscanf($message, "#DFBA%*02d/%*[0-9A-Z,]/%*[A-Z-],%*[0-9A-Z],%*d,%4c,%4c", $dair, $darr);
340 401
 				if ($n == 7) {
341
-					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
402
+					if ($globalDebug) {
403
+						echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
404
+					}
342 405
 					//$icao = $Translation->checkTranslation($ident);
343 406
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
344 407
 					$decode = array('Departure airport' => $dair, 'Arrival airport' => $darr);
@@ -366,8 +429,12 @@  discard block
 block discarded – undo
366 429
 					$decode['icao'] = $icao;
367 430
 					$latitude = $las / 100.0;
368 431
 					$longitude = $lns / 100.0;
369
-					if ($lac == 'S') $latitude = '-'.$latitude;
370
-					if ($lnc == 'W') $longitude = '-'.$longitude;
432
+					if ($lac == 'S') {
433
+						$latitude = '-'.$latitude;
434
+					}
435
+					if ($lnc == 'W') {
436
+						$longitude = '-'.$longitude;
437
+					}
371 438
 
372 439
 					$decode = array('Latitude' => $latitude,'Longitude' => $longitude,'Altitude' => 'FL'.$alt,'Fuel' => $fuel,'speed' => $speed);
373 440
 					$found = true;
@@ -385,8 +452,12 @@  discard block
 block discarded – undo
385 452
 				if ($n == 4) {
386 453
 					$latitude = $las;
387 454
 					$longitude = $lns;
388
-					if ($lac == 'S') $latitude = '-'.$latitude;
389
-					if ($lnc == 'W') $longitude = '-'.$longitude;
455
+					if ($lac == 'S') {
456
+						$latitude = '-'.$latitude;
457
+					}
458
+					if ($lnc == 'W') {
459
+						$longitude = '-'.$longitude;
460
+					}
390 461
 
391 462
 					$decode = array('Latitude' => $latitude,'Longitude' => $longitude);
392 463
 					$found = true;
@@ -402,7 +473,9 @@  discard block
 block discarded – undo
402 473
 				$darr = '';
403 474
 				$n = sscanf($message, "%*[0-9A-Z] NLINFO %*d/%*d %4c/%4c .", $dair, $darr);
404 475
 				if ($n == 5) {
405
-					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
476
+					if ($globalDebug) {
477
+						echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
478
+					}
406 479
 					//$icao = $Translation->checkTranslation($ident);
407 480
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
408 481
 					$decode = array('Departure airport' => $dair, 'Arrival airport' => $darr);
@@ -423,7 +496,9 @@  discard block
 block discarded – undo
423 496
 				$aident = '';
424 497
 				$n = sscanf(str_replace(array("\r\n", "\n", "\r"),'',$message), "%*[0-9A-Z],,%*[0-9A-Z],%*[0-9A-Z],%4s,%4s,.%*6s,%*4[A-Z],%[0-9A-Z],", $dair, $darr, $aident);
425 498
 				if ($n == 8) {
426
-					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
499
+					if ($globalDebug) {
500
+						echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
501
+					}
427 502
 					$icao = trim($aident);
428 503
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
429 504
 					$decode['icao'] = $icao;
@@ -440,7 +515,9 @@  discard block
 block discarded – undo
440 515
 				$darr = '';
441 516
 				$n = sscanf($message, "%*d/%*d %4s/%4s .%*6s", $dair, $darr);
442 517
 				if ($n == 5) {
443
-					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
518
+					if ($globalDebug) {
519
+						echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
520
+					}
444 521
 					//$icao = $Translation->checkTranslation($ident);
445 522
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
446 523
 					$decode = array('Departure airport' => $dair, 'Arrival airport' => $darr);
@@ -455,7 +532,9 @@  discard block
 block discarded – undo
455 532
 				$darr = '';
456 533
 				$n = sscanf($message,'%4[A-Z]%4[A-Z]%*4d',$dair,$darr);
457 534
 				if ($n == 3) {
458
-					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
535
+					if ($globalDebug) {
536
+						echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
537
+					}
459 538
 					//$icao = $Translation->checkTranslation($ident);
460 539
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
461 540
 					$decode = array('Departure airport' => $dair, 'Arrival airport' => $darr);
@@ -470,7 +549,9 @@  discard block
 block discarded – undo
470 549
 				$darr = '';
471 550
 				$n = sscanf($message,'3J01 DSPTCH %*d/%*d %4s/%4s .%*6s',$dair,$darr);
472 551
 				if ($n == 3) {
473
-					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
552
+					if ($globalDebug) {
553
+						echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
554
+					}
474 555
 					//$icao = $Translation->checkTranslation($ident);
475 556
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
476 557
 					$decode = array('Departure airport' => $dair, 'Arrival airport' => $darr);
@@ -480,7 +561,9 @@  discard block
 block discarded – undo
480 561
 			if (!$found) {
481 562
 				$n = sscanf($message,'MET01%4c',$airport);
482 563
 				if ($n == 1) {
483
-					if ($globalDebug) echo 'airport name : '.$airport;
564
+					if ($globalDebug) {
565
+						echo 'airport name : '.$airport;
566
+					}
484 567
 					$decode = array('Airport/Waypoint name' => $airport);
485 568
 					$found = true;
486 569
 				}
@@ -488,184 +571,126 @@  discard block
 block discarded – undo
488 571
 			if ($label == 'H1') {
489 572
 				if (preg_match('/^#CFBFLR/',$message) || preg_match('/^#CFBWRN/',$message)) {
490 573
 					$decode = array_merge(array('Message nature' => 'Equipment failure'),$decode);
491
-				}
492
-				elseif (preg_match('/^#DFB\*TKO/',$message) || preg_match('/^#DFBTKO/',$message)) {
574
+				} elseif (preg_match('/^#DFB\*TKO/',$message) || preg_match('/^#DFBTKO/',$message)) {
493 575
 					$decode = array_merge(array('Message nature' => 'Take off performance data'),$decode);
494
-				}
495
-				elseif (preg_match('/^#DFB\*CRZ/',$message) || preg_match('/^#DFBCRZ/',$message)) {
576
+				} elseif (preg_match('/^#DFB\*CRZ/',$message) || preg_match('/^#DFBCRZ/',$message)) {
496 577
 					$decode = array_merge(array('Message nature' => 'Cruise performance data'),$decode);
497
-				}
498
-				elseif (preg_match('/^#DFB\*WOB/',$message) || preg_match('/^#DFBWOB/',$message)) {
578
+				} elseif (preg_match('/^#DFB\*WOB/',$message) || preg_match('/^#DFBWOB/',$message)) {
499 579
 					$decode = array_merge(array('Message nature' => 'Weather observation'),$decode);
500
-				}
501
-				elseif (preg_match(':^#DFB/PIREP:',$message)) {
580
+				} elseif (preg_match(':^#DFB/PIREP:',$message)) {
502 581
 					$decode = array_merge(array('Message nature' => 'Pilot Report'),$decode);
503
-				}
504
-				elseif (preg_match('/^#DFBEDA/',$message) || preg_match('/^#DFBENG/',$message)) {
582
+				} elseif (preg_match('/^#DFBEDA/',$message) || preg_match('/^#DFBENG/',$message)) {
505 583
 					$decode = array_merge(array('Message nature' => 'Engine Data'),$decode);
506
-				}
507
-				elseif (preg_match(':^#M1AAEP:',$message)) {
584
+				} elseif (preg_match(':^#M1AAEP:',$message)) {
508 585
 					$decode = array_merge(array('Message nature' => 'Position/Weather Report'),$decode);
509
-				}
510
-				elseif (preg_match(':^#M2APWD:',$message)) {
586
+				} elseif (preg_match(':^#M2APWD:',$message)) {
511 587
 					$decode = array_merge(array('Message nature' => 'Flight plan predicted wind data'),$decode);
512
-				}
513
-				elseif (preg_match(':^#M1BREQPWI:',$message)) {
588
+				} elseif (preg_match(':^#M1BREQPWI:',$message)) {
514 589
 					$decode = array_merge(array('Message nature' => 'Predicted wind info request'),$decode);
515
-				}
516
-				elseif (preg_match(':^#CF:',$message)) {
590
+				} elseif (preg_match(':^#CF:',$message)) {
517 591
 					$decode = array_merge(array('Message nature' => 'Central Fault Display'),$decode);
518
-				}
519
-				elseif (preg_match(':^#DF:',$message)) {
592
+				} elseif (preg_match(':^#DF:',$message)) {
520 593
 					$decode = array_merge(array('Message nature' => 'Digital Flight Data Acquisition Unit'),$decode);
521
-				}
522
-				elseif (preg_match(':^#EC:',$message)) {
594
+				} elseif (preg_match(':^#EC:',$message)) {
523 595
 					$decode = array_merge(array('Message nature' => 'Engine Display System'),$decode);
524
-				}
525
-				elseif (preg_match(':^#EI:',$message)) {
596
+				} elseif (preg_match(':^#EI:',$message)) {
526 597
 					$decode = array_merge(array('Message nature' => 'Engine Report'),$decode);
527
-				}
528
-				elseif (preg_match(':^#H1:',$message)) {
598
+				} elseif (preg_match(':^#H1:',$message)) {
529 599
 					$decode = array_merge(array('Message nature' => 'HF Data Radio - Left'),$decode);
530
-				}
531
-				elseif (preg_match(':^#H2:',$message)) {
600
+				} elseif (preg_match(':^#H2:',$message)) {
532 601
 					$decode = array_merge(array('Message nature' => 'HF Data Radio - Right'),$decode);
533
-				}
534
-				elseif (preg_match(':^#HD:',$message)) {
602
+				} elseif (preg_match(':^#HD:',$message)) {
535 603
 					$decode = array_merge(array('Message nature' => 'HF Data Radio - Selected'),$decode);
536
-				}
537
-				elseif (preg_match(':^#M1:',$message)) {
604
+				} elseif (preg_match(':^#M1:',$message)) {
538 605
 					$decode = array_merge(array('Message nature' => 'Flight Management Computer - Left'),$decode);
539
-				}
540
-				elseif (preg_match(':^#M2:',$message)) {
606
+				} elseif (preg_match(':^#M2:',$message)) {
541 607
 					$decode = array_merge(array('Message nature' => 'Flight Management Computer - Right'),$decode);
542
-				}
543
-				elseif (preg_match(':^#M3:',$message)) {
608
+				} elseif (preg_match(':^#M3:',$message)) {
544 609
 					$decode = array_merge(array('Message nature' => 'Flight Management Computer - Center'),$decode);
545
-				}
546
-				elseif (preg_match(':^#MD:',$message)) {
610
+				} elseif (preg_match(':^#MD:',$message)) {
547 611
 					$decode = array_merge(array('Message nature' => 'Flight Management Computer - Selected'),$decode);
548
-				}
549
-				elseif (preg_match(':^#PS:',$message)) {
612
+				} elseif (preg_match(':^#PS:',$message)) {
550 613
 					$decode = array_merge(array('Message nature' => 'Keyboard/Display Unit'),$decode);
551
-				}
552
-				elseif (preg_match(':^#S1:',$message)) {
614
+				} elseif (preg_match(':^#S1:',$message)) {
553 615
 					$decode = array_merge(array('Message nature' => 'SDU - Left'),$decode);
554
-				}
555
-				elseif (preg_match(':^#S2:',$message)) {
616
+				} elseif (preg_match(':^#S2:',$message)) {
556 617
 					$decode = array_merge(array('Message nature' => 'SDU - Right'),$decode);
557
-				}
558
-				elseif (preg_match(':^#SD:',$message)) {
618
+				} elseif (preg_match(':^#SD:',$message)) {
559 619
 					$decode = array_merge(array('Message nature' => 'SDU - Selected'),$decode);
560
-				}
561
-				elseif (preg_match(':^#T[0-8]:',$message)) {
620
+				} elseif (preg_match(':^#T[0-8]:',$message)) {
562 621
 					$decode = array_merge(array('Message nature' => 'Cabin Terminal Messages'),$decode);
563
-				}
564
-				elseif (preg_match(':^#WO:',$message)) {
622
+				} elseif (preg_match(':^#WO:',$message)) {
565 623
 					$decode = array_merge(array('Message nature' => 'Weather Observation Report'),$decode);
566
-				}
567
-				elseif (preg_match(':^#A1:',$message)) {
624
+				} elseif (preg_match(':^#A1:',$message)) {
568 625
 					$decode = array_merge(array('Message nature' => 'Oceanic Clearance'),$decode);
569
-				}
570
-				elseif (preg_match(':^#A3:',$message)) {
626
+				} elseif (preg_match(':^#A3:',$message)) {
571 627
 					$decode = array_merge(array('Message nature' => 'Departure Clearance Response'),$decode);
572
-				}
573
-				elseif (preg_match(':^#A4:',$message)) {
628
+				} elseif (preg_match(':^#A4:',$message)) {
574 629
 					$decode = array_merge(array('Message nature' => 'Flight Systems Message'),$decode);
575
-				}
576
-				elseif (preg_match(':^#A6:',$message)) {
630
+				} elseif (preg_match(':^#A6:',$message)) {
577 631
 					$decode = array_merge(array('Message nature' => 'Request ADS Reports'),$decode);
578
-				}
579
-				elseif (preg_match(':^#A8:',$message)) {
632
+				} elseif (preg_match(':^#A8:',$message)) {
580 633
 					$decode = array_merge(array('Message nature' => 'Deliver Departure Slot'),$decode);
581
-				}
582
-				elseif (preg_match(':^#A9:',$message)) {
634
+				} elseif (preg_match(':^#A9:',$message)) {
583 635
 					$decode = array_merge(array('Message nature' => 'ATIS report'),$decode);
584
-				}
585
-				elseif (preg_match(':^#A0:',$message)) {
636
+				} elseif (preg_match(':^#A0:',$message)) {
586 637
 					$decode = array_merge(array('Message nature' => 'ATIS Facility Notification (AFN)'),$decode);
587
-				}
588
-				elseif (preg_match(':^#AA:',$message)) {
638
+				} elseif (preg_match(':^#AA:',$message)) {
589 639
 					$decode = array_merge(array('Message nature' => 'ATCComm'),$decode);
590
-				}
591
-				elseif (preg_match(':^#AB:',$message)) {
640
+				} elseif (preg_match(':^#AB:',$message)) {
592 641
 					$decode = array_merge(array('Message nature' => 'TWIP Report'),$decode);
593
-				}
594
-				elseif (preg_match(':^#AC:',$message)) {
642
+				} elseif (preg_match(':^#AC:',$message)) {
595 643
 					$decode = array_merge(array('Message nature' => 'Pushback Clearance'),$decode);
596
-				}
597
-				elseif (preg_match(':^#AD:',$message)) {
644
+				} elseif (preg_match(':^#AD:',$message)) {
598 645
 					$decode = array_merge(array('Message nature' => 'Expected Taxi Clearance'),$decode);
599
-				}
600
-				elseif (preg_match(':^#AF:',$message)) {
646
+				} elseif (preg_match(':^#AF:',$message)) {
601 647
 					$decode = array_merge(array('Message nature' => 'CPC Command/Response'),$decode);
602
-				}
603
-				elseif (preg_match(':^#B1:',$message)) {
648
+				} elseif (preg_match(':^#B1:',$message)) {
604 649
 					$decode = array_merge(array('Message nature' => 'Request Oceanic Clearance'),$decode);
605
-				}
606
-				elseif (preg_match(':^#B2:',$message)) {
650
+				} elseif (preg_match(':^#B2:',$message)) {
607 651
 					$decode = array_merge(array('Message nature' => 'Oceanic Clearance Readback'),$decode);
608
-				}
609
-				elseif (preg_match(':^#B3:',$message)) {
652
+				} elseif (preg_match(':^#B3:',$message)) {
610 653
 					$decode = array_merge(array('Message nature' => 'Request Departure Clearance'),$decode);
611
-				}
612
-				elseif (preg_match(':^#B4:',$message)) {
654
+				} elseif (preg_match(':^#B4:',$message)) {
613 655
 					$decode = array_merge(array('Message nature' => 'Departure Clearance Readback'),$decode);
614
-				}
615
-				elseif (preg_match(':^#B6:',$message)) {
656
+				} elseif (preg_match(':^#B6:',$message)) {
616 657
 					$decode = array_merge(array('Message nature' => 'Provide ADS Report'),$decode);
617
-				}
618
-				elseif (preg_match(':^#B8:',$message)) {
658
+				} elseif (preg_match(':^#B8:',$message)) {
619 659
 					$decode = array_merge(array('Message nature' => 'Request Departure Slot'),$decode);
620
-				}
621
-				elseif (preg_match(':^#B9:',$message)) {
660
+				} elseif (preg_match(':^#B9:',$message)) {
622 661
 					$decode = array_merge(array('Message nature' => 'Request ATIS Report'),$decode);
623
-				}
624
-				elseif (preg_match(':^#B0:',$message)) {
662
+				} elseif (preg_match(':^#B0:',$message)) {
625 663
 					$decode = array_merge(array('Message nature' => 'ATS Facility Notification'),$decode);
626
-				}
627
-				elseif (preg_match(':^#BA:',$message)) {
664
+				} elseif (preg_match(':^#BA:',$message)) {
628 665
 					$decode = array_merge(array('Message nature' => 'ATCComm'),$decode);
629
-				}
630
-				elseif (preg_match(':^#BB:',$message)) {
666
+				} elseif (preg_match(':^#BB:',$message)) {
631 667
 					$decode = array_merge(array('Message nature' => 'Request TWIP Report'),$decode);
632
-				}
633
-				elseif (preg_match(':^#BC:',$message)) {
668
+				} elseif (preg_match(':^#BC:',$message)) {
634 669
 					$decode = array_merge(array('Message nature' => 'Pushback Clearance Request'),$decode);
635
-				}
636
-				elseif (preg_match(':^#BD:',$message)) {
670
+				} elseif (preg_match(':^#BD:',$message)) {
637 671
 					$decode = array_merge(array('Message nature' => 'Expected Taxi Clearance Request'),$decode);
638
-				}
639
-				elseif (preg_match(':^#BE:',$message)) {
672
+				} elseif (preg_match(':^#BE:',$message)) {
640 673
 					$decode = array_merge(array('Message nature' => 'CPC Aircraft Log-On/Off Request'),$decode);
641
-				}
642
-				elseif (preg_match(':^#BF:',$message)) {
674
+				} elseif (preg_match(':^#BF:',$message)) {
643 675
 					$decode = array_merge(array('Message nature' => 'CPC WILCO/UNABLE Response'),$decode);
644
-				}
645
-				elseif (preg_match(':^#H3:',$message)) {
676
+				} elseif (preg_match(':^#H3:',$message)) {
646 677
 					$decode = array_merge(array('Message nature' => 'Icing Report'),$decode);
647 678
 				}
648 679
 			}
649 680
 			if ($label == '10') {
650 681
 				if (preg_match(':^DTO01:',$message)) {
651 682
 					$decode = array_merge(array('Message nature' => 'Delayed Takeoff Report'),$decode);
652
-				}
653
-				elseif (preg_match(':^AIS01:',$message)) {
683
+				} elseif (preg_match(':^AIS01:',$message)) {
654 684
 					$decode = array_merge(array('Message nature' => 'AIS Request'),$decode);
655
-				}
656
-				elseif (preg_match(':^FTX01:',$message)) {
685
+				} elseif (preg_match(':^FTX01:',$message)) {
657 686
 					$decode = array_merge(array('Message nature' => 'Free Text Downlink'),$decode);
658
-				}
659
-				elseif (preg_match(':^FPL01:',$message)) {
687
+				} elseif (preg_match(':^FPL01:',$message)) {
660 688
 					$decode = array_merge(array('Message nature' => 'Flight Plan Request'),$decode);
661
-				}
662
-				elseif (preg_match(':^WAB01:',$message)) {
689
+				} elseif (preg_match(':^WAB01:',$message)) {
663 690
 					$decode = array_merge(array('Message nature' => 'Weight & Balance Request'),$decode);
664
-				}
665
-				elseif (preg_match(':^MET01:',$message)) {
691
+				} elseif (preg_match(':^MET01:',$message)) {
666 692
 					$decode = array_merge(array('Message nature' => 'Weather Data Request'),$decode);
667
-				}
668
-				elseif (preg_match(':^WAB02:',$message)) {
693
+				} elseif (preg_match(':^WAB02:',$message)) {
669 694
 					$decode = array_merge(array('Message nature' => 'Weight and Balance Acknowledgement'),$decode);
670 695
 				}
671 696
 			}
@@ -680,38 +705,28 @@  discard block
 block discarded – undo
680 705
 					$vsta = array('Version' => $version);
681 706
 					if ($state == 'E') {
682 707
 						$vsta = array_merge($vsta,array('Link state' => 'Established'));
683
-					}
684
-					elseif ($state == 'L') {
708
+					} elseif ($state == 'L') {
685 709
 						$vsta = array_merge($vsta,array('Link state' => 'Lost'));
686
-					}
687
-					else {
710
+					} else {
688 711
 						$vsta = array_merge($vsta,array('Link state' => 'Unknown'));
689 712
 					}
690 713
 					if ($type == 'V') {
691 714
 						$vsta = array_merge($vsta,array('Link type' => 'VHF ACARS'));
692
-					}
693
-					elseif ($type == 'S') {
715
+					} elseif ($type == 'S') {
694 716
 						$vsta = array_merge($vsta,array('Link type' => 'Generic SATCOM'));
695
-					}
696
-					elseif ($type == 'H') {
717
+					} elseif ($type == 'H') {
697 718
 						$vsta = array_merge($vsta,array('Link type' => 'HF'));
698
-					}
699
-					elseif ($type == 'G') {
719
+					} elseif ($type == 'G') {
700 720
 						$vsta = array_merge($vsta,array('Link type' => 'GlobalStar SATCOM'));
701
-					}
702
-					elseif ($type == 'C') {
721
+					} elseif ($type == 'C') {
703 722
 						$vsta = array_merge($vsta,array('Link type' => 'ICO SATCOM'));
704
-					}
705
-					elseif ($type == '2') {
723
+					} elseif ($type == '2') {
706 724
 						$vsta = array_merge($vsta,array('Link type' => 'VDL Mode 2'));
707
-					}
708
-					elseif ($type == 'X') {
725
+					} elseif ($type == 'X') {
709 726
 						$vsta = array_merge($vsta,array('Link type' => 'Inmarsat Aero'));
710
-					}
711
-					elseif ($type == 'I') {
727
+					} elseif ($type == 'I') {
712 728
 						$vsta = array_merge($vsta,array('Link type' => 'Irridium SATCOM'));
713
-					}
714
-					else {
729
+					} else {
715 730
 						$vsta = array_merge($vsta,array('Link type' => 'Unknown'));
716 731
 					}
717 732
 					$vsta = array_merge($vsta,array('Event occured at' => implode(':',str_split($at,2))));
@@ -720,7 +735,9 @@  discard block
 block discarded – undo
720 735
 			}
721 736
 
722 737
 			$title = $this->getTitlefromLabel($label);
723
-			if ($title != '') $decode = array_merge(array('Message title' => $title),$decode);
738
+			if ($title != '') {
739
+				$decode = array_merge(array('Message title' => $title),$decode);
740
+			}
724 741
 			/*
725 742
 			// Business jets always use GS0001
726 743
 			if ($ident != 'GS0001') $info = $this->addModeSData($ident,$registration,$icao,$airicao,$latitude,$longitude);
@@ -756,31 +773,54 @@  discard block
 block discarded – undo
756 773
 			$msg = $message['message'];
757 774
 			$decode = $message['decode'];
758 775
 			$registration = (string)$message['registration'];
759
-			if (isset($decode['latitude'])) $latitude = $decode['latitude'];
760
-			else $latitude = '';
761
-			if (isset($decode['longitude'])) $longitude = $decode['longitude'];
762
-			else $longitude = '';
763
-			if (isset($decode['airicao'])) $airicao = $decode['airicao'];
764
-			else $airicao = '';
765
-			if (isset($decode['icao'])) $icao = $decode['icao'];
766
-			else $icao = $Translation->checkTranslation($ident);
776
+			if (isset($decode['latitude'])) {
777
+				$latitude = $decode['latitude'];
778
+			} else {
779
+				$latitude = '';
780
+			}
781
+			if (isset($decode['longitude'])) {
782
+				$longitude = $decode['longitude'];
783
+			} else {
784
+				$longitude = '';
785
+			}
786
+			if (isset($decode['airicao'])) {
787
+				$airicao = $decode['airicao'];
788
+			} else {
789
+				$airicao = '';
790
+			}
791
+			if (isset($decode['icao'])) {
792
+				$icao = $decode['icao'];
793
+			} else {
794
+				$icao = $Translation->checkTranslation($ident);
795
+			}
767 796
 			$image_array = $Image->getSpotterImage($registration);
768 797
 			if (!isset($image_array[0]['registration'])) {
769 798
 				$Image->addSpotterImage($registration);
770 799
 			}
771 800
 			// Business jets always use GS0001
772
-			if ($ident != 'GS0001') $info = $this->addModeSData($ident,$registration,$icao,$airicao,$latitude,$longitude);
773
-			if ($globalDebug && isset($info) && $info != '') echo $info;
774
-			if (count($decode) > 0) $decode_json = json_encode($decode);
775
-			else $decode_json = '';
801
+			if ($ident != 'GS0001') {
802
+				$info = $this->addModeSData($ident,$registration,$icao,$airicao,$latitude,$longitude);
803
+			}
804
+			if ($globalDebug && isset($info) && $info != '') {
805
+				echo $info;
806
+			}
807
+			if (count($decode) > 0) {
808
+				$decode_json = json_encode($decode);
809
+			} else {
810
+				$decode_json = '';
811
+			}
776 812
 			if (isset($decode['Departure airport']) && isset($decode['Departure hour']) && isset($decode['Arrival airport']) && isset($decode['Arrival hour'])) {
777 813
 				$Schedule->addSchedule($icao,$decode['Departure airport'],$decode['Departure hour'],$decode['Arrival airport'],$decode['Arrival hour'],'ACARS');
778 814
 			} elseif (isset($decode['Departure airport']) && isset($decode['Arrival airport'])) {
779 815
 				$Schedule->addSchedule($icao,$decode['Departure airport'],'',$decode['Arrival airport'],'','ACARS');
780 816
 			}
781 817
 			$result = $this->addLiveAcarsData($ident,$registration,$label,$block_id,$msg_no,$msg,$decode_json);
782
-			if (!isset($globalACARSArchive)) $globalACARSArchive = array('10','80','81','82','3F');
783
-			if ($result && in_array($label,$globalACARSArchive)) $this->addArchiveAcarsData($ident,$registration,$label,$block_id,$msg_no,$msg,$decode_json);
818
+			if (!isset($globalACARSArchive)) {
819
+				$globalACARSArchive = array('10','80','81','82','3F');
820
+			}
821
+			if ($result && in_array($label,$globalACARSArchive)) {
822
+				$this->addArchiveAcarsData($ident,$registration,$label,$block_id,$msg_no,$msg,$decode_json);
823
+			}
784 824
 			if ($globalDebug && count($decode) > 0) {
785 825
 				echo "Human readable data : ".implode(' - ',$decode)."\n";
786 826
 			}
@@ -805,7 +845,9 @@  discard block
 block discarded – undo
805 845
 		if ($label != 'SQ' && $label != 'Q0' && $label != '_d' && $message != '') {
806 846
 			$Connection = new Connection($this->db);
807 847
 			$this->db = $Connection->db;
808
-			if ($globalDebug) echo "Test if not already in Live ACARS table...";
848
+			if ($globalDebug) {
849
+				echo "Test if not already in Live ACARS table...";
850
+			}
809 851
 			$query_test = "SELECT COUNT(*) as nb FROM acars_live WHERE ident = :ident AND registration = :registration AND message = :message";
810 852
 			$query_test_values = array(':ident' => $ident,':registration' => $registration, ':message' => $message);
811 853
 			try {
@@ -816,7 +858,9 @@  discard block
 block discarded – undo
816 858
 				return false;
817 859
 			}
818 860
 			if ($stht->fetchColumn() == 0) {
819
-				if ($globalDebug) echo "Add Live ACARS data...";
861
+				if ($globalDebug) {
862
+					echo "Add Live ACARS data...";
863
+				}
820 864
 				$query = "INSERT INTO acars_live (ident,registration,label,block_id,msg_no,message,decode,date) VALUES (:ident,:registration,:label,:block_id,:msg_no,:message,:decode,:date)";
821 865
 				$query_values = array(':ident' => $ident,':registration' => $registration, ':label' => $label,':block_id' => $block_id, ':msg_no' => $msg_no, ':message' => $message, ':decode' => $decode,':date' => date("Y-m-d H:i:s"));
822 866
 				try {
@@ -827,10 +871,14 @@  discard block
 block discarded – undo
827 871
 					return false;
828 872
 				}
829 873
 			} else {
830
-				if ($globalDebug) echo "Data already in DB...\n";
874
+				if ($globalDebug) {
875
+					echo "Data already in DB...\n";
876
+				}
831 877
 				return false;
832 878
 			}
833
-			if ($globalDebug) echo "Done\n";
879
+			if ($globalDebug) {
880
+				echo "Done\n";
881
+			}
834 882
 			return true;
835 883
 		}
836 884
 		return false;
@@ -864,7 +912,9 @@  discard block
 block discarded – undo
864 912
 			    	    }
865 913
 				    if ($stht->fetchColumn() == 0) {
866 914
 			*/
867
-			if ($globalDebug) echo "Add Live ACARS data...";
915
+			if ($globalDebug) {
916
+				echo "Add Live ACARS data...";
917
+			}
868 918
 			$query = "INSERT INTO acars_archive (ident,registration,label,block_id,msg_no,message,decode) VALUES (:ident,:registration,:label,:block_id,:msg_no,:message,:decode)";
869 919
 			$query_values = array(':ident' => $ident,':registration' => $registration, ':label' => $label,':block_id' => $block_id, ':msg_no' => $msg_no, ':message' => $message, ':decode' => $decode);
870 920
 			try {
@@ -873,7 +923,9 @@  discard block
 block discarded – undo
873 923
 			} catch(PDOException $e) {
874 924
 				return "error : ".$e->getMessage();
875 925
 			}
876
-			if ($globalDebug) echo "Done\n";
926
+			if ($globalDebug) {
927
+				echo "Done\n";
928
+			}
877 929
 		}
878 930
 		return '';
879 931
 	}
@@ -897,8 +949,11 @@  discard block
 block discarded – undo
897 949
 			return '';
898 950
 		}
899 951
 		$row = $sth->fetchAll(PDO::FETCH_ASSOC);
900
-		if (count($row) > 0) return $row[0]['title'];
901
-		else return '';
952
+		if (count($row) > 0) {
953
+			return $row[0]['title'];
954
+		} else {
955
+			return '';
956
+		}
902 957
 	}
903 958
 
904 959
 	/**
@@ -917,8 +972,11 @@  discard block
 block discarded – undo
917 972
 			return array();
918 973
 		}
919 974
 		$row = $sth->fetchAll(PDO::FETCH_ASSOC);
920
-		if (count($row) > 0) return $row;
921
-		else return array();
975
+		if (count($row) > 0) {
976
+			return $row;
977
+		} else {
978
+			return array();
979
+		}
922 980
 	}
923 981
 
924 982
 	/**
@@ -938,8 +996,11 @@  discard block
 block discarded – undo
938 996
 			return array();
939 997
 		}
940 998
 		$row = $sth->fetchAll(PDO::FETCH_ASSOC);
941
-		if (count($row) > 0) return $row[0];
942
-		else return array();
999
+		if (count($row) > 0) {
1000
+			return $row[0];
1001
+		} else {
1002
+			return array();
1003
+		}
943 1004
 	}
944 1005
 
945 1006
     /**
@@ -987,19 +1048,35 @@  discard block
 block discarded – undo
987 1048
 			if ($row['registration'] != '') {
988 1049
 				$row['registration'] = str_replace('.','',$row['registration']);
989 1050
 				$image_array = $Image->getSpotterImage($row['registration']);
990
-				if (count($image_array) > 0) $data = array_merge($data,array('image' => $image_array[0]['image'],'image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website']));
991
-				else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
992
-			} else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
993
-			if ($row['registration'] == '') $row['registration'] = 'NA';
994
-			if ($row['ident'] == '') $row['ident'] = 'NA';
1051
+				if (count($image_array) > 0) {
1052
+					$data = array_merge($data,array('image' => $image_array[0]['image'],'image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website']));
1053
+				} else {
1054
+					$data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
1055
+				}
1056
+			} else {
1057
+				$data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
1058
+			}
1059
+			if ($row['registration'] == '') {
1060
+				$row['registration'] = 'NA';
1061
+			}
1062
+			if ($row['ident'] == '') {
1063
+				$row['ident'] = 'NA';
1064
+			}
995 1065
 			$identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,2));
996 1066
 			if (isset($identicao[0])) {
997 1067
 				if (substr($row['ident'],0,2) == 'AF') {
998
-					if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident'];
999
-					else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
1000
-				} else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
1068
+					if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) {
1069
+						$icao = $row['ident'];
1070
+					} else {
1071
+						$icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
1072
+					}
1073
+				} else {
1074
+					$icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
1075
+				}
1001 1076
 				$data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name']));
1002
-			} else $icao = $row['ident'];
1077
+			} else {
1078
+				$icao = $row['ident'];
1079
+			}
1003 1080
 			$icao = $Translation->checkTranslation($icao,false);
1004 1081
 			$decode = json_decode($row['decode'],true);
1005 1082
 			$found = false;
@@ -1024,7 +1101,9 @@  discard block
 block discarded – undo
1024 1101
 					$found = true;
1025 1102
 				}
1026 1103
 			}
1027
-			if ($found) $row['decode'] = json_encode($decode);
1104
+			if ($found) {
1105
+				$row['decode'] = json_encode($decode);
1106
+			}
1028 1107
 			$data = array_merge($data,array('registration' => $row['registration'],'message' => $row['message'], 'date' => $row['date'], 'ident' => $icao, 'decode' => $row['decode']));
1029 1108
 			$result[] = $data;
1030 1109
 			$i++;
@@ -1032,8 +1111,9 @@  discard block
 block discarded – undo
1032 1111
 		if (isset($result)) {
1033 1112
 			$result[0]['query_number_rows'] = $i;
1034 1113
 			return $result;
1114
+		} else {
1115
+			return array();
1035 1116
 		}
1036
-		else return array();
1037 1117
 	}
1038 1118
 
1039 1119
     /**
@@ -1086,31 +1166,51 @@  discard block
 block discarded – undo
1086 1166
 			if ($row['registration'] != '') {
1087 1167
 				$row['registration'] = str_replace('.','',$row['registration']);
1088 1168
 				$image_array = $Image->getSpotterImage($row['registration']);
1089
-				if (count($image_array) > 0) $data = array_merge($data,array('image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website']));
1090
-				else $data = array_merge($data,array('image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
1091
-			} else $data = array_merge($data,array('image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
1169
+				if (count($image_array) > 0) {
1170
+					$data = array_merge($data,array('image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website']));
1171
+				} else {
1172
+					$data = array_merge($data,array('image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
1173
+				}
1174
+			} else {
1175
+				$data = array_merge($data,array('image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
1176
+			}
1092 1177
 			$icao = '';
1093
-			if ($row['registration'] == '') $row['registration'] = 'NA';
1094
-			if ($row['ident'] == '') $row['ident'] = 'NA';
1178
+			if ($row['registration'] == '') {
1179
+				$row['registration'] = 'NA';
1180
+			}
1181
+			if ($row['ident'] == '') {
1182
+				$row['ident'] = 'NA';
1183
+			}
1095 1184
 			$identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,2));
1096 1185
 			if (isset($identicao[0])) {
1097 1186
 				if (substr($row['ident'],0,2) == 'AF') {
1098
-					if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident'];
1099
-					else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
1100
-				} else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
1187
+					if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) {
1188
+						$icao = $row['ident'];
1189
+					} else {
1190
+						$icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
1191
+					}
1192
+				} else {
1193
+					$icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
1194
+				}
1101 1195
 				$data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name']));
1102
-			} else $icao = $row['ident'];
1196
+			} else {
1197
+				$icao = $row['ident'];
1198
+			}
1103 1199
 			$icao = $Translation->checkTranslation($icao);
1104 1200
 			$decode = json_decode($row['decode'],true);
1105 1201
 			$found = false;
1106 1202
 			if ($decode != '' && array_key_exists('Departure airport',$decode)) {
1107 1203
 				$airport_info = $Spotter->getAllAirportInfo($decode['Departure airport']);
1108
-				if (isset($airport_info[0]['icao'])) $decode['Departure airport'] = '<a href="'.$globalURL.'/airport/'.$airport_info[0]['icao'].'">'.$airport_info[0]['city'].','.$airport_info[0]['country'].' ('.$airport_info[0]['icao'].')</a>';
1204
+				if (isset($airport_info[0]['icao'])) {
1205
+					$decode['Departure airport'] = '<a href="'.$globalURL.'/airport/'.$airport_info[0]['icao'].'">'.$airport_info[0]['city'].','.$airport_info[0]['country'].' ('.$airport_info[0]['icao'].')</a>';
1206
+				}
1109 1207
 				$found = true;
1110 1208
 			}
1111 1209
 			if ($decode != '' && array_key_exists('Arrival airport',$decode)) {
1112 1210
 				$airport_info = $Spotter->getAllAirportInfo($decode['Arrival airport']);
1113
-				if (isset($airport_info[0]['icao'])) $decode['Arrival airport'] = '<a href="'.$globalURL.'/airport/'.$airport_info[0]['icao'].'">'.$airport_info[0]['city'].','.$airport_info[0]['country'].' ('.$airport_info[0]['icao'].')</a>';
1211
+				if (isset($airport_info[0]['icao'])) {
1212
+					$decode['Arrival airport'] = '<a href="'.$globalURL.'/airport/'.$airport_info[0]['icao'].'">'.$airport_info[0]['city'].','.$airport_info[0]['country'].' ('.$airport_info[0]['icao'].')</a>';
1213
+				}
1114 1214
 				$found = true;
1115 1215
 			}
1116 1216
 			if ($decode != '' && array_key_exists('Airport/Waypoint name',$decode)) {
@@ -1120,7 +1220,9 @@  discard block
 block discarded – undo
1120 1220
 					$found = true;
1121 1221
 				}
1122 1222
 			}
1123
-			if ($found) $row['decode'] = json_encode($decode);
1223
+			if ($found) {
1224
+				$row['decode'] = json_encode($decode);
1225
+			}
1124 1226
 			$data = array_merge($data,array('registration' => $row['registration'],'message' => $row['message'], 'date' => $row['date'], 'ident' => $icao, 'decode' => $row['decode']));
1125 1227
 			$result[] = $data;
1126 1228
 			$i++;
@@ -1128,7 +1230,9 @@  discard block
 block discarded – undo
1128 1230
 		if (!empty($result)) {
1129 1231
 			$result[0]['query_number_rows'] = $i;
1130 1232
 			return $result;
1131
-		} else return array();
1233
+		} else {
1234
+			return array();
1235
+		}
1132 1236
 	}
1133 1237
 
1134 1238
     /**
@@ -1147,25 +1251,37 @@  discard block
 block discarded – undo
1147 1251
 		$ident = trim($ident);
1148 1252
 		$Translation = new Translation($this->db);
1149 1253
 		$Spotter = new Spotter($this->db);
1150
-		if ($globalDebug) echo "Test if we add ModeS data...";
1254
+		if ($globalDebug) {
1255
+			echo "Test if we add ModeS data...";
1256
+		}
1151 1257
 		//if ($icao == '') $icao = ACARS->ident2icao($ident);
1152
-		if ($icao == '') $icao = $Translation->checkTranslation($ident);
1153
-		if ($globalDebug) echo '- Ident : '.$icao.' - ';
1258
+		if ($icao == '') {
1259
+			$icao = $Translation->checkTranslation($ident);
1260
+		}
1261
+		if ($globalDebug) {
1262
+			echo '- Ident : '.$icao.' - ';
1263
+		}
1154 1264
 		if ($ident == '' || $registration == '') {
1155
-			if ($globalDebug) echo "Ident or registration null, exit\n";
1265
+			if ($globalDebug) {
1266
+				echo "Ident or registration null, exit\n";
1267
+			}
1156 1268
 			return '';
1157 1269
 		}
1158 1270
 		$registration = str_replace('.','',$registration);
1159 1271
 		$ident = $Translation->ident2icao($ident);
1160 1272
 		// Check if a flight with same registration is flying now, if ok check if callsign = name in ACARS, else add it to translation
1161
-		if ($globalDebug) echo "Check if needed to add translation ".$ident.'... ';
1273
+		if ($globalDebug) {
1274
+			echo "Check if needed to add translation ".$ident.'... ';
1275
+		}
1162 1276
 		$querysi = "SELECT ident FROM spotter_live s,aircraft_modes a WHERE a.ModeS = s.ModeS AND a.Registration = :registration AND s.format_source <> 'ACARS' LIMIT 1";
1163 1277
 		$querysi_values = array(':registration' => $registration);
1164 1278
 		try {
1165 1279
 			$sthsi = $this->db->prepare($querysi);
1166 1280
 			$sthsi->execute($querysi_values);
1167 1281
 		} catch(PDOException $e) {
1168
-			if ($globalDebug) echo $e->getMessage();
1282
+			if ($globalDebug) {
1283
+				echo $e->getMessage();
1284
+			}
1169 1285
 			return "error : ".$e->getMessage();
1170 1286
 		}
1171 1287
 		$resultsi = $sthsi->fetch(PDO::FETCH_ASSOC);
@@ -1173,9 +1289,14 @@  discard block
 block discarded – undo
1173 1289
 		if (count($resultsi) > 0 && $resultsi['ident'] != $ident && $resultsi['ident'] != '') {
1174 1290
 			$Translation = new Translation($this->db);
1175 1291
 			$trans_ident = $Translation->getOperator($resultsi['ident']);
1176
-			if ($globalDebug) echo 'Add translation to table : '.$ident.' -> '.$resultsi['ident'].' ';
1177
-			if ($ident != $trans_ident) $Translation->addOperator($resultsi['ident'],$ident,'ACARS');
1178
-			elseif ($trans_ident == $ident) $Translation->updateOperator($resultsi['ident'],$ident,'ACARS');
1292
+			if ($globalDebug) {
1293
+				echo 'Add translation to table : '.$ident.' -> '.$resultsi['ident'].' ';
1294
+			}
1295
+			if ($ident != $trans_ident) {
1296
+				$Translation->addOperator($resultsi['ident'],$ident,'ACARS');
1297
+			} elseif ($trans_ident == $ident) {
1298
+				$Translation->updateOperator($resultsi['ident'],$ident,'ACARS');
1299
+			}
1179 1300
 		} else {
1180 1301
 			if ($registration != '' && $latitude != '' && $longitude != '') {
1181 1302
 				$query = "SELECT ModeS FROM aircraft_modes WHERE Registration = :registration LIMIT 1";
@@ -1184,32 +1305,46 @@  discard block
 block discarded – undo
1184 1305
 					$sth = $this->db->prepare($query);
1185 1306
 					$sth->execute($query_values);
1186 1307
 				} catch(PDOException $e) {
1187
-					if ($globalDebug) echo $e->getMessage();
1308
+					if ($globalDebug) {
1309
+						echo $e->getMessage();
1310
+					}
1188 1311
 					return "error : ".$e->getMessage();
1189 1312
 				}
1190 1313
 				$result = $sth->fetch(PDO::FETCH_ASSOC);
1191 1314
 				$sth->closeCursor();
1192
-				if (isset($result['modes'])) $hex = $result['modes'];
1193
-				else $hex = '';
1315
+				if (isset($result['modes'])) {
1316
+					$hex = $result['modes'];
1317
+				} else {
1318
+					$hex = '';
1319
+				}
1194 1320
 				$SI_data = array('hex' => $hex,'ident' => $ident,'aircraft_icao' => $ICAOTypeCode,'registration' => $registration,'latitude' => $latitude,'$longitude' => $longitude,'format_source' => 'ACARS');
1195
-				if ($this->fromACARSscript) $this->SI->add($SI_data);
1321
+				if ($this->fromACARSscript) {
1322
+					$this->SI->add($SI_data);
1323
+				}
1196 1324
 			}
1197 1325
 		}
1198
-		if ($globalDebug) echo 'Done'."\n";
1326
+		if ($globalDebug) {
1327
+			echo 'Done'."\n";
1328
+		}
1199 1329
 		$query = "SELECT flightaware_id, ModeS FROM spotter_output WHERE ident = :ident AND format_source <> 'ACARS' ORDER BY spotter_id DESC LIMIT 1";
1200 1330
 		$query_values = array(':ident' => $icao);
1201 1331
 		try {
1202 1332
 			$sth = $this->db->prepare($query);
1203 1333
 			$sth->execute($query_values);
1204 1334
 		} catch(PDOException $e) {
1205
-			if ($globalDebug) echo $e->getMessage();
1335
+			if ($globalDebug) {
1336
+				echo $e->getMessage();
1337
+			}
1206 1338
 			return "error : ".$e->getMessage();
1207 1339
 		}
1208 1340
 		$result = $sth->fetch(PDO::FETCH_ASSOC);
1209 1341
 		$sth->closeCursor();
1210 1342
 		if (isset($result['flightaware_id'])) {
1211
-			if (isset($result['ModeS'])) $ModeS = $result['ModeS'];
1212
-			else $ModeS = '';
1343
+			if (isset($result['ModeS'])) {
1344
+				$ModeS = $result['ModeS'];
1345
+			} else {
1346
+				$ModeS = '';
1347
+			}
1213 1348
 			if ($ModeS == '') {
1214 1349
 				$id = explode('-',$result['flightaware_id']);
1215 1350
 				$ModeS = $id[0];
@@ -1222,24 +1357,32 @@  discard block
 block discarded – undo
1222 1357
 					$sthc = $this->db->prepare($queryc);
1223 1358
 					$sthc->execute($queryc_values);
1224 1359
 				} catch(PDOException $e) {
1225
-					if ($globalDebug) echo $e->getMessage();
1360
+					if ($globalDebug) {
1361
+						echo $e->getMessage();
1362
+					}
1226 1363
 					return "error : ".$e->getMessage();
1227 1364
 				}
1228 1365
 				$row = $sthc->fetch(PDO::FETCH_ASSOC);
1229 1366
 				$sthc->closeCursor();
1230 1367
 				if (count($row) ==  0) {
1231
-					if ($globalDebug) echo " Add to ModeS table - ";
1368
+					if ($globalDebug) {
1369
+						echo " Add to ModeS table - ";
1370
+					}
1232 1371
 					$queryi = "INSERT INTO aircraft_modes (ModeS,ModeSCountry,Registration,ICAOTypeCode,Source) VALUES (:ModeS,:ModeSCountry,:Registration, :ICAOTypeCode,'ACARS')";
1233 1372
 					$queryi_values = array(':ModeS' => $ModeS,':ModeSCountry' => $country,':Registration' => $registration, ':ICAOTypeCode' => $ICAOTypeCode);
1234 1373
 					try {
1235 1374
 						$sthi = $this->db->prepare($queryi);
1236 1375
 						$sthi->execute($queryi_values);
1237 1376
 					} catch(PDOException $e) {
1238
-						if ($globalDebug) echo $e->getMessage();
1377
+						if ($globalDebug) {
1378
+							echo $e->getMessage();
1379
+						}
1239 1380
 						return "error : ".$e->getMessage();
1240 1381
 					}
1241 1382
 				} else {
1242
-					if ($globalDebug) echo " Update ModeS table - ";
1383
+					if ($globalDebug) {
1384
+						echo " Update ModeS table - ";
1385
+					}
1243 1386
 					if ($ICAOTypeCode != '') {
1244 1387
 						$queryi = "UPDATE aircraft_modes SET ModeSCountry = :ModeSCountry,Registration = :Registration,ICAOTypeCode = :ICAOTypeCode,Source = 'ACARS',LastModified = NOW() WHERE ModeS = :ModeS";
1245 1388
 						$queryi_values = array(':ModeS' => $ModeS,':ModeSCountry' => $country,':Registration' => $registration, ':ICAOTypeCode' => $ICAOTypeCode);
@@ -1251,7 +1394,9 @@  discard block
 block discarded – undo
1251 1394
 						$sthi = $this->db->prepare($queryi);
1252 1395
 						$sthi->execute($queryi_values);
1253 1396
 					} catch(PDOException $e) {
1254
-						if ($globalDebug) echo $e->getMessage();
1397
+						if ($globalDebug) {
1398
+							echo $e->getMessage();
1399
+						}
1255 1400
 						return "error : ".$e->getMessage();
1256 1401
 					}
1257 1402
 				}
@@ -1272,7 +1417,9 @@  discard block
 block discarded – undo
1272 1417
 					    return "error : ".$e->getMessage();
1273 1418
 				}
1274 1419
 				*/
1275
-				if ($globalDebug) echo " Update Spotter_output table - ";
1420
+				if ($globalDebug) {
1421
+					echo " Update Spotter_output table - ";
1422
+				}
1276 1423
 				if ($ICAOTypeCode != '') {
1277 1424
 					if ($globalDBdriver == 'mysql') {
1278 1425
 						$queryi = "UPDATE spotter_output SET registration = :Registration,aircraft_icao = :ICAOTypeCode WHERE ident = :ident AND date >= date_sub(UTC_TIMESTAMP(), INTERVAL 1 HOUR)";
@@ -1283,8 +1430,7 @@  discard block
 block discarded – undo
1283 1430
 				} else {
1284 1431
 					if ($globalDBdriver == 'mysql') {
1285 1432
 						$queryi = "UPDATE spotter_output SET registration = :Registration WHERE ident = :ident AND date >= date_sub(UTC_TIMESTAMP(), INTERVAL 1 HOUR)";
1286
-					}
1287
-					elseif ($globalDBdriver == 'pgsql') {
1433
+					} elseif ($globalDBdriver == 'pgsql') {
1288 1434
 						$queryi = "UPDATE spotter_output SET registration = :Registration WHERE ident = :ident AND date >= NOW() AT TIME ZONE 'UTC' - INTERVAL '1 HOUR'";
1289 1435
 					}
1290 1436
 					$queryi_values = array(':Registration' => $registration,':ident' => $icao);
@@ -1293,14 +1439,20 @@  discard block
 block discarded – undo
1293 1439
 					$sthi = $this->db->prepare($queryi);
1294 1440
 					$sthi->execute($queryi_values);
1295 1441
 				} catch(PDOException $e) {
1296
-					if ($globalDebug) echo $e->getMessage();
1442
+					if ($globalDebug) {
1443
+						echo $e->getMessage();
1444
+					}
1297 1445
 					return "error : ".$e->getMessage();
1298 1446
 				}
1299 1447
 			}
1300 1448
 		} else {
1301
-			if ($globalDebug) echo " Can't find ModeS in spotter_output - ";
1449
+			if ($globalDebug) {
1450
+				echo " Can't find ModeS in spotter_output - ";
1451
+			}
1452
+		}
1453
+		if ($globalDebug) {
1454
+			echo "Done\n";
1302 1455
 		}
1303
-		if ($globalDebug) echo "Done\n";
1304 1456
 		return '';
1305 1457
 	}
1306 1458
 }
Please login to merge, or discard this patch.
airline-detailed.php 2 patches
Braces   +31 added lines, -11 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 		$limit_start = 0;
15 15
 		$limit_end = 25;
16 16
 		$absolute_difference = 25;
17
-	}  else {
17
+	} else {
18 18
 		$limit_explode = explode(",", $_GET['limit']);
19 19
 		$limit_start = filter_var($limit_explode[0],FILTER_SANITIZE_NUMBER_INT);
20 20
 		$limit_end = filter_var($limit_explode[1],FILTER_SANITIZE_NUMBER_INT);
@@ -55,7 +55,9 @@  discard block
 block discarded – undo
55 55
 				$title = sprintf(_("Detailed View for %s (%s)"),$airline_info[0]['name'],$airline_info[0]['icao']);
56 56
 			} elseif (isset($spotter_array[0]['airline_name']) && isset($spotter_array[0]['airline_icao'])) {
57 57
 				$title = sprintf(_("Detailed View for %s (%s)"),$spotter_array[0]['airline_name'],$spotter_array[0]['airline_icao']);
58
-			} else $title = '';
58
+			} else {
59
+				$title = '';
60
+			}
59 61
 		}
60 62
 		require_once('header.php');
61 63
 	  
@@ -76,7 +78,9 @@  discard block
 block discarded – undo
76 78
 		}
77 79
 		$Stats = new Stats();
78 80
 		$airline_names = $Stats->getAllAirlineNames();
79
-		if (empty($airline_names)) $airline_names = $Spotter->getAllAirlineNames();
81
+		if (empty($airline_names)) {
82
+			$airline_names = $Spotter->getAllAirlineNames();
83
+		}
80 84
 		foreach($airline_names as $airline_name)
81 85
 		{
82 86
 			if($airline == $airline_name['airline_icao'])
@@ -108,12 +112,22 @@  discard block
 block discarded – undo
108 112
 					print '<div><span class="label">'._("Name").'</span>'.$airline_info[0]['name'].'</div>';
109 113
 					print '<div><span class="label">'._("Country").'</span>'.$airline_info[0]['country'].'</div>';
110 114
 					print '<div><span class="label">'._("ICAO").'</span>'.$airline_info[0]['icao'].'</div>';
111
-					if ($airline_info[0]['iata'] != '') print '<div><span class="label">'._("IATA").'</span>'.$airline_info[0]['iata'].'</div>';
112
-					if ($airline_info[0]['callsign'] != '') print '<div><span class="label">'._("Callsign").'</span>'.$airline_info[0]['callsign'].'</div>'; 
115
+					if ($airline_info[0]['iata'] != '') {
116
+						print '<div><span class="label">'._("IATA").'</span>'.$airline_info[0]['iata'].'</div>';
117
+					}
118
+					if ($airline_info[0]['callsign'] != '') {
119
+						print '<div><span class="label">'._("Callsign").'</span>'.$airline_info[0]['callsign'].'</div>';
120
+					}
113 121
 					print '<div><span class="label">'._("Type").'</span>'.ucwords($airline_info[0]['type']).'</div>';
114
-					if (isset($airline_info[0]['home_link']) && $airline_info[0]['home_link'] != '') print '<div><a href="'.$airline_info[0]['home_link'].'"><i class="fa fa-home"></i></a></div>';
115
-					if (isset($airline_info[0]['wikipedia_link']) && $airline_info[0]['wikipedia_link'] != '') print '<div><a href="'.$airline_info[0]['wikipedia_link'].'"><i class="fa fa-wikipedia-w"></i></a></div>';
116
-					if (isset($airline_info[0]['ban_eu']) && $airline_info[0]['ban_eu'] == 1) print '<div><img src="'.$globalURL.'/images/baneu.png" alt="'._("This airline is banned in Europe").'" title="'._("This airline is banned in Europe").'" /></div>';
122
+					if (isset($airline_info[0]['home_link']) && $airline_info[0]['home_link'] != '') {
123
+						print '<div><a href="'.$airline_info[0]['home_link'].'"><i class="fa fa-home"></i></a></div>';
124
+					}
125
+					if (isset($airline_info[0]['wikipedia_link']) && $airline_info[0]['wikipedia_link'] != '') {
126
+						print '<div><a href="'.$airline_info[0]['wikipedia_link'].'"><i class="fa fa-wikipedia-w"></i></a></div>';
127
+					}
128
+					if (isset($airline_info[0]['ban_eu']) && $airline_info[0]['ban_eu'] == 1) {
129
+						print '<div><img src="'.$globalURL.'/images/baneu.png" alt="'._("This airline is banned in Europe").'" title="'._("This airline is banned in Europe").'" /></div>';
130
+					}
117 131
 					print '</div>';
118 132
 				
119 133
 				} else {
@@ -129,10 +143,16 @@  discard block
 block discarded – undo
129 143
 					print '<div><span class="label">'._("Name").'</span>'.$spotter_array[0]['airline_name'].'</div>';
130 144
 					print '<div><span class="label">'._("Country").'</span>'.$spotter_array[0]['airline_country'].'</div>';
131 145
 					print '<div><span class="label">'._("ICAO").'</span>'.$spotter_array[0]['airline_icao'].'</div>';
132
-					if (isset($spotter_array[0]['airline_iata']) && $spotter_array[0]['airline_iata'] != '') print '<div><span class="label">'._("IATA").'</span>'.$spotter_array[0]['airline_iata'].'</div>';
133
-					if (isset($spotter_array[0]['airline_callsign']) && $spotter_array[0]['airline_callsign'] != '') print '<div><span class="label">'._("Callsign").'</span>'.$spotter_array[0]['airline_callsign'].'</div>'; 
146
+					if (isset($spotter_array[0]['airline_iata']) && $spotter_array[0]['airline_iata'] != '') {
147
+						print '<div><span class="label">'._("IATA").'</span>'.$spotter_array[0]['airline_iata'].'</div>';
148
+					}
149
+					if (isset($spotter_array[0]['airline_callsign']) && $spotter_array[0]['airline_callsign'] != '') {
150
+						print '<div><span class="label">'._("Callsign").'</span>'.$spotter_array[0]['airline_callsign'].'</div>';
151
+					}
134 152
 					print '<div><span class="label">'._("Type").'</span>'.ucwords($spotter_array[0]['airline_type']).'</div>';
135
-					if (isset($spotter_array[0]['ban_eu']) && $spotter_array[0]['ban_eu'] == 1) print '<div><img src="'.$globalURL.'/images/baneu.png" alt="'._("This airline is banned in Europe").'" title="'._("This airline is banned in Europe").'" /></div>';
153
+					if (isset($spotter_array[0]['ban_eu']) && $spotter_array[0]['ban_eu'] == 1) {
154
+						print '<div><img src="'.$globalURL.'/images/baneu.png" alt="'._("This airline is banned in Europe").'" title="'._("This airline is banned in Europe").'" /></div>';
155
+					}
136 156
 					print '</div>';
137 157
 				}
138 158
 			} else {
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -4,20 +4,20 @@  discard block
 block discarded – undo
4 4
 require_once('require/class.Stats.php');
5 5
 require_once('require/class.Language.php');
6 6
 
7
-if (!isset($_GET['airline'])){
7
+if (!isset($_GET['airline'])) {
8 8
 	header('Location: '.$globalURL.'/airline');
9
-} else{
9
+} else {
10 10
 	$Spotter = new Spotter();
11 11
 	//calculuation for the pagination
12
-	if(!isset($_GET['limit']) || $_GET['limit'] == "")
12
+	if (!isset($_GET['limit']) || $_GET['limit'] == "")
13 13
 	{
14 14
 		$limit_start = 0;
15 15
 		$limit_end = 25;
16 16
 		$absolute_difference = 25;
17
-	}  else {
17
+	} else {
18 18
 		$limit_explode = explode(",", $_GET['limit']);
19
-		$limit_start = filter_var($limit_explode[0],FILTER_SANITIZE_NUMBER_INT);
20
-		$limit_end = filter_var($limit_explode[1],FILTER_SANITIZE_NUMBER_INT);
19
+		$limit_start = filter_var($limit_explode[0], FILTER_SANITIZE_NUMBER_INT);
20
+		$limit_end = filter_var($limit_explode[1], FILTER_SANITIZE_NUMBER_INT);
21 21
 		if (!ctype_digit(strval($limit_start)) || !ctype_digit(strval($limit_end))) {
22 22
 			$limit_start = 0;
23 23
 			$limit_end = 25;
@@ -28,20 +28,20 @@  discard block
 block discarded – undo
28 28
 	$limit_previous_1 = $limit_start - $absolute_difference;
29 29
 	$limit_previous_2 = $limit_end - $absolute_difference;
30 30
 	
31
-	$airline = urldecode(filter_input(INPUT_GET,'airline',FILTER_SANITIZE_STRING));
31
+	$airline = urldecode(filter_input(INPUT_GET, 'airline', FILTER_SANITIZE_STRING));
32 32
 	$page_url = $globalURL.'/airline/'.$airline;
33 33
 	$alliance = false;
34
-	$sort = filter_input(INPUT_GET,'sort',FILTER_SANITIZE_STRING);
34
+	$sort = filter_input(INPUT_GET, 'sort', FILTER_SANITIZE_STRING);
35 35
 	$airline_info = array();
36
-	if (strpos($airline,'alliance_') !== FALSE) {
37
-		$spotter_array = $Spotter->getSpotterDataByAirline('',$limit_start.",".$absolute_difference, $sort,array('alliance' => str_replace('_',' ',str_replace('alliance_','',$airline))));
36
+	if (strpos($airline, 'alliance_') !== FALSE) {
37
+		$spotter_array = $Spotter->getSpotterDataByAirline('', $limit_start.",".$absolute_difference, $sort, array('alliance' => str_replace('_', ' ', str_replace('alliance_', '', $airline))));
38 38
 		$alliance = true;
39 39
 	} else {
40
-		$spotter_array = $Spotter->getSpotterDataByAirline($airline,$limit_start.",".$absolute_difference, $sort);
40
+		$spotter_array = $Spotter->getSpotterDataByAirline($airline, $limit_start.",".$absolute_difference, $sort);
41 41
 		if (isset($globalIVAO)) {
42
-			$airline_info = $Spotter->getAllAirlineInfo($airline,'ivao');
42
+			$airline_info = $Spotter->getAllAirlineInfo($airline, 'ivao');
43 43
 		} elseif (isset($globalVATSIM)) {
44
-			$airline_info = $Spotter->getAllAirlineInfo($airline,'vatsim');
44
+			$airline_info = $Spotter->getAllAirlineInfo($airline, 'vatsim');
45 45
 		} else {
46 46
 			$airline_info = $Spotter->getAllAirlineInfo($airline);
47 47
 		}
@@ -49,12 +49,12 @@  discard block
 block discarded – undo
49 49
 	if (!empty($spotter_array) || !empty($airline_info))
50 50
 	{
51 51
 		if ($alliance) {
52
-			$title = sprintf(_("Detailed View for %s"),str_replace('_',' ',str_replace('alliance_','',$airline)));
52
+			$title = sprintf(_("Detailed View for %s"), str_replace('_', ' ', str_replace('alliance_', '', $airline)));
53 53
 		} else {
54 54
 			if (isset($airline_info[0]['name']) && isset($airline_info[0]['icao'])) {
55
-				$title = sprintf(_("Detailed View for %s (%s)"),$airline_info[0]['name'],$airline_info[0]['icao']);
55
+				$title = sprintf(_("Detailed View for %s (%s)"), $airline_info[0]['name'], $airline_info[0]['icao']);
56 56
 			} elseif (isset($spotter_array[0]['airline_name']) && isset($spotter_array[0]['airline_icao'])) {
57
-				$title = sprintf(_("Detailed View for %s (%s)"),$spotter_array[0]['airline_name'],$spotter_array[0]['airline_icao']);
57
+				$title = sprintf(_("Detailed View for %s (%s)"), $spotter_array[0]['airline_name'], $spotter_array[0]['airline_icao']);
58 58
 			} else $title = '';
59 59
 		}
60 60
 		require_once('header.php');
@@ -66,10 +66,10 @@  discard block
 block discarded – undo
66 66
 		$alliances = $Spotter->getAllAllianceNames();
67 67
 		if (!empty($alliances)) {
68 68
 			foreach ($alliances as $al) {
69
-				if ($alliance && str_replace('_',' ',str_replace('alliance_','',$airline)) == $al['alliance']) {
70
-					print '<option value="alliance_'.str_replace(' ','_',$al['alliance']).'" selected>'.$al['alliance'].'</option>';
69
+				if ($alliance && str_replace('_', ' ', str_replace('alliance_', '', $airline)) == $al['alliance']) {
70
+					print '<option value="alliance_'.str_replace(' ', '_', $al['alliance']).'" selected>'.$al['alliance'].'</option>';
71 71
 				} else {
72
-					print '<option value="alliance_'.str_replace(' ','_',$al['alliance']).'">'.$al['alliance'].'</option>';
72
+					print '<option value="alliance_'.str_replace(' ', '_', $al['alliance']).'">'.$al['alliance'].'</option>';
73 73
 				}
74 74
 			}
75 75
 			print '<option disabled>───────────────</option>';
@@ -77,9 +77,9 @@  discard block
 block discarded – undo
77 77
 		$Stats = new Stats();
78 78
 		$airline_names = $Stats->getAllAirlineNames();
79 79
 		if (empty($airline_names)) $airline_names = $Spotter->getAllAirlineNames();
80
-		foreach($airline_names as $airline_name)
80
+		foreach ($airline_names as $airline_name)
81 81
 		{
82
-			if($airline == $airline_name['airline_icao'])
82
+			if ($airline == $airline_name['airline_icao'])
83 83
 			{
84 84
 				print '<option value="'.$airline_name['airline_icao'].'" selected="selected">'.$airline_name['airline_name'].' ('.$airline_name['airline_icao'].')</option>';
85 85
 			} else {
@@ -137,12 +137,12 @@  discard block
 block discarded – undo
137 137
 				}
138 138
 			} else {
139 139
 				print '<div class="info column">';
140
-				print '<h1>'.str_replace('_',' ',str_replace('alliance_','',$airline)).'</h1>';
141
-				if (@getimagesize($globalURL.'/images/airlines/'.str_replace('alliance_','',$airline).'.png') || @getimagesize('images/airlines/'.str_replace('alliance_','',$airline).'.png'))
140
+				print '<h1>'.str_replace('_', ' ', str_replace('alliance_', '', $airline)).'</h1>';
141
+				if (@getimagesize($globalURL.'/images/airlines/'.str_replace('alliance_', '', $airline).'.png') || @getimagesize('images/airlines/'.str_replace('alliance_', '', $airline).'.png'))
142 142
 				{
143
-					print '<img src="'.$globalURL.'/images/airlines/'.str_replace('alliance_','',$airline).'.png" alt="'.str_replace('_',' ',str_replace('alliance_','',$airline)).'" title="'.str_replace('_',' ',str_replace('alliance_','',$airline)).'" class="logo" />';
143
+					print '<img src="'.$globalURL.'/images/airlines/'.str_replace('alliance_', '', $airline).'.png" alt="'.str_replace('_', ' ', str_replace('alliance_', '', $airline)).'" title="'.str_replace('_', ' ', str_replace('alliance_', '', $airline)).'" class="logo" />';
144 144
 				}
145
-				print '<div><span class="label">'._("Name").'</span>'.str_replace('_',' ',str_replace('alliance_','',$airline)).'</div>';
145
+				print '<div><span class="label">'._("Name").'</span>'.str_replace('_', ' ', str_replace('alliance_', '', $airline)).'</div>';
146 146
 				print '</div>';
147 147
 			}
148 148
 		} else {
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 			include('airline-sub-menu.php');
154 154
 			print '<div class="table column">';
155 155
 			if (isset($spotter_array[0]['airline_name']) && $alliance === false) {
156
-				print '<p>'.sprintf(_("The table below shows the detailed information of all flights from <strong>%s</strong>."),$spotter_array[0]['airline_name']).'</p>';
156
+				print '<p>'.sprintf(_("The table below shows the detailed information of all flights from <strong>%s</strong>."), $spotter_array[0]['airline_name']).'</p>';
157 157
 			}
158 158
 			include('table-output.php');  
159 159
 			print '<div class="pagination">';
Please login to merge, or discard this patch.
table-output.php 3 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 				}
366 366
 			}
367 367
 		}
368
-    		if ($type == 'aircraft') {
368
+			if ($type == 'aircraft') {
369 369
 			if ((isset($globalUsePilot) && $globalUsePilot) || (!isset($globalUsePilot) && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalVAM) && $globalVAM) || (isset($globalphpVMS) && $globalphpVMS)))) {
370 370
 				print '<th class="pilot"><span class="nomobile">'._("Pilot name").'</span><span class="mobile">'._("Pilot").'</span></a></th>';
371 371
 			}
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
 	} elseif(strtolower($current_page) != "currently" && strtolower($current_page) != "upcoming" && strtolower($current_page) != "acars-latest" && strtolower($current_page) != "acars-archive" && strtolower($current_page) != "accident-latest" && strtolower($current_page) != "incident-latest" && strtolower($current_page) != "accident-detailed" && strtolower($current_page) != "incident-detailed"){
724 724
 		if ($type == 'aircraft') {
725 725
 			if (!isset($spotter_item['squawk']) || $spotter_item['squawk'] == 0) {
726
-			    $spotter_item['squawk'] = '-';
726
+				$spotter_item['squawk'] = '-';
727 727
 			}
728 728
 			if ($spotter_item['image_thumbnail'] != "")
729 729
 			{
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
 				print '</td>'."\n";
763 763
 			} else {
764 764
 				print '<td class="aircraft_thumbnail">'."\n";
765
-	       //   	 	print '<a href="'.$globalURL.'/flightid/'.$spotter_item['spotter_id'].'"><img src="'.$globalURL.'/images/placeholder_thumb.png" alt="Click to see more information about this flight" title="Click to see more information about this flight" width="100px" /></a>';
765
+		   //   	 	print '<a href="'.$globalURL.'/flightid/'.$spotter_item['spotter_id'].'"><img src="'.$globalURL.'/images/placeholder_thumb.png" alt="Click to see more information about this flight" title="Click to see more information about this flight" width="100px" /></a>';
766 766
 		//}
767 767
 				if (!isset($spotter_item['airline_name']) && !isset($spotter_item['aircraft_name'])) {
768 768
 					print '<a href="'.$globalURL.'/flightid/'.$spotter_item['spotter_id'].'"><img src="'.$globalURL.'/images/placeholder_thumb.png" class="img-rounded" data-toggle="popover" title="'.$spotter_item['registration'].' - '.$spotter_item['aircraft_type'].' - '._("Not available").'" alt="'.$spotter_item['registration'].' - '.$spotter_item['aircraft_type'].' - '._("Not available").'" data-content="'._("Registration:").' '.$spotter_item['registration'].'<br />'._("Aircraft:").' '._("Not available").' ('.$spotter_item['aircraft_type'].')<br />'._("Airline:").' '._("Not available").'<br />'._("Squawk:").' '.$spotter_item['squawk'].'" data-html="true" width="100px" /></a>'."\n";
@@ -1034,11 +1034,11 @@  discard block
 block discarded – undo
1034 1034
 					if (!isset($Spotter)) $Spotter = new Spotter();
1035 1035
 					$arrival_airport_info = $Spotter->getAllAirportInfo($spotter_item['real_arrival_airport']);
1036 1036
 					if (isset($arrival_airport_info[0])) {
1037
-                        print '<br /><span class="nomobile">' . _("Real:") . ' <a href="' . $globalURL . '/airport/' . $spotter_item['real_arrival_airport'] . '">' . $arrival_airport_info[0]['city'] . ',' . $arrival_airport_info[0]['country'] . ' (' . $spotter_item['real_arrival_airport'] . ')</a></span>' . "\n";
1038
-                    }
1039
-                    print '<span class="mobile">'._("Scheduled:").' <a href="'.$globalURL.'/airport/'.$spotter_item['real_arrival_airport'].'">'.$spotter_item['real_arrival_airport'].'</a></span>'."\n";
1040
-                    if (isset($arrival_airport_info[0])) {
1041
-                        print '<span class="mobile">'._("Real:").' <a href="'.$globalURL.'/airport/'.$spotter_item['real_arrival_airport'].'">'.$arrival_airport_info[0]['city'].','.$arrival_airport_info[0]['country'].' ('.$spotter_item['real_arrival_airport'].')</a></span>'."\n";
1037
+						print '<br /><span class="nomobile">' . _("Real:") . ' <a href="' . $globalURL . '/airport/' . $spotter_item['real_arrival_airport'] . '">' . $arrival_airport_info[0]['city'] . ',' . $arrival_airport_info[0]['country'] . ' (' . $spotter_item['real_arrival_airport'] . ')</a></span>' . "\n";
1038
+					}
1039
+					print '<span class="mobile">'._("Scheduled:").' <a href="'.$globalURL.'/airport/'.$spotter_item['real_arrival_airport'].'">'.$spotter_item['real_arrival_airport'].'</a></span>'."\n";
1040
+					if (isset($arrival_airport_info[0])) {
1041
+						print '<span class="mobile">'._("Real:").' <a href="'.$globalURL.'/airport/'.$spotter_item['real_arrival_airport'].'">'.$arrival_airport_info[0]['city'].','.$arrival_airport_info[0]['country'].' ('.$spotter_item['real_arrival_airport'].')</a></span>'."\n";
1042 1042
 					}
1043 1043
 				} elseif ($spotter_item['arrival_airport'] != 'NA') {
1044 1044
 					print '<span class="nomobile"><a href="'.$globalURL.'/airport/'.$spotter_item['arrival_airport'].'">'.$spotter_item['arrival_airport_city'].', '.$spotter_item['arrival_airport_country'].' ('.$spotter_item['arrival_airport'].')</a></span>'."\n";
Please login to merge, or discard this patch.
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -4,15 +4,15 @@  discard block
 block discarded – undo
4 4
 
5 5
 require_once(dirname(__FILE__).'/require/class.Common.php');
6 6
 $Common = new Common();
7
-$showRouteStop = $Common->multiKeyExists($spotter_array,'route_stop');
7
+$showRouteStop = $Common->multiKeyExists($spotter_array, 'route_stop');
8 8
 if (isset($globalVM) && $globalVM && isset($type) && $type == 'marine') {
9
-	$showDuration = $Common->multiKeyExists($spotter_array,'race_time');
10
-	if ($showDuration === false) $showDuration = $Common->multiKeyExists($spotter_array,'duration');
9
+	$showDuration = $Common->multiKeyExists($spotter_array, 'race_time');
10
+	if ($showDuration === false) $showDuration = $Common->multiKeyExists($spotter_array, 'duration');
11 11
 } else {
12
-	$showDuration = $Common->multiKeyExists($spotter_array,'duration');
12
+	$showDuration = $Common->multiKeyExists($spotter_array, 'duration');
13 13
 }
14 14
 if (isset($globalVM) && $globalVM && isset($type) && $type == 'marine') {
15
-	$showDistance = $Common->multiKeyExists($spotter_array,'distance');
15
+	$showDistance = $Common->multiKeyExists($spotter_array, 'distance');
16 16
 }
17 17
 
18 18
 
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 	}
179 179
 	print '<th class="more"></th>';
180 180
 	print '</thead>';
181
-} else if (strtolower($current_page) == "upcoming"){
181
+} else if (strtolower($current_page) == "upcoming") {
182 182
 	print '<thead>';
183 183
 	if (!isset($globalNoAirlines) || $globalNoAirlines === FALSE) {
184 184
 		if ($_GET['sort'] == "airline_name_asc")
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 	}
233 233
 	*/
234 234
 	print '</thead>';
235
-} else if (strtolower($current_page) == "acars-latest" || strtolower($current_page) == "acars-archive"){
235
+} else if (strtolower($current_page) == "acars-latest" || strtolower($current_page) == "acars-archive") {
236 236
 	print '<thead>';
237 237
 	print '<th class="aircraft_thumbnail"></th>';
238 238
 	print '<th class="logo">'._("Airline").'</th>';
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 	print '</thead>';
270 270
 } else {
271 271
 
272
-	if ($hide_th_links === true){
272
+	if ($hide_th_links === true) {
273 273
 		print '<thead>';
274 274
 		if ($type == 'marine' && isset($globalVM) && $globalVM) {
275 275
 			print '<th class="rank">'._("Rank").'</th>';
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
 }
588 588
 
589 589
 print '<tbody>'."\n";
590
-foreach($spotter_array as $spotter_item)
590
+foreach ($spotter_array as $spotter_item)
591 591
 {
592 592
 	if (isset($globalTimezone))
593 593
 	{
@@ -622,13 +622,13 @@  discard block
 block discarded – undo
622 622
 						$image_src = 'https://www.planespotters.net/Aviation_Photos/photo.show?id='.$planespotter_id;
623 623
 					}
624 624
 					if (isset($spotter_item['airline_name'])) {
625
-						print '<a href="'.$image_src.'"><img src="'.preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']).'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['registration'].' - '.$spotter_item['airline_name'].'" alt="'.$spotter_item['registration'].' - '.$spotter_item['airline_name'].'" data-content="'._("Registration:").' '.$spotter_item['registration'].'<br />'._("Airline:").' '.$spotter_item['airline_name'].'" data-html="true" width="100px" /></a>'."\n".'<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
625
+						print '<a href="'.$image_src.'"><img src="'.preg_replace("/^http:/i", "https:", $spotter_item['image_thumbnail']).'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['registration'].' - '.$spotter_item['airline_name'].'" alt="'.$spotter_item['registration'].' - '.$spotter_item['airline_name'].'" data-content="'._("Registration:").' '.$spotter_item['registration'].'<br />'._("Airline:").' '.$spotter_item['airline_name'].'" data-html="true" width="100px" /></a>'."\n".'<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
626 626
 					} else {
627
-						print '<a href="'.$image_src.'"><img src="'.preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']).'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['registration'].' - '._("Not available").'" alt="'.$spotter_item['registration'].' - '._("Not available").'" data-content="'._("Registration:").' '.$spotter_item['registration'].'<br />'._("Airline:").' '._("Not available").'" data-html="true" width="100px" /></a>'."\n".'<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
627
+						print '<a href="'.$image_src.'"><img src="'.preg_replace("/^http:/i", "https:", $spotter_item['image_thumbnail']).'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['registration'].' - '._("Not available").'" alt="'.$spotter_item['registration'].' - '._("Not available").'" data-content="'._("Registration:").' '.$spotter_item['registration'].'<br />'._("Airline:").' '._("Not available").'" data-html="true" width="100px" /></a>'."\n".'<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
628 628
 					}
629 629
 				} else {
630 630
 					if ($spotter_item['image_source'] == 'wikimedia' || $spotter_item['image_source'] == 'devianart' || $spotter_item['image_source'] == 'flickr') {
631
-						$image_thumbnail = preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']);
631
+						$image_thumbnail = preg_replace("/^http:/i", "https:", $spotter_item['image_thumbnail']);
632 632
 					} else 	$image_thumbnail = $spotter_item['image_thumbnail'];
633 633
 					if (isset($spotter_item['airline_name'])) {
634 634
 						print '<img src="'.$image_thumbnail.'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['registration'].' - '.$spotter_item['airline_name'].'" alt="'.$spotter_item['registration'].' - '.$spotter_item['airline_name'].'" data-content="'._("Registration:").' '.$spotter_item['registration'].'<br />'._("Airline:").' '.$spotter_item['airline_name'].'" data-html="true" width="100px" />'."\n".'<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
 			{
655 655
 				print '<td class="aircraft_thumbnail">'."\n";
656 656
 				if ($spotter_item['image_source'] == 'wikimedia' || $spotter_item['image_source'] == 'devianart' || $spotter_item['image_source'] == 'flickr') {
657
-					$image_thumbnail = preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']);
657
+					$image_thumbnail = preg_replace("/^http:/i", "https:", $spotter_item['image_thumbnail']);
658 658
 				} else 	$image_thumbnail = $spotter_item['image_thumbnail'];
659 659
 				if (isset($spotter_item['mmsi']) && $spotter_item['mmsi'] != '') {
660 660
 					print '<img src="'.$image_thumbnail.'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['mmsi'].'" alt="'.$spotter_item['mmsi'].'" data-content="'._("MMSI:").' '.$spotter_item['mmsi'].'" data-html="true" width="100px" />'."\n".'<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 			{
677 677
 				print '<td class="aircraft_thumbnail">'."\n";
678 678
 				if ($spotter_item['image_source'] == 'wikimedia' || $spotter_item['image_source'] == 'devianart' || $spotter_item['image_source'] == 'flickr') {
679
-					$image_thumbnail = preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']);
679
+					$image_thumbnail = preg_replace("/^http:/i", "https:", $spotter_item['image_thumbnail']);
680 680
 				} else 	$image_thumbnail = $spotter_item['image_thumbnail'];
681 681
 				print '<img src="'.$image_thumbnail.'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['ident'].'" alt="'.$spotter_item['type'].'" data-content="'._("Type:").' '.$spotter_item['type'].'" data-html="true" width="100px" />'."\n".'<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
682 682
 				print '</td>'."\n";
@@ -720,7 +720,7 @@  discard block
 block discarded – undo
720 720
 				print '</td>'."\n";
721 721
 			}
722 722
 		}
723
-	} elseif(strtolower($current_page) != "currently" && strtolower($current_page) != "upcoming" && strtolower($current_page) != "acars-latest" && strtolower($current_page) != "acars-archive" && strtolower($current_page) != "accident-latest" && strtolower($current_page) != "incident-latest" && strtolower($current_page) != "accident-detailed" && strtolower($current_page) != "incident-detailed"){
723
+	} elseif (strtolower($current_page) != "currently" && strtolower($current_page) != "upcoming" && strtolower($current_page) != "acars-latest" && strtolower($current_page) != "acars-archive" && strtolower($current_page) != "accident-latest" && strtolower($current_page) != "incident-latest" && strtolower($current_page) != "accident-detailed" && strtolower($current_page) != "incident-detailed") {
724 724
 		if ($type == 'aircraft') {
725 725
 			if (!isset($spotter_item['squawk']) || $spotter_item['squawk'] == 0) {
726 726
 			    $spotter_item['squawk'] = '-';
@@ -737,17 +737,17 @@  discard block
 block discarded – undo
737 737
 						$image_src = 'https://www.planespotters.net/Aviation_Photos/photo.show?id='.$planespotter_id;
738 738
 					}
739 739
 					if (!isset($spotter_item['airline_name']) && isset($spotter_item['aircraft_name'])) {
740
-						print '<a href="'.$image_src.'"><img src="'.preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']).'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['registration'].' - '.$spotter_item['aircraft_type'].' - '._("Not available").'" alt="'.$spotter_item['registration'].' - '.$spotter_item['aircraft_type'].' - '._("Not available").'" data-content="'._("Registration:").' '.$spotter_item['registration'].'<br />'._("Aircraft:").' '.$spotter_item['aircraft_name'].' ('.$spotter_item['aircraft_type'].')<br />'._("Airline:").' '._("Not available").'<br />'._("Squawk:").' '.$spotter_item['squawk'].'" data-html="true" width="100px" /></a>'."\n".'<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
740
+						print '<a href="'.$image_src.'"><img src="'.preg_replace("/^http:/i", "https:", $spotter_item['image_thumbnail']).'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['registration'].' - '.$spotter_item['aircraft_type'].' - '._("Not available").'" alt="'.$spotter_item['registration'].' - '.$spotter_item['aircraft_type'].' - '._("Not available").'" data-content="'._("Registration:").' '.$spotter_item['registration'].'<br />'._("Aircraft:").' '.$spotter_item['aircraft_name'].' ('.$spotter_item['aircraft_type'].')<br />'._("Airline:").' '._("Not available").'<br />'._("Squawk:").' '.$spotter_item['squawk'].'" data-html="true" width="100px" /></a>'."\n".'<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
741 741
 					} elseif (!isset($spotter_item['aircraft_name']) && isset($spotter_item['airline_name'])) {
742
-						print '<a href="'.$image_src.'"><img src="'.preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']).'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['registration'].' - '.$spotter_item['aircraft_type'].' - '.$spotter_item['airline_name'].'" alt="'.$spotter_item['registration'].' - '.$spotter_item['aircraft_type'].' - '.$spotter_item['airline_name'].'" data-content="'._("Registration:").' '.$spotter_item['registration'].'<br />'._("Aircraft:").' ('.$spotter_item['aircraft_type'].')<br />'._("Airline:").' '.$spotter_item['airline_name'].'<br />'._("Squawk:").' '.$spotter_item['squawk'].'" data-html="true" width="100px" /></a>'."\n".'<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
742
+						print '<a href="'.$image_src.'"><img src="'.preg_replace("/^http:/i", "https:", $spotter_item['image_thumbnail']).'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['registration'].' - '.$spotter_item['aircraft_type'].' - '.$spotter_item['airline_name'].'" alt="'.$spotter_item['registration'].' - '.$spotter_item['aircraft_type'].' - '.$spotter_item['airline_name'].'" data-content="'._("Registration:").' '.$spotter_item['registration'].'<br />'._("Aircraft:").' ('.$spotter_item['aircraft_type'].')<br />'._("Airline:").' '.$spotter_item['airline_name'].'<br />'._("Squawk:").' '.$spotter_item['squawk'].'" data-html="true" width="100px" /></a>'."\n".'<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
743 743
 					} elseif (!isset($spotter_item['aircraft_name']) && !isset($spotter_item['airline_name'])) {
744
-						print '<a href="'.$image_src.'"><img src="'.preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']).'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['registration'].' - '.$spotter_item['aircraft_type'].' - '._("Not available").'" alt="'.$spotter_item['registration'].' - '.$spotter_item['aircraft_type'].' - '._("Not available").'" data-content="'._("Registration:").' '.$spotter_item['registration'].'<br />'._("Aircraft:").' ('.$spotter_item['aircraft_type'].')<br />'._("Airline:").' '._("Not available").'<br />'._("Squawk:").' '.$spotter_item['squawk'].'" data-html="true" width="100px" /></a>'."\n".'<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
744
+						print '<a href="'.$image_src.'"><img src="'.preg_replace("/^http:/i", "https:", $spotter_item['image_thumbnail']).'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['registration'].' - '.$spotter_item['aircraft_type'].' - '._("Not available").'" alt="'.$spotter_item['registration'].' - '.$spotter_item['aircraft_type'].' - '._("Not available").'" data-content="'._("Registration:").' '.$spotter_item['registration'].'<br />'._("Aircraft:").' ('.$spotter_item['aircraft_type'].')<br />'._("Airline:").' '._("Not available").'<br />'._("Squawk:").' '.$spotter_item['squawk'].'" data-html="true" width="100px" /></a>'."\n".'<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
745 745
 					} else {
746
-						print '<a href="'.$image_src.'"><img src="'.preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']).'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['registration'].' - '.$spotter_item['aircraft_type'].' - '.$spotter_item['airline_name'].'" alt="'.$spotter_item['registration'].' - '.$spotter_item['aircraft_type'].' - '.$spotter_item['airline_name'].'" data-content="'._("Registration:").' '.$spotter_item['registration'].'<br />'._("Aircraft:").' '.$spotter_item['aircraft_name'].' ('.$spotter_item['aircraft_type'].')<br />'._("Airline:").' '.$spotter_item['airline_name'].'<br />'._("Squawk:").' '.$spotter_item['squawk'].'" data-html="true" width="100px" /></a>'."\n".'<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
746
+						print '<a href="'.$image_src.'"><img src="'.preg_replace("/^http:/i", "https:", $spotter_item['image_thumbnail']).'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['registration'].' - '.$spotter_item['aircraft_type'].' - '.$spotter_item['airline_name'].'" alt="'.$spotter_item['registration'].' - '.$spotter_item['aircraft_type'].' - '.$spotter_item['airline_name'].'" data-content="'._("Registration:").' '.$spotter_item['registration'].'<br />'._("Aircraft:").' '.$spotter_item['aircraft_name'].' ('.$spotter_item['aircraft_type'].')<br />'._("Airline:").' '.$spotter_item['airline_name'].'<br />'._("Squawk:").' '.$spotter_item['squawk'].'" data-html="true" width="100px" /></a>'."\n".'<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
747 747
 					}
748 748
 				} else {
749 749
 					if ($spotter_item['image_source'] == 'wikimedia' || $spotter_item['image_source'] == 'devianart' || $spotter_item['image_source'] == 'flickr') {
750
-						$image_thumbnail = preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']);
750
+						$image_thumbnail = preg_replace("/^http:/i", "https:", $spotter_item['image_thumbnail']);
751 751
 					} else 	$image_thumbnail = $spotter_item['image_thumbnail'];
752 752
 					if (!isset($spotter_item['airline_name']) && isset($spotter_item['aircraft_name'])) {
753 753
 						print '<a href="'.$globalURL.'/flightid/'.$spotter_item['spotter_id'].'"><img src="'.$image_thumbnail.'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['registration'].' - '.$spotter_item['aircraft_type'].' - '._("Not available").'" alt="'.$spotter_item['registration'].' - '.$spotter_item['aircraft_type'].' - '._("Not available").'" data-content="'._("Registration:").' '.$spotter_item['registration'].'<br />'._("Aircraft:").' '.$spotter_item['aircraft_name'].' ('.$spotter_item['aircraft_type'].')<br />'._("Airline:").' '._("Not available").'<br />'._("Squawk:").' '.$spotter_item['squawk'].'" data-html="true" width="100px" /></a>'."\n".'<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
 			{
788 788
 				print '<td class="aircraft_thumbnail">'."\n";
789 789
 				if ($spotter_item['image_source'] == 'wikimedia' || $spotter_item['image_source'] == 'devianart' || $spotter_item['image_source'] == 'flickr') {
790
-					$image_thumbnail = preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']);
790
+					$image_thumbnail = preg_replace("/^http:/i", "https:", $spotter_item['image_thumbnail']);
791 791
 				} else 	$image_thumbnail = $spotter_item['image_thumbnail'];
792 792
 				if (isset($spotter_item['mmsi']) && $spotter_item['mmsi'] != '') {
793 793
 					print '<img src="'.$image_thumbnail.'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['mmsi'].'" alt="'.$spotter_item['mmsi'].'" data-content="'._("MMSI:").' '.$spotter_item['mmsi'].'" data-html="true" width="100px" />'."\n";
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
 			{
812 812
 				print '<td class="aircraft_thumbnail">'."\n";
813 813
 				if ($spotter_item['image_source'] == 'wikimedia' || $spotter_item['image_source'] == 'devianart' || $spotter_item['image_source'] == 'flickr') {
814
-					$image_thumbnail = preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']);
814
+					$image_thumbnail = preg_replace("/^http:/i", "https:", $spotter_item['image_thumbnail']);
815 815
 				} else 	$image_thumbnail = $spotter_item['image_thumbnail'];
816 816
 				print '<img src="'.$image_thumbnail.'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['ident'].'" alt="'.$spotter_item['type'].'" data-content="'._("Type:").' '.$spotter_item['type'].'" data-html="true" width="100px" />'."\n".'<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
817 817
 				print '</td>'."\n";
@@ -920,7 +920,7 @@  discard block
 block discarded – undo
920 920
 		print '</td>'."\n";
921 921
 	}
922 922
 	// Aircraft type
923
-	if(strtolower($current_page) != "upcoming" && strtolower($current_page) != "acars-latest" && strtolower($current_page) != "acars-archive"){
923
+	if (strtolower($current_page) != "upcoming" && strtolower($current_page) != "acars-latest" && strtolower($current_page) != "acars-archive") {
924 924
 		print '<td class="type">'."\n";
925 925
 		if ($type == 'aircraft') {
926 926
 			if (!isset($spotter_item['aircraft_type']) && isset($spotter_item['aircraft_name'])) {
@@ -929,7 +929,7 @@  discard block
 block discarded – undo
929 929
 				//print '<span class="nomobile"><a href="'.$globalURL.'/aircraft/'.$spotter_item['aircraft_type'].'">'._("Not available").'</a></span>'."\n";
930 930
 				print '<span class="nomobile"><a href="'.$globalURL.'/aircraft/'.$spotter_item['aircraft_type'].'">'.$spotter_item['aircraft_type'].'</a></span>'."\n";
931 931
 			} else {
932
-				$aircraft_names = explode('/',$spotter_item['aircraft_name']);
932
+				$aircraft_names = explode('/', $spotter_item['aircraft_name']);
933 933
 				if (count($aircraft_names) == 1) print '<span class="nomobile"><a href="'.$globalURL.'/aircraft/'.$spotter_item['aircraft_type'].'">'.$spotter_item['aircraft_manufacturer'].' '.$spotter_item['aircraft_name'].'</a></span>'."\n";
934 934
 				else print '<span class="nomobile"><a href="'.$globalURL.'/aircraft/'.$spotter_item['aircraft_type'].'" title="'.$spotter_item['aircraft_name'].'">'.$spotter_item['aircraft_manufacturer'].' '.$aircraft_names[0].'</a></span>'."\n";
935 935
 			}
@@ -973,22 +973,22 @@  discard block
 block discarded – undo
973 973
 			}
974 974
 			if (isset($spotter_item['departure_airport_time']) && isset($spotter_item['real_departure_airport_time'])) {
975 975
 				if ($spotter_item['departure_airport_time'] > 2460) {
976
-					$departure_airport_time = date('H:m',$spotter_item['departure_airport_time']);
977
-				} else $departure_airport_time = substr($spotter_item['departure_airport_time'],0,-2).':'.substr($spotter_item['departure_airport_time'],-2);
976
+					$departure_airport_time = date('H:m', $spotter_item['departure_airport_time']);
977
+				} else $departure_airport_time = substr($spotter_item['departure_airport_time'], 0, -2).':'.substr($spotter_item['departure_airport_time'], -2);
978 978
 				if ($spotter_item['real_departure_airport_time'] > 2460) {
979
-					$real_departure_airport_time = date('H:m',$spotter_item['real_departure_airport_time']);
979
+					$real_departure_airport_time = date('H:m', $spotter_item['real_departure_airport_time']);
980 980
 				} else $real_departure_airport_time = $spotter_item['real_departure_airport_time'];
981 981
 				print '<br /><span class="airport_time">'.$departure_airport_time.' ('.$real_departure_airport_time.')</span>'."\n";
982 982
 			} elseif (isset($spotter_item['real_departure_airport_time']) && $spotter_item['real_departure_airport_time'] != 'NULL') {
983 983
 				if ($spotter_item['real_departure_airport_time'] > 2460) {
984
-					$real_departure_airport_time = date('H:m',$spotter_item['real_departure_airport_time']);
984
+					$real_departure_airport_time = date('H:m', $spotter_item['real_departure_airport_time']);
985 985
 				} else $real_departure_airport_time = $spotter_item['real_departure_airport_time'];
986 986
 				print '<br /><span class="airport_time">'.$real_departure_airport_time.'</span>'."\n";
987 987
 			} elseif (isset($spotter_item['departure_airport_time']) && $spotter_item['departure_airport_time'] != 'NULL') {
988 988
 				if ($spotter_item['departure_airport_time'] > 2460) {
989
-					$departure_airport_time = date('H:m',$spotter_item['departure_airport_time']);
989
+					$departure_airport_time = date('H:m', $spotter_item['departure_airport_time']);
990 990
 				} else {
991
-					$departure_airport_time = substr($spotter_item['departure_airport_time'],0,-2).':'.substr($spotter_item['departure_airport_time'],-2);
991
+					$departure_airport_time = substr($spotter_item['departure_airport_time'], 0, -2).':'.substr($spotter_item['departure_airport_time'], -2);
992 992
 				}
993 993
 				print '<br /><span class="airport_time">'.$departure_airport_time.'</span>'."\n";
994 994
 			}
@@ -1003,7 +1003,7 @@  discard block
 block discarded – undo
1003 1003
 						$latitude = $spotter_item['latitude'];
1004 1004
 						$longitude = $spotter_item['longitude'];
1005 1005
 					}
1006
-					$distance = $Spotter->getAirportDistance($spotter_item['departure_airport'],$latitude,$longitude);
1006
+					$distance = $Spotter->getAirportDistance($spotter_item['departure_airport'], $latitude, $longitude);
1007 1007
 				} else $distance = '';
1008 1008
 				if ($distance != '') {
1009 1009
 					if ((!isset($_COOKIE['unitdistance']) && isset($globalUnitDistance) && $globalUnitDistance == 'nm') || (isset($_COOKIE['unitdistance']) && $_COOKIE['unitdistance'] == 'nm')) {
@@ -1034,7 +1034,7 @@  discard block
 block discarded – undo
1034 1034
 					if (!isset($Spotter)) $Spotter = new Spotter();
1035 1035
 					$arrival_airport_info = $Spotter->getAllAirportInfo($spotter_item['real_arrival_airport']);
1036 1036
 					if (isset($arrival_airport_info[0])) {
1037
-                        print '<br /><span class="nomobile">' . _("Real:") . ' <a href="' . $globalURL . '/airport/' . $spotter_item['real_arrival_airport'] . '">' . $arrival_airport_info[0]['city'] . ',' . $arrival_airport_info[0]['country'] . ' (' . $spotter_item['real_arrival_airport'] . ')</a></span>' . "\n";
1037
+                        print '<br /><span class="nomobile">'._("Real:").' <a href="'.$globalURL.'/airport/'.$spotter_item['real_arrival_airport'].'">'.$arrival_airport_info[0]['city'].','.$arrival_airport_info[0]['country'].' ('.$spotter_item['real_arrival_airport'].')</a></span>'."\n";
1038 1038
                     }
1039 1039
                     print '<span class="mobile">'._("Scheduled:").' <a href="'.$globalURL.'/airport/'.$spotter_item['real_arrival_airport'].'">'.$spotter_item['real_arrival_airport'].'</a></span>'."\n";
1040 1040
                     if (isset($arrival_airport_info[0])) {
@@ -1050,20 +1050,20 @@  discard block
 block discarded – undo
1050 1050
 			}
1051 1051
 			if (isset($spotter_item['arrival_airport_time']) && isset($spotter_item['real_arrival_airport_time'])) {
1052 1052
 				if ($spotter_item['arrival_airport_time'] > 2460) {
1053
-					$arrival_airport_time = date('H:m',$spotter_item['arrival_airport_time']);
1053
+					$arrival_airport_time = date('H:m', $spotter_item['arrival_airport_time']);
1054 1054
 				} else $arrival_airport_time = $spotter_item['arrival_airport_time'];
1055 1055
 				if ($spotter_item['real_arrival_airport_time'] > 2460) {
1056
-					$real_arrival_airport_time = date('H:m',$spotter_item['real_arrival_airport_time']);
1056
+					$real_arrival_airport_time = date('H:m', $spotter_item['real_arrival_airport_time']);
1057 1057
 				} else $real_arrival_airport_time = $spotter_item['real_arrival_airport_time'];
1058 1058
 				print '<br /><span class="airport_time">'.$spotter_item['arrival_airport_time'].' ('.$spotter_item['real_arrival_airport_time'].')</span>'."\n";
1059 1059
 			} elseif (isset($spotter_item['real_arrival_airport_time'])) {
1060 1060
 				if ($spotter_item['real_arrival_airport_time'] > 2460) {
1061
-					$real_arrival_airport_time = date('H:m',$spotter_item['real_arrival_airport_time']);
1061
+					$real_arrival_airport_time = date('H:m', $spotter_item['real_arrival_airport_time']);
1062 1062
 				} else $real_arrival_airport_time = $spotter_item['real_arrival_airport_time'];
1063 1063
 				print '<br /><span class="airport_time">'.$real_arrival_airport_time.'</span>'."\n";
1064 1064
 			} elseif (isset($spotter_item['arrival_airport_time']) && $spotter_item['arrival_airport_time'] != 'NULL') {
1065 1065
 				if ($spotter_item['arrival_airport_time'] > 2460) {
1066
-					$arrival_airport_time = date('H:m',$spotter_item['arrival_airport_time']);
1066
+					$arrival_airport_time = date('H:m', $spotter_item['arrival_airport_time']);
1067 1067
 				} else $arrival_airport_time = $spotter_item['arrival_airport_time'];
1068 1068
 				print '<br /><span class="airport_time">'.$arrival_airport_time.'</span>'."\n";
1069 1069
 			}
@@ -1076,7 +1076,7 @@  discard block
 block discarded – undo
1076 1076
 						$latitude = $spotter_item['latitude'];
1077 1077
 						$longitude = $spotter_item['longitude'];
1078 1078
 					}
1079
-					$distance = $Spotter->getAirportDistance($spotter_item['arrival_airport'],$latitude,$longitude);
1079
+					$distance = $Spotter->getAirportDistance($spotter_item['arrival_airport'], $latitude, $longitude);
1080 1080
 				} else $distance = '';
1081 1081
 				if ($distance != '') {
1082 1082
 					if ((!isset($_COOKIE['unitdistance']) && isset($globalUnitDistance) && $globalUnitDistance == 'nm') || (isset($_COOKIE['unitdistance']) && $_COOKIE['unitdistance'] == 'nm')) {
@@ -1138,19 +1138,19 @@  discard block
 block discarded – undo
1138 1138
 				print '<span class="mobile">-</span>'."\n";
1139 1139
 			} else {
1140 1140
 				if ((!isset($_COOKIE['unitdistance']) && ((isset($globalUnitDistance) && $globalUnitDistance == 'km') || !isset($globalUnitDistance))) || (isset($_COOKIE['unitdistance']) && $_COOKIE['unitdistance'] == 'km')) {
1141
-					print '<span class="nomobile">'.round($spotter_item['distance'],2).' km</span>'."\n";
1142
-					print '<span class="mobile">'.round($spotter_item['distance'],2).' km</span><br />'."\n";
1141
+					print '<span class="nomobile">'.round($spotter_item['distance'], 2).' km</span>'."\n";
1142
+					print '<span class="mobile">'.round($spotter_item['distance'], 2).' km</span><br />'."\n";
1143 1143
 				} elseif ((!isset($_COOKIE['unitdistance']) && isset($globalUnitDistance) && $globalUnitDistance == 'mi') || (isset($_COOKIE['unitdistance']) && $_COOKIE['unitdistance'] == 'mi')) {
1144
-					print '<span class="nomobile">'.round($spotter_item['distance']*0.621371,2).' mi</span>'."\n";
1145
-					print '<span class="mobile">'.round($spotter_item['distance']*0.621371,2).' mi</span><br />'."\n";
1144
+					print '<span class="nomobile">'.round($spotter_item['distance']*0.621371, 2).' mi</span>'."\n";
1145
+					print '<span class="mobile">'.round($spotter_item['distance']*0.621371, 2).' mi</span><br />'."\n";
1146 1146
 				} elseif ((!isset($_COOKIE['unitdistance']) && isset($globalUnitDistance) && $globalUnitDistance == 'nm') || (isset($_COOKIE['unitdistance']) && $_COOKIE['unitdistance'] == 'nm')) {
1147
-					print '<span class="nomobile">'.round($spotter_item['distance']*0.539957,2).' nm</span>'."\n";
1148
-					print '<span class="mobile">'.round($spotter_item['distance']*0.539957,2).' nm</span><br />'."\n";
1147
+					print '<span class="nomobile">'.round($spotter_item['distance']*0.539957, 2).' nm</span>'."\n";
1148
+					print '<span class="mobile">'.round($spotter_item['distance']*0.539957, 2).' nm</span><br />'."\n";
1149 1149
 				}
1150 1150
 			}
1151 1151
 			print '</td>'."\n";
1152 1152
 		}
1153
-		if(strtolower($current_page) != "upcoming"){
1153
+		if (strtolower($current_page) != "upcoming") {
1154 1154
 			if ($type == 'aircraft') {
1155 1155
 				//if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS)) {
1156 1156
 				if ((isset($globalUsePilot) && $globalUsePilot) || !isset($globalUsePilot) && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM))) {
@@ -1195,14 +1195,14 @@  discard block
 block discarded – undo
1195 1195
 						if (isset($spotter_item['distance'])) {
1196 1196
 							print '<td class="distance">';
1197 1197
 							if ((!isset($_COOKIE['unitdistance']) && ((isset($globalUnitDistance) && $globalUnitDistance == 'km') || !isset($globalUnitDistance))) || (isset($_COOKIE['unitdistance']) && $_COOKIE['unitdistance'] == 'km')) {
1198
-								print '<span class="nomobile">'.round($spotter_item['distance'],2).' km</span>'."\n";
1199
-								print '<span class="mobile">'.round($spotter_item['distance'],2).' km</span><br />'."\n";
1198
+								print '<span class="nomobile">'.round($spotter_item['distance'], 2).' km</span>'."\n";
1199
+								print '<span class="mobile">'.round($spotter_item['distance'], 2).' km</span><br />'."\n";
1200 1200
 							} elseif ((!isset($_COOKIE['unitdistance']) && isset($globalUnitDistance) && $globalUnitDistance == 'mi') || (isset($_COOKIE['unitdistance']) && $_COOKIE['unitdistance'] == 'mi')) {
1201
-								print '<span class="nomobile">'.round($spotter_item['distance']*0.621371,2).' mi</span>'."\n";
1202
-								print '<span class="mobile">'.round($spotter_item['distance']*0.621371,2).' mi</span><br />'."\n";
1201
+								print '<span class="nomobile">'.round($spotter_item['distance']*0.621371, 2).' mi</span>'."\n";
1202
+								print '<span class="mobile">'.round($spotter_item['distance']*0.621371, 2).' mi</span><br />'."\n";
1203 1203
 							} elseif ((!isset($_COOKIE['unitdistance']) && isset($globalUnitDistance) && $globalUnitDistance == 'nm') || (isset($_COOKIE['unitdistance']) && $_COOKIE['unitdistance'] == 'nm')) {
1204
-								print '<span class="nomobile">'.round($spotter_item['distance']*0.539957,2).' nm</span>'."\n";
1205
-								print '<span class="mobile">'.round($spotter_item['distance']*0.539957,2).' nm</span><br />'."\n";
1204
+								print '<span class="nomobile">'.round($spotter_item['distance']*0.539957, 2).' nm</span>'."\n";
1205
+								print '<span class="mobile">'.round($spotter_item['distance']*0.539957, 2).' nm</span><br />'."\n";
1206 1206
 							}
1207 1207
 							print '</td>'."\n";
1208 1208
 						} else {
@@ -1233,7 +1233,7 @@  discard block
 block discarded – undo
1233 1233
 		
1234 1234
 		if ($showRouteStop) {
1235 1235
 		// Route stop
1236
-			if(strtolower($current_page) != "upcoming"){
1236
+			if (strtolower($current_page) != "upcoming") {
1237 1237
 				print '<td class="route_stop">'."\n";
1238 1238
 				if (!isset($spotter_item['route_stop']) || $spotter_item['route_stop'] == '' || $spotter_item['route_stop'] == 'NULL') {
1239 1239
 					print '<span class="nomobile">-</span>'."\n";
@@ -1256,19 +1256,19 @@  discard block
 block discarded – undo
1256 1256
 				print '<td class="duration">'."\n";
1257 1257
 				if (isset($spotter_item['race_time'])) {
1258 1258
 					if ($spotter_item['race_time'] > 86400) {
1259
-						print '<span class="nomobile">'.gmdate("z\d. H\h. i\m. s\s.",$spotter_item['race_time']).'</span>'."\n";
1260
-						print '<span class="mobile">'.gmdate("z\d. H\h. i\m. s\s.",$spotter_item['race_time']).'</span>'."\n";
1259
+						print '<span class="nomobile">'.gmdate("z\d. H\h. i\m. s\s.", $spotter_item['race_time']).'</span>'."\n";
1260
+						print '<span class="mobile">'.gmdate("z\d. H\h. i\m. s\s.", $spotter_item['race_time']).'</span>'."\n";
1261 1261
 					} else {
1262
-						print '<span class="nomobile">'.gmdate("H\h. i\m. s\s.",$spotter_item['race_time']).'</span>'."\n";
1263
-						print '<span class="mobile">'.gmdate("H\h. i\m. s\s.",$spotter_item['race_time']).'</span>'."\n";
1262
+						print '<span class="nomobile">'.gmdate("H\h. i\m. s\s.", $spotter_item['race_time']).'</span>'."\n";
1263
+						print '<span class="mobile">'.gmdate("H\h. i\m. s\s.", $spotter_item['race_time']).'</span>'."\n";
1264 1264
 					}
1265 1265
 				} elseif (isset($spotter_item['duration'])) {
1266 1266
 					if ($spotter_item['duration'] > 86400) {
1267
-						print '<span class="nomobile">'.gmdate('z\d. H\h. i\m. s\s.',$spotter_item['duration']).'</span>'."\n";
1268
-						print '<span class="mobile">'.gmdate('z\d. H\h. i\m. s\s.',$spotter_item['duration']).'</span>'."\n";
1267
+						print '<span class="nomobile">'.gmdate('z\d. H\h. i\m. s\s.', $spotter_item['duration']).'</span>'."\n";
1268
+						print '<span class="mobile">'.gmdate('z\d. H\h. i\m. s\s.', $spotter_item['duration']).'</span>'."\n";
1269 1269
 					} else {
1270
-						print '<span class="nomobile">'.gmdate('H\h. i\m. s\s.',$spotter_item['duration']).'</span>'."\n";
1271
-						print '<span class="mobile">'.gmdate('H\h. i\m. s\s.',$spotter_item['duration']).'</span>'."\n";
1270
+						print '<span class="nomobile">'.gmdate('H\h. i\m. s\s.', $spotter_item['duration']).'</span>'."\n";
1271
+						print '<span class="mobile">'.gmdate('H\h. i\m. s\s.', $spotter_item['duration']).'</span>'."\n";
1272 1272
 					}
1273 1273
 				} else {
1274 1274
 					print '<span class="nomobile">-</span>'."\n";
@@ -1276,11 +1276,11 @@  discard block
 block discarded – undo
1276 1276
 				}
1277 1277
 				print '</td>'."\n";
1278 1278
 			} else {
1279
-				if(strtolower($current_page) != "upcoming"){
1279
+				if (strtolower($current_page) != "upcoming") {
1280 1280
 					print '<td class="duration">'."\n";
1281 1281
 					if (isset($spotter_item['duration'])) {
1282
-						print '<span class="nomobile">'.gmdate('H:i:s',$spotter_item['duration']).'</span>'."\n";
1283
-						print '<span class="mobile">'.gmdate('H:i:s',$spotter_item['duration']).'</span>'."\n";
1282
+						print '<span class="nomobile">'.gmdate('H:i:s', $spotter_item['duration']).'</span>'."\n";
1283
+						print '<span class="mobile">'.gmdate('H:i:s', $spotter_item['duration']).'</span>'."\n";
1284 1284
 					} else {
1285 1285
 						print '<span class="nomobile">-</span>'."\n";
1286 1286
 						print '<span class="mobile">-</span>'."\n";
@@ -1294,7 +1294,7 @@  discard block
 block discarded – undo
1294 1294
 	if (strtolower($current_page) == "acars-latest" || strtolower($current_page) == "acars-archive") {
1295 1295
 		if (isset($spotter_item['decode']) && $spotter_item['decode'] != '') {
1296 1296
 			print '<td class="message"><p>'."\n";
1297
-			print str_replace(array("\r\n", "\n", "\r"),'<br />',$spotter_item['message']);
1297
+			print str_replace(array("\r\n", "\n", "\r"), '<br />', $spotter_item['message']);
1298 1298
 			print '</p><p class="decode">';
1299 1299
 			$decode_array = json_decode($spotter_item['decode']);
1300 1300
 			foreach ($decode_array as $key => $value) {
@@ -1304,7 +1304,7 @@  discard block
 block discarded – undo
1304 1304
 			print '</td>'."\n";
1305 1305
 		} else {
1306 1306
 			print '<td class="message">'."\n";
1307
-			print str_replace(array("\r\n", "\n", "\r"),'<br />',$spotter_item['message']);
1307
+			print str_replace(array("\r\n", "\n", "\r"), '<br />', $spotter_item['message']);
1308 1308
 			print '</td>'."\n";
1309 1309
 		}
1310 1310
 	}
@@ -1329,7 +1329,7 @@  discard block
 block discarded – undo
1329 1329
 		}
1330 1330
 		print '</td>'."\n";
1331 1331
 		print '<td class="message">'."\n";
1332
-		print str_replace(array("\r\n", "\n", "\r"),'<br />',$spotter_item['message']);
1332
+		print str_replace(array("\r\n", "\n", "\r"), '<br />', $spotter_item['message']);
1333 1333
 		print '</td>'."\n";
1334 1334
 	}
1335 1335
 	if (strtolower($current_page) == "incident-latest" || strtolower($current_page) == "incident-detailed") {
@@ -1355,7 +1355,7 @@  discard block
 block discarded – undo
1355 1355
 		print '</td>'."\n";
1356 1356
 		*/
1357 1357
 		print '<td class="message">'."\n";
1358
-		print str_replace(array("\r\n", "\n", "\r"),'<br />',$spotter_item['message']);
1358
+		print str_replace(array("\r\n", "\n", "\r"), '<br />', $spotter_item['message']);
1359 1359
 		print '</td>'."\n";
1360 1360
 	}
1361 1361
 
Please login to merge, or discard this patch.
Braces   +78 added lines, -29 removed lines patch added patch discarded remove patch
@@ -7,8 +7,10 @@  discard block
 block discarded – undo
7 7
 $showRouteStop = $Common->multiKeyExists($spotter_array,'route_stop');
8 8
 if (isset($globalVM) && $globalVM && isset($type) && $type == 'marine') {
9 9
 	$showDuration = $Common->multiKeyExists($spotter_array,'race_time');
10
-	if ($showDuration === false) $showDuration = $Common->multiKeyExists($spotter_array,'duration');
11
-} else {
10
+	if ($showDuration === false) {
11
+		$showDuration = $Common->multiKeyExists($spotter_array,'duration');
12
+	}
13
+	} else {
12 14
 	$showDuration = $Common->multiKeyExists($spotter_array,'duration');
13 15
 }
14 16
 if (isset($globalVM) && $globalVM && isset($type) && $type == 'marine') {
@@ -16,7 +18,9 @@  discard block
 block discarded – undo
16 18
 }
17 19
 
18 20
 
19
-if (!isset($type)) $type = 'aircraft';
21
+if (!isset($type)) {
22
+	$type = 'aircraft';
23
+}
20 24
 
21 25
 if (!isset($_GET['sort'])) 
22 26
 {
@@ -592,7 +596,9 @@  discard block
 block discarded – undo
592 596
 	if (isset($globalTimezone))
593 597
 	{
594 598
 		date_default_timezone_set($globalTimezone);
595
-	} else date_default_timezone_set('UTC');
599
+	} else {
600
+		date_default_timezone_set('UTC');
601
+	}
596 602
 	if ($showSpecial === true)
597 603
 	{
598 604
 		print '<tr class="special">'."\n";
@@ -607,7 +613,9 @@  discard block
 block discarded – undo
607 613
 			print '<tr class="active">';
608 614
 		} elseif (isset($spotter_item['spotted_registration'])) {
609 615
 			print '<tr class="info">';
610
-		} else print '<tr>';
616
+		} else {
617
+			print '<tr>';
618
+		}
611 619
 	}
612 620
 	if (strtolower($current_page) == "acars-latest" || strtolower($current_page) == "acars-archive" || strtolower($current_page) == "currently" || strtolower($current_page) == "accident-latest" || strtolower($current_page) == "incident-latest" || strtolower($current_page) == "accident-detailed" || strtolower($current_page) == "incident-detailed") {
613 621
 		if ($type == 'aircraft') {
@@ -615,8 +623,9 @@  discard block
 block discarded – undo
615 623
 			{
616 624
 				print '<td class="aircraft_thumbnail">'."\n";
617 625
 				if ($spotter_item['image_source'] == 'planespotters') {
618
-					if ($spotter_item['image_source_website'] != '') $image_src = $spotter_item['image_source_website'];
619
-					else {
626
+					if ($spotter_item['image_source_website'] != '') {
627
+						$image_src = $spotter_item['image_source_website'];
628
+					} else {
620 629
 						$planespotter_url_array = explode("_", $spotter_item['image']);
621 630
 						$planespotter_id = str_replace(".jpg", "", $planespotter_url_array[1]);
622 631
 						$image_src = 'https://www.planespotters.net/Aviation_Photos/photo.show?id='.$planespotter_id;
@@ -629,7 +638,9 @@  discard block
 block discarded – undo
629 638
 				} else {
630 639
 					if ($spotter_item['image_source'] == 'wikimedia' || $spotter_item['image_source'] == 'devianart' || $spotter_item['image_source'] == 'flickr') {
631 640
 						$image_thumbnail = preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']);
632
-					} else 	$image_thumbnail = $spotter_item['image_thumbnail'];
641
+					} else {
642
+						$image_thumbnail = $spotter_item['image_thumbnail'];
643
+					}
633 644
 					if (isset($spotter_item['airline_name'])) {
634 645
 						print '<img src="'.$image_thumbnail.'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['registration'].' - '.$spotter_item['airline_name'].'" alt="'.$spotter_item['registration'].' - '.$spotter_item['airline_name'].'" data-content="'._("Registration:").' '.$spotter_item['registration'].'<br />'._("Airline:").' '.$spotter_item['airline_name'].'" data-html="true" width="100px" />'."\n".'<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
635 646
 					} else {
@@ -655,7 +666,9 @@  discard block
 block discarded – undo
655 666
 				print '<td class="aircraft_thumbnail">'."\n";
656 667
 				if ($spotter_item['image_source'] == 'wikimedia' || $spotter_item['image_source'] == 'devianart' || $spotter_item['image_source'] == 'flickr') {
657 668
 					$image_thumbnail = preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']);
658
-				} else 	$image_thumbnail = $spotter_item['image_thumbnail'];
669
+				} else {
670
+					$image_thumbnail = $spotter_item['image_thumbnail'];
671
+				}
659 672
 				if (isset($spotter_item['mmsi']) && $spotter_item['mmsi'] != '') {
660 673
 					print '<img src="'.$image_thumbnail.'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['mmsi'].'" alt="'.$spotter_item['mmsi'].'" data-content="'._("MMSI:").' '.$spotter_item['mmsi'].'" data-html="true" width="100px" />'."\n".'<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
661 674
 				} else {
@@ -677,7 +690,9 @@  discard block
 block discarded – undo
677 690
 				print '<td class="aircraft_thumbnail">'."\n";
678 691
 				if ($spotter_item['image_source'] == 'wikimedia' || $spotter_item['image_source'] == 'devianart' || $spotter_item['image_source'] == 'flickr') {
679 692
 					$image_thumbnail = preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']);
680
-				} else 	$image_thumbnail = $spotter_item['image_thumbnail'];
693
+				} else {
694
+					$image_thumbnail = $spotter_item['image_thumbnail'];
695
+				}
681 696
 				print '<img src="'.$image_thumbnail.'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['ident'].'" alt="'.$spotter_item['type'].'" data-content="'._("Type:").' '.$spotter_item['type'].'" data-html="true" width="100px" />'."\n".'<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
682 697
 				print '</td>'."\n";
683 698
 			} else {
@@ -730,8 +745,9 @@  discard block
 block discarded – undo
730 745
 				print '<td class="aircraft_thumbnail">'."\n";
731 746
 				//print '<a href="'.$globalURL.'/flightid/'.$spotter_item['spotter_id'].'"><img src="'.$spotter_item['image_thumbnail'].'" alt="Click to see more information about this flight" title="Click to see more information about this flight" width="100px" /></a>';
732 747
 				if ($spotter_item['image_source'] == 'planespotters') {
733
-					if ($spotter_item['image_source_website'] != '') $image_src = $spotter_item['image_source_website'];
734
-					else {
748
+					if ($spotter_item['image_source_website'] != '') {
749
+						$image_src = $spotter_item['image_source_website'];
750
+					} else {
735 751
 						$planespotter_url_array = explode("_", $spotter_array[0]['image']);
736 752
 						$planespotter_id = str_replace(".jpg", "", $planespotter_url_array[1]);
737 753
 						$image_src = 'https://www.planespotters.net/Aviation_Photos/photo.show?id='.$planespotter_id;
@@ -748,7 +764,9 @@  discard block
 block discarded – undo
748 764
 				} else {
749 765
 					if ($spotter_item['image_source'] == 'wikimedia' || $spotter_item['image_source'] == 'devianart' || $spotter_item['image_source'] == 'flickr') {
750 766
 						$image_thumbnail = preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']);
751
-					} else 	$image_thumbnail = $spotter_item['image_thumbnail'];
767
+					} else {
768
+						$image_thumbnail = $spotter_item['image_thumbnail'];
769
+					}
752 770
 					if (!isset($spotter_item['airline_name']) && isset($spotter_item['aircraft_name'])) {
753 771
 						print '<a href="'.$globalURL.'/flightid/'.$spotter_item['spotter_id'].'"><img src="'.$image_thumbnail.'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['registration'].' - '.$spotter_item['aircraft_type'].' - '._("Not available").'" alt="'.$spotter_item['registration'].' - '.$spotter_item['aircraft_type'].' - '._("Not available").'" data-content="'._("Registration:").' '.$spotter_item['registration'].'<br />'._("Aircraft:").' '.$spotter_item['aircraft_name'].' ('.$spotter_item['aircraft_type'].')<br />'._("Airline:").' '._("Not available").'<br />'._("Squawk:").' '.$spotter_item['squawk'].'" data-html="true" width="100px" /></a>'."\n".'<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
754 772
 					} elseif (!isset($spotter_item['aircraft_name']) && isset($spotter_item['airline_name'])) {
@@ -788,13 +806,19 @@  discard block
 block discarded – undo
788 806
 				print '<td class="aircraft_thumbnail">'."\n";
789 807
 				if ($spotter_item['image_source'] == 'wikimedia' || $spotter_item['image_source'] == 'devianart' || $spotter_item['image_source'] == 'flickr') {
790 808
 					$image_thumbnail = preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']);
791
-				} else 	$image_thumbnail = $spotter_item['image_thumbnail'];
809
+				} else {
810
+					$image_thumbnail = $spotter_item['image_thumbnail'];
811
+				}
792 812
 				if (isset($spotter_item['mmsi']) && $spotter_item['mmsi'] != '') {
793 813
 					print '<img src="'.$image_thumbnail.'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['mmsi'].'" alt="'.$spotter_item['mmsi'].'" data-content="'._("MMSI:").' '.$spotter_item['mmsi'].'" data-html="true" width="100px" />'."\n";
794
-					if ($spotter_item['image_copyright'] != '') print '<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
814
+					if ($spotter_item['image_copyright'] != '') {
815
+						print '<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
816
+					}
795 817
 				} else {
796 818
 					print '<img src="'.$image_thumbnail.'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['ident'].'" alt="'.$spotter_item['ident'].'" data-content="'._("Ident:").' '.$spotter_item['ident'].'" data-html="true" width="100px" />'."\n";
797
-					if ($spotter_item['image_copyright'] != '') print '<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
819
+					if ($spotter_item['image_copyright'] != '') {
820
+						print '<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
821
+					}
798 822
 				}
799 823
 				print '</td>'."\n";
800 824
 			} else {
@@ -812,7 +836,9 @@  discard block
 block discarded – undo
812 836
 				print '<td class="aircraft_thumbnail">'."\n";
813 837
 				if ($spotter_item['image_source'] == 'wikimedia' || $spotter_item['image_source'] == 'devianart' || $spotter_item['image_source'] == 'flickr') {
814 838
 					$image_thumbnail = preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']);
815
-				} else 	$image_thumbnail = $spotter_item['image_thumbnail'];
839
+				} else {
840
+					$image_thumbnail = $spotter_item['image_thumbnail'];
841
+				}
816 842
 				print '<img src="'.$image_thumbnail.'" class="img-rounded" data-toggle="popover" title="'.$spotter_item['ident'].'" alt="'.$spotter_item['type'].'" data-content="'._("Type:").' '.$spotter_item['type'].'" data-html="true" width="100px" />'."\n".'<div class="thumbnail-copyright">&copy; '.$spotter_item['image_copyright'].'</div>';
817 843
 				print '</td>'."\n";
818 844
 			} else {
@@ -930,8 +956,11 @@  discard block
 block discarded – undo
930 956
 				print '<span class="nomobile"><a href="'.$globalURL.'/aircraft/'.$spotter_item['aircraft_type'].'">'.$spotter_item['aircraft_type'].'</a></span>'."\n";
931 957
 			} else {
932 958
 				$aircraft_names = explode('/',$spotter_item['aircraft_name']);
933
-				if (count($aircraft_names) == 1) print '<span class="nomobile"><a href="'.$globalURL.'/aircraft/'.$spotter_item['aircraft_type'].'">'.$spotter_item['aircraft_manufacturer'].' '.$spotter_item['aircraft_name'].'</a></span>'."\n";
934
-				else print '<span class="nomobile"><a href="'.$globalURL.'/aircraft/'.$spotter_item['aircraft_type'].'" title="'.$spotter_item['aircraft_name'].'">'.$spotter_item['aircraft_manufacturer'].' '.$aircraft_names[0].'</a></span>'."\n";
959
+				if (count($aircraft_names) == 1) {
960
+					print '<span class="nomobile"><a href="'.$globalURL.'/aircraft/'.$spotter_item['aircraft_type'].'">'.$spotter_item['aircraft_manufacturer'].' '.$spotter_item['aircraft_name'].'</a></span>'."\n";
961
+				} else {
962
+					print '<span class="nomobile"><a href="'.$globalURL.'/aircraft/'.$spotter_item['aircraft_type'].'" title="'.$spotter_item['aircraft_name'].'">'.$spotter_item['aircraft_manufacturer'].' '.$aircraft_names[0].'</a></span>'."\n";
963
+				}
935 964
 			}
936 965
 			print '<span class="mobile"><a href="'.$globalURL.'/aircraft/'.$spotter_item['aircraft_type'].'">'.$spotter_item['aircraft_type'].'</a></span>'."\n";
937 966
 		} elseif ($type == 'marine') {
@@ -974,15 +1003,21 @@  discard block
 block discarded – undo
974 1003
 			if (isset($spotter_item['departure_airport_time']) && isset($spotter_item['real_departure_airport_time'])) {
975 1004
 				if ($spotter_item['departure_airport_time'] > 2460) {
976 1005
 					$departure_airport_time = date('H:m',$spotter_item['departure_airport_time']);
977
-				} else $departure_airport_time = substr($spotter_item['departure_airport_time'],0,-2).':'.substr($spotter_item['departure_airport_time'],-2);
1006
+				} else {
1007
+					$departure_airport_time = substr($spotter_item['departure_airport_time'],0,-2).':'.substr($spotter_item['departure_airport_time'],-2);
1008
+				}
978 1009
 				if ($spotter_item['real_departure_airport_time'] > 2460) {
979 1010
 					$real_departure_airport_time = date('H:m',$spotter_item['real_departure_airport_time']);
980
-				} else $real_departure_airport_time = $spotter_item['real_departure_airport_time'];
1011
+				} else {
1012
+					$real_departure_airport_time = $spotter_item['real_departure_airport_time'];
1013
+				}
981 1014
 				print '<br /><span class="airport_time">'.$departure_airport_time.' ('.$real_departure_airport_time.')</span>'."\n";
982 1015
 			} elseif (isset($spotter_item['real_departure_airport_time']) && $spotter_item['real_departure_airport_time'] != 'NULL') {
983 1016
 				if ($spotter_item['real_departure_airport_time'] > 2460) {
984 1017
 					$real_departure_airport_time = date('H:m',$spotter_item['real_departure_airport_time']);
985
-				} else $real_departure_airport_time = $spotter_item['real_departure_airport_time'];
1018
+				} else {
1019
+					$real_departure_airport_time = $spotter_item['real_departure_airport_time'];
1020
+				}
986 1021
 				print '<br /><span class="airport_time">'.$real_departure_airport_time.'</span>'."\n";
987 1022
 			} elseif (isset($spotter_item['departure_airport_time']) && $spotter_item['departure_airport_time'] != 'NULL') {
988 1023
 				if ($spotter_item['departure_airport_time'] > 2460) {
@@ -1004,7 +1039,9 @@  discard block
 block discarded – undo
1004 1039
 						$longitude = $spotter_item['longitude'];
1005 1040
 					}
1006 1041
 					$distance = $Spotter->getAirportDistance($spotter_item['departure_airport'],$latitude,$longitude);
1007
-				} else $distance = '';
1042
+				} else {
1043
+					$distance = '';
1044
+				}
1008 1045
 				if ($distance != '') {
1009 1046
 					if ((!isset($_COOKIE['unitdistance']) && isset($globalUnitDistance) && $globalUnitDistance == 'nm') || (isset($_COOKIE['unitdistance']) && $_COOKIE['unitdistance'] == 'nm')) {
1010 1047
 						echo '<br/><i>'.round($distance*0.539957).' nm</i>';
@@ -1031,7 +1068,9 @@  discard block
 block discarded – undo
1031 1068
 			} else {
1032 1069
 				if (isset($spotter_item['real_arrival_airport']) && $spotter_item['real_arrival_airport'] != $spotter_item['arrival_airport']) {
1033 1070
 					print '<span class="nomobile">Scheduled : <a href="'.$globalURL.'/airport/'.$spotter_item['arrival_airport'].'">'.$spotter_item['arrival_airport_city'].', '.$spotter_item['arrival_airport_country'].' ('.$spotter_item['arrival_airport'].')</a></span>'."\n";
1034
-					if (!isset($Spotter)) $Spotter = new Spotter();
1071
+					if (!isset($Spotter)) {
1072
+						$Spotter = new Spotter();
1073
+					}
1035 1074
 					$arrival_airport_info = $Spotter->getAllAirportInfo($spotter_item['real_arrival_airport']);
1036 1075
 					if (isset($arrival_airport_info[0])) {
1037 1076
                         print '<br /><span class="nomobile">' . _("Real:") . ' <a href="' . $globalURL . '/airport/' . $spotter_item['real_arrival_airport'] . '">' . $arrival_airport_info[0]['city'] . ',' . $arrival_airport_info[0]['country'] . ' (' . $spotter_item['real_arrival_airport'] . ')</a></span>' . "\n";
@@ -1051,20 +1090,28 @@  discard block
 block discarded – undo
1051 1090
 			if (isset($spotter_item['arrival_airport_time']) && isset($spotter_item['real_arrival_airport_time'])) {
1052 1091
 				if ($spotter_item['arrival_airport_time'] > 2460) {
1053 1092
 					$arrival_airport_time = date('H:m',$spotter_item['arrival_airport_time']);
1054
-				} else $arrival_airport_time = $spotter_item['arrival_airport_time'];
1093
+				} else {
1094
+					$arrival_airport_time = $spotter_item['arrival_airport_time'];
1095
+				}
1055 1096
 				if ($spotter_item['real_arrival_airport_time'] > 2460) {
1056 1097
 					$real_arrival_airport_time = date('H:m',$spotter_item['real_arrival_airport_time']);
1057
-				} else $real_arrival_airport_time = $spotter_item['real_arrival_airport_time'];
1098
+				} else {
1099
+					$real_arrival_airport_time = $spotter_item['real_arrival_airport_time'];
1100
+				}
1058 1101
 				print '<br /><span class="airport_time">'.$spotter_item['arrival_airport_time'].' ('.$spotter_item['real_arrival_airport_time'].')</span>'."\n";
1059 1102
 			} elseif (isset($spotter_item['real_arrival_airport_time'])) {
1060 1103
 				if ($spotter_item['real_arrival_airport_time'] > 2460) {
1061 1104
 					$real_arrival_airport_time = date('H:m',$spotter_item['real_arrival_airport_time']);
1062
-				} else $real_arrival_airport_time = $spotter_item['real_arrival_airport_time'];
1105
+				} else {
1106
+					$real_arrival_airport_time = $spotter_item['real_arrival_airport_time'];
1107
+				}
1063 1108
 				print '<br /><span class="airport_time">'.$real_arrival_airport_time.'</span>'."\n";
1064 1109
 			} elseif (isset($spotter_item['arrival_airport_time']) && $spotter_item['arrival_airport_time'] != 'NULL') {
1065 1110
 				if ($spotter_item['arrival_airport_time'] > 2460) {
1066 1111
 					$arrival_airport_time = date('H:m',$spotter_item['arrival_airport_time']);
1067
-				} else $arrival_airport_time = $spotter_item['arrival_airport_time'];
1112
+				} else {
1113
+					$arrival_airport_time = $spotter_item['arrival_airport_time'];
1114
+				}
1068 1115
 				print '<br /><span class="airport_time">'.$arrival_airport_time.'</span>'."\n";
1069 1116
 			}
1070 1117
 			if (!isset($spotter_item['real_arrival_airport']) && $spotter_item['arrival_airport'] != 'NA') {
@@ -1077,7 +1124,9 @@  discard block
 block discarded – undo
1077 1124
 						$longitude = $spotter_item['longitude'];
1078 1125
 					}
1079 1126
 					$distance = $Spotter->getAirportDistance($spotter_item['arrival_airport'],$latitude,$longitude);
1080
-				} else $distance = '';
1127
+				} else {
1128
+					$distance = '';
1129
+				}
1081 1130
 				if ($distance != '') {
1082 1131
 					if ((!isset($_COOKIE['unitdistance']) && isset($globalUnitDistance) && $globalUnitDistance == 'nm') || (isset($_COOKIE['unitdistance']) && $_COOKIE['unitdistance'] == 'nm')) {
1083 1132
 						echo '<br/><i>'.round($distance*0.539957).' nm</i>';
Please login to merge, or discard this patch.
require/class.MarineLive.php 3 patches
Indentation   +229 added lines, -229 removed lines patch added patch discarded remove patch
@@ -20,13 +20,13 @@  discard block
 block discarded – undo
20 20
 	}
21 21
 
22 22
 
23
-    /**
24
-     * Get SQL query part for filter used
25
-     * @param array $filter the filter
26
-     * @param bool $where
27
-     * @param bool $and
28
-     * @return string the SQL part
29
-     */
23
+	/**
24
+	 * Get SQL query part for filter used
25
+	 * @param array $filter the filter
26
+	 * @param bool $where
27
+	 * @param bool $and
28
+	 * @return string the SQL part
29
+	 */
30 30
 	public function getFilter($filter = array(),$where = false,$and = false) {
31 31
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
32 32
 		$filters = array();
@@ -105,14 +105,14 @@  discard block
 block discarded – undo
105 105
 		return $filter_query;
106 106
 	}
107 107
 
108
-    /**
109
-     * Gets all the spotter information based on the latest data entry
110
-     *
111
-     * @param string $limit
112
-     * @param string $sort
113
-     * @param array $filter
114
-     * @return array the spotter information
115
-     */
108
+	/**
109
+	 * Gets all the spotter information based on the latest data entry
110
+	 *
111
+	 * @param string $limit
112
+	 * @param string $sort
113
+	 * @param array $filter
114
+	 * @return array the spotter information
115
+	 */
116 116
 	public function getLiveMarineData($limit = '', $sort = '', $filter = array())
117 117
 	{
118 118
 		global $globalDBdriver, $globalLiveInterval;
@@ -154,12 +154,12 @@  discard block
 block discarded – undo
154 154
 		return $spotter_array;
155 155
 	}
156 156
 
157
-    /**
158
-     * Gets Minimal Live Spotter data
159
-     *
160
-     * @param array $filter
161
-     * @return array the spotter information
162
-     */
157
+	/**
158
+	 * Gets Minimal Live Spotter data
159
+	 *
160
+	 * @param array $filter
161
+	 * @return array the spotter information
162
+	 */
163 163
 	public function getMinLiveMarineData($filter = array())
164 164
 	{
165 165
 		global $globalDBdriver, $globalLiveInterval;
@@ -188,15 +188,15 @@  discard block
 block discarded – undo
188 188
 		return $spotter_array;
189 189
 	}
190 190
 
191
-    /**
192
-     * Gets Minimal Live Spotter data since xx seconds
193
-     *
194
-     * @param array $coord
195
-     * @param array $filter
196
-     * @param bool $limit
197
-     * @param string $id
198
-     * @return array the spotter information
199
-     */
191
+	/**
192
+	 * Gets Minimal Live Spotter data since xx seconds
193
+	 *
194
+	 * @param array $coord
195
+	 * @param array $filter
196
+	 * @param bool $limit
197
+	 * @param string $id
198
+	 * @return array the spotter information
199
+	 */
200 200
 	public function getMinLastLiveMarineData($coord = array(),$filter = array(), $limit = false, $id = '')
201 201
 	{
202 202
 		global $globalDBdriver, $globalLiveInterval, $globalMap3DMarinesLimit, $globalArchive;
@@ -275,14 +275,14 @@  discard block
 block discarded – undo
275 275
 		return $spotter_array;
276 276
 	}
277 277
 
278
-    /**
279
-     * Gets Minimal Live Spotter data since xx seconds
280
-     *
281
-     * @param string $id
282
-     * @param array $filter
283
-     * @param bool $limit
284
-     * @return array the spotter information
285
-     */
278
+	/**
279
+	 * Gets Minimal Live Spotter data since xx seconds
280
+	 *
281
+	 * @param string $id
282
+	 * @param array $filter
283
+	 * @param bool $limit
284
+	 * @return array the spotter information
285
+	 */
286 286
 	public function getMinLastLiveMarineDataByID($id = '',$filter = array(), $limit = false)
287 287
 	{
288 288
 		global $globalDBdriver, $globalLiveInterval, $globalMap3DMarinesLimit, $globalArchive;
@@ -341,12 +341,12 @@  discard block
 block discarded – undo
341 341
 		return $spotter_array;
342 342
 	}
343 343
 
344
-    /**
345
-     * Gets number of latest data entry
346
-     *
347
-     * @param array $filter
348
-     * @return String number of entry
349
-     */
344
+	/**
345
+	 * Gets number of latest data entry
346
+	 *
347
+	 * @param array $filter
348
+	 * @return String number of entry
349
+	 */
350 350
 	public function getLiveMarineCount($filter = array())
351 351
 	{
352 352
 		global $globalDBdriver, $globalLiveInterval;
@@ -370,13 +370,13 @@  discard block
 block discarded – undo
370 370
 		return $result['nb'];
371 371
 	}
372 372
 
373
-    /**
374
-     * Gets all the spotter information based on the latest data entry and coord
375
-     *
376
-     * @param $coord
377
-     * @param array $filter
378
-     * @return array the spotter information
379
-     */
373
+	/**
374
+	 * Gets all the spotter information based on the latest data entry and coord
375
+	 *
376
+	 * @param $coord
377
+	 * @param array $filter
378
+	 * @return array the spotter information
379
+	 */
380 380
 	public function getLiveMarineDatabyCoord($coord, $filter = array())
381 381
 	{
382 382
 		global $globalDBdriver, $globalLiveInterval;
@@ -399,13 +399,13 @@  discard block
 block discarded – undo
399 399
 		return $spotter_array;
400 400
 	}
401 401
 
402
-    /**
403
-     * Gets all the spotter information based on the latest data entry and coord
404
-     *
405
-     * @param $coord
406
-     * @param array $filter
407
-     * @return array the spotter information
408
-     */
402
+	/**
403
+	 * Gets all the spotter information based on the latest data entry and coord
404
+	 *
405
+	 * @param $coord
406
+	 * @param array $filter
407
+	 * @return array the spotter information
408
+	 */
409 409
 	public function getMinLiveMarineDatabyCoord($coord, $filter = array())
410 410
 	{
411 411
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
@@ -473,15 +473,15 @@  discard block
 block discarded – undo
473 473
 		return $spotter_array;
474 474
 	}
475 475
 
476
-    /**
477
-     * Gets all the spotter information based on a user's latitude and longitude
478
-     *
479
-     * @param $lat
480
-     * @param $lng
481
-     * @param $radius
482
-     * @param $interval
483
-     * @return array the spotter information
484
-     */
476
+	/**
477
+	 * Gets all the spotter information based on a user's latitude and longitude
478
+	 *
479
+	 * @param $lat
480
+	 * @param $lng
481
+	 * @param $radius
482
+	 * @param $interval
483
+	 * @return array the spotter information
484
+	 */
485 485
 	public function getLatestMarineForLayar($lat, $lng, $radius, $interval)
486 486
 	{
487 487
 		$Marine = new Marine($this->db);
@@ -538,32 +538,32 @@  discard block
 block discarded – undo
538 538
 	}
539 539
 
540 540
 
541
-    /**
542
-     * Gets all the spotter information based on a particular callsign
543
-     *
544
-     * @param $ident
545
-     * @return array the spotter information
546
-     */
541
+	/**
542
+	 * Gets all the spotter information based on a particular callsign
543
+	 *
544
+	 * @param $ident
545
+	 * @return array the spotter information
546
+	 */
547 547
 	public function getLastLiveMarineDataByIdent($ident)
548 548
 	{
549 549
 		$Marine = new Marine($this->db);
550 550
 		date_default_timezone_set('UTC');
551 551
 
552 552
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
553
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
553
+				$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
554 554
 
555 555
 		$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident),'',true);
556 556
 
557 557
 		return $spotter_array;
558 558
 	}
559 559
 
560
-    /**
561
-     * Gets all the spotter information based on a particular callsign
562
-     *
563
-     * @param $ident
564
-     * @param $date
565
-     * @return array the spotter information
566
-     */
560
+	/**
561
+	 * Gets all the spotter information based on a particular callsign
562
+	 *
563
+	 * @param $ident
564
+	 * @param $date
565
+	 * @return array the spotter information
566
+	 */
567 567
 	public function getDateLiveMarineDataByIdent($ident,$date)
568 568
 	{
569 569
 		$Marine = new Marine($this->db);
@@ -575,13 +575,13 @@  discard block
 block discarded – undo
575 575
 		return $spotter_array;
576 576
 	}
577 577
 
578
-    /**
579
-     * Gets all the spotter information based on a particular MMSI
580
-     *
581
-     * @param $mmsi
582
-     * @param $date
583
-     * @return array the spotter information
584
-     */
578
+	/**
579
+	 * Gets all the spotter information based on a particular MMSI
580
+	 *
581
+	 * @param $mmsi
582
+	 * @param $date
583
+	 * @return array the spotter information
584
+	 */
585 585
 	public function getDateLiveMarineDataByMMSI($mmsi,$date)
586 586
 	{
587 587
 		$Marine = new Marine($this->db);
@@ -593,53 +593,53 @@  discard block
 block discarded – undo
593 593
 		return $spotter_array;
594 594
 	}
595 595
 
596
-    /**
597
-     * Gets last spotter information based on a particular callsign
598
-     *
599
-     * @param $id
600
-     * @return array the spotter information
601
-     */
596
+	/**
597
+	 * Gets last spotter information based on a particular callsign
598
+	 *
599
+	 * @param $id
600
+	 * @return array the spotter information
601
+	 */
602 602
 	public function getLastLiveMarineDataById($id)
603 603
 	{
604 604
 		$Marine = new Marine($this->db);
605 605
 		date_default_timezone_set('UTC');
606 606
 
607 607
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
608
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
608
+				$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
609 609
 
610 610
 		$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id),'',true);
611 611
 
612 612
 		return $spotter_array;
613 613
 	}
614 614
 
615
-    /**
616
-     * Gets last spotter information based on a particular callsign
617
-     *
618
-     * @param $id
619
-     * @param $date
620
-     * @return array the spotter information
621
-     */
615
+	/**
616
+	 * Gets last spotter information based on a particular callsign
617
+	 *
618
+	 * @param $id
619
+	 * @param $date
620
+	 * @return array the spotter information
621
+	 */
622 622
 	public function getDateLiveMarineDataById($id,$date)
623 623
 	{
624 624
 		$Marine = new Marine($this->db);
625 625
 		date_default_timezone_set('UTC');
626 626
 
627 627
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
628
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
629
-                $date = date('c',$date);
628
+				$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
629
+				$date = date('c',$date);
630 630
 		$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id,':date' => $date),'',true);
631 631
 
632 632
 		return $spotter_array;
633 633
 	}
634 634
 
635 635
 
636
-    /**
637
-     * Gets all the spotter information based on a particular id
638
-     *
639
-     * @param $id
640
-     * @param bool $liveinterval
641
-     * @return array the spotter information
642
-     */
636
+	/**
637
+	 * Gets all the spotter information based on a particular id
638
+	 *
639
+	 * @param $id
640
+	 * @param bool $liveinterval
641
+	 * @return array the spotter information
642
+	 */
643 643
 	public function getAllLiveMarineDataById($id,$liveinterval = false)
644 644
 	{
645 645
 		global $globalDBdriver, $globalLiveInterval;
@@ -667,18 +667,18 @@  discard block
 block discarded – undo
667 667
 		return $spotter_array;
668 668
 	}
669 669
 
670
-    /**
671
-     * Gets all the spotter information based on a particular ident
672
-     *
673
-     * @param $ident
674
-     * @return array the spotter information
675
-     */
670
+	/**
671
+	 * Gets all the spotter information based on a particular ident
672
+	 *
673
+	 * @param $ident
674
+	 * @return array the spotter information
675
+	 */
676 676
 	public function getAllLiveMarineDataByIdent($ident)
677 677
 	{
678 678
 		date_default_timezone_set('UTC');
679 679
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
680 680
 		$query  = self::$global_query.' WHERE marine_live.ident = :ident';
681
-    		try {
681
+			try {
682 682
 			
683 683
 			$sth = $this->db->prepare($query);
684 684
 			$sth->execute(array(':ident' => $ident));
@@ -692,23 +692,23 @@  discard block
 block discarded – undo
692 692
 
693 693
 
694 694
 	/**
695
-	* Deletes all info in the table
696
-	*
697
-	* @return String success or false
698
-	*
699
-	*/
695
+	 * Deletes all info in the table
696
+	 *
697
+	 * @return String success or false
698
+	 *
699
+	 */
700 700
 	public function deleteLiveMarineData()
701 701
 	{
702 702
 		global $globalDBdriver;
703 703
 		if ($globalDBdriver == 'mysql') {
704 704
 			//$query  = "DELETE FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE) >= marine_live.date";
705 705
 			$query  = 'DELETE FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 12 HOUR) >= marine_live.date';
706
-            		//$query  = "DELETE FROM marine_live WHERE marine_live.id IN (SELECT marine_live.id FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= marine_live.date)";
706
+					//$query  = "DELETE FROM marine_live WHERE marine_live.id IN (SELECT marine_live.id FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= marine_live.date)";
707 707
 		} else {
708 708
 			$query  = "DELETE FROM marine_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '12 HOURS' >= marine_live.date";
709 709
 		}
710 710
         
711
-    		try {
711
+			try {
712 712
 			
713 713
 			$sth = $this->db->prepare($query);
714 714
 			$sth->execute();
@@ -720,18 +720,18 @@  discard block
 block discarded – undo
720 720
 	}
721 721
 
722 722
 	/**
723
-	* Deletes all info in the table for aircraft not seen since 2 HOUR
724
-	*
725
-	* @return String success or false
726
-	*
727
-	*/
723
+	 * Deletes all info in the table for aircraft not seen since 2 HOUR
724
+	 *
725
+	 * @return String success or false
726
+	 *
727
+	 */
728 728
 	public function deleteLiveMarineDataNotUpdated()
729 729
 	{
730 730
 		global $globalDBdriver, $globalDebug;
731 731
 		if ($globalDBdriver == 'mysql') {
732 732
 			//$query = 'SELECT fammarine_id FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) >= marine_live.date AND marine_live.fammarine_id NOT IN (SELECT fammarine_id FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) < marine_live.date) LIMIT 800 OFFSET 0';
733
-    			$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 1200 OFFSET 0";
734
-    			try {
733
+				$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 1200 OFFSET 0";
734
+				try {
735 735
 				
736 736
 				$sth = $this->db->prepare($query);
737 737
 				$sth->execute();
@@ -739,8 +739,8 @@  discard block
 block discarded – undo
739 739
 				return "error";
740 740
 			}
741 741
 			$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
742
-                        $i = 0;
743
-                        $j =0;
742
+						$i = 0;
743
+						$j =0;
744 744
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
745 745
 			foreach($all as $row)
746 746
 			{
@@ -748,20 +748,20 @@  discard block
 block discarded – undo
748 748
 				$j++;
749 749
 				if ($j == 30) {
750 750
 					if ($globalDebug) echo ".";
751
-				    	try {
751
+						try {
752 752
 						
753 753
 						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
754 754
 						$sth->execute();
755 755
 					} catch(PDOException $e) {
756 756
 						return "error";
757 757
 					}
758
-                                	$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
759
-                                	$j = 0;
758
+									$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
759
+									$j = 0;
760 760
 				}
761 761
 				$query_delete .= "'".$row['fammarine_id']."',";
762 762
 			}
763 763
 			if ($i > 0) {
764
-    				try {
764
+					try {
765 765
 					
766 766
 					$sth = $this->db->prepare(substr($query_delete,0,-1).")");
767 767
 					$sth->execute();
@@ -772,9 +772,9 @@  discard block
 block discarded – undo
772 772
 			return "success";
773 773
 		} elseif ($globalDBdriver == 'pgsql') {
774 774
 			//$query = "SELECT fammarine_id FROM marine_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= marine_live.date AND marine_live.fammarine_id NOT IN (SELECT fammarine_id FROM marine_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' < marine_live.date) LIMIT 800 OFFSET 0";
775
-    			//$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0";
776
-    			$query = "DELETE FROM marine_live WHERE fammarine_id IN (SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0)";
777
-    			try {
775
+				//$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0";
776
+				$query = "DELETE FROM marine_live WHERE fammarine_id IN (SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0)";
777
+				try {
778 778
 				
779 779
 				$sth = $this->db->prepare($query);
780 780
 				$sth->execute();
@@ -818,18 +818,18 @@  discard block
 block discarded – undo
818 818
 		return 'error';
819 819
 	}
820 820
 
821
-    /**
822
-     * Deletes all info in the table for an ident
823
-     *
824
-     * @param $ident
825
-     * @return String success or false
826
-     */
821
+	/**
822
+	 * Deletes all info in the table for an ident
823
+	 *
824
+	 * @param $ident
825
+	 * @return String success or false
826
+	 */
827 827
 	public function deleteLiveMarineDataByIdent($ident)
828 828
 	{
829 829
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
830 830
 		$query  = 'DELETE FROM marine_live WHERE ident = :ident';
831 831
         
832
-    		try {
832
+			try {
833 833
 			
834 834
 			$sth = $this->db->prepare($query);
835 835
 			$sth->execute(array(':ident' => $ident));
@@ -840,18 +840,18 @@  discard block
 block discarded – undo
840 840
 		return "success";
841 841
 	}
842 842
 
843
-    /**
844
-     * Deletes all info in the table for an id
845
-     *
846
-     * @param $id
847
-     * @return String success or false
848
-     */
843
+	/**
844
+	 * Deletes all info in the table for an id
845
+	 *
846
+	 * @param $id
847
+	 * @return String success or false
848
+	 */
849 849
 	public function deleteLiveMarineDataById($id)
850 850
 	{
851 851
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
852 852
 		$query  = 'DELETE FROM marine_live WHERE fammarine_id = :id';
853 853
         
854
-    		try {
854
+			try {
855 855
 			
856 856
 			$sth = $this->db->prepare($query);
857 857
 			$sth->execute(array(':id' => $id));
@@ -864,11 +864,11 @@  discard block
 block discarded – undo
864 864
 
865 865
 
866 866
 	/**
867
-	* Gets the marine races
868
-	*
869
-	* @return array all races
870
-	*
871
-	*/
867
+	 * Gets the marine races
868
+	 *
869
+	 * @return array all races
870
+	 *
871
+	 */
872 872
 	public function getAllRaces()
873 873
 	{
874 874
 		$query  = 'SELECT DISTINCT marine_live.race_id, marine_live.race_name FROM marine_live ORDER BY marine_live.race_name';
@@ -877,12 +877,12 @@  discard block
 block discarded – undo
877 877
 		return $sth->fetchAll(PDO::FETCH_ASSOC);
878 878
 	}
879 879
 
880
-    /**
881
-     * Gets the aircraft ident within the last hour
882
-     *
883
-     * @param $ident
884
-     * @return String the ident
885
-     */
880
+	/**
881
+	 * Gets the aircraft ident within the last hour
882
+	 *
883
+	 * @param $ident
884
+	 * @return String the ident
885
+	 */
886 886
 	public function getIdentFromLastHour($ident)
887 887
 	{
888 888
 		global $globalDBdriver;
@@ -908,14 +908,14 @@  discard block
 block discarded – undo
908 908
 			$ident_result = $row['ident'];
909 909
 		}
910 910
 		return $ident_result;
911
-        }
912
-
913
-    /**
914
-     * Check recent aircraft
915
-     *
916
-     * @param $ident
917
-     * @return String the ident
918
-     */
911
+		}
912
+
913
+	/**
914
+	 * Check recent aircraft
915
+	 *
916
+	 * @param $ident
917
+	 * @return String the ident
918
+	 */
919 919
 	public function checkIdentRecent($ident)
920 920
 	{
921 921
 		global $globalDBdriver;
@@ -941,14 +941,14 @@  discard block
 block discarded – undo
941 941
 			$ident_result = $row['fammarine_id'];
942 942
 		}
943 943
 		return $ident_result;
944
-        }
945
-
946
-    /**
947
-     * Check recent aircraft by id
948
-     *
949
-     * @param $id
950
-     * @return String the ident
951
-     */
944
+		}
945
+
946
+	/**
947
+	 * Check recent aircraft by id
948
+	 *
949
+	 * @param $id
950
+	 * @return String the ident
951
+	 */
952 952
 	public function checkIdRecent($id)
953 953
 	{
954 954
 		global $globalDBdriver;
@@ -974,14 +974,14 @@  discard block
 block discarded – undo
974 974
 			$ident_result = $row['fammarine_id'];
975 975
 		}
976 976
 		return $ident_result;
977
-        }
978
-
979
-    /**
980
-     * Check recent aircraft by mmsi
981
-     *
982
-     * @param $mmsi
983
-     * @return String the ident
984
-     */
977
+		}
978
+
979
+	/**
980
+	 * Check recent aircraft by mmsi
981
+	 *
982
+	 * @param $mmsi
983
+	 * @return String the ident
984
+	 */
985 985
 	public function checkMMSIRecent($mmsi)
986 986
 	{
987 987
 		global $globalDBdriver;
@@ -1007,41 +1007,41 @@  discard block
 block discarded – undo
1007 1007
 			$ident_result = $row['fammarine_id'];
1008 1008
 		}
1009 1009
 		return $ident_result;
1010
-        }
1011
-
1012
-    /**
1013
-     * Adds a new spotter data
1014
-     *
1015
-     * @param String $fammarine_id the ID from flightaware
1016
-     * @param String $ident the flight ident
1017
-     * @param string $latitude
1018
-     * @param string $longitude
1019
-     * @param string $heading
1020
-     * @param string $groundspeed
1021
-     * @param string $date
1022
-     * @param bool $putinarchive
1023
-     * @param string $mmsi
1024
-     * @param string $type
1025
-     * @param string $typeid
1026
-     * @param string $imo
1027
-     * @param string $callsign
1028
-     * @param string $arrival_code
1029
-     * @param string $arrival_date
1030
-     * @param string $status
1031
-     * @param string $statusid
1032
-     * @param bool $noarchive
1033
-     * @param string $format_source
1034
-     * @param string $source_name
1035
-     * @param string $over_country
1036
-     * @param string $captain_id
1037
-     * @param string $captain_name
1038
-     * @param string $race_id
1039
-     * @param string $race_name
1040
-     * @param string $distance
1041
-     * @param string $race_rank
1042
-     * @param string $race_time
1043
-     * @return String success or false
1044
-     */
1010
+		}
1011
+
1012
+	/**
1013
+	 * Adds a new spotter data
1014
+	 *
1015
+	 * @param String $fammarine_id the ID from flightaware
1016
+	 * @param String $ident the flight ident
1017
+	 * @param string $latitude
1018
+	 * @param string $longitude
1019
+	 * @param string $heading
1020
+	 * @param string $groundspeed
1021
+	 * @param string $date
1022
+	 * @param bool $putinarchive
1023
+	 * @param string $mmsi
1024
+	 * @param string $type
1025
+	 * @param string $typeid
1026
+	 * @param string $imo
1027
+	 * @param string $callsign
1028
+	 * @param string $arrival_code
1029
+	 * @param string $arrival_date
1030
+	 * @param string $status
1031
+	 * @param string $statusid
1032
+	 * @param bool $noarchive
1033
+	 * @param string $format_source
1034
+	 * @param string $source_name
1035
+	 * @param string $over_country
1036
+	 * @param string $captain_id
1037
+	 * @param string $captain_name
1038
+	 * @param string $race_id
1039
+	 * @param string $race_name
1040
+	 * @param string $distance
1041
+	 * @param string $race_rank
1042
+	 * @param string $race_time
1043
+	 * @return String success or false
1044
+	 */
1045 1045
 	public function addLiveMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $putinarchive = false, $mmsi = '',$type = '',$typeid = '',$imo = '', $callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$statusid = '',$noarchive = false,$format_source = '', $source_name = '', $over_country = '',$captain_id = '',$captain_name = '',$race_id = '', $race_name = '', $distance = '', $race_rank = '', $race_time = '')
1046 1046
 	{
1047 1047
 		global $globalArchive, $globalDebug;
@@ -1123,10 +1123,10 @@  discard block
 block discarded – undo
1123 1123
 		if ($statusid == '') $statusid = NULL;
1124 1124
 		if ($distance == '') $distance = NULL;
1125 1125
 
1126
-            	//if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
1127
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
1128
-            	if ($arrival_date == '') $arrival_date = NULL;
1129
-            	$query = '';
1126
+				//if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
1127
+				if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
1128
+				if ($arrival_date == '') $arrival_date = NULL;
1129
+				$query = '';
1130 1130
 		if ($globalArchive) {
1131 1131
 			if ($globalDebug) echo '-- Delete previous data -- ';
1132 1132
 			$query .= 'DELETE FROM marine_live WHERE fammarine_id = :fammarine_id;';
Please login to merge, or discard this patch.
Spacing   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -27,33 +27,33 @@  discard block
 block discarded – undo
27 27
      * @param bool $and
28 28
      * @return string the SQL part
29 29
      */
30
-	public function getFilter($filter = array(),$where = false,$and = false) {
30
+	public function getFilter($filter = array(), $where = false, $and = false) {
31 31
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
32 32
 		$filters = array();
33 33
 		if (is_array($globalStatsFilters) && isset($globalStatsFilters[$globalFilterName])) {
34 34
 			if (isset($globalStatsFilters[$globalFilterName][0]['source'])) {
35 35
 				$filters = $globalStatsFilters[$globalFilterName];
36 36
 			} else {
37
-				$filter = array_merge($filter,$globalStatsFilters[$globalFilterName]);
37
+				$filter = array_merge($filter, $globalStatsFilters[$globalFilterName]);
38 38
 			}
39 39
 		}
40 40
 		if (isset($filter[0]['source'])) {
41
-			$filters = array_merge($filters,$filter);
41
+			$filters = array_merge($filters, $filter);
42 42
 		}
43
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
43
+		if (is_array($globalFilter)) $filter = array_merge($filter, $globalFilter);
44 44
 		$filter_query_join = '';
45 45
 		$filter_query_where = '';
46
-		foreach($filters as $flt) {
46
+		foreach ($filters as $flt) {
47 47
 			if (isset($flt['idents']) && !empty($flt['idents'])) {
48 48
 				if (isset($flt['source'])) {
49
-					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','",$flt['idents'])."') AND marine_output.format_source IN ('".implode("','",$flt['source'])."')) spid ON spid.fammarine_id = marine_live.fammarine_id";
49
+					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','", $flt['idents'])."') AND marine_output.format_source IN ('".implode("','", $flt['source'])."')) spid ON spid.fammarine_id = marine_live.fammarine_id";
50 50
 				} else {
51
-					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','",$flt['idents'])."')) spid ON spid.fammarine_id = marine_live.fammarine_id";
51
+					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','", $flt['idents'])."')) spid ON spid.fammarine_id = marine_live.fammarine_id";
52 52
 				}
53 53
 			}
54 54
 		}
55 55
 		if (isset($filter['source']) && !empty($filter['source'])) {
56
-			$filter_query_where .= " AND format_source IN ('".implode("','",$filter['source'])."')";
56
+			$filter_query_where .= " AND format_source IN ('".implode("','", $filter['source'])."')";
57 57
 		}
58 58
 		if (isset($filter['ident']) && !empty($filter['ident'])) {
59 59
 			$filter_query_where .= " AND ident = '".$filter['ident']."'";
@@ -91,15 +91,15 @@  discard block
 block discarded – undo
91 91
 					$filter_query_date .= " AND EXTRACT(DAY FROM marine_output.date) = '".$filter['day']."'";
92 92
 				}
93 93
 			}
94
-			$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output".preg_replace('/^ AND/',' WHERE',$filter_query_date).") sd ON sd.fammarine_id = marine_live.fammarine_id";
94
+			$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output".preg_replace('/^ AND/', ' WHERE', $filter_query_date).") sd ON sd.fammarine_id = marine_live.fammarine_id";
95 95
 		}
96 96
 		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
97
-			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
97
+			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','", $filter['source_aprs'])."')";
98 98
 		}
99 99
 		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
100 100
 		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
101 101
 		if ($filter_query_where != '') {
102
-			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
102
+			$filter_query_where = preg_replace('/^ AND/', ' WHERE', $filter_query_where);
103 103
 		}
104 104
 		$filter_query = $filter_query_join.$filter_query_where;
105 105
 		return $filter_query;
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
 		if ($limit != '')
125 125
 		{
126 126
 			$limit_array = explode(',', $limit);
127
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
128
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
127
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
128
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
129 129
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
130 130
 			{
131 131
 				$limit_query = ' LIMIT '.$limit_array[1].' OFFSET '.$limit_array[0];
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 				$orderby_query = ' '.$search_orderby_array[$sort]['sql'];
141 141
 			}
142 142
 		}
143
-		if ($orderby_query == '') $orderby_query= ' ORDER BY date DESC';
143
+		if ($orderby_query == '') $orderby_query = ' ORDER BY date DESC';
144 144
 
145 145
 		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
146 146
 		if ($globalDBdriver == 'mysql') {
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 		} else {
150 150
 			$query  = "SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate".$filter_query.$orderby_query;
151 151
 		}
152
-		$spotter_array = $Marine->getDataFromDB($query.$limit_query,array(),'',true);
152
+		$spotter_array = $Marine->getDataFromDB($query.$limit_query, array(), '', true);
153 153
 
154 154
 		return $spotter_array;
155 155
 	}
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 		global $globalDBdriver, $globalLiveInterval;
166 166
 		date_default_timezone_set('UTC');
167 167
 
168
-		$filter_query = $this->getFilter($filter,true,true);
168
+		$filter_query = $this->getFilter($filter, true, true);
169 169
 
170 170
 		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
171 171
 		if ($globalDBdriver == 'mysql') {
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 		try {
180 180
 			$sth = $this->db->prepare($query);
181 181
 			$sth->execute();
182
-		} catch(PDOException $e) {
182
+		} catch (PDOException $e) {
183 183
 			echo $e->getMessage();
184 184
 			die;
185 185
 		}
@@ -197,26 +197,26 @@  discard block
 block discarded – undo
197 197
      * @param string $id
198 198
      * @return array the spotter information
199 199
      */
200
-	public function getMinLastLiveMarineData($coord = array(),$filter = array(), $limit = false, $id = '')
200
+	public function getMinLastLiveMarineData($coord = array(), $filter = array(), $limit = false, $id = '')
201 201
 	{
202 202
 		global $globalDBdriver, $globalLiveInterval, $globalMap3DMarinesLimit, $globalArchive;
203 203
 		date_default_timezone_set('UTC');
204 204
 		$usecoord = false;
205 205
 		if (is_array($coord) && !empty($coord)) {
206
-			$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
207
-			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
208
-			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
209
-			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
206
+			$minlong = filter_var($coord[0], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
207
+			$minlat = filter_var($coord[1], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
208
+			$maxlong = filter_var($coord[2], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
209
+			$maxlat = filter_var($coord[3], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
210 210
 			$usecoord = true;
211 211
 		}
212
-		$id = filter_var($id,FILTER_SANITIZE_STRING);
213
-		$filter_query = $this->getFilter($filter,true,true);
212
+		$id = filter_var($id, FILTER_SANITIZE_STRING);
213
+		$filter_query = $this->getFilter($filter, true, true);
214 214
 
215 215
 		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
216 216
 		if (!isset($globalMap3DMarinesLimit) || $globalMap3DMarinesLimit == '') $globalMap3DMarinesLimit = '300';
217 217
 		if ($globalDBdriver == 'mysql') {
218 218
 			if (isset($globalArchive) && $globalArchive === TRUE) {
219
-				$query  = 'SELECT * FROM (SELECT marine_archive.ident, marine_archive.fammarine_id,marine_archive.type_id,marine_archive.type, marine_archive.latitude, marine_archive.longitude, marine_archive.heading, marine_archive.ground_speed, marine_archive.date, marine_archive.format_source, marine_archive.captain_name, marine_archive.race_id, marine_archive.race_rank, marine_archive.race_name 
219
+				$query = 'SELECT * FROM (SELECT marine_archive.ident, marine_archive.fammarine_id,marine_archive.type_id,marine_archive.type, marine_archive.latitude, marine_archive.longitude, marine_archive.heading, marine_archive.ground_speed, marine_archive.date, marine_archive.format_source, marine_archive.captain_name, marine_archive.race_id, marine_archive.race_rank, marine_archive.race_name 
220 220
 				    FROM marine_archive INNER JOIN (SELECT fammarine_id FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= marine_live.date) l ON l.fammarine_id = marine_archive.fammarine_id ";
221 221
 				if ($usecoord) $query .= "AND marine_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_archive.longitude BETWEEN ".$minlong." AND ".$maxlong." ";
222 222
 				if ($id != '') $query .= "OR marine_archive.fammarine_id = :id ";
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 				    ORDER BY fammarine_id, date";
231 231
 				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
232 232
 			} else {
233
-				$query  = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
233
+				$query = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
234 234
 				    FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= marine_live.date ";
235 235
 				if ($usecoord) $query .= "AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong." ";
236 236
 				if ($id != '') $query .= "OR marine_live.fammarine_id = :id ";
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 			}
241 241
 		} else {
242 242
 			if (isset($globalArchive) && $globalArchive === TRUE) {
243
-				$query  = "SELECT * FROM (SELECT marine_archive.ident, marine_archive.fammarine_id, marine_archive.type_id, marine_archive.type,marine_archive.latitude, marine_archive.longitude, marine_archive.heading, marine_archive.ground_speed, marine_archive.date, marine_archive.format_source, marine_archive.captain_name, marine_archive.race_id, marine_archive.race_rank, marine_archive.race_name 
243
+				$query = "SELECT * FROM (SELECT marine_archive.ident, marine_archive.fammarine_id, marine_archive.type_id, marine_archive.type,marine_archive.latitude, marine_archive.longitude, marine_archive.heading, marine_archive.ground_speed, marine_archive.date, marine_archive.format_source, marine_archive.captain_name, marine_archive.race_id, marine_archive.race_rank, marine_archive.race_name 
244 244
 				    FROM marine_archive INNER JOIN (SELECT fammarine_id FROM marine_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= marine_live.date) l ON l.fammarine_id = marine_archive.fammarine_id ";
245 245
 				if ($usecoord) $query .= "AND (marine_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_archive.longitude BETWEEN ".$minlong." AND ".$maxlong.") ";
246 246
 				if ($id != '') $query .= "OR marine_archive.fammarine_id = :id ";
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 		try {
268 268
 			$sth = $this->db->prepare($query);
269 269
 			$sth->execute($query_values);
270
-		} catch(PDOException $e) {
270
+		} catch (PDOException $e) {
271 271
 			echo $e->getMessage();
272 272
 			die;
273 273
 		}
@@ -283,12 +283,12 @@  discard block
 block discarded – undo
283 283
      * @param bool $limit
284 284
      * @return array the spotter information
285 285
      */
286
-	public function getMinLastLiveMarineDataByID($id = '',$filter = array(), $limit = false)
286
+	public function getMinLastLiveMarineDataByID($id = '', $filter = array(), $limit = false)
287 287
 	{
288 288
 		global $globalDBdriver, $globalLiveInterval, $globalMap3DMarinesLimit, $globalArchive;
289 289
 		date_default_timezone_set('UTC');
290
-		$id = filter_var($id,FILTER_SANITIZE_STRING);
291
-		$filter_query = $this->getFilter($filter,true,true);
290
+		$id = filter_var($id, FILTER_SANITIZE_STRING);
291
+		$filter_query = $this->getFilter($filter, true, true);
292 292
 
293 293
 		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
294 294
 		if (!isset($globalMap3DMarinesLimit) || $globalMap3DMarinesLimit == '') $globalMap3DMarinesLimit = '300';
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 		try {
334 334
 			$sth = $this->db->prepare($query);
335 335
 			$sth->execute($query_values);
336
-		} catch(PDOException $e) {
336
+		} catch (PDOException $e) {
337 337
 			echo $e->getMessage();
338 338
 			die;
339 339
 		}
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
 	public function getLiveMarineCount($filter = array())
351 351
 	{
352 352
 		global $globalDBdriver, $globalLiveInterval;
353
-		$filter_query = $this->getFilter($filter,true,true);
353
+		$filter_query = $this->getFilter($filter, true, true);
354 354
 
355 355
 		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
356 356
 		if ($globalDBdriver == 'mysql') {
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
 		try {
362 362
 			$sth = $this->db->prepare($query);
363 363
 			$sth->execute();
364
-		} catch(PDOException $e) {
364
+		} catch (PDOException $e) {
365 365
 			echo $e->getMessage();
366 366
 			die;
367 367
 		}
@@ -385,10 +385,10 @@  discard block
 block discarded – undo
385 385
 		$filter_query = $this->getFilter($filter);
386 386
 
387 387
 		if (is_array($coord)) {
388
-			$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
389
-			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
390
-			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
391
-			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
388
+			$minlong = filter_var($coord[0], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
389
+			$minlat = filter_var($coord[1], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
390
+			$maxlong = filter_var($coord[2], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
391
+			$maxlat = filter_var($coord[3], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
392 392
 		} else return array();
393 393
 		if ($globalDBdriver == 'mysql') {
394 394
 			$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND marine_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND marine_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.' GROUP BY marine_live.fammarine_id ORDER BY date DESC'.$filter_query;
@@ -411,13 +411,13 @@  discard block
 block discarded – undo
411 411
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
412 412
 		$Marine = new Marine($this->db);
413 413
 		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
414
-		$filter_query = $this->getFilter($filter,true,true);
414
+		$filter_query = $this->getFilter($filter, true, true);
415 415
 
416 416
 		if (is_array($coord)) {
417
-			$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
418
-			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
419
-			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
420
-			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
417
+			$minlong = filter_var($coord[0], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
418
+			$minlat = filter_var($coord[1], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
419
+			$maxlong = filter_var($coord[2], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
420
+			$maxlat = filter_var($coord[3], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
421 421
 		} else return array();
422 422
 		/*
423 423
 		if ($globalDBdriver == 'mysql') {
@@ -432,13 +432,13 @@  discard block
 block discarded – undo
432 432
 		*/
433 433
 		if ($globalDBdriver == 'mysql') {
434 434
 			if (isset($globalArchive) && $globalArchive === TRUE) {
435
-				$query  = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
435
+				$query = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
436 436
 				    FROM marine_live 
437 437
 				    '.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= marine_live.date 
438 438
 				    AND marine_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND marine_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.'
439 439
 				    AND marine_live.latitude <> 0 AND marine_live.longitude <> 0 ORDER BY race_rank,date DESC';
440 440
 			} else {
441
-				$query  = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
441
+				$query = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
442 442
 				    FROM marine_live 
443 443
 				    INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate 
444 444
 				    FROM marine_live l 
@@ -450,14 +450,14 @@  discard block
 block discarded – undo
450 450
 			}
451 451
 		} else {
452 452
 			if (isset($globalArchive) && $globalArchive === TRUE) {
453
-				$query  = "SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
453
+				$query = "SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
454 454
 				    FROM marine_live 
455 455
 				    ".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= marine_live.date 
456 456
 				    AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." 
457 457
 				    AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong." 
458 458
 				    AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' ORDER BY race_rank, date DESC";
459 459
 			} else {
460
-				$query  = "SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
460
+				$query = "SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
461 461
 				    FROM marine_live 
462 462
 				    INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate 
463 463
 				    FROM marine_live l 
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
 				if ($interval == '1m')
518 518
 				{
519 519
 					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
520
-				} else if ($interval == '15m'){
520
+				} else if ($interval == '15m') {
521 521
 					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= marine_live.date ';
522 522
 				}
523 523
 			}
@@ -525,14 +525,14 @@  discard block
 block discarded – undo
525 525
 			$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
526 526
 		}
527 527
 
528
-		$query  = "SELECT marine_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM marine_live 
528
+		$query = "SELECT marine_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM marine_live 
529 529
                    WHERE marine_live.latitude <> '' 
530 530
                                    AND marine_live.longitude <> '' 
531 531
                    ".$additional_query."
532 532
                    HAVING distance < :radius  
533 533
                                    ORDER BY distance";
534 534
 
535
-		$spotter_array = $Marine->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius));
535
+		$spotter_array = $Marine->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng, ':radius' => $radius));
536 536
 
537 537
 		return $spotter_array;
538 538
 	}
@@ -550,9 +550,9 @@  discard block
 block discarded – undo
550 550
 		date_default_timezone_set('UTC');
551 551
 
552 552
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
553
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
553
+                $query = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
554 554
 
555
-		$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident),'',true);
555
+		$spotter_array = $Marine->getDataFromDB($query, array(':ident' => $ident), '', true);
556 556
 
557 557
 		return $spotter_array;
558 558
 	}
@@ -564,14 +564,14 @@  discard block
 block discarded – undo
564 564
      * @param $date
565 565
      * @return array the spotter information
566 566
      */
567
-	public function getDateLiveMarineDataByIdent($ident,$date)
567
+	public function getDateLiveMarineDataByIdent($ident, $date)
568 568
 	{
569 569
 		$Marine = new Marine($this->db);
570 570
 		date_default_timezone_set('UTC');
571 571
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
572 572
 		$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
573
-		$date = date('c',$date);
574
-		$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident,':date' => $date));
573
+		$date = date('c', $date);
574
+		$spotter_array = $Marine->getDataFromDB($query, array(':ident' => $ident, ':date' => $date));
575 575
 		return $spotter_array;
576 576
 	}
577 577
 
@@ -582,14 +582,14 @@  discard block
 block discarded – undo
582 582
      * @param $date
583 583
      * @return array the spotter information
584 584
      */
585
-	public function getDateLiveMarineDataByMMSI($mmsi,$date)
585
+	public function getDateLiveMarineDataByMMSI($mmsi, $date)
586 586
 	{
587 587
 		$Marine = new Marine($this->db);
588 588
 		date_default_timezone_set('UTC');
589 589
 		$mmsi = filter_var($mmsi, FILTER_SANITIZE_NUMBER_INT);
590 590
 		$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.mmsi = :mmsi AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
591
-		$date = date('c',$date);
592
-		$spotter_array = $Marine->getDataFromDB($query,array(':mmsi' => $mmsi,':date' => $date));
591
+		$date = date('c', $date);
592
+		$spotter_array = $Marine->getDataFromDB($query, array(':mmsi' => $mmsi, ':date' => $date));
593 593
 		return $spotter_array;
594 594
 	}
595 595
 
@@ -605,9 +605,9 @@  discard block
 block discarded – undo
605 605
 		date_default_timezone_set('UTC');
606 606
 
607 607
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
608
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
608
+                $query = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
609 609
 
610
-		$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id),'',true);
610
+		$spotter_array = $Marine->getDataFromDB($query, array(':id' => $id), '', true);
611 611
 
612 612
 		return $spotter_array;
613 613
 	}
@@ -619,15 +619,15 @@  discard block
 block discarded – undo
619 619
      * @param $date
620 620
      * @return array the spotter information
621 621
      */
622
-	public function getDateLiveMarineDataById($id,$date)
622
+	public function getDateLiveMarineDataById($id, $date)
623 623
 	{
624 624
 		$Marine = new Marine($this->db);
625 625
 		date_default_timezone_set('UTC');
626 626
 
627 627
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
628
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
629
-                $date = date('c',$date);
630
-		$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id,':date' => $date),'',true);
628
+                $query = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
629
+                $date = date('c', $date);
630
+		$spotter_array = $Marine->getDataFromDB($query, array(':id' => $id, ':date' => $date), '', true);
631 631
 
632 632
 		return $spotter_array;
633 633
 	}
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
      * @param bool $liveinterval
641 641
      * @return array the spotter information
642 642
      */
643
-	public function getAllLiveMarineDataById($id,$liveinterval = false)
643
+	public function getAllLiveMarineDataById($id, $liveinterval = false)
644 644
 	{
645 645
 		global $globalDBdriver, $globalLiveInterval;
646 646
 		date_default_timezone_set('UTC');
@@ -659,7 +659,7 @@  discard block
 block discarded – undo
659 659
 		try {
660 660
 			$sth = $this->db->prepare($query);
661 661
 			$sth->execute(array(':id' => $id));
662
-		} catch(PDOException $e) {
662
+		} catch (PDOException $e) {
663 663
 			echo $e->getMessage();
664 664
 			die;
665 665
 		}
@@ -677,12 +677,12 @@  discard block
 block discarded – undo
677 677
 	{
678 678
 		date_default_timezone_set('UTC');
679 679
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
680
-		$query  = self::$global_query.' WHERE marine_live.ident = :ident';
680
+		$query = self::$global_query.' WHERE marine_live.ident = :ident';
681 681
     		try {
682 682
 			
683 683
 			$sth = $this->db->prepare($query);
684 684
 			$sth->execute(array(':ident' => $ident));
685
-		} catch(PDOException $e) {
685
+		} catch (PDOException $e) {
686 686
 			echo $e->getMessage();
687 687
 			die;
688 688
 		}
@@ -712,7 +712,7 @@  discard block
 block discarded – undo
712 712
 			
713 713
 			$sth = $this->db->prepare($query);
714 714
 			$sth->execute();
715
-		} catch(PDOException $e) {
715
+		} catch (PDOException $e) {
716 716
 			return "error";
717 717
 		}
718 718
 
@@ -735,14 +735,14 @@  discard block
 block discarded – undo
735 735
 				
736 736
 				$sth = $this->db->prepare($query);
737 737
 				$sth->execute();
738
-			} catch(PDOException $e) {
738
+			} catch (PDOException $e) {
739 739
 				return "error";
740 740
 			}
741 741
 			$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
742 742
                         $i = 0;
743
-                        $j =0;
743
+                        $j = 0;
744 744
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
745
-			foreach($all as $row)
745
+			foreach ($all as $row)
746 746
 			{
747 747
 				$i++;
748 748
 				$j++;
@@ -750,9 +750,9 @@  discard block
 block discarded – undo
750 750
 					if ($globalDebug) echo ".";
751 751
 				    	try {
752 752
 						
753
-						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
753
+						$sth = $this->db->prepare(substr($query_delete, 0, -1).")");
754 754
 						$sth->execute();
755
-					} catch(PDOException $e) {
755
+					} catch (PDOException $e) {
756 756
 						return "error";
757 757
 					}
758 758
                                 	$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
@@ -763,9 +763,9 @@  discard block
 block discarded – undo
763 763
 			if ($i > 0) {
764 764
     				try {
765 765
 					
766
-					$sth = $this->db->prepare(substr($query_delete,0,-1).")");
766
+					$sth = $this->db->prepare(substr($query_delete, 0, -1).")");
767 767
 					$sth->execute();
768
-				} catch(PDOException $e) {
768
+				} catch (PDOException $e) {
769 769
 					return "error";
770 770
 				}
771 771
 			}
@@ -778,7 +778,7 @@  discard block
 block discarded – undo
778 778
 				
779 779
 				$sth = $this->db->prepare($query);
780 780
 				$sth->execute();
781
-			} catch(PDOException $e) {
781
+			} catch (PDOException $e) {
782 782
 				return "error";
783 783
 			}
784 784
 /*			$query_delete = "DELETE FROM marine_live WHERE fammarine_id IN (";
@@ -827,13 +827,13 @@  discard block
 block discarded – undo
827 827
 	public function deleteLiveMarineDataByIdent($ident)
828 828
 	{
829 829
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
830
-		$query  = 'DELETE FROM marine_live WHERE ident = :ident';
830
+		$query = 'DELETE FROM marine_live WHERE ident = :ident';
831 831
         
832 832
     		try {
833 833
 			
834 834
 			$sth = $this->db->prepare($query);
835 835
 			$sth->execute(array(':ident' => $ident));
836
-		} catch(PDOException $e) {
836
+		} catch (PDOException $e) {
837 837
 			return "error";
838 838
 		}
839 839
 
@@ -849,13 +849,13 @@  discard block
 block discarded – undo
849 849
 	public function deleteLiveMarineDataById($id)
850 850
 	{
851 851
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
852
-		$query  = 'DELETE FROM marine_live WHERE fammarine_id = :id';
852
+		$query = 'DELETE FROM marine_live WHERE fammarine_id = :id';
853 853
         
854 854
     		try {
855 855
 			
856 856
 			$sth = $this->db->prepare($query);
857 857
 			$sth->execute(array(':id' => $id));
858
-		} catch(PDOException $e) {
858
+		} catch (PDOException $e) {
859 859
 			return "error";
860 860
 		}
861 861
 
@@ -871,7 +871,7 @@  discard block
 block discarded – undo
871 871
 	*/
872 872
 	public function getAllRaces()
873 873
 	{
874
-		$query  = 'SELECT DISTINCT marine_live.race_id, marine_live.race_name FROM marine_live ORDER BY marine_live.race_name';
874
+		$query = 'SELECT DISTINCT marine_live.race_id, marine_live.race_name FROM marine_live ORDER BY marine_live.race_name';
875 875
 		$sth = $this->db->prepare($query);
876 876
 		$sth->execute();
877 877
 		return $sth->fetchAll(PDO::FETCH_ASSOC);
@@ -887,13 +887,13 @@  discard block
 block discarded – undo
887 887
 	{
888 888
 		global $globalDBdriver;
889 889
 		if ($globalDBdriver == 'mysql') {
890
-			$query  = 'SELECT marine_live.ident FROM marine_live 
890
+			$query = 'SELECT marine_live.ident FROM marine_live 
891 891
 				WHERE marine_live.ident = :ident 
892 892
 				AND marine_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) 
893 893
 				AND marine_live.date < UTC_TIMESTAMP()';
894 894
 			$query_data = array(':ident' => $ident);
895 895
 		} else {
896
-			$query  = "SELECT marine_live.ident FROM marine_live 
896
+			$query = "SELECT marine_live.ident FROM marine_live 
897 897
 				WHERE marine_live.ident = :ident 
898 898
 				AND marine_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
899 899
 				AND marine_live.date < now() AT TIME ZONE 'UTC'";
@@ -902,8 +902,8 @@  discard block
 block discarded – undo
902 902
 		
903 903
 		$sth = $this->db->prepare($query);
904 904
 		$sth->execute($query_data);
905
-		$ident_result='';
906
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
905
+		$ident_result = '';
906
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
907 907
 		{
908 908
 			$ident_result = $row['ident'];
909 909
 		}
@@ -920,13 +920,13 @@  discard block
 block discarded – undo
920 920
 	{
921 921
 		global $globalDBdriver;
922 922
 		if ($globalDBdriver == 'mysql') {
923
-			$query  = 'SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
923
+			$query = 'SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
924 924
 				WHERE marine_live.ident = :ident 
925 925
 				AND marine_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE)'; 
926 926
 //				AND marine_live.date < UTC_TIMESTAMP()";
927 927
 			$query_data = array(':ident' => $ident);
928 928
 		} else {
929
-			$query  = "SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
929
+			$query = "SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
930 930
 				WHERE marine_live.ident = :ident 
931 931
 				AND marine_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '30 MINUTES'";
932 932
 //				AND marine_live.date < now() AT TIME ZONE 'UTC'";
@@ -935,8 +935,8 @@  discard block
 block discarded – undo
935 935
 		
936 936
 		$sth = $this->db->prepare($query);
937 937
 		$sth->execute($query_data);
938
-		$ident_result='';
939
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
938
+		$ident_result = '';
939
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
940 940
 		{
941 941
 			$ident_result = $row['fammarine_id'];
942 942
 		}
@@ -953,13 +953,13 @@  discard block
 block discarded – undo
953 953
 	{
954 954
 		global $globalDBdriver;
955 955
 		if ($globalDBdriver == 'mysql') {
956
-			$query  = 'SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
956
+			$query = 'SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
957 957
 				WHERE marine_live.fammarine_id = :id 
958 958
 				AND marine_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 10 HOUR)'; 
959 959
 //				AND marine_live.date < UTC_TIMESTAMP()";
960 960
 			$query_data = array(':id' => $id);
961 961
 		} else {
962
-			$query  = "SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
962
+			$query = "SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
963 963
 				WHERE marine_live.fammarine_id = :id 
964 964
 				AND marine_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '10 HOUR'";
965 965
 //				AND marine_live.date < now() AT TIME ZONE 'UTC'";
@@ -968,8 +968,8 @@  discard block
 block discarded – undo
968 968
 		
969 969
 		$sth = $this->db->prepare($query);
970 970
 		$sth->execute($query_data);
971
-		$ident_result='';
972
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
971
+		$ident_result = '';
972
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
973 973
 		{
974 974
 			$ident_result = $row['fammarine_id'];
975 975
 		}
@@ -986,13 +986,13 @@  discard block
 block discarded – undo
986 986
 	{
987 987
 		global $globalDBdriver;
988 988
 		if ($globalDBdriver == 'mysql') {
989
-			$query  = 'SELECT marine_live.fammarine_id FROM marine_live 
989
+			$query = 'SELECT marine_live.fammarine_id FROM marine_live 
990 990
 				WHERE marine_live.mmsi = :mmsi 
991 991
 				AND marine_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 10 HOUR)'; 
992 992
 //				AND marine_live.date < UTC_TIMESTAMP()";
993 993
 			$query_data = array(':mmsi' => $mmsi);
994 994
 		} else {
995
-			$query  = "SELECT marine_live.fammarine_id FROM marine_live 
995
+			$query = "SELECT marine_live.fammarine_id FROM marine_live 
996 996
 				WHERE marine_live.mmsi = :mmsi 
997 997
 				AND marine_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '10 HOUR'";
998 998
 //				AND marine_live.date < now() AT TIME ZONE 'UTC'";
@@ -1001,8 +1001,8 @@  discard block
 block discarded – undo
1001 1001
 		
1002 1002
 		$sth = $this->db->prepare($query);
1003 1003
 		$sth->execute($query_data);
1004
-		$ident_result='';
1005
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1004
+		$ident_result = '';
1005
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1006 1006
 		{
1007 1007
 			$ident_result = $row['fammarine_id'];
1008 1008
 		}
@@ -1042,7 +1042,7 @@  discard block
 block discarded – undo
1042 1042
      * @param string $race_time
1043 1043
      * @return String success or false
1044 1044
      */
1045
-	public function addLiveMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $putinarchive = false, $mmsi = '',$type = '',$typeid = '',$imo = '', $callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$statusid = '',$noarchive = false,$format_source = '', $source_name = '', $over_country = '',$captain_id = '',$captain_name = '',$race_id = '', $race_name = '', $distance = '', $race_rank = '', $race_time = '')
1045
+	public function addLiveMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $putinarchive = false, $mmsi = '', $type = '', $typeid = '', $imo = '', $callsign = '', $arrival_code = '', $arrival_date = '', $status = '', $statusid = '', $noarchive = false, $format_source = '', $source_name = '', $over_country = '', $captain_id = '', $captain_name = '', $race_id = '', $race_name = '', $distance = '', $race_rank = '', $race_time = '')
1046 1046
 	{
1047 1047
 		global $globalArchive, $globalDebug;
1048 1048
 		$Common = new Common();
@@ -1094,39 +1094,39 @@  discard block
 block discarded – undo
1094 1094
 		if ($date == '') $date = date("Y-m-d H:i:s", time());
1095 1095
 
1096 1096
         
1097
-		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
1098
-		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
1099
-		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1100
-		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1101
-		$distance = filter_var($distance,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1102
-		$heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT);
1103
-		$groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1104
-		$format_source = filter_var($format_source,FILTER_SANITIZE_STRING);
1105
-		$source_name = filter_var($source_name,FILTER_SANITIZE_STRING);
1106
-		$over_country = filter_var($over_country,FILTER_SANITIZE_STRING);
1107
-		$type = filter_var($type,FILTER_SANITIZE_STRING);
1108
-		$typeid = filter_var($typeid,FILTER_SANITIZE_NUMBER_INT);
1109
-		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
1110
-		$status = filter_var($status,FILTER_SANITIZE_STRING);
1111
-		$statusid = filter_var($statusid,FILTER_SANITIZE_NUMBER_INT);
1112
-		$imo = filter_var($imo,FILTER_SANITIZE_STRING);
1113
-		$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
1114
-		$arrival_code = filter_var($arrival_code,FILTER_SANITIZE_STRING);
1115
-		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING);
1116
-		$captain_id = filter_var($captain_id,FILTER_SANITIZE_STRING);
1117
-		$captain_name = filter_var($captain_name,FILTER_SANITIZE_STRING);
1118
-		$race_id = filter_var($race_id,FILTER_SANITIZE_STRING);
1119
-		$race_name = filter_var($race_name,FILTER_SANITIZE_STRING);
1120
-		$race_rank = filter_var($race_rank,FILTER_SANITIZE_NUMBER_INT);
1097
+		$fammarine_id = filter_var($fammarine_id, FILTER_SANITIZE_STRING);
1098
+		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
1099
+		$latitude = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
1100
+		$longitude = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
1101
+		$distance = filter_var($distance, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
1102
+		$heading = filter_var($heading, FILTER_SANITIZE_NUMBER_INT);
1103
+		$groundspeed = filter_var($groundspeed, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
1104
+		$format_source = filter_var($format_source, FILTER_SANITIZE_STRING);
1105
+		$source_name = filter_var($source_name, FILTER_SANITIZE_STRING);
1106
+		$over_country = filter_var($over_country, FILTER_SANITIZE_STRING);
1107
+		$type = filter_var($type, FILTER_SANITIZE_STRING);
1108
+		$typeid = filter_var($typeid, FILTER_SANITIZE_NUMBER_INT);
1109
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_NUMBER_INT);
1110
+		$status = filter_var($status, FILTER_SANITIZE_STRING);
1111
+		$statusid = filter_var($statusid, FILTER_SANITIZE_NUMBER_INT);
1112
+		$imo = filter_var($imo, FILTER_SANITIZE_STRING);
1113
+		$callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
1114
+		$arrival_code = filter_var($arrival_code, FILTER_SANITIZE_STRING);
1115
+		$arrival_date = filter_var($arrival_date, FILTER_SANITIZE_STRING);
1116
+		$captain_id = filter_var($captain_id, FILTER_SANITIZE_STRING);
1117
+		$captain_name = filter_var($captain_name, FILTER_SANITIZE_STRING);
1118
+		$race_id = filter_var($race_id, FILTER_SANITIZE_STRING);
1119
+		$race_name = filter_var($race_name, FILTER_SANITIZE_STRING);
1120
+		$race_rank = filter_var($race_rank, FILTER_SANITIZE_NUMBER_INT);
1121 1121
 		if ($race_rank == '') $race_rank = NULL;
1122
-		$race_time = filter_var($race_time,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1122
+		$race_time = filter_var($race_time, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
1123 1123
 		if ($race_time == '') $race_time = NULL;
1124 1124
 		if ($typeid == '') $typeid = NULL;
1125 1125
 		if ($statusid == '') $statusid = NULL;
1126 1126
 		if ($distance == '') $distance = NULL;
1127 1127
 
1128 1128
             	//if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
1129
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
1129
+            	if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
1130 1130
             	if ($arrival_date == '') $arrival_date = NULL;
1131 1131
             	$query = '';
1132 1132
 		if ($globalArchive) {
@@ -1135,19 +1135,19 @@  discard block
 block discarded – undo
1135 1135
 		}
1136 1136
 		$query .= 'INSERT INTO marine_live (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, over_country, mmsi, type,type_id,status,status_id,imo,arrival_port_name,arrival_port_date,captain_id,captain_name,race_id,race_name,distance,race_rank,race_time) 
1137 1137
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:groundspeed,:date,:format_source, :source_name, :over_country,:mmsi,:type,:typeid,:status,:statusid,:imo,:arrival_port_name,:arrival_port_date,:captain_id,:captain_name,:race_id,:race_name,:distance,:race_rank,:race_time)';
1138
-		$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident,':latitude' => $latitude,':longitude' => $longitude,':heading' => $heading,':groundspeed' => $groundspeed,':date' => $date, ':format_source' => $format_source, ':source_name' => $source_name, ':over_country' => $over_country,':mmsi' => $mmsi,':type' => $type,':typeid' => $typeid,':status' => $status,':statusid' => $statusid,':imo' => $imo,':arrival_port_name' => $arrival_code,':arrival_port_date' => $arrival_date,':captain_id' => $captain_id,':captain_name' => $captain_name,':race_id' => $race_id,':race_name' => $race_name,':distance' => $distance,':race_time' => $race_time,':race_rank' => $race_rank);
1138
+		$query_values = array(':fammarine_id' => $fammarine_id, ':ident' => $ident, ':latitude' => $latitude, ':longitude' => $longitude, ':heading' => $heading, ':groundspeed' => $groundspeed, ':date' => $date, ':format_source' => $format_source, ':source_name' => $source_name, ':over_country' => $over_country, ':mmsi' => $mmsi, ':type' => $type, ':typeid' => $typeid, ':status' => $status, ':statusid' => $statusid, ':imo' => $imo, ':arrival_port_name' => $arrival_code, ':arrival_port_date' => $arrival_date, ':captain_id' => $captain_id, ':captain_name' => $captain_name, ':race_id' => $race_id, ':race_name' => $race_name, ':distance' => $distance, ':race_time' => $race_time, ':race_rank' => $race_rank);
1139 1139
 		try {
1140 1140
 			$sth = $this->db->prepare($query);
1141 1141
 			$sth->execute($query_values);
1142 1142
 			$sth->closeCursor();
1143
-		} catch(PDOException $e) {
1143
+		} catch (PDOException $e) {
1144 1144
 			return "error : ".$e->getMessage();
1145 1145
 		}
1146 1146
 		
1147 1147
 		if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) {
1148 1148
 			if ($globalDebug) echo '(Add to Marine archive : ';
1149 1149
 			$MarineArchive = new MarineArchive($this->db);
1150
-			$result =  $MarineArchive->addMarineArchiveData($fammarine_id, $ident, $latitude, $longitude, $heading, $groundspeed, $date, $putinarchive, $mmsi,$type,$typeid,$imo, $callsign,$arrival_code,$arrival_date,$status,$statusid,$noarchive,$format_source, $source_name, $over_country,$captain_id,$captain_name,$race_id,$race_name,$distance,$race_rank,$race_time);
1150
+			$result = $MarineArchive->addMarineArchiveData($fammarine_id, $ident, $latitude, $longitude, $heading, $groundspeed, $date, $putinarchive, $mmsi, $type, $typeid, $imo, $callsign, $arrival_code, $arrival_date, $status, $statusid, $noarchive, $format_source, $source_name, $over_country, $captain_id, $captain_name, $race_id, $race_name, $distance, $race_rank, $race_time);
1151 1151
 			if ($globalDebug) echo $result.')';
1152 1152
 		}
1153 1153
 		return "success";
@@ -1155,7 +1155,7 @@  discard block
 block discarded – undo
1155 1155
 
1156 1156
 	public function getOrderBy()
1157 1157
 	{
1158
-		$orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY marine_live.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY marine_live.aircraft_icao DESC"),"manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY marine_live.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY marine_live.aircraft_manufacturer DESC"),"airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY marine_live.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY marine_live.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY marine_live.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY marine_live.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY marine_live.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY marine_live.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY marine_live.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY marine_live.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY marine_live.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY marine_live.date DESC"));
1158
+		$orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY marine_live.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY marine_live.aircraft_icao DESC"), "manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY marine_live.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY marine_live.aircraft_manufacturer DESC"), "airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY marine_live.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY marine_live.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY marine_live.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY marine_live.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY marine_live.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY marine_live.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY marine_live.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY marine_live.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY marine_live.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY marine_live.date DESC"));
1159 1159
 		return $orderby;
1160 1160
 	}
1161 1161
 
Please login to merge, or discard this patch.
Braces   +164 added lines, -55 removed lines patch added patch discarded remove patch
@@ -16,7 +16,9 @@  discard block
 block discarded – undo
16 16
 	public function __construct($dbc = null) {
17 17
 		$Connection = new Connection($dbc);
18 18
 		$this->db = $Connection->db();
19
-		if ($this->db === null) die('Error: No DB connection. (MarineLive)');
19
+		if ($this->db === null) {
20
+			die('Error: No DB connection. (MarineLive)');
21
+		}
20 22
 	}
21 23
 
22 24
 
@@ -40,7 +42,9 @@  discard block
 block discarded – undo
40 42
 		if (isset($filter[0]['source'])) {
41 43
 			$filters = array_merge($filters,$filter);
42 44
 		}
43
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
45
+		if (is_array($globalFilter)) {
46
+			$filter = array_merge($filter,$globalFilter);
47
+		}
44 48
 		$filter_query_join = '';
45 49
 		$filter_query_where = '';
46 50
 		foreach($filters as $flt) {
@@ -96,8 +100,11 @@  discard block
 block discarded – undo
96 100
 		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
97 101
 			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
98 102
 		}
99
-		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
100
-		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
103
+		if ($filter_query_where == '' && $where) {
104
+			$filter_query_where = ' WHERE';
105
+		} elseif ($filter_query_where != '' && $and) {
106
+			$filter_query_where .= ' AND';
107
+		}
101 108
 		if ($filter_query_where != '') {
102 109
 			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
103 110
 		}
@@ -140,9 +147,13 @@  discard block
 block discarded – undo
140 147
 				$orderby_query = ' '.$search_orderby_array[$sort]['sql'];
141 148
 			}
142 149
 		}
143
-		if ($orderby_query == '') $orderby_query= ' ORDER BY date DESC';
150
+		if ($orderby_query == '') {
151
+			$orderby_query= ' ORDER BY date DESC';
152
+		}
144 153
 
145
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
154
+		if (!isset($globalLiveInterval)) {
155
+			$globalLiveInterval = '200';
156
+		}
146 157
 		if ($globalDBdriver == 'mysql') {
147 158
 			//$query  = "SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate";
148 159
 			$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate'.$filter_query.$orderby_query;
@@ -167,7 +178,9 @@  discard block
 block discarded – undo
167 178
 
168 179
 		$filter_query = $this->getFilter($filter,true,true);
169 180
 
170
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
181
+		if (!isset($globalLiveInterval)) {
182
+			$globalLiveInterval = '200';
183
+		}
171 184
 		if ($globalDBdriver == 'mysql') {
172 185
 			$query  = 'SELECT marine_live.mmsi, marine_live.ident, marine_live.type,marine_live.fammarine_id, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
173 186
 			FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate'.$filter_query." marine_live.latitude <> 0 AND marine_live.longitude <> 0 ORDER BY marine_live.race_rank";
@@ -212,58 +225,96 @@  discard block
 block discarded – undo
212 225
 		$id = filter_var($id,FILTER_SANITIZE_STRING);
213 226
 		$filter_query = $this->getFilter($filter,true,true);
214 227
 
215
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
216
-		if (!isset($globalMap3DMarinesLimit) || $globalMap3DMarinesLimit == '') $globalMap3DMarinesLimit = '300';
228
+		if (!isset($globalLiveInterval)) {
229
+			$globalLiveInterval = '200';
230
+		}
231
+		if (!isset($globalMap3DMarinesLimit) || $globalMap3DMarinesLimit == '') {
232
+			$globalMap3DMarinesLimit = '300';
233
+		}
217 234
 		if ($globalDBdriver == 'mysql') {
218 235
 			if (isset($globalArchive) && $globalArchive === TRUE) {
219 236
 				$query  = 'SELECT * FROM (SELECT marine_archive.ident, marine_archive.fammarine_id,marine_archive.type_id,marine_archive.type, marine_archive.latitude, marine_archive.longitude, marine_archive.heading, marine_archive.ground_speed, marine_archive.date, marine_archive.format_source, marine_archive.captain_name, marine_archive.race_id, marine_archive.race_rank, marine_archive.race_name 
220 237
 				    FROM marine_archive INNER JOIN (SELECT fammarine_id FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= marine_live.date) l ON l.fammarine_id = marine_archive.fammarine_id ";
221
-				if ($usecoord) $query .= "AND marine_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_archive.longitude BETWEEN ".$minlong." AND ".$maxlong." ";
222
-				if ($id != '') $query .= "OR marine_archive.fammarine_id = :id ";
238
+				if ($usecoord) {
239
+					$query .= "AND marine_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_archive.longitude BETWEEN ".$minlong." AND ".$maxlong." ";
240
+				}
241
+				if ($id != '') {
242
+					$query .= "OR marine_archive.fammarine_id = :id ";
243
+				}
223 244
 				$query .= "UNION
224 245
 				    SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
225 246
 				    FROM marine_live".$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= marine_live.date";
226
-				if ($usecoord) $query .= " AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong;
227
-				if ($id != '') $query .= "OR marine_live.fammarine_id = :id ";
247
+				if ($usecoord) {
248
+					$query .= " AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong;
249
+				}
250
+				if ($id != '') {
251
+					$query .= "OR marine_live.fammarine_id = :id ";
252
+				}
228 253
 				$query .= ") AS marine 
229 254
 				    WHERE latitude <> '0' AND longitude <> '0' 
230 255
 				    ORDER BY fammarine_id, date";
231
-				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
256
+				if ($limit) {
257
+					$query .= " LIMIT ".$globalMap3DMarinesLimit;
258
+				}
232 259
 			} else {
233 260
 				$query  = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
234 261
 				    FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= marine_live.date ";
235
-				if ($usecoord) $query .= "AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong." ";
236
-				if ($id != '') $query .= "OR marine_live.fammarine_id = :id ";
262
+				if ($usecoord) {
263
+					$query .= "AND marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong." ";
264
+				}
265
+				if ($id != '') {
266
+					$query .= "OR marine_live.fammarine_id = :id ";
267
+				}
237 268
 				$query .= "AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
238 269
 				ORDER BY marine_live.fammarine_id, marine_live.date";
239
-				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
270
+				if ($limit) {
271
+					$query .= " LIMIT ".$globalMap3DMarinesLimit;
272
+				}
240 273
 			}
241 274
 		} else {
242 275
 			if (isset($globalArchive) && $globalArchive === TRUE) {
243 276
 				$query  = "SELECT * FROM (SELECT marine_archive.ident, marine_archive.fammarine_id, marine_archive.type_id, marine_archive.type,marine_archive.latitude, marine_archive.longitude, marine_archive.heading, marine_archive.ground_speed, marine_archive.date, marine_archive.format_source, marine_archive.captain_name, marine_archive.race_id, marine_archive.race_rank, marine_archive.race_name 
244 277
 				    FROM marine_archive INNER JOIN (SELECT fammarine_id FROM marine_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= marine_live.date) l ON l.fammarine_id = marine_archive.fammarine_id ";
245
-				if ($usecoord) $query .= "AND (marine_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_archive.longitude BETWEEN ".$minlong." AND ".$maxlong.") ";
246
-				if ($id != '') $query .= "OR marine_archive.fammarine_id = :id ";
278
+				if ($usecoord) {
279
+					$query .= "AND (marine_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_archive.longitude BETWEEN ".$minlong." AND ".$maxlong.") ";
280
+				}
281
+				if ($id != '') {
282
+					$query .= "OR marine_archive.fammarine_id = :id ";
283
+				}
247 284
 				$query .= "UNION
248 285
 				    SELECT marine_live.ident, marine_live.fammarine_id, marine_live.type_id, marine_live.type,marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
249 286
 				    FROM marine_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= marine_live.date";
250
-				if ($usecoord) $query .= " AND (marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong.")";
251
-				if ($id != '') $query .= " OR marine_live.fammarine_id = :id";
287
+				if ($usecoord) {
288
+					$query .= " AND (marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong.")";
289
+				}
290
+				if ($id != '') {
291
+					$query .= " OR marine_live.fammarine_id = :id";
292
+				}
252 293
 				$query .= ") AS marine WHERE latitude <> '0' AND longitude <> '0' ";
253 294
 				$query .= "ORDER BY fammarine_id, date";
254
-				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
295
+				if ($limit) {
296
+					$query .= " LIMIT ".$globalMap3DMarinesLimit;
297
+				}
255 298
 			} else {
256 299
 				$query  = "SELECT marine_live.ident, marine_live.fammarine_id, marine_live.type_id, marine_live.type,marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
257 300
 				    FROM marine_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= marine_live.date ";
258
-				if ($usecoord) $query .= "AND (marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong.") ";
259
-				if ($id != '') $query .= "OR marine_live.fammarine_id = :id ";
301
+				if ($usecoord) {
302
+					$query .= "AND (marine_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND marine_live.longitude BETWEEN ".$minlong." AND ".$maxlong.") ";
303
+				}
304
+				if ($id != '') {
305
+					$query .= "OR marine_live.fammarine_id = :id ";
306
+				}
260 307
 				$query .= "AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
261 308
 				ORDER BY marine_live.fammarine_id, marine_live.date";
262
-				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
309
+				if ($limit) {
310
+					$query .= " LIMIT ".$globalMap3DMarinesLimit;
311
+				}
263 312
 			}
264 313
 		}
265 314
 		$query_values = array();
266
-		if ($id != '') $query_values = array(':id' => $id);
315
+		if ($id != '') {
316
+			$query_values = array(':id' => $id);
317
+		}
267 318
 		try {
268 319
 			$sth = $this->db->prepare($query);
269 320
 			$sth->execute($query_values);
@@ -290,8 +341,12 @@  discard block
 block discarded – undo
290 341
 		$id = filter_var($id,FILTER_SANITIZE_STRING);
291 342
 		$filter_query = $this->getFilter($filter,true,true);
292 343
 
293
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
294
-		if (!isset($globalMap3DMarinesLimit) || $globalMap3DMarinesLimit == '') $globalMap3DMarinesLimit = '300';
344
+		if (!isset($globalLiveInterval)) {
345
+			$globalLiveInterval = '200';
346
+		}
347
+		if (!isset($globalMap3DMarinesLimit) || $globalMap3DMarinesLimit == '') {
348
+			$globalMap3DMarinesLimit = '300';
349
+		}
295 350
 		if ($globalDBdriver == 'mysql') {
296 351
 			if (isset($globalArchive) && $globalArchive === TRUE) {
297 352
 				$query  = 'SELECT * FROM (SELECT marine_archive.ident, marine_archive.fammarine_id,marine_archive.type_id,marine_archive.type, marine_archive.latitude, marine_archive.longitude, marine_archive.heading, marine_archive.ground_speed, marine_archive.date, marine_archive.format_source, marine_archive.captain_name, marine_archive.race_id, marine_archive.race_rank, marine_archive.race_name 
@@ -302,13 +357,17 @@  discard block
 block discarded – undo
302 357
 				$query .= ") AS marine 
303 358
 				    WHERE latitude <> '0' AND longitude <> '0' 
304 359
 				    ORDER BY fammarine_id, date";
305
-				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
360
+				if ($limit) {
361
+					$query .= " LIMIT ".$globalMap3DMarinesLimit;
362
+				}
306 363
 			} else {
307 364
 				$query  = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
308 365
 				    FROM marine_live'.$filter_query.' marine_live.fammarine_id = :id ';
309 366
 				$query .= "AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
310 367
 				ORDER BY marine_live.fammarine_id, marine_live.date";
311
-				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
368
+				if ($limit) {
369
+					$query .= " LIMIT ".$globalMap3DMarinesLimit;
370
+				}
312 371
 			}
313 372
 		} else {
314 373
 			if (isset($globalArchive) && $globalArchive === TRUE) {
@@ -320,13 +379,17 @@  discard block
 block discarded – undo
320 379
 				$query .= ") AS marine 
321 380
 				    WHERE latitude <> '0' AND longitude <> '0' 
322 381
 				    ORDER BY fammarine_id, date";
323
-				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
382
+				if ($limit) {
383
+					$query .= " LIMIT ".$globalMap3DMarinesLimit;
384
+				}
324 385
 			} else {
325 386
 				$query  = "SELECT marine_live.ident, marine_live.fammarine_id, marine_live.type_id, marine_live.type,marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source, marine_live.captain_name, marine_live.race_id, marine_live.race_rank, marine_live.race_name 
326 387
 				    FROM marine_live".$filter_query." marine_live.fammarine_id = :id ";
327 388
 				$query .= "AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
328 389
 				ORDER BY marine_live.fammarine_id, marine_live.date";
329
-				if ($limit) $query .= " LIMIT ".$globalMap3DMarinesLimit;
390
+				if ($limit) {
391
+					$query .= " LIMIT ".$globalMap3DMarinesLimit;
392
+				}
330 393
 			}
331 394
 		}
332 395
 		$query_values = array(':id' => $id);
@@ -352,7 +415,9 @@  discard block
 block discarded – undo
352 415
 		global $globalDBdriver, $globalLiveInterval;
353 416
 		$filter_query = $this->getFilter($filter,true,true);
354 417
 
355
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
418
+		if (!isset($globalLiveInterval)) {
419
+			$globalLiveInterval = '200';
420
+		}
356 421
 		if ($globalDBdriver == 'mysql') {
357 422
 			$query = 'SELECT COUNT(DISTINCT marine_live.fammarine_id) as nb FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
358 423
 		} else {
@@ -381,7 +446,9 @@  discard block
 block discarded – undo
381 446
 	{
382 447
 		global $globalDBdriver, $globalLiveInterval;
383 448
 		$Marine = new Marine($this->db);
384
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
449
+		if (!isset($globalLiveInterval)) {
450
+			$globalLiveInterval = '200';
451
+		}
385 452
 		$filter_query = $this->getFilter($filter);
386 453
 
387 454
 		if (is_array($coord)) {
@@ -389,7 +456,9 @@  discard block
 block discarded – undo
389 456
 			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
390 457
 			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
391 458
 			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
392
-		} else return array();
459
+		} else {
460
+			return array();
461
+		}
393 462
 		if ($globalDBdriver == 'mysql') {
394 463
 			$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND marine_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND marine_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.' GROUP BY marine_live.fammarine_id ORDER BY date DESC'.$filter_query;
395 464
 		} else {
@@ -410,7 +479,9 @@  discard block
 block discarded – undo
410 479
 	{
411 480
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
412 481
 		$Marine = new Marine($this->db);
413
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
482
+		if (!isset($globalLiveInterval)) {
483
+			$globalLiveInterval = '200';
484
+		}
414 485
 		$filter_query = $this->getFilter($filter,true,true);
415 486
 
416 487
 		if (is_array($coord)) {
@@ -418,7 +489,9 @@  discard block
 block discarded – undo
418 489
 			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
419 490
 			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
420 491
 			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
421
-		} else return array();
492
+		} else {
493
+			return array();
494
+		}
422 495
 		/*
423 496
 		if ($globalDBdriver == 'mysql') {
424 497
 			$query  = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
@@ -648,11 +721,15 @@  discard block
 block discarded – undo
648 721
 		//$query  = self::$global_query.' WHERE marine_live.fammarine_id = :id ORDER BY date';
649 722
 		if ($globalDBdriver == 'mysql') {
650 723
 			$query = 'SELECT marine_live.* FROM marine_live WHERE marine_live.fammarine_id = :id';
651
-			if ($liveinterval) $query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
724
+			if ($liveinterval) {
725
+				$query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
726
+			}
652 727
 			$query .= ' ORDER BY date';
653 728
 		} else {
654 729
 			$query = 'SELECT marine_live.* FROM marine_live WHERE marine_live.fammarine_id = :id';
655
-			if ($liveinterval) $query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
730
+			if ($liveinterval) {
731
+				$query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
732
+			}
656 733
 			$query .= ' ORDER BY date';
657 734
 		}
658 735
 
@@ -747,7 +824,9 @@  discard block
 block discarded – undo
747 824
 				$i++;
748 825
 				$j++;
749 826
 				if ($j == 30) {
750
-					if ($globalDebug) echo ".";
827
+					if ($globalDebug) {
828
+						echo ".";
829
+					}
751 830
 				    	try {
752 831
 						
753 832
 						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
@@ -1064,7 +1143,9 @@  discard block
 block discarded – undo
1064 1143
 			{
1065 1144
 				return false;
1066 1145
 			}
1067
-		} else return '';
1146
+		} else {
1147
+			return '';
1148
+		}
1068 1149
 
1069 1150
 		if ($longitude != '')
1070 1151
 		{
@@ -1072,7 +1153,9 @@  discard block
 block discarded – undo
1072 1153
 			{
1073 1154
 				return false;
1074 1155
 			}
1075
-		} else return '';
1156
+		} else {
1157
+			return '';
1158
+		}
1076 1159
 
1077 1160
 
1078 1161
 		if ($heading != '')
@@ -1081,7 +1164,9 @@  discard block
 block discarded – undo
1081 1164
 			{
1082 1165
 				return false;
1083 1166
 			}
1084
-		} else $heading = 0;
1167
+		} else {
1168
+			$heading = 0;
1169
+		}
1085 1170
 
1086 1171
 		if ($groundspeed != '')
1087 1172
 		{
@@ -1089,9 +1174,13 @@  discard block
 block discarded – undo
1089 1174
 			{
1090 1175
 				return false;
1091 1176
 			}
1092
-		} else $groundspeed = 0;
1177
+		} else {
1178
+			$groundspeed = 0;
1179
+		}
1093 1180
 		date_default_timezone_set('UTC');
1094
-		if ($date == '') $date = date("Y-m-d H:i:s", time());
1181
+		if ($date == '') {
1182
+			$date = date("Y-m-d H:i:s", time());
1183
+		}
1095 1184
 
1096 1185
         
1097 1186
 		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
@@ -1118,19 +1207,35 @@  discard block
 block discarded – undo
1118 1207
 		$race_id = filter_var($race_id,FILTER_SANITIZE_STRING);
1119 1208
 		$race_name = filter_var($race_name,FILTER_SANITIZE_STRING);
1120 1209
 		$race_rank = filter_var($race_rank,FILTER_SANITIZE_NUMBER_INT);
1121
-		if ($race_rank == '') $race_rank = NULL;
1210
+		if ($race_rank == '') {
1211
+			$race_rank = NULL;
1212
+		}
1122 1213
 		$race_time = filter_var($race_time,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1123
-		if ($race_time == '') $race_time = NULL;
1124
-		if ($typeid == '') $typeid = NULL;
1125
-		if ($statusid == '') $statusid = NULL;
1126
-		if ($distance == '') $distance = NULL;
1214
+		if ($race_time == '') {
1215
+			$race_time = NULL;
1216
+		}
1217
+		if ($typeid == '') {
1218
+			$typeid = NULL;
1219
+		}
1220
+		if ($statusid == '') {
1221
+			$statusid = NULL;
1222
+		}
1223
+		if ($distance == '') {
1224
+			$distance = NULL;
1225
+		}
1127 1226
 
1128 1227
             	//if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
1129
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
1130
-            	if ($arrival_date == '') $arrival_date = NULL;
1228
+            	if ($heading == '' || $Common->isInteger($heading) === false ) {
1229
+            		$heading = 0;
1230
+            	}
1231
+            	if ($arrival_date == '') {
1232
+            		$arrival_date = NULL;
1233
+            	}
1131 1234
             	$query = '';
1132 1235
 		if ($globalArchive) {
1133
-			if ($globalDebug) echo '-- Delete previous data -- ';
1236
+			if ($globalDebug) {
1237
+				echo '-- Delete previous data -- ';
1238
+			}
1134 1239
 			$query .= 'DELETE FROM marine_live WHERE fammarine_id = :fammarine_id;';
1135 1240
 		}
1136 1241
 		$query .= 'INSERT INTO marine_live (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, over_country, mmsi, type,type_id,status,status_id,imo,arrival_port_name,arrival_port_date,captain_id,captain_name,race_id,race_name,distance,race_rank,race_time) 
@@ -1145,10 +1250,14 @@  discard block
 block discarded – undo
1145 1250
 		}
1146 1251
 		
1147 1252
 		if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) {
1148
-			if ($globalDebug) echo '(Add to Marine archive : ';
1253
+			if ($globalDebug) {
1254
+				echo '(Add to Marine archive : ';
1255
+			}
1149 1256
 			$MarineArchive = new MarineArchive($this->db);
1150 1257
 			$result =  $MarineArchive->addMarineArchiveData($fammarine_id, $ident, $latitude, $longitude, $heading, $groundspeed, $date, $putinarchive, $mmsi,$type,$typeid,$imo, $callsign,$arrival_code,$arrival_date,$status,$statusid,$noarchive,$format_source, $source_name, $over_country,$captain_id,$captain_name,$race_id,$race_name,$distance,$race_rank,$race_time);
1151
-			if ($globalDebug) echo $result.')';
1258
+			if ($globalDebug) {
1259
+				echo $result.')';
1260
+			}
1152 1261
 		}
1153 1262
 		return "success";
1154 1263
 	}
Please login to merge, or discard this patch.
require/class.MarineImport.php 3 patches
Indentation   +266 added lines, -266 removed lines patch added patch discarded remove patch
@@ -16,25 +16,25 @@  discard block
 block discarded – undo
16 16
 require_once(dirname(__FILE__).'/class.Stats.php');
17 17
 require_once(dirname(__FILE__).'/class.Source.php');
18 18
 if (isset($globalServerAPRS) && $globalServerAPRS) {
19
-    require_once(dirname(__FILE__).'/class.APRS.php');
19
+	require_once(dirname(__FILE__).'/class.APRS.php');
20 20
 }
21 21
 
22 22
 class MarineImport {
23
-    private $all_tracked = array();
24
-    private $last_delete_hourly = 0;
25
-    private $last_delete = 0;
26
-    private $stats = array();
27
-    private $tmd = 0;
28
-    private $source_location = array();
29
-    public $db = null;
30
-    public $nb = 0;
23
+	private $all_tracked = array();
24
+	private $last_delete_hourly = 0;
25
+	private $last_delete = 0;
26
+	private $stats = array();
27
+	private $tmd = 0;
28
+	private $source_location = array();
29
+	public $db = null;
30
+	public $nb = 0;
31 31
 
32
-    public function __construct($dbc = null) {
32
+	public function __construct($dbc = null) {
33 33
 	global $globalBeta, $globalServerAPRS, $APRSMarine, $globalNoDB;
34 34
 	if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
35
-	    $Connection = new Connection($dbc);
36
-	    $this->db = $Connection->db();
37
-	    date_default_timezone_set('UTC');
35
+		$Connection = new Connection($dbc);
36
+		$this->db = $Connection->db();
37
+		date_default_timezone_set('UTC');
38 38
 	}
39 39
 	// Get previous source stats
40 40
 	/*
@@ -53,79 +53,79 @@  discard block
 block discarded – undo
53 53
 	}
54 54
 	*/
55 55
 	if (isset($globalServerAPRS) && $globalServerAPRS) {
56
-	    $APRSMarine = new APRSMarine();
57
-	    //$APRSSpotter->connect();
56
+		$APRSMarine = new APRSMarine();
57
+		//$APRSSpotter->connect();
58
+	}
58 59
 	}
59
-    }
60 60
 
61
-    public function checkAll() {
61
+	public function checkAll() {
62 62
 	global $globalDebug, $globalNoDB, $globalVM;
63 63
 	if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
64
-	    if ($globalDebug) echo "Update last seen tracked data...\n";
65
-	    foreach ($this->all_tracked as $key => $flight) {
64
+		if ($globalDebug) echo "Update last seen tracked data...\n";
65
+		foreach ($this->all_tracked as $key => $flight) {
66 66
 		if (isset($this->all_tracked[$key]['id'])) {
67
-		    //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
68
-    		    $Marine = new Marine($this->db);
69
-    		    if (isset($globalVM) && $globalVM) {
67
+			//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
68
+				$Marine = new Marine($this->db);
69
+				if (isset($globalVM) && $globalVM) {
70 70
 			if ($this->all_tracked[$key]['status'] == 'Racing') {
71
-    			    $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
72
-    			} else {
73
-    			    $timerace = (strtotime($this->all_tracked[$key]['race_begin'])+$this->all_tracked[$key]['race_time']);
74
-    			    if ($timerace > time()) $finaldatetime = NULL;
75
-    			    else $finaldatetime = date('Y-m-d H:i:s',$timerace);
76
-    			    $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$finaldatetime,$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
77
-    			}
78
-    		    } else {
71
+					$Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
72
+				} else {
73
+					$timerace = (strtotime($this->all_tracked[$key]['race_begin'])+$this->all_tracked[$key]['race_time']);
74
+					if ($timerace > time()) $finaldatetime = NULL;
75
+					else $finaldatetime = date('Y-m-d H:i:s',$timerace);
76
+					$Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$finaldatetime,$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
77
+				}
78
+				} else {
79 79
 			$Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
80
-		    }
80
+			}
81
+		}
81 82
 		}
82
-	    }
83 83
 	}
84
-    }
84
+	}
85 85
 
86
-    public function del() {
86
+	public function del() {
87 87
 	global $globalDebug, $globalNoDB, $globalNoImport;
88 88
 	// Delete old infos
89 89
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
90 90
 	foreach ($this->all_tracked as $key => $flight) {
91
-    	    if (isset($flight['lastupdate'])) {
92
-        	if ($flight['lastupdate'] < (time()-3000)) {
93
-            	    if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
94
-            		if (isset($this->all_tracked[$key]['id'])) {
95
-            		    if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
96
-			    /*
91
+			if (isset($flight['lastupdate'])) {
92
+			if ($flight['lastupdate'] < (time()-3000)) {
93
+					if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
94
+					if (isset($this->all_tracked[$key]['id'])) {
95
+						if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
96
+				/*
97 97
 			    $MarineLive = new MarineLive();
98 98
             		    $MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']);
99 99
 			    $MarineLive->db = null;
100 100
 			    */
101
-            		    //$real_arrival = $this->arrival($key);
102
-            		    $Marine = new Marine($this->db);
103
-            		    if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
101
+						//$real_arrival = $this->arrival($key);
102
+						$Marine = new Marine($this->db);
103
+						if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
104 104
 				if (isset($globalVM) && $globalVM) {
105
-				    if ($this->all_tracked[$key]['status'] == 'Racing') {
105
+					if ($this->all_tracked[$key]['status'] == 'Racing') {
106 106
 					$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
107
-				    } else {
107
+					} else {
108 108
 					$timerace = strtotime($this->all_tracked[$key]['race_begin'])+$this->all_tracked[$key]['race_time'];
109
-	        			if ($timerace > time()) $finaldatetime = NULL;
109
+						if ($timerace > time()) $finaldatetime = NULL;
110 110
 					else $finaldatetime = date('Y-m-d H:i:s',$timerace);
111 111
 					$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$finaldatetime,$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
112
-				    }
112
+					}
113 113
 				} else {
114 114
 					$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
115 115
 				}
116 116
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
117
-			    }
118
-			    // Put in archive
117
+				}
118
+				// Put in archive
119 119
 //				$Marine->db = null;
120 120
 			}
121
-            	    }
122
-            	    unset($this->all_tracked[$key]);
123
-    	        }
124
-	    }
125
-        }
126
-    }
121
+					}
122
+					unset($this->all_tracked[$key]);
123
+				}
124
+		}
125
+		}
126
+	}
127 127
 
128
-    public function add($line) {
128
+	public function add($line) {
129 129
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine, $globalLiveInterval, $globalVM, $globalOnlyID;
130 130
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
131 131
 	date_default_timezone_set('UTC');
@@ -134,106 +134,106 @@  discard block
 block discarded – undo
134 134
 	
135 135
 	// SBS format is CSV format
136 136
 	if(is_array($line) && (isset($line['mmsi']) || isset($line['id']))) {
137
-	    //print_r($line);
138
-  	    if (isset($line['mmsi']) || isset($line['id'])) {
137
+		//print_r($line);
138
+  		if (isset($line['mmsi']) || isset($line['id'])) {
139 139
 
140 140
 		
141 141
 		// Increment message number
142 142
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
143
-		    $current_date = date('Y-m-d');
144
-		    if (isset($line['source_name'])) $source = $line['source_name'];
145
-		    else $source = '';
146
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
147
-		    if (!isset($this->stats[$current_date][$source]['msg'])) {
148
-		    	$this->stats[$current_date][$source]['msg']['date'] = time();
149
-		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
150
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
143
+			$current_date = date('Y-m-d');
144
+			if (isset($line['source_name'])) $source = $line['source_name'];
145
+			else $source = '';
146
+			if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
147
+			if (!isset($this->stats[$current_date][$source]['msg'])) {
148
+				$this->stats[$current_date][$source]['msg']['date'] = time();
149
+				$this->stats[$current_date][$source]['msg']['nb'] = 1;
150
+			} else $this->stats[$current_date][$source]['msg']['nb'] += 1;
151 151
 		}
152 152
 		
153 153
 		
154 154
 		$Common = new Common();
155 155
 		$AIS = new AIS();
156
-	        if (!isset($line['id'])) $id = trim($line['mmsi']);
157
-	        else $id = trim($line['id']);
156
+			if (!isset($line['id'])) $id = trim($line['mmsi']);
157
+			else $id = trim($line['id']);
158 158
 		
159 159
 		if (!isset($this->all_tracked[$id])) {
160
-		    $this->all_tracked[$id] = array();
161
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
162
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => '','captain_id' => '','captain_name' => '','race_id' => '','race_name' => '','distance' => NULL,'race_rank' => NULL,'race_time' => NULL,'race_begin' => ''));
163
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
164
-		    if (!isset($line['id'])) {
160
+			$this->all_tracked[$id] = array();
161
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
162
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => '','captain_id' => '','captain_name' => '','race_id' => '','race_name' => '','distance' => NULL,'race_rank' => NULL,'race_time' => NULL,'race_begin' => ''));
163
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
164
+			if (!isset($line['id'])) {
165 165
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
166 166
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
167
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
168
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
167
+			 } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
168
+			if ($globalAllTracked !== FALSE) $dataFound = true;
169 169
 		}
170 170
 		
171 171
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
172
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
173
-		    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
172
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
173
+			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
174 174
 			$Marine = new Marine($this->db);
175 175
 			$identity = $Marine->getIdentity($line['mmsi']);
176 176
 			if (!empty($identity)) {
177
-			    $this->all_tracked[$id]['ident'] = $identity['ship_name'];
178
-			    $this->all_tracked[$id]['type'] = $identity['type'];
179
-			    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($identity['type'])));
177
+				$this->all_tracked[$id]['ident'] = $identity['ship_name'];
178
+				$this->all_tracked[$id]['type'] = $identity['type'];
179
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($identity['type'])));
180 180
 			}
181 181
 			//print_r($identity);
182 182
 			unset($Marine);
183 183
 			//$dataFound = true;
184
-		    }
184
+			}
185 185
 		}
186 186
 		if (isset($line['type_id'])) {
187
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
188
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $line['type_id']));
187
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
188
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $line['type_id']));
189 189
 		}
190 190
 		if (isset($line['type']) && $line['type'] != '' && $this->all_tracked[$id]['type'] == '') {
191
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
192
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($line['type'])));
191
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
192
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($line['type'])));
193 193
 		} elseif (isset($line['type']) && $line['type'] != '' && $this->all_tracked[$id]['type'] != '') {
194
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
194
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
195 195
 		}
196 196
 		if (isset($line['status']) && $line['status'] != '') {
197
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
197
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
198 198
 		}
199 199
 		if (isset($line['status_id']) && (!isset($this->all_tracked[$id]['status_id']) || $this->all_tracked[$id]['status_id'] != $line['status_id'])) {
200
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id']));
201
-		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
200
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id']));
201
+			if ($this->all_tracked[$id]['addedMarine'] == 1) {
202 202
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
203
-			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
203
+				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
204 204
 				$Marine = new Marine($this->db);
205 205
 				$Marine->updateStatusMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['status']);
206 206
 				unset($Marine);
207
-			    }
207
+				}
208
+			}
208 209
 			}
209
-		    }
210 210
 		}
211 211
 
212 212
 
213 213
 		if (isset($line['mmsi_type']) && $line['mmsi_type'] != '') {
214
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type']));
214
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type']));
215 215
 		}
216 216
 		if (isset($line['imo']) && $line['imo'] != '') {
217
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
217
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
218 218
 		}
219 219
 		if (isset($line['callsign']) && $line['callsign'] != '') {
220
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
220
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
221 221
 		}
222 222
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
223
-		    if (!isset($this->all_tracked[$id]['arrival_code'])) {
223
+			if (!isset($this->all_tracked[$id]['arrival_code'])) {
224 224
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
225 225
 			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
226 226
 			if ($this->all_tracked[$id]['addedMarine'] != 0) {
227
-			    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
227
+				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
228 228
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
229
-				    $Marine = new Marine($this->db);
230
-				    $fromsource = NULL;
231
-				    $Marine->updateArrivalPortNameMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['arrival_code'],$fromsource);
232
-				    $Marine->db = null;
229
+					$Marine = new Marine($this->db);
230
+					$fromsource = NULL;
231
+					$Marine->updateArrivalPortNameMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['arrival_code'],$fromsource);
232
+					$Marine->db = null;
233
+				}
233 234
 				}
234
-			    }
235 235
 			}
236
-		    } elseif ($this->all_tracked[$id]['arrival_code'] != $line['arrival_code']) {
236
+			} elseif ($this->all_tracked[$id]['arrival_code'] != $line['arrival_code']) {
237 237
 			$this->all_tracked[$id]['arrival_code'] = $line['arrival_code'];
238 238
 			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
239 239
 			if (!isset($line['id'])) {
@@ -241,50 +241,50 @@  discard block
 block discarded – undo
241 241
 				$this->all_tracked[$id]['forcenew'] = 1;
242 242
 				$this->all_tracked[$id]['addedMarine'] = 0;
243 243
 			}
244
-		    }
244
+			}
245 245
 		}
246 246
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
247
-		    if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
247
+			if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
248 248
 		}
249 249
 		if (isset($line['captain_id']) && $line['captain_id'] != '') {
250
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('captain_id' => $line['captain_id']));
250
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('captain_id' => $line['captain_id']));
251 251
 		}
252 252
 		if (isset($line['captain_name']) && $line['captain_name'] != '') {
253
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('captain_name' => $line['captain_name']));
253
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('captain_name' => $line['captain_name']));
254 254
 		}
255 255
 		if (isset($line['race_id']) && $line['race_id'] != '') {
256
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_id' => $line['race_id']));
256
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_id' => $line['race_id']));
257 257
 		}
258 258
 		if (isset($line['race_name']) && $line['race_name'] != '') {
259
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_name' => $line['race_name']));
259
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_name' => $line['race_name']));
260 260
 		}
261 261
 		if (isset($line['race_rank']) && $line['race_rank'] != '') {
262
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_rank' => $line['race_rank']));
262
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_rank' => $line['race_rank']));
263 263
 		}
264 264
 		if (isset($line['race_time']) && $line['race_time'] != '') {
265
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_time' => $line['race_time']));
265
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_time' => $line['race_time']));
266 266
 		}
267 267
 		if (isset($line['race_begin']) && $line['race_begin'] != '') {
268
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_begin' => $line['race_begin']));
268
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_begin' => $line['race_begin']));
269 269
 		}
270 270
 		if (isset($line['distance']) && $line['distance'] != '') {
271
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('distance' => $line['distance']));
271
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('distance' => $line['distance']));
272 272
 		}
273 273
 
274 274
 		//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'])) {
275 275
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
276
-		    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
276
+			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
277 277
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
278
-			    $timeelapsed = microtime(true);
279
-			    $Marine = new Marine($this->db);
280
-			    $Marine->addIdentity($this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['type']);
281
-			    $Marine->db = null;
278
+				$timeelapsed = microtime(true);
279
+				$Marine = new Marine($this->db);
280
+				$Marine->addIdentity($this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['type']);
281
+				$Marine->db = null;
282
+			}
282 283
 			}
283
-		    }
284
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
285
-		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
284
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
285
+			if ($this->all_tracked[$id]['addedMarine'] == 1) {
286 286
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
287
-			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
287
+				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
288 288
 				$timeelapsed = microtime(true);
289 289
 				$Marine = new Marine($this->db);
290 290
 				$fromsource = NULL;
@@ -292,20 +292,20 @@  discard block
 block discarded – undo
292 292
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
293 293
 				$Marine->db = null;
294 294
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
295
-			    }
295
+				}
296
+			}
296 297
 			}
297
-		    }
298
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
298
+			if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
299 299
 		}
300 300
 
301 301
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) {
302
-		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
302
+			if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
303 303
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
304
-		    } else {
304
+			} else {
305 305
 				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
306 306
 				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]['hex']." - format : ".$line['format_source']."\n";
307 307
 				return '';
308
-		    }
308
+			}
309 309
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) {
310 310
 			if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
311 311
 			return '';
@@ -322,33 +322,33 @@  discard block
 block discarded – undo
322 322
 
323 323
 
324 324
 		if (isset($line['speed'])) {
325
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'],2)));
326
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
325
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'],2)));
326
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
327 327
 		} 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'])) {
328
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
329
-		    if ($distance > 1000 && $distance < 10000) {
328
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
329
+			if ($distance > 1000 && $distance < 10000) {
330 330
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
331 331
 			$speed = $speed*3.6;
332 332
 			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed,2)));
333 333
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['id']." : ".$speed." - distance : ".$distance."\n";
334
-		    }
334
+			}
335 335
 		}
336 336
 
337
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
338
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
339
-	    	    else unset($timediff);
340
-	    	    if ($this->tmd > 5 ||
341
-	    		!isset($timediff) ||
342
-	    		$timediff > $globalLiveInterval ||
343
-	    		(
344
-	    		    $timediff > 30 && 
345
-	    		    isset($this->all_tracked[$id]['latitude']) &&
346
-	    		    isset($this->all_tracked[$id]['longitude']) &&
347
-	    		    $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m'))
348
-	    		)
349
-	    		) {
337
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
338
+				if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
339
+				else unset($timediff);
340
+				if ($this->tmd > 5 ||
341
+				!isset($timediff) ||
342
+				$timediff > $globalLiveInterval ||
343
+				(
344
+					$timediff > 30 && 
345
+					isset($this->all_tracked[$id]['latitude']) &&
346
+					isset($this->all_tracked[$id]['longitude']) &&
347
+					$Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m'))
348
+				)
349
+				) {
350 350
 			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'])) {
351
-			    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'])) {
351
+				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'])) {
352 352
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
353 353
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
354 354
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -356,217 +356,217 @@  discard block
 block discarded – undo
356 356
 				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
357 357
 				$timeelapsed = microtime(true);
358 358
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
359
-				    $Marine = new Marine($this->db);
360
-				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
361
-				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
362
-				    $Marine->db = null;
363
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
359
+					$Marine = new Marine($this->db);
360
+					$all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
361
+					if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
362
+					$Marine->db = null;
363
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
364 364
 				}
365 365
 				$this->tmd = 0;
366 366
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
367
-			    }
367
+				}
368 368
 			}
369 369
 
370 370
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
371 371
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
372 372
 				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') {
373
-				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
374
-				    $dataFound = true;
375
-				    $this->all_tracked[$id]['time_last_coord'] = time();
373
+					$this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
374
+					$dataFound = true;
375
+					$this->all_tracked[$id]['time_last_coord'] = time();
376 376
 				}
377 377
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
378 378
 			}
379 379
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
380
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
380
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
381 381
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
382 382
 				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') {
383
-				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
384
-				    $dataFound = true;
385
-				    $this->all_tracked[$id]['time_last_coord'] = time();
383
+					$this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
384
+					$dataFound = true;
385
+					$this->all_tracked[$id]['time_last_coord'] = time();
386 386
 				}
387 387
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
388 388
 			}
389 389
 
390
-		    } else if ($globalDebug && $timediff > 20) {
390
+			} else if ($globalDebug && $timediff > 20) {
391 391
 			$this->tmd = $this->tmd + 1;
392 392
 			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
393 393
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
394 394
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
395 395
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
396
-		    }
396
+			}
397 397
 		}
398 398
 		if (isset($line['last_update']) && $line['last_update'] != '') {
399
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
400
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
399
+			if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
400
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
401 401
 		}
402 402
 		if (isset($line['format_source']) && $line['format_source'] != '') {
403
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
403
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
404 404
 		}
405 405
 		if (isset($line['source_name']) && $line['source_name'] != '') {
406
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
406
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
407 407
 		}
408 408
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
409
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
409
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
410 410
 		}
411 411
 		
412 412
 		if (isset($line['heading']) && $line['heading'] != '') {
413
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
414
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
415
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
416
-		    //$dataFound = true;
413
+			if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
414
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
415
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
416
+			//$dataFound = true;
417 417
   		} 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']) {
418
-  		    $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']);
419
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
420
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
421
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
418
+  			$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']);
419
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
420
+			if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
421
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
422 422
   		}
423 423
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
424 424
 
425 425
 
426 426
 
427 427
 		if ($dataFound === true && (isset($this->all_tracked[$id]['mmsi']) || isset($this->all_tracked[$id]['id']))) {
428
-		    $this->all_tracked[$id]['lastupdate'] = time();
429
-		    if ($this->all_tracked[$id]['addedMarine'] == 0 || (isset($globalVM) && $globalVM)) {
430
-		        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'])) && (!isset($globalOnlyID) || in_array($id,$globalOnlyID))) {
431
-			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
428
+			$this->all_tracked[$id]['lastupdate'] = time();
429
+			if ($this->all_tracked[$id]['addedMarine'] == 0 || (isset($globalVM) && $globalVM)) {
430
+				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'])) && (!isset($globalOnlyID) || in_array($id,$globalOnlyID))) {
431
+				if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
432 432
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
433
-				    if ($globalDebug) echo "Check if vessel is already in DB...";
434
-				    $timeelapsed = microtime(true);
435
-				    $MarineLive = new MarineLive($this->db);
436
-				    if (isset($line['id']) && isset($globalVM) && $globalVM) {
433
+					if ($globalDebug) echo "Check if vessel is already in DB...";
434
+					$timeelapsed = microtime(true);
435
+					$MarineLive = new MarineLive($this->db);
436
+					if (isset($line['id']) && isset($globalVM) && $globalVM) {
437 437
 					$Marine = new Marine($this->db);
438 438
 					$recent_ident = $Marine->checkId($line['id']);
439 439
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkId : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
440 440
 					$Marine->db=null;
441
-				    } elseif (isset($line['id'])) {
441
+					} elseif (isset($line['id'])) {
442 442
 					$recent_ident = $MarineLive->checkIdRecent($line['id']);
443 443
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
444
-				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
444
+					} elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
445 445
 					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
446 446
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
447
-				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
447
+					} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
448 448
 					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
449 449
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
450
-				    } else $recent_ident = '';
451
-				    $MarineLive->db=null;
452
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
453
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
450
+					} else $recent_ident = '';
451
+					$MarineLive->db=null;
452
+					if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
453
+					elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
454 454
 				} else $recent_ident = '';
455
-			    } else {
455
+				} else {
456 456
 				$recent_ident = '';
457 457
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
458
-			    }
459
-			    //if there was no vessel with the same callsign within the last hour and go post it into the archive
460
-			    if($recent_ident == "" && (($this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') || (isset($globalVM) && $globalVM)))
461
-			    {
458
+				}
459
+				//if there was no vessel with the same callsign within the last hour and go post it into the archive
460
+				if($recent_ident == "" && (($this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') || (isset($globalVM) && $globalVM)))
461
+				{
462 462
 				if ($globalDebug) {
463 463
 					if ($this->all_tracked[$id]['mmsi'] != '') echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
464 464
 					else echo "\o/ Add ".$this->all_tracked[$id]['ident']." in archive DB : ";
465 465
 				}
466 466
 				//adds the spotter data for the archive
467
-				    $highlight = '';
468
-				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
469
-				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
467
+					$highlight = '';
468
+					if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
469
+					if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
470 470
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
471
-					    $timeelapsed = microtime(true);
472
-					    $Marine = new Marine($this->db);
473
-					    if (isset($globalVM) && $globalVM && ($this->all_tracked[$id]['race_begin'] != '' || $this->all_tracked[$id]['format_source'] == 'sailaway')) {
471
+						$timeelapsed = microtime(true);
472
+						$Marine = new Marine($this->db);
473
+						if (isset($globalVM) && $globalVM && ($this->all_tracked[$id]['race_begin'] != '' || $this->all_tracked[$id]['format_source'] == 'sailaway')) {
474 474
 						$result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['race_begin'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time']);
475
-					    } else {
475
+						} else {
476 476
 						$result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time']);
477
-					    }
478
-					    $Marine->db = null;
479
-					    if ($globalDebug && isset($result)) echo $result."\n";
480
-					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
477
+						}
478
+						$Marine->db = null;
479
+						if ($globalDebug && isset($result)) echo $result."\n";
480
+						if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
481 481
 					}
482
-				    }
483
-				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
482
+					}
483
+					if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
484 484
 					// Add source stat in DB
485 485
 					$Stats = new Stats($this->db);
486 486
 					if (!empty($this->stats)) {
487
-					    if ($globalDebug) echo 'Add source stats : ';
488
-				    	    foreach($this->stats as $date => $data) {
487
+						if ($globalDebug) echo 'Add source stats : ';
488
+							foreach($this->stats as $date => $data) {
489 489
 						foreach($data as $source => $sourced) {
490
-					    	    //print_r($sourced);
491
-				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
492
-				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
493
-				    		    if (isset($sourced['msg'])) {
494
-				    			if (time() - $sourced['msg']['date'] > 10) {
495
-				    		    	    $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
496
-				    		    	    echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date);
497
-			    			    	    unset($this->stats[$date][$source]['msg']);
498
-			    				}
499
-			    			    }
500
-			    			}
501
-			    			if ($date != date('Y-m-d')) {
502
-			    			    unset($this->stats[$date]);
503
-			    			}
504
-				    	    }
505
-				    	    if ($globalDebug) echo 'Done'."\n";
490
+								//print_r($sourced);
491
+									if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
492
+									if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
493
+								if (isset($sourced['msg'])) {
494
+								if (time() - $sourced['msg']['date'] > 10) {
495
+										$nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
496
+										echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date);
497
+										unset($this->stats[$date][$source]['msg']);
498
+								}
499
+								}
500
+							}
501
+							if ($date != date('Y-m-d')) {
502
+								unset($this->stats[$date]);
503
+							}
504
+							}
505
+							if ($globalDebug) echo 'Done'."\n";
506 506
 					}
507 507
 					$Stats->db = null;
508
-				    }
508
+					}
509 509
 				    
510
-				    $this->del();
510
+					$this->del();
511 511
 				//$ignoreImport = false;
512 512
 				$this->all_tracked[$id]['addedMarine'] = 1;
513 513
 				//print_r($this->all_tracked[$id]);
514 514
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
515
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 12 hours...";
516
-				    //MarineLive->deleteLiveMarineDataNotUpdated();
517
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
515
+					if ($globalDebug) echo "---- Deleting Live Marine data older than 12 hours...";
516
+					//MarineLive->deleteLiveMarineDataNotUpdated();
517
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
518 518
 					$MarineLive = new MarineLive($this->db);
519 519
 					$MarineLive->deleteLiveMarineData();
520 520
 					$MarineLive->db=null;
521 521
 					if ($globalDebug) echo " Done\n";
522
-				    }
523
-				    $this->last_delete = time();
522
+					}
523
+					$this->last_delete = time();
524 524
 				}
525
-			    } elseif ($recent_ident != '') {
525
+				} elseif ($recent_ident != '') {
526 526
 				$this->all_tracked[$id]['id'] = $recent_ident;
527 527
 				$this->all_tracked[$id]['addedMarine'] = 1;
528 528
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
529
-				    if ((isset($globalDaemon) && !$globalDaemon) || (isset($globalVM) && $globalVM)) {
529
+					if ((isset($globalDaemon) && !$globalDaemon) || (isset($globalVM) && $globalVM)) {
530 530
 					$Marine = new Marine($this->db);
531 531
 					if (isset($globalVM) && $globalVM) {
532
-					    if ($this->all_tracked[$id]['status'] == 'Racing') {
532
+						if ($this->all_tracked[$id]['status'] == 'Racing') {
533 533
 						$Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['race_begin']);
534
-					    } else {
534
+						} else {
535 535
 						//$finaldatetime = date('Y-m-d H:i:s',strtotime($this->all_tracked[$id]['race_begin'])+$this->all_tracked[$id]['race_time']);
536 536
 						$timerace = (strtotime($this->all_tracked[$id]['race_begin'])+$this->all_tracked[$id]['race_time']);
537 537
 						if ($timerace > time()) $finaldatetime = NULL;
538 538
 						else $finaldatetime = date('Y-m-d H:i:s',$timerace);
539 539
 
540 540
 						$Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$finaldatetime,$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['race_begin']);
541
-					    }
541
+						}
542 542
 					} else {
543
-					    $Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['race_begin']);
543
+						$Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['race_begin']);
544 544
 					}
545 545
 					$Marine->db = null;
546
-				    }
546
+					}
547 547
 				}
548 548
 				
549
-			    }
549
+				}
550 550
 			}
551
-		    }
552
-		    //adds the spotter LIVE data
553
-		    if ($globalDebug) {
551
+			}
552
+			//adds the spotter LIVE data
553
+			if ($globalDebug) {
554 554
 			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'].' - Heading : '.$this->all_tracked[$id]['heading'].' - Speed : '.$this->all_tracked[$id]['speed']."\n";
555
-		    }
556
-		    $ignoreImport = false;
557
-		    if ((isset($globalVM) && $globalVM) && $this->all_tracked[$id]['status'] == 'sailawayfull' && $this->all_tracked[$id]['status'] != 'Racing') $ignoreImport = true;
558
-		    if (!$ignoreImport) {
555
+			}
556
+			$ignoreImport = false;
557
+			if ((isset($globalVM) && $globalVM) && $this->all_tracked[$id]['status'] == 'sailawayfull' && $this->all_tracked[$id]['status'] != 'Racing') $ignoreImport = true;
558
+			if (!$ignoreImport) {
559 559
 			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'])) && (!isset($globalOnlyID) || in_array($id,$globalOnlyID))) {
560 560
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
561 561
 				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
562
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
562
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
563 563
 					$timeelapsed = microtime(true);
564 564
 					$MarineLive = new MarineLive($this->db);
565 565
 					$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time']);
566 566
 					$MarineLive->db = null;
567 567
 					if ($globalDebug) echo $result."\n";
568 568
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
569
-				    }
569
+					}
570 570
 				}
571 571
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) {
572 572
 					$APRSMarine->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
 					if ($stats_heading == 16) $stats_heading = 0;
602 602
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
603 603
 						for ($i=0;$i<=15;$i++) {
604
-						    $this->stats[$current_date][$source]['polar'][$i] = 0;
604
+							$this->stats[$current_date][$source]['polar'][$i] = 0;
605 605
 						}
606 606
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
607 607
 					} else {
@@ -614,11 +614,11 @@  discard block
 block discarded – undo
614 614
 					//var_dump($this->stats);
615 615
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
616 616
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
617
-						    end($this->stats[$current_date][$source]['hist']);
618
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
617
+							end($this->stats[$current_date][$source]['hist']);
618
+							$mini = key($this->stats[$current_date][$source]['hist'])+10;
619 619
 						} else $mini = 0;
620 620
 						for ($i=$mini;$i<=$distance;$i+=10) {
621
-						    $this->stats[$current_date][$source]['hist'][$i] = 0;
621
+							$this->stats[$current_date][$source]['hist'][$i] = 0;
622 622
 						}
623 623
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
624 624
 					} else {
@@ -634,30 +634,30 @@  discard block
 block discarded – undo
634 634
 			
635 635
 			
636 636
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
637
-			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
637
+				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
638 638
 				if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
639 639
 				$MarineLive = new MarineLive($this->db);
640 640
 				$MarineLive->deleteLiveMarineDataNotUpdated();
641 641
 				$MarineLive->db = null;
642 642
 				//MarineLive->deleteLiveMarineData();
643 643
 				if ($globalDebug) echo " Done\n";
644
-			    }
645
-			    $this->last_delete_hourly = time();
644
+				}
645
+				$this->last_delete_hourly = time();
646 646
 			}
647 647
 			
648
-		    }
649
-		    //$ignoreImport = false;
648
+			}
649
+			//$ignoreImport = false;
650 650
 		}
651 651
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
652 652
 		if ($send) return $this->all_tracked[$id];
653
-	    }
653
+		}
654
+	}
654 655
 	}
655
-    }
656 656
     
657
-    public function race_add($data) {
658
-        $Marine = new Marine();
659
-        $Marine->addRace($data['id'],$data['name'],$data['creator'],$data['desc'],$data['startdate'],$data['markers']);
660
-        $Marine->db = null;
661
-    }
657
+	public function race_add($data) {
658
+		$Marine = new Marine();
659
+		$Marine->addRace($data['id'],$data['name'],$data['creator'],$data['desc'],$data['startdate'],$data['markers']);
660
+		$Marine->db = null;
661
+	}
662 662
 }
663 663
 ?>
Please login to merge, or discard this patch.
Spacing   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -68,15 +68,15 @@  discard block
 block discarded – undo
68 68
     		    $Marine = new Marine($this->db);
69 69
     		    if (isset($globalVM) && $globalVM) {
70 70
 			if ($this->all_tracked[$key]['status'] == 'Racing') {
71
-    			    $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
71
+    			    $Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed'], $this->all_tracked[$key]['datetime'], $this->all_tracked[$key]['distance'], $this->all_tracked[$key]['race_rank'], $this->all_tracked[$key]['race_time'], $this->all_tracked[$key]['status'], $this->all_tracked[$key]['race_begin']);
72 72
     			} else {
73
-    			    $timerace = (strtotime($this->all_tracked[$key]['race_begin'])+$this->all_tracked[$key]['race_time']);
73
+    			    $timerace = (strtotime($this->all_tracked[$key]['race_begin']) + $this->all_tracked[$key]['race_time']);
74 74
     			    if ($timerace > time()) $finaldatetime = NULL;
75
-    			    else $finaldatetime = date('Y-m-d H:i:s',$timerace);
76
-    			    $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$finaldatetime,$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
75
+    			    else $finaldatetime = date('Y-m-d H:i:s', $timerace);
76
+    			    $Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed'], $finaldatetime, $this->all_tracked[$key]['distance'], $this->all_tracked[$key]['race_rank'], $this->all_tracked[$key]['race_time'], $this->all_tracked[$key]['status'], $this->all_tracked[$key]['race_begin']);
77 77
     			}
78 78
     		    } else {
79
-			$Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
79
+			$Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed'], $this->all_tracked[$key]['datetime'], $this->all_tracked[$key]['distance'], $this->all_tracked[$key]['race_rank'], $this->all_tracked[$key]['race_time'], $this->all_tracked[$key]['status'], $this->all_tracked[$key]['race_begin']);
80 80
 		    }
81 81
 		}
82 82
 	    }
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
90 90
 	foreach ($this->all_tracked as $key => $flight) {
91 91
     	    if (isset($flight['lastupdate'])) {
92
-        	if ($flight['lastupdate'] < (time()-3000)) {
92
+        	if ($flight['lastupdate'] < (time() - 3000)) {
93 93
             	    if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
94 94
             		if (isset($this->all_tracked[$key]['id'])) {
95 95
             		    if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
@@ -103,15 +103,15 @@  discard block
 block discarded – undo
103 103
             		    if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
104 104
 				if (isset($globalVM) && $globalVM) {
105 105
 				    if ($this->all_tracked[$key]['status'] == 'Racing') {
106
-					$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
106
+					$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed'], $this->all_tracked[$key]['datetime'], $this->all_tracked[$key]['distance'], $this->all_tracked[$key]['race_rank'], $this->all_tracked[$key]['race_time'], $this->all_tracked[$key]['status'], $this->all_tracked[$key]['race_begin']);
107 107
 				    } else {
108
-					$timerace = strtotime($this->all_tracked[$key]['race_begin'])+$this->all_tracked[$key]['race_time'];
108
+					$timerace = strtotime($this->all_tracked[$key]['race_begin']) + $this->all_tracked[$key]['race_time'];
109 109
 	        			if ($timerace > time()) $finaldatetime = NULL;
110
-					else $finaldatetime = date('Y-m-d H:i:s',$timerace);
111
-					$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$finaldatetime,$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
110
+					else $finaldatetime = date('Y-m-d H:i:s', $timerace);
111
+					$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed'], $finaldatetime, $this->all_tracked[$key]['distance'], $this->all_tracked[$key]['race_rank'], $this->all_tracked[$key]['race_time'], $this->all_tracked[$key]['status'], $this->all_tracked[$key]['race_begin']);
112 112
 				    }
113 113
 				} else {
114
-					$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
114
+					$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed'], $this->all_tracked[$key]['datetime'], $this->all_tracked[$key]['distance'], $this->all_tracked[$key]['race_rank'], $this->all_tracked[$key]['race_time'], $this->all_tracked[$key]['status'], $this->all_tracked[$key]['race_begin']);
115 115
 				}
116 116
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
117 117
 			    }
@@ -126,14 +126,14 @@  discard block
 block discarded – undo
126 126
     }
127 127
 
128 128
     public function add($line) {
129
-	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine, $globalLiveInterval, $globalVM, $globalOnlyID;
129
+	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS, $APRSMarine, $globalLiveInterval, $globalVM, $globalOnlyID;
130 130
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
131 131
 	date_default_timezone_set('UTC');
132 132
 	$dataFound = false;
133 133
 	$send = false;
134 134
 	
135 135
 	// SBS format is CSV format
136
-	if(is_array($line) && (isset($line['mmsi']) || isset($line['id']))) {
136
+	if (is_array($line) && (isset($line['mmsi']) || isset($line['id']))) {
137 137
 	    //print_r($line);
138 138
   	    if (isset($line['mmsi']) || isset($line['id'])) {
139 139
 
@@ -158,25 +158,25 @@  discard block
 block discarded – undo
158 158
 		
159 159
 		if (!isset($this->all_tracked[$id])) {
160 160
 		    $this->all_tracked[$id] = array();
161
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
162
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => '','captain_id' => '','captain_name' => '','race_id' => '','race_name' => '','distance' => NULL,'race_rank' => NULL,'race_time' => NULL,'race_begin' => ''));
163
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
161
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('addedMarine' => 0));
162
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => '', 'latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '', 'source_name' => '', 'comment'=> '', 'type' => '', 'typeid' => '', 'noarchive' => false, 'putinarchive' => true, 'over_country' => '', 'mmsi' => '', 'status' => '', 'status_id' => '', 'imo' => '', 'callsign' => '', 'arrival_code' => '', 'arrival_date' => '', 'mmsi_type' => '', 'captain_id' => '', 'captain_name' => '', 'race_id' => '', 'race_name' => '', 'distance' => NULL, 'race_rank' => NULL, 'race_time' => NULL, 'race_begin' => ''));
163
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('lastupdate' => time()));
164 164
 		    if (!isset($line['id'])) {
165 165
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
166
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
167
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
166
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $id.'-'.date('YmdHi')));
167
+		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $line['id']));
168 168
 		    if ($globalAllTracked !== FALSE) $dataFound = true;
169 169
 		}
170 170
 		
171 171
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
172
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
172
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('mmsi' => $line['mmsi']));
173 173
 		    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
174 174
 			$Marine = new Marine($this->db);
175 175
 			$identity = $Marine->getIdentity($line['mmsi']);
176 176
 			if (!empty($identity)) {
177 177
 			    $this->all_tracked[$id]['ident'] = $identity['ship_name'];
178 178
 			    $this->all_tracked[$id]['type'] = $identity['type'];
179
-			    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($identity['type'])));
179
+			    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('typeid' => $AIS->getShipTypeID($identity['type'])));
180 180
 			}
181 181
 			//print_r($identity);
182 182
 			unset($Marine);
@@ -184,25 +184,25 @@  discard block
 block discarded – undo
184 184
 		    }
185 185
 		}
186 186
 		if (isset($line['type_id'])) {
187
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id'])));
188
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $line['type_id']));
187
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $AIS->getShipType($line['type_id'])));
188
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('typeid' => $line['type_id']));
189 189
 		}
190 190
 		if (isset($line['type']) && $line['type'] != '' && $this->all_tracked[$id]['type'] == '') {
191
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
192
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($line['type'])));
191
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $line['type']));
192
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('typeid' => $AIS->getShipTypeID($line['type'])));
193 193
 		} elseif (isset($line['type']) && $line['type'] != '' && $this->all_tracked[$id]['type'] != '') {
194
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
194
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $line['type']));
195 195
 		}
196 196
 		if (isset($line['status']) && $line['status'] != '') {
197
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
197
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status' => $line['status']));
198 198
 		}
199 199
 		if (isset($line['status_id']) && (!isset($this->all_tracked[$id]['status_id']) || $this->all_tracked[$id]['status_id'] != $line['status_id'])) {
200
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id']));
200
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status_id' => $line['status_id']));
201 201
 		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
202 202
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
203 203
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
204 204
 				$Marine = new Marine($this->db);
205
-				$Marine->updateStatusMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['status']);
205
+				$Marine->updateStatusMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['status']);
206 206
 				unset($Marine);
207 207
 			    }
208 208
 			}
@@ -211,24 +211,24 @@  discard block
 block discarded – undo
211 211
 
212 212
 
213 213
 		if (isset($line['mmsi_type']) && $line['mmsi_type'] != '') {
214
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type']));
214
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('mmsi_type' => $line['mmsi_type']));
215 215
 		}
216 216
 		if (isset($line['imo']) && $line['imo'] != '') {
217
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
217
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('imo' => $line['imo']));
218 218
 		}
219 219
 		if (isset($line['callsign']) && $line['callsign'] != '') {
220
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
220
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('callsign' => $line['callsign']));
221 221
 		}
222 222
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
223 223
 		    if (!isset($this->all_tracked[$id]['arrival_code'])) {
224
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
224
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_code' => $line['arrival_code']));
225 225
 			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
226 226
 			if ($this->all_tracked[$id]['addedMarine'] != 0) {
227 227
 			    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
228 228
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
229 229
 				    $Marine = new Marine($this->db);
230 230
 				    $fromsource = NULL;
231
-				    $Marine->updateArrivalPortNameMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['arrival_code'],$fromsource);
231
+				    $Marine->updateArrivalPortNameMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['arrival_code'], $fromsource);
232 232
 				    $Marine->db = null;
233 233
 				}
234 234
 			    }
@@ -244,31 +244,31 @@  discard block
 block discarded – undo
244 244
 		    }
245 245
 		}
246 246
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
247
-		    if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
247
+		    if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_date' => $line['arrival_date']));
248 248
 		}
249 249
 		if (isset($line['captain_id']) && $line['captain_id'] != '') {
250
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('captain_id' => $line['captain_id']));
250
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('captain_id' => $line['captain_id']));
251 251
 		}
252 252
 		if (isset($line['captain_name']) && $line['captain_name'] != '') {
253
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('captain_name' => $line['captain_name']));
253
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('captain_name' => $line['captain_name']));
254 254
 		}
255 255
 		if (isset($line['race_id']) && $line['race_id'] != '') {
256
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_id' => $line['race_id']));
256
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('race_id' => $line['race_id']));
257 257
 		}
258 258
 		if (isset($line['race_name']) && $line['race_name'] != '') {
259
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_name' => $line['race_name']));
259
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('race_name' => $line['race_name']));
260 260
 		}
261 261
 		if (isset($line['race_rank']) && $line['race_rank'] != '') {
262
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_rank' => $line['race_rank']));
262
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('race_rank' => $line['race_rank']));
263 263
 		}
264 264
 		if (isset($line['race_time']) && $line['race_time'] != '') {
265
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_time' => $line['race_time']));
265
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('race_time' => $line['race_time']));
266 266
 		}
267 267
 		if (isset($line['race_begin']) && $line['race_begin'] != '') {
268
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_begin' => $line['race_begin']));
268
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('race_begin' => $line['race_begin']));
269 269
 		}
270 270
 		if (isset($line['distance']) && $line['distance'] != '') {
271
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('distance' => $line['distance']));
271
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('distance' => $line['distance']));
272 272
 		}
273 273
 
274 274
 		//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'])) {
@@ -277,44 +277,44 @@  discard block
 block discarded – undo
277 277
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
278 278
 			    $timeelapsed = microtime(true);
279 279
 			    $Marine = new Marine($this->db);
280
-			    $Marine->addIdentity($this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['type']);
280
+			    $Marine->addIdentity($this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['type']);
281 281
 			    $Marine->db = null;
282 282
 			}
283 283
 		    }
284
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
284
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => trim($line['ident'])));
285 285
 		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
286 286
 			if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
287 287
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
288 288
 				$timeelapsed = microtime(true);
289 289
 				$Marine = new Marine($this->db);
290 290
 				$fromsource = NULL;
291
-				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
291
+				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $fromsource);
292 292
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
293 293
 				$Marine->db = null;
294
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
294
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
295 295
 			    }
296 296
 			}
297 297
 		    }
298
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
298
+		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $this->all_tracked[$id]['ident']));
299 299
 		}
300 300
 
301
-		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) {
301
+		if (isset($line['datetime']) && strtotime($line['datetime']) > time() - 30*60 && strtotime($line['datetime']) < time() + 20*60) {
302 302
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
303
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
303
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => $line['datetime']));
304 304
 		    } else {
305 305
 				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
306 306
 				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]['hex']." - format : ".$line['format_source']."\n";
307 307
 				return '';
308 308
 		    }
309
-		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) {
309
+		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time() - 30*60) {
310 310
 			if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
311 311
 			return '';
312
-		} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time()+20*60) {
312
+		} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time() + 20*60) {
313 313
 			if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
314 314
 			return '';
315 315
 		} elseif (!isset($line['datetime'])) {
316 316
 			date_default_timezone_set('UTC');
317
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
317
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => date('Y-m-d H:i:s')));
318 318
 		} else {
319 319
 			if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!\n";
320 320
 			return '';
@@ -322,20 +322,20 @@  discard block
 block discarded – undo
322 322
 
323 323
 
324 324
 		if (isset($line['speed'])) {
325
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'],2)));
326
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
325
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($line['speed'], 2)));
326
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed_fromsrc' => true));
327 327
 		} 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'])) {
328
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
328
+		    $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm');
329 329
 		    if ($distance > 1000 && $distance < 10000) {
330 330
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
331 331
 			$speed = $speed*3.6;
332
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed,2)));
332
+			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($speed, 2)));
333 333
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['id']." : ".$speed." - distance : ".$distance."\n";
334 334
 		    }
335 335
 		}
336 336
 
337 337
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
338
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
338
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time() - $this->all_tracked[$id]['time_last_coord']);
339 339
 	    	    else unset($timediff);
340 340
 	    	    if ($this->tmd > 5 ||
341 341
 	    		!isset($timediff) ||
@@ -344,11 +344,11 @@  discard block
 block discarded – undo
344 344
 	    		    $timediff > 30 && 
345 345
 	    		    isset($this->all_tracked[$id]['latitude']) &&
346 346
 	    		    isset($this->all_tracked[$id]['longitude']) &&
347
-	    		    $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m'))
347
+	    		    $Common->withinThreshold($timediff, $Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm'))
348 348
 	    		)
349 349
 	    		) {
350 350
 			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'])) {
351
-			    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'])) {
351
+			    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'])) {
352 352
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
353 353
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
354 354
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -357,10 +357,10 @@  discard block
 block discarded – undo
357 357
 				$timeelapsed = microtime(true);
358 358
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
359 359
 				    $Marine = new Marine($this->db);
360
-				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
360
+				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']);
361 361
 				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
362 362
 				    $Marine->db = null;
363
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
363
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
364 364
 				}
365 365
 				$this->tmd = 0;
366 366
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
@@ -369,55 +369,55 @@  discard block
 block discarded – undo
369 369
 
370 370
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
371 371
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
372
-				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') {
372
+				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') {
373 373
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
374 374
 				    $dataFound = true;
375 375
 				    $this->all_tracked[$id]['time_last_coord'] = time();
376 376
 				}
377
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
377
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('latitude' => $line['latitude']));
378 378
 			}
379 379
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
380 380
 			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
381 381
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
382
-				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') {
382
+				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') {
383 383
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
384 384
 				    $dataFound = true;
385 385
 				    $this->all_tracked[$id]['time_last_coord'] = time();
386 386
 				}
387
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
387
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('longitude' => $line['longitude']));
388 388
 			}
389 389
 
390 390
 		    } else if ($globalDebug && $timediff > 20) {
391 391
 			$this->tmd = $this->tmd + 1;
392 392
 			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
393
-			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
394
-			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
393
+			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')."m -";
394
+			echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - ";
395 395
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
396 396
 		    }
397 397
 		}
398 398
 		if (isset($line['last_update']) && $line['last_update'] != '') {
399 399
 		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
400
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
400
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('last_update' => $line['last_update']));
401 401
 		}
402 402
 		if (isset($line['format_source']) && $line['format_source'] != '') {
403
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
403
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('format_source' => $line['format_source']));
404 404
 		}
405 405
 		if (isset($line['source_name']) && $line['source_name'] != '') {
406
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
406
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('source_name' => $line['source_name']));
407 407
 		}
408 408
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
409
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
409
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('noarchive' => true));
410 410
 		}
411 411
 		
412 412
 		if (isset($line['heading']) && $line['heading'] != '') {
413
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
414
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
415
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
413
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading'] - round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
414
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($line['heading'])));
415
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading_fromsrc' => true));
416 416
 		    //$dataFound = true;
417 417
   		} 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']) {
418
-  		    $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']);
419
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
420
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
418
+  		    $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']);
419
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($heading)));
420
+		    if (abs($this->all_tracked[$id]['heading'] - round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
421 421
   		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
422 422
   		}
423 423
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
 		if ($dataFound === true && (isset($this->all_tracked[$id]['mmsi']) || isset($this->all_tracked[$id]['id']))) {
428 428
 		    $this->all_tracked[$id]['lastupdate'] = time();
429 429
 		    if ($this->all_tracked[$id]['addedMarine'] == 0 || (isset($globalVM) && $globalVM)) {
430
-		        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'])) && (!isset($globalOnlyID) || in_array($id,$globalOnlyID))) {
430
+		        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'])) && (!isset($globalOnlyID) || in_array($id, $globalOnlyID))) {
431 431
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
432 432
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
433 433
 				    if ($globalDebug) echo "Check if vessel is already in DB...";
@@ -436,28 +436,28 @@  discard block
 block discarded – undo
436 436
 				    if (isset($line['id']) && isset($globalVM) && $globalVM) {
437 437
 					$Marine = new Marine($this->db);
438 438
 					$recent_ident = $Marine->checkId($line['id']);
439
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkId : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
440
-					$Marine->db=null;
439
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkId : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
440
+					$Marine->db = null;
441 441
 				    } elseif (isset($line['id'])) {
442 442
 					$recent_ident = $MarineLive->checkIdRecent($line['id']);
443
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
443
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
444 444
 				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
445 445
 					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
446
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
446
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
447 447
 				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
448 448
 					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
449
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
449
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
450 450
 				    } else $recent_ident = '';
451
-				    $MarineLive->db=null;
451
+				    $MarineLive->db = null;
452 452
 				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
453 453
 				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
454 454
 				} else $recent_ident = '';
455 455
 			    } else {
456 456
 				$recent_ident = '';
457
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
457
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('forcenew' => 0));
458 458
 			    }
459 459
 			    //if there was no vessel with the same callsign within the last hour and go post it into the archive
460
-			    if($recent_ident == "" && (($this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') || (isset($globalVM) && $globalVM)))
460
+			    if ($recent_ident == "" && (($this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') || (isset($globalVM) && $globalVM)))
461 461
 			    {
462 462
 				if ($globalDebug) {
463 463
 					if ($this->all_tracked[$id]['mmsi'] != '') echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
@@ -465,19 +465,19 @@  discard block
 block discarded – undo
465 465
 				}
466 466
 				//adds the spotter data for the archive
467 467
 				    $highlight = '';
468
-				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
468
+				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
469 469
 				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
470 470
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
471 471
 					    $timeelapsed = microtime(true);
472 472
 					    $Marine = new Marine($this->db);
473 473
 					    if (isset($globalVM) && $globalVM && ($this->all_tracked[$id]['race_begin'] != '' || $this->all_tracked[$id]['format_source'] == 'sailaway')) {
474
-						$result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['race_begin'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time']);
474
+						$result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['race_begin'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['captain_id'], $this->all_tracked[$id]['captain_name'], $this->all_tracked[$id]['race_id'], $this->all_tracked[$id]['race_name'], $this->all_tracked[$id]['distance'], $this->all_tracked[$id]['race_rank'], $this->all_tracked[$id]['race_time']);
475 475
 					    } else {
476
-						$result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time']);
476
+						$result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['captain_id'], $this->all_tracked[$id]['captain_name'], $this->all_tracked[$id]['race_id'], $this->all_tracked[$id]['race_name'], $this->all_tracked[$id]['distance'], $this->all_tracked[$id]['race_rank'], $this->all_tracked[$id]['race_time']);
477 477
 					    }
478 478
 					    $Marine->db = null;
479 479
 					    if ($globalDebug && isset($result)) echo $result."\n";
480
-					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
480
+					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
481 481
 					}
482 482
 				    }
483 483
 				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
@@ -485,15 +485,15 @@  discard block
 block discarded – undo
485 485
 					$Stats = new Stats($this->db);
486 486
 					if (!empty($this->stats)) {
487 487
 					    if ($globalDebug) echo 'Add source stats : ';
488
-				    	    foreach($this->stats as $date => $data) {
489
-						foreach($data as $source => $sourced) {
488
+				    	    foreach ($this->stats as $date => $data) {
489
+						foreach ($data as $source => $sourced) {
490 490
 					    	    //print_r($sourced);
491
-				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
492
-				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
491
+				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']), $source, 'polar_marine', $date);
492
+				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']), $source, 'hist_marine', $date);
493 493
 				    		    if (isset($sourced['msg'])) {
494 494
 				    			if (time() - $sourced['msg']['date'] > 10) {
495 495
 				    		    	    $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
496
-				    		    	    echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date);
496
+				    		    	    echo $Stats->addStatSource($nbmsg, $source, 'msg_marine', $date);
497 497
 			    			    	    unset($this->stats[$date][$source]['msg']);
498 498
 			    				}
499 499
 			    			    }
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
518 518
 					$MarineLive = new MarineLive($this->db);
519 519
 					$MarineLive->deleteLiveMarineData();
520
-					$MarineLive->db=null;
520
+					$MarineLive->db = null;
521 521
 					if ($globalDebug) echo " Done\n";
522 522
 				    }
523 523
 				    $this->last_delete = time();
@@ -530,17 +530,17 @@  discard block
 block discarded – undo
530 530
 					$Marine = new Marine($this->db);
531 531
 					if (isset($globalVM) && $globalVM) {
532 532
 					    if ($this->all_tracked[$id]['status'] == 'Racing') {
533
-						$Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['race_begin']);
533
+						$Marine->updateLatestMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['distance'], $this->all_tracked[$id]['race_rank'], $this->all_tracked[$id]['race_time'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['race_begin']);
534 534
 					    } else {
535 535
 						//$finaldatetime = date('Y-m-d H:i:s',strtotime($this->all_tracked[$id]['race_begin'])+$this->all_tracked[$id]['race_time']);
536
-						$timerace = (strtotime($this->all_tracked[$id]['race_begin'])+$this->all_tracked[$id]['race_time']);
536
+						$timerace = (strtotime($this->all_tracked[$id]['race_begin']) + $this->all_tracked[$id]['race_time']);
537 537
 						if ($timerace > time()) $finaldatetime = NULL;
538
-						else $finaldatetime = date('Y-m-d H:i:s',$timerace);
538
+						else $finaldatetime = date('Y-m-d H:i:s', $timerace);
539 539
 
540
-						$Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$finaldatetime,$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['race_begin']);
540
+						$Marine->updateLatestMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['speed'], $finaldatetime, $this->all_tracked[$id]['distance'], $this->all_tracked[$id]['race_rank'], $this->all_tracked[$id]['race_time'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['race_begin']);
541 541
 					    }
542 542
 					} else {
543
-					    $Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['race_begin']);
543
+					    $Marine->updateLatestMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['distance'], $this->all_tracked[$id]['race_rank'], $this->all_tracked[$id]['race_time'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['race_begin']);
544 544
 					}
545 545
 					$Marine->db = null;
546 546
 				    }
@@ -556,20 +556,20 @@  discard block
 block discarded – undo
556 556
 		    $ignoreImport = false;
557 557
 		    if ((isset($globalVM) && $globalVM) && $this->all_tracked[$id]['status'] == 'sailawayfull' && $this->all_tracked[$id]['status'] != 'Racing') $ignoreImport = true;
558 558
 		    if (!$ignoreImport) {
559
-			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'])) && (!isset($globalOnlyID) || in_array($id,$globalOnlyID))) {
559
+			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'])) && (!isset($globalOnlyID) || in_array($id, $globalOnlyID))) {
560 560
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
561 561
 				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
562 562
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
563 563
 					$timeelapsed = microtime(true);
564 564
 					$MarineLive = new MarineLive($this->db);
565
-					$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time']);
565
+					$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['noarchive'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['over_country'], $this->all_tracked[$id]['captain_id'], $this->all_tracked[$id]['captain_name'], $this->all_tracked[$id]['race_id'], $this->all_tracked[$id]['race_name'], $this->all_tracked[$id]['distance'], $this->all_tracked[$id]['race_rank'], $this->all_tracked[$id]['race_time']);
566 566
 					$MarineLive->db = null;
567 567
 					if ($globalDebug) echo $result."\n";
568
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
568
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
569 569
 				    }
570 570
 				}
571 571
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) {
572
-					$APRSMarine->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
572
+					$APRSMarine->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['noarchive'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['over_country']);
573 573
 				}
574 574
 				$this->all_tracked[$id]['putinarchive'] = false;
575 575
 
@@ -588,19 +588,19 @@  discard block
 block discarded – undo
588 588
 							$latitude = $globalCenterLatitude;
589 589
 							$longitude = $globalCenterLongitude;
590 590
 						}
591
-						$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude);
591
+						$this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude);
592 592
 					} else {
593 593
 						$latitude = $this->source_location[$source]['latitude'];
594 594
 						$longitude = $this->source_location[$source]['longitude'];
595 595
 					}
596
-					$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
596
+					$stats_heading = $Common->getHeading($latitude, $longitude, $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude']);
597 597
 					//$stats_heading = $stats_heading%22.5;
598 598
 					$stats_heading = round($stats_heading/22.5);
599
-					$stats_distance = $Common->distance($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
599
+					$stats_distance = $Common->distance($latitude, $longitude, $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude']);
600 600
 					$current_date = date('Y-m-d');
601 601
 					if ($stats_heading == 16) $stats_heading = 0;
602 602
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
603
-						for ($i=0;$i<=15;$i++) {
603
+						for ($i = 0; $i <= 15; $i++) {
604 604
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
605 605
 						}
606 606
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
@@ -615,9 +615,9 @@  discard block
 block discarded – undo
615 615
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
616 616
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
617 617
 						    end($this->stats[$current_date][$source]['hist']);
618
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
618
+						    $mini = key($this->stats[$current_date][$source]['hist']) + 10;
619 619
 						} else $mini = 0;
620
-						for ($i=$mini;$i<=$distance;$i+=10) {
620
+						for ($i = $mini; $i <= $distance; $i += 10) {
621 621
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
622 622
 						}
623 623
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
 
630 630
 				$this->all_tracked[$id]['lastupdate'] = time();
631 631
 				if ($this->all_tracked[$id]['putinarchive']) $send = true;
632
-			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
632
+			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude'])."\n";
633 633
 			//$this->del();
634 634
 			
635 635
 			
@@ -656,7 +656,7 @@  discard block
 block discarded – undo
656 656
     
657 657
     public function race_add($data) {
658 658
         $Marine = new Marine();
659
-        $Marine->addRace($data['id'],$data['name'],$data['creator'],$data['desc'],$data['startdate'],$data['markers']);
659
+        $Marine->addRace($data['id'], $data['name'], $data['creator'], $data['desc'], $data['startdate'], $data['markers']);
660 660
         $Marine->db = null;
661 661
     }
662 662
 }
Please login to merge, or discard this patch.
Braces   +225 added lines, -78 removed lines patch added patch discarded remove patch
@@ -61,7 +61,9 @@  discard block
 block discarded – undo
61 61
     public function checkAll() {
62 62
 	global $globalDebug, $globalNoDB, $globalVM;
63 63
 	if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
64
-	    if ($globalDebug) echo "Update last seen tracked data...\n";
64
+	    if ($globalDebug) {
65
+	    	echo "Update last seen tracked data...\n";
66
+	    }
65 67
 	    foreach ($this->all_tracked as $key => $flight) {
66 68
 		if (isset($this->all_tracked[$key]['id'])) {
67 69
 		    //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
@@ -71,8 +73,11 @@  discard block
 block discarded – undo
71 73
     			    $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
72 74
     			} else {
73 75
     			    $timerace = (strtotime($this->all_tracked[$key]['race_begin'])+$this->all_tracked[$key]['race_time']);
74
-    			    if ($timerace > time()) $finaldatetime = NULL;
75
-    			    else $finaldatetime = date('Y-m-d H:i:s',$timerace);
76
+    			    if ($timerace > time()) {
77
+    			    	$finaldatetime = NULL;
78
+    			    } else {
79
+    			    	$finaldatetime = date('Y-m-d H:i:s',$timerace);
80
+    			    }
76 81
     			    $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$finaldatetime,$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
77 82
     			}
78 83
     		    } else {
@@ -86,13 +91,17 @@  discard block
 block discarded – undo
86 91
     public function del() {
87 92
 	global $globalDebug, $globalNoDB, $globalNoImport;
88 93
 	// Delete old infos
89
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
94
+	if ($globalDebug) {
95
+		echo 'Delete old values and update latest data...'."\n";
96
+	}
90 97
 	foreach ($this->all_tracked as $key => $flight) {
91 98
     	    if (isset($flight['lastupdate'])) {
92 99
         	if ($flight['lastupdate'] < (time()-3000)) {
93 100
             	    if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
94 101
             		if (isset($this->all_tracked[$key]['id'])) {
95
-            		    if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
102
+            		    if ($globalDebug) {
103
+            		    	echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
104
+            		    }
96 105
 			    /*
97 106
 			    $MarineLive = new MarineLive();
98 107
             		    $MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']);
@@ -106,14 +115,19 @@  discard block
 block discarded – undo
106 115
 					$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
107 116
 				    } else {
108 117
 					$timerace = strtotime($this->all_tracked[$key]['race_begin'])+$this->all_tracked[$key]['race_time'];
109
-	        			if ($timerace > time()) $finaldatetime = NULL;
110
-					else $finaldatetime = date('Y-m-d H:i:s',$timerace);
118
+	        			if ($timerace > time()) {
119
+	        				$finaldatetime = NULL;
120
+	        			} else {
121
+						$finaldatetime = date('Y-m-d H:i:s',$timerace);
122
+					}
111 123
 					$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$finaldatetime,$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
112 124
 				    }
113 125
 				} else {
114 126
 					$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status'],$this->all_tracked[$key]['race_begin']);
115 127
 				}
116
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
128
+				if ($globalDebug && $result != 'success') {
129
+					echo '!!! ERROR : '.$result."\n";
130
+				}
117 131
 			    }
118 132
 			    // Put in archive
119 133
 //				$Marine->db = null;
@@ -127,7 +141,9 @@  discard block
 block discarded – undo
127 141
 
128 142
     public function add($line) {
129 143
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine, $globalLiveInterval, $globalVM, $globalOnlyID;
130
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
144
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
145
+		$globalCoordMinChange = '0.02';
146
+	}
131 147
 	date_default_timezone_set('UTC');
132 148
 	$dataFound = false;
133 149
 	$send = false;
@@ -141,20 +157,30 @@  discard block
 block discarded – undo
141 157
 		// Increment message number
142 158
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
143 159
 		    $current_date = date('Y-m-d');
144
-		    if (isset($line['source_name'])) $source = $line['source_name'];
145
-		    else $source = '';
146
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
160
+		    if (isset($line['source_name'])) {
161
+		    	$source = $line['source_name'];
162
+		    } else {
163
+		    	$source = '';
164
+		    }
165
+		    if ($source == '' || $line['format_source'] == 'aprs') {
166
+		    	$source = $line['format_source'];
167
+		    }
147 168
 		    if (!isset($this->stats[$current_date][$source]['msg'])) {
148 169
 		    	$this->stats[$current_date][$source]['msg']['date'] = time();
149 170
 		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
150
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
171
+		    } else {
172
+		    	$this->stats[$current_date][$source]['msg']['nb'] += 1;
173
+		    }
151 174
 		}
152 175
 		
153 176
 		
154 177
 		$Common = new Common();
155 178
 		$AIS = new AIS();
156
-	        if (!isset($line['id'])) $id = trim($line['mmsi']);
157
-	        else $id = trim($line['id']);
179
+	        if (!isset($line['id'])) {
180
+	        	$id = trim($line['mmsi']);
181
+	        } else {
182
+	        	$id = trim($line['id']);
183
+	        }
158 184
 		
159 185
 		if (!isset($this->all_tracked[$id])) {
160 186
 		    $this->all_tracked[$id] = array();
@@ -162,10 +188,16 @@  discard block
 block discarded – undo
162 188
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => '','captain_id' => '','captain_name' => '','race_id' => '','race_name' => '','distance' => NULL,'race_rank' => NULL,'race_time' => NULL,'race_begin' => ''));
163 189
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
164 190
 		    if (!isset($line['id'])) {
165
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
191
+			if (!isset($globalDaemon)) {
192
+				$globalDaemon = TRUE;
193
+			}
166 194
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
167
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
168
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
195
+		     } else {
196
+		     	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
197
+		     }
198
+		    if ($globalAllTracked !== FALSE) {
199
+		    	$dataFound = true;
200
+		    }
169 201
 		}
170 202
 		
171 203
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
@@ -222,7 +254,9 @@  discard block
 block discarded – undo
222 254
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
223 255
 		    if (!isset($this->all_tracked[$id]['arrival_code'])) {
224 256
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
225
-			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
257
+			if ($globalDebug) {
258
+				echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
259
+			}
226 260
 			if ($this->all_tracked[$id]['addedMarine'] != 0) {
227 261
 			    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
228 262
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
@@ -235,7 +269,9 @@  discard block
 block discarded – undo
235 269
 			}
236 270
 		    } elseif ($this->all_tracked[$id]['arrival_code'] != $line['arrival_code']) {
237 271
 			$this->all_tracked[$id]['arrival_code'] = $line['arrival_code'];
238
-			if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
272
+			if ($globalDebug) {
273
+				echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n";
274
+			}
239 275
 			if (!isset($line['id'])) {
240 276
 				$this->all_tracked[$id]['id'] = $id.'-'.date('YmdHi');
241 277
 				$this->all_tracked[$id]['forcenew'] = 1;
@@ -244,7 +280,9 @@  discard block
 block discarded – undo
244 280
 		    }
245 281
 		}
246 282
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
247
-		    if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
283
+		    if (strtotime($line['arrival_date']) > time()) {
284
+		    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
285
+		    }
248 286
 		}
249 287
 		if (isset($line['captain_id']) && $line['captain_id'] != '') {
250 288
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('captain_id' => $line['captain_id']));
@@ -289,34 +327,49 @@  discard block
 block discarded – undo
289 327
 				$Marine = new Marine($this->db);
290 328
 				$fromsource = NULL;
291 329
 				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
292
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
330
+				if ($globalDebug && $result != 'success') {
331
+					echo '!!! ERROR : '.$result."\n";
332
+				}
293 333
 				$Marine->db = null;
294
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
334
+				if ($globalDebugTimeElapsed) {
335
+					echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
336
+				}
295 337
 			    }
296 338
 			}
297 339
 		    }
298
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
340
+		    if (!isset($this->all_tracked[$id]['id'])) {
341
+		    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
342
+		    }
299 343
 		}
300 344
 
301 345
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) {
302 346
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
303 347
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
304 348
 		    } else {
305
-				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
306
-				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]['hex']." - format : ".$line['format_source']."\n";
349
+				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
350
+					echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
351
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
352
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
353
+				}
307 354
 				return '';
308 355
 		    }
309 356
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) {
310
-			if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
357
+			if ($globalDebug) {
358
+				echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
359
+			}
311 360
 			return '';
312 361
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time()+20*60) {
313
-			if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
362
+			if ($globalDebug) {
363
+				echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n";
364
+			}
314 365
 			return '';
315 366
 		} elseif (!isset($line['datetime'])) {
316 367
 			date_default_timezone_set('UTC');
317 368
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
318 369
 		} else {
319
-			if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!\n";
370
+			if ($globalDebug) {
371
+				echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!\n";
372
+			}
320 373
 			return '';
321 374
 		}
322 375
 
@@ -329,14 +382,21 @@  discard block
 block discarded – undo
329 382
 		    if ($distance > 1000 && $distance < 10000) {
330 383
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
331 384
 			$speed = $speed*3.6;
332
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed,2)));
333
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['id']." : ".$speed." - distance : ".$distance."\n";
385
+			if ($speed < 1000) {
386
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed,2)));
387
+			}
388
+  			if ($globalDebug) {
389
+  				echo "ø Calculated Speed for ".$this->all_tracked[$id]['id']." : ".$speed." - distance : ".$distance."\n";
390
+  			}
334 391
 		    }
335 392
 		}
336 393
 
337 394
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
338
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
339
-	    	    else unset($timediff);
395
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) {
396
+	    	    	$timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
397
+	    	    } else {
398
+	    	    	unset($timediff);
399
+	    	    }
340 400
 	    	    if ($this->tmd > 5 ||
341 401
 	    		!isset($timediff) ||
342 402
 	    		$timediff > $globalLiveInterval ||
@@ -353,22 +413,32 @@  discard block
 block discarded – undo
353 413
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
354 414
 				$this->all_tracked[$id]['putinarchive'] = true;
355 415
 				
356
-				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
416
+				if ($globalDebug) {
417
+					echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
418
+				}
357 419
 				$timeelapsed = microtime(true);
358 420
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
359 421
 				    $Marine = new Marine($this->db);
360 422
 				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
361
-				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
423
+				    if (!empty($all_country)) {
424
+				    	$this->all_tracked[$id]['over_country'] = $all_country['iso2'];
425
+				    }
362 426
 				    $Marine->db = null;
363
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
427
+				    if ($globalDebugTimeElapsed) {
428
+				    	echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
429
+				    }
364 430
 				}
365 431
 				$this->tmd = 0;
366
-				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
432
+				if ($globalDebug) {
433
+					echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
434
+				}
367 435
 			    }
368 436
 			}
369 437
 
370 438
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
371
-				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
439
+				if (!isset($this->all_tracked[$id]['archive_latitude'])) {
440
+					$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
441
+				}
372 442
 				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') {
373 443
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
374 444
 				    $dataFound = true;
@@ -377,8 +447,12 @@  discard block
 block discarded – undo
377 447
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
378 448
 			}
379 449
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
380
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
381
-				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
450
+			    if ($line['longitude'] > 180) {
451
+			    	$line['longitude'] = $line['longitude'] - 360;
452
+			    }
453
+				if (!isset($this->all_tracked[$id]['archive_longitude'])) {
454
+					$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
455
+				}
382 456
 				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') {
383 457
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
384 458
 				    $dataFound = true;
@@ -396,7 +470,9 @@  discard block
 block discarded – undo
396 470
 		    }
397 471
 		}
398 472
 		if (isset($line['last_update']) && $line['last_update'] != '') {
399
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
473
+		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) {
474
+		    	$dataFound = true;
475
+		    }
400 476
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
401 477
 		}
402 478
 		if (isset($line['format_source']) && $line['format_source'] != '') {
@@ -410,15 +486,21 @@  discard block
 block discarded – undo
410 486
 		}
411 487
 		
412 488
 		if (isset($line['heading']) && $line['heading'] != '') {
413
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
489
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) {
490
+		    	$this->all_tracked[$id]['putinarchive'] = true;
491
+		    }
414 492
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
415 493
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
416 494
 		    //$dataFound = true;
417 495
   		} 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']) {
418 496
   		    $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']);
419 497
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
420
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
421
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
498
+		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) {
499
+		    	$this->all_tracked[$id]['putinarchive'] = true;
500
+		    }
501
+  		    if ($globalDebug) {
502
+  		    	echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
503
+  		    }
422 504
   		}
423 505
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
424 506
 
@@ -430,28 +512,45 @@  discard block
 block discarded – undo
430 512
 		        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'])) && (!isset($globalOnlyID) || in_array($id,$globalOnlyID))) {
431 513
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
432 514
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
433
-				    if ($globalDebug) echo "Check if vessel is already in DB...";
515
+				    if ($globalDebug) {
516
+				    	echo "Check if vessel is already in DB...";
517
+				    }
434 518
 				    $timeelapsed = microtime(true);
435 519
 				    $MarineLive = new MarineLive($this->db);
436 520
 				    if (isset($line['id']) && isset($globalVM) && $globalVM) {
437 521
 					$Marine = new Marine($this->db);
438 522
 					$recent_ident = $Marine->checkId($line['id']);
439
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkId : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
523
+					if ($globalDebugTimeElapsed) {
524
+						echo 'Time elapsed for update checkId : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
525
+					}
440 526
 					$Marine->db=null;
441 527
 				    } elseif (isset($line['id'])) {
442 528
 					$recent_ident = $MarineLive->checkIdRecent($line['id']);
443
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
529
+					if ($globalDebugTimeElapsed) {
530
+						echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
531
+					}
444 532
 				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
445 533
 					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
446
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
534
+					if ($globalDebugTimeElapsed) {
535
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
536
+					}
447 537
 				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
448 538
 					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
449
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
450
-				    } else $recent_ident = '';
539
+					if ($globalDebugTimeElapsed) {
540
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
541
+					}
542
+				    } else {
543
+				    	$recent_ident = '';
544
+				    }
451 545
 				    $MarineLive->db=null;
452
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
453
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
454
-				} else $recent_ident = '';
546
+				    if ($globalDebug && $recent_ident == '') {
547
+				    	echo " Not in DB.\n";
548
+				    } elseif ($globalDebug && $recent_ident != '') {
549
+				    	echo " Already in DB.\n";
550
+				    }
551
+				} else {
552
+					$recent_ident = '';
553
+				}
455 554
 			    } else {
456 555
 				$recent_ident = '';
457 556
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
@@ -460,12 +559,17 @@  discard block
 block discarded – undo
460 559
 			    if($recent_ident == "" && (($this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') || (isset($globalVM) && $globalVM)))
461 560
 			    {
462 561
 				if ($globalDebug) {
463
-					if ($this->all_tracked[$id]['mmsi'] != '') echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
464
-					else echo "\o/ Add ".$this->all_tracked[$id]['ident']." in archive DB : ";
562
+					if ($this->all_tracked[$id]['mmsi'] != '') {
563
+						echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
564
+					} else {
565
+						echo "\o/ Add ".$this->all_tracked[$id]['ident']." in archive DB : ";
566
+					}
465 567
 				}
466 568
 				//adds the spotter data for the archive
467 569
 				    $highlight = '';
468
-				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
570
+				    if (!isset($this->all_tracked[$id]['id'])) {
571
+				    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
572
+				    }
469 573
 				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
470 574
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
471 575
 					    $timeelapsed = microtime(true);
@@ -476,20 +580,30 @@  discard block
 block discarded – undo
476 580
 						$result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time']);
477 581
 					    }
478 582
 					    $Marine->db = null;
479
-					    if ($globalDebug && isset($result)) echo $result."\n";
480
-					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
583
+					    if ($globalDebug && isset($result)) {
584
+					    	echo $result."\n";
585
+					    }
586
+					    if ($globalDebugTimeElapsed) {
587
+					    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
588
+					    }
481 589
 					}
482 590
 				    }
483 591
 				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
484 592
 					// Add source stat in DB
485 593
 					$Stats = new Stats($this->db);
486 594
 					if (!empty($this->stats)) {
487
-					    if ($globalDebug) echo 'Add source stats : ';
595
+					    if ($globalDebug) {
596
+					    	echo 'Add source stats : ';
597
+					    }
488 598
 				    	    foreach($this->stats as $date => $data) {
489 599
 						foreach($data as $source => $sourced) {
490 600
 					    	    //print_r($sourced);
491
-				    	    	    if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
492
-				    	    	    if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
601
+				    	    	    if (isset($sourced['polar'])) {
602
+				    	    	    	echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date);
603
+				    	    	    }
604
+				    	    	    if (isset($sourced['hist'])) {
605
+				    	    	    	echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date);
606
+				    	    	    }
493 607
 				    		    if (isset($sourced['msg'])) {
494 608
 				    			if (time() - $sourced['msg']['date'] > 10) {
495 609
 				    		    	    $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
@@ -502,7 +616,9 @@  discard block
 block discarded – undo
502 616
 			    			    unset($this->stats[$date]);
503 617
 			    			}
504 618
 				    	    }
505
-				    	    if ($globalDebug) echo 'Done'."\n";
619
+				    	    if ($globalDebug) {
620
+				    	    	echo 'Done'."\n";
621
+				    	    }
506 622
 					}
507 623
 					$Stats->db = null;
508 624
 				    }
@@ -512,13 +628,17 @@  discard block
 block discarded – undo
512 628
 				$this->all_tracked[$id]['addedMarine'] = 1;
513 629
 				//print_r($this->all_tracked[$id]);
514 630
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
515
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 12 hours...";
631
+				    if ($globalDebug) {
632
+				    	echo "---- Deleting Live Marine data older than 12 hours...";
633
+				    }
516 634
 				    //MarineLive->deleteLiveMarineDataNotUpdated();
517 635
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
518 636
 					$MarineLive = new MarineLive($this->db);
519 637
 					$MarineLive->deleteLiveMarineData();
520 638
 					$MarineLive->db=null;
521
-					if ($globalDebug) echo " Done\n";
639
+					if ($globalDebug) {
640
+						echo " Done\n";
641
+					}
522 642
 				    }
523 643
 				    $this->last_delete = time();
524 644
 				}
@@ -534,8 +654,11 @@  discard block
 block discarded – undo
534 654
 					    } else {
535 655
 						//$finaldatetime = date('Y-m-d H:i:s',strtotime($this->all_tracked[$id]['race_begin'])+$this->all_tracked[$id]['race_time']);
536 656
 						$timerace = (strtotime($this->all_tracked[$id]['race_begin'])+$this->all_tracked[$id]['race_time']);
537
-						if ($timerace > time()) $finaldatetime = NULL;
538
-						else $finaldatetime = date('Y-m-d H:i:s',$timerace);
657
+						if ($timerace > time()) {
658
+							$finaldatetime = NULL;
659
+						} else {
660
+							$finaldatetime = date('Y-m-d H:i:s',$timerace);
661
+						}
539 662
 
540 663
 						$Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$finaldatetime,$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['race_begin']);
541 664
 					    }
@@ -554,18 +677,26 @@  discard block
 block discarded – undo
554 677
 			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'].' - Heading : '.$this->all_tracked[$id]['heading'].' - Speed : '.$this->all_tracked[$id]['speed']."\n";
555 678
 		    }
556 679
 		    $ignoreImport = false;
557
-		    if ((isset($globalVM) && $globalVM) && $this->all_tracked[$id]['status'] == 'sailawayfull' && $this->all_tracked[$id]['status'] != 'Racing') $ignoreImport = true;
680
+		    if ((isset($globalVM) && $globalVM) && $this->all_tracked[$id]['status'] == 'sailawayfull' && $this->all_tracked[$id]['status'] != 'Racing') {
681
+		    	$ignoreImport = true;
682
+		    }
558 683
 		    if (!$ignoreImport) {
559 684
 			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'])) && (!isset($globalOnlyID) || in_array($id,$globalOnlyID))) {
560
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
685
+				if ($globalDebug) {
686
+					echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
687
+				}
561 688
 				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
562 689
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
563 690
 					$timeelapsed = microtime(true);
564 691
 					$MarineLive = new MarineLive($this->db);
565 692
 					$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time']);
566 693
 					$MarineLive->db = null;
567
-					if ($globalDebug) echo $result."\n";
568
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
694
+					if ($globalDebug) {
695
+						echo $result."\n";
696
+					}
697
+					if ($globalDebugTimeElapsed) {
698
+						echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
699
+					}
569 700
 				    }
570 701
 				}
571 702
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) {
@@ -577,7 +708,9 @@  discard block
 block discarded – undo
577 708
 				
578 709
 				if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
579 710
 					$source = $this->all_tracked[$id]['source_name'];
580
-					if ($source == '') $source = $this->all_tracked[$id]['format_source'];
711
+					if ($source == '') {
712
+						$source = $this->all_tracked[$id]['format_source'];
713
+					}
581 714
 					if (!isset($this->source_location[$source])) {
582 715
 						$Location = new Source($this->db);
583 716
 						$coord = $Location->getLocationInfobySourceName($source);
@@ -598,7 +731,9 @@  discard block
 block discarded – undo
598 731
 					$stats_heading = round($stats_heading/22.5);
599 732
 					$stats_distance = $Common->distance($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
600 733
 					$current_date = date('Y-m-d');
601
-					if ($stats_heading == 16) $stats_heading = 0;
734
+					if ($stats_heading == 16) {
735
+						$stats_heading = 0;
736
+					}
602 737
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
603 738
 						for ($i=0;$i<=15;$i++) {
604 739
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
@@ -616,7 +751,9 @@  discard block
 block discarded – undo
616 751
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
617 752
 						    end($this->stats[$current_date][$source]['hist']);
618 753
 						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
619
-						} else $mini = 0;
754
+						} else {
755
+							$mini = 0;
756
+						}
620 757
 						for ($i=$mini;$i<=$distance;$i+=10) {
621 758
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
622 759
 						}
@@ -628,19 +765,27 @@  discard block
 block discarded – undo
628 765
 				
629 766
 
630 767
 				$this->all_tracked[$id]['lastupdate'] = time();
631
-				if ($this->all_tracked[$id]['putinarchive']) $send = true;
632
-			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
768
+				if ($this->all_tracked[$id]['putinarchive']) {
769
+					$send = true;
770
+				}
771
+			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
772
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
773
+			}
633 774
 			//$this->del();
634 775
 			
635 776
 			
636 777
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
637 778
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
638
-				if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
779
+				if ($globalDebug) {
780
+					echo "---- Deleting Live Marine data Not updated since 2 hour...";
781
+				}
639 782
 				$MarineLive = new MarineLive($this->db);
640 783
 				$MarineLive->deleteLiveMarineDataNotUpdated();
641 784
 				$MarineLive->db = null;
642 785
 				//MarineLive->deleteLiveMarineData();
643
-				if ($globalDebug) echo " Done\n";
786
+				if ($globalDebug) {
787
+					echo " Done\n";
788
+				}
644 789
 			    }
645 790
 			    $this->last_delete_hourly = time();
646 791
 			}
@@ -649,7 +794,9 @@  discard block
 block discarded – undo
649 794
 		    //$ignoreImport = false;
650 795
 		}
651 796
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
652
-		if ($send) return $this->all_tracked[$id];
797
+		if ($send) {
798
+			return $this->all_tracked[$id];
799
+		}
653 800
 	    }
654 801
 	}
655 802
     }
Please login to merge, or discard this patch.
scripts/daemon-spotter.php 3 patches
Indentation   +1221 added lines, -1221 removed lines patch added patch discarded remove patch
@@ -15,65 +15,65 @@  discard block
 block discarded – undo
15 15
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
16 16
 require_once(dirname(__FILE__).'/../require/class.Common.php');
17 17
 if (isset($globalTracker) && $globalTracker) {
18
-    require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
18
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
19 19
 }
20 20
 if (isset($globalMarine) && $globalMarine) {
21
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
22
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
21
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
22
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
23 23
 }
24 24
 
25 25
 if (!isset($globalDebug)) $globalDebug = FALSE;
26 26
 
27 27
 if ($globalInstalled === FALSE) {
28
-    echo "This script MUST be run after install script. Use your web browser to run install/index.php";
29
-    sleep(5);
30
-    die();
28
+	echo "This script MUST be run after install script. Use your web browser to run install/index.php";
29
+	sleep(5);
30
+	die();
31 31
 }
32 32
 
33 33
 
34 34
 // Check if schema is at latest version
35 35
 $Connection = new Connection();
36 36
 if ($Connection->connectionExists() === false) {
37
-    echo "Can't connect to your database. Check DB is running, user/password and database logs.";
38
-    exit();
37
+	echo "Can't connect to your database. Check DB is running, user/password and database logs.";
38
+	exit();
39 39
 }
40 40
 if ($Connection->latest() === false) {
41
-    echo "You MUST update to latest schema. Use your web browser to run install/index.php";
42
-    exit();
41
+	echo "You MUST update to latest schema. Use your web browser to run install/index.php";
42
+	exit();
43 43
 }
44 44
 if (PHP_SAPI != 'cli') {
45
-    echo "This script MUST be called from console, not a web browser.";
45
+	echo "This script MUST be called from console, not a web browser.";
46 46
 //    exit();
47 47
 }
48 48
 
49 49
 // This is to be compatible with old version of settings.php
50 50
 if (!isset($globalSources)) {
51
-    if (isset($globalSBS1Hosts)) {
52
-        //$hosts = $globalSBS1Hosts;
53
-        foreach ($globalSBS1Hosts as $host) {
54
-	    $globalSources[] = array('host' => $host);
55
-    	}
56
-    } else {
57
-        if (!isset($globalSBS1Host)) {
58
-	    echo '$globalSources MUST be defined !';
59
-	    die;
51
+	if (isset($globalSBS1Hosts)) {
52
+		//$hosts = $globalSBS1Hosts;
53
+		foreach ($globalSBS1Hosts as $host) {
54
+		$globalSources[] = array('host' => $host);
55
+		}
56
+	} else {
57
+		if (!isset($globalSBS1Host)) {
58
+		echo '$globalSources MUST be defined !';
59
+		die;
60 60
 	}
61 61
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
62 62
 	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
63
-    }
63
+	}
64 64
 }
65 65
 
66 66
 $options = getopt('s::',array('source::','server','nodaemon','idsource::','aprsserverssid::','aprsserverpass::','aprsserverhost::','aprsserverport::','format::','noaprsserver','enable-aircraft','disable-aircraft','enable-tracker','disable-tracker','enable-marine','disable-marine'));
67 67
 //if (isset($options['s'])) $hosts = array($options['s']);
68 68
 //elseif (isset($options['source'])) $hosts = array($options['source']);
69 69
 if (isset($options['s'])) {
70
-    $globalSources = array();
71
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
72
-    else $globalSources[] = array('host' => $options['s']);
70
+	$globalSources = array();
71
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
72
+	else $globalSources[] = array('host' => $options['s']);
73 73
 } elseif (isset($options['source'])) {
74
-    $globalSources = array();
75
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
76
-    else $globalSources[] = array('host' => $options['source']);
74
+	$globalSources = array();
75
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
76
+	else $globalSources[] = array('host' => $options['source']);
77 77
 }
78 78
 if (isset($options['aprsserverhost'])) {
79 79
 	$globalServerAPRS = TRUE;
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
 if (isset($options['idsource'])) $id_source = $options['idsource'];
113 113
 else $id_source = 1;
114 114
 if (isset($globalServer) && $globalServer) {
115
-    if ($globalDebug) echo "Using Server Mode\n";
116
-    $SI=new SpotterServer();
115
+	if ($globalDebug) echo "Using Server Mode\n";
116
+	$SI=new SpotterServer();
117 117
 /*
118 118
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
119 119
     $SI = new adsb2aprs();
@@ -123,14 +123,14 @@  discard block
 block discarded – undo
123 123
 
124 124
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
125 125
 if (isset($globalMarine) && $globalMarine) {
126
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
127
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
126
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
127
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
128 128
 }
129 129
 
130 130
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
131 131
 if (isset($globalMarine) && $globalMarine) {
132
-    $AIS = new AIS();
133
-    $MI = new MarineImport($Connection->db);
132
+	$AIS = new AIS();
133
+	$MI = new MarineImport($Connection->db);
134 134
 }
135 135
 //$APRS=new APRS($Connection->db);
136 136
 $SBS=new SBS();
@@ -143,12 +143,12 @@  discard block
 block discarded – undo
143 143
 //$servertz = system('date +%Z');
144 144
 // signal handler - playing nice with sockets and dump1090
145 145
 if (function_exists('pcntl_fork')) {
146
-    pcntl_signal(SIGINT,  function() {
147
-        global $sockets;
148
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
149
-        die("Bye!\n");
150
-    });
151
-    pcntl_signal_dispatch();
146
+	pcntl_signal(SIGINT,  function() {
147
+		global $sockets;
148
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
149
+		die("Bye!\n");
150
+	});
151
+	pcntl_signal_dispatch();
152 152
 }
153 153
 
154 154
 // let's try and connect
@@ -158,47 +158,47 @@  discard block
 block discarded – undo
158 158
 $reset = 0;
159 159
 
160 160
 function connect_all($hosts) {
161
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
162
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
163
-    $reset++;
164
-    if ($globalDebug) echo 'Connect to all...'."\n";
165
-    foreach ($hosts as $id => $value) {
161
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
162
+	global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
163
+	$reset++;
164
+	if ($globalDebug) echo 'Connect to all...'."\n";
165
+	foreach ($hosts as $id => $value) {
166 166
 	$host = $value['host'];
167 167
 	$udp = false;
168 168
 	$globalSources[$id]['last_exec'] = 0;
169 169
 	// Here we check type of source(s)
170 170
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
171
-            if (preg_match('/deltadb.txt$/i',$host)) {
172
-        	//$formats[$id] = 'deltadbtxt';
173
-        	$globalSources[$id]['format'] = 'deltadbtxt';
174
-        	//$last_exec['deltadbtxt'] = 0;
175
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
176
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
177
-        	//$formats[$id] = 'vatsimtxt';
178
-        	$globalSources[$id]['format'] = 'vatsimtxt';
179
-        	//$last_exec['vatsimtxt'] = 0;
180
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
181
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
182
-        	//$formats[$id] = 'aircraftlistjson';
183
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
184
-        	//$last_exec['aircraftlistjson'] = 0;
185
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
186
-    	    } else if (preg_match('/aircraft.json$/i',$host)) {
187
-        	//$formats[$id] = 'aircraftjson';
188
-        	$globalSources[$id]['format'] = 'aircraftjson';
189
-        	//$last_exec['aircraftlistjson'] = 0;
190
-        	if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
191
-    	    } else if (preg_match('/aircraft$/i',$host)) {
192
-        	//$formats[$id] = 'planefinderclient';
193
-        	$globalSources[$id]['format'] = 'planefinderclient';
194
-        	//$last_exec['aircraftlistjson'] = 0;
195
-        	if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
196
-    	    } else if (preg_match('/opensky/i',$host)) {
197
-        	//$formats[$id] = 'aircraftlistjson';
198
-        	$globalSources[$id]['format'] = 'opensky';
199
-        	//$last_exec['aircraftlistjson'] = 0;
200
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
201
-    	    /*
171
+			if (preg_match('/deltadb.txt$/i',$host)) {
172
+			//$formats[$id] = 'deltadbtxt';
173
+			$globalSources[$id]['format'] = 'deltadbtxt';
174
+			//$last_exec['deltadbtxt'] = 0;
175
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
176
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
177
+			//$formats[$id] = 'vatsimtxt';
178
+			$globalSources[$id]['format'] = 'vatsimtxt';
179
+			//$last_exec['vatsimtxt'] = 0;
180
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
181
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
182
+			//$formats[$id] = 'aircraftlistjson';
183
+			$globalSources[$id]['format'] = 'aircraftlistjson';
184
+			//$last_exec['aircraftlistjson'] = 0;
185
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
186
+			} else if (preg_match('/aircraft.json$/i',$host)) {
187
+			//$formats[$id] = 'aircraftjson';
188
+			$globalSources[$id]['format'] = 'aircraftjson';
189
+			//$last_exec['aircraftlistjson'] = 0;
190
+			if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
191
+			} else if (preg_match('/aircraft$/i',$host)) {
192
+			//$formats[$id] = 'planefinderclient';
193
+			$globalSources[$id]['format'] = 'planefinderclient';
194
+			//$last_exec['aircraftlistjson'] = 0;
195
+			if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
196
+			} else if (preg_match('/opensky/i',$host)) {
197
+			//$formats[$id] = 'aircraftlistjson';
198
+			$globalSources[$id]['format'] = 'opensky';
199
+			//$last_exec['aircraftlistjson'] = 0;
200
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
201
+			/*
202 202
     	    // Disabled for now, site change source format
203 203
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
204 204
         	//$formats[$id] = 'radarvirtueljson';
@@ -210,131 +210,131 @@  discard block
 block discarded – undo
210 210
         	    exit(0);
211 211
         	}
212 212
     	    */
213
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
214
-        	//$formats[$id] = 'planeupdatefaa';
215
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
216
-        	//$last_exec['planeupdatefaa'] = 0;
217
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
218
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
219
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
220
-        	    exit(0);
221
-        	}
222
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
223
-        	//$formats[$id] = 'phpvmacars';
224
-        	$globalSources[$id]['format'] = 'phpvmacars';
225
-        	//$last_exec['phpvmacars'] = 0;
226
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
227
-            } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
228
-        	//$formats[$id] = 'phpvmacars';
229
-        	$globalSources[$id]['format'] = 'vaos';
230
-        	//$last_exec['phpvmacars'] = 0;
231
-        	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
232
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
233
-        	//$formats[$id] = 'phpvmacars';
234
-        	$globalSources[$id]['format'] = 'vam';
235
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
236
-            } else if (preg_match('/whazzup/i',$host)) {
237
-        	//$formats[$id] = 'whazzup';
238
-        	$globalSources[$id]['format'] = 'whazzup';
239
-        	//$last_exec['whazzup'] = 0;
240
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
241
-            } else if (preg_match('/blitzortung/i',$host)) {
242
-        	$globalSources[$id]['format'] = 'blitzortung';
243
-        	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
244
-            } else if (preg_match('/airwhere/i',$host)) {
245
-        	$globalSources[$id]['format'] = 'airwhere';
246
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
247
-            } else if (preg_match('/recentpireps/i',$host)) {
248
-        	//$formats[$id] = 'pirepsjson';
249
-        	$globalSources[$id]['format'] = 'pirepsjson';
250
-        	//$last_exec['pirepsjson'] = 0;
251
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
252
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
253
-        	//$formats[$id] = 'fr24json';
254
-        	$globalSources[$id]['format'] = 'fr24json';
255
-        	//$last_exec['fr24json'] = 0;
256
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
257
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
258
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
259
-        	    exit(0);
260
-        	}
261
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
262
-        	//$formats[$id] = 'fr24json';
263
-        	$globalSources[$id]['format'] = 'myshiptracking';
264
-        	//$last_exec['fr24json'] = 0;
265
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
266
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
267
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
268
-        	    exit(0);
269
-        	}
270
-            //} else if (preg_match('/10001/',$host)) {
271
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
272
-        	//$formats[$id] = 'tsv';
273
-        	$globalSources[$id]['format'] = 'tsv';
274
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
275
-            }
276
-        } elseif (filter_var($host,FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'acarsjson')) {
277
-    		if ($globalSources[$id]['format'] == 'aisnmeahttp' || $globalSources[$id]['format'] == 'acarsjson') {
278
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
279
-    		    if ($idf !== false) {
280
-    			$httpfeeds[$id] = $idf;
281
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
282
-    		    } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
283
-    		} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
284
-    		elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') echo "Connect to ".$globalSources[$id]['format']." source (sailawayfull)...\n";
285
-    		elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
286
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
287
-	    $hostport = explode(':',$host);
288
-	    if (isset($hostport[1])) {
213
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
214
+			//$formats[$id] = 'planeupdatefaa';
215
+			$globalSources[$id]['format'] = 'planeupdatefaa';
216
+			//$last_exec['planeupdatefaa'] = 0;
217
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
218
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
219
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
220
+				exit(0);
221
+			}
222
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
223
+			//$formats[$id] = 'phpvmacars';
224
+			$globalSources[$id]['format'] = 'phpvmacars';
225
+			//$last_exec['phpvmacars'] = 0;
226
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
227
+			} else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
228
+			//$formats[$id] = 'phpvmacars';
229
+			$globalSources[$id]['format'] = 'vaos';
230
+			//$last_exec['phpvmacars'] = 0;
231
+			if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
232
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
233
+			//$formats[$id] = 'phpvmacars';
234
+			$globalSources[$id]['format'] = 'vam';
235
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
236
+			} else if (preg_match('/whazzup/i',$host)) {
237
+			//$formats[$id] = 'whazzup';
238
+			$globalSources[$id]['format'] = 'whazzup';
239
+			//$last_exec['whazzup'] = 0;
240
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
241
+			} else if (preg_match('/blitzortung/i',$host)) {
242
+			$globalSources[$id]['format'] = 'blitzortung';
243
+			if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
244
+			} else if (preg_match('/airwhere/i',$host)) {
245
+			$globalSources[$id]['format'] = 'airwhere';
246
+			if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
247
+			} else if (preg_match('/recentpireps/i',$host)) {
248
+			//$formats[$id] = 'pirepsjson';
249
+			$globalSources[$id]['format'] = 'pirepsjson';
250
+			//$last_exec['pirepsjson'] = 0;
251
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
252
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
253
+			//$formats[$id] = 'fr24json';
254
+			$globalSources[$id]['format'] = 'fr24json';
255
+			//$last_exec['fr24json'] = 0;
256
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
257
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
258
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
259
+				exit(0);
260
+			}
261
+			} else if (preg_match(':myshiptracking.com/:i',$host)) {
262
+			//$formats[$id] = 'fr24json';
263
+			$globalSources[$id]['format'] = 'myshiptracking';
264
+			//$last_exec['fr24json'] = 0;
265
+			if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
266
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
267
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
268
+				exit(0);
269
+			}
270
+			//} else if (preg_match('/10001/',$host)) {
271
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
272
+			//$formats[$id] = 'tsv';
273
+			$globalSources[$id]['format'] = 'tsv';
274
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
275
+			}
276
+		} elseif (filter_var($host,FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'acarsjson')) {
277
+			if ($globalSources[$id]['format'] == 'aisnmeahttp' || $globalSources[$id]['format'] == 'acarsjson') {
278
+				$idf = fopen($globalSources[$id]['host'],'r',false,$context);
279
+				if ($idf !== false) {
280
+				$httpfeeds[$id] = $idf;
281
+				if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
282
+				} elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
283
+			} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
284
+			elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') echo "Connect to ".$globalSources[$id]['format']." source (sailawayfull)...\n";
285
+			elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
286
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
287
+		$hostport = explode(':',$host);
288
+		if (isset($hostport[1])) {
289 289
 		$port = $hostport[1];
290 290
 		$hostn = $hostport[0];
291
-	    } else {
291
+		} else {
292 292
 		$port = $globalSources[$id]['port'];
293 293
 		$hostn = $globalSources[$id]['host'];
294
-	    }
295
-	    $Common = new Common();
296
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acarsjsonudp' && $globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
297
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
298
-    	    } else {
299
-    		$udp = true;
300
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
301
-	    }
302
-	    if ($s) {
303
-    	        $sockets[$id] = $s;
304
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
305
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
294
+		}
295
+		$Common = new Common();
296
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acarsjsonudp' && $globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
297
+			$s = $Common->create_socket($hostn,$port, $errno, $errstr);
298
+			} else {
299
+			$udp = true;
300
+			$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
301
+		}
302
+		if ($s) {
303
+				$sockets[$id] = $s;
304
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
305
+			if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
306 306
 			//$formats[$id] = 'aprs';
307 307
 			$globalSources[$id]['format'] = 'aprs';
308 308
 			//$aprs_connect = 0;
309 309
 			//$use_aprs = true;
310
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
310
+			} elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
311 311
 			$globalSources[$id]['format'] = 'vrstcp';
312
-    		    } elseif ($port == '10001') {
313
-        		//$formats[$id] = 'tsv';
314
-        		$globalSources[$id]['format'] = 'tsv';
315
-		    } elseif ($port == '30002') {
316
-        		//$formats[$id] = 'raw';
317
-        		$globalSources[$id]['format'] = 'raw';
318
-		    } elseif ($port == '5001') {
319
-        		//$formats[$id] = 'raw';
320
-        		$globalSources[$id]['format'] = 'flightgearmp';
321
-		    } elseif ($port == '30005') {
312
+				} elseif ($port == '10001') {
313
+				//$formats[$id] = 'tsv';
314
+				$globalSources[$id]['format'] = 'tsv';
315
+			} elseif ($port == '30002') {
316
+				//$formats[$id] = 'raw';
317
+				$globalSources[$id]['format'] = 'raw';
318
+			} elseif ($port == '5001') {
319
+				//$formats[$id] = 'raw';
320
+				$globalSources[$id]['format'] = 'flightgearmp';
321
+			} elseif ($port == '30005') {
322 322
 			// Not yet supported
323
-        		//$formats[$id] = 'beast';
324
-        		$globalSources[$id]['format'] = 'beast';
325
-		    //} else $formats[$id] = 'sbs';
326
-		    } else $globalSources[$id]['format'] = 'sbs';
327
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
323
+				//$formats[$id] = 'beast';
324
+				$globalSources[$id]['format'] = 'beast';
325
+			//} else $formats[$id] = 'sbs';
326
+			} else $globalSources[$id]['format'] = 'sbs';
327
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
328 328
 		}
329 329
 		if ($globalDebug && $udp) echo 'Listening in UDP from '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
330 330
 		elseif ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
331
-            } else {
331
+			} else {
332 332
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
333 333
 		sleep(10);
334 334
 		connect_all($hosts);
335
-    	    }
336
-        }
337
-    }
335
+			}
336
+		}
337
+	}
338 338
 }
339 339
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
340 340
 
@@ -357,9 +357,9 @@  discard block
 block discarded – undo
357 357
 //connect_all($globalSources);
358 358
 
359 359
 if (isset($globalProxy) && $globalProxy) {
360
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
360
+	$context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
361 361
 } else {
362
-    $context = stream_context_create(array('http' => array('timeout' => $timeout)));
362
+	$context = stream_context_create(array('http' => array('timeout' => $timeout)));
363 363
 }
364 364
 
365 365
 // APRS Configuration
@@ -368,21 +368,21 @@  discard block
 block discarded – undo
368 368
 	die;
369 369
 }
370 370
 foreach ($globalSources as $key => $source) {
371
-    if (!isset($source['format'])) {
372
-        $globalSources[$key]['format'] = 'auto';
373
-    }
374
-    if (isset($source['callback']) && $source['callback'] === TRUE) {
375
-        unset($globalSources[$key]);
376
-    }
371
+	if (!isset($source['format'])) {
372
+		$globalSources[$key]['format'] = 'auto';
373
+	}
374
+	if (isset($source['callback']) && $source['callback'] === TRUE) {
375
+		unset($globalSources[$key]);
376
+	}
377 377
 }
378 378
 connect_all($globalSources);
379 379
 foreach ($globalSources as $key => $source) {
380
-    if (isset($source['format']) && $source['format'] == 'aprs') {
380
+	if (isset($source['format']) && $source['format'] == 'aprs') {
381 381
 	$aprs_connect = 0;
382 382
 	$use_aprs = true;
383 383
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
384 384
 	break;
385
-    }
385
+	}
386 386
 }
387 387
 
388 388
 if ($use_aprs) {
@@ -423,173 +423,173 @@  discard block
 block discarded – undo
423 423
 
424 424
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
425 425
 while ($i > 0) {
426
-    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
426
+	if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
427 427
 
428
-    if (!$globalDaemon) $i = $endtime-time();
429
-    // Delete old ATC
430
-    if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
428
+	if (!$globalDaemon) $i = $endtime-time();
429
+	// Delete old ATC
430
+	if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
431 431
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
432
-        $ATC->deleteOldATC();
433
-    }
432
+		$ATC->deleteOldATC();
433
+	}
434 434
     
435
-    if (count($last_exec) == count($globalSources)) {
435
+	if (count($last_exec) == count($globalSources)) {
436 436
 	$max = $globalMinFetch;
437 437
 	foreach ($last_exec as $last) {
438
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
438
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
439 439
 	}
440 440
 	if ($max < $globalMinFetch) {
441
-	    if ($globalDebug) echo 'Sleeping...'."\n";
442
-	    sleep($globalMinFetch-$max+2);
441
+		if ($globalDebug) echo 'Sleeping...'."\n";
442
+		sleep($globalMinFetch-$max+2);
443
+	}
443 444
 	}
444
-    }
445 445
 
446 446
     
447
-    //foreach ($formats as $id => $value) {
448
-    foreach ($globalSources as $id => $value) {
447
+	//foreach ($formats as $id => $value) {
448
+	foreach ($globalSources as $id => $value) {
449 449
 	date_default_timezone_set('UTC');
450 450
 	//if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n";
451 451
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
452 452
 	if ($value['format'] === 'deltadbtxt' && 
453
-	    (
453
+		(
454 454
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
455 455
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
456
-	    )
456
+		)
457 457
 	) {
458
-        //$buffer = $Common->getData($hosts[$id]);
459
-        $buffer = $Common->getData($value['host']);
460
-        if ($buffer != '') $reset = 0;
461
-        $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
462
-        $buffer = explode('\n', $buffer);
463
-        foreach ($buffer as $line) {
464
-            if ($line != '' && count($line) > 7) {
465
-                $line = explode(',', $line);
466
-                $data = array();
467
-                $data['hex'] = $line[1]; // hex
468
-                $data['ident'] = $line[2]; // ident
469
-                if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
470
-                if (isset($line[4])) $data['speed'] = $line[4]; // speed
471
-                if (isset($line[5])) $data['heading'] = $line[5]; // heading
472
-                if (isset($line[6])) $data['latitude'] = $line[6]; // lat
473
-                if (isset($line[7])) $data['longitude'] = $line[7]; // long
474
-                $data['verticalrate'] = ''; // vertical rate
475
-                //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
476
-                $data['emergency'] = ''; // emergency
477
-                $data['datetime'] = date('Y-m-d H:i:s');
478
-                $data['format_source'] = 'deltadbtxt';
479
-                $data['id_source'] = $id_source;
480
-                if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
481
-                if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
482
-                if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
483
-                $SI->add($data);
484
-                unset($data);
485
-            }
486
-        }
487
-        $last_exec[$id]['last'] = time();
488
-    } elseif ($value['format'] === 'radarcapejson' &&
489
-            (
490
-                (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
491
-                (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
492
-            )
493
-        ) {
494
-            //$buffer = $Common->getData($hosts[$id]);
495
-            $buffer = $Common->getData($value['host']);
496
-            if ($buffer != '') {
497
-                $all_data = json_decode($buffer,true);
498
-                foreach ($all_data as $line) {
499
-                    $data = array();
500
-                    $data['datetime'] = date('Y-m-d H:i:s',$line['uti']);
501
-                    $data['hex'] = $line['hex']; // hex
502
-                    $data['ident'] = $line['fli']; // ident
503
-                    $data['altitude'] = $line['alt']; // altitude
504
-                    $data['speed'] = $line['spd']; // speed
505
-                    $data['heading'] = $line['trk']; // heading
506
-                    $data['latitude'] = $line['lat']; // lat
507
-                    $data['longitude'] = $line['lon']; // long
508
-                    $data['verticalrate'] = $line['vrt']; // vertical rate
509
-                    $data['squawk'] = $line['squ']; // squawk
510
-                    $data['ground'] = $line['gda']; // ground
511
-                    $data['registration'] = $line['reg'];
512
-                    //$data['emergency'] = ''; // emergency
513
-                    $data['datetime'] = date('Y-m-d H:i:s');
514
-                    $data['format_source'] = 'radarcapejson';
515
-                    $data['id_source'] = $id_source;
516
-                    if (isset($value['name']) && $value['name'] != '') {
517
-                        if (isset($line['src']) && !$line['src'] == 'M') $data['source_name'] = $value['name'].'_MLAT';
518
-                        else $data['source_name'] = $value['name'];
519
-                    } elseif (isset($line['src']) && $line['src'] == 'M') $data['source_name'] = 'MLAT';
520
-                    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
521
-                    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
458
+		//$buffer = $Common->getData($hosts[$id]);
459
+		$buffer = $Common->getData($value['host']);
460
+		if ($buffer != '') $reset = 0;
461
+		$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
462
+		$buffer = explode('\n', $buffer);
463
+		foreach ($buffer as $line) {
464
+			if ($line != '' && count($line) > 7) {
465
+				$line = explode(',', $line);
466
+				$data = array();
467
+				$data['hex'] = $line[1]; // hex
468
+				$data['ident'] = $line[2]; // ident
469
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
470
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
471
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
472
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
473
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
474
+				$data['verticalrate'] = ''; // vertical rate
475
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
476
+				$data['emergency'] = ''; // emergency
477
+				$data['datetime'] = date('Y-m-d H:i:s');
478
+				$data['format_source'] = 'deltadbtxt';
479
+				$data['id_source'] = $id_source;
480
+				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
481
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
482
+				if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
483
+				$SI->add($data);
484
+				unset($data);
485
+			}
486
+		}
487
+		$last_exec[$id]['last'] = time();
488
+	} elseif ($value['format'] === 'radarcapejson' &&
489
+			(
490
+				(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
491
+				(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
492
+			)
493
+		) {
494
+			//$buffer = $Common->getData($hosts[$id]);
495
+			$buffer = $Common->getData($value['host']);
496
+			if ($buffer != '') {
497
+				$all_data = json_decode($buffer,true);
498
+				foreach ($all_data as $line) {
499
+					$data = array();
500
+					$data['datetime'] = date('Y-m-d H:i:s',$line['uti']);
501
+					$data['hex'] = $line['hex']; // hex
502
+					$data['ident'] = $line['fli']; // ident
503
+					$data['altitude'] = $line['alt']; // altitude
504
+					$data['speed'] = $line['spd']; // speed
505
+					$data['heading'] = $line['trk']; // heading
506
+					$data['latitude'] = $line['lat']; // lat
507
+					$data['longitude'] = $line['lon']; // long
508
+					$data['verticalrate'] = $line['vrt']; // vertical rate
509
+					$data['squawk'] = $line['squ']; // squawk
510
+					$data['ground'] = $line['gda']; // ground
511
+					$data['registration'] = $line['reg'];
512
+					//$data['emergency'] = ''; // emergency
513
+					$data['datetime'] = date('Y-m-d H:i:s');
514
+					$data['format_source'] = 'radarcapejson';
515
+					$data['id_source'] = $id_source;
516
+					if (isset($value['name']) && $value['name'] != '') {
517
+						if (isset($line['src']) && !$line['src'] == 'M') $data['source_name'] = $value['name'].'_MLAT';
518
+						else $data['source_name'] = $value['name'];
519
+					} elseif (isset($line['src']) && $line['src'] == 'M') $data['source_name'] = 'MLAT';
520
+					if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
521
+					if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
522 522
 
523
-                    $SI->add($data);
524
-                    unset($data);
525
-                }
526
-            }
527
-            $last_exec[$id]['last'] = time();
523
+					$SI->add($data);
524
+					unset($data);
525
+				}
526
+			}
527
+			$last_exec[$id]['last'] = time();
528 528
 	} elseif ($value['format'] === 'aisnmeatxt' && 
529
-	    (
529
+		(
530 530
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
531 531
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
532
-	    )
532
+		)
533 533
 	) {
534
-	    date_default_timezone_set('CET');
535
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
536
-	    date_default_timezone_set('UTC');
537
-	    if ($buffer != '') $reset = 0;
538
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
539
-	    $buffer = explode('\n',$buffer);
540
-	    foreach ($buffer as $line) {
534
+		date_default_timezone_set('CET');
535
+		$buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
536
+		date_default_timezone_set('UTC');
537
+		if ($buffer != '') $reset = 0;
538
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
539
+		$buffer = explode('\n',$buffer);
540
+		foreach ($buffer as $line) {
541 541
 		if ($line != '') {
542
-		    //echo "'".$line."'\n";
543
-		    $add = false;
544
-		    $ais_data = $AIS->parse_line(trim($line));
545
-		    $data = array();
546
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
547
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
548
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
549
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
550
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
551
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
552
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
553
-		    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
554
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
555
-		    if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
556
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
557
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
558
-		    if (isset($ais_data['timestamp'])) {
542
+			//echo "'".$line."'\n";
543
+			$add = false;
544
+			$ais_data = $AIS->parse_line(trim($line));
545
+			$data = array();
546
+			if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
547
+			if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
548
+			if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
549
+			if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
550
+			if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
551
+			if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
552
+			if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
553
+			if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
554
+			if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
555
+			if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
556
+			if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
557
+			if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
558
+			if (isset($ais_data['timestamp'])) {
559 559
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
560 560
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
561
-			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
562
-			    $add = true;
561
+				$last_exec[$id]['timestamp'] = $ais_data['timestamp'];
562
+				$add = true;
563 563
 			}
564
-		    } else {
564
+			} else {
565 565
 			$data['datetime'] = date('Y-m-d H:i:s');
566 566
 			$add = true;
567
-		    }
568
-		    $data['format_source'] = 'aisnmeatxt';
569
-    		    $data['id_source'] = $id_source;
570
-		    //print_r($data);
571
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
572
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
573
-		    unset($data);
567
+			}
568
+			$data['format_source'] = 'aisnmeatxt';
569
+				$data['id_source'] = $id_source;
570
+			//print_r($data);
571
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
572
+			if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
573
+			unset($data);
574 574
 		}
575
-    	    }
576
-    	    $last_exec[$id]['last'] = time();
575
+			}
576
+			$last_exec[$id]['last'] = time();
577 577
 	} elseif ($value['format'] === 'aisnmeahttp') {
578
-	    $arr = $httpfeeds;
579
-	    $w = $e = null;
578
+		$arr = $httpfeeds;
579
+		$w = $e = null;
580 580
 	    
581
-	    if (isset($arr[$id])) {
581
+		if (isset($arr[$id])) {
582 582
 		$nn = stream_select($arr,$w,$e,$timeout);
583 583
 		if ($nn > 0) {
584
-		    foreach ($httpfeeds as $feed) {
584
+			foreach ($httpfeeds as $feed) {
585 585
 			$buffer = stream_get_line($feed,2000,"\n");
586 586
 			if ($buffer === FALSE) {
587
-			    connect_all($globalSources);
587
+				connect_all($globalSources);
588 588
 			}
589 589
 			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
590 590
 			$buffer = explode('\n',$buffer);
591 591
 			foreach ($buffer as $line) {
592
-			    if ($line != '') {
592
+				if ($line != '') {
593 593
 				$ais_data = $AIS->parse_line(trim($line));
594 594
 				$data = array();
595 595
 				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
@@ -607,117 +607,117 @@  discard block
 block discarded – undo
607 607
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
608 608
 				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
609 609
 				if (isset($ais_data['timestamp'])) {
610
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
610
+					$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
611 611
 				} else {
612
-				    $data['datetime'] = date('Y-m-d H:i:s');
612
+					$data['datetime'] = date('Y-m-d H:i:s');
613 613
 				}
614 614
 				$data['format_source'] = 'aisnmeahttp';
615 615
 				$data['id_source'] = $id_source;
616 616
 				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
617 617
 				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
618 618
 				unset($data);
619
-			    }
619
+				}
620
+			}
620 621
 			}
621
-		    }
622 622
 		} else {
623
-		    $format = $value['format'];
624
-		    if (isset($tt[$format])) $tt[$format]++;
625
-		    else $tt[$format] = 0;
626
-		    if ($tt[$format] > 30) {
623
+			$format = $value['format'];
624
+			if (isset($tt[$format])) $tt[$format]++;
625
+			else $tt[$format] = 0;
626
+			if ($tt[$format] > 30) {
627 627
 			if ($globalDebug) echo 'Reconnect...'."\n";
628 628
 			sleep(2);
629 629
 			//$sourceeen[] = $value;
630 630
 			//connect_all($sourceeen);
631 631
 			//$sourceeen = array();
632 632
 			connect_all($globalSources);
633
-		    }
633
+			}
634
+		}
634 635
 		}
635
-	    }
636 636
 	} elseif ($value['format'] === 'myshiptracking' && 
637
-	    (
637
+		(
638 638
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
639 639
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
640
-	    )
640
+		)
641 641
 	) {
642
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
643
-	    if ($buffer != '') {
642
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
643
+		if ($buffer != '') {
644 644
 		//echo $buffer;
645 645
 		$all_data = json_decode($buffer,true);
646 646
 		//print_r($all_data);
647 647
 		if (isset($all_data[0]['DATA'])) {
648
-		    foreach ($all_data[0]['DATA'] as $line) {
648
+			foreach ($all_data[0]['DATA'] as $line) {
649 649
 			if ($line != '') {
650
-			    $data = array();
651
-			    $data['ident'] = $line['NAME'];
652
-			    $data['mmsi'] = $line['MMSI'];
653
-			    if (strlen($data['mmsi']) > 9) {
650
+				$data = array();
651
+				$data['ident'] = $line['NAME'];
652
+				$data['mmsi'] = $line['MMSI'];
653
+				if (strlen($data['mmsi']) > 9) {
654 654
 				$data['mmsi'] = substr($data['mmsi'],-9);
655
-			    }
656
-			    $data['speed'] = $line['SOG'];
657
-			    $data['heading'] = $line['COG'];
658
-			    $data['latitude'] = $line['LAT'];
659
-			    $data['longitude'] = $line['LNG'];
660
-			    //    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
661
-			    //$data['type_id'] = $line['TYPE'];
662
-			    $data['imo'] = $line['IMO'];
663
-			    if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
664
-			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
665
-			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
666
-			    $data['format_source'] = 'myshiptracking';
667
-			    $data['id_source'] = $id_source;
668
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
669
-			    $MI->add($data);
670
-			    unset($data);
655
+				}
656
+				$data['speed'] = $line['SOG'];
657
+				$data['heading'] = $line['COG'];
658
+				$data['latitude'] = $line['LAT'];
659
+				$data['longitude'] = $line['LNG'];
660
+				//    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
661
+				//$data['type_id'] = $line['TYPE'];
662
+				$data['imo'] = $line['IMO'];
663
+				if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
664
+				if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
665
+				$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
666
+				$data['format_source'] = 'myshiptracking';
667
+				$data['id_source'] = $id_source;
668
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
669
+				$MI->add($data);
670
+				unset($data);
671
+			}
671 672
 			}
672
-		    }
673 673
 		}
674
-	    }
675
-	    $last_exec[$id]['last'] = time();
674
+		}
675
+		$last_exec[$id]['last'] = time();
676 676
 	} elseif ($value['format'] === 'boatbeaconapp' && 
677
-	    (
677
+		(
678 678
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
679 679
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
680
-	    )
680
+		)
681 681
 	) {
682
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
683
-	    if ($buffer != '') {
682
+		$buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
683
+		if ($buffer != '') {
684 684
 		$all_data = json_decode($buffer,true);
685 685
 		if (isset($all_data[0]['mmsi'])) {
686
-		    foreach ($all_data as $line) {
686
+			foreach ($all_data as $line) {
687 687
 			if ($line != '') {
688
-			    $data = array();
689
-			    $data['ident'] = $line['shipname'];
690
-			    $data['callsign'] = $line['callsign'];
691
-			    $data['mmsi'] = substr($line['mmsi'],-9);
692
-			    $data['speed'] = $line['sog'];
693
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
694
-			    $data['latitude'] = $line['latitude'];
695
-			    $data['longitude'] = $line['longitude'];
696
-			    $data['type_id'] = $line['shiptype'];
697
-			    $data['arrival_code'] = $line['destination'];
698
-			    $data['datetime'] = $line['time'];
699
-			    $data['format_source'] = 'boatbeaconapp';
700
-			    $data['id_source'] = $id_source;
701
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
702
-			    $MI->add($data);
703
-			    unset($data);
688
+				$data = array();
689
+				$data['ident'] = $line['shipname'];
690
+				$data['callsign'] = $line['callsign'];
691
+				$data['mmsi'] = substr($line['mmsi'],-9);
692
+				$data['speed'] = $line['sog'];
693
+				if ($line['heading'] != '511') $data['heading'] = $line['heading'];
694
+				$data['latitude'] = $line['latitude'];
695
+				$data['longitude'] = $line['longitude'];
696
+				$data['type_id'] = $line['shiptype'];
697
+				$data['arrival_code'] = $line['destination'];
698
+				$data['datetime'] = $line['time'];
699
+				$data['format_source'] = 'boatbeaconapp';
700
+				$data['id_source'] = $id_source;
701
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
702
+				$MI->add($data);
703
+				unset($data);
704
+			}
704 705
 			}
705
-		    }
706 706
 		}
707 707
 		
708
-	    }
709
-    	    $last_exec[$id]['last'] = time();
708
+		}
709
+			$last_exec[$id]['last'] = time();
710 710
 	} elseif ($value['format'] === 'boatnerd' && 
711
-	    (
711
+		(
712 712
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
713 713
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
714
-	    )
714
+		)
715 715
 	) {
716
-	    $buffer = $Common->getData($value['host']);
717
-	    if ($buffer != '') {
716
+		$buffer = $Common->getData($value['host']);
717
+		if ($buffer != '') {
718 718
 		$all_data = json_decode($buffer,true);
719 719
 		if (isset($all_data['features'][0]['id'])) {
720
-		    foreach ($all_data['features'] as $line) {
720
+			foreach ($all_data['features'] as $line) {
721 721
 			print_r($line);
722 722
 			$data = array();
723 723
 			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
@@ -737,75 +737,75 @@  discard block
 block discarded – undo
737 737
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
738 738
 			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
739 739
 			unset($data);
740
-		    }
740
+			}
741 741
 		}
742 742
 		
743
-	    }
744
-    	    $last_exec[$id]['last'] = time();
743
+		}
744
+			$last_exec[$id]['last'] = time();
745 745
 	} elseif ($value['format'] === 'shipplotter' && 
746
-	    (
746
+		(
747 747
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
748 748
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
749
-	    )
749
+		)
750 750
 	) {
751
-	    if ($globalDebug) echo 'download...';
752
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
753
-	    if ($globalDebug) echo 'done !'."\n";
754
-	    // FIXME: Need more work
755
-	    if ($buffer != '') $reset = 0;
756
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
757
-	    $buffer = explode('\n',$buffer);
758
-	    foreach ($buffer as $line) {
751
+		if ($globalDebug) echo 'download...';
752
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
753
+		if ($globalDebug) echo 'done !'."\n";
754
+		// FIXME: Need more work
755
+		if ($buffer != '') $reset = 0;
756
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
757
+		$buffer = explode('\n',$buffer);
758
+		foreach ($buffer as $line) {
759 759
 		if ($line != '') {
760
-		    $data = array();
761
-		    //echo $line."\n";
762
-		    $data['mmsi'] = (int)substr($line,0,9);
763
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
764
-		    $data['status_id'] = substr($line,21,2);
765
-		    $data['type_id'] = substr($line,24,3);
766
-		    $data['latitude'] = substr($line,29,9);
767
-		    $data['longitude'] = substr($line,41,9);
768
-		    $data['speed'] = round(substr($line,51,5));
769
-		    //$data['course'] = substr($line,57,5);
770
-		    $data['heading'] = round(substr($line,63,3));
771
-		    //$data['draft'] = substr($line,67,4);
772
-		    //$data['length'] = substr($line,72,3);
773
-		    //$data['beam'] = substr($line,76,2);
774
-		    $data['ident'] = trim(utf8_encode(substr($line,78,20)));
775
-		    //$data['callsign'] = trim(substr($line,100,7);
776
-		    $data['arrival_code'] = substr($line,108,20);
777
-		    //$data['etaDate'] = substr($line,129,5);
778
-		    //$data['etaTime'] = substr($line,135,5);
779
-		    $data['format_source'] = 'shipplotter';
780
-    		    $data['id_source'] = $id_source;
781
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
782
-		    //print_r($data);
783
-		    //echo 'Add...'."\n";
784
-		    $MI->add($data);
785
-		    unset($data);
760
+			$data = array();
761
+			//echo $line."\n";
762
+			$data['mmsi'] = (int)substr($line,0,9);
763
+			$data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
764
+			$data['status_id'] = substr($line,21,2);
765
+			$data['type_id'] = substr($line,24,3);
766
+			$data['latitude'] = substr($line,29,9);
767
+			$data['longitude'] = substr($line,41,9);
768
+			$data['speed'] = round(substr($line,51,5));
769
+			//$data['course'] = substr($line,57,5);
770
+			$data['heading'] = round(substr($line,63,3));
771
+			//$data['draft'] = substr($line,67,4);
772
+			//$data['length'] = substr($line,72,3);
773
+			//$data['beam'] = substr($line,76,2);
774
+			$data['ident'] = trim(utf8_encode(substr($line,78,20)));
775
+			//$data['callsign'] = trim(substr($line,100,7);
776
+			$data['arrival_code'] = substr($line,108,20);
777
+			//$data['etaDate'] = substr($line,129,5);
778
+			//$data['etaTime'] = substr($line,135,5);
779
+			$data['format_source'] = 'shipplotter';
780
+				$data['id_source'] = $id_source;
781
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
782
+			//print_r($data);
783
+			//echo 'Add...'."\n";
784
+			$MI->add($data);
785
+			unset($data);
786 786
 		}
787
-    	    }
788
-    	    $last_exec[$id]['last'] = time();
787
+			}
788
+			$last_exec[$id]['last'] = time();
789 789
 	} elseif ($value['format'] === 'sailawayfull' && 
790
-	    (
790
+		(
791 791
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > 5*60))
792
-	    )
792
+		)
793 793
 	) {
794
-	    if (isset($globalSailaway['email']) && $globalSailaway['email'] != '' && isset($globalSailaway['password']) && $globalSailaway['password'] != '') {
794
+		if (isset($globalSailaway['email']) && $globalSailaway['email'] != '' && isset($globalSailaway['password']) && $globalSailaway['password'] != '') {
795 795
 		$authsailaway = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/weblogin.pl','post',array('submitlogin' => 'Login','email' => $globalSailaway['email'],'pwd' => $globalSailaway['password'], 'page' => 'http://sailaway.world/cgi-bin/sailaway/missions.pl'),'','','','','',false,false,true);
796 796
 		//echo $authsailaway;
797 797
 		preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $authsailaway, $setcookie);
798 798
 		if (isset($setcookie[1][0])) {
799
-		    $sailaway_authcookie = $setcookie[1][0];
799
+			$sailaway_authcookie = $setcookie[1][0];
800
+		}
800 801
 		}
801
-	    }
802 802
 
803
-	    if ($globalDebug) echo '! Download... ';
804
-	    for ($i =0; $i <= 1; $i++) {
803
+		if ($globalDebug) echo '! Download... ';
804
+		for ($i =0; $i <= 1; $i++) {
805 805
 		if ($globalDebug) echo 'Racetype: '.$i.' ';
806 806
 		$buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/GetMissions.pl?race=1&tutorial=0&hist=1&racetype='.$i);
807
-	    if ($globalDebug) echo 'done'."\n";
808
-	    if ($buffer != '') {
807
+		if ($globalDebug) echo 'done'."\n";
808
+		if ($buffer != '') {
809 809
 		$all_data = json_decode($buffer,true);
810 810
 		if (isset($all_data['missions'])) {
811 811
 			foreach ($all_data['missions'] as $mission) {
@@ -826,19 +826,19 @@  discard block
 block discarded – undo
826 826
 					//print_r($race_data);
827 827
 					unset($racebuffer);
828 828
 					if (isset($race_data['mission'])) {
829
-					    $datar = array();
830
-					    $datar['id'] = $mission['misnr'];
831
-					    $datar['desc'] = $race_data['mission']['misdescr'];
832
-					    $datar['creator'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($race_data['mission']['usrname'])));
833
-					    $datar['name'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($race_data['mission']['mistitle'])));
834
-					    $datar['startdate'] = $race_data['mission']['misstartdatetime'];
835
-					    $markers = array();
836
-					    foreach ($race_data['mission']['course'] as $course) {
829
+						$datar = array();
830
+						$datar['id'] = $mission['misnr'];
831
+						$datar['desc'] = $race_data['mission']['misdescr'];
832
+						$datar['creator'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($race_data['mission']['usrname'])));
833
+						$datar['name'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($race_data['mission']['mistitle'])));
834
+						$datar['startdate'] = $race_data['mission']['misstartdatetime'];
835
+						$markers = array();
836
+						foreach ($race_data['mission']['course'] as $course) {
837 837
 						$markers[] = array('lat' => $course['miclat'],'lon' => $course['miclon'],'name' => $course['micname'],'type' => $course['mictype']);
838
-					    }
839
-					    $datar['markers'] = json_encode($markers);
840
-					    //print_r($datar);
841
-					    $MI->race_add($datar);
838
+						}
839
+						$datar['markers'] = json_encode($markers);
840
+						//print_r($datar);
841
+						$MI->race_add($datar);
842 842
 					}
843 843
 				}
844 844
 				if ($bufferm != '') {
@@ -903,16 +903,16 @@  discard block
 block discarded – undo
903 903
 				sleep(30);
904 904
 			}
905 905
 		}
906
-	    }
907
-	    sleep(5);
908
-	    }
909
-    	    $last_exec[$id]['last'] = time();
906
+		}
907
+		sleep(5);
908
+		}
909
+			$last_exec[$id]['last'] = time();
910 910
 	} elseif ($value['format'] === 'sailaway' && 
911
-	    (
911
+		(
912 912
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > 5*60))
913
-	    )
913
+		)
914 914
 	) {
915
-	    /*
915
+		/*
916 916
 	    if (isset($globalSailaway['email']) && $globalSailaway['email'] != '' && isset($globalSailaway['password']) && $globalSailaway['password'] != '') {
917 917
 		$authsailaway = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/weblogin.pl','post',array('submitlogin' => 'Login','email' => $globalSailaway['email'],'pwd' => $globalSailaway['password'], 'page' => 'http://sailaway.world/cgi-bin/sailaway/missions.pl'),'','','','','',false,false,true);
918 918
 		//echo $authsailaway;
@@ -923,20 +923,20 @@  discard block
 block discarded – undo
923 923
 		}
924 924
 	    }
925 925
 	    */
926
-	    if (!isset($globalSailaway['key']) || $globalSailaway['key'] == '') {
926
+		if (!isset($globalSailaway['key']) || $globalSailaway['key'] == '') {
927 927
 		echo 'Sailaway API key MUST be defined';
928 928
 		exit(0);
929
-	    }
930
-	    if ($globalDebug) echo '! Download... ';
931
-	    $sailawayoption = array('key' => $globalSailaway['key']);
932
-	    if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
933
-	    if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
934
-	    $buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption),'get','','','','',30);
935
-	    if ($buffer != '') {
929
+		}
930
+		if ($globalDebug) echo '! Download... ';
931
+		$sailawayoption = array('key' => $globalSailaway['key']);
932
+		if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
933
+		if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
934
+		$buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption),'get','','','','',30);
935
+		if ($buffer != '') {
936 936
 		$data = json_decode($buffer,true);
937 937
 		//print_r($data);
938 938
 		if (isset($data['boats'])) {
939
-		    foreach ($data['boats'] as $sail) {
939
+			foreach ($data['boats'] as $sail) {
940 940
 			$data = array();
941 941
 			$data['id'] = $sail['ubtnr'];
942 942
 			$data['datetime'] = date('Y-m-d H:i:s');
@@ -956,35 +956,35 @@  discard block
 block discarded – undo
956 956
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
957 957
 			$MI->add($data);
958 958
 			unset($data);
959
-		    }
959
+			}
960 960
 		} elseif ($globalDebug) echo 'Error in JSON parsing';
961
-	    } elseif ($globalDebug) echo 'Empty result !'."\n";
962
-    	    $last_exec[$id]['last'] = time();
961
+		} elseif ($globalDebug) echo 'Empty result !'."\n";
962
+			$last_exec[$id]['last'] = time();
963 963
 	//} elseif (($value === 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value === 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
964 964
 	} elseif (
965
-	    (
965
+		(
966 966
 		$value['format'] === 'whazzup' && 
967 967
 		(
968
-		    (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
969
-		    (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
968
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
969
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
970 970
 		)
971
-	    ) || (
971
+		) || (
972 972
 		$value['format'] === 'vatsimtxt' && 
973 973
 		(
974
-		    (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
975
-		    (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
974
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
975
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
976
+		)
976 977
 		)
977
-	    )
978 978
 	) {
979
-	    //$buffer = $Common->getData($hosts[$id]);
980
-	    $buffer = $Common->getData($value['host']);
981
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
982
-	    $buffer = explode('\n',$buffer);
983
-	    $reset = 0;
984
-	    foreach ($buffer as $line) {
985
-    		if ($line != '') {
986
-    		    $line = explode(':', $line);
987
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
979
+		//$buffer = $Common->getData($hosts[$id]);
980
+		$buffer = $Common->getData($value['host']);
981
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
982
+		$buffer = explode('\n',$buffer);
983
+		$reset = 0;
984
+		foreach ($buffer as $line) {
985
+			if ($line != '') {
986
+				$line = explode(':', $line);
987
+				if (count($line) > 30 && $line[0] != 'callsign') {
988 988
 			$data = array();
989 989
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
990 990
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -997,37 +997,37 @@  discard block
 block discarded – undo
997 997
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
998 998
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
999 999
 			$data['latitude'] = $line[5]; // lat
1000
-	        	$data['longitude'] = $line[6]; // long
1001
-	        	$data['verticalrate'] = ''; // vertical rate
1002
-	        	$data['squawk'] = ''; // squawk
1003
-	        	$data['emergency'] = ''; // emergency
1004
-	        	$data['waypoints'] = $line[30];
1000
+				$data['longitude'] = $line[6]; // long
1001
+				$data['verticalrate'] = ''; // vertical rate
1002
+				$data['squawk'] = ''; // squawk
1003
+				$data['emergency'] = ''; // emergency
1004
+				$data['waypoints'] = $line[30];
1005 1005
 			$data['datetime'] = date('Y-m-d H:i:s');
1006 1006
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
1007 1007
 			//if (isset($line[37])) $data['last_update'] = $line[37];
1008
-		        $data['departure_airport_icao'] = $line[11];
1009
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
1010
-		        $data['arrival_airport_icao'] = $line[13];
1008
+				$data['departure_airport_icao'] = $line[11];
1009
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
1010
+				$data['arrival_airport_icao'] = $line[13];
1011 1011
 			$data['frequency'] = $line[4];
1012 1012
 			$data['type'] = $line[18];
1013 1013
 			$data['range'] = $line[19];
1014 1014
 			if (isset($line[35])) $data['info'] = $line[35];
1015
-    			$data['id_source'] = $id_source;
1016
-	    		//$data['arrival_airport_time'] = ;
1017
-	    		if ($line[9] != '') {
1018
-	    		    $aircraft_data = explode('/',$line[9]);
1019
-	    		    if (isset($aircraft_data[1])) {
1020
-	    			$data['aircraft_icao'] = $aircraft_data[1];
1021
-	    		    }
1022
-        		}
1023
-	    		/*
1015
+				$data['id_source'] = $id_source;
1016
+				//$data['arrival_airport_time'] = ;
1017
+				if ($line[9] != '') {
1018
+					$aircraft_data = explode('/',$line[9]);
1019
+					if (isset($aircraft_data[1])) {
1020
+					$data['aircraft_icao'] = $aircraft_data[1];
1021
+					}
1022
+				}
1023
+				/*
1024 1024
 	    		if ($value === 'whazzup') $data['format_source'] = 'whazzup';
1025 1025
 	    		elseif ($value === 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
1026 1026
 	    		*/
1027
-	    		$data['format_source'] = $value['format'];
1027
+				$data['format_source'] = $value['format'];
1028 1028
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1029 1029
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1030
-    			if ($line[3] === 'PILOT') $SI->add($data);
1030
+				if ($line[3] === 'PILOT') $SI->add($data);
1031 1031
 			elseif ($line[3] === 'ATC') {
1032 1032
 				//print_r($data);
1033 1033
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -1048,21 +1048,21 @@  discard block
 block discarded – undo
1048 1048
 					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']);
1049 1049
 				}
1050 1050
 			}
1051
-    			unset($data);
1052
-    		    }
1053
-    		}
1054
-    	    }
1055
-    	    //if ($value === 'whazzup') $last_exec['whazzup'] = time();
1056
-    	    //elseif ($value === 'vatsimtxt') $last_exec['vatsimtxt'] = time();
1057
-    	    $last_exec[$id]['last'] = time();
1058
-    	} elseif ($value['format'] === 'airwhere' && 
1059
-    	    (
1060
-    		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1061
-    		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1062
-    	    )
1063
-    	) {
1064
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
1065
-	    if ($buffer != '') {
1051
+				unset($data);
1052
+				}
1053
+			}
1054
+			}
1055
+			//if ($value === 'whazzup') $last_exec['whazzup'] = time();
1056
+			//elseif ($value === 'vatsimtxt') $last_exec['vatsimtxt'] = time();
1057
+			$last_exec[$id]['last'] = time();
1058
+		} elseif ($value['format'] === 'airwhere' && 
1059
+			(
1060
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1061
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1062
+			)
1063
+		) {
1064
+		$buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
1065
+		if ($buffer != '') {
1066 1066
 		$all_data = simplexml_load_string($buffer);
1067 1067
 		foreach($all_data->children() as $childdata) {
1068 1068
 			$data = array();
@@ -1084,10 +1084,10 @@  discard block
 block discarded – undo
1084 1084
 			$SI->add($data);
1085 1085
 			unset($data);
1086 1086
 		}
1087
-	    }
1088
-	    $Source->deleteOldLocationByType('gs');
1089
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
1090
-	    if ($buffer != '') {
1087
+		}
1088
+		$Source->deleteOldLocationByType('gs');
1089
+		$buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
1090
+		if ($buffer != '') {
1091 1091
 		$all_data = simplexml_load_string($buffer);
1092 1092
 		foreach($all_data->children() as $childdata) {
1093 1093
 			$data = array();
@@ -1105,8 +1105,8 @@  discard block
 block discarded – undo
1105 1105
 			}
1106 1106
 			unset($data);
1107 1107
 		}
1108
-	    }
1109
-	    $last_exec[$id]['last'] = time();
1108
+		}
1109
+		$last_exec[$id]['last'] = time();
1110 1110
 	/*
1111 1111
 	} if ($value['format'] === 'aircraftlistjson') {
1112 1112
 	    print_r($globalSources);
@@ -1114,17 +1114,17 @@  discard block
 block discarded – undo
1114 1114
 	    echo $globalMinFetch;
1115 1115
 	*/
1116 1116
 	} elseif ($value['format'] === 'aircraftlistjson' && 
1117
-	    (
1117
+		(
1118 1118
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1119 1119
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1120
-	    )
1120
+		)
1121 1121
 	) {
1122
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
1123
-	    if ($buffer != '') {
1124
-	        $all_data = json_decode($buffer,true);
1122
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
1123
+		if ($buffer != '') {
1124
+			$all_data = json_decode($buffer,true);
1125 1125
 		if (isset($all_data['acList'])) {
1126
-		    $reset = 0;
1127
-		    foreach ($all_data['acList'] as $line) {
1126
+			$reset = 0;
1127
+			foreach ($all_data['acList'] as $line) {
1128 1128
 			$data = array();
1129 1129
 			$data['hex'] = $line['Icao']; // hex
1130 1130
 			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1147,10 +1147,10 @@  discard block
 block discarded – undo
1147 1147
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1148 1148
 			if (isset($data['latitude'])) $SI->add($data);
1149 1149
 			unset($data);
1150
-		    }
1150
+			}
1151 1151
 		} elseif (is_array($all_data)) {
1152
-		    $reset = 0;
1153
-		    foreach ($all_data as $line) {
1152
+			$reset = 0;
1153
+			foreach ($all_data as $line) {
1154 1154
 			$data = array();
1155 1155
 			$data['hex'] = $line['hex']; // hex
1156 1156
 			$data['ident'] = $line['flight']; // ident
@@ -1170,291 +1170,291 @@  discard block
 block discarded – undo
1170 1170
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1171 1171
 			$SI->add($data);
1172 1172
 			unset($data);
1173
-		    }
1173
+			}
1174 1174
 		}
1175
-	    } elseif ($globalDebug) echo 'No data'."\n";
1176
-    	    //$last_exec['aircraftlistjson'] = time();
1177
-    	    $last_exec[$id]['last'] = time();
1178
-    	//} elseif ($value === 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
1179
-    	} elseif ($value['format'] === 'planeupdatefaa' && 
1180
-    	    (
1181
-    		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1182
-    		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1183
-    	    )
1184
-    	) {
1185
-	    $buffer = $Common->getData($value['host']);
1186
-	    $all_data = json_decode($buffer,true);
1187
-	    if (isset($all_data['planes'])) {
1175
+		} elseif ($globalDebug) echo 'No data'."\n";
1176
+			//$last_exec['aircraftlistjson'] = time();
1177
+			$last_exec[$id]['last'] = time();
1178
+		//} elseif ($value === 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
1179
+		} elseif ($value['format'] === 'planeupdatefaa' && 
1180
+			(
1181
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1182
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1183
+			)
1184
+		) {
1185
+		$buffer = $Common->getData($value['host']);
1186
+		$all_data = json_decode($buffer,true);
1187
+		if (isset($all_data['planes'])) {
1188 1188
 		$reset = 0;
1189 1189
 		foreach ($all_data['planes'] as $key => $line) {
1190
-		    $data = array();
1191
-		    $data['hex'] = $key; // hex
1192
-		    $data['ident'] = $line[3]; // ident
1193
-		    $data['altitude'] = $line[6]; // altitude
1194
-		    $data['speed'] = $line[8]; // speed
1195
-		    $data['heading'] = $line[7]; // heading
1196
-		    $data['latitude'] = $line[4]; // lat
1197
-		    $data['longitude'] = $line[5]; // long
1198
-		    //$data['verticalrate'] = $line[]; // verticale rate
1199
-		    $data['squawk'] = $line[10]; // squawk
1200
-		    $data['emergency'] = ''; // emergency
1201
-		    $data['registration'] = $line[2];
1202
-		    $data['aircraft_icao'] = $line[0];
1203
-		    $deparr = explode('-',$line[1]);
1204
-		    if (count($deparr) === 2) {
1190
+			$data = array();
1191
+			$data['hex'] = $key; // hex
1192
+			$data['ident'] = $line[3]; // ident
1193
+			$data['altitude'] = $line[6]; // altitude
1194
+			$data['speed'] = $line[8]; // speed
1195
+			$data['heading'] = $line[7]; // heading
1196
+			$data['latitude'] = $line[4]; // lat
1197
+			$data['longitude'] = $line[5]; // long
1198
+			//$data['verticalrate'] = $line[]; // verticale rate
1199
+			$data['squawk'] = $line[10]; // squawk
1200
+			$data['emergency'] = ''; // emergency
1201
+			$data['registration'] = $line[2];
1202
+			$data['aircraft_icao'] = $line[0];
1203
+			$deparr = explode('-',$line[1]);
1204
+			if (count($deparr) === 2) {
1205 1205
 			$data['departure_airport_icao'] = $deparr[0];
1206 1206
 			$data['arrival_airport_icao'] = $deparr[1];
1207
-		    }
1208
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
1209
-	    	    $data['format_source'] = 'planeupdatefaa';
1210
-    		    $data['id_source'] = $id_source;
1211
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1212
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1213
-		    $SI->add($data);
1214
-		    unset($data);
1207
+			}
1208
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
1209
+				$data['format_source'] = 'planeupdatefaa';
1210
+				$data['id_source'] = $id_source;
1211
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1212
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1213
+			$SI->add($data);
1214
+			unset($data);
1215 1215
 		}
1216
-	    }
1217
-	    //$last_exec['planeupdatefaa'] = time();
1218
-	    $last_exec[$id]['last'] = time();
1216
+		}
1217
+		//$last_exec['planeupdatefaa'] = time();
1218
+		$last_exec[$id]['last'] = time();
1219 1219
 	} elseif ($value['format'] === 'opensky' && 
1220
-	    (
1220
+		(
1221 1221
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1222 1222
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1223
-	    )
1223
+		)
1224 1224
 	) {
1225
-	    $buffer = $Common->getData($value['host']);
1226
-	    $all_data = json_decode($buffer,true);
1227
-	    if (isset($all_data['states'])) {
1225
+		$buffer = $Common->getData($value['host']);
1226
+		$all_data = json_decode($buffer,true);
1227
+		if (isset($all_data['states'])) {
1228 1228
 		$reset = 0;
1229 1229
 		foreach ($all_data['states'] as $key => $line) {
1230
-		    $data = array();
1231
-		    $data['hex'] = $line[0]; // hex
1232
-		    $data['ident'] = trim($line[1]); // ident
1233
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
1234
-		    $data['speed'] = round($line[9]*1.94384); // speed
1235
-		    $data['heading'] = round($line[10]); // heading
1236
-		    $data['latitude'] = $line[6]; // lat
1237
-		    $data['longitude'] = $line[5]; // long
1238
-		    $data['verticalrate'] = $line[11]; // verticale rate
1239
-		    //$data['squawk'] = $line[10]; // squawk
1240
-		    //$data['emergency'] = ''; // emergency
1241
-		    //$data['registration'] = $line[2];
1242
-		    //$data['aircraft_icao'] = $line[0];
1243
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1244
-		    $data['format_source'] = 'opensky';
1245
-		    $data['id_source'] = $id_source;
1246
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1247
-		    $SI->add($data);
1248
-		    unset($data);
1230
+			$data = array();
1231
+			$data['hex'] = $line[0]; // hex
1232
+			$data['ident'] = trim($line[1]); // ident
1233
+			$data['altitude'] = round($line[7]*3.28084); // altitude
1234
+			$data['speed'] = round($line[9]*1.94384); // speed
1235
+			$data['heading'] = round($line[10]); // heading
1236
+			$data['latitude'] = $line[6]; // lat
1237
+			$data['longitude'] = $line[5]; // long
1238
+			$data['verticalrate'] = $line[11]; // verticale rate
1239
+			//$data['squawk'] = $line[10]; // squawk
1240
+			//$data['emergency'] = ''; // emergency
1241
+			//$data['registration'] = $line[2];
1242
+			//$data['aircraft_icao'] = $line[0];
1243
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1244
+			$data['format_source'] = 'opensky';
1245
+			$data['id_source'] = $id_source;
1246
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1247
+			$SI->add($data);
1248
+			unset($data);
1249 1249
 		}
1250
-	    }
1251
-	    //$last_exec['planeupdatefaa'] = time();
1252
-	    $last_exec[$id]['last'] = time();
1250
+		}
1251
+		//$last_exec['planeupdatefaa'] = time();
1252
+		$last_exec[$id]['last'] = time();
1253 1253
 	} elseif ($value['format'] === 'aircraftjson' && 
1254
-	    (
1254
+		(
1255 1255
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1256 1256
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1257
-	    )
1257
+		)
1258 1258
 	) {
1259
-	    $buffer = $Common->getData($value['host']);
1260
-	    $all_data = json_decode($buffer,true);
1261
-	    if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time()-1800) {
1259
+		$buffer = $Common->getData($value['host']);
1260
+		$all_data = json_decode($buffer,true);
1261
+		if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time()-1800) {
1262 1262
 		$reset = 0;
1263 1263
 		foreach ($all_data['aircraft'] as $key => $line) {
1264
-		    $data = array();
1265
-		    // add support for ground vehicule with ~ in front of hex
1266
-		    if (isset($line['hex'])) $data['hex'] = $line['hex']; // hex
1267
-		    if (isset($line['flight'])) $data['ident'] = trim($line['flight']); // ident
1268
-		    if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1269
-		    if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1270
-		    if (isset($line['track'])) $data['heading'] = $line['track']; // heading
1271
-		    if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1272
-		    if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1273
-		    if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1274
-		    if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1275
-		    //$data['emergency'] = ''; // emergency
1276
-		    //$data['registration'] = $line[2];
1277
-		    //$data['aircraft_icao'] = $line[0];
1278
-		    $data['datetime'] = date('Y-m-d H:i:s');
1279
-		    $data['format_source'] = 'aircraftjson';
1280
-		    $data['id_source'] = $id_source;
1281
-		    if (isset($value['name']) && $value['name'] != '') {
1282
-			    if (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = $value['name'].'_MLAT';
1283
-			    else $data['source_name'] = $value['name'];
1284
-		    } elseif (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = 'MLAT';
1285
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1286
-		    $SI->add($data);
1287
-		    unset($data);
1264
+			$data = array();
1265
+			// add support for ground vehicule with ~ in front of hex
1266
+			if (isset($line['hex'])) $data['hex'] = $line['hex']; // hex
1267
+			if (isset($line['flight'])) $data['ident'] = trim($line['flight']); // ident
1268
+			if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1269
+			if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1270
+			if (isset($line['track'])) $data['heading'] = $line['track']; // heading
1271
+			if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1272
+			if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1273
+			if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1274
+			if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1275
+			//$data['emergency'] = ''; // emergency
1276
+			//$data['registration'] = $line[2];
1277
+			//$data['aircraft_icao'] = $line[0];
1278
+			$data['datetime'] = date('Y-m-d H:i:s');
1279
+			$data['format_source'] = 'aircraftjson';
1280
+			$data['id_source'] = $id_source;
1281
+			if (isset($value['name']) && $value['name'] != '') {
1282
+				if (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = $value['name'].'_MLAT';
1283
+				else $data['source_name'] = $value['name'];
1284
+			} elseif (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = 'MLAT';
1285
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1286
+			$SI->add($data);
1287
+			unset($data);
1288 1288
 		}
1289
-	    }
1290
-	    //$last_exec['planeupdatefaa'] = time();
1291
-	    $last_exec[$id]['last'] = time();
1289
+		}
1290
+		//$last_exec['planeupdatefaa'] = time();
1291
+		$last_exec[$id]['last'] = time();
1292 1292
 	} elseif ($value['format'] === 'planefinderclient' && 
1293
-	    (
1293
+		(
1294 1294
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1295 1295
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1296
-	    )
1296
+		)
1297 1297
 	) {
1298
-	    $buffer = $Common->getData($value['host']);
1299
-	    $all_data = json_decode($buffer,true);
1300
-	    if (isset($all_data['aircraft'])) {
1298
+		$buffer = $Common->getData($value['host']);
1299
+		$all_data = json_decode($buffer,true);
1300
+		if (isset($all_data['aircraft'])) {
1301 1301
 		$reset = 0;
1302 1302
 		foreach ($all_data['aircraft'] as $key => $line) {
1303
-		    $data = array();
1304
-		    $data['hex'] = $key; // hex
1305
-		    if (isset($line['callsign'])) $data['ident'] = trim($line['callsign']); // ident
1306
-		    if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1307
-		    if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1308
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1309
-		    if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1310
-		    if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1311
-		    if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1312
-		    if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1313
-		    //$data['emergency'] = ''; // emergency
1314
-		    if (isset($line['reg'])) $data['registration'] = $line['reg'];
1315
-		    if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1316
-		    $data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1317
-		    $data['format_source'] = 'planefinderclient';
1318
-		    $data['id_source'] = $id_source;
1319
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1320
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1321
-		    $SI->add($data);
1322
-		    unset($data);
1303
+			$data = array();
1304
+			$data['hex'] = $key; // hex
1305
+			if (isset($line['callsign'])) $data['ident'] = trim($line['callsign']); // ident
1306
+			if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1307
+			if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1308
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1309
+			if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1310
+			if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1311
+			if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1312
+			if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1313
+			//$data['emergency'] = ''; // emergency
1314
+			if (isset($line['reg'])) $data['registration'] = $line['reg'];
1315
+			if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1316
+			$data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1317
+			$data['format_source'] = 'planefinderclient';
1318
+			$data['id_source'] = $id_source;
1319
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1320
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1321
+			$SI->add($data);
1322
+			unset($data);
1323 1323
 		}
1324
-	    }
1325
-	    $last_exec[$id]['last'] = time();
1324
+		}
1325
+		$last_exec[$id]['last'] = time();
1326 1326
 	//} elseif ($value === 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
1327 1327
 	} elseif ($value['format'] === 'fr24json' && 
1328
-	    (
1328
+		(
1329 1329
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1330 1330
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1331
-	    )
1331
+		)
1332 1332
 	) {
1333
-	    //$buffer = $Common->getData($hosts[$id]);
1334
-	    $buffer = $Common->getData($value['host']);
1335
-	    $all_data = json_decode($buffer,true);
1336
-	    if (!empty($all_data)) $reset = 0;
1337
-	    foreach ($all_data as $key => $line) {
1333
+		//$buffer = $Common->getData($hosts[$id]);
1334
+		$buffer = $Common->getData($value['host']);
1335
+		$all_data = json_decode($buffer,true);
1336
+		if (!empty($all_data)) $reset = 0;
1337
+		foreach ($all_data as $key => $line) {
1338 1338
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
1339
-		    $data = array();
1340
-		    $data['hex'] = $line[0];
1341
-		    $data['ident'] = $line[16]; //$line[13]
1342
-	    	    $data['altitude'] = $line[4]; // altitude
1343
-	    	    $data['speed'] = $line[5]; // speed
1344
-	    	    $data['heading'] = $line[3]; // heading
1345
-	    	    $data['latitude'] = $line[1]; // lat
1346
-	    	    $data['longitude'] = $line[2]; // long
1347
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
1348
-	    	    $data['squawk'] = $line[6]; // squawk
1349
-	    	    $data['aircraft_icao'] = $line[8];
1350
-	    	    $data['registration'] = $line[9];
1351
-		    $data['departure_airport_iata'] = $line[11];
1352
-		    $data['arrival_airport_iata'] = $line[12];
1353
-	    	    $data['emergency'] = ''; // emergency
1354
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1355
-	    	    $data['format_source'] = 'fr24json';
1356
-    		    $data['id_source'] = $id_source;
1357
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1358
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1359
-		    $SI->add($data);
1360
-		    unset($data);
1339
+			$data = array();
1340
+			$data['hex'] = $line[0];
1341
+			$data['ident'] = $line[16]; //$line[13]
1342
+				$data['altitude'] = $line[4]; // altitude
1343
+				$data['speed'] = $line[5]; // speed
1344
+				$data['heading'] = $line[3]; // heading
1345
+				$data['latitude'] = $line[1]; // lat
1346
+				$data['longitude'] = $line[2]; // long
1347
+				$data['verticalrate'] = $line[15]; // verticale rate
1348
+				$data['squawk'] = $line[6]; // squawk
1349
+				$data['aircraft_icao'] = $line[8];
1350
+				$data['registration'] = $line[9];
1351
+			$data['departure_airport_iata'] = $line[11];
1352
+			$data['arrival_airport_iata'] = $line[12];
1353
+				$data['emergency'] = ''; // emergency
1354
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1355
+				$data['format_source'] = 'fr24json';
1356
+				$data['id_source'] = $id_source;
1357
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1358
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1359
+			$SI->add($data);
1360
+			unset($data);
1361 1361
 		}
1362
-	    }
1363
-	    //$last_exec['fr24json'] = time();
1364
-	    $last_exec[$id]['last'] = time();
1362
+		}
1363
+		//$last_exec['fr24json'] = time();
1364
+		$last_exec[$id]['last'] = time();
1365 1365
 	//} elseif ($value === 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
1366 1366
 	} elseif ($value['format'] === 'radarvirtueljson' && 
1367
-	    (
1367
+		(
1368 1368
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1369 1369
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1370
-	    )
1370
+		)
1371 1371
 	) {
1372
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1373
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
1374
-	    //echo $buffer;
1375
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
1376
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1377
-	    $all_data = json_decode($buffer,true);
1378
-	    if (json_last_error() != JSON_ERROR_NONE) {
1372
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1373
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
1374
+		//echo $buffer;
1375
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
1376
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1377
+		$all_data = json_decode($buffer,true);
1378
+		if (json_last_error() != JSON_ERROR_NONE) {
1379 1379
 		die(json_last_error_msg());
1380
-	    }
1381
-	    if (isset($all_data['mrkrs'])) {
1380
+		}
1381
+		if (isset($all_data['mrkrs'])) {
1382 1382
 		$reset = 0;
1383 1383
 		foreach ($all_data['mrkrs'] as $key => $line) {
1384
-		    if (isset($line['inf'])) {
1384
+			if (isset($line['inf'])) {
1385 1385
 			$data = array();
1386 1386
 			$data['hex'] = $line['inf']['ia'];
1387 1387
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1388
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1389
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1390
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1391
-	    		$data['latitude'] = $line['pt'][0]; // lat
1392
-	    		$data['longitude'] = $line['pt'][1]; // long
1393
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1394
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1395
-	    		//$data['aircraft_icao'] = $line[8];
1396
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1388
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1389
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1390
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1391
+				$data['latitude'] = $line['pt'][0]; // lat
1392
+				$data['longitude'] = $line['pt'][1]; // long
1393
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1394
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1395
+				//$data['aircraft_icao'] = $line[8];
1396
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1397 1397
 			//$data['departure_airport_iata'] = $line[11];
1398 1398
 			//$data['arrival_airport_iata'] = $line[12];
1399
-	    		//$data['emergency'] = ''; // emergency
1399
+				//$data['emergency'] = ''; // emergency
1400 1400
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1401
-	    		$data['format_source'] = 'radarvirtueljson';
1402
-    			$data['id_source'] = $id_source;
1401
+				$data['format_source'] = 'radarvirtueljson';
1402
+				$data['id_source'] = $id_source;
1403 1403
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1404 1404
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1405 1405
 			$SI->add($data);
1406 1406
 			unset($data);
1407
-		    }
1407
+			}
1408 1408
 		}
1409
-	    }
1410
-	    //$last_exec['radarvirtueljson'] = time();
1411
-	    $last_exec[$id]['last'] = time();
1409
+		}
1410
+		//$last_exec['radarvirtueljson'] = time();
1411
+		$last_exec[$id]['last'] = time();
1412 1412
 	//} elseif ($value === 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
1413 1413
 	} elseif ($value['format'] === 'pirepsjson' && 
1414
-	    (
1414
+		(
1415 1415
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1416 1416
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1417
-	    )
1417
+		)
1418 1418
 	) {
1419
-	    //$buffer = $Common->getData($hosts[$id]);
1420
-	    $buffer = $Common->getData($value['host'].'?'.time());
1421
-	    $all_data = json_decode(utf8_encode($buffer),true);
1419
+		//$buffer = $Common->getData($hosts[$id]);
1420
+		$buffer = $Common->getData($value['host'].'?'.time());
1421
+		$all_data = json_decode(utf8_encode($buffer),true);
1422 1422
 	    
1423
-	    if (isset($all_data['pireps'])) {
1423
+		if (isset($all_data['pireps'])) {
1424 1424
 		$reset = 0;
1425
-	        foreach ($all_data['pireps'] as $line) {
1426
-		    $data = array();
1427
-		    $data['id'] = $line['id'];
1428
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1429
-		    $data['ident'] = $line['callsign']; // ident
1430
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1431
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1432
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1433
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1434
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1435
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1436
-		    $data['latitude'] = $line['lat']; // lat
1437
-		    $data['longitude'] = $line['lon']; // long
1438
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
1439
-		    //$data['squawk'] = $line['squawk']; // squawk
1440
-		    //$data['emergency'] = ''; // emergency
1441
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1442
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1443
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1444
-		    //$data['arrival_airport_time'] = $line['arrtime'];
1445
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1446
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1447
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
1448
-		    else $data['info'] = '';
1449
-		    $data['format_source'] = 'pireps';
1450
-    		    $data['id_source'] = $id_source;
1451
-		    $data['datetime'] = date('Y-m-d H:i:s');
1452
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1453
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1454
-		    if ($line['icon'] === 'plane') {
1425
+			foreach ($all_data['pireps'] as $line) {
1426
+			$data = array();
1427
+			$data['id'] = $line['id'];
1428
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1429
+			$data['ident'] = $line['callsign']; // ident
1430
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1431
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1432
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1433
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1434
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1435
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1436
+			$data['latitude'] = $line['lat']; // lat
1437
+			$data['longitude'] = $line['lon']; // long
1438
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
1439
+			//$data['squawk'] = $line['squawk']; // squawk
1440
+			//$data['emergency'] = ''; // emergency
1441
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1442
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1443
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1444
+			//$data['arrival_airport_time'] = $line['arrtime'];
1445
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1446
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1447
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
1448
+			else $data['info'] = '';
1449
+			$data['format_source'] = 'pireps';
1450
+				$data['id_source'] = $id_source;
1451
+			$data['datetime'] = date('Y-m-d H:i:s');
1452
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1453
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1454
+			if ($line['icon'] === 'plane') {
1455 1455
 			$SI->add($data);
1456
-		    //    print_r($data);
1457
-    		    } elseif ($line['icon'] === 'ct') {
1456
+			//    print_r($data);
1457
+				} elseif ($line['icon'] === 'ct') {
1458 1458
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1459 1459
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1460 1460
 			$typec = substr($data['ident'],-3);
@@ -1469,209 +1469,209 @@  discard block
 block discarded – undo
1469 1469
 			elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
1470 1470
 			else $data['type'] = 'Observer';
1471 1471
 			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']);
1472
-		    }
1473
-		    unset($data);
1472
+			}
1473
+			unset($data);
1474 1474
 		}
1475
-	    }
1476
-	    //$last_exec['pirepsjson'] = time();
1477
-	    $last_exec[$id]['last'] = time();
1475
+		}
1476
+		//$last_exec['pirepsjson'] = time();
1477
+		$last_exec[$id]['last'] = time();
1478 1478
 	//} elseif ($value === 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
1479 1479
 	} elseif ($value['format'] === 'phpvmacars' && 
1480
-	    (
1480
+		(
1481 1481
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1482 1482
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1483
-	    )
1483
+		)
1484 1484
 	) {
1485
-	    //$buffer = $Common->getData($hosts[$id]);
1486
-	    if ($globalDebug) echo 'Get Data...'."\n";
1487
-	    $buffer = $Common->getData($value['host']);
1488
-	    $all_data = json_decode($buffer,true);
1489
-	    if ($buffer != '' && is_array($all_data)) {
1485
+		//$buffer = $Common->getData($hosts[$id]);
1486
+		if ($globalDebug) echo 'Get Data...'."\n";
1487
+		$buffer = $Common->getData($value['host']);
1488
+		$all_data = json_decode($buffer,true);
1489
+		if ($buffer != '' && is_array($all_data)) {
1490 1490
 		$reset = 0;
1491 1491
 		foreach ($all_data as $line) {
1492
-	    	    $data = array();
1493
-	    	    //$data['id'] = $line['id']; // id not usable
1494
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1495
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1496
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1497
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1498
-	    	    $data['ident'] = $line['flightnum']; // ident
1499
-	    	    $data['altitude'] = $line['alt']; // altitude
1500
-	    	    $data['speed'] = $line['gs']; // speed
1501
-	    	    $data['heading'] = $line['heading']; // heading
1502
-	    	    $data['latitude'] = $line['lat']; // lat
1503
-	    	    $data['longitude'] = $line['lng']; // long
1504
-	    	    $data['verticalrate'] = ''; // verticale rate
1505
-	    	    $data['squawk'] = ''; // squawk
1506
-	    	    $data['emergency'] = ''; // emergency
1507
-	    	    //$data['datetime'] = $line['lastupdate'];
1508
-	    	    //$data['last_update'] = $line['lastupdate'];
1509
-	    	    if (isset($value['timezone'])) {
1510
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1511
-	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1512
-	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1513
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1514
-	    	    $data['departure_airport_icao'] = $line['depicao'];
1515
-	    	    $data['departure_airport_time'] = $line['deptime'];
1516
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
1517
-    		    $data['arrival_airport_time'] = $line['arrtime'];
1518
-    		    if (isset($line['registration'])) {
1519
-    			$data['registration'] = $line['registration'];
1520
-    			//if (isset($line['aircraft'])) $data['id'] = $line['aircraft'];
1521
-    		    } else $data['registration'] = $line['aircraft'];
1522
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1523
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1524
-		    if (isset($line['aircraftname'])) {
1492
+				$data = array();
1493
+				//$data['id'] = $line['id']; // id not usable
1494
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1495
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1496
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1497
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1498
+				$data['ident'] = $line['flightnum']; // ident
1499
+				$data['altitude'] = $line['alt']; // altitude
1500
+				$data['speed'] = $line['gs']; // speed
1501
+				$data['heading'] = $line['heading']; // heading
1502
+				$data['latitude'] = $line['lat']; // lat
1503
+				$data['longitude'] = $line['lng']; // long
1504
+				$data['verticalrate'] = ''; // verticale rate
1505
+				$data['squawk'] = ''; // squawk
1506
+				$data['emergency'] = ''; // emergency
1507
+				//$data['datetime'] = $line['lastupdate'];
1508
+				//$data['last_update'] = $line['lastupdate'];
1509
+				if (isset($value['timezone'])) {
1510
+				$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1511
+				$datetime->setTimeZone(new DateTimeZone('UTC'));
1512
+				$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1513
+				} else $data['datetime'] = date('Y-m-d H:i:s');
1514
+				$data['departure_airport_icao'] = $line['depicao'];
1515
+				$data['departure_airport_time'] = $line['deptime'];
1516
+				$data['arrival_airport_icao'] = $line['arricao'];
1517
+				$data['arrival_airport_time'] = $line['arrtime'];
1518
+				if (isset($line['registration'])) {
1519
+				$data['registration'] = $line['registration'];
1520
+				//if (isset($line['aircraft'])) $data['id'] = $line['aircraft'];
1521
+				} else $data['registration'] = $line['aircraft'];
1522
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1523
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1524
+			if (isset($line['aircraftname'])) {
1525 1525
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1526 1526
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1527
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1528
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1529
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1530
-	    		else {
1531
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1532
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1533
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1534
-	    		}
1535
-	    	    }
1536
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1537
-    		    $data['id_source'] = $id_source;
1538
-	    	    $data['format_source'] = 'phpvmacars';
1539
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1540
-		    $SI->add($data);
1541
-		    unset($data);
1527
+				$aircraft_data = explode('-',$line['aircraftname']);
1528
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1529
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1530
+				else {
1531
+					$aircraft_data = explode(' ',$line['aircraftname']);
1532
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1533
+					else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1534
+				}
1535
+				}
1536
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
1537
+				$data['id_source'] = $id_source;
1538
+				$data['format_source'] = 'phpvmacars';
1539
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1540
+			$SI->add($data);
1541
+			unset($data);
1542 1542
 		}
1543 1543
 		if ($globalDebug) echo 'No more data...'."\n";
1544 1544
 		unset($buffer);
1545 1545
 		unset($all_data);
1546
-	    }
1547
-	    //$last_exec['phpvmacars'] = time();
1548
-	    $last_exec[$id]['last'] = time();
1546
+		}
1547
+		//$last_exec['phpvmacars'] = time();
1548
+		$last_exec[$id]['last'] = time();
1549 1549
 	} elseif ($value['format'] === 'vaos' && 
1550
-	    (
1550
+		(
1551 1551
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1552 1552
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1553
-	    )
1553
+		)
1554 1554
 	) {
1555
-	    //$buffer = $Common->getData($hosts[$id]);
1556
-	    if ($globalDebug) echo 'Get Data...'."\n";
1557
-	    $buffer = $Common->getData($value['host']);
1558
-	    $all_data = json_decode($buffer,true);
1559
-	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1555
+		//$buffer = $Common->getData($hosts[$id]);
1556
+		if ($globalDebug) echo 'Get Data...'."\n";
1557
+		$buffer = $Common->getData($value['host']);
1558
+		$all_data = json_decode($buffer,true);
1559
+		if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1560 1560
 		$reset = 0;
1561 1561
 		foreach ($all_data['ACARSData'] as $line) {
1562
-		    //print_r($line);
1563
-	    	    $data = array();
1564
-	    	    //$data['id'] = $line['id']; // id not usable
1565
-	    	    $data['id'] = $line['id'];
1566
-	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1567
-	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1568
-	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1569
-	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1570
-	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1571
-	    	    $data['altitude'] = $line['altitude']; // altitude
1572
-	    	    $data['speed'] = $line['groundspeed']; // speed
1573
-	    	    $data['heading'] = $line['heading']; // heading
1574
-	    	    $data['latitude'] = $line['lat']; // lat
1575
-	    	    $data['longitude'] = $line['lon']; // long
1576
-	    	    //$data['verticalrate'] = ''; // verticale rate
1577
-	    	    //$data['squawk'] = ''; // squawk
1578
-	    	    //$data['emergency'] = ''; // emergency
1579
-	    	    if (isset($value['timezone'])) {
1580
-	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1581
-	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1582
-	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1583
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1562
+			//print_r($line);
1563
+				$data = array();
1564
+				//$data['id'] = $line['id']; // id not usable
1565
+				$data['id'] = $line['id'];
1566
+				//$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1567
+				if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1568
+				if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1569
+				$data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1570
+				if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1571
+				$data['altitude'] = $line['altitude']; // altitude
1572
+				$data['speed'] = $line['groundspeed']; // speed
1573
+				$data['heading'] = $line['heading']; // heading
1574
+				$data['latitude'] = $line['lat']; // lat
1575
+				$data['longitude'] = $line['lon']; // long
1576
+				//$data['verticalrate'] = ''; // verticale rate
1577
+				//$data['squawk'] = ''; // squawk
1578
+				//$data['emergency'] = ''; // emergency
1579
+				if (isset($value['timezone'])) {
1580
+				$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1581
+				$datetime->setTimeZone(new DateTimeZone('UTC'));
1582
+				$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1583
+				} else $data['datetime'] = date('Y-m-d H:i:s');
1584 1584
 	    	    
1585
-	    	    $data['departure_airport_icao'] = $line['bid']['depapt']['icao'];
1586
-	    	    $data['departure_airport_time'] = $line['bid']['deptime'];
1587
-	    	    $data['arrival_airport_icao'] = $line['bid']['arrapt']['icao'];
1588
-		    $data['arrival_airport_time'] = $line['bid']['arrtime'];
1589
-		    $data['registration'] = $line['bid']['aircraft']['registration'];
1585
+				$data['departure_airport_icao'] = $line['bid']['depapt']['icao'];
1586
+				$data['departure_airport_time'] = $line['bid']['deptime'];
1587
+				$data['arrival_airport_icao'] = $line['bid']['arrapt']['icao'];
1588
+			$data['arrival_airport_time'] = $line['bid']['arrtime'];
1589
+			$data['registration'] = $line['bid']['aircraft']['registration'];
1590 1590
 
1591
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1592
-		    if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route
1593
-	    	    $data['aircraft_icao'] = $line['bid']['aircraft']['icao'];
1591
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1592
+			if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route
1593
+				$data['aircraft_icao'] = $line['bid']['aircraft']['icao'];
1594 1594
 
1595
-    		    $data['id_source'] = $id_source;
1596
-	    	    $data['format_source'] = 'vaos';
1597
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1598
-		    $SI->add($data);
1599
-		    unset($data);
1595
+				$data['id_source'] = $id_source;
1596
+				$data['format_source'] = 'vaos';
1597
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1598
+			$SI->add($data);
1599
+			unset($data);
1600 1600
 		}
1601 1601
 		if ($globalDebug) echo 'No more data...'."\n";
1602 1602
 		unset($buffer);
1603 1603
 		unset($all_data);
1604
-	    }
1605
-	    //$last_exec['phpvmacars'] = time();
1606
-	    $last_exec[$id]['last'] = time();
1604
+		}
1605
+		//$last_exec['phpvmacars'] = time();
1606
+		$last_exec[$id]['last'] = time();
1607 1607
 	} elseif ($value['format'] === 'vam' && 
1608
-	    (
1608
+		(
1609 1609
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1610 1610
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1611
-	    )
1611
+		)
1612 1612
 	) {
1613
-	    //$buffer = $Common->getData($hosts[$id]);
1614
-	    if ($globalDebug) echo 'Get Data...'."\n";
1615
-	    $buffer = $Common->getData($value['host']);
1616
-	    $all_data = json_decode($buffer,true);
1617
-	    if ($buffer != '' && is_array($all_data)) {
1613
+		//$buffer = $Common->getData($hosts[$id]);
1614
+		if ($globalDebug) echo 'Get Data...'."\n";
1615
+		$buffer = $Common->getData($value['host']);
1616
+		$all_data = json_decode($buffer,true);
1617
+		if ($buffer != '' && is_array($all_data)) {
1618 1618
 		$reset = 0;
1619 1619
 		foreach ($all_data as $line) {
1620
-	    	    $data = array();
1621
-	    	    //$data['id'] = $line['id']; // id not usable
1622
-	    	    $data['id'] = trim($line['flight_id']);
1623
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1624
-	    	    $data['pilot_name'] = $line['pilot_name'];
1625
-	    	    $data['pilot_id'] = $line['pilot_id'];
1626
-	    	    $data['ident'] = trim($line['callsign']); // ident
1627
-	    	    $data['altitude'] = $line['altitude']; // altitude
1628
-	    	    $data['speed'] = $line['gs']; // speed
1629
-	    	    $data['heading'] = $line['heading']; // heading
1630
-	    	    $data['latitude'] = $line['latitude']; // lat
1631
-	    	    $data['longitude'] = $line['longitude']; // long
1632
-	    	    $data['verticalrate'] = ''; // verticale rate
1633
-	    	    $data['squawk'] = ''; // squawk
1634
-	    	    $data['emergency'] = ''; // emergency
1635
-	    	    //$data['datetime'] = $line['lastupdate'];
1636
-	    	    $data['last_update'] = $line['last_update'];
1637
-		    $data['datetime'] = date('Y-m-d H:i:s');
1638
-	    	    $data['departure_airport_icao'] = $line['departure'];
1639
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
1640
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
1641
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
1642
-    		    //$data['registration'] = $line['aircraft'];
1643
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1644
-	    	    $data['aircraft_icao'] = $line['plane_type'];
1645
-    		    $data['id_source'] = $id_source;
1646
-	    	    $data['format_source'] = 'vam';
1647
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1648
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1649
-		    $SI->add($data);
1650
-		    unset($data);
1620
+				$data = array();
1621
+				//$data['id'] = $line['id']; // id not usable
1622
+				$data['id'] = trim($line['flight_id']);
1623
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1624
+				$data['pilot_name'] = $line['pilot_name'];
1625
+				$data['pilot_id'] = $line['pilot_id'];
1626
+				$data['ident'] = trim($line['callsign']); // ident
1627
+				$data['altitude'] = $line['altitude']; // altitude
1628
+				$data['speed'] = $line['gs']; // speed
1629
+				$data['heading'] = $line['heading']; // heading
1630
+				$data['latitude'] = $line['latitude']; // lat
1631
+				$data['longitude'] = $line['longitude']; // long
1632
+				$data['verticalrate'] = ''; // verticale rate
1633
+				$data['squawk'] = ''; // squawk
1634
+				$data['emergency'] = ''; // emergency
1635
+				//$data['datetime'] = $line['lastupdate'];
1636
+				$data['last_update'] = $line['last_update'];
1637
+			$data['datetime'] = date('Y-m-d H:i:s');
1638
+				$data['departure_airport_icao'] = $line['departure'];
1639
+				//$data['departure_airport_time'] = $line['departure_time'];
1640
+				$data['arrival_airport_icao'] = $line['arrival'];
1641
+				//$data['arrival_airport_time'] = $line['arrival_time'];
1642
+				//$data['registration'] = $line['aircraft'];
1643
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1644
+				$data['aircraft_icao'] = $line['plane_type'];
1645
+				$data['id_source'] = $id_source;
1646
+				$data['format_source'] = 'vam';
1647
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1648
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1649
+			$SI->add($data);
1650
+			unset($data);
1651 1651
 		}
1652 1652
 		if ($globalDebug) echo 'No more data...'."\n";
1653 1653
 		unset($buffer);
1654 1654
 		unset($all_data);
1655
-	    }
1656
-	    //$last_exec['phpvmacars'] = time();
1657
-	    $last_exec[$id]['last'] = time();
1655
+		}
1656
+		//$last_exec['phpvmacars'] = time();
1657
+		$last_exec[$id]['last'] = time();
1658 1658
 	} elseif ($value['format'] === 'blitzortung' && 
1659
-	    (
1659
+		(
1660 1660
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1661 1661
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1662
-	    )
1662
+		)
1663 1663
 	) {
1664
-	    //$buffer = $Common->getData($hosts[$id]);
1665
-	    if ($globalDebug) echo 'Get Data...'."\n";
1666
-	    $buffer = $Common->getData($value['host']);
1667
-	    $all_data = json_decode($buffer,true);
1668
-	    if ($buffer != '') {
1664
+		//$buffer = $Common->getData($hosts[$id]);
1665
+		if ($globalDebug) echo 'Get Data...'."\n";
1666
+		$buffer = $Common->getData($value['host']);
1667
+		$all_data = json_decode($buffer,true);
1668
+		if ($buffer != '') {
1669 1669
 		$Source->deleteLocationBySource('blitzortung');
1670 1670
 		$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1671 1671
 		$buffer = explode('\n',$buffer);
1672 1672
 		foreach ($buffer as $buffer_line) {
1673
-		    $line = json_decode($buffer_line,true);
1674
-		    if (isset($line['time'])) {
1673
+			$line = json_decode($buffer_line,true);
1674
+			if (isset($line['time'])) {
1675 1675
 			$data = array();
1676 1676
 			$data['altitude'] = $line['alt']; // altitude
1677 1677
 			$data['latitude'] = $line['lat']; // lat
@@ -1683,92 +1683,92 @@  discard block
 block discarded – undo
1683 1683
 			if ($globalDebug) echo '☈ Lightning added'."\n";
1684 1684
 			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1685 1685
 			unset($data);
1686
-		    }
1686
+			}
1687 1687
 		}
1688 1688
 		if ($globalDebug) echo 'No more data...'."\n";
1689 1689
 		unset($buffer);
1690
-	    }
1691
-	    $last_exec[$id]['last'] = time();
1690
+		}
1691
+		$last_exec[$id]['last'] = time();
1692 1692
 	} elseif ($value['format'] === 'acarsjson') {
1693
-        $arr = $httpfeeds;
1694
-        $w = $e = null;
1695
-        if (isset($arr[$id])) {
1696
-            $nn = stream_select($arr,$w,$e,$timeout);
1697
-            if ($nn > 0) {
1698
-                foreach ($httpfeeds as $feed) {
1699
-                    $buffer = stream_get_line($feed,2000,"\n");
1700
-                    if ($buffer === FALSE) {
1701
-                        connect_all($globalSources);
1702
-                    }
1703
-                    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1704
-                    $buffer = explode('\n',$buffer);
1705
-                    foreach ($buffer as $line) {
1706
-                        if ($line != '') {
1707
-                            $line = json_decode($line, true);
1708
-                            if (!empty($line)) {
1709
-                                $ACARS->add(isset($line['text']) ? $line['text'] : '', array('registration' => str_replace('.', '', $line['tail']), 'ident' => $line['flight'], 'label' => $line['label'], 'block_id' => $line['block_id'], 'msg_no' => $line['msgno'], 'message' => (isset($line['text']) ? $line['text'] : '')));
1710
-                                $ACARS->deleteLiveAcarsData();
1711
-                            }
1712
-                        }
1713
-                    }
1714
-                }
1715
-            } else {
1716
-                $format = $value['format'];
1717
-                if (isset($tt[$format])) $tt[$format]++;
1718
-                else $tt[$format] = 0;
1719
-                if ($tt[$format] > 30) {
1720
-                    if ($globalDebug) echo 'Reconnect...'."\n";
1721
-                    sleep(2);
1722
-                    //$sourceeen[] = $value;
1723
-                    //connect_all($sourceeen);
1724
-                    //$sourceeen = array();
1725
-                    connect_all($globalSources);
1726
-                }
1727
-            }
1728
-        }
1693
+		$arr = $httpfeeds;
1694
+		$w = $e = null;
1695
+		if (isset($arr[$id])) {
1696
+			$nn = stream_select($arr,$w,$e,$timeout);
1697
+			if ($nn > 0) {
1698
+				foreach ($httpfeeds as $feed) {
1699
+					$buffer = stream_get_line($feed,2000,"\n");
1700
+					if ($buffer === FALSE) {
1701
+						connect_all($globalSources);
1702
+					}
1703
+					$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1704
+					$buffer = explode('\n',$buffer);
1705
+					foreach ($buffer as $line) {
1706
+						if ($line != '') {
1707
+							$line = json_decode($line, true);
1708
+							if (!empty($line)) {
1709
+								$ACARS->add(isset($line['text']) ? $line['text'] : '', array('registration' => str_replace('.', '', $line['tail']), 'ident' => $line['flight'], 'label' => $line['label'], 'block_id' => $line['block_id'], 'msg_no' => $line['msgno'], 'message' => (isset($line['text']) ? $line['text'] : '')));
1710
+								$ACARS->deleteLiveAcarsData();
1711
+							}
1712
+						}
1713
+					}
1714
+				}
1715
+			} else {
1716
+				$format = $value['format'];
1717
+				if (isset($tt[$format])) $tt[$format]++;
1718
+				else $tt[$format] = 0;
1719
+				if ($tt[$format] > 30) {
1720
+					if ($globalDebug) echo 'Reconnect...'."\n";
1721
+					sleep(2);
1722
+					//$sourceeen[] = $value;
1723
+					//connect_all($sourceeen);
1724
+					//$sourceeen = array();
1725
+					connect_all($globalSources);
1726
+				}
1727
+			}
1728
+		}
1729 1729
 	//} elseif ($value === 'sbs' || $value === 'tsv' || $value === 'raw' || $value === 'aprs' || $value === 'beast') {
1730 1730
 	} 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'] === 'acarsjsonudp' || $value['format'] === 'acarssbs3' || $value['format'] === 'ais' || $value['format'] === 'vrstcp') {
1731
-	    //$last_exec[$id]['last'] = time();
1732
-	    //$read = array( $sockets[$id] );
1733
-	    $read = $sockets;
1734
-	    $write = NULL;
1735
-	    $e = NULL;
1736
-	    $n = socket_select($read, $write, $e, $timeout);
1737
-	    if ($e != NULL) var_dump($e);
1738
-	    if ($n > 0) {
1731
+		//$last_exec[$id]['last'] = time();
1732
+		//$read = array( $sockets[$id] );
1733
+		$read = $sockets;
1734
+		$write = NULL;
1735
+		$e = NULL;
1736
+		$n = socket_select($read, $write, $e, $timeout);
1737
+		if ($e != NULL) var_dump($e);
1738
+		if ($n > 0) {
1739 1739
 		$reset = 0;
1740 1740
 		foreach ($read as $nb => $r) {
1741
-		    //$value = $formats[$nb];
1742
-		    $format = $globalSources[$nb]['format'];
1743
-		    if ($format === 'sbs' || $format === 'aprs' || $format === 'famaprs' || $format === 'raw' || $format === 'tsv' || $format === 'acarssbs3') {
1741
+			//$value = $formats[$nb];
1742
+			$format = $globalSources[$nb]['format'];
1743
+			if ($format === 'sbs' || $format === 'aprs' || $format === 'famaprs' || $format === 'raw' || $format === 'tsv' || $format === 'acarssbs3') {
1744 1744
 			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1745
-		    } elseif ($format === 'vrstcp') {
1745
+			} elseif ($format === 'vrstcp') {
1746 1746
 			$buffer = @socket_read($r, 6000);
1747
-		    } else {
1747
+			} else {
1748 1748
 			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1749
-		    }
1750
-		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1751
-		    //echo $buffer."\n";
1752
-		    // lets play nice and handle signals such as ctrl-c/kill properly
1753
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1754
-		    $error = false;
1755
-		    //$SI::del();
1756
-		    if ($buffer !== FALSE) {
1749
+			}
1750
+			//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1751
+			//echo $buffer."\n";
1752
+			// lets play nice and handle signals such as ctrl-c/kill properly
1753
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1754
+			$error = false;
1755
+			//$SI::del();
1756
+			if ($buffer !== FALSE) {
1757 1757
 			if ($format === 'vrstcp') {
1758
-			    $buffer = explode('},{',$buffer);
1758
+				$buffer = explode('},{',$buffer);
1759 1759
 			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1760
-		    }
1761
-		    // SBS format is CSV format
1762
-		    if ($buffer !== FALSE && $buffer !== '') {
1760
+			}
1761
+			// SBS format is CSV format
1762
+			if ($buffer !== FALSE && $buffer !== '') {
1763 1763
 			$tt[$format] = 0;
1764 1764
 			if ($format === 'acarssbs3') {
1765
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1766
-			    $ACARS->add(trim($buffer));
1767
-			    $ACARS->deleteLiveAcarsData();
1765
+				if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1766
+				$ACARS->add(trim($buffer));
1767
+				$ACARS->deleteLiveAcarsData();
1768 1768
 			} elseif ($format === 'raw') {
1769
-			    // AVR format
1770
-			    $data = $SBS->parse($buffer);
1771
-			    if (is_array($data)) {
1769
+				// AVR format
1770
+				$data = $SBS->parse($buffer);
1771
+				if (is_array($data)) {
1772 1772
 				//if (!empty($data)) print_r($data);
1773 1773
 				$data['datetime'] = date('Y-m-d H:i:s');
1774 1774
 				$data['format_source'] = 'raw';
@@ -1778,39 +1778,39 @@  discard block
 block discarded – undo
1778 1778
 				//if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1779 1779
 				$SI->add($data);
1780 1780
 				unset($data);
1781
-			    }
1781
+				}
1782 1782
 			} elseif ($format === 'ais') {
1783
-			    $ais_data = $AIS->parse_line(trim($buffer));
1784
-			    $data = array();
1785
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1786
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1787
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1788
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1789
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1790
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1791
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1792
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1793
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1794
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1795
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1796
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1797
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1798
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1799
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1800
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1783
+				$ais_data = $AIS->parse_line(trim($buffer));
1784
+				$data = array();
1785
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1786
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1787
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1788
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1789
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1790
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1791
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1792
+				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1793
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1794
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1795
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1796
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1797
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1798
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1799
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1800
+				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1801 1801
 
1802
-			    if (isset($ais_data['timestamp'])) {
1802
+				if (isset($ais_data['timestamp'])) {
1803 1803
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1804
-			    } else {
1804
+				} else {
1805 1805
 				$data['datetime'] = date('Y-m-d H:i:s');
1806
-			    }
1807
-			    $data['format_source'] = 'aisnmea';
1808
-    			    $data['id_source'] = $id_source;
1809
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
1810
-			    unset($data);
1811
-                        } elseif ($format === 'flightgearsp') {
1812
-                    	    //echo $buffer."\n";
1813
-                    	    if (strlen($buffer) > 5) {
1806
+				}
1807
+				$data['format_source'] = 'aisnmea';
1808
+					$data['id_source'] = $id_source;
1809
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
1810
+				unset($data);
1811
+						} elseif ($format === 'flightgearsp') {
1812
+							//echo $buffer."\n";
1813
+							if (strlen($buffer) > 5) {
1814 1814
 				$line = explode(',',$buffer);
1815 1815
 				$data = array();
1816 1816
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1827,47 +1827,47 @@  discard block
 block discarded – undo
1827 1827
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1828 1828
 				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1829 1829
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1830
-			    }
1831
-                        } elseif ($format === 'acars') {
1832
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1833
-			    $ACARS->add(trim($buffer));
1834
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1835
-			    $ACARS->deleteLiveAcarsData();
1830
+				}
1831
+						} elseif ($format === 'acars') {
1832
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1833
+				$ACARS->add(trim($buffer));
1834
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1835
+				$ACARS->deleteLiveAcarsData();
1836 1836
 			} elseif ($format === 'acarsjsonudp') {
1837
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1838
-                            $line = json_decode(trim($buffer), true);
1839
-                            if (!empty($line)) {
1837
+				if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1838
+							$line = json_decode(trim($buffer), true);
1839
+							if (!empty($line)) {
1840 1840
 				$line = array_merge(array('text' => '','tail' => '','label' => '','block_id' => '','flight' => '','msgno' => ''),$line);
1841
-                                $ACARS->add(isset($line['text']) ? $line['text'] : '', array('registration' => str_replace('.', '', $line['tail']), 'ident' => $line['flight'], 'label' => $line['label'], 'block_id' => $line['block_id'], 'msg_no' => $line['msgno'], 'message' => (isset($line['text']) ? $line['text'] : '')));
1842
-                                $ACARS->deleteLiveAcarsData();
1843
-                            }
1844
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1841
+								$ACARS->add(isset($line['text']) ? $line['text'] : '', array('registration' => str_replace('.', '', $line['tail']), 'ident' => $line['flight'], 'label' => $line['label'], 'block_id' => $line['block_id'], 'msg_no' => $line['msgno'], 'message' => (isset($line['text']) ? $line['text'] : '')));
1842
+								$ACARS->deleteLiveAcarsData();
1843
+							}
1844
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1845 1845
 			} elseif ($format === 'flightgearmp') {
1846
-			    if (substr($buffer,0,1) != '#') {
1846
+				if (substr($buffer,0,1) != '#') {
1847 1847
 				$data = array();
1848 1848
 				//echo $buffer."\n";
1849 1849
 				$line = explode(' ',$buffer);
1850 1850
 				if (count($line) === 11) {
1851
-				    $userserver = explode('@',$line[0]);
1852
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1853
-				    $data['ident'] = $userserver[0];
1854
-				    $data['registration'] = $userserver[0];
1855
-				    $data['latitude'] = $line[4];
1856
-				    $data['longitude'] = $line[5];
1857
-				    $data['altitude'] = $line[6];
1858
-				    $data['datetime'] = date('Y-m-d H:i:s');
1859
-				    $aircraft_type = $line[10];
1860
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1861
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1862
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1863
-				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1851
+					$userserver = explode('@',$line[0]);
1852
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1853
+					$data['ident'] = $userserver[0];
1854
+					$data['registration'] = $userserver[0];
1855
+					$data['latitude'] = $line[4];
1856
+					$data['longitude'] = $line[5];
1857
+					$data['altitude'] = $line[6];
1858
+					$data['datetime'] = date('Y-m-d H:i:s');
1859
+					$aircraft_type = $line[10];
1860
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1861
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1862
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1863
+					if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1864
+				}
1864 1865
 				}
1865
-			    }
1866 1866
 			} elseif ($format === 'beast') {
1867
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1868
-			    die;
1867
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1868
+				die;
1869 1869
 			} elseif ($format === 'vrstcp') {
1870
-			    foreach($buffer as $all_data) {
1870
+				foreach($buffer as $all_data) {
1871 1871
 				$line = json_decode('{'.$all_data.'}',true);
1872 1872
 				$data = array();
1873 1873
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
@@ -1887,158 +1887,158 @@  discard block
 block discarded – undo
1887 1887
 				*/
1888 1888
 				$data['datetime'] = date('Y-m-d H:i:s');
1889 1889
 				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1890
-		    		$data['format_source'] = 'vrstcp';
1890
+					$data['format_source'] = 'vrstcp';
1891 1891
 				$data['id_source'] = $id_source;
1892 1892
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1893 1893
 				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1894 1894
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1895 1895
 				unset($data);
1896
-			    }
1896
+				}
1897 1897
 			} elseif ($format === 'tsv' || substr($buffer,0,4) === 'clock') {
1898
-			    $line = explode("\t", $buffer);
1899
-			    for($k = 0; $k < count($line); $k=$k+2) {
1898
+				$line = explode("\t", $buffer);
1899
+				for($k = 0; $k < count($line); $k=$k+2) {
1900 1900
 				$key = $line[$k];
1901
-			        $lined[$key] = $line[$k+1];
1902
-			    }
1903
-    			    if (count($lined) > 3) {
1904
-    				$data['hex'] = $lined['hexid'];
1905
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1906
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1907
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1908
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1909
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1910
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1911
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1912
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1913
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1914
-    				$data['id_source'] = $id_source;
1915
-    				$data['format_source'] = 'tsv';
1916
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1917
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1901
+					$lined[$key] = $line[$k+1];
1902
+				}
1903
+					if (count($lined) > 3) {
1904
+					$data['hex'] = $lined['hexid'];
1905
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1906
+					$data['datetime'] = date('Y-m-d H:i:s');;
1907
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1908
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1909
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1910
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1911
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1912
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1913
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1914
+					$data['id_source'] = $id_source;
1915
+					$data['format_source'] = 'tsv';
1916
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1917
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1918 1918
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1919
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1920
-    				unset($lined);
1921
-    				unset($data);
1922
-    			    } else $error = true;
1919
+					if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1920
+					unset($lined);
1921
+					unset($data);
1922
+					} else $error = true;
1923 1923
 			} elseif ($format === 'aprs' && $use_aprs) {
1924
-			    if ($aprs_connect === 0) {
1924
+				if ($aprs_connect === 0) {
1925 1925
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1926 1926
 				$aprs_connect = 1;
1927
-			    }
1927
+				}
1928 1928
 			    
1929
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1929
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1930 1930
 				$aprs_last_tx = time();
1931 1931
 				$data_aprs = "# Keep alive";
1932 1932
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1933
-			    }
1933
+				}
1934 1934
 			    
1935
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1936
-			    //echo 'APRS data : '.$buffer."\n";
1937
-			    $buffer = str_replace('APRS <- ','',$buffer);
1938
-			    $buffer = str_replace('APRS -> ','',$buffer);
1939
-			    //echo $buffer."\n";
1940
-			    date_default_timezone_set('UTC');
1941
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1935
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1936
+				//echo 'APRS data : '.$buffer."\n";
1937
+				$buffer = str_replace('APRS <- ','',$buffer);
1938
+				$buffer = str_replace('APRS -> ','',$buffer);
1939
+				//echo $buffer."\n";
1940
+				date_default_timezone_set('UTC');
1941
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1942 1942
 				$line = $APRS->parse($buffer);
1943 1943
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1944 1944
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
1945
-				    $aprs_last_tx = time();
1946
-				    $data = array();
1947
-				    //print_r($line);
1948
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1949
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1950
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1951
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1952
-				    if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code'];
1953
-				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1954
-				    if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1955
-				    if (isset($line['statusid'])) $data['status_id'] = $line['statusid'];
1956
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1957
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1958
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1959
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1960
-				    $data['latitude'] = $line['latitude'];
1961
-				    $data['longitude'] = $line['longitude'];
1962
-				    //$data['verticalrate'] = $line[16];
1963
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1964
-				    //else $data['speed'] = 0;
1965
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1966
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1967
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1968
-				    //if (isset($line['heading'])) $data['heading'] = $line['heading'];
1945
+					$aprs_last_tx = time();
1946
+					$data = array();
1947
+					//print_r($line);
1948
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1949
+					if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1950
+					if (isset($line['imo'])) $data['imo'] = $line['imo'];
1951
+					if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1952
+					if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code'];
1953
+					if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1954
+					if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1955
+					if (isset($line['statusid'])) $data['status_id'] = $line['statusid'];
1956
+					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1957
+					else $data['datetime'] = date('Y-m-d H:i:s');
1958
+					//$data['datetime'] = date('Y-m-d H:i:s');
1959
+					if (isset($line['ident'])) $data['ident'] = $line['ident'];
1960
+					$data['latitude'] = $line['latitude'];
1961
+					$data['longitude'] = $line['longitude'];
1962
+					//$data['verticalrate'] = $line[16];
1963
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1964
+					//else $data['speed'] = 0;
1965
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1966
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1967
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1968
+					//if (isset($line['heading'])) $data['heading'] = $line['heading'];
1969 1969
 				    
1970
-				    if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
1971
-				    //else echo 'No heading...'."\n";
1972
-				    //else $data['heading'] = 0;
1973
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1974
-				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1975
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1976
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1977
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1978
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1979
-    				    $data['id_source'] = $id_source;
1980
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1981
-				    else $data['format_source'] = 'aprs';
1982
-				    $data['source_name'] = $line['source'];
1983
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1984
-				    else $data['source_type'] = 'flarm';
1985
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1986
-				    $currentdate = date('Y-m-d H:i:s');
1987
-				    $aprsdate = strtotime($data['datetime']);
1988
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
1989
-				    // Accept data if time <= system time + 20s
1990
-				    //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'])))) {
1991
-				    if (
1970
+					if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
1971
+					//else echo 'No heading...'."\n";
1972
+					//else $data['heading'] = 0;
1973
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1974
+					//if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1975
+					if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1976
+					elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1977
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1978
+					elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1979
+						$data['id_source'] = $id_source;
1980
+						if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1981
+					else $data['format_source'] = 'aprs';
1982
+					$data['source_name'] = $line['source'];
1983
+					if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1984
+					else $data['source_type'] = 'flarm';
1985
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1986
+					$currentdate = date('Y-m-d H:i:s');
1987
+					$aprsdate = strtotime($data['datetime']);
1988
+					if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
1989
+					// Accept data if time <= system time + 20s
1990
+					//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'])))) {
1991
+					if (
1992 1992
 					($data['source_type'] === 'modes') || 
1993 1993
 					isset($line['stealth']) && 
1994 1994
 					(!isset($data['hex']) || $data['hex'] != 'FFFFFF') && 
1995 1995
 					 ($line['stealth'] === 0 || $line['stealth'] == '') && 
1996 1996
 					 (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1997 1997
 					$send = $SI->add($data);
1998
-				    } elseif ($data['source_type'] === 'ais') {
1998
+					} elseif ($data['source_type'] === 'ais') {
1999 1999
 					$data['type'] = '';
2000 2000
 					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
2001
-				    } elseif (isset($line['stealth']) && $line['stealth'] != 0) {
2001
+					} elseif (isset($line['stealth']) && $line['stealth'] != 0) {
2002 2002
 					 echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
2003
-				    } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
2004
-					    //$line['symbol'] === 'Balloon' ||
2005
-					    $line['symbol'] === 'Glider' || 
2006
-					    $line['symbol'] === 'No. Plane' || 
2007
-					    $line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter')) {
2008
-					    if ($line['symbol'] === 'Ballon') $data['aircraft_icao'] = 'BALL';
2009
-					    if ($line['symbol'] === 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
2010
-					    $send = $SI->add($data);
2011
-				    } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
2012
-					    $line['symbol'] === 'Yacht (Sail)' || 
2013
-					    $line['symbol'] === 'Ship (Power Boat)')) {
2014
-					    $send = $MI->add($data);
2015
-				    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
2016
-					    $line['symbol'] === 'Car' || 
2017
-					    $line['symbol'] === 'Ambulance' || 
2018
-					    $line['symbol'] === 'Van' || 
2019
-					    $line['symbol'] === 'Truck' || $line['symbol'] === 'Truck (18 Wheeler)' || 
2020
-					    $line['symbol'] === 'Motorcycle' || 
2021
-					    $line['symbol'] === 'Tractor' || 
2022
-					    $line['symbol'] === 'Police' || 
2023
-					    $line['symbol'] === 'Bike' || 
2024
-					    $line['symbol'] === 'Jogger' || 
2025
-					    $line['symbol'] === 'Horse' || 
2026
-					    $line['symbol'] === 'Bus' || 
2027
-					    $line['symbol'] === 'Jeep' || 
2028
-					    $line['symbol'] === 'Recreational Vehicle' || 
2029
-					    $line['symbol'] === 'Yacht (Sail)' || 
2030
-					    $line['symbol'] === 'Ship (Power Boat)' || 
2031
-					    $line['symbol'] === 'Firetruck' || 
2032
-					    $line['symbol'] === 'Balloon' || $line['symbol'] === 'Glider' || 
2033
-					    $line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter' || 
2034
-					    $line['symbol'] === 'SUV' ||
2035
-					    $line['symbol'] === 'Snowmobile' ||
2036
-					    $line['symbol'] === 'Mobile Satellite Station')) {
2037
-				    //} 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') {
2003
+					} elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
2004
+						//$line['symbol'] === 'Balloon' ||
2005
+						$line['symbol'] === 'Glider' || 
2006
+						$line['symbol'] === 'No. Plane' || 
2007
+						$line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter')) {
2008
+						if ($line['symbol'] === 'Ballon') $data['aircraft_icao'] = 'BALL';
2009
+						if ($line['symbol'] === 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
2010
+						$send = $SI->add($data);
2011
+					} elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
2012
+						$line['symbol'] === 'Yacht (Sail)' || 
2013
+						$line['symbol'] === 'Ship (Power Boat)')) {
2014
+						$send = $MI->add($data);
2015
+					} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
2016
+						$line['symbol'] === 'Car' || 
2017
+						$line['symbol'] === 'Ambulance' || 
2018
+						$line['symbol'] === 'Van' || 
2019
+						$line['symbol'] === 'Truck' || $line['symbol'] === 'Truck (18 Wheeler)' || 
2020
+						$line['symbol'] === 'Motorcycle' || 
2021
+						$line['symbol'] === 'Tractor' || 
2022
+						$line['symbol'] === 'Police' || 
2023
+						$line['symbol'] === 'Bike' || 
2024
+						$line['symbol'] === 'Jogger' || 
2025
+						$line['symbol'] === 'Horse' || 
2026
+						$line['symbol'] === 'Bus' || 
2027
+						$line['symbol'] === 'Jeep' || 
2028
+						$line['symbol'] === 'Recreational Vehicle' || 
2029
+						$line['symbol'] === 'Yacht (Sail)' || 
2030
+						$line['symbol'] === 'Ship (Power Boat)' || 
2031
+						$line['symbol'] === 'Firetruck' || 
2032
+						$line['symbol'] === 'Balloon' || $line['symbol'] === 'Glider' || 
2033
+						$line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter' || 
2034
+						$line['symbol'] === 'SUV' ||
2035
+						$line['symbol'] === 'Snowmobile' ||
2036
+						$line['symbol'] === 'Mobile Satellite Station')) {
2037
+					//} 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') {
2038 2038
 				//    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && $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') {
2039 2039
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
2040 2040
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
2041
-				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
2041
+					} elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
2042 2042
 					if (!isset($data['altitude'])) $data['altitude'] = 0;
2043 2043
 					$Source->deleteOldLocationByType('gs');
2044 2044
 					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
@@ -2046,7 +2046,7 @@  discard block
 block discarded – undo
2046 2046
 					} else {
2047 2047
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
2048 2048
 					}
2049
-				    } elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
2049
+					} elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
2050 2050
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
2051 2051
 					if ($globalDebug) echo '# Weather Station added'."\n";
2052 2052
 					$Source->deleteOldLocationByType('wx');
@@ -2056,7 +2056,7 @@  discard block
 block discarded – undo
2056 2056
 					} else {
2057 2057
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
2058 2058
 					}
2059
-				    } elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
2059
+					} elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
2060 2060
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
2061 2061
 					if ($globalDebug) echo '☈ Lightning added'."\n";
2062 2062
 					$Source->deleteOldLocationByType('lightning');
@@ -2065,11 +2065,11 @@  discard block
 block discarded – undo
2065 2065
 					} else {
2066 2066
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
2067 2067
 					}
2068
-				    } elseif ($globalDebug) {
2069
-				    	echo '/!\ Not added: '.$buffer."\n";
2070
-				    	print_r($line);
2071
-				    }
2072
-				    unset($data);
2068
+					} elseif ($globalDebug) {
2069
+						echo '/!\ Not added: '.$buffer."\n";
2070
+						print_r($line);
2071
+					}
2072
+					unset($data);
2073 2073
 				}
2074 2074
 				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
2075 2075
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
@@ -2088,13 +2088,13 @@  discard block
 block discarded – undo
2088 2088
 				} elseif (!isset($globalSources[$nb]['last_weather_clean'])) {
2089 2089
 					$globalSources[$nb]['last_weather_clean'] = time();
2090 2090
 				}
2091
-			    }
2091
+				}
2092 2092
 			} else {
2093
-			    $line = explode(',', $buffer);
2094
-			    //print_r($line);
2095
-    			    if (count($line) > 20) {
2096
-    			    	$data['hex'] = $line[4];
2097
-    				/*
2093
+				$line = explode(',', $buffer);
2094
+				//print_r($line);
2095
+					if (count($line) > 20) {
2096
+						$data['hex'] = $line[4];
2097
+					/*
2098 2098
     				$data['datetime'] = $line[6].' '.$line[7];
2099 2099
     					date_default_timezone_set($globalTimezone);
2100 2100
     					$datetime = new DateTime($data['datetime']);
@@ -2102,31 +2102,31 @@  discard block
 block discarded – undo
2102 2102
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
2103 2103
     					date_default_timezone_set('UTC');
2104 2104
     				*/
2105
-    				// Force datetime to current UTC datetime
2106
-    				date_default_timezone_set('UTC');
2107
-    				$data['datetime'] = date('Y-m-d H:i:s');
2108
-    				$data['ident'] = trim($line[10]);
2109
-    				$data['latitude'] = $line[14];
2110
-    				$data['longitude'] = $line[15];
2111
-    				$data['verticalrate'] = $line[16];
2112
-    				$data['emergency'] = $line[20];
2113
-    				$data['speed'] = $line[12];
2114
-    				$data['squawk'] = $line[17];
2115
-    				$data['altitude'] = $line[11];
2116
-    				$data['heading'] = $line[13];
2117
-    				$data['ground'] = $line[21];
2118
-    				$data['emergency'] = $line[19];
2119
-    				$data['format_source'] = 'sbs';
2105
+					// Force datetime to current UTC datetime
2106
+					date_default_timezone_set('UTC');
2107
+					$data['datetime'] = date('Y-m-d H:i:s');
2108
+					$data['ident'] = trim($line[10]);
2109
+					$data['latitude'] = $line[14];
2110
+					$data['longitude'] = $line[15];
2111
+					$data['verticalrate'] = $line[16];
2112
+					$data['emergency'] = $line[20];
2113
+					$data['speed'] = $line[12];
2114
+					$data['squawk'] = $line[17];
2115
+					$data['altitude'] = $line[11];
2116
+					$data['heading'] = $line[13];
2117
+					$data['ground'] = $line[21];
2118
+					$data['emergency'] = $line[19];
2119
+					$data['format_source'] = 'sbs';
2120 2120
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
2121 2121
 				elseif ($line[0] == 'MLAT') $data['source_name'] = 'MLAT';
2122 2122
 				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2123 2123
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
2124
-    				$data['id_source'] = $id_source;
2125
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
2126
-    				else $error = true;
2127
-    				unset($data);
2128
-    			    } else $error = true;
2129
-			    if ($error) {
2124
+					$data['id_source'] = $id_source;
2125
+					if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
2126
+					else $error = true;
2127
+					unset($data);
2128
+					} else $error = true;
2129
+				if ($error) {
2130 2130
 				if (count($line) > 1 && ($line[0] === 'STA' || $line[0] === 'AIR' || $line[0] === 'SEL' || $line[0] === 'ID' || $line[0] === 'CLK')) { 
2131 2131
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
2132 2132
 				} else {
@@ -2142,13 +2142,13 @@  discard block
 block discarded – undo
2142 2142
 					connect_all($sourceer);
2143 2143
 					$sourceer = array();
2144 2144
 				}
2145
-			    }
2145
+				}
2146 2146
 			}
2147 2147
 			// Sleep for xxx microseconds
2148 2148
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
2149
-		    } else {
2149
+			} else {
2150 2150
 			if ($format === 'flightgearmp') {
2151
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
2151
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
2152 2152
 				//@socket_close($r);
2153 2153
 				sleep($globalMinFetch);
2154 2154
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -2157,9 +2157,9 @@  discard block
 block discarded – undo
2157 2157
 				break;
2158 2158
 				
2159 2159
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
2160
-			    if (isset($tt[$format])) $tt[$format]++;
2161
-			    else $tt[$format] = 0;
2162
-			    if ($tt[$format] > 30 || $buffer === FALSE) {
2160
+				if (isset($tt[$format])) $tt[$format]++;
2161
+				else $tt[$format] = 0;
2162
+				if ($tt[$format] > 30 || $buffer === FALSE) {
2163 2163
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
2164 2164
 				//@socket_close($r);
2165 2165
 				sleep(2);
@@ -2170,24 +2170,24 @@  discard block
 block discarded – undo
2170 2170
 				//connect_all($globalSources);
2171 2171
 				$tt[$format]=0;
2172 2172
 				break;
2173
-			    } 
2174
-			    //else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
2173
+				} 
2174
+				//else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
2175
+			}
2175 2176
 			}
2176
-		    }
2177 2177
 		}
2178
-	    } else {
2178
+		} else {
2179 2179
 		$error = socket_strerror(socket_last_error());
2180 2180
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
2181 2181
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
2182 2182
 			if (isset($globalDebug)) echo "Restarting...\n";
2183 2183
 			// Restart the script if possible
2184 2184
 			if (is_array($sockets)) {
2185
-			    if ($globalDebug) echo "Shutdown all sockets...";
2185
+				if ($globalDebug) echo "Shutdown all sockets...";
2186 2186
 			    
2187
-			    foreach ($sockets as $sock) {
2187
+				foreach ($sockets as $sock) {
2188 2188
 				@socket_shutdown($sock,2);
2189 2189
 				@socket_close($sock);
2190
-			    }
2190
+				}
2191 2191
 			    
2192 2192
 			}
2193 2193
 			if ($globalDebug) echo "Waiting...";
@@ -2202,15 +2202,15 @@  discard block
 block discarded – undo
2202 2202
 			if ($globalDebug) echo "Restart all connections...";
2203 2203
 			connect_all($globalSources);
2204 2204
 		}
2205
-	    }
2205
+		}
2206 2206
 	}
2207 2207
 	if ($globalDaemon === false) {
2208
-	    if ($globalDebug) echo 'Check all...'."\n";
2209
-	    if (isset($SI)) $SI->checkAll();
2210
-	    if (isset($TI)) $TI->checkAll();
2211
-	    if (isset($MI)) $MI->checkAll();
2208
+		if ($globalDebug) echo 'Check all...'."\n";
2209
+		if (isset($SI)) $SI->checkAll();
2210
+		if (isset($TI)) $TI->checkAll();
2211
+		if (isset($MI)) $MI->checkAll();
2212
+	}
2212 2213
 	}
2213
-    }
2214 2214
 }
2215 2215
 
2216 2216
 ?>
Please login to merge, or discard this patch.
Spacing   +233 added lines, -233 removed lines patch added patch discarded remove patch
@@ -59,20 +59,20 @@  discard block
 block discarded – undo
59 59
 	    die;
60 60
 	}
61 61
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
62
-	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
62
+	$globalSources[] = array('host' => $globalSBS1Host, 'port' => $globalSBS1Port);
63 63
     }
64 64
 }
65 65
 
66
-$options = getopt('s::',array('source::','server','nodaemon','idsource::','aprsserverssid::','aprsserverpass::','aprsserverhost::','aprsserverport::','format::','noaprsserver','enable-aircraft','disable-aircraft','enable-tracker','disable-tracker','enable-marine','disable-marine'));
66
+$options = getopt('s::', array('source::', 'server', 'nodaemon', 'idsource::', 'aprsserverssid::', 'aprsserverpass::', 'aprsserverhost::', 'aprsserverport::', 'format::', 'noaprsserver', 'enable-aircraft', 'disable-aircraft', 'enable-tracker', 'disable-tracker', 'enable-marine', 'disable-marine'));
67 67
 //if (isset($options['s'])) $hosts = array($options['s']);
68 68
 //elseif (isset($options['source'])) $hosts = array($options['source']);
69 69
 if (isset($options['s'])) {
70 70
     $globalSources = array();
71
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
71
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'], 'format' => $options['format']);
72 72
     else $globalSources[] = array('host' => $options['s']);
73 73
 } elseif (isset($options['source'])) {
74 74
     $globalSources = array();
75
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
75
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'], 'format' => $options['format']);
76 76
     else $globalSources[] = array('host' => $options['source']);
77 77
 }
78 78
 if (isset($options['aprsserverhost'])) {
@@ -113,13 +113,13 @@  discard block
 block discarded – undo
113 113
 else $id_source = 1;
114 114
 if (isset($globalServer) && $globalServer) {
115 115
     if ($globalDebug) echo "Using Server Mode\n";
116
-    $SI=new SpotterServer();
116
+    $SI = new SpotterServer();
117 117
 /*
118 118
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
119 119
     $SI = new adsb2aprs();
120 120
     $SI->connect();
121 121
 */
122
-} else $SI=new SpotterImport($Connection->db);
122
+} else $SI = new SpotterImport($Connection->db);
123 123
 
124 124
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
125 125
 if (isset($globalMarine) && $globalMarine) {
@@ -133,17 +133,17 @@  discard block
 block discarded – undo
133 133
     $MI = new MarineImport($Connection->db);
134 134
 }
135 135
 //$APRS=new APRS($Connection->db);
136
-$SBS=new SBS();
136
+$SBS = new SBS();
137 137
 if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
138
-	$ACARS=new ACARS($Connection->db,true);
139
-	$Source=new Source($Connection->db);
138
+	$ACARS = new ACARS($Connection->db, true);
139
+	$Source = new Source($Connection->db);
140 140
 }
141
-$Common=new Common();
141
+$Common = new Common();
142 142
 date_default_timezone_set('UTC');
143 143
 //$servertz = system('date +%Z');
144 144
 // signal handler - playing nice with sockets and dump1090
145 145
 if (function_exists('pcntl_fork')) {
146
-    pcntl_signal(SIGINT,  function() {
146
+    pcntl_signal(SIGINT, function() {
147 147
         global $sockets;
148 148
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
149 149
         die("Bye!\n");
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 
160 160
 function connect_all($hosts) {
161 161
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
162
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
162
+    global $sockets, $httpfeeds, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset, $context;
163 163
     $reset++;
164 164
     if ($globalDebug) echo 'Connect to all...'."\n";
165 165
     foreach ($hosts as $id => $value) {
@@ -167,33 +167,33 @@  discard block
 block discarded – undo
167 167
 	$udp = false;
168 168
 	$globalSources[$id]['last_exec'] = 0;
169 169
 	// Here we check type of source(s)
170
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
171
-            if (preg_match('/deltadb.txt$/i',$host)) {
170
+	if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
171
+            if (preg_match('/deltadb.txt$/i', $host)) {
172 172
         	//$formats[$id] = 'deltadbtxt';
173 173
         	$globalSources[$id]['format'] = 'deltadbtxt';
174 174
         	//$last_exec['deltadbtxt'] = 0;
175 175
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
176
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
176
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
177 177
         	//$formats[$id] = 'vatsimtxt';
178 178
         	$globalSources[$id]['format'] = 'vatsimtxt';
179 179
         	//$last_exec['vatsimtxt'] = 0;
180 180
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
181
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
181
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
182 182
         	//$formats[$id] = 'aircraftlistjson';
183 183
         	$globalSources[$id]['format'] = 'aircraftlistjson';
184 184
         	//$last_exec['aircraftlistjson'] = 0;
185 185
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
186
-    	    } else if (preg_match('/aircraft.json$/i',$host)) {
186
+    	    } else if (preg_match('/aircraft.json$/i', $host)) {
187 187
         	//$formats[$id] = 'aircraftjson';
188 188
         	$globalSources[$id]['format'] = 'aircraftjson';
189 189
         	//$last_exec['aircraftlistjson'] = 0;
190 190
         	if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
191
-    	    } else if (preg_match('/aircraft$/i',$host)) {
191
+    	    } else if (preg_match('/aircraft$/i', $host)) {
192 192
         	//$formats[$id] = 'planefinderclient';
193 193
         	$globalSources[$id]['format'] = 'planefinderclient';
194 194
         	//$last_exec['aircraftlistjson'] = 0;
195 195
         	if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
196
-    	    } else if (preg_match('/opensky/i',$host)) {
196
+    	    } else if (preg_match('/opensky/i', $host)) {
197 197
         	//$formats[$id] = 'aircraftlistjson';
198 198
         	$globalSources[$id]['format'] = 'opensky';
199 199
         	//$last_exec['aircraftlistjson'] = 0;
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
         	    exit(0);
211 211
         	}
212 212
     	    */
213
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
213
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
214 214
         	//$formats[$id] = 'planeupdatefaa';
215 215
         	$globalSources[$id]['format'] = 'planeupdatefaa';
216 216
         	//$last_exec['planeupdatefaa'] = 0;
@@ -219,37 +219,37 @@  discard block
 block discarded – undo
219 219
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
220 220
         	    exit(0);
221 221
         	}
222
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
222
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
223 223
         	//$formats[$id] = 'phpvmacars';
224 224
         	$globalSources[$id]['format'] = 'phpvmacars';
225 225
         	//$last_exec['phpvmacars'] = 0;
226 226
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
227
-            } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
227
+            } else if (preg_match('/\/api\/v1\/acars\/data$/i', $host)) {
228 228
         	//$formats[$id] = 'phpvmacars';
229 229
         	$globalSources[$id]['format'] = 'vaos';
230 230
         	//$last_exec['phpvmacars'] = 0;
231 231
         	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
232
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
232
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
233 233
         	//$formats[$id] = 'phpvmacars';
234 234
         	$globalSources[$id]['format'] = 'vam';
235 235
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
236
-            } else if (preg_match('/whazzup/i',$host)) {
236
+            } else if (preg_match('/whazzup/i', $host)) {
237 237
         	//$formats[$id] = 'whazzup';
238 238
         	$globalSources[$id]['format'] = 'whazzup';
239 239
         	//$last_exec['whazzup'] = 0;
240 240
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
241
-            } else if (preg_match('/blitzortung/i',$host)) {
241
+            } else if (preg_match('/blitzortung/i', $host)) {
242 242
         	$globalSources[$id]['format'] = 'blitzortung';
243 243
         	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
244
-            } else if (preg_match('/airwhere/i',$host)) {
244
+            } else if (preg_match('/airwhere/i', $host)) {
245 245
         	$globalSources[$id]['format'] = 'airwhere';
246 246
         	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
247
-            } else if (preg_match('/recentpireps/i',$host)) {
247
+            } else if (preg_match('/recentpireps/i', $host)) {
248 248
         	//$formats[$id] = 'pirepsjson';
249 249
         	$globalSources[$id]['format'] = 'pirepsjson';
250 250
         	//$last_exec['pirepsjson'] = 0;
251 251
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
252
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
252
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
253 253
         	//$formats[$id] = 'fr24json';
254 254
         	$globalSources[$id]['format'] = 'fr24json';
255 255
         	//$last_exec['fr24json'] = 0;
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
259 259
         	    exit(0);
260 260
         	}
261
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
261
+            } else if (preg_match(':myshiptracking.com/:i', $host)) {
262 262
         	//$formats[$id] = 'fr24json';
263 263
         	$globalSources[$id]['format'] = 'myshiptracking';
264 264
         	//$last_exec['fr24json'] = 0;
@@ -268,14 +268,14 @@  discard block
 block discarded – undo
268 268
         	    exit(0);
269 269
         	}
270 270
             //} else if (preg_match('/10001/',$host)) {
271
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
271
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
272 272
         	//$formats[$id] = 'tsv';
273 273
         	$globalSources[$id]['format'] = 'tsv';
274 274
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
275 275
             }
276
-        } elseif (filter_var($host,FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'acarsjson')) {
276
+        } elseif (filter_var($host, FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'acarsjson')) {
277 277
     		if ($globalSources[$id]['format'] == 'aisnmeahttp' || $globalSources[$id]['format'] == 'acarsjson') {
278
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
278
+    		    $idf = fopen($globalSources[$id]['host'], 'r', false, $context);
279 279
     		    if ($idf !== false) {
280 280
     			$httpfeeds[$id] = $idf;
281 281
         		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
@@ -283,8 +283,8 @@  discard block
 block discarded – undo
283 283
     		} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
284 284
     		elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') echo "Connect to ".$globalSources[$id]['format']." source (sailawayfull)...\n";
285 285
     		elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
286
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
287
-	    $hostport = explode(':',$host);
286
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
287
+	    $hostport = explode(':', $host);
288 288
 	    if (isset($hostport[1])) {
289 289
 		$port = $hostport[1];
290 290
 		$hostn = $hostport[0];
@@ -294,20 +294,20 @@  discard block
 block discarded – undo
294 294
 	    }
295 295
 	    $Common = new Common();
296 296
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acarsjsonudp' && $globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
297
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
297
+        	$s = $Common->create_socket($hostn, $port, $errno, $errstr);
298 298
     	    } else {
299 299
     		$udp = true;
300
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
300
+        	$s = $Common->create_socket_udp($hostn, $port, $errno, $errstr);
301 301
 	    }
302 302
 	    if ($s) {
303 303
     	        $sockets[$id] = $s;
304 304
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
305
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
305
+		    if (preg_match('/aprs/', $hostn) || $port == '10152' || $port == '14580') {
306 306
 			//$formats[$id] = 'aprs';
307 307
 			$globalSources[$id]['format'] = 'aprs';
308 308
 			//$aprs_connect = 0;
309 309
 			//$use_aprs = true;
310
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
310
+		    } elseif (preg_match('/pub-vrs/', $hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
311 311
 			$globalSources[$id]['format'] = 'vrstcp';
312 312
     		    } elseif ($port == '10001') {
313 313
         		//$formats[$id] = 'tsv';
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
350 350
 else $timeout = 20;
351 351
 $errno = '';
352
-$errstr='';
352
+$errstr = '';
353 353
 
354 354
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
355 355
 /* Initiate connections to all the hosts simultaneously */
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
 //connect_all($globalSources);
358 358
 
359 359
 if (isset($globalProxy) && $globalProxy) {
360
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
360
+    $context = stream_context_create(array('http' => array('timeout' => $timeout, 'proxy' => $globalProxy, 'request_fulluri' => true)));
361 361
 } else {
362 362
     $context = stream_context_create(array('http' => array('timeout' => $timeout)));
363 363
 }
@@ -387,16 +387,16 @@  discard block
 block discarded – undo
387 387
 
388 388
 if ($use_aprs) {
389 389
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
390
-	$APRS=new APRS();
390
+	$APRS = new APRS();
391 391
 	$aprs_connect = 0;
392 392
 	$aprs_keep = 120;
393 393
 	$aprs_last_tx = time();
394 394
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
395
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
395
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
396 396
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
397
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
397
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
398 398
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
399
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
399
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
400 400
 	if ($aprs_full) $aprs_filter = '';
401 401
 	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
402 402
 	else $aprs_pass = '-1';
@@ -410,12 +410,12 @@  discard block
 block discarded – undo
410 410
 sleep(1);
411 411
 if ($globalDebug) echo "SCAN MODE \n\n";
412 412
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
413
-$endtime = time()+$globalCronEnd;
413
+$endtime = time() + $globalCronEnd;
414 414
 $i = 1;
415 415
 $tt = array();
416 416
 // Delete all ATC
417 417
 if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
418
-	$ATC=new ATC($Connection->db);
418
+	$ATC = new ATC($Connection->db);
419 419
 }
420 420
 if (!$globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
421 421
 	$ATC->deleteAll();
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
 while ($i > 0) {
426 426
     if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
427 427
 
428
-    if (!$globalDaemon) $i = $endtime-time();
428
+    if (!$globalDaemon) $i = $endtime - time();
429 429
     // Delete old ATC
430 430
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
431 431
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
 	}
440 440
 	if ($max < $globalMinFetch) {
441 441
 	    if ($globalDebug) echo 'Sleeping...'."\n";
442
-	    sleep($globalMinFetch-$max+2);
442
+	    sleep($globalMinFetch - $max + 2);
443 443
 	}
444 444
     }
445 445
 
@@ -494,10 +494,10 @@  discard block
 block discarded – undo
494 494
             //$buffer = $Common->getData($hosts[$id]);
495 495
             $buffer = $Common->getData($value['host']);
496 496
             if ($buffer != '') {
497
-                $all_data = json_decode($buffer,true);
497
+                $all_data = json_decode($buffer, true);
498 498
                 foreach ($all_data as $line) {
499 499
                     $data = array();
500
-                    $data['datetime'] = date('Y-m-d H:i:s',$line['uti']);
500
+                    $data['datetime'] = date('Y-m-d H:i:s', $line['uti']);
501 501
                     $data['hex'] = $line['hex']; // hex
502 502
                     $data['ident'] = $line['fli']; // ident
503 503
                     $data['altitude'] = $line['alt']; // altitude
@@ -532,11 +532,11 @@  discard block
 block discarded – undo
532 532
 	    )
533 533
 	) {
534 534
 	    date_default_timezone_set('CET');
535
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
535
+	    $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host']));
536 536
 	    date_default_timezone_set('UTC');
537 537
 	    if ($buffer != '') $reset = 0;
538
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
539
-	    $buffer = explode('\n',$buffer);
538
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
539
+	    $buffer = explode('\n', $buffer);
540 540
 	    foreach ($buffer as $line) {
541 541
 		if ($line != '') {
542 542
 		    //echo "'".$line."'\n";
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
 		    $ais_data = $AIS->parse_line(trim($line));
545 545
 		    $data = array();
546 546
 		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
547
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
547
+		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
548 548
 		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
549 549
 		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
550 550
 		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -556,7 +556,7 @@  discard block
 block discarded – undo
556 556
 		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
557 557
 		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
558 558
 		    if (isset($ais_data['timestamp'])) {
559
-			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
559
+			$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
560 560
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
561 561
 			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
562 562
 			    $add = true;
@@ -579,21 +579,21 @@  discard block
 block discarded – undo
579 579
 	    $w = $e = null;
580 580
 	    
581 581
 	    if (isset($arr[$id])) {
582
-		$nn = stream_select($arr,$w,$e,$timeout);
582
+		$nn = stream_select($arr, $w, $e, $timeout);
583 583
 		if ($nn > 0) {
584 584
 		    foreach ($httpfeeds as $feed) {
585
-			$buffer = stream_get_line($feed,2000,"\n");
585
+			$buffer = stream_get_line($feed, 2000, "\n");
586 586
 			if ($buffer === FALSE) {
587 587
 			    connect_all($globalSources);
588 588
 			}
589
-			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
590
-			$buffer = explode('\n',$buffer);
589
+			$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
590
+			$buffer = explode('\n', $buffer);
591 591
 			foreach ($buffer as $line) {
592 592
 			    if ($line != '') {
593 593
 				$ais_data = $AIS->parse_line(trim($line));
594 594
 				$data = array();
595 595
 				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
596
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
596
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
597 597
 				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
598 598
 				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
599 599
 				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -605,9 +605,9 @@  discard block
 block discarded – undo
605 605
 				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
606 606
 				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
607 607
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
608
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
608
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
609 609
 				if (isset($ais_data['timestamp'])) {
610
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
610
+				    $data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
611 611
 				} else {
612 612
 				    $data['datetime'] = date('Y-m-d H:i:s');
613 613
 				}
@@ -639,10 +639,10 @@  discard block
 block discarded – undo
639 639
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
640 640
 	    )
641 641
 	) {
642
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
642
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
643 643
 	    if ($buffer != '') {
644 644
 		//echo $buffer;
645
-		$all_data = json_decode($buffer,true);
645
+		$all_data = json_decode($buffer, true);
646 646
 		//print_r($all_data);
647 647
 		if (isset($all_data[0]['DATA'])) {
648 648
 		    foreach ($all_data[0]['DATA'] as $line) {
@@ -651,7 +651,7 @@  discard block
 block discarded – undo
651 651
 			    $data['ident'] = $line['NAME'];
652 652
 			    $data['mmsi'] = $line['MMSI'];
653 653
 			    if (strlen($data['mmsi']) > 9) {
654
-				$data['mmsi'] = substr($data['mmsi'],-9);
654
+				$data['mmsi'] = substr($data['mmsi'], -9);
655 655
 			    }
656 656
 			    $data['speed'] = $line['SOG'];
657 657
 			    $data['heading'] = $line['COG'];
@@ -661,8 +661,8 @@  discard block
 block discarded – undo
661 661
 			    //$data['type_id'] = $line['TYPE'];
662 662
 			    $data['imo'] = $line['IMO'];
663 663
 			    if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
664
-			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
665
-			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
664
+			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s', strtotime($line['ARV']));
665
+			    $data['datetime'] = date('Y-m-d H:i:s', $line['T']);
666 666
 			    $data['format_source'] = 'myshiptracking';
667 667
 			    $data['id_source'] = $id_source;
668 668
 			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -679,16 +679,16 @@  discard block
 block discarded – undo
679 679
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
680 680
 	    )
681 681
 	) {
682
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
682
+	    $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host']));
683 683
 	    if ($buffer != '') {
684
-		$all_data = json_decode($buffer,true);
684
+		$all_data = json_decode($buffer, true);
685 685
 		if (isset($all_data[0]['mmsi'])) {
686 686
 		    foreach ($all_data as $line) {
687 687
 			if ($line != '') {
688 688
 			    $data = array();
689 689
 			    $data['ident'] = $line['shipname'];
690 690
 			    $data['callsign'] = $line['callsign'];
691
-			    $data['mmsi'] = substr($line['mmsi'],-9);
691
+			    $data['mmsi'] = substr($line['mmsi'], -9);
692 692
 			    $data['speed'] = $line['sog'];
693 693
 			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
694 694
 			    $data['latitude'] = $line['latitude'];
@@ -715,14 +715,14 @@  discard block
 block discarded – undo
715 715
 	) {
716 716
 	    $buffer = $Common->getData($value['host']);
717 717
 	    if ($buffer != '') {
718
-		$all_data = json_decode($buffer,true);
718
+		$all_data = json_decode($buffer, true);
719 719
 		if (isset($all_data['features'][0]['id'])) {
720 720
 		    foreach ($all_data['features'] as $line) {
721 721
 			print_r($line);
722 722
 			$data = array();
723 723
 			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
724 724
 			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
725
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'],-9);
725
+			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'], -9);
726 726
 			if (isset($line['properties']['imo'])) $data['imo'] = $line['properties']['imo'];
727 727
 			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
728 728
 			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) $data['heading'] = $line['properties']['heading'];
@@ -749,31 +749,31 @@  discard block
 block discarded – undo
749 749
 	    )
750 750
 	) {
751 751
 	    if ($globalDebug) echo 'download...';
752
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
752
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
753 753
 	    if ($globalDebug) echo 'done !'."\n";
754 754
 	    // FIXME: Need more work
755 755
 	    if ($buffer != '') $reset = 0;
756
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
757
-	    $buffer = explode('\n',$buffer);
756
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
757
+	    $buffer = explode('\n', $buffer);
758 758
 	    foreach ($buffer as $line) {
759 759
 		if ($line != '') {
760 760
 		    $data = array();
761 761
 		    //echo $line."\n";
762
-		    $data['mmsi'] = (int)substr($line,0,9);
763
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
764
-		    $data['status_id'] = substr($line,21,2);
765
-		    $data['type_id'] = substr($line,24,3);
766
-		    $data['latitude'] = substr($line,29,9);
767
-		    $data['longitude'] = substr($line,41,9);
768
-		    $data['speed'] = round(substr($line,51,5));
762
+		    $data['mmsi'] = (int) substr($line, 0, 9);
763
+		    $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10));
764
+		    $data['status_id'] = substr($line, 21, 2);
765
+		    $data['type_id'] = substr($line, 24, 3);
766
+		    $data['latitude'] = substr($line, 29, 9);
767
+		    $data['longitude'] = substr($line, 41, 9);
768
+		    $data['speed'] = round(substr($line, 51, 5));
769 769
 		    //$data['course'] = substr($line,57,5);
770
-		    $data['heading'] = round(substr($line,63,3));
770
+		    $data['heading'] = round(substr($line, 63, 3));
771 771
 		    //$data['draft'] = substr($line,67,4);
772 772
 		    //$data['length'] = substr($line,72,3);
773 773
 		    //$data['beam'] = substr($line,76,2);
774
-		    $data['ident'] = trim(utf8_encode(substr($line,78,20)));
774
+		    $data['ident'] = trim(utf8_encode(substr($line, 78, 20)));
775 775
 		    //$data['callsign'] = trim(substr($line,100,7);
776
-		    $data['arrival_code'] = substr($line,108,20);
776
+		    $data['arrival_code'] = substr($line, 108, 20);
777 777
 		    //$data['etaDate'] = substr($line,129,5);
778 778
 		    //$data['etaTime'] = substr($line,135,5);
779 779
 		    $data['format_source'] = 'shipplotter';
@@ -792,7 +792,7 @@  discard block
 block discarded – undo
792 792
 	    )
793 793
 	) {
794 794
 	    if (isset($globalSailaway['email']) && $globalSailaway['email'] != '' && isset($globalSailaway['password']) && $globalSailaway['password'] != '') {
795
-		$authsailaway = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/weblogin.pl','post',array('submitlogin' => 'Login','email' => $globalSailaway['email'],'pwd' => $globalSailaway['password'], 'page' => 'http://sailaway.world/cgi-bin/sailaway/missions.pl'),'','','','','',false,false,true);
795
+		$authsailaway = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/weblogin.pl', 'post', array('submitlogin' => 'Login', 'email' => $globalSailaway['email'], 'pwd' => $globalSailaway['password'], 'page' => 'http://sailaway.world/cgi-bin/sailaway/missions.pl'), '', '', '', '', '', false, false, true);
796 796
 		//echo $authsailaway;
797 797
 		preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $authsailaway, $setcookie);
798 798
 		if (isset($setcookie[1][0])) {
@@ -801,19 +801,19 @@  discard block
 block discarded – undo
801 801
 	    }
802 802
 
803 803
 	    if ($globalDebug) echo '! Download... ';
804
-	    for ($i =0; $i <= 1; $i++) {
804
+	    for ($i = 0; $i <= 1; $i++) {
805 805
 		if ($globalDebug) echo 'Racetype: '.$i.' ';
806 806
 		$buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/GetMissions.pl?race=1&tutorial=0&hist=1&racetype='.$i);
807 807
 	    if ($globalDebug) echo 'done'."\n";
808 808
 	    if ($buffer != '') {
809
-		$all_data = json_decode($buffer,true);
809
+		$all_data = json_decode($buffer, true);
810 810
 		if (isset($all_data['missions'])) {
811 811
 			foreach ($all_data['missions'] as $mission) {
812 812
 				$mission_user = $mission['usrname'];
813
-				$mission_name = preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($mission['mistitle']));
814
-				if (!isset($globalFilter['sailway']['race']) || (isset($globalFilter['sailway']['race']) && in_array($mission['misnr'],$globalFilter['sailway']['race']))) {
813
+				$mission_name = preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $Common->remove_accents($mission['mistitle']));
814
+				if (!isset($globalFilter['sailway']['race']) || (isset($globalFilter['sailway']['race']) && in_array($mission['misnr'], $globalFilter['sailway']['race']))) {
815 815
 					if (isset($sailaway_authcookie) && $sailaway_authcookie != '') {
816
-						$racebuffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/GetMission.pl?misnr='.$mission['misnr'],'get','','',$sailaway_authcookie);
816
+						$racebuffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/GetMission.pl?misnr='.$mission['misnr'], 'get', '', '', $sailaway_authcookie);
817 817
 						sleep(30);
818 818
 					} else $racebuffer = '';
819 819
 					$bufferm = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/GetLeaderboard.pl?misnr='.$mission['misnr']);
@@ -822,19 +822,19 @@  discard block
 block discarded – undo
822 822
 					$racebuffer = '';
823 823
 				}
824 824
 				if ($racebuffer != '') {
825
-					$race_data = json_decode($racebuffer,true);
825
+					$race_data = json_decode($racebuffer, true);
826 826
 					//print_r($race_data);
827 827
 					unset($racebuffer);
828 828
 					if (isset($race_data['mission'])) {
829 829
 					    $datar = array();
830 830
 					    $datar['id'] = $mission['misnr'];
831 831
 					    $datar['desc'] = $race_data['mission']['misdescr'];
832
-					    $datar['creator'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($race_data['mission']['usrname'])));
833
-					    $datar['name'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($race_data['mission']['mistitle'])));
832
+					    $datar['creator'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $Common->remove_accents($race_data['mission']['usrname'])));
833
+					    $datar['name'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $Common->remove_accents($race_data['mission']['mistitle'])));
834 834
 					    $datar['startdate'] = $race_data['mission']['misstartdatetime'];
835 835
 					    $markers = array();
836 836
 					    foreach ($race_data['mission']['course'] as $course) {
837
-						$markers[] = array('lat' => $course['miclat'],'lon' => $course['miclon'],'name' => $course['micname'],'type' => $course['mictype']);
837
+						$markers[] = array('lat' => $course['miclat'], 'lon' => $course['miclon'], 'name' => $course['micname'], 'type' => $course['mictype']);
838 838
 					    }
839 839
 					    $datar['markers'] = json_encode($markers);
840 840
 					    //print_r($datar);
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
 					}
843 843
 				}
844 844
 				if ($bufferm != '') {
845
-					$mission_data = json_decode($bufferm,true);
845
+					$mission_data = json_decode($bufferm, true);
846 846
 					unset($bufferm);
847 847
 					if (isset($mission_data['leaderboard'][0]['results'])) {
848 848
 						foreach ($mission_data['leaderboard'][0]['results'] as $sail) {
@@ -855,7 +855,7 @@  discard block
 block discarded – undo
855 855
 								//$data['id'] = $sail['misnr'].'-'.$sail['usrnr'].'-'.$sail['ubtnr'];
856 856
 								$data['id'] = $sail['misnr'].'-'.$sail['usrnr'];
857 857
 								$data['datetime'] = date('Y-m-d H:i:s');
858
-								$data['race_begin'] = date('Y-m-d H:i:s',strtotime($mission_data['leaderboard'][0]['misstart']));
858
+								$data['race_begin'] = date('Y-m-d H:i:s', strtotime($mission_data['leaderboard'][0]['misstart']));
859 859
 								$data['last_update'] = date('Y-m-d H:i:s');
860 860
 								$data['status'] = $sail['status'];
861 861
 								$data['type'] = $sail['btptype'];
@@ -866,16 +866,16 @@  discard block
 block discarded – undo
866 866
 									$data['longitude'] = $pos['longitude'];
867 867
 								}
868 868
 								if ($sail['status'] == 'Racing' && $sail['resultdescr'] != '-') {
869
-									$resultdescr = explode(',',$sail['resultdescr']);
869
+									$resultdescr = explode(',', $sail['resultdescr']);
870 870
 									if (count($resultdescr) > 2) {
871
-										$data['speed'] = round(str_replace(array('Spd: ','kn.'),'',trim($resultdescr[2]))*1.852,2);
872
-										$data['heading'] = str_replace(array('Hdg: ','°'),'',trim($resultdescr[1]));
871
+										$data['speed'] = round(str_replace(array('Spd: ', 'kn.'), '', trim($resultdescr[2]))*1.852, 2);
872
+										$data['heading'] = str_replace(array('Hdg: ', '°'), '', trim($resultdescr[1]));
873 873
 										if (isset($resultdescr[3])) {
874
-											$data['distance'] = round(str_replace('nm.','',trim(explode(' ',$resultdescr[3])[1]))*1.852,3);
874
+											$data['distance'] = round(str_replace('nm.', '', trim(explode(' ', $resultdescr[3])[1]))*1.852, 3);
875 875
 										}
876 876
 									}
877 877
 								}
878
-								$data['ident'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($sail['ubtname'])));
878
+								$data['ident'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $Common->remove_accents($sail['ubtname'])));
879 879
 								$data['captain_id'] = $sail['usrnr'];
880 880
 								$data['captain_name'] = $sail['usrname'];
881 881
 								$data['race_id'] = $sail['misnr'];
@@ -929,11 +929,11 @@  discard block
 block discarded – undo
929 929
 	    }
930 930
 	    if ($globalDebug) echo '! Download... ';
931 931
 	    $sailawayoption = array('key' => $globalSailaway['key']);
932
-	    if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
933
-	    if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
934
-	    $buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption),'get','','','','',30);
932
+	    if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption, array('usrnr' => $globalSailaway['usrnr']));
933
+	    if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption, array('ubtnr' => $globalSailaway['ubtnr']));
934
+	    $buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption), 'get', '', '', '', '', 30);
935 935
 	    if ($buffer != '') {
936
-		$data = json_decode($buffer,true);
936
+		$data = json_decode($buffer, true);
937 937
 		//print_r($data);
938 938
 		if (isset($data['boats'])) {
939 939
 		    foreach ($data['boats'] as $sail) {
@@ -945,12 +945,12 @@  discard block
 block discarded – undo
945 945
 			$data['longitude'] = $sail['ubtlon'];
946 946
 			$data['type_id'] = 36;
947 947
 			$data['heading'] = $sail['ubtheading'];
948
-			$data['ident'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',$Common->remove_accents($sail['ubtname'])));
948
+			$data['ident'] = trim(preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $Common->remove_accents($sail['ubtname'])));
949 949
 			$data['captain_name'] = $sail['usrname'];
950
-			$allboats = array('Sailaway Cruiser 38','Mini Transat','Caribbean Rose','52&#39; Cruising Cat','50&#39; Performance Cruiser','Nordic Folkboat');
950
+			$allboats = array('Sailaway Cruiser 38', 'Mini Transat', 'Caribbean Rose', '52&#39; Cruising Cat', '50&#39; Performance Cruiser', 'Nordic Folkboat');
951 951
 			$boattype = $sail['ubtbtpnr'];
952
-			if (isset($allboats[$boattype-1])) $data['type'] = $allboats[$boattype-1];
953
-			$data['speed'] = round($sail['ubtspeed']*3.6,2);
952
+			if (isset($allboats[$boattype - 1])) $data['type'] = $allboats[$boattype - 1];
953
+			$data['speed'] = round($sail['ubtspeed']*3.6, 2);
954 954
 			$data['format_source'] = 'sailaway';
955 955
 			$data['id_source'] = $id_source;
956 956
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -978,8 +978,8 @@  discard block
 block discarded – undo
978 978
 	) {
979 979
 	    //$buffer = $Common->getData($hosts[$id]);
980 980
 	    $buffer = $Common->getData($value['host']);
981
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
982
-	    $buffer = explode('\n',$buffer);
981
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
982
+	    $buffer = explode('\n', $buffer);
983 983
 	    $reset = 0;
984 984
 	    foreach ($buffer as $line) {
985 985
     		if ($line != '') {
@@ -990,7 +990,7 @@  discard block
 block discarded – undo
990 990
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
991 991
 			$data['pilot_id'] = $line[1];
992 992
 			$data['pilot_name'] = $line[2];
993
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
993
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
994 994
 			$data['ident'] = $line[0]; // ident
995 995
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
996 996
 			$data['speed'] = $line[8]; // speed
@@ -1006,7 +1006,7 @@  discard block
 block discarded – undo
1006 1006
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
1007 1007
 			//if (isset($line[37])) $data['last_update'] = $line[37];
1008 1008
 		        $data['departure_airport_icao'] = $line[11];
1009
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
1009
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
1010 1010
 		        $data['arrival_airport_icao'] = $line[13];
1011 1011
 			$data['frequency'] = $line[4];
1012 1012
 			$data['type'] = $line[18];
@@ -1015,7 +1015,7 @@  discard block
 block discarded – undo
1015 1015
     			$data['id_source'] = $id_source;
1016 1016
 	    		//$data['arrival_airport_time'] = ;
1017 1017
 	    		if ($line[9] != '') {
1018
-	    		    $aircraft_data = explode('/',$line[9]);
1018
+	    		    $aircraft_data = explode('/', $line[9]);
1019 1019
 	    		    if (isset($aircraft_data[1])) {
1020 1020
 	    			$data['aircraft_icao'] = $aircraft_data[1];
1021 1021
 	    		    }
@@ -1030,9 +1030,9 @@  discard block
 block discarded – undo
1030 1030
     			if ($line[3] === 'PILOT') $SI->add($data);
1031 1031
 			elseif ($line[3] === 'ATC') {
1032 1032
 				//print_r($data);
1033
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1034
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
1035
-				$typec = substr($data['ident'],-3);
1033
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
1034
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
1035
+				$typec = substr($data['ident'], -3);
1036 1036
 				if ($typec === 'APP') $data['type'] = 'Approach';
1037 1037
 				elseif ($typec === 'TWR') $data['type'] = 'Tower';
1038 1038
 				elseif ($typec === 'OBS') $data['type'] = 'Observer';
@@ -1044,8 +1044,8 @@  discard block
 block discarded – undo
1044 1044
 				elseif ($data['type'] === '') $data['type'] = 'Observer';
1045 1045
 				if (!isset($data['source_name'])) $data['source_name'] = '';
1046 1046
 				if (isset($ATC)) {
1047
-					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) echo $ATC->update($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']);
1048
-					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']);
1047
+					if (count($ATC->getByIdent($data['ident'], $data['format_source'])) > 0) echo $ATC->update($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']);
1048
+					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']);
1049 1049
 				}
1050 1050
 			}
1051 1051
     			unset($data);
@@ -1061,24 +1061,24 @@  discard block
 block discarded – undo
1061 1061
     		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1062 1062
     	    )
1063 1063
     	) {
1064
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
1064
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php', 'get', '', '', '', '', '20');
1065 1065
 	    if ($buffer != '') {
1066 1066
 		$all_data = simplexml_load_string($buffer);
1067
-		foreach($all_data->children() as $childdata) {
1067
+		foreach ($all_data->children() as $childdata) {
1068 1068
 			$data = array();
1069 1069
 			$line = $childdata;
1070 1070
 			//$data['hex'] = str_pad(dechex((int)$line['pktPilotID']),6,'000000',STR_PAD_LEFT);
1071
-			$data['id'] = date('Ymd').(int)$line['pktPilotID'];
1072
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
1073
-			$data['latitude'] = (float)$line['pktLatitude'];
1074
-			$data['longitude'] = (float)$line['pktLongitude'];
1075
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
1076
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
1077
-			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
1071
+			$data['id'] = date('Ymd').(int) $line['pktPilotID'];
1072
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['entryTime'].' BST'));
1073
+			$data['latitude'] = (float) $line['pktLatitude'];
1074
+			$data['longitude'] = (float) $line['pktLongitude'];
1075
+			if ((float) $line['pktTrack'] != 0) $data['heading'] = (float) $line['pktTrack'];
1076
+			if ((int) $line['pktSpeed'] != 0) $data['speed'] = (int) $line['pktSpeed'];
1077
+			$data['altitude'] = round((int) $line['pktAltitude']*3.28084);
1078 1078
 			$data['altitude_relative'] = 'AMSL';
1079
-			$data['pilot_id'] = (int)$line['pktPilotID'];
1079
+			$data['pilot_id'] = (int) $line['pktPilotID'];
1080 1080
 			$data['aircraft_icao'] = 'PARAGLIDER';
1081
-			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
1081
+			$pilot_data = explode(',', $Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
1082 1082
 			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
1083 1083
 			$data['format_source'] = $value['format'];
1084 1084
 			$SI->add($data);
@@ -1086,22 +1086,22 @@  discard block
 block discarded – undo
1086 1086
 		}
1087 1087
 	    }
1088 1088
 	    $Source->deleteOldLocationByType('gs');
1089
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
1089
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php', 'get', '', '', '', '', '20');
1090 1090
 	    if ($buffer != '') {
1091 1091
 		$all_data = simplexml_load_string($buffer);
1092
-		foreach($all_data->children() as $childdata) {
1092
+		foreach ($all_data->children() as $childdata) {
1093 1093
 			$data = array();
1094 1094
 			$line = $childdata;
1095
-			$data['id'] = (int)$line['gsID'];
1096
-			$data['latitude'] = (float)$line['gsLatitude'];
1097
-			$data['longitude'] = (float)$line['gsLongitude'];
1098
-			$data['altitude'] = round((int)$line['gsHeight']*3.28084);
1095
+			$data['id'] = (int) $line['gsID'];
1096
+			$data['latitude'] = (float) $line['gsLatitude'];
1097
+			$data['longitude'] = (float) $line['gsLongitude'];
1098
+			$data['altitude'] = round((int) $line['gsHeight']*3.28084);
1099 1099
 			$data['altitude_relative'] = 'AMSL';
1100
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['gsLastUpdate'].' BST'));
1100
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['gsLastUpdate'].' BST'));
1101 1101
 			if (count($Source->getLocationInfoByLocationID($data['id'])) > 0) {
1102
-				$Source->updateLocationByLocationID('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
1102
+				$Source->updateLocationByLocationID('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
1103 1103
 			} else {
1104
-				$Source->addLocation('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
1104
+				$Source->addLocation('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
1105 1105
 			}
1106 1106
 			unset($data);
1107 1107
 		}
@@ -1119,9 +1119,9 @@  discard block
 block discarded – undo
1119 1119
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1120 1120
 	    )
1121 1121
 	) {
1122
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
1122
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
1123 1123
 	    if ($buffer != '') {
1124
-	        $all_data = json_decode($buffer,true);
1124
+	        $all_data = json_decode($buffer, true);
1125 1125
 		if (isset($all_data['acList'])) {
1126 1126
 		    $reset = 0;
1127 1127
 		    foreach ($all_data['acList'] as $line) {
@@ -1137,7 +1137,7 @@  discard block
 block discarded – undo
1137 1137
 			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1138 1138
 			$data['emergency'] = ''; // emergency
1139 1139
 			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
1140
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1140
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
1141 1141
 			else $data['datetime'] = date('Y-m-d H:i:s');
1142 1142
 			//$data['datetime'] = date('Y-m-d H:i:s');
1143 1143
 			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
@@ -1162,7 +1162,7 @@  discard block
 block discarded – undo
1162 1162
 			$data['verticalrate'] = $line['vrt']; // verticale rate
1163 1163
 			$data['squawk'] = $line['squawk']; // squawk
1164 1164
 			$data['emergency'] = ''; // emergency
1165
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1165
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
1166 1166
 			else $data['datetime'] = date('Y-m-d H:i:s');
1167 1167
 			$data['format_source'] = 'aircraftlistjson';
1168 1168
 			$data['id_source'] = $id_source;
@@ -1183,7 +1183,7 @@  discard block
 block discarded – undo
1183 1183
     	    )
1184 1184
     	) {
1185 1185
 	    $buffer = $Common->getData($value['host']);
1186
-	    $all_data = json_decode($buffer,true);
1186
+	    $all_data = json_decode($buffer, true);
1187 1187
 	    if (isset($all_data['planes'])) {
1188 1188
 		$reset = 0;
1189 1189
 		foreach ($all_data['planes'] as $key => $line) {
@@ -1200,12 +1200,12 @@  discard block
 block discarded – undo
1200 1200
 		    $data['emergency'] = ''; // emergency
1201 1201
 		    $data['registration'] = $line[2];
1202 1202
 		    $data['aircraft_icao'] = $line[0];
1203
-		    $deparr = explode('-',$line[1]);
1203
+		    $deparr = explode('-', $line[1]);
1204 1204
 		    if (count($deparr) === 2) {
1205 1205
 			$data['departure_airport_icao'] = $deparr[0];
1206 1206
 			$data['arrival_airport_icao'] = $deparr[1];
1207 1207
 		    }
1208
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
1208
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
1209 1209
 	    	    $data['format_source'] = 'planeupdatefaa';
1210 1210
     		    $data['id_source'] = $id_source;
1211 1211
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1223,7 +1223,7 @@  discard block
 block discarded – undo
1223 1223
 	    )
1224 1224
 	) {
1225 1225
 	    $buffer = $Common->getData($value['host']);
1226
-	    $all_data = json_decode($buffer,true);
1226
+	    $all_data = json_decode($buffer, true);
1227 1227
 	    if (isset($all_data['states'])) {
1228 1228
 		$reset = 0;
1229 1229
 		foreach ($all_data['states'] as $key => $line) {
@@ -1240,7 +1240,7 @@  discard block
 block discarded – undo
1240 1240
 		    //$data['emergency'] = ''; // emergency
1241 1241
 		    //$data['registration'] = $line[2];
1242 1242
 		    //$data['aircraft_icao'] = $line[0];
1243
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1243
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
1244 1244
 		    $data['format_source'] = 'opensky';
1245 1245
 		    $data['id_source'] = $id_source;
1246 1246
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1257,8 +1257,8 @@  discard block
 block discarded – undo
1257 1257
 	    )
1258 1258
 	) {
1259 1259
 	    $buffer = $Common->getData($value['host']);
1260
-	    $all_data = json_decode($buffer,true);
1261
-	    if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time()-1800) {
1260
+	    $all_data = json_decode($buffer, true);
1261
+	    if (isset($all_data['aircraft']) && isset($all_data['now']) && $all_data['now'] > time() - 1800) {
1262 1262
 		$reset = 0;
1263 1263
 		foreach ($all_data['aircraft'] as $key => $line) {
1264 1264
 		    $data = array();
@@ -1296,7 +1296,7 @@  discard block
 block discarded – undo
1296 1296
 	    )
1297 1297
 	) {
1298 1298
 	    $buffer = $Common->getData($value['host']);
1299
-	    $all_data = json_decode($buffer,true);
1299
+	    $all_data = json_decode($buffer, true);
1300 1300
 	    if (isset($all_data['aircraft'])) {
1301 1301
 		$reset = 0;
1302 1302
 		foreach ($all_data['aircraft'] as $key => $line) {
@@ -1313,7 +1313,7 @@  discard block
 block discarded – undo
1313 1313
 		    //$data['emergency'] = ''; // emergency
1314 1314
 		    if (isset($line['reg'])) $data['registration'] = $line['reg'];
1315 1315
 		    if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1316
-		    $data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1316
+		    $data['datetime'] = date('Y-m-d H:i:s', $line['pos_update_time']);
1317 1317
 		    $data['format_source'] = 'planefinderclient';
1318 1318
 		    $data['id_source'] = $id_source;
1319 1319
 		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -1332,7 +1332,7 @@  discard block
 block discarded – undo
1332 1332
 	) {
1333 1333
 	    //$buffer = $Common->getData($hosts[$id]);
1334 1334
 	    $buffer = $Common->getData($value['host']);
1335
-	    $all_data = json_decode($buffer,true);
1335
+	    $all_data = json_decode($buffer, true);
1336 1336
 	    if (!empty($all_data)) $reset = 0;
1337 1337
 	    foreach ($all_data as $key => $line) {
1338 1338
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -1370,11 +1370,11 @@  discard block
 block discarded – undo
1370 1370
 	    )
1371 1371
 	) {
1372 1372
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1373
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
1373
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
1374 1374
 	    //echo $buffer;
1375
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
1376
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1377
-	    $all_data = json_decode($buffer,true);
1375
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
1376
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
1377
+	    $all_data = json_decode($buffer, true);
1378 1378
 	    if (json_last_error() != JSON_ERROR_NONE) {
1379 1379
 		die(json_last_error_msg());
1380 1380
 	    }
@@ -1397,7 +1397,7 @@  discard block
 block discarded – undo
1397 1397
 			//$data['departure_airport_iata'] = $line[11];
1398 1398
 			//$data['arrival_airport_iata'] = $line[12];
1399 1399
 	    		//$data['emergency'] = ''; // emergency
1400
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1400
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
1401 1401
 	    		$data['format_source'] = 'radarvirtueljson';
1402 1402
     			$data['id_source'] = $id_source;
1403 1403
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1418,14 +1418,14 @@  discard block
 block discarded – undo
1418 1418
 	) {
1419 1419
 	    //$buffer = $Common->getData($hosts[$id]);
1420 1420
 	    $buffer = $Common->getData($value['host'].'?'.time());
1421
-	    $all_data = json_decode(utf8_encode($buffer),true);
1421
+	    $all_data = json_decode(utf8_encode($buffer), true);
1422 1422
 	    
1423 1423
 	    if (isset($all_data['pireps'])) {
1424 1424
 		$reset = 0;
1425 1425
 	        foreach ($all_data['pireps'] as $line) {
1426 1426
 		    $data = array();
1427 1427
 		    $data['id'] = $line['id'];
1428
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1428
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
1429 1429
 		    $data['ident'] = $line['callsign']; // ident
1430 1430
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1431 1431
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -1455,9 +1455,9 @@  discard block
 block discarded – undo
1455 1455
 			$SI->add($data);
1456 1456
 		    //    print_r($data);
1457 1457
     		    } elseif ($line['icon'] === 'ct') {
1458
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1459
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1460
-			$typec = substr($data['ident'],-3);
1458
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
1459
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
1460
+			$typec = substr($data['ident'], -3);
1461 1461
 			$data['type'] = '';
1462 1462
 			if ($typec === 'APP') $data['type'] = 'Approach';
1463 1463
 			elseif ($typec === 'TWR') $data['type'] = 'Tower';
@@ -1468,7 +1468,7 @@  discard block
 block discarded – undo
1468 1468
 			elseif ($typec === 'FSS') $data['type'] = 'Flight Service Station';
1469 1469
 			elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
1470 1470
 			else $data['type'] = 'Observer';
1471
-			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']);
1471
+			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']);
1472 1472
 		    }
1473 1473
 		    unset($data);
1474 1474
 		}
@@ -1485,14 +1485,14 @@  discard block
 block discarded – undo
1485 1485
 	    //$buffer = $Common->getData($hosts[$id]);
1486 1486
 	    if ($globalDebug) echo 'Get Data...'."\n";
1487 1487
 	    $buffer = $Common->getData($value['host']);
1488
-	    $all_data = json_decode($buffer,true);
1488
+	    $all_data = json_decode($buffer, true);
1489 1489
 	    if ($buffer != '' && is_array($all_data)) {
1490 1490
 		$reset = 0;
1491 1491
 		foreach ($all_data as $line) {
1492 1492
 	    	    $data = array();
1493 1493
 	    	    //$data['id'] = $line['id']; // id not usable
1494 1494
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1495
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1495
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
1496 1496
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1497 1497
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1498 1498
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -1507,7 +1507,7 @@  discard block
 block discarded – undo
1507 1507
 	    	    //$data['datetime'] = $line['lastupdate'];
1508 1508
 	    	    //$data['last_update'] = $line['lastupdate'];
1509 1509
 	    	    if (isset($value['timezone'])) {
1510
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1510
+	    		$datetime = new DateTime($line['lastupdate'], new DateTimeZone($value['timezone']));
1511 1511
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1512 1512
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1513 1513
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1523,14 +1523,14 @@  discard block
 block discarded – undo
1523 1523
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1524 1524
 		    if (isset($line['aircraftname'])) {
1525 1525
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1526
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1527
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1526
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
1527
+	    		$aircraft_data = explode('-', $line['aircraftname']);
1528 1528
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1529 1529
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1530 1530
 	    		else {
1531
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1532
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1533
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1531
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
1532
+	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-', '', $aircraft_data[1]);
1533
+	    		    else $data['aircraft_icao'] = str_replace('-', '', $line['aircraftname']);
1534 1534
 	    		}
1535 1535
 	    	    }
1536 1536
     		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
@@ -1555,7 +1555,7 @@  discard block
 block discarded – undo
1555 1555
 	    //$buffer = $Common->getData($hosts[$id]);
1556 1556
 	    if ($globalDebug) echo 'Get Data...'."\n";
1557 1557
 	    $buffer = $Common->getData($value['host']);
1558
-	    $all_data = json_decode($buffer,true);
1558
+	    $all_data = json_decode($buffer, true);
1559 1559
 	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
1560 1560
 		$reset = 0;
1561 1561
 		foreach ($all_data['ACARSData'] as $line) {
@@ -1566,7 +1566,7 @@  discard block
 block discarded – undo
1566 1566
 	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1567 1567
 	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1568 1568
 	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1569
-	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1569
+	    	    $data['ident'] = str_replace(' ', '', $line['bid']['flightnum']); // ident
1570 1570
 	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1571 1571
 	    	    $data['altitude'] = $line['altitude']; // altitude
1572 1572
 	    	    $data['speed'] = $line['groundspeed']; // speed
@@ -1577,7 +1577,7 @@  discard block
 block discarded – undo
1577 1577
 	    	    //$data['squawk'] = ''; // squawk
1578 1578
 	    	    //$data['emergency'] = ''; // emergency
1579 1579
 	    	    if (isset($value['timezone'])) {
1580
-	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1580
+	    		$datetime = new DateTime($line['updated_at'], new DateTimeZone($value['timezone']));
1581 1581
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1582 1582
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1583 1583
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1613,14 +1613,14 @@  discard block
 block discarded – undo
1613 1613
 	    //$buffer = $Common->getData($hosts[$id]);
1614 1614
 	    if ($globalDebug) echo 'Get Data...'."\n";
1615 1615
 	    $buffer = $Common->getData($value['host']);
1616
-	    $all_data = json_decode($buffer,true);
1616
+	    $all_data = json_decode($buffer, true);
1617 1617
 	    if ($buffer != '' && is_array($all_data)) {
1618 1618
 		$reset = 0;
1619 1619
 		foreach ($all_data as $line) {
1620 1620
 	    	    $data = array();
1621 1621
 	    	    //$data['id'] = $line['id']; // id not usable
1622 1622
 	    	    $data['id'] = trim($line['flight_id']);
1623
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1623
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
1624 1624
 	    	    $data['pilot_name'] = $line['pilot_name'];
1625 1625
 	    	    $data['pilot_id'] = $line['pilot_id'];
1626 1626
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -1664,24 +1664,24 @@  discard block
 block discarded – undo
1664 1664
 	    //$buffer = $Common->getData($hosts[$id]);
1665 1665
 	    if ($globalDebug) echo 'Get Data...'."\n";
1666 1666
 	    $buffer = $Common->getData($value['host']);
1667
-	    $all_data = json_decode($buffer,true);
1667
+	    $all_data = json_decode($buffer, true);
1668 1668
 	    if ($buffer != '') {
1669 1669
 		$Source->deleteLocationBySource('blitzortung');
1670
-		$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1671
-		$buffer = explode('\n',$buffer);
1670
+		$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
1671
+		$buffer = explode('\n', $buffer);
1672 1672
 		foreach ($buffer as $buffer_line) {
1673
-		    $line = json_decode($buffer_line,true);
1673
+		    $line = json_decode($buffer_line, true);
1674 1674
 		    if (isset($line['time'])) {
1675 1675
 			$data = array();
1676 1676
 			$data['altitude'] = $line['alt']; // altitude
1677 1677
 			$data['latitude'] = $line['lat']; // lat
1678 1678
 			$data['longitude'] = $line['lon']; // long
1679
-			$data['datetime'] = date('Y-m-d H:i:s',substr($line['time'],0,10));
1679
+			$data['datetime'] = date('Y-m-d H:i:s', substr($line['time'], 0, 10));
1680 1680
 			$data['id_source'] = $id_source;
1681 1681
 			$data['format_source'] = 'blitzortung';
1682 1682
 			$SI->add($data);
1683 1683
 			if ($globalDebug) echo '☈ Lightning added'."\n";
1684
-			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1684
+			$Source->addLocation('', $data['latitude'], $data['longitude'], 0, '', '', 'blitzortung', 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime']);
1685 1685
 			unset($data);
1686 1686
 		    }
1687 1687
 		}
@@ -1693,15 +1693,15 @@  discard block
 block discarded – undo
1693 1693
         $arr = $httpfeeds;
1694 1694
         $w = $e = null;
1695 1695
         if (isset($arr[$id])) {
1696
-            $nn = stream_select($arr,$w,$e,$timeout);
1696
+            $nn = stream_select($arr, $w, $e, $timeout);
1697 1697
             if ($nn > 0) {
1698 1698
                 foreach ($httpfeeds as $feed) {
1699
-                    $buffer = stream_get_line($feed,2000,"\n");
1699
+                    $buffer = stream_get_line($feed, 2000, "\n");
1700 1700
                     if ($buffer === FALSE) {
1701 1701
                         connect_all($globalSources);
1702 1702
                     }
1703
-                    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1704
-                    $buffer = explode('\n',$buffer);
1703
+                    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
1704
+                    $buffer = explode('\n', $buffer);
1705 1705
                     foreach ($buffer as $line) {
1706 1706
                         if ($line != '') {
1707 1707
                             $line = json_decode($line, true);
@@ -1741,11 +1741,11 @@  discard block
 block discarded – undo
1741 1741
 		    //$value = $formats[$nb];
1742 1742
 		    $format = $globalSources[$nb]['format'];
1743 1743
 		    if ($format === 'sbs' || $format === 'aprs' || $format === 'famaprs' || $format === 'raw' || $format === 'tsv' || $format === 'acarssbs3') {
1744
-			$buffer = @socket_read($r, 6000,PHP_NORMAL_READ);
1744
+			$buffer = @socket_read($r, 6000, PHP_NORMAL_READ);
1745 1745
 		    } elseif ($format === 'vrstcp') {
1746 1746
 			$buffer = @socket_read($r, 6000);
1747 1747
 		    } else {
1748
-			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1748
+			$az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
1749 1749
 		    }
1750 1750
 		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1751 1751
 		    //echo $buffer."\n";
@@ -1755,8 +1755,8 @@  discard block
 block discarded – undo
1755 1755
 		    //$SI::del();
1756 1756
 		    if ($buffer !== FALSE) {
1757 1757
 			if ($format === 'vrstcp') {
1758
-			    $buffer = explode('},{',$buffer);
1759
-			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1758
+			    $buffer = explode('},{', $buffer);
1759
+			} else $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
1760 1760
 		    }
1761 1761
 		    // SBS format is CSV format
1762 1762
 		    if ($buffer !== FALSE && $buffer !== '') {
@@ -1783,7 +1783,7 @@  discard block
 block discarded – undo
1783 1783
 			    $ais_data = $AIS->parse_line(trim($buffer));
1784 1784
 			    $data = array();
1785 1785
 			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1786
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1786
+			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9);
1787 1787
 			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1788 1788
 			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1789 1789
 			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
@@ -1794,13 +1794,13 @@  discard block
 block discarded – undo
1794 1794
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1795 1795
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1796 1796
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1797
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1797
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1798 1798
 			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1799 1799
 			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1800 1800
 			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1801 1801
 
1802 1802
 			    if (isset($ais_data['timestamp'])) {
1803
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1803
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1804 1804
 			    } else {
1805 1805
 				$data['datetime'] = date('Y-m-d H:i:s');
1806 1806
 			    }
@@ -1811,10 +1811,10 @@  discard block
 block discarded – undo
1811 1811
                         } elseif ($format === 'flightgearsp') {
1812 1812
                     	    //echo $buffer."\n";
1813 1813
                     	    if (strlen($buffer) > 5) {
1814
-				$line = explode(',',$buffer);
1814
+				$line = explode(',', $buffer);
1815 1815
 				$data = array();
1816 1816
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1817
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1817
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1818 1818
 				$data['ident'] = $line[6];
1819 1819
 				$data['aircraft_name'] = $line[7];
1820 1820
 				$data['longitude'] = $line[1];
@@ -1831,25 +1831,25 @@  discard block
 block discarded – undo
1831 1831
                         } elseif ($format === 'acars') {
1832 1832
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1833 1833
 			    $ACARS->add(trim($buffer));
1834
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1834
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1835 1835
 			    $ACARS->deleteLiveAcarsData();
1836 1836
 			} elseif ($format === 'acarsjsonudp') {
1837 1837
 			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1838 1838
                             $line = json_decode(trim($buffer), true);
1839 1839
                             if (!empty($line)) {
1840
-				$line = array_merge(array('text' => '','tail' => '','label' => '','block_id' => '','flight' => '','msgno' => ''),$line);
1840
+				$line = array_merge(array('text' => '', 'tail' => '', 'label' => '', 'block_id' => '', 'flight' => '', 'msgno' => ''), $line);
1841 1841
                                 $ACARS->add(isset($line['text']) ? $line['text'] : '', array('registration' => str_replace('.', '', $line['tail']), 'ident' => $line['flight'], 'label' => $line['label'], 'block_id' => $line['block_id'], 'msg_no' => $line['msgno'], 'message' => (isset($line['text']) ? $line['text'] : '')));
1842 1842
                                 $ACARS->deleteLiveAcarsData();
1843 1843
                             }
1844
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1844
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1845 1845
 			} elseif ($format === 'flightgearmp') {
1846
-			    if (substr($buffer,0,1) != '#') {
1846
+			    if (substr($buffer, 0, 1) != '#') {
1847 1847
 				$data = array();
1848 1848
 				//echo $buffer."\n";
1849
-				$line = explode(' ',$buffer);
1849
+				$line = explode(' ', $buffer);
1850 1850
 				if (count($line) === 11) {
1851
-				    $userserver = explode('@',$line[0]);
1852
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1851
+				    $userserver = explode('@', $line[0]);
1852
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1853 1853
 				    $data['ident'] = $userserver[0];
1854 1854
 				    $data['registration'] = $userserver[0];
1855 1855
 				    $data['latitude'] = $line[4];
@@ -1857,8 +1857,8 @@  discard block
 block discarded – undo
1857 1857
 				    $data['altitude'] = $line[6];
1858 1858
 				    $data['datetime'] = date('Y-m-d H:i:s');
1859 1859
 				    $aircraft_type = $line[10];
1860
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1861
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1860
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1861
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1862 1862
 				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1863 1863
 				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1864 1864
 				}
@@ -1867,8 +1867,8 @@  discard block
 block discarded – undo
1867 1867
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1868 1868
 			    die;
1869 1869
 			} elseif ($format === 'vrstcp') {
1870
-			    foreach($buffer as $all_data) {
1871
-				$line = json_decode('{'.$all_data.'}',true);
1870
+			    foreach ($buffer as $all_data) {
1871
+				$line = json_decode('{'.$all_data.'}', true);
1872 1872
 				$data = array();
1873 1873
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1874 1874
 				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1894,16 +1894,16 @@  discard block
 block discarded – undo
1894 1894
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1895 1895
 				unset($data);
1896 1896
 			    }
1897
-			} elseif ($format === 'tsv' || substr($buffer,0,4) === 'clock') {
1897
+			} elseif ($format === 'tsv' || substr($buffer, 0, 4) === 'clock') {
1898 1898
 			    $line = explode("\t", $buffer);
1899
-			    for($k = 0; $k < count($line); $k=$k+2) {
1899
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1900 1900
 				$key = $line[$k];
1901
-			        $lined[$key] = $line[$k+1];
1901
+			        $lined[$key] = $line[$k + 1];
1902 1902
 			    }
1903 1903
     			    if (count($lined) > 3) {
1904 1904
     				$data['hex'] = $lined['hexid'];
1905 1905
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1906
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1906
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1907 1907
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1908 1908
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1909 1909
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1922,23 +1922,23 @@  discard block
 block discarded – undo
1922 1922
     			    } else $error = true;
1923 1923
 			} elseif ($format === 'aprs' && $use_aprs) {
1924 1924
 			    if ($aprs_connect === 0) {
1925
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1925
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
1926 1926
 				$aprs_connect = 1;
1927 1927
 			    }
1928 1928
 			    
1929
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1929
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
1930 1930
 				$aprs_last_tx = time();
1931 1931
 				$data_aprs = "# Keep alive";
1932
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1932
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1933 1933
 			    }
1934 1934
 			    
1935 1935
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1936 1936
 			    //echo 'APRS data : '.$buffer."\n";
1937
-			    $buffer = str_replace('APRS <- ','',$buffer);
1938
-			    $buffer = str_replace('APRS -> ','',$buffer);
1937
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1938
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1939 1939
 			    //echo $buffer."\n";
1940 1940
 			    date_default_timezone_set('UTC');
1941
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1941
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
1942 1942
 				$line = $APRS->parse($buffer);
1943 1943
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1944 1944
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
@@ -1953,7 +1953,7 @@  discard block
 block discarded – undo
1953 1953
 				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1954 1954
 				    if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1955 1955
 				    if (isset($line['statusid'])) $data['status_id'] = $line['statusid'];
1956
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1956
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1957 1957
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1958 1958
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1959 1959
 				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
@@ -2041,29 +2041,29 @@  discard block
 block discarded – undo
2041 2041
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
2042 2042
 					if (!isset($data['altitude'])) $data['altitude'] = 0;
2043 2043
 					$Source->deleteOldLocationByType('gs');
2044
-					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
2045
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
2044
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'gs')) > 0) {
2045
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
2046 2046
 					} else {
2047
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
2047
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
2048 2048
 					}
2049 2049
 				    } elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
2050 2050
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
2051 2051
 					if ($globalDebug) echo '# Weather Station added'."\n";
2052 2052
 					$Source->deleteOldLocationByType('wx');
2053 2053
 					$weather_data = json_encode($line);
2054
-					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
2055
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
2054
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'wx')) > 0) {
2055
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
2056 2056
 					} else {
2057
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
2057
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
2058 2058
 					}
2059 2059
 				    } elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
2060 2060
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
2061 2061
 					if ($globalDebug) echo '☈ Lightning added'."\n";
2062 2062
 					$Source->deleteOldLocationByType('lightning');
2063
-					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
2064
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
2063
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'lightning')) > 0) {
2064
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
2065 2065
 					} else {
2066
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
2066
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
2067 2067
 					}
2068 2068
 				    } elseif ($globalDebug) {
2069 2069
 				    	echo '/!\ Not added: '.$buffer."\n";
@@ -2072,7 +2072,7 @@  discard block
 block discarded – undo
2072 2072
 				    unset($data);
2073 2073
 				}
2074 2074
 				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
2075
-					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
2075
+					$Source->updateLocationDescByName($line['ident'], $line['source'], $id, $line['comment']);
2076 2076
 				}
2077 2077
 				/*
2078 2078
 				elseif (is_array($line) && $globalDebug && 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')) {
@@ -2081,7 +2081,7 @@  discard block
 block discarded – undo
2081 2081
 				*/
2082 2082
 				//elseif ($line === false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
2083 2083
 				elseif ($line === true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
2084
-				if (isset($Source) && isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
2084
+				if (isset($Source) && isset($globalSources[$nb]['last_weather_clean']) && time() - $globalSources[$nb]['last_weather_clean'] > 60*5) {
2085 2085
 					$Source->deleteOldLocationByType('lightning');
2086 2086
 					$Source->deleteOldLocationByType('wx');
2087 2087
 					$globalSources[$nb]['last_weather_clean'] = time();
@@ -2168,7 +2168,7 @@  discard block
 block discarded – undo
2168 2168
 				connect_all($sourceee);
2169 2169
 				$sourceee = array();
2170 2170
 				//connect_all($globalSources);
2171
-				$tt[$format]=0;
2171
+				$tt[$format] = 0;
2172 2172
 				break;
2173 2173
 			    } 
2174 2174
 			    //else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."...";
@@ -2178,14 +2178,14 @@  discard block
 block discarded – undo
2178 2178
 	    } else {
2179 2179
 		$error = socket_strerror(socket_last_error());
2180 2180
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
2181
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
2181
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
2182 2182
 			if (isset($globalDebug)) echo "Restarting...\n";
2183 2183
 			// Restart the script if possible
2184 2184
 			if (is_array($sockets)) {
2185 2185
 			    if ($globalDebug) echo "Shutdown all sockets...";
2186 2186
 			    
2187 2187
 			    foreach ($sockets as $sock) {
2188
-				@socket_shutdown($sock,2);
2188
+				@socket_shutdown($sock, 2);
2189 2189
 				@socket_close($sock);
2190 2190
 			    }
2191 2191
 			    
Please login to merge, or discard this patch.
Braces   +1260 added lines, -424 removed lines patch added patch discarded remove patch
@@ -22,7 +22,9 @@  discard block
 block discarded – undo
22 22
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
23 23
 }
24 24
 
25
-if (!isset($globalDebug)) $globalDebug = FALSE;
25
+if (!isset($globalDebug)) {
26
+	$globalDebug = FALSE;
27
+}
26 28
 
27 29
 if ($globalInstalled === FALSE) {
28 30
     echo "This script MUST be run after install script. Use your web browser to run install/index.php";
@@ -68,66 +70,107 @@  discard block
 block discarded – undo
68 70
 //elseif (isset($options['source'])) $hosts = array($options['source']);
69 71
 if (isset($options['s'])) {
70 72
     $globalSources = array();
71
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
72
-    else $globalSources[] = array('host' => $options['s']);
73
-} elseif (isset($options['source'])) {
73
+    if (isset($options['format'])) {
74
+    	$globalSources[] = array('host' => $options['s'],'format' => $options['format']);
75
+    } else {
76
+    	$globalSources[] = array('host' => $options['s']);
77
+    }
78
+    } elseif (isset($options['source'])) {
74 79
     $globalSources = array();
75
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
76
-    else $globalSources[] = array('host' => $options['source']);
77
-}
80
+    if (isset($options['format'])) {
81
+    	$globalSources[] = array('host' => $options['source'],'format' => $options['format']);
82
+    } else {
83
+    	$globalSources[] = array('host' => $options['source']);
84
+    }
85
+    }
78 86
 if (isset($options['aprsserverhost'])) {
79 87
 	$globalServerAPRS = TRUE;
80 88
 	$globalServerAPRShost = $options['aprsserverhost'];
81 89
 }
82
-if (isset($options['aprsserverport'])) $globalServerAPRSport = $options['aprsserverport'];
83
-if (isset($options['aprsserverssid'])) $globalServerAPRSssid = $options['aprsserverssid'];
84
-if (isset($options['aprsserverpass'])) $globalServerAPRSpass = $options['aprsserverpass'];
85
-if (isset($options['noaprsserver'])) $globalServerAPRS = FALSE; 
90
+if (isset($options['aprsserverport'])) {
91
+	$globalServerAPRSport = $options['aprsserverport'];
92
+}
93
+if (isset($options['aprsserverssid'])) {
94
+	$globalServerAPRSssid = $options['aprsserverssid'];
95
+}
96
+if (isset($options['aprsserverpass'])) {
97
+	$globalServerAPRSpass = $options['aprsserverpass'];
98
+}
99
+if (isset($options['noaprsserver'])) {
100
+	$globalServerAPRS = FALSE;
101
+}
86 102
 if (isset($options['enable-aircraft'])) {
87
-	if ($globalDebug) echo 'Enable Aircraft mode'."\n";
103
+	if ($globalDebug) {
104
+		echo 'Enable Aircraft mode'."\n";
105
+	}
88 106
 	$globalAircraft = TRUE; 
89 107
 }
90 108
 if (isset($options['disable-aircraft'])) {
91
-	if ($globalDebug) echo 'Disable Aircraft mode'."\n";
109
+	if ($globalDebug) {
110
+		echo 'Disable Aircraft mode'."\n";
111
+	}
92 112
 	$globalAircraft = FALSE;
93 113
 }
94 114
 if (isset($options['enable-tracker'])) {
95
-	if ($globalDebug) echo 'Enable Tracker mode'."\n";
115
+	if ($globalDebug) {
116
+		echo 'Enable Tracker mode'."\n";
117
+	}
96 118
 	$globalTracker = TRUE; 
97 119
 }
98 120
 if (isset($options['disable-tracker'])) {
99
-	if ($globalDebug) echo 'Disable Tracker mode'."\n";
121
+	if ($globalDebug) {
122
+		echo 'Disable Tracker mode'."\n";
123
+	}
100 124
 	$globalTracker = FALSE;
101 125
 }
102 126
 if (isset($options['enable-marine'])) {
103
-	if ($globalDebug) echo 'Enable Marine mode'."\n";
127
+	if ($globalDebug) {
128
+		echo 'Enable Marine mode'."\n";
129
+	}
104 130
 	$globalMarine = TRUE;
105 131
 }
106 132
 if (isset($options['disable-marine'])) {
107
-	if ($globalDebug) echo 'Disable Marine mode'."\n";
133
+	if ($globalDebug) {
134
+		echo 'Disable Marine mode'."\n";
135
+	}
108 136
 	$globalMarine = FALSE;
109 137
 }
110
-if (isset($options['nodaemon'])) $globalDaemon = FALSE;
111
-if (isset($options['server'])) $globalServer = TRUE;
112
-if (isset($options['idsource'])) $id_source = $options['idsource'];
113
-else $id_source = 1;
138
+if (isset($options['nodaemon'])) {
139
+	$globalDaemon = FALSE;
140
+}
141
+if (isset($options['server'])) {
142
+	$globalServer = TRUE;
143
+}
144
+if (isset($options['idsource'])) {
145
+	$id_source = $options['idsource'];
146
+} else {
147
+	$id_source = 1;
148
+}
114 149
 if (isset($globalServer) && $globalServer) {
115
-    if ($globalDebug) echo "Using Server Mode\n";
150
+    if ($globalDebug) {
151
+    	echo "Using Server Mode\n";
152
+    }
116 153
     $SI=new SpotterServer();
117 154
 /*
118 155
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
119 156
     $SI = new adsb2aprs();
120 157
     $SI->connect();
121 158
 */
122
-} else $SI=new SpotterImport($Connection->db);
159
+} else {
160
+	$SI=new SpotterImport($Connection->db);
161
+}
123 162
 
124
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
163
+if (isset($globalTracker) && $globalTracker) {
164
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
165
+}
125 166
 if (isset($globalMarine) && $globalMarine) {
126 167
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
127 168
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
128 169
 }
129 170
 
130
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
171
+if (isset($globalTracker) && $globalTracker) {
172
+	$TI = new TrackerImport($Connection->db);
173
+}
131 174
 if (isset($globalMarine) && $globalMarine) {
132 175
     $AIS = new AIS();
133 176
     $MI = new MarineImport($Connection->db);
@@ -152,7 +195,9 @@  discard block
 block discarded – undo
152 195
 }
153 196
 
154 197
 // let's try and connect
155
-if ($globalDebug) echo "Connecting...\n";
198
+if ($globalDebug) {
199
+	echo "Connecting...\n";
200
+}
156 201
 $use_aprs = false;
157 202
 $aprs_full = false;
158 203
 $reset = 0;
@@ -161,7 +206,9 @@  discard block
 block discarded – undo
161 206
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
162 207
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
163 208
     $reset++;
164
-    if ($globalDebug) echo 'Connect to all...'."\n";
209
+    if ($globalDebug) {
210
+    	echo 'Connect to all...'."\n";
211
+    }
165 212
     foreach ($hosts as $id => $value) {
166 213
 	$host = $value['host'];
167 214
 	$udp = false;
@@ -172,32 +219,44 @@  discard block
 block discarded – undo
172 219
         	//$formats[$id] = 'deltadbtxt';
173 220
         	$globalSources[$id]['format'] = 'deltadbtxt';
174 221
         	//$last_exec['deltadbtxt'] = 0;
175
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
222
+        	if ($globalDebug) {
223
+        		echo "Connect to deltadb source (".$host.")...\n";
224
+        	}
176 225
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
177 226
         	//$formats[$id] = 'vatsimtxt';
178 227
         	$globalSources[$id]['format'] = 'vatsimtxt';
179 228
         	//$last_exec['vatsimtxt'] = 0;
180
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
229
+        	if ($globalDebug) {
230
+        		echo "Connect to vatsim source (".$host.")...\n";
231
+        	}
181 232
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
182 233
         	//$formats[$id] = 'aircraftlistjson';
183 234
         	$globalSources[$id]['format'] = 'aircraftlistjson';
184 235
         	//$last_exec['aircraftlistjson'] = 0;
185
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
236
+        	if ($globalDebug) {
237
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
238
+        	}
186 239
     	    } else if (preg_match('/aircraft.json$/i',$host)) {
187 240
         	//$formats[$id] = 'aircraftjson';
188 241
         	$globalSources[$id]['format'] = 'aircraftjson';
189 242
         	//$last_exec['aircraftlistjson'] = 0;
190
-        	if ($globalDebug) echo "Connect to aircraft.json source (".$host.")...\n";
243
+        	if ($globalDebug) {
244
+        		echo "Connect to aircraft.json source (".$host.")...\n";
245
+        	}
191 246
     	    } else if (preg_match('/aircraft$/i',$host)) {
192 247
         	//$formats[$id] = 'planefinderclient';
193 248
         	$globalSources[$id]['format'] = 'planefinderclient';
194 249
         	//$last_exec['aircraftlistjson'] = 0;
195
-        	if ($globalDebug) echo "Connect to planefinderclient source (".$host.")...\n";
250
+        	if ($globalDebug) {
251
+        		echo "Connect to planefinderclient source (".$host.")...\n";
252
+        	}
196 253
     	    } else if (preg_match('/opensky/i',$host)) {
197 254
         	//$formats[$id] = 'aircraftlistjson';
198 255
         	$globalSources[$id]['format'] = 'opensky';
199 256
         	//$last_exec['aircraftlistjson'] = 0;
200
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
257
+        	if ($globalDebug) {
258
+        		echo "Connect to opensky source (".$host.")...\n";
259
+        	}
201 260
     	    /*
202 261
     	    // Disabled for now, site change source format
203 262
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
@@ -214,7 +273,9 @@  discard block
 block discarded – undo
214 273
         	//$formats[$id] = 'planeupdatefaa';
215 274
         	$globalSources[$id]['format'] = 'planeupdatefaa';
216 275
         	//$last_exec['planeupdatefaa'] = 0;
217
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
276
+        	if ($globalDebug) {
277
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
278
+        	}
218 279
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
219 280
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
220 281
         	    exit(0);
@@ -223,37 +284,53 @@  discard block
 block discarded – undo
223 284
         	//$formats[$id] = 'phpvmacars';
224 285
         	$globalSources[$id]['format'] = 'phpvmacars';
225 286
         	//$last_exec['phpvmacars'] = 0;
226
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
287
+        	if ($globalDebug) {
288
+        		echo "Connect to phpvmacars source (".$host.")...\n";
289
+        	}
227 290
             } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
228 291
         	//$formats[$id] = 'phpvmacars';
229 292
         	$globalSources[$id]['format'] = 'vaos';
230 293
         	//$last_exec['phpvmacars'] = 0;
231
-        	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
294
+        	if ($globalDebug) {
295
+        		echo "Connect to vaos source (".$host.")...\n";
296
+        	}
232 297
             } else if (preg_match('/VAM-json.php$/i',$host)) {
233 298
         	//$formats[$id] = 'phpvmacars';
234 299
         	$globalSources[$id]['format'] = 'vam';
235
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
300
+        	if ($globalDebug) {
301
+        		echo "Connect to Vam source (".$host.")...\n";
302
+        	}
236 303
             } else if (preg_match('/whazzup/i',$host)) {
237 304
         	//$formats[$id] = 'whazzup';
238 305
         	$globalSources[$id]['format'] = 'whazzup';
239 306
         	//$last_exec['whazzup'] = 0;
240
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
307
+        	if ($globalDebug) {
308
+        		echo "Connect to whazzup source (".$host.")...\n";
309
+        	}
241 310
             } else if (preg_match('/blitzortung/i',$host)) {
242 311
         	$globalSources[$id]['format'] = 'blitzortung';
243
-        	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
312
+        	if ($globalDebug) {
313
+        		echo "Connect to blitzortung source (".$host.")...\n";
314
+        	}
244 315
             } else if (preg_match('/airwhere/i',$host)) {
245 316
         	$globalSources[$id]['format'] = 'airwhere';
246
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
317
+        	if ($globalDebug) {
318
+        		echo "Connect to airwhere source (".$host.")...\n";
319
+        	}
247 320
             } else if (preg_match('/recentpireps/i',$host)) {
248 321
         	//$formats[$id] = 'pirepsjson';
249 322
         	$globalSources[$id]['format'] = 'pirepsjson';
250 323
         	//$last_exec['pirepsjson'] = 0;
251
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
324
+        	if ($globalDebug) {
325
+        		echo "Connect to pirepsjson source (".$host.")...\n";
326
+        	}
252 327
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
253 328
         	//$formats[$id] = 'fr24json';
254 329
         	$globalSources[$id]['format'] = 'fr24json';
255 330
         	//$last_exec['fr24json'] = 0;
256
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
331
+        	if ($globalDebug) {
332
+        		echo "Connect to fr24 source (".$host.")...\n";
333
+        	}
257 334
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
258 335
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
259 336
         	    exit(0);
@@ -262,7 +339,9 @@  discard block
 block discarded – undo
262 339
         	//$formats[$id] = 'fr24json';
263 340
         	$globalSources[$id]['format'] = 'myshiptracking';
264 341
         	//$last_exec['fr24json'] = 0;
265
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
342
+        	if ($globalDebug) {
343
+        		echo "Connect to myshiptracking source (".$host.")...\n";
344
+        	}
266 345
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
267 346
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
268 347
         	    exit(0);
@@ -271,18 +350,28 @@  discard block
 block discarded – undo
271 350
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
272 351
         	//$formats[$id] = 'tsv';
273 352
         	$globalSources[$id]['format'] = 'tsv';
274
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
353
+        	if ($globalDebug) {
354
+        		echo "Connect to tsv source (".$host.")...\n";
355
+        	}
275 356
             }
276 357
         } elseif (filter_var($host,FILTER_VALIDATE_URL) || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') || (isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'acarsjson')) {
277 358
     		if ($globalSources[$id]['format'] == 'aisnmeahttp' || $globalSources[$id]['format'] == 'acarsjson') {
278 359
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
279 360
     		    if ($idf !== false) {
280 361
     			$httpfeeds[$id] = $idf;
281
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
282
-    		    } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
283
-    		} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
284
-    		elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') echo "Connect to ".$globalSources[$id]['format']." source (sailawayfull)...\n";
285
-    		elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
362
+        		if ($globalDebug) {
363
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
364
+        		}
365
+    		    } elseif ($globalDebug) {
366
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
367
+    		    }
368
+    		} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailaway') {
369
+    			echo "Connect to ".$globalSources[$id]['format']." source (sailaway)...\n";
370
+    		} elseif ($globalDebug && isset($globalSources[$id]['format']) && $globalSources[$id]['format'] == 'sailawayfull') {
371
+    			echo "Connect to ".$globalSources[$id]['format']." source (sailawayfull)...\n";
372
+    		} elseif ($globalDebug) {
373
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
374
+    		}
286 375
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
287 376
 	    $hostport = explode(':',$host);
288 377
 	    if (isset($hostport[1])) {
@@ -323,20 +412,29 @@  discard block
 block discarded – undo
323 412
         		//$formats[$id] = 'beast';
324 413
         		$globalSources[$id]['format'] = 'beast';
325 414
 		    //} else $formats[$id] = 'sbs';
326
-		    } else $globalSources[$id]['format'] = 'sbs';
415
+		    } else {
416
+		    	$globalSources[$id]['format'] = 'sbs';
417
+		    }
327 418
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
328 419
 		}
329
-		if ($globalDebug && $udp) echo 'Listening in UDP from '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
330
-		elseif ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
420
+		if ($globalDebug && $udp) {
421
+			echo 'Listening in UDP from '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
422
+		} elseif ($globalDebug) {
423
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
424
+		}
331 425
             } else {
332
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
426
+		if ($globalDebug) {
427
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
428
+		}
333 429
 		sleep(10);
334 430
 		connect_all($hosts);
335 431
     	    }
336 432
         }
337 433
     }
338 434
 }
339
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
435
+if (!isset($globalMinFetch)) {
436
+	$globalMinFetch = 15;
437
+}
340 438
 
341 439
 // Initialize all
342 440
 $status = array();
@@ -345,13 +443,19 @@  discard block
 block discarded – undo
345 443
 $formats = array();
346 444
 $last_exec = array();
347 445
 $time = time();
348
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
349
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
350
-else $timeout = 20;
446
+if (isset($globalSourcesTimeout)) {
447
+	$timeout = $globalSourcesTimeOut;
448
+} else if (isset($globalSBS1TimeOut)) {
449
+	$timeout = $globalSBS1TimeOut;
450
+} else {
451
+	$timeout = 20;
452
+}
351 453
 $errno = '';
352 454
 $errstr='';
353 455
 
354
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
456
+if (!isset($globalDaemon)) {
457
+	$globalDaemon = TRUE;
458
+}
355 459
 /* Initiate connections to all the hosts simultaneously */
356 460
 //connect_all($hosts);
357 461
 //connect_all($globalSources);
@@ -380,7 +484,9 @@  discard block
 block discarded – undo
380 484
     if (isset($source['format']) && $source['format'] == 'aprs') {
381 485
 	$aprs_connect = 0;
382 486
 	$use_aprs = true;
383
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
487
+	if (isset($source['port']) && $source['port'] == '10152') {
488
+		$aprs_full = true;
489
+	}
384 490
 	break;
385 491
     }
386 492
 }
@@ -391,25 +497,46 @@  discard block
 block discarded – undo
391 497
 	$aprs_connect = 0;
392 498
 	$aprs_keep = 120;
393 499
 	$aprs_last_tx = time();
394
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
395
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
396
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
397
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
398
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
399
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
400
-	if ($aprs_full) $aprs_filter = '';
401
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
402
-	else $aprs_pass = '-1';
500
+	if (isset($globalAPRSversion)) {
501
+		$aprs_version = $globalAPRSversion;
502
+	} else {
503
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
504
+	}
505
+	if (isset($globalAPRSssid)) {
506
+		$aprs_ssid = $globalAPRSssid;
507
+	} else {
508
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
509
+	}
510
+	if (isset($globalAPRSfilter)) {
511
+		$aprs_filter = $globalAPRSfilter;
512
+	} else {
513
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
514
+	}
515
+	if ($aprs_full) {
516
+		$aprs_filter = '';
517
+	}
518
+	if (isset($globalAPRSpass)) {
519
+		$aprs_pass = $globalAPRSpass;
520
+	} else {
521
+		$aprs_pass = '-1';
522
+	}
403 523
 
404
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
405
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
406
-}
524
+	if ($aprs_filter != '') {
525
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
526
+	} else {
527
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
528
+	}
529
+	}
407 530
 
408 531
 // connected - lets do some work
409 532
 //if ($globalDebug) echo "Connected!\n";
410 533
 sleep(1);
411
-if ($globalDebug) echo "SCAN MODE \n\n";
412
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
534
+if ($globalDebug) {
535
+	echo "SCAN MODE \n\n";
536
+}
537
+if (!isset($globalCronEnd)) {
538
+	$globalCronEnd = 60;
539
+}
413 540
 $endtime = time()+$globalCronEnd;
414 541
 $i = 1;
415 542
 $tt = array();
@@ -423,22 +550,32 @@  discard block
 block discarded – undo
423 550
 
424 551
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
425 552
 while ($i > 0) {
426
-    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
553
+    if (function_exists('pcntl_fork')) {
554
+    	pcntl_signal_dispatch();
555
+    }
427 556
 
428
-    if (!$globalDaemon) $i = $endtime-time();
557
+    if (!$globalDaemon) {
558
+    	$i = $endtime-time();
559
+    }
429 560
     // Delete old ATC
430 561
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
431
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
562
+	if ($globalDebug) {
563
+		echo 'Delete old ATC...'."\n";
564
+	}
432 565
         $ATC->deleteOldATC();
433 566
     }
434 567
     
435 568
     if (count($last_exec) == count($globalSources)) {
436 569
 	$max = $globalMinFetch;
437 570
 	foreach ($last_exec as $last) {
438
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
571
+	    if ((time() - $last['last']) < $max) {
572
+	    	$max = time() - $last['last'];
573
+	    }
439 574
 	}
440 575
 	if ($max < $globalMinFetch) {
441
-	    if ($globalDebug) echo 'Sleeping...'."\n";
576
+	    if ($globalDebug) {
577
+	    	echo 'Sleeping...'."\n";
578
+	    }
442 579
 	    sleep($globalMinFetch-$max+2);
443 580
 	}
444 581
     }
@@ -448,7 +585,9 @@  discard block
 block discarded – undo
448 585
     foreach ($globalSources as $id => $value) {
449 586
 	date_default_timezone_set('UTC');
450 587
 	//if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n";
451
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
588
+	if (!isset($last_exec[$id]['last'])) {
589
+		$last_exec[$id]['last'] = 0;
590
+	}
452 591
 	if ($value['format'] === 'deltadbtxt' && 
453 592
 	    (
454 593
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
@@ -457,7 +596,9 @@  discard block
 block discarded – undo
457 596
 	) {
458 597
         //$buffer = $Common->getData($hosts[$id]);
459 598
         $buffer = $Common->getData($value['host']);
460
-        if ($buffer != '') $reset = 0;
599
+        if ($buffer != '') {
600
+        	$reset = 0;
601
+        }
461 602
         $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
462 603
         $buffer = explode('\n', $buffer);
463 604
         foreach ($buffer as $line) {
@@ -466,20 +607,41 @@  discard block
 block discarded – undo
466 607
                 $data = array();
467 608
                 $data['hex'] = $line[1]; // hex
468 609
                 $data['ident'] = $line[2]; // ident
469
-                if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
470
-                if (isset($line[4])) $data['speed'] = $line[4]; // speed
471
-                if (isset($line[5])) $data['heading'] = $line[5]; // heading
472
-                if (isset($line[6])) $data['latitude'] = $line[6]; // lat
473
-                if (isset($line[7])) $data['longitude'] = $line[7]; // long
610
+                if (isset($line[3])) {
611
+                	$data['altitude'] = $line[3];
612
+                }
613
+                // altitude
614
+                if (isset($line[4])) {
615
+                	$data['speed'] = $line[4];
616
+                }
617
+                // speed
618
+                if (isset($line[5])) {
619
+                	$data['heading'] = $line[5];
620
+                }
621
+                // heading
622
+                if (isset($line[6])) {
623
+                	$data['latitude'] = $line[6];
624
+                }
625
+                // lat
626
+                if (isset($line[7])) {
627
+                	$data['longitude'] = $line[7];
628
+                }
629
+                // long
474 630
                 $data['verticalrate'] = ''; // vertical rate
475 631
                 //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
476 632
                 $data['emergency'] = ''; // emergency
477 633
                 $data['datetime'] = date('Y-m-d H:i:s');
478 634
                 $data['format_source'] = 'deltadbtxt';
479 635
                 $data['id_source'] = $id_source;
480
-                if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
481
-                if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
482
-                if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
636
+                if (isset($value['name']) && $value['name'] != '') {
637
+                	$data['source_name'] = $value['name'];
638
+                }
639
+                if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
640
+                	$data['noarchive'] = true;
641
+                }
642
+                if (isset($value['sourcestats'])) {
643
+                	$data['sourcestats'] = $value['sourcestats'];
644
+                }
483 645
                 $SI->add($data);
484 646
                 unset($data);
485 647
             }
@@ -514,11 +676,20 @@  discard block
 block discarded – undo
514 676
                     $data['format_source'] = 'radarcapejson';
515 677
                     $data['id_source'] = $id_source;
516 678
                     if (isset($value['name']) && $value['name'] != '') {
517
-                        if (isset($line['src']) && !$line['src'] == 'M') $data['source_name'] = $value['name'].'_MLAT';
518
-                        else $data['source_name'] = $value['name'];
519
-                    } elseif (isset($line['src']) && $line['src'] == 'M') $data['source_name'] = 'MLAT';
520
-                    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
521
-                    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
679
+                        if (isset($line['src']) && !$line['src'] == 'M') {
680
+                        	$data['source_name'] = $value['name'].'_MLAT';
681
+                        } else {
682
+                        	$data['source_name'] = $value['name'];
683
+                        }
684
+                    } elseif (isset($line['src']) && $line['src'] == 'M') {
685
+                    	$data['source_name'] = 'MLAT';
686
+                    }
687
+                    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
688
+                    	$data['noarchive'] = true;
689
+                    }
690
+                    if (isset($value['sourcestats'])) {
691
+                    	$data['sourcestats'] = $value['sourcestats'];
692
+                    }
522 693
 
523 694
                     $SI->add($data);
524 695
                     unset($data);
@@ -534,7 +705,9 @@  discard block
 block discarded – undo
534 705
 	    date_default_timezone_set('CET');
535 706
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
536 707
 	    date_default_timezone_set('UTC');
537
-	    if ($buffer != '') $reset = 0;
708
+	    if ($buffer != '') {
709
+	    	$reset = 0;
710
+	    }
538 711
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
539 712
 	    $buffer = explode('\n',$buffer);
540 713
 	    foreach ($buffer as $line) {
@@ -543,18 +716,42 @@  discard block
 block discarded – undo
543 716
 		    $add = false;
544 717
 		    $ais_data = $AIS->parse_line(trim($line));
545 718
 		    $data = array();
546
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
547
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
548
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
549
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
550
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
551
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
552
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
553
-		    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
554
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
555
-		    if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
556
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
557
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
719
+		    if (isset($ais_data['ident'])) {
720
+		    	$data['ident'] = $ais_data['ident'];
721
+		    }
722
+		    if (isset($ais_data['mmsi'])) {
723
+		    	$data['mmsi'] = substr($ais_data['mmsi'],-9);
724
+		    }
725
+		    if (isset($ais_data['speed'])) {
726
+		    	$data['speed'] = $ais_data['speed'];
727
+		    }
728
+		    if (isset($ais_data['heading'])) {
729
+		    	$data['heading'] = $ais_data['heading'];
730
+		    }
731
+		    if (isset($ais_data['latitude'])) {
732
+		    	$data['latitude'] = $ais_data['latitude'];
733
+		    }
734
+		    if (isset($ais_data['longitude'])) {
735
+		    	$data['longitude'] = $ais_data['longitude'];
736
+		    }
737
+		    if (isset($ais_data['status'])) {
738
+		    	$data['status'] = $ais_data['status'];
739
+		    }
740
+		    if (isset($ais_data['statusid'])) {
741
+		    	$data['status_id'] = $ais_data['statusid'];
742
+		    }
743
+		    if (isset($ais_data['type'])) {
744
+		    	$data['type'] = $ais_data['type'];
745
+		    }
746
+		    if (isset($ais_data['typeid'])) {
747
+		    	$data['type_id'] = $ais_data['typeid'];
748
+		    }
749
+		    if (isset($ais_data['imo'])) {
750
+		    	$data['imo'] = $ais_data['imo'];
751
+		    }
752
+		    if (isset($ais_data['callsign'])) {
753
+		    	$data['callsign'] = $ais_data['callsign'];
754
+		    }
558 755
 		    if (isset($ais_data['timestamp'])) {
559 756
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
560 757
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -568,8 +765,12 @@  discard block
 block discarded – undo
568 765
 		    $data['format_source'] = 'aisnmeatxt';
569 766
     		    $data['id_source'] = $id_source;
570 767
 		    //print_r($data);
571
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
572
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
768
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
769
+		    	$data['noarchive'] = true;
770
+		    }
771
+		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') {
772
+		    	$MI->add($data);
773
+		    }
573 774
 		    unset($data);
574 775
 		}
575 776
     	    }
@@ -592,20 +793,48 @@  discard block
 block discarded – undo
592 793
 			    if ($line != '') {
593 794
 				$ais_data = $AIS->parse_line(trim($line));
594 795
 				$data = array();
595
-				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
596
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
597
-				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
598
-				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
599
-				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
600
-				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
601
-				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
602
-				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
603
-				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
604
-				if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
605
-				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
606
-				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
607
-				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
608
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
796
+				if (isset($ais_data['ident'])) {
797
+					$data['ident'] = $ais_data['ident'];
798
+				}
799
+				if (isset($ais_data['mmsi'])) {
800
+					$data['mmsi'] = substr($ais_data['mmsi'],-9);
801
+				}
802
+				if (isset($ais_data['speed'])) {
803
+					$data['speed'] = $ais_data['speed'];
804
+				}
805
+				if (isset($ais_data['heading'])) {
806
+					$data['heading'] = $ais_data['heading'];
807
+				}
808
+				if (isset($ais_data['latitude'])) {
809
+					$data['latitude'] = $ais_data['latitude'];
810
+				}
811
+				if (isset($ais_data['longitude'])) {
812
+					$data['longitude'] = $ais_data['longitude'];
813
+				}
814
+				if (isset($ais_data['status'])) {
815
+					$data['status'] = $ais_data['status'];
816
+				}
817
+				if (isset($ais_data['statusid'])) {
818
+					$data['status_id'] = $ais_data['statusid'];
819
+				}
820
+				if (isset($ais_data['type'])) {
821
+					$data['type'] = $ais_data['type'];
822
+				}
823
+				if (isset($ais_data['typeid'])) {
824
+					$data['type_id'] = $ais_data['typeid'];
825
+				}
826
+				if (isset($ais_data['imo'])) {
827
+					$data['imo'] = $ais_data['imo'];
828
+				}
829
+				if (isset($ais_data['callsign'])) {
830
+					$data['callsign'] = $ais_data['callsign'];
831
+				}
832
+				if (isset($ais_data['destination'])) {
833
+					$data['arrival_code'] = $ais_data['destination'];
834
+				}
835
+				if (isset($ais_data['eta_ts'])) {
836
+					$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
837
+				}
609 838
 				if (isset($ais_data['timestamp'])) {
610 839
 				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
611 840
 				} else {
@@ -613,18 +842,27 @@  discard block
 block discarded – undo
613 842
 				}
614 843
 				$data['format_source'] = 'aisnmeahttp';
615 844
 				$data['id_source'] = $id_source;
616
-				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
617
-				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
845
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
846
+					$data['noarchive'] = true;
847
+				}
848
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') {
849
+					$MI->add($data);
850
+				}
618 851
 				unset($data);
619 852
 			    }
620 853
 			}
621 854
 		    }
622 855
 		} else {
623 856
 		    $format = $value['format'];
624
-		    if (isset($tt[$format])) $tt[$format]++;
625
-		    else $tt[$format] = 0;
857
+		    if (isset($tt[$format])) {
858
+		    	$tt[$format]++;
859
+		    } else {
860
+		    	$tt[$format] = 0;
861
+		    }
626 862
 		    if ($tt[$format] > 30) {
627
-			if ($globalDebug) echo 'Reconnect...'."\n";
863
+			if ($globalDebug) {
864
+				echo 'Reconnect...'."\n";
865
+			}
628 866
 			sleep(2);
629 867
 			//$sourceeen[] = $value;
630 868
 			//connect_all($sourceeen);
@@ -660,12 +898,18 @@  discard block
 block discarded – undo
660 898
 			    //    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
661 899
 			    //$data['type_id'] = $line['TYPE'];
662 900
 			    $data['imo'] = $line['IMO'];
663
-			    if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
664
-			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
901
+			    if ($line['DEST'] != '') {
902
+			    	$data['arrival_code'] = $line['DEST'];
903
+			    }
904
+			    if ($line['ARV'] != '') {
905
+			    	$data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
906
+			    }
665 907
 			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
666 908
 			    $data['format_source'] = 'myshiptracking';
667 909
 			    $data['id_source'] = $id_source;
668
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
910
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
911
+			    	$data['noarchive'] = true;
912
+			    }
669 913
 			    $MI->add($data);
670 914
 			    unset($data);
671 915
 			}
@@ -690,7 +934,9 @@  discard block
 block discarded – undo
690 934
 			    $data['callsign'] = $line['callsign'];
691 935
 			    $data['mmsi'] = substr($line['mmsi'],-9);
692 936
 			    $data['speed'] = $line['sog'];
693
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
937
+			    if ($line['heading'] != '511') {
938
+			    	$data['heading'] = $line['heading'];
939
+			    }
694 940
 			    $data['latitude'] = $line['latitude'];
695 941
 			    $data['longitude'] = $line['longitude'];
696 942
 			    $data['type_id'] = $line['shiptype'];
@@ -698,7 +944,9 @@  discard block
 block discarded – undo
698 944
 			    $data['datetime'] = $line['time'];
699 945
 			    $data['format_source'] = 'boatbeaconapp';
700 946
 			    $data['id_source'] = $id_source;
701
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
947
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
948
+			    	$data['noarchive'] = true;
949
+			    }
702 950
 			    $MI->add($data);
703 951
 			    unset($data);
704 952
 			}
@@ -720,22 +968,44 @@  discard block
 block discarded – undo
720 968
 		    foreach ($all_data['features'] as $line) {
721 969
 			print_r($line);
722 970
 			$data = array();
723
-			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
724
-			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
725
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'],-9);
726
-			if (isset($line['properties']['imo'])) $data['imo'] = $line['properties']['imo'];
727
-			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
728
-			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) $data['heading'] = $line['properties']['heading'];
971
+			if (isset($line['properties']['name'])) {
972
+				$data['ident'] = $line['properties']['name'];
973
+			}
974
+			if (isset($line['properties']['callsign'])) {
975
+				$data['callsign'] = $line['properties']['callsign'];
976
+			}
977
+			if (isset($line['properties']['mmsi'])) {
978
+				$data['mmsi'] = substr($line['properties']['mmsi'],-9);
979
+			}
980
+			if (isset($line['properties']['imo'])) {
981
+				$data['imo'] = $line['properties']['imo'];
982
+			}
983
+			if (isset($line['properties']['speed'])) {
984
+				$data['speed'] = $line['properties']['speed'];
985
+			}
986
+			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) {
987
+				$data['heading'] = $line['properties']['heading'];
988
+			}
729 989
 			$data['latitude'] = $line['geometry']['coordinates'][1];
730 990
 			$data['longitude'] = $line['geometry']['coordinates'][0];
731
-			if (isset($line['properties']['vesselType'])) $data['type'] = $line['properties']['vesselType'];
732
-			if (isset($line['properties']['destination'])) $data['arrival_code'] = $line['properties']['destination'];
733
-			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') $data['arrival_date'] = $line['properties']['eta'];
991
+			if (isset($line['properties']['vesselType'])) {
992
+				$data['type'] = $line['properties']['vesselType'];
993
+			}
994
+			if (isset($line['properties']['destination'])) {
995
+				$data['arrival_code'] = $line['properties']['destination'];
996
+			}
997
+			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') {
998
+				$data['arrival_date'] = $line['properties']['eta'];
999
+			}
734 1000
 			$data['format_source'] = 'boatnerd';
735 1001
 			$data['id_source'] = $id_source;
736 1002
 			$data['datetime'] = date('Y-m-d H:i:s');
737
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
738
-			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
1003
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1004
+				$data['noarchive'] = true;
1005
+			}
1006
+			if ($line['properties']['vesselType'] != 'Navigation Aid') {
1007
+				$MI->add($data);
1008
+			}
739 1009
 			unset($data);
740 1010
 		    }
741 1011
 		}
@@ -748,11 +1018,17 @@  discard block
 block discarded – undo
748 1018
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
749 1019
 	    )
750 1020
 	) {
751
-	    if ($globalDebug) echo 'download...';
1021
+	    if ($globalDebug) {
1022
+	    	echo 'download...';
1023
+	    }
752 1024
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
753
-	    if ($globalDebug) echo 'done !'."\n";
1025
+	    if ($globalDebug) {
1026
+	    	echo 'done !'."\n";
1027
+	    }
754 1028
 	    // FIXME: Need more work
755
-	    if ($buffer != '') $reset = 0;
1029
+	    if ($buffer != '') {
1030
+	    	$reset = 0;
1031
+	    }
756 1032
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
757 1033
 	    $buffer = explode('\n',$buffer);
758 1034
 	    foreach ($buffer as $line) {
@@ -778,7 +1054,9 @@  discard block
 block discarded – undo
778 1054
 		    //$data['etaTime'] = substr($line,135,5);
779 1055
 		    $data['format_source'] = 'shipplotter';
780 1056
     		    $data['id_source'] = $id_source;
781
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1057
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1058
+		    	$data['noarchive'] = true;
1059
+		    }
782 1060
 		    //print_r($data);
783 1061
 		    //echo 'Add...'."\n";
784 1062
 		    $MI->add($data);
@@ -800,11 +1078,17 @@  discard block
 block discarded – undo
800 1078
 		}
801 1079
 	    }
802 1080
 
803
-	    if ($globalDebug) echo '! Download... ';
1081
+	    if ($globalDebug) {
1082
+	    	echo '! Download... ';
1083
+	    }
804 1084
 	    for ($i =0; $i <= 1; $i++) {
805
-		if ($globalDebug) echo 'Racetype: '.$i.' ';
1085
+		if ($globalDebug) {
1086
+			echo 'Racetype: '.$i.' ';
1087
+		}
806 1088
 		$buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/GetMissions.pl?race=1&tutorial=0&hist=1&racetype='.$i);
807
-	    if ($globalDebug) echo 'done'."\n";
1089
+	    if ($globalDebug) {
1090
+	    	echo 'done'."\n";
1091
+	    }
808 1092
 	    if ($buffer != '') {
809 1093
 		$all_data = json_decode($buffer,true);
810 1094
 		if (isset($all_data['missions'])) {
@@ -815,7 +1099,9 @@  discard block
 block discarded – undo
815 1099
 					if (isset($sailaway_authcookie) && $sailaway_authcookie != '') {
816 1100
 						$racebuffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/GetMission.pl?misnr='.$mission['misnr'],'get','','',$sailaway_authcookie);
817 1101
 						sleep(30);
818
-					} else $racebuffer = '';
1102
+					} else {
1103
+						$racebuffer = '';
1104
+					}
819 1105
 					$bufferm = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/GetLeaderboard.pl?misnr='.$mission['misnr']);
820 1106
 				} else {
821 1107
 					$bufferm = '';
@@ -879,7 +1165,9 @@  discard block
 block discarded – undo
879 1165
 								$data['captain_id'] = $sail['usrnr'];
880 1166
 								$data['captain_name'] = $sail['usrname'];
881 1167
 								$data['race_id'] = $sail['misnr'];
882
-								if ($sail['rank'] != 'DNF') $data['race_rank'] = $sail['rank'];
1168
+								if ($sail['rank'] != 'DNF') {
1169
+									$data['race_rank'] = $sail['rank'];
1170
+								}
883 1171
 								$data['race_time'] = $sail['racetime'];
884 1172
 								if ($mission_user != '') {
885 1173
 									$data['race_name'] = $mission_name.' ('.$mission_user.')';
@@ -889,7 +1177,9 @@  discard block
 block discarded – undo
889 1177
 								//$data['callsign'] = trim(substr($line,100,7);
890 1178
 								$data['format_source'] = 'sailawayfull';
891 1179
 								$data['id_source'] = $id_source;
892
-								if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1180
+								if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1181
+									$data['noarchive'] = true;
1182
+								}
893 1183
 								//print_r($data);
894 1184
 								//if ($data['race_id'] == '48') print_r($data);
895 1185
 								//echo 'Add...'."\n";
@@ -927,10 +1217,16 @@  discard block
 block discarded – undo
927 1217
 		echo 'Sailaway API key MUST be defined';
928 1218
 		exit(0);
929 1219
 	    }
930
-	    if ($globalDebug) echo '! Download... ';
1220
+	    if ($globalDebug) {
1221
+	    	echo '! Download... ';
1222
+	    }
931 1223
 	    $sailawayoption = array('key' => $globalSailaway['key']);
932
-	    if (isset($globalSailaway['usrnr'])) $sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
933
-	    if (isset($globalSailaway['ubtnr'])) $sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
1224
+	    if (isset($globalSailaway['usrnr'])) {
1225
+	    	$sailawayoption = array_merge($sailawayoption,array('usrnr' => $globalSailaway['usrnr']));
1226
+	    }
1227
+	    if (isset($globalSailaway['ubtnr'])) {
1228
+	    	$sailawayoption = array_merge($sailawayoption,array('ubtnr' => $globalSailaway['ubtnr']));
1229
+	    }
934 1230
 	    $buffer = $Common->getData('http://backend.sailaway.world/cgi-bin/sailaway/TrackAllBoats.pl?'.http_build_query($sailawayoption),'get','','','','',30);
935 1231
 	    if ($buffer != '') {
936 1232
 		$data = json_decode($buffer,true);
@@ -940,7 +1236,9 @@  discard block
 block discarded – undo
940 1236
 			$data = array();
941 1237
 			$data['id'] = $sail['ubtnr'];
942 1238
 			$data['datetime'] = date('Y-m-d H:i:s');
943
-			if ($sail['online'] == '1') $data['last_update'] = date('Y-m-d H:i:s');
1239
+			if ($sail['online'] == '1') {
1240
+				$data['last_update'] = date('Y-m-d H:i:s');
1241
+			}
944 1242
 			$data['latitude'] = $sail['ubtlat'];
945 1243
 			$data['longitude'] = $sail['ubtlon'];
946 1244
 			$data['type_id'] = 36;
@@ -949,16 +1247,24 @@  discard block
 block discarded – undo
949 1247
 			$data['captain_name'] = $sail['usrname'];
950 1248
 			$allboats = array('Sailaway Cruiser 38','Mini Transat','Caribbean Rose','52&#39; Cruising Cat','50&#39; Performance Cruiser','Nordic Folkboat');
951 1249
 			$boattype = $sail['ubtbtpnr'];
952
-			if (isset($allboats[$boattype-1])) $data['type'] = $allboats[$boattype-1];
1250
+			if (isset($allboats[$boattype-1])) {
1251
+				$data['type'] = $allboats[$boattype-1];
1252
+			}
953 1253
 			$data['speed'] = round($sail['ubtspeed']*3.6,2);
954 1254
 			$data['format_source'] = 'sailaway';
955 1255
 			$data['id_source'] = $id_source;
956
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1256
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1257
+				$data['noarchive'] = true;
1258
+			}
957 1259
 			$MI->add($data);
958 1260
 			unset($data);
959 1261
 		    }
960
-		} elseif ($globalDebug) echo 'Error in JSON parsing';
961
-	    } elseif ($globalDebug) echo 'Empty result !'."\n";
1262
+		} elseif ($globalDebug) {
1263
+			echo 'Error in JSON parsing';
1264
+		}
1265
+	    } elseif ($globalDebug) {
1266
+	    	echo 'Empty result !'."\n";
1267
+	    }
962 1268
     	    $last_exec[$id]['last'] = time();
963 1269
 	//} elseif (($value === 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value === 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
964 1270
 	} elseif (
@@ -986,16 +1292,28 @@  discard block
 block discarded – undo
986 1292
     		    $line = explode(':', $line);
987 1293
     		    if (count($line) > 30 && $line[0] != 'callsign') {
988 1294
 			$data = array();
989
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
990
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
1295
+			if (isset($line[37]) && $line[37] != '') {
1296
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
1297
+			} else {
1298
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
1299
+			}
991 1300
 			$data['pilot_id'] = $line[1];
992 1301
 			$data['pilot_name'] = $line[2];
993 1302
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
994 1303
 			$data['ident'] = $line[0]; // ident
995
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
1304
+			if ($line[7] != '' && $line[7] != 0) {
1305
+				$data['altitude'] = $line[7];
1306
+			}
1307
+			// altitude
996 1308
 			$data['speed'] = $line[8]; // speed
997
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
998
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
1309
+			if (isset($line[45])) {
1310
+				$data['heading'] = $line[45];
1311
+			}
1312
+			// heading
1313
+			elseif (isset($line[38])) {
1314
+				$data['heading'] = $line[38];
1315
+			}
1316
+			// heading
999 1317
 			$data['latitude'] = $line[5]; // lat
1000 1318
 	        	$data['longitude'] = $line[6]; // long
1001 1319
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -1011,7 +1329,9 @@  discard block
 block discarded – undo
1011 1329
 			$data['frequency'] = $line[4];
1012 1330
 			$data['type'] = $line[18];
1013 1331
 			$data['range'] = $line[19];
1014
-			if (isset($line[35])) $data['info'] = $line[35];
1332
+			if (isset($line[35])) {
1333
+				$data['info'] = $line[35];
1334
+			}
1015 1335
     			$data['id_source'] = $id_source;
1016 1336
 	    		//$data['arrival_airport_time'] = ;
1017 1337
 	    		if ($line[9] != '') {
@@ -1025,27 +1345,47 @@  discard block
 block discarded – undo
1025 1345
 	    		elseif ($value === 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
1026 1346
 	    		*/
1027 1347
 	    		$data['format_source'] = $value['format'];
1028
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1029
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1030
-    			if ($line[3] === 'PILOT') $SI->add($data);
1031
-			elseif ($line[3] === 'ATC') {
1348
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1349
+				$data['noarchive'] = true;
1350
+			}
1351
+			if (isset($value['name']) && $value['name'] != '') {
1352
+				$data['source_name'] = $value['name'];
1353
+			}
1354
+    			if ($line[3] === 'PILOT') {
1355
+    				$SI->add($data);
1356
+    			} elseif ($line[3] === 'ATC') {
1032 1357
 				//print_r($data);
1033 1358
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1034 1359
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
1035 1360
 				$typec = substr($data['ident'],-3);
1036
-				if ($typec === 'APP') $data['type'] = 'Approach';
1037
-				elseif ($typec === 'TWR') $data['type'] = 'Tower';
1038
-				elseif ($typec === 'OBS') $data['type'] = 'Observer';
1039
-				elseif ($typec === 'GND') $data['type'] = 'Ground';
1040
-				elseif ($typec === 'DEL') $data['type'] = 'Delivery';
1041
-				elseif ($typec === 'DEP') $data['type'] = 'Departure';
1042
-				elseif ($typec === 'FSS') $data['type'] = 'Flight Service Station';
1043
-				elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
1044
-				elseif ($data['type'] === '') $data['type'] = 'Observer';
1045
-				if (!isset($data['source_name'])) $data['source_name'] = '';
1361
+				if ($typec === 'APP') {
1362
+					$data['type'] = 'Approach';
1363
+				} elseif ($typec === 'TWR') {
1364
+					$data['type'] = 'Tower';
1365
+				} elseif ($typec === 'OBS') {
1366
+					$data['type'] = 'Observer';
1367
+				} elseif ($typec === 'GND') {
1368
+					$data['type'] = 'Ground';
1369
+				} elseif ($typec === 'DEL') {
1370
+					$data['type'] = 'Delivery';
1371
+				} elseif ($typec === 'DEP') {
1372
+					$data['type'] = 'Departure';
1373
+				} elseif ($typec === 'FSS') {
1374
+					$data['type'] = 'Flight Service Station';
1375
+				} elseif ($typec === 'CTR') {
1376
+					$data['type'] = 'Control Radar or Centre';
1377
+				} elseif ($data['type'] === '') {
1378
+					$data['type'] = 'Observer';
1379
+				}
1380
+				if (!isset($data['source_name'])) {
1381
+					$data['source_name'] = '';
1382
+				}
1046 1383
 				if (isset($ATC)) {
1047
-					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) echo $ATC->update($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']);
1048
-					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']);
1384
+					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) {
1385
+						echo $ATC->update($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']);
1386
+					} else {
1387
+						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']);
1388
+					}
1049 1389
 				}
1050 1390
 			}
1051 1391
     			unset($data);
@@ -1072,14 +1412,20 @@  discard block
 block discarded – undo
1072 1412
 			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
1073 1413
 			$data['latitude'] = (float)$line['pktLatitude'];
1074 1414
 			$data['longitude'] = (float)$line['pktLongitude'];
1075
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
1076
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
1415
+			if ((float)$line['pktTrack'] != 0) {
1416
+				$data['heading'] = (float)$line['pktTrack'];
1417
+			}
1418
+			if ((int)$line['pktSpeed'] != 0) {
1419
+				$data['speed'] = (int)$line['pktSpeed'];
1420
+			}
1077 1421
 			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
1078 1422
 			$data['altitude_relative'] = 'AMSL';
1079 1423
 			$data['pilot_id'] = (int)$line['pktPilotID'];
1080 1424
 			$data['aircraft_icao'] = 'PARAGLIDER';
1081 1425
 			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
1082
-			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
1426
+			if (isset($pilot_data[4])) {
1427
+				$data['pilot_name'] = $pilot_data[4];
1428
+			}
1083 1429
 			$data['format_source'] = $value['format'];
1084 1430
 			$SI->add($data);
1085 1431
 			unset($data);
@@ -1127,25 +1473,59 @@  discard block
 block discarded – undo
1127 1473
 		    foreach ($all_data['acList'] as $line) {
1128 1474
 			$data = array();
1129 1475
 			$data['hex'] = $line['Icao']; // hex
1130
-			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1131
-			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1132
-			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1133
-			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1134
-			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1135
-			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1476
+			if (isset($line['Call'])) {
1477
+				$data['ident'] = $line['Call'];
1478
+			}
1479
+			// ident
1480
+			if (isset($line['Alt'])) {
1481
+				$data['altitude'] = $line['Alt'];
1482
+			}
1483
+			// altitude
1484
+			if (isset($line['Spd'])) {
1485
+				$data['speed'] = $line['Spd'];
1486
+			}
1487
+			// speed
1488
+			if (isset($line['Trak'])) {
1489
+				$data['heading'] = $line['Trak'];
1490
+			}
1491
+			// heading
1492
+			if (isset($line['Lat'])) {
1493
+				$data['latitude'] = $line['Lat'];
1494
+			}
1495
+			// lat
1496
+			if (isset($line['Long'])) {
1497
+				$data['longitude'] = $line['Long'];
1498
+			}
1499
+			// long
1136 1500
 			//$data['verticalrate'] = $line['']; // verticale rate
1137
-			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1501
+			if (isset($line['Sqk'])) {
1502
+				$data['squawk'] = $line['Sqk'];
1503
+			}
1504
+			// squawk
1138 1505
 			$data['emergency'] = ''; // emergency
1139
-			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
1140
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1141
-			else $data['datetime'] = date('Y-m-d H:i:s');
1506
+			if (isset($line['Reg'])) {
1507
+				$data['registration'] = $line['Reg'];
1508
+			}
1509
+			if (isset($line['PosTime'])) {
1510
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1511
+			} else {
1512
+				$data['datetime'] = date('Y-m-d H:i:s');
1513
+			}
1142 1514
 			//$data['datetime'] = date('Y-m-d H:i:s');
1143
-			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1515
+			if (isset($line['Type'])) {
1516
+				$data['aircraft_icao'] = $line['Type'];
1517
+			}
1144 1518
 			$data['format_source'] = 'aircraftlistjson';
1145 1519
 			$data['id_source'] = $id_source;
1146
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1147
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1148
-			if (isset($data['latitude'])) $SI->add($data);
1520
+			if (isset($value['name']) && $value['name'] != '') {
1521
+				$data['source_name'] = $value['name'];
1522
+			}
1523
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1524
+				$data['noarchive'] = true;
1525
+			}
1526
+			if (isset($data['latitude'])) {
1527
+				$SI->add($data);
1528
+			}
1149 1529
 			unset($data);
1150 1530
 		    }
1151 1531
 		} elseif (is_array($all_data)) {
@@ -1162,17 +1542,26 @@  discard block
 block discarded – undo
1162 1542
 			$data['verticalrate'] = $line['vrt']; // verticale rate
1163 1543
 			$data['squawk'] = $line['squawk']; // squawk
1164 1544
 			$data['emergency'] = ''; // emergency
1165
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1166
-			else $data['datetime'] = date('Y-m-d H:i:s');
1545
+			if (isset($line['PosTime'])) {
1546
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1547
+			} else {
1548
+				$data['datetime'] = date('Y-m-d H:i:s');
1549
+			}
1167 1550
 			$data['format_source'] = 'aircraftlistjson';
1168 1551
 			$data['id_source'] = $id_source;
1169
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1170
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1552
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1553
+				$data['noarchive'] = true;
1554
+			}
1555
+			if (isset($value['name']) && $value['name'] != '') {
1556
+				$data['source_name'] = $value['name'];
1557
+			}
1171 1558
 			$SI->add($data);
1172 1559
 			unset($data);
1173 1560
 		    }
1174 1561
 		}
1175
-	    } elseif ($globalDebug) echo 'No data'."\n";
1562
+	    } elseif ($globalDebug) {
1563
+	    	echo 'No data'."\n";
1564
+	    }
1176 1565
     	    //$last_exec['aircraftlistjson'] = time();
1177 1566
     	    $last_exec[$id]['last'] = time();
1178 1567
     	//} elseif ($value === 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
@@ -1208,8 +1597,12 @@  discard block
 block discarded – undo
1208 1597
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
1209 1598
 	    	    $data['format_source'] = 'planeupdatefaa';
1210 1599
     		    $data['id_source'] = $id_source;
1211
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1212
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1600
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1601
+		    	$data['noarchive'] = true;
1602
+		    }
1603
+		    if (isset($value['name']) && $value['name'] != '') {
1604
+		    	$data['source_name'] = $value['name'];
1605
+		    }
1213 1606
 		    $SI->add($data);
1214 1607
 		    unset($data);
1215 1608
 		}
@@ -1243,7 +1636,9 @@  discard block
 block discarded – undo
1243 1636
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1244 1637
 		    $data['format_source'] = 'opensky';
1245 1638
 		    $data['id_source'] = $id_source;
1246
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1639
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1640
+		    	$data['noarchive'] = true;
1641
+		    }
1247 1642
 		    $SI->add($data);
1248 1643
 		    unset($data);
1249 1644
 		}
@@ -1263,15 +1658,42 @@  discard block
 block discarded – undo
1263 1658
 		foreach ($all_data['aircraft'] as $key => $line) {
1264 1659
 		    $data = array();
1265 1660
 		    // add support for ground vehicule with ~ in front of hex
1266
-		    if (isset($line['hex'])) $data['hex'] = $line['hex']; // hex
1267
-		    if (isset($line['flight'])) $data['ident'] = trim($line['flight']); // ident
1268
-		    if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1269
-		    if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1270
-		    if (isset($line['track'])) $data['heading'] = $line['track']; // heading
1271
-		    if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1272
-		    if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1273
-		    if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1274
-		    if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1661
+		    if (isset($line['hex'])) {
1662
+		    	$data['hex'] = $line['hex'];
1663
+		    }
1664
+		    // hex
1665
+		    if (isset($line['flight'])) {
1666
+		    	$data['ident'] = trim($line['flight']);
1667
+		    }
1668
+		    // ident
1669
+		    if (isset($line['altitude'])) {
1670
+		    	$data['altitude'] = $line['altitude'];
1671
+		    }
1672
+		    // altitude
1673
+		    if (isset($line['speed'])) {
1674
+		    	$data['speed'] = $line['speed'];
1675
+		    }
1676
+		    // speed
1677
+		    if (isset($line['track'])) {
1678
+		    	$data['heading'] = $line['track'];
1679
+		    }
1680
+		    // heading
1681
+		    if (isset($line['lat'])) {
1682
+		    	$data['latitude'] = $line['lat'];
1683
+		    }
1684
+		    // lat
1685
+		    if (isset($line['lon'])) {
1686
+		    	$data['longitude'] = $line['lon'];
1687
+		    }
1688
+		    // long
1689
+		    if (isset($line['vert_rate'])) {
1690
+		    	$data['verticalrate'] = $line['vert_rate'];
1691
+		    }
1692
+		    // verticale rate
1693
+		    if (isset($line['squawk'])) {
1694
+		    	$data['squawk'] = $line['squawk'];
1695
+		    }
1696
+		    // squawk
1275 1697
 		    //$data['emergency'] = ''; // emergency
1276 1698
 		    //$data['registration'] = $line[2];
1277 1699
 		    //$data['aircraft_icao'] = $line[0];
@@ -1279,10 +1701,17 @@  discard block
 block discarded – undo
1279 1701
 		    $data['format_source'] = 'aircraftjson';
1280 1702
 		    $data['id_source'] = $id_source;
1281 1703
 		    if (isset($value['name']) && $value['name'] != '') {
1282
-			    if (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = $value['name'].'_MLAT';
1283
-			    else $data['source_name'] = $value['name'];
1284
-		    } elseif (isset($line['mlat']) && !empty($line['mlat'])) $data['source_name'] = 'MLAT';
1285
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1704
+			    if (isset($line['mlat']) && !empty($line['mlat'])) {
1705
+			    	$data['source_name'] = $value['name'].'_MLAT';
1706
+			    } else {
1707
+			    	$data['source_name'] = $value['name'];
1708
+			    }
1709
+		    } elseif (isset($line['mlat']) && !empty($line['mlat'])) {
1710
+		    	$data['source_name'] = 'MLAT';
1711
+		    }
1712
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1713
+		    	$data['noarchive'] = true;
1714
+		    }
1286 1715
 		    $SI->add($data);
1287 1716
 		    unset($data);
1288 1717
 		}
@@ -1302,22 +1731,54 @@  discard block
 block discarded – undo
1302 1731
 		foreach ($all_data['aircraft'] as $key => $line) {
1303 1732
 		    $data = array();
1304 1733
 		    $data['hex'] = $key; // hex
1305
-		    if (isset($line['callsign'])) $data['ident'] = trim($line['callsign']); // ident
1306
-		    if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1307
-		    if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1308
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1309
-		    if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1310
-		    if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1311
-		    if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1312
-		    if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1734
+		    if (isset($line['callsign'])) {
1735
+		    	$data['ident'] = trim($line['callsign']);
1736
+		    }
1737
+		    // ident
1738
+		    if (isset($line['altitude'])) {
1739
+		    	$data['altitude'] = $line['altitude'];
1740
+		    }
1741
+		    // altitude
1742
+		    if (isset($line['speed'])) {
1743
+		    	$data['speed'] = $line['speed'];
1744
+		    }
1745
+		    // speed
1746
+		    if (isset($line['heading'])) {
1747
+		    	$data['heading'] = $line['heading'];
1748
+		    }
1749
+		    // heading
1750
+		    if (isset($line['lat'])) {
1751
+		    	$data['latitude'] = $line['lat'];
1752
+		    }
1753
+		    // lat
1754
+		    if (isset($line['lon'])) {
1755
+		    	$data['longitude'] = $line['lon'];
1756
+		    }
1757
+		    // long
1758
+		    if (isset($line['vert_rate'])) {
1759
+		    	$data['verticalrate'] = $line['vert_rate'];
1760
+		    }
1761
+		    // verticale rate
1762
+		    if (isset($line['squawk'])) {
1763
+		    	$data['squawk'] = $line['squawk'];
1764
+		    }
1765
+		    // squawk
1313 1766
 		    //$data['emergency'] = ''; // emergency
1314
-		    if (isset($line['reg'])) $data['registration'] = $line['reg'];
1315
-		    if (isset($line['type'])) $data['aircraft_icao'] = $line['type'];
1767
+		    if (isset($line['reg'])) {
1768
+		    	$data['registration'] = $line['reg'];
1769
+		    }
1770
+		    if (isset($line['type'])) {
1771
+		    	$data['aircraft_icao'] = $line['type'];
1772
+		    }
1316 1773
 		    $data['datetime'] = date('Y-m-d H:i:s',$line['pos_update_time']);
1317 1774
 		    $data['format_source'] = 'planefinderclient';
1318 1775
 		    $data['id_source'] = $id_source;
1319
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1320
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1776
+		    if (isset($value['name']) && $value['name'] != '') {
1777
+		    	$data['source_name'] = $value['name'];
1778
+		    }
1779
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1780
+		    	$data['noarchive'] = true;
1781
+		    }
1321 1782
 		    $SI->add($data);
1322 1783
 		    unset($data);
1323 1784
 		}
@@ -1333,7 +1794,9 @@  discard block
 block discarded – undo
1333 1794
 	    //$buffer = $Common->getData($hosts[$id]);
1334 1795
 	    $buffer = $Common->getData($value['host']);
1335 1796
 	    $all_data = json_decode($buffer,true);
1336
-	    if (!empty($all_data)) $reset = 0;
1797
+	    if (!empty($all_data)) {
1798
+	    	$reset = 0;
1799
+	    }
1337 1800
 	    foreach ($all_data as $key => $line) {
1338 1801
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
1339 1802
 		    $data = array();
@@ -1354,8 +1817,12 @@  discard block
 block discarded – undo
1354 1817
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1355 1818
 	    	    $data['format_source'] = 'fr24json';
1356 1819
     		    $data['id_source'] = $id_source;
1357
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1358
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1820
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1821
+		    	$data['noarchive'] = true;
1822
+		    }
1823
+		    if (isset($value['name']) && $value['name'] != '') {
1824
+		    	$data['source_name'] = $value['name'];
1825
+		    }
1359 1826
 		    $SI->add($data);
1360 1827
 		    unset($data);
1361 1828
 		}
@@ -1384,24 +1851,42 @@  discard block
 block discarded – undo
1384 1851
 		    if (isset($line['inf'])) {
1385 1852
 			$data = array();
1386 1853
 			$data['hex'] = $line['inf']['ia'];
1387
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1854
+			if (isset($line['inf']['cs'])) {
1855
+				$data['ident'] = $line['inf']['cs'];
1856
+			}
1857
+			//$line[13]
1388 1858
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1389
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1390
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1859
+	    		if (isset($line['inf']['gs'])) {
1860
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1861
+	    		}
1862
+	    		// speed
1863
+	    		if (isset($line['inf']['tr'])) {
1864
+	    			$data['heading'] = $line['inf']['tr'];
1865
+	    		}
1866
+	    		// heading
1391 1867
 	    		$data['latitude'] = $line['pt'][0]; // lat
1392 1868
 	    		$data['longitude'] = $line['pt'][1]; // long
1393 1869
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1394
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1870
+	    		if (isset($line['inf']['sq'])) {
1871
+	    			$data['squawk'] = $line['inf']['sq'];
1872
+	    		}
1873
+	    		// squawk
1395 1874
 	    		//$data['aircraft_icao'] = $line[8];
1396
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1875
+	    		if (isset($line['inf']['rc'])) {
1876
+	    			$data['registration'] = $line['inf']['rc'];
1877
+	    		}
1397 1878
 			//$data['departure_airport_iata'] = $line[11];
1398 1879
 			//$data['arrival_airport_iata'] = $line[12];
1399 1880
 	    		//$data['emergency'] = ''; // emergency
1400 1881
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1401 1882
 	    		$data['format_source'] = 'radarvirtueljson';
1402 1883
     			$data['id_source'] = $id_source;
1403
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1404
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1884
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1885
+				$data['noarchive'] = true;
1886
+			}
1887
+			if (isset($value['name']) && $value['name'] != '') {
1888
+				$data['source_name'] = $value['name'];
1889
+			}
1405 1890
 			$SI->add($data);
1406 1891
 			unset($data);
1407 1892
 		    }
@@ -1427,30 +1912,65 @@  discard block
 block discarded – undo
1427 1912
 		    $data['id'] = $line['id'];
1428 1913
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1429 1914
 		    $data['ident'] = $line['callsign']; // ident
1430
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1431
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1432
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1433
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1434
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1435
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1915
+		    if (isset($line['pilotid'])) {
1916
+		    	$data['pilot_id'] = $line['pilotid'];
1917
+		    }
1918
+		    // pilot id
1919
+		    if (isset($line['name'])) {
1920
+		    	$data['pilot_name'] = $line['name'];
1921
+		    }
1922
+		    // pilot name
1923
+		    if (isset($line['alt'])) {
1924
+		    	$data['altitude'] = $line['alt'];
1925
+		    }
1926
+		    // altitude
1927
+		    if (isset($line['gs'])) {
1928
+		    	$data['speed'] = $line['gs'];
1929
+		    }
1930
+		    // speed
1931
+		    if (isset($line['heading'])) {
1932
+		    	$data['heading'] = $line['heading'];
1933
+		    }
1934
+		    // heading
1935
+		    if (isset($line['route'])) {
1936
+		    	$data['waypoints'] = $line['route'];
1937
+		    }
1938
+		    // route
1436 1939
 		    $data['latitude'] = $line['lat']; // lat
1437 1940
 		    $data['longitude'] = $line['lon']; // long
1438 1941
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
1439 1942
 		    //$data['squawk'] = $line['squawk']; // squawk
1440 1943
 		    //$data['emergency'] = ''; // emergency
1441
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1442
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1443
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1944
+		    if (isset($line['depicao'])) {
1945
+		    	$data['departure_airport_icao'] = $line['depicao'];
1946
+		    }
1947
+		    if (isset($line['deptime'])) {
1948
+		    	$data['departure_airport_time'] = $line['deptime'];
1949
+		    }
1950
+		    if (isset($line['arricao'])) {
1951
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1952
+		    }
1444 1953
 		    //$data['arrival_airport_time'] = $line['arrtime'];
1445
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1446
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1447
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
1448
-		    else $data['info'] = '';
1954
+		    if (isset($line['aircraft'])) {
1955
+		    	$data['aircraft_icao'] = $line['aircraft'];
1956
+		    }
1957
+		    if (isset($line['transponder'])) {
1958
+		    	$data['squawk'] = $line['transponder'];
1959
+		    }
1960
+		    if (isset($line['atis'])) {
1961
+		    	$data['info'] = $line['atis'];
1962
+		    } else {
1963
+		    	$data['info'] = '';
1964
+		    }
1449 1965
 		    $data['format_source'] = 'pireps';
1450 1966
     		    $data['id_source'] = $id_source;
1451 1967
 		    $data['datetime'] = date('Y-m-d H:i:s');
1452
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1453
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1968
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1969
+		    	$data['noarchive'] = true;
1970
+		    }
1971
+		    if (isset($value['name']) && $value['name'] != '') {
1972
+		    	$data['source_name'] = $value['name'];
1973
+		    }
1454 1974
 		    if ($line['icon'] === 'plane') {
1455 1975
 			$SI->add($data);
1456 1976
 		    //    print_r($data);
@@ -1459,16 +1979,28 @@  discard block
 block discarded – undo
1459 1979
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1460 1980
 			$typec = substr($data['ident'],-3);
1461 1981
 			$data['type'] = '';
1462
-			if ($typec === 'APP') $data['type'] = 'Approach';
1463
-			elseif ($typec === 'TWR') $data['type'] = 'Tower';
1464
-			elseif ($typec === 'OBS') $data['type'] = 'Observer';
1465
-			elseif ($typec === 'GND') $data['type'] = 'Ground';
1466
-			elseif ($typec === 'DEL') $data['type'] = 'Delivery';
1467
-			elseif ($typec === 'DEP') $data['type'] = 'Departure';
1468
-			elseif ($typec === 'FSS') $data['type'] = 'Flight Service Station';
1469
-			elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
1470
-			else $data['type'] = 'Observer';
1471
-			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']);
1982
+			if ($typec === 'APP') {
1983
+				$data['type'] = 'Approach';
1984
+			} elseif ($typec === 'TWR') {
1985
+				$data['type'] = 'Tower';
1986
+			} elseif ($typec === 'OBS') {
1987
+				$data['type'] = 'Observer';
1988
+			} elseif ($typec === 'GND') {
1989
+				$data['type'] = 'Ground';
1990
+			} elseif ($typec === 'DEL') {
1991
+				$data['type'] = 'Delivery';
1992
+			} elseif ($typec === 'DEP') {
1993
+				$data['type'] = 'Departure';
1994
+			} elseif ($typec === 'FSS') {
1995
+				$data['type'] = 'Flight Service Station';
1996
+			} elseif ($typec === 'CTR') {
1997
+				$data['type'] = 'Control Radar or Centre';
1998
+			} else {
1999
+				$data['type'] = 'Observer';
2000
+			}
2001
+			if (isset($ATC)) {
2002
+				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']);
2003
+			}
1472 2004
 		    }
1473 2005
 		    unset($data);
1474 2006
 		}
@@ -1483,7 +2015,9 @@  discard block
 block discarded – undo
1483 2015
 	    )
1484 2016
 	) {
1485 2017
 	    //$buffer = $Common->getData($hosts[$id]);
1486
-	    if ($globalDebug) echo 'Get Data...'."\n";
2018
+	    if ($globalDebug) {
2019
+	    	echo 'Get Data...'."\n";
2020
+	    }
1487 2021
 	    $buffer = $Common->getData($value['host']);
1488 2022
 	    $all_data = json_decode($buffer,true);
1489 2023
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1491,10 +2025,16 @@  discard block
 block discarded – undo
1491 2025
 		foreach ($all_data as $line) {
1492 2026
 	    	    $data = array();
1493 2027
 	    	    //$data['id'] = $line['id']; // id not usable
1494
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
2028
+	    	    if (isset($line['pilotid'])) {
2029
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
2030
+	    	    }
1495 2031
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1496
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1497
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
2032
+	    	    if (isset($line['pilotname'])) {
2033
+	    	    	$data['pilot_name'] = $line['pilotname'];
2034
+	    	    }
2035
+	    	    if (isset($line['pilotid'])) {
2036
+	    	    	$data['pilot_id'] = $line['pilotid'];
2037
+	    	    }
1498 2038
 	    	    $data['ident'] = $line['flightnum']; // ident
1499 2039
 	    	    $data['altitude'] = $line['alt']; // altitude
1500 2040
 	    	    $data['speed'] = $line['gs']; // speed
@@ -1510,7 +2050,9 @@  discard block
 block discarded – undo
1510 2050
 	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1511 2051
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1512 2052
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1513
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
2053
+	    	    } else {
2054
+	    	    	$data['datetime'] = date('Y-m-d H:i:s');
2055
+	    	    }
1514 2056
 	    	    $data['departure_airport_icao'] = $line['depicao'];
1515 2057
 	    	    $data['departure_airport_time'] = $line['deptime'];
1516 2058
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
@@ -1518,29 +2060,47 @@  discard block
 block discarded – undo
1518 2060
     		    if (isset($line['registration'])) {
1519 2061
     			$data['registration'] = $line['registration'];
1520 2062
     			//if (isset($line['aircraft'])) $data['id'] = $line['aircraft'];
1521
-    		    } else $data['registration'] = $line['aircraft'];
1522
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1523
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
2063
+    		    } else {
2064
+    		    	$data['registration'] = $line['aircraft'];
2065
+    		    }
2066
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
2067
+		    	$data['noarchive'] = true;
2068
+		    }
2069
+		    if (isset($line['route'])) {
2070
+		    	$data['waypoints'] = $line['route'];
2071
+		    }
2072
+		    // route
1524 2073
 		    if (isset($line['aircraftname'])) {
1525 2074
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1526 2075
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1527 2076
 	    		$aircraft_data = explode('-',$line['aircraftname']);
1528
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1529
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1530
-	    		else {
2077
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) {
2078
+	    			$data['aircraft_icao'] = $aircraft_data[0];
2079
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) {
2080
+	    			$data['aircraft_icao'] = $aircraft_data[1];
2081
+	    		} else {
1531 2082
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1532
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1533
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
2083
+	    		    if (isset($aircraft_data[1])) {
2084
+	    		    	$data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
2085
+	    		    } else {
2086
+	    		    	$data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
2087
+	    		    }
1534 2088
 	    		}
1535 2089
 	    	    }
1536
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
2090
+    		    if (isset($line['route'])) {
2091
+    		    	$data['waypoints'] = $line['route'];
2092
+    		    }
1537 2093
     		    $data['id_source'] = $id_source;
1538 2094
 	    	    $data['format_source'] = 'phpvmacars';
1539
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
2095
+		    if (isset($value['name']) && $value['name'] != '') {
2096
+		    	$data['source_name'] = $value['name'];
2097
+		    }
1540 2098
 		    $SI->add($data);
1541 2099
 		    unset($data);
1542 2100
 		}
1543
-		if ($globalDebug) echo 'No more data...'."\n";
2101
+		if ($globalDebug) {
2102
+			echo 'No more data...'."\n";
2103
+		}
1544 2104
 		unset($buffer);
1545 2105
 		unset($all_data);
1546 2106
 	    }
@@ -1553,7 +2113,9 @@  discard block
 block discarded – undo
1553 2113
 	    )
1554 2114
 	) {
1555 2115
 	    //$buffer = $Common->getData($hosts[$id]);
1556
-	    if ($globalDebug) echo 'Get Data...'."\n";
2116
+	    if ($globalDebug) {
2117
+	    	echo 'Get Data...'."\n";
2118
+	    }
1557 2119
 	    $buffer = $Common->getData($value['host']);
1558 2120
 	    $all_data = json_decode($buffer,true);
1559 2121
 	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
@@ -1564,10 +2126,16 @@  discard block
 block discarded – undo
1564 2126
 	    	    //$data['id'] = $line['id']; // id not usable
1565 2127
 	    	    $data['id'] = $line['id'];
1566 2128
 	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1567
-	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1568
-	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
2129
+	    	    if (isset($line['user']['username'])) {
2130
+	    	    	$data['pilot_name'] = $line['user']['username'];
2131
+	    	    }
2132
+	    	    if (isset($line['user_id'])) {
2133
+	    	    	$data['pilot_id'] = $line['user_id'];
2134
+	    	    }
1569 2135
 	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1570
-	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
2136
+	    	    if (is_numeric($data['ident'])) {
2137
+	    	    	$data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
2138
+	    	    }
1571 2139
 	    	    $data['altitude'] = $line['altitude']; // altitude
1572 2140
 	    	    $data['speed'] = $line['groundspeed']; // speed
1573 2141
 	    	    $data['heading'] = $line['heading']; // heading
@@ -1580,7 +2148,9 @@  discard block
 block discarded – undo
1580 2148
 	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1581 2149
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1582 2150
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1583
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
2151
+	    	    } else {
2152
+	    	    	$data['datetime'] = date('Y-m-d H:i:s');
2153
+	    	    }
1584 2154
 	    	    
1585 2155
 	    	    $data['departure_airport_icao'] = $line['bid']['depapt']['icao'];
1586 2156
 	    	    $data['departure_airport_time'] = $line['bid']['deptime'];
@@ -1588,17 +2158,26 @@  discard block
 block discarded – undo
1588 2158
 		    $data['arrival_airport_time'] = $line['bid']['arrtime'];
1589 2159
 		    $data['registration'] = $line['bid']['aircraft']['registration'];
1590 2160
 
1591
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1592
-		    if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route
2161
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
2162
+		    	$data['noarchive'] = true;
2163
+		    }
2164
+		    if (isset($line['bid']['route']) && $line['bid']['route'] != '') {
2165
+		    	$data['waypoints'] = $line['bid']['route'];
2166
+		    }
2167
+		    // route
1593 2168
 	    	    $data['aircraft_icao'] = $line['bid']['aircraft']['icao'];
1594 2169
 
1595 2170
     		    $data['id_source'] = $id_source;
1596 2171
 	    	    $data['format_source'] = 'vaos';
1597
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
2172
+		    if (isset($value['name']) && $value['name'] != '') {
2173
+		    	$data['source_name'] = $value['name'];
2174
+		    }
1598 2175
 		    $SI->add($data);
1599 2176
 		    unset($data);
1600 2177
 		}
1601
-		if ($globalDebug) echo 'No more data...'."\n";
2178
+		if ($globalDebug) {
2179
+			echo 'No more data...'."\n";
2180
+		}
1602 2181
 		unset($buffer);
1603 2182
 		unset($all_data);
1604 2183
 	    }
@@ -1611,7 +2190,9 @@  discard block
 block discarded – undo
1611 2190
 	    )
1612 2191
 	) {
1613 2192
 	    //$buffer = $Common->getData($hosts[$id]);
1614
-	    if ($globalDebug) echo 'Get Data...'."\n";
2193
+	    if ($globalDebug) {
2194
+	    	echo 'Get Data...'."\n";
2195
+	    }
1615 2196
 	    $buffer = $Common->getData($value['host']);
1616 2197
 	    $all_data = json_decode($buffer,true);
1617 2198
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1640,16 +2221,25 @@  discard block
 block discarded – undo
1640 2221
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
1641 2222
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
1642 2223
     		    //$data['registration'] = $line['aircraft'];
1643
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
2224
+		    if (isset($line['route'])) {
2225
+		    	$data['waypoints'] = $line['route'];
2226
+		    }
2227
+		    // route
1644 2228
 	    	    $data['aircraft_icao'] = $line['plane_type'];
1645 2229
     		    $data['id_source'] = $id_source;
1646 2230
 	    	    $data['format_source'] = 'vam';
1647
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1648
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
2231
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
2232
+		    	$data['noarchive'] = true;
2233
+		    }
2234
+		    if (isset($value['name']) && $value['name'] != '') {
2235
+		    	$data['source_name'] = $value['name'];
2236
+		    }
1649 2237
 		    $SI->add($data);
1650 2238
 		    unset($data);
1651 2239
 		}
1652
-		if ($globalDebug) echo 'No more data...'."\n";
2240
+		if ($globalDebug) {
2241
+			echo 'No more data...'."\n";
2242
+		}
1653 2243
 		unset($buffer);
1654 2244
 		unset($all_data);
1655 2245
 	    }
@@ -1662,7 +2252,9 @@  discard block
 block discarded – undo
1662 2252
 	    )
1663 2253
 	) {
1664 2254
 	    //$buffer = $Common->getData($hosts[$id]);
1665
-	    if ($globalDebug) echo 'Get Data...'."\n";
2255
+	    if ($globalDebug) {
2256
+	    	echo 'Get Data...'."\n";
2257
+	    }
1666 2258
 	    $buffer = $Common->getData($value['host']);
1667 2259
 	    $all_data = json_decode($buffer,true);
1668 2260
 	    if ($buffer != '') {
@@ -1680,12 +2272,16 @@  discard block
 block discarded – undo
1680 2272
 			$data['id_source'] = $id_source;
1681 2273
 			$data['format_source'] = 'blitzortung';
1682 2274
 			$SI->add($data);
1683
-			if ($globalDebug) echo '☈ Lightning added'."\n";
2275
+			if ($globalDebug) {
2276
+				echo '☈ Lightning added'."\n";
2277
+			}
1684 2278
 			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1685 2279
 			unset($data);
1686 2280
 		    }
1687 2281
 		}
1688
-		if ($globalDebug) echo 'No more data...'."\n";
2282
+		if ($globalDebug) {
2283
+			echo 'No more data...'."\n";
2284
+		}
1689 2285
 		unset($buffer);
1690 2286
 	    }
1691 2287
 	    $last_exec[$id]['last'] = time();
@@ -1714,10 +2310,15 @@  discard block
 block discarded – undo
1714 2310
                 }
1715 2311
             } else {
1716 2312
                 $format = $value['format'];
1717
-                if (isset($tt[$format])) $tt[$format]++;
1718
-                else $tt[$format] = 0;
2313
+                if (isset($tt[$format])) {
2314
+                	$tt[$format]++;
2315
+                } else {
2316
+                	$tt[$format] = 0;
2317
+                }
1719 2318
                 if ($tt[$format] > 30) {
1720
-                    if ($globalDebug) echo 'Reconnect...'."\n";
2319
+                    if ($globalDebug) {
2320
+                    	echo 'Reconnect...'."\n";
2321
+                    }
1721 2322
                     sleep(2);
1722 2323
                     //$sourceeen[] = $value;
1723 2324
                     //connect_all($sourceeen);
@@ -1734,7 +2335,9 @@  discard block
 block discarded – undo
1734 2335
 	    $write = NULL;
1735 2336
 	    $e = NULL;
1736 2337
 	    $n = socket_select($read, $write, $e, $timeout);
1737
-	    if ($e != NULL) var_dump($e);
2338
+	    if ($e != NULL) {
2339
+	    	var_dump($e);
2340
+	    }
1738 2341
 	    if ($n > 0) {
1739 2342
 		$reset = 0;
1740 2343
 		foreach ($read as $nb => $r) {
@@ -1756,13 +2359,17 @@  discard block
 block discarded – undo
1756 2359
 		    if ($buffer !== FALSE) {
1757 2360
 			if ($format === 'vrstcp') {
1758 2361
 			    $buffer = explode('},{',$buffer);
1759
-			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
2362
+			} else {
2363
+				$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
2364
+			}
1760 2365
 		    }
1761 2366
 		    // SBS format is CSV format
1762 2367
 		    if ($buffer !== FALSE && $buffer !== '') {
1763 2368
 			$tt[$format] = 0;
1764 2369
 			if ($format === 'acarssbs3') {
1765
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
2370
+			    if ($globalDebug) {
2371
+			    	echo 'ACARS : '.$buffer."\n";
2372
+			    }
1766 2373
 			    $ACARS->add(trim($buffer));
1767 2374
 			    $ACARS->deleteLiveAcarsData();
1768 2375
 			} elseif ($format === 'raw') {
@@ -1772,9 +2379,15 @@  discard block
 block discarded – undo
1772 2379
 				//if (!empty($data)) print_r($data);
1773 2380
 				$data['datetime'] = date('Y-m-d H:i:s');
1774 2381
 				$data['format_source'] = 'raw';
1775
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1776
-				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1777
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
2382
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2383
+					$data['source_name'] = $globalSources[$nb]['name'];
2384
+				}
2385
+				if (isset($globalSources[$nb]['sourcestats'])) {
2386
+					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2387
+				}
2388
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2389
+					$data['noarchive'] = true;
2390
+				}
1778 2391
 				//if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1779 2392
 				$SI->add($data);
1780 2393
 				unset($data);
@@ -1782,22 +2395,54 @@  discard block
 block discarded – undo
1782 2395
 			} elseif ($format === 'ais') {
1783 2396
 			    $ais_data = $AIS->parse_line(trim($buffer));
1784 2397
 			    $data = array();
1785
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1786
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1787
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1788
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1789
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1790
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1791
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1792
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1793
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1794
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1795
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1796
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1797
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1798
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1799
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1800
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2398
+			    if (isset($ais_data['ident'])) {
2399
+			    	$data['ident'] = $ais_data['ident'];
2400
+			    }
2401
+			    if (isset($ais_data['mmsi'])) {
2402
+			    	$data['mmsi'] = substr($ais_data['mmsi'],-9);
2403
+			    }
2404
+			    if (isset($ais_data['speed'])) {
2405
+			    	$data['speed'] = $ais_data['speed'];
2406
+			    }
2407
+			    if (isset($ais_data['heading'])) {
2408
+			    	$data['heading'] = $ais_data['heading'];
2409
+			    }
2410
+			    if (isset($ais_data['latitude'])) {
2411
+			    	$data['latitude'] = $ais_data['latitude'];
2412
+			    }
2413
+			    if (isset($ais_data['longitude'])) {
2414
+			    	$data['longitude'] = $ais_data['longitude'];
2415
+			    }
2416
+			    if (isset($ais_data['status'])) {
2417
+			    	$data['status'] = $ais_data['status'];
2418
+			    }
2419
+			    if (isset($ais_data['statusid'])) {
2420
+			    	$data['status_id'] = $ais_data['statusid'];
2421
+			    }
2422
+			    if (isset($ais_data['type'])) {
2423
+			    	$data['type'] = $ais_data['type'];
2424
+			    }
2425
+			    if (isset($ais_data['imo'])) {
2426
+			    	$data['imo'] = $ais_data['imo'];
2427
+			    }
2428
+			    if (isset($ais_data['callsign'])) {
2429
+			    	$data['callsign'] = $ais_data['callsign'];
2430
+			    }
2431
+			    if (isset($ais_data['destination'])) {
2432
+			    	$data['arrival_code'] = $ais_data['destination'];
2433
+			    }
2434
+			    if (isset($ais_data['eta_ts'])) {
2435
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
2436
+			    }
2437
+			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2438
+			    	$data['noarchive'] = true;
2439
+			    }
2440
+			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2441
+			    	$data['source_name'] = $globalSources[$nb]['name'];
2442
+			    }
2443
+			    if (isset($globalSources[$nb]['sourcestats'])) {
2444
+			    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2445
+			    }
1801 2446
 
1802 2447
 			    if (isset($ais_data['timestamp'])) {
1803 2448
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1806,7 +2451,9 @@  discard block
 block discarded – undo
1806 2451
 			    }
1807 2452
 			    $data['format_source'] = 'aisnmea';
1808 2453
     			    $data['id_source'] = $id_source;
1809
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
2454
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') {
2455
+			    	$MI->add($data);
2456
+			    }
1810 2457
 			    unset($data);
1811 2458
                         } elseif ($format === 'flightgearsp') {
1812 2459
                     	    //echo $buffer."\n";
@@ -1824,17 +2471,25 @@  discard block
 block discarded – undo
1824 2471
 				$data['speed'] = round($line[5]*1.94384);
1825 2472
 				$data['datetime'] = date('Y-m-d H:i:s');
1826 2473
 				$data['format_source'] = 'flightgearsp';
1827
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1828
-				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2474
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2475
+					$data['noarchive'] = true;
2476
+				}
2477
+				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2478
+					$SI->add($data);
2479
+				}
1829 2480
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1830 2481
 			    }
1831 2482
                         } elseif ($format === 'acars') {
1832
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
2483
+                    	    if ($globalDebug) {
2484
+                    	    	echo 'ACARS : '.$buffer."\n";
2485
+                    	    }
1833 2486
 			    $ACARS->add(trim($buffer));
1834 2487
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1835 2488
 			    $ACARS->deleteLiveAcarsData();
1836 2489
 			} elseif ($format === 'acarsjsonudp') {
1837
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
2490
+			    if ($globalDebug) {
2491
+			    	echo 'ACARS : '.$buffer."\n";
2492
+			    }
1838 2493
                             $line = json_decode(trim($buffer), true);
1839 2494
                             if (!empty($line)) {
1840 2495
 				$line = array_merge(array('text' => '','tail' => '','label' => '','block_id' => '','flight' => '','msgno' => ''),$line);
@@ -1859,8 +2514,12 @@  discard block
 block discarded – undo
1859 2514
 				    $aircraft_type = $line[10];
1860 2515
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1861 2516
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1862
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1863
-				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2517
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2518
+				    	$data['noarchive'] = true;
2519
+				    }
2520
+				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2521
+				    	$SI->add($data);
2522
+				    }
1864 2523
 				}
1865 2524
 			    }
1866 2525
 			} elseif ($format === 'beast') {
@@ -1870,28 +2529,62 @@  discard block
 block discarded – undo
1870 2529
 			    foreach($buffer as $all_data) {
1871 2530
 				$line = json_decode('{'.$all_data.'}',true);
1872 2531
 				$data = array();
1873
-				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1874
-				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1875
-				if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1876
-				if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1877
-				if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1878
-				if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1879
-				if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
2532
+				if (isset($line['Icao'])) {
2533
+					$data['hex'] = $line['Icao'];
2534
+				}
2535
+				// hex
2536
+				if (isset($line['Call'])) {
2537
+					$data['ident'] = $line['Call'];
2538
+				}
2539
+				// ident
2540
+				if (isset($line['Alt'])) {
2541
+					$data['altitude'] = $line['Alt'];
2542
+				}
2543
+				// altitude
2544
+				if (isset($line['Spd'])) {
2545
+					$data['speed'] = $line['Spd'];
2546
+				}
2547
+				// speed
2548
+				if (isset($line['Trak'])) {
2549
+					$data['heading'] = $line['Trak'];
2550
+				}
2551
+				// heading
2552
+				if (isset($line['Lat'])) {
2553
+					$data['latitude'] = $line['Lat'];
2554
+				}
2555
+				// lat
2556
+				if (isset($line['Long'])) {
2557
+					$data['longitude'] = $line['Long'];
2558
+				}
2559
+				// long
1880 2560
 				//$data['verticalrate'] = $line['']; // verticale rate
1881
-				if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
2561
+				if (isset($line['Sqk'])) {
2562
+					$data['squawk'] = $line['Sqk'];
2563
+				}
2564
+				// squawk
1882 2565
 				$data['emergency'] = ''; // emergency
1883
-				if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
2566
+				if (isset($line['Reg'])) {
2567
+					$data['registration'] = $line['Reg'];
2568
+				}
1884 2569
 				/*
1885 2570
 				if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
1886 2571
 				else $data['datetime'] = date('Y-m-d H:i:s');
1887 2572
 				*/
1888 2573
 				$data['datetime'] = date('Y-m-d H:i:s');
1889
-				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
2574
+				if (isset($line['Type'])) {
2575
+					$data['aircraft_icao'] = $line['Type'];
2576
+				}
1890 2577
 		    		$data['format_source'] = 'vrstcp';
1891 2578
 				$data['id_source'] = $id_source;
1892
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1893
-				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1894
-				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
2579
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2580
+					$data['noarchive'] = true;
2581
+				}
2582
+				if (isset($value['name']) && $value['name'] != '') {
2583
+					$data['source_name'] = $value['name'];
2584
+				}
2585
+				if (isset($data['latitude']) && isset($data['hex'])) {
2586
+					$SI->add($data);
2587
+				}
1895 2588
 				unset($data);
1896 2589
 			    }
1897 2590
 			} elseif ($format === 'tsv' || substr($buffer,0,4) === 'clock') {
@@ -1904,22 +2597,46 @@  discard block
 block discarded – undo
1904 2597
     				$data['hex'] = $lined['hexid'];
1905 2598
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1906 2599
     				$data['datetime'] = date('Y-m-d H:i:s');;
1907
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1908
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1909
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1910
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1911
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1912
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1913
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
2600
+    				if (isset($lined['ident'])) {
2601
+    					$data['ident'] = $lined['ident'];
2602
+    				}
2603
+    				if (isset($lined['lat'])) {
2604
+    					$data['latitude'] = $lined['lat'];
2605
+    				}
2606
+    				if (isset($lined['lon'])) {
2607
+    					$data['longitude'] = $lined['lon'];
2608
+    				}
2609
+    				if (isset($lined['speed'])) {
2610
+    					$data['speed'] = $lined['speed'];
2611
+    				}
2612
+    				if (isset($lined['squawk'])) {
2613
+    					$data['squawk'] = $lined['squawk'];
2614
+    				}
2615
+    				if (isset($lined['alt'])) {
2616
+    					$data['altitude'] = $lined['alt'];
2617
+    				}
2618
+    				if (isset($lined['heading'])) {
2619
+    					$data['heading'] = $lined['heading'];
2620
+    				}
1914 2621
     				$data['id_source'] = $id_source;
1915 2622
     				$data['format_source'] = 'tsv';
1916
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1917
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1918
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1919
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2623
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2624
+    					$data['source_name'] = $globalSources[$nb]['name'];
2625
+    				}
2626
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2627
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2628
+    				}
2629
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2630
+					$data['noarchive'] = true;
2631
+				}
2632
+    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2633
+    					$SI->add($data);
2634
+    				}
1920 2635
     				unset($lined);
1921 2636
     				unset($data);
1922
-    			    } else $error = true;
2637
+    			    } else {
2638
+    			    	$error = true;
2639
+    			    }
1923 2640
 			} elseif ($format === 'aprs' && $use_aprs) {
1924 2641
 			    if ($aprs_connect === 0) {
1925 2642
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1945,47 +2662,96 @@  discard block
 block discarded – undo
1945 2662
 				    $aprs_last_tx = time();
1946 2663
 				    $data = array();
1947 2664
 				    //print_r($line);
1948
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1949
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1950
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1951
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1952
-				    if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code'];
1953
-				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1954
-				    if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1955
-				    if (isset($line['statusid'])) $data['status_id'] = $line['statusid'];
1956
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1957
-				    else $data['datetime'] = date('Y-m-d H:i:s');
2665
+				    if (isset($line['address'])) {
2666
+				    	$data['hex'] = $line['address'];
2667
+				    }
2668
+				    if (isset($line['mmsi'])) {
2669
+				    	$data['mmsi'] = $line['mmsi'];
2670
+				    }
2671
+				    if (isset($line['imo'])) {
2672
+				    	$data['imo'] = $line['imo'];
2673
+				    }
2674
+				    if (isset($line['squawk'])) {
2675
+				    	$data['squawk'] = $line['squawk'];
2676
+				    }
2677
+				    if (isset($line['arrival_code'])) {
2678
+				    	$data['arrival_code'] = $line['arrival_code'];
2679
+				    }
2680
+				    if (isset($line['arrival_date'])) {
2681
+				    	$data['arrival_date'] = $line['arrival_date'];
2682
+				    }
2683
+				    if (isset($line['typeid'])) {
2684
+				    	$data['type_id'] = $line['typeid'];
2685
+				    }
2686
+				    if (isset($line['statusid'])) {
2687
+				    	$data['status_id'] = $line['statusid'];
2688
+				    }
2689
+				    if (isset($line['timestamp'])) {
2690
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
2691
+				    } else {
2692
+				    	$data['datetime'] = date('Y-m-d H:i:s');
2693
+				    }
1958 2694
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1959
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
2695
+				    if (isset($line['ident'])) {
2696
+				    	$data['ident'] = $line['ident'];
2697
+				    }
1960 2698
 				    $data['latitude'] = $line['latitude'];
1961 2699
 				    $data['longitude'] = $line['longitude'];
1962 2700
 				    //$data['verticalrate'] = $line[16];
1963
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
2701
+				    if (isset($line['speed'])) {
2702
+				    	$data['speed'] = $line['speed'];
2703
+				    }
1964 2704
 				    //else $data['speed'] = 0;
1965
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1966
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1967
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
2705
+				    if (isset($line['altitude'])) {
2706
+				    	$data['altitude'] = $line['altitude'];
2707
+				    }
2708
+				    if (isset($line['comment'])) {
2709
+				    	$data['comment'] = $line['comment'];
2710
+				    }
2711
+				    if (isset($line['symbol'])) {
2712
+				    	$data['type'] = $line['symbol'];
2713
+				    }
1968 2714
 				    //if (isset($line['heading'])) $data['heading'] = $line['heading'];
1969 2715
 				    
1970
-				    if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
2716
+				    if (isset($line['heading']) && isset($line['format_source'])) {
2717
+				    	$data['heading'] = $line['heading'];
2718
+				    }
1971 2719
 				    //else echo 'No heading...'."\n";
1972 2720
 				    //else $data['heading'] = 0;
1973
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
2721
+				    if (isset($line['stealth'])) {
2722
+				    	$data['aircraft_type'] = $line['stealth'];
2723
+				    }
1974 2724
 				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1975
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1976
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1977
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1978
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
2725
+				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) {
2726
+				    	$data['noarchive'] = true;
2727
+				    } elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) {
2728
+				    	$data['noarchive'] = false;
2729
+				    }
2730
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2731
+				    	$data['noarchive'] = true;
2732
+				    } elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) {
2733
+				    	$data['noarchive'] = false;
2734
+				    }
1979 2735
     				    $data['id_source'] = $id_source;
1980
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1981
-				    else $data['format_source'] = 'aprs';
2736
+    				    if (isset($line['format_source'])) {
2737
+    				    	$data['format_source'] = $line['format_source'];
2738
+    				    } else {
2739
+				    	$data['format_source'] = 'aprs';
2740
+				    }
1982 2741
 				    $data['source_name'] = $line['source'];
1983
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1984
-				    else $data['source_type'] = 'flarm';
1985
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2742
+				    if (isset($line['source_type'])) {
2743
+				    	$data['source_type'] = $line['source_type'];
2744
+				    } else {
2745
+				    	$data['source_type'] = 'flarm';
2746
+				    }
2747
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
2748
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2749
+    				    }
1986 2750
 				    $currentdate = date('Y-m-d H:i:s');
1987 2751
 				    $aprsdate = strtotime($data['datetime']);
1988
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
2752
+				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') {
2753
+				    	$data['altitude_relative'] = 'AMSL';
2754
+				    }
1989 2755
 				    // Accept data if time <= system time + 20s
1990 2756
 				    //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'])))) {
1991 2757
 				    if (
@@ -1997,7 +2763,9 @@  discard block
 block discarded – undo
1997 2763
 					$send = $SI->add($data);
1998 2764
 				    } elseif ($data['source_type'] === 'ais') {
1999 2765
 					$data['type'] = '';
2000
-					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
2766
+					if (isset($globalMarine) && $globalMarine) {
2767
+						$send = $MI->add($data);
2768
+					}
2001 2769
 				    } elseif (isset($line['stealth']) && $line['stealth'] != 0) {
2002 2770
 					 echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
2003 2771
 				    } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
@@ -2005,8 +2773,12 @@  discard block
 block discarded – undo
2005 2773
 					    $line['symbol'] === 'Glider' || 
2006 2774
 					    $line['symbol'] === 'No. Plane' || 
2007 2775
 					    $line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter')) {
2008
-					    if ($line['symbol'] === 'Ballon') $data['aircraft_icao'] = 'BALL';
2009
-					    if ($line['symbol'] === 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
2776
+					    if ($line['symbol'] === 'Ballon') {
2777
+					    	$data['aircraft_icao'] = 'BALL';
2778
+					    }
2779
+					    if ($line['symbol'] === 'Glider') {
2780
+					    	$data['aircraft_icao'] = 'PARAGLIDER';
2781
+					    }
2010 2782
 					    $send = $SI->add($data);
2011 2783
 				    } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
2012 2784
 					    $line['symbol'] === 'Yacht (Sail)' || 
@@ -2037,9 +2809,13 @@  discard block
 block discarded – undo
2037 2809
 				    //} 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') {
2038 2810
 				//    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && $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') {
2039 2811
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
2040
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
2812
+					if (isset($globalTracker) && $globalTracker) {
2813
+						$send = $TI->add($data);
2814
+					}
2041 2815
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
2042
-					if (!isset($data['altitude'])) $data['altitude'] = 0;
2816
+					if (!isset($data['altitude'])) {
2817
+						$data['altitude'] = 0;
2818
+					}
2043 2819
 					$Source->deleteOldLocationByType('gs');
2044 2820
 					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
2045 2821
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
@@ -2048,7 +2824,9 @@  discard block
 block discarded – undo
2048 2824
 					}
2049 2825
 				    } elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
2050 2826
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
2051
-					if ($globalDebug) echo '# Weather Station added'."\n";
2827
+					if ($globalDebug) {
2828
+						echo '# Weather Station added'."\n";
2829
+					}
2052 2830
 					$Source->deleteOldLocationByType('wx');
2053 2831
 					$weather_data = json_encode($line);
2054 2832
 					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
@@ -2058,7 +2836,9 @@  discard block
 block discarded – undo
2058 2836
 					}
2059 2837
 				    } elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
2060 2838
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
2061
-					if ($globalDebug) echo '☈ Lightning added'."\n";
2839
+					if ($globalDebug) {
2840
+						echo '☈ Lightning added'."\n";
2841
+					}
2062 2842
 					$Source->deleteOldLocationByType('lightning');
2063 2843
 					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
2064 2844
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
@@ -2070,8 +2850,7 @@  discard block
 block discarded – undo
2070 2850
 				    	print_r($line);
2071 2851
 				    }
2072 2852
 				    unset($data);
2073
-				}
2074
-				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
2853
+				} elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
2075 2854
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
2076 2855
 				}
2077 2856
 				/*
@@ -2080,7 +2859,9 @@  discard block
 block discarded – undo
2080 2859
 				}
2081 2860
 				*/
2082 2861
 				//elseif ($line === false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
2083
-				elseif ($line === true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
2862
+				elseif ($line === true && $globalDebug) {
2863
+					echo '!! Failed : '.$buffer."!!\n";
2864
+				}
2084 2865
 				if (isset($Source) && isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
2085 2866
 					$Source->deleteOldLocationByType('lightning');
2086 2867
 					$Source->deleteOldLocationByType('wx');
@@ -2117,27 +2898,47 @@  discard block
 block discarded – undo
2117 2898
     				$data['ground'] = $line[21];
2118 2899
     				$data['emergency'] = $line[19];
2119 2900
     				$data['format_source'] = 'sbs';
2120
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
2121
-				elseif ($line[0] == 'MLAT') $data['source_name'] = 'MLAT';
2122
-				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2123
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
2901
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2902
+					$data['source_name'] = $globalSources[$nb]['name'];
2903
+				} elseif ($line[0] == 'MLAT') {
2904
+					$data['source_name'] = 'MLAT';
2905
+				}
2906
+				if (isset($globalSources[$nb]['sourcestats'])) {
2907
+					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2908
+				}
2909
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2910
+					$data['noarchive'] = true;
2911
+				}
2124 2912
     				$data['id_source'] = $id_source;
2125
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
2126
-    				else $error = true;
2913
+    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2914
+    					$send = $SI->add($data);
2915
+    				} else {
2916
+    					$error = true;
2917
+    				}
2127 2918
     				unset($data);
2128
-    			    } else $error = true;
2919
+    			    } else {
2920
+    			    	$error = true;
2921
+    			    }
2129 2922
 			    if ($error) {
2130 2923
 				if (count($line) > 1 && ($line[0] === 'STA' || $line[0] === 'AIR' || $line[0] === 'SEL' || $line[0] === 'ID' || $line[0] === 'CLK')) { 
2131
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
2924
+					if ($globalDebug) {
2925
+						echo "Not a message. Ignoring... \n";
2926
+					}
2132 2927
 				} else {
2133
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
2928
+					if ($globalDebug) {
2929
+						echo "Wrong line format. Ignoring... \n";
2930
+					}
2134 2931
 					if ($globalDebug) {
2135 2932
 						echo $buffer;
2136 2933
 						//print_r($line);
2137 2934
 					}
2138 2935
 					//socket_close($r);
2139
-					if ($globalDebug) echo "Reconnect after an error...\n";
2140
-					if ($format === 'aprs') $aprs_connect = 0;
2936
+					if ($globalDebug) {
2937
+						echo "Reconnect after an error...\n";
2938
+					}
2939
+					if ($format === 'aprs') {
2940
+						$aprs_connect = 0;
2941
+					}
2141 2942
 					$sourceer[$nb] = $globalSources[$nb];
2142 2943
 					connect_all($sourceer);
2143 2944
 					$sourceer = array();
@@ -2145,10 +2946,14 @@  discard block
 block discarded – undo
2145 2946
 			    }
2146 2947
 			}
2147 2948
 			// Sleep for xxx microseconds
2148
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
2949
+			if (isset($globalSBSSleep)) {
2950
+				usleep($globalSBSSleep);
2951
+			}
2149 2952
 		    } else {
2150 2953
 			if ($format === 'flightgearmp') {
2151
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
2954
+			    	if ($globalDebug) {
2955
+			    		echo "Reconnect FlightGear MP...";
2956
+			    	}
2152 2957
 				//@socket_close($r);
2153 2958
 				sleep($globalMinFetch);
2154 2959
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -2157,10 +2962,15 @@  discard block
 block discarded – undo
2157 2962
 				break;
2158 2963
 				
2159 2964
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
2160
-			    if (isset($tt[$format])) $tt[$format]++;
2161
-			    else $tt[$format] = 0;
2965
+			    if (isset($tt[$format])) {
2966
+			    	$tt[$format]++;
2967
+			    } else {
2968
+			    	$tt[$format] = 0;
2969
+			    }
2162 2970
 			    if ($tt[$format] > 30 || $buffer === FALSE) {
2163
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
2971
+				if ($globalDebug) {
2972
+					echo "ERROR : Reconnect ".$format."...";
2973
+				}
2164 2974
 				//@socket_close($r);
2165 2975
 				sleep(2);
2166 2976
 				$aprs_connect = 0;
@@ -2178,11 +2988,17 @@  discard block
 block discarded – undo
2178 2988
 	    } else {
2179 2989
 		$error = socket_strerror(socket_last_error());
2180 2990
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
2181
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
2182
-			if (isset($globalDebug)) echo "Restarting...\n";
2991
+			if ($globalDebug) {
2992
+				echo "ERROR : socket_select give this error ".$error . "\n";
2993
+			}
2994
+			if (isset($globalDebug)) {
2995
+				echo "Restarting...\n";
2996
+			}
2183 2997
 			// Restart the script if possible
2184 2998
 			if (is_array($sockets)) {
2185
-			    if ($globalDebug) echo "Shutdown all sockets...";
2999
+			    if ($globalDebug) {
3000
+			    	echo "Shutdown all sockets...";
3001
+			    }
2186 3002
 			    
2187 3003
 			    foreach ($sockets as $sock) {
2188 3004
 				@socket_shutdown($sock,2);
@@ -2190,25 +3006,45 @@  discard block
 block discarded – undo
2190 3006
 			    }
2191 3007
 			    
2192 3008
 			}
2193
-			if ($globalDebug) echo "Waiting...";
3009
+			if ($globalDebug) {
3010
+				echo "Waiting...";
3011
+			}
2194 3012
 			sleep(2);
2195 3013
 			$time = time();
2196 3014
 			//connect_all($hosts);
2197 3015
 			$aprs_connect = 0;
2198
-			if ($reset%5 === 0) sleep(20);
2199
-			if ($reset%10 === 0) sleep(100);
2200
-			if ($reset%20 === 0) sleep(200);
2201
-			if ($reset > 100) exit('Too many attempts...');
2202
-			if ($globalDebug) echo "Restart all connections...";
3016
+			if ($reset%5 === 0) {
3017
+				sleep(20);
3018
+			}
3019
+			if ($reset%10 === 0) {
3020
+				sleep(100);
3021
+			}
3022
+			if ($reset%20 === 0) {
3023
+				sleep(200);
3024
+			}
3025
+			if ($reset > 100) {
3026
+				exit('Too many attempts...');
3027
+			}
3028
+			if ($globalDebug) {
3029
+				echo "Restart all connections...";
3030
+			}
2203 3031
 			connect_all($globalSources);
2204 3032
 		}
2205 3033
 	    }
2206 3034
 	}
2207 3035
 	if ($globalDaemon === false) {
2208
-	    if ($globalDebug) echo 'Check all...'."\n";
2209
-	    if (isset($SI)) $SI->checkAll();
2210
-	    if (isset($TI)) $TI->checkAll();
2211
-	    if (isset($MI)) $MI->checkAll();
3036
+	    if ($globalDebug) {
3037
+	    	echo 'Check all...'."\n";
3038
+	    }
3039
+	    if (isset($SI)) {
3040
+	    	$SI->checkAll();
3041
+	    }
3042
+	    if (isset($TI)) {
3043
+	    	$TI->checkAll();
3044
+	    }
3045
+	    if (isset($MI)) {
3046
+	    	$MI->checkAll();
3047
+	    }
2212 3048
 	}
2213 3049
     }
2214 3050
 }
Please login to merge, or discard this patch.