Completed
Push — master ( abe207...090b05 )
by Yannick
07:26
created
marine-data.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -9,11 +9,11 @@  discard block
 block discarded – undo
9 9
 
10 10
 $from_archive = false;
11 11
 if (isset($_GET['ident'])) {
12
-	$ident = filter_input(INPUT_GET,'ident',FILTER_SANITIZE_STRING);
12
+	$ident = filter_input(INPUT_GET, 'ident', FILTER_SANITIZE_STRING);
13 13
 	if (isset($_GET['currenttime'])) {
14
-		$currenttime = filter_input(INPUT_GET,'currenttime',FILTER_SANITIZE_NUMBER_INT);
14
+		$currenttime = filter_input(INPUT_GET, 'currenttime', FILTER_SANITIZE_NUMBER_INT);
15 15
 		$currenttime = round($currenttime/1000);
16
-		$spotter_array = $MarineLive->getDateLiveMarineDataByIdent($ident,$currenttime);
16
+		$spotter_array = $MarineLive->getDateLiveMarineDataByIdent($ident, $currenttime);
17 17
 		/*
18 18
 		if (empty($spotter_array)) {
19 19
 			$from_archive = true;
@@ -31,11 +31,11 @@  discard block
 block discarded – undo
31 31
 	}
32 32
 }
33 33
 if (isset($_GET['fammarine_id'])) {
34
-	$fammarine_id = filter_input(INPUT_GET,'fammarine_id',FILTER_SANITIZE_STRING);
34
+	$fammarine_id = filter_input(INPUT_GET, 'fammarine_id', FILTER_SANITIZE_STRING);
35 35
 	if (isset($_GET['currenttime'])) {
36
-		$currenttime = filter_input(INPUT_GET,'currenttime',FILTER_SANITIZE_NUMBER_INT);
36
+		$currenttime = filter_input(INPUT_GET, 'currenttime', FILTER_SANITIZE_NUMBER_INT);
37 37
 		$currenttime = round($currenttime/1000);
38
-		$spotter_array = $MarineLive->getDateLiveMarineDataById($fammarine_id,$currenttime);
38
+		$spotter_array = $MarineLive->getDateLiveMarineDataById($fammarine_id, $currenttime);
39 39
 		/*
40 40
 		if (empty($spotter_array)) {
41 41
 			$from_archive = true;
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 if (isset($spotter_item['image_thumbnail']) && $spotter_item['image_thumbnail'] != "")
63 63
 {
64 64
 	if ($spotter_item['image_source'] == 'flickr' || $spotter_item['image_source'] == 'wikimedia' || $spotter_item['image_source'] == 'devianart') {
65
-		$image = preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']);
65
+		$image = preg_replace("/^http:/i", "https:", $spotter_item['image_thumbnail']);
66 66
 	} else $image = $spotter_item['image_thumbnail'];
67 67
 
68 68
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -63,7 +63,9 @@
 block discarded – undo
63 63
 {
64 64
 	if ($spotter_item['image_source'] == 'flickr' || $spotter_item['image_source'] == 'wikimedia' || $spotter_item['image_source'] == 'devianart') {
65 65
 		$image = preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']);
66
-	} else $image = $spotter_item['image_thumbnail'];
66
+	} else {
67
+		$image = $spotter_item['image_thumbnail'];
68
+	}
67 69
 
68 70
 }
69 71
 /* else {
Please login to merge, or discard this patch.
tracker-data.php 3 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -63,7 +63,9 @@
 block discarded – undo
63 63
 {
64 64
 	if ($spotter_item['image_source'] == 'flickr' || $spotter_item['image_source'] == 'wikimedia' || $spotter_item['image_source'] == 'devianart') {
65 65
 		$image = preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']);
66
-	} else $image = $spotter_item['image_thumbnail'];
66
+	} else {
67
+		$image = $spotter_item['image_thumbnail'];
68
+	}
67 69
 
68 70
 }
69 71
 /* else {
Please login to merge, or discard this patch.
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -78,10 +78,10 @@  discard block
 block discarded – undo
78 78
 print '<div class="details">';
79 79
 print '<div><span>'._("Altitude").'</span>';
80 80
 if (isset($globalGroundAltitude) && $globalGroundAltitude) {
81
-    try {
81
+	try {
82 82
 	$groundAltitude = $Elevation->getElevation($spotter_item['latitude'],$spotter_item['longitude']);
83
-    } catch(Exception $e) {
84
-    }
83
+	} catch(Exception $e) {
84
+	}
85 85
 }
86 86
 if ((!isset($_COOKIE['unitaltitude']) && isset($globalUnitAltitude) && $globalUnitAltitude == 'feet') || (isset($_COOKIE['unitaltitude']) && $_COOKIE['unitaltitude'] == 'feet')) {
87 87
 	print $spotter_item['altitude'].' feet (FL'.$spotter_item['altitude'].')';
@@ -89,14 +89,14 @@  discard block
 block discarded – undo
89 89
 	print round($spotter_item['altitude']*0.3048).' m (FL'.round($spotter_item['altitude']/100).')';
90 90
 }
91 91
 if (isset($groundAltitude) && $groundAltitude < $spotter_item['altitude']*0.3048) {
92
-    print '<br>';
93
-    print '<span>'._("Ground Altitude").'</span>';
94
-    if ((!isset($_COOKIE['unitaltitude']) && isset($globalUnitAltitude) && $globalUnitAltitude == 'feet') || (isset($_COOKIE['unitaltitude']) && $_COOKIE['unitaltitude'] == 'feet')) {
92
+	print '<br>';
93
+	print '<span>'._("Ground Altitude").'</span>';
94
+	if ((!isset($_COOKIE['unitaltitude']) && isset($globalUnitAltitude) && $globalUnitAltitude == 'feet') || (isset($_COOKIE['unitaltitude']) && $_COOKIE['unitaltitude'] == 'feet')) {
95 95
 	print round($groundAltitude*3.28084).' feet';
96
-    } else {
96
+	} else {
97 97
 	print round($groundAltitude).' m';
98
-    }
99
-    print '</i>';
98
+	}
99
+	print '</i>';
100 100
 }
101 101
 print '</div>';
102 102
 print '<div><span>'._("Speed").'</span>';
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -11,14 +11,14 @@  discard block
 block discarded – undo
11 11
 
12 12
 $from_archive = false;
13 13
 if (isset($_GET['ident'])) {
14
-	$ident = filter_input(INPUT_GET,'ident',FILTER_SANITIZE_STRING);
14
+	$ident = filter_input(INPUT_GET, 'ident', FILTER_SANITIZE_STRING);
15 15
 	if (isset($_GET['currenttime'])) {
16
-		$currenttime = filter_input(INPUT_GET,'currenttime',FILTER_SANITIZE_NUMBER_INT);
16
+		$currenttime = filter_input(INPUT_GET, 'currenttime', FILTER_SANITIZE_NUMBER_INT);
17 17
 		$currenttime = round($currenttime/1000);
18
-		$spotter_array = $TrackerLive->getDateLiveTrackerDataByIdent($ident,$currenttime);
18
+		$spotter_array = $TrackerLive->getDateLiveTrackerDataByIdent($ident, $currenttime);
19 19
 		if (empty($spotter_array)) {
20 20
 			$from_archive = true;
21
-			$spotter_array = $TrackerArchive->getDateArchiveTrackerDataByIdent($ident,$currenttime);
21
+			$spotter_array = $TrackerArchive->getDateArchiveTrackerDataByIdent($ident, $currenttime);
22 22
 		}
23 23
 		
24 24
 	} else {
@@ -30,16 +30,16 @@  discard block
 block discarded – undo
30 30
 	}
31 31
 }
32 32
 if (isset($_GET['famtrackid'])) {
33
-	$famtrackid = filter_input(INPUT_GET,'famtrackid',FILTER_SANITIZE_STRING);
33
+	$famtrackid = filter_input(INPUT_GET, 'famtrackid', FILTER_SANITIZE_STRING);
34 34
 	if (isset($_GET['currenttime'])) {
35
-		$currenttime = filter_input(INPUT_GET,'currenttime',FILTER_SANITIZE_NUMBER_INT);
35
+		$currenttime = filter_input(INPUT_GET, 'currenttime', FILTER_SANITIZE_NUMBER_INT);
36 36
 		$currenttime = round($currenttime/1000);
37
-		$spotter_array = $TrackerLive->getDateLiveTrackerDataById($famtrackid,$currenttime);
37
+		$spotter_array = $TrackerLive->getDateLiveTrackerDataById($famtrackid, $currenttime);
38 38
 		
39 39
 		if (empty($spotter_array)) {
40 40
 			$from_archive = true;
41 41
 //			$spotter_array = $SpotterArchive->getLastArchiveSpotterDataById($flightaware_id);
42
-			$spotter_array = $TrackerArchive->getDateArchiveTrackerDataById($flightaware_id,$currenttime);
42
+			$spotter_array = $TrackerArchive->getDateArchiveTrackerDataById($flightaware_id, $currenttime);
43 43
 		}
44 44
 		
45 45
 	} else {
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 if (isset($spotter_item['image_thumbnail']) && $spotter_item['image_thumbnail'] != "")
60 60
 {
61 61
 	if ($spotter_item['image_source'] == 'flickr' || $spotter_item['image_source'] == 'wikimedia' || $spotter_item['image_source'] == 'devianart') {
62
-		$image = preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']);
62
+		$image = preg_replace("/^http:/i", "https:", $spotter_item['image_thumbnail']);
63 63
 	} else $image = $spotter_item['image_thumbnail'];
64 64
 
65 65
 }
@@ -79,8 +79,8 @@  discard block
 block discarded – undo
79 79
 print '<div><span>'._("Altitude").'</span>';
80 80
 if (isset($globalGroundAltitude) && $globalGroundAltitude) {
81 81
     try {
82
-	$groundAltitude = $Elevation->getElevation($spotter_item['latitude'],$spotter_item['longitude']);
83
-    } catch(Exception $e) {
82
+	$groundAltitude = $Elevation->getElevation($spotter_item['latitude'], $spotter_item['longitude']);
83
+    } catch (Exception $e) {
84 84
     }
85 85
 }
86 86
 if ((!isset($_COOKIE['unitaltitude']) && isset($globalUnitAltitude) && $globalUnitAltitude == 'feet') || (isset($_COOKIE['unitaltitude']) && $_COOKIE['unitaltitude'] == 'feet')) {
Please login to merge, or discard this patch.
require/class.AIS.php 4 patches
Doc Comments   +25 added lines patch added patch discarded remove patch
@@ -68,6 +68,10 @@  discard block
 block discarded – undo
68 68
        't', 'u', 'v', 'w' // 119
69 69
     ); // char 64
70 70
     */
71
+
72
+	/**
73
+	 * @param integer $ascii
74
+	 */
71 75
 	private function asciidec_2_8bit($ascii) {
72 76
 		//only process in the following range: 48-87, 96-119
73 77
 		if ($ascii < 48) { }
@@ -93,6 +97,10 @@  discard block
 block discarded – undo
93 97
 		return(substr($bin, -6)); 
94 98
 	}
95 99
 
100
+	/**
101
+	 * @param integer $_start
102
+	 * @param integer $_size
103
+	 */
96 104
 	private function binchar($_str, $_start, $_size) {
97 105
 		//  ' ' --- '?', // 0x20 - 0x3F
98 106
 		//  '@' --- '_', // 0x40 - 0x5F
@@ -118,6 +126,10 @@  discard block
 block discarded – undo
118 126
 	}
119 127
 
120 128
 	// function for decoding the AIS Message ITU Payload
129
+
130
+	/**
131
+	 * @param string $_aisdata
132
+	 */
121 133
 	private function decode_ais($_aisdata) {
122 134
 		$ro = new stdClass(); // return object
123 135
 		$ro->cls = 0; // AIS class undefined, also indicate unparsed msg
@@ -351,6 +363,12 @@  discard block
 block discarded – undo
351 363
 		elseif ($code == 99) return 'Other Type, no additional information';
352 364
 	}
353 365
 
366
+	/**
367
+	 * @param string $_itu
368
+	 * @param integer $_len
369
+	 * @param integer $_filler
370
+	 * @param string $aux
371
+	 */
354 372
 	public function process_ais_itu($_itu, $_len, $_filler, $aux /*, $ais_ch*/) {
355 373
 		global $port; // tcpip port...
356 374
 		
@@ -371,6 +389,10 @@  discard block
 block discarded – undo
371 389
 
372 390
 	// char* - AIS \r terminated string
373 391
 	// TCP based streams which send messages in full can use this instead of calling process_ais_buf
392
+
393
+	/**
394
+	 * @param string $rawdata
395
+	 */
374 396
 	public function process_ais_raw($rawdata, $aux = '') { // return int
375 397
 		static $num_seq; // 1 to 9
376 398
 		static $seq; // 1 to 9
@@ -589,6 +611,9 @@  discard block
 block discarded – undo
589 611
 		return $result;
590 612
 	}
591 613
 
614
+	/**
615
+	 * @param string $mmsi
616
+	 */
592 617
 	public function mmsitype($mmsi) {
593 618
 		if (strlen($mmsi) == 9) {
594 619
 			if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
Please login to merge, or discard this patch.
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 		return ($dec);
58 58
 	}
59 59
 	
60
-    /*
60
+	/*
61 61
     $ais_map64 = array(
62 62
        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', // 48
63 63
        ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C',
@@ -97,13 +97,13 @@  discard block
 block discarded – undo
97 97
 		//  ' ' --- '?', // 0x20 - 0x3F
98 98
 		//  '@' --- '_', // 0x40 - 0x5F
99 99
 		$ais_chars = array(
100
-		    '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
101
-		    'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
102
-		    'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']',
103
-		    '^', '_', ' ', '!', '\"', '#', '$', '%', '&', '\'',
104
-		    '(', ')', '*', '+', ',', '-', '.', '/', '0', '1',
105
-		    '2', '3', '4', '5', '6', '7', '8', '9', ':', ';',
106
-		    '<', '=', '>', '?'
100
+			'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
101
+			'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
102
+			'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']',
103
+			'^', '_', ' ', '!', '\"', '#', '$', '%', '&', '\'',
104
+			'(', ')', '*', '+', ',', '-', '.', '/', '0', '1',
105
+			'2', '3', '4', '5', '6', '7', '8', '9', ':', ';',
106
+			'<', '=', '>', '?'
107 107
 		);
108 108
 		// "
109 109
 		$rv = '';
@@ -419,8 +419,8 @@  discard block
 block discarded – undo
419 419
 				}
420 420
 				if ($num_seq > 1) { // for multipart messages
421 421
 					if ($cmsg_sid != $msg_sid // different msg_sid
422
-					    || $msg_sid == -1 // invalid initial msg_sid
423
-					    || ($seq - $pseq) != 1 // not insequence
422
+						|| $msg_sid == -1 // invalid initial msg_sid
423
+						|| ($seq - $pseq) != 1 // not insequence
424 424
 					) {  // invalid for multipart message
425 425
 						$msg_sid = -1;
426 426
 						$cmsg_sid = -1;
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 				$itu = $itu.$pcs[5]; // get itu message
434 434
 				$filler += (int)$pcs[6][0]; // get filler
435 435
 				if ($num_seq == 1 // valid single message
436
-				    || $num_seq == $pseq // valid multi-part message
436
+					|| $num_seq == $pseq // valid multi-part message
437 437
 				) {
438 438
 					if ($num_seq != 1) { // test
439 439
 						//echo $rawdata;
@@ -516,13 +516,13 @@  discard block
 block discarded – undo
516 516
 		else $pad = '';
517 517
 		$rv = '';
518 518
 		$ais_chars = array(
519
-		    '@'=>0, 'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 'I'=>9,
520
-		    'J'=>10, 'K'=>11, 'L'=>12, 'M'=>13, 'N'=>14, 'O'=>15, 'P'=>16, 'Q'=>17, 'R'=>18, 'S'=>19,
521
-		    'T'=>20, 'U'=>21, 'V'=>22, 'W'=>23, 'X'=>24, 'Y'=>25, 'Z'=>26, '['=>27, '\\'=>28, ']'=>29,
522
-		    '^'=>30, '_'=>31, ' '=>32, '!'=>33, '\"'=>34, '#'=>35, '$'=>36, '%'=>37, '&'=>38, '\''=>39,
523
-		    '('=>40, ')'=>41, '*'=>42, '+'=>43, ','=>44, '-'=>45, '.'=>46, '/'=>47, '0'=>48, '1'=>49,
524
-		    '2'=>50, '3'=>51, '4'=>52, '5'=>53, '6'=>54, '7'=>55, '8'=>56, '9'=>57, ':'=>58, ';'=>59,
525
-		    '<'=>60, '='=>61, '>'=>62, '?'=>63
519
+			'@'=>0, 'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 'I'=>9,
520
+			'J'=>10, 'K'=>11, 'L'=>12, 'M'=>13, 'N'=>14, 'O'=>15, 'P'=>16, 'Q'=>17, 'R'=>18, 'S'=>19,
521
+			'T'=>20, 'U'=>21, 'V'=>22, 'W'=>23, 'X'=>24, 'Y'=>25, 'Z'=>26, '['=>27, '\\'=>28, ']'=>29,
522
+			'^'=>30, '_'=>31, ' '=>32, '!'=>33, '\"'=>34, '#'=>35, '$'=>36, '%'=>37, '&'=>38, '\''=>39,
523
+			'('=>40, ')'=>41, '*'=>42, '+'=>43, ','=>44, '-'=>45, '.'=>46, '/'=>47, '0'=>48, '1'=>49,
524
+			'2'=>50, '3'=>51, '4'=>52, '5'=>53, '6'=>54, '7'=>55, '8'=>56, '9'=>57, ':'=>58, ';'=>59,
525
+			'<'=>60, '='=>61, '>'=>62, '?'=>63
526 526
 		);
527 527
 		// "
528 528
 		$_a = str_split($name);
Please login to merge, or discard this patch.
Spacing   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -29,31 +29,31 @@  discard block
 block discarded – undo
29 29
 
30 30
 	private function make_latf($temp) { // unsigned long 
31 31
 		$flat = 0.0; // float
32
-		$temp = $temp & 0x07FFFFFF;
33
-		if ($temp & 0x04000000) {
34
-			$temp = $temp ^ 0x07FFFFFF;
32
+		$temp = $temp&0x07FFFFFF;
33
+		if ($temp&0x04000000) {
34
+			$temp = $temp^0x07FFFFFF;
35 35
 			$temp += 1;
36
-			$flat = (float)($temp / (60.0 * 10000.0));
36
+			$flat = (float) ($temp/(60.0*10000.0));
37 37
 			$flat *= -1.0;
38
-		} else $flat = (float)($temp / (60.0 * 10000.0));
38
+		} else $flat = (float) ($temp/(60.0*10000.0));
39 39
 		return $flat; // float
40 40
 	}
41 41
 
42 42
 	private function make_lonf($temp) { // unsigned long
43 43
 		$flon = 0.0; // float
44
-		$temp = $temp & 0x0FFFFFFF;
45
-		if ($temp & 0x08000000) {
46
-			$temp = $temp ^ 0x0FFFFFFF;
44
+		$temp = $temp&0x0FFFFFFF;
45
+		if ($temp&0x08000000) {
46
+			$temp = $temp^0x0FFFFFFF;
47 47
 			$temp += 1;
48
-			$flon = (float)($temp / (60.0 * 10000.0));
48
+			$flon = (float) ($temp/(60.0*10000.0));
49 49
 			$flon *= -1.0;
50
-		} else $flon = (float)($temp / (60.0 * 10000.0));
50
+		} else $flon = (float) ($temp/(60.0*10000.0));
51 51
 		return $flon;
52 52
 	}
53 53
 
54 54
 	private function ascii_2_dec($chr) {
55
-		$dec=ord($chr);//get decimal ascii code
56
-		$hex=dechex($dec);//convert decimal to hex
55
+		$dec = ord($chr); //get decimal ascii code
56
+		$hex = dechex($dec); //convert decimal to hex
57 57
 		return ($dec);
58 58
 	}
59 59
 	
@@ -72,15 +72,15 @@  discard block
 block discarded – undo
72 72
 		//only process in the following range: 48-87, 96-119
73 73
 		if ($ascii < 48) { }
74 74
 		else {
75
-			if($ascii>119) { }
75
+			if ($ascii > 119) { }
76 76
 			else {
77
-				if ($ascii>87 && $ascii<96) ;
77
+				if ($ascii > 87 && $ascii < 96);
78 78
 				else {
79
-					$ascii=$ascii+40;
80
-					if ($ascii>128){
81
-						$ascii=$ascii+32;
79
+					$ascii = $ascii + 40;
80
+					if ($ascii > 128) {
81
+						$ascii = $ascii + 32;
82 82
 					} else {
83
-						$ascii=$ascii+40;
83
+						$ascii = $ascii + 40;
84 84
 					}
85 85
 				}
86 86
 			}
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 	}
90 90
 
91 91
 	private function dec_2_6bit($dec) {
92
-		$bin=decbin($dec);
92
+		$bin = decbin($dec);
93 93
 		return(substr($bin, -6)); 
94 94
 	}
95 95
 
@@ -107,11 +107,11 @@  discard block
 block discarded – undo
107 107
 		);
108 108
 		// "
109 109
 		$rv = '';
110
-		if ($_size % 6 == 0) {
111
-			$len = $_size / 6;
112
-			for ($i=0; $i<$len; $i++) {
113
-				$offset = $i * 6;
114
-				$rv .= $ais_chars[ bindec(substr($_str,$_start + $offset,6)) ];
110
+		if ($_size%6 == 0) {
111
+			$len = $_size/6;
112
+			for ($i = 0; $i < $len; $i++) {
113
+				$offset = $i*6;
114
+				$rv .= $ais_chars[bindec(substr($_str, $_start + $offset, 6))];
115 115
 			}
116 116
 		}
117 117
 		return $rv;
@@ -138,93 +138,93 @@  discard block
 block discarded – undo
138 138
 		$ro->eta_hour = '';
139 139
 		$ro->eta_minute = '';
140 140
 		$ro->ts = time();
141
-		$ro->id = bindec(substr($_aisdata,0,6));
142
-		$ro->mmsi = bindec(substr($_aisdata,8,30));
141
+		$ro->id = bindec(substr($_aisdata, 0, 6));
142
+		$ro->mmsi = bindec(substr($_aisdata, 8, 30));
143 143
 		if ($ro->id >= 1 && $ro->id <= 3) {
144
-			$ro->cog = bindec(substr($_aisdata,116,12))/10;
145
-			$ro->sog = bindec(substr($_aisdata,50,10))/10;
146
-			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,61,28)));
147
-			$ro->lat = $this->make_latf(bindec(substr($_aisdata,89,27)));
144
+			$ro->cog = bindec(substr($_aisdata, 116, 12))/10;
145
+			$ro->sog = bindec(substr($_aisdata, 50, 10))/10;
146
+			$ro->lon = $this->make_lonf(bindec(substr($_aisdata, 61, 28)));
147
+			$ro->lat = $this->make_latf(bindec(substr($_aisdata, 89, 27)));
148 148
 			$ro->cls = 1; // class A
149 149
 		} else if ($ro->id == 4) {
150
-			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,79,28)));
151
-			$ro->lat = $this->make_latf(bindec(substr($_aisdata,107,27)));
150
+			$ro->lon = $this->make_lonf(bindec(substr($_aisdata, 79, 28)));
151
+			$ro->lat = $this->make_latf(bindec(substr($_aisdata, 107, 27)));
152 152
 			$ro->cls = 1; // class A
153 153
 		} else if ($ro->id == 5) {
154
-			$ro->imo = bindec(substr($_aisdata,40,30));
155
-			$ro->callsign = $this->binchar($_aisdata,70,42);
156
-			$ro->name = $this->binchar($_aisdata,112,120);
157
-			$ro->typeid = bindec(substr($_aisdata,232,8));
154
+			$ro->imo = bindec(substr($_aisdata, 40, 30));
155
+			$ro->callsign = $this->binchar($_aisdata, 70, 42);
156
+			$ro->name = $this->binchar($_aisdata, 112, 120);
157
+			$ro->typeid = bindec(substr($_aisdata, 232, 8));
158 158
 			$ro->type = $this->getShipType($ro->typeid);
159 159
 			//$ro->to_bow = bindec(substr($_aisdata,240,9));
160 160
 			//$ro->to_stern = bindec(substr($_aisdata,249,9));
161 161
 			//$ro->to_port = bindec(substr($_aisdata,258,6));
162 162
 			//$ro->to_starboard = bindec(substr($_aisdata,264,6));
163
-			$ro->eta_month = bindec(substr($_aisdata,274,4));
164
-			$ro->eta_day = bindec(substr($_aisdata,278,5));
165
-			$ro->eta_hour = bindec(substr($_aisdata,283,5));
166
-			$ro->eta_minute = bindec(substr($_aisdata,288,6));
163
+			$ro->eta_month = bindec(substr($_aisdata, 274, 4));
164
+			$ro->eta_day = bindec(substr($_aisdata, 278, 5));
165
+			$ro->eta_hour = bindec(substr($_aisdata, 283, 5));
166
+			$ro->eta_minute = bindec(substr($_aisdata, 288, 6));
167 167
 			//$ro->draught = bindec(substr($_aisdata,294,8));
168
-			$ro->destination = $this->binchar($_aisdata,302,120);
168
+			$ro->destination = $this->binchar($_aisdata, 302, 120);
169 169
 			$ro->cls = 1; // class A
170 170
 		} else if ($ro->id == 9) {
171 171
 			// Search and Rescue aircraft position report
172 172
 		} else if ($ro->id == 18) {
173
-			$ro->cog = bindec(substr($_aisdata,112,12))/10;
174
-			$ro->sog = bindec(substr($_aisdata,46,10))/10;
175
-			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,57,28)));
176
-			$ro->lat = $this->make_latf(bindec(substr($_aisdata,85,27)));
177
-			$ro->heading = bindec(substr($_aisdata,124,9));
173
+			$ro->cog = bindec(substr($_aisdata, 112, 12))/10;
174
+			$ro->sog = bindec(substr($_aisdata, 46, 10))/10;
175
+			$ro->lon = $this->make_lonf(bindec(substr($_aisdata, 57, 28)));
176
+			$ro->lat = $this->make_latf(bindec(substr($_aisdata, 85, 27)));
177
+			$ro->heading = bindec(substr($_aisdata, 124, 9));
178 178
 			if ($ro->heading == 511) $ro->heading = '';
179 179
 			$ro->cls = 2; // class B
180 180
 		} else if ($ro->id == 19) {
181
-			$ro->cog = bindec(substr($_aisdata,112,12))/10;
182
-			$ro->sog = bindec(substr($_aisdata,46,10))/10;
183
-			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,61,28)));
184
-			$ro->lat = $this->make_latf(bindec(substr($_aisdata,89,27)));
185
-			$ro->name = $this->binchar($_aisdata,143,120);
181
+			$ro->cog = bindec(substr($_aisdata, 112, 12))/10;
182
+			$ro->sog = bindec(substr($_aisdata, 46, 10))/10;
183
+			$ro->lon = $this->make_lonf(bindec(substr($_aisdata, 61, 28)));
184
+			$ro->lat = $this->make_latf(bindec(substr($_aisdata, 89, 27)));
185
+			$ro->name = $this->binchar($_aisdata, 143, 120);
186 186
 			$ro->cls = 2; // class B
187
-			$ro->heading = bindec(substr($_aisdata,124,9));
187
+			$ro->heading = bindec(substr($_aisdata, 124, 9));
188 188
 			if ($ro->heading == 511) $ro->heading = '';
189
-			$ro->typeid = bindec(substr($_aisdata,263,8));
189
+			$ro->typeid = bindec(substr($_aisdata, 263, 8));
190 190
 			$ro->type = $this->getShipType($ro->typeid);
191 191
 			//$ro->to_bow = bindec(substr($_aisdata,271,9));
192 192
 			//$ro->to_stern = bindec(substr($_aisdata,280,9));
193 193
 			//$ro->to_port = bindec(substr($_aisdata,289,6));
194 194
 			//$ro->to_starboard = bindec(substr($_aisdata,295,6));
195 195
 		} else if ($ro->id == 21) {
196
-			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,164,28)));
197
-			$ro->lat = $this->make_latf(bindec(substr($_aisdata,192,27)));
198
-			$ro->name = $this->binchar($_aisdata,43,120);
196
+			$ro->lon = $this->make_lonf(bindec(substr($_aisdata, 164, 28)));
197
+			$ro->lat = $this->make_latf(bindec(substr($_aisdata, 192, 27)));
198
+			$ro->name = $this->binchar($_aisdata, 43, 120);
199 199
 			//$ro->to_bow = bindec(substr($_aisdata,219,9));
200 200
 			//$ro->to_stern = bindec(substr($_aisdata,228,9));
201 201
 			//$ro->to_port = bindec(substr($_aisdata,237,6));
202 202
 			//$ro->to_starboard = bindec(substr($_aisdata,243,6));
203 203
 			$ro->cls = 2; // class B
204 204
 		} else if ($ro->id == 24) {
205
-			$pn = bindec(substr($_aisdata,38,2));
205
+			$pn = bindec(substr($_aisdata, 38, 2));
206 206
 			if ($pn == 0) {
207
-				$ro->name = $this->binchar($_aisdata,40,120);
207
+				$ro->name = $this->binchar($_aisdata, 40, 120);
208 208
 			}
209
-			$ro->typeid = bindec(substr($_aisdata,40,8));
209
+			$ro->typeid = bindec(substr($_aisdata, 40, 8));
210 210
 			$ro->type = $this->getShipType($ro->typeid);
211
-			$ro->callsign = $this->binchar($_aisdata,90,42);
211
+			$ro->callsign = $this->binchar($_aisdata, 90, 42);
212 212
 			//$ro->to_bow = bindec(substr($_aisdata,132,9));
213 213
 			//$ro->to_stern = bindec(substr($_aisdata,141,9));
214 214
 			//$ro->to_port = bindec(substr($_aisdata,150,6));
215 215
 			//$ro->to_starboard = bindec(substr($_aisdata,156,6));
216 216
 			$ro->cls = 2; // class B
217 217
 		} else if ($ro->id == 27) {
218
-			$ro->cog = bindec(substr($_aisdata,85,9));
218
+			$ro->cog = bindec(substr($_aisdata, 85, 9));
219 219
 			if ($ro->cog == 511) $ro->cog = 0.0;
220
-			$ro->sog = bindec(substr($_aisdata,79,6));
220
+			$ro->sog = bindec(substr($_aisdata, 79, 6));
221 221
 			if ($ro->sog == 63) $ro->sog = 0.0;
222
-			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,44,18))*10);
223
-			$ro->lat = $this->make_latf(bindec(substr($_aisdata,62,17))*10);
222
+			$ro->lon = $this->make_lonf(bindec(substr($_aisdata, 44, 18))*10);
223
+			$ro->lat = $this->make_latf(bindec(substr($_aisdata, 62, 17))*10);
224 224
 			$ro->cls = 1; // class A
225 225
 		
226 226
 		}
227
-		$ro->statusid = bindec(substr($_aisdata,38,4));
227
+		$ro->statusid = bindec(substr($_aisdata, 38, 4));
228 228
 		$ro->status = $this->getStatus($ro->statusid);
229 229
 		//var_dump($ro); // dump results here for demo purpose
230 230
 		return $ro;
@@ -355,14 +355,14 @@  discard block
 block discarded – undo
355 355
 		global $port; // tcpip port...
356 356
 		
357 357
 		static $debug_counter = 0;
358
-		$aisdata168='';//six bit array of ascii characters
358
+		$aisdata168 = ''; //six bit array of ascii characters
359 359
 		$ais_nmea_array = str_split($_itu); // convert to an array
360 360
 		foreach ($ais_nmea_array as $value) {
361 361
 			$dec = $this->ascii_2_dec($value);
362 362
 			$bit8 = $this->asciidec_2_8bit($dec);
363 363
 			$bit6 = $this->dec_2_6bit($bit8);
364 364
 			//echo $value ."-" .$bit6 ."";
365
-			$aisdata168 .=$bit6;
365
+			$aisdata168 .= $bit6;
366 366
 		}
367 367
 		//echo $aisdata168 . "<br/>";
368 368
 		//return $this->decode_ais($aisdata168, $aux);
@@ -385,20 +385,20 @@  discard block
 block discarded – undo
385 385
 		// calculate checksum after ! till *
386 386
 		// assume 1st ! is valid
387 387
 		// find * ensure that it is at correct position
388
-		$end = strrpos ( $rawdata , '*' );
388
+		$end = strrpos($rawdata, '*');
389 389
 		if ($end === FALSE) return -1; // check for NULLS!!!
390
-		$cs = substr( $rawdata, $end + 1 );
391
-		if ( strlen($cs) != 2 ) return -1; // correct cs length
392
-		$dcs = (int)hexdec( $cs );
393
-		for ( $alias=1; $alias<$end; $alias++) $chksum ^= ord( $rawdata[$alias] ); // perform XOR for NMEA checksum
394
-		if ( $chksum == $dcs ) { // NMEA checksum pass
390
+		$cs = substr($rawdata, $end + 1);
391
+		if (strlen($cs) != 2) return -1; // correct cs length
392
+		$dcs = (int) hexdec($cs);
393
+		for ($alias = 1; $alias < $end; $alias++) $chksum ^= ord($rawdata[$alias]); // perform XOR for NMEA checksum
394
+		if ($chksum == $dcs) { // NMEA checksum pass
395 395
 			$pcs = explode(',', $rawdata);
396 396
 			// !AI??? identifier
397
-			$num_seq = (int)$pcs[1]; // number of sequences
398
-			$seq = (int)$pcs[2]; // get sequence
397
+			$num_seq = (int) $pcs[1]; // number of sequences
398
+			$seq = (int) $pcs[2]; // get sequence
399 399
 			// get msg sequence id
400 400
 			if ($pcs[3] == '') $msg_sid = -1; // non-multipart message, set to -1
401
-			else $msg_sid = (int)$pcs[3]; // multipart message
401
+			else $msg_sid = (int) $pcs[3]; // multipart message
402 402
 			$ais_ch = $pcs[4]; // get AIS channel
403 403
 			// message sequence checking
404 404
 			if ($num_seq < 1 || $num_seq > 9) {
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
 					}
432 432
 				}
433 433
 				$itu = $itu.$pcs[5]; // get itu message
434
-				$filler += (int)$pcs[6][0]; // get filler
434
+				$filler += (int) $pcs[6][0]; // get filler
435 435
 				if ($num_seq == 1 // valid single message
436 436
 				    || $num_seq == $pseq // valid multi-part message
437 437
 				) {
@@ -451,13 +451,13 @@  discard block
 block discarded – undo
451 451
 		$cbuf = $cbuf.$ibuf;
452 452
 		$last_pos = 0;
453 453
 		$result = new stdClass();
454
-		while ( ($start = strpos($cbuf,"VDM",$last_pos)) !== FALSE) {
454
+		while (($start = strpos($cbuf, "VDM", $last_pos)) !== FALSE) {
455 455
 		//while ( ($start = strpos($cbuf,"!AI",$last_pos)) !== FALSE) {
456 456
 			//DEBUG echo $cbuf;
457
-			if ( ($end = strpos($cbuf,"\r\n", $start)) !== FALSE) { //TBD need to trim?
457
+			if (($end = strpos($cbuf, "\r\n", $start)) !== FALSE) { //TBD need to trim?
458 458
 				$tst = substr($cbuf, $start - 3, ($end - $start + 3));
459 459
 				//DEBUG echo "[$start $end $tst]\n";
460
-				$result = $this->process_ais_raw( $tst, "" );
460
+				$result = $this->process_ais_raw($tst, "");
461 461
 				$last_pos = $end + 1;
462 462
 			} else break;
463 463
 		}
@@ -469,41 +469,41 @@  discard block
 block discarded – undo
469 469
 	// incoming data from serial or IP comms
470 470
 	public function process_ais_line($cbuf) {
471 471
 		$result = new stdClass();
472
-		$start = strpos($cbuf,"VDM");
472
+		$start = strpos($cbuf, "VDM");
473 473
 		$tst = substr($cbuf, $start - 3);
474
-		$result = $this->process_ais_raw( $tst, "" );
474
+		$result = $this->process_ais_raw($tst, "");
475 475
 		return $result;
476 476
 	}
477 477
 
478 478
 	/* AIS Encoding
479 479
 	*/
480
-	private function mk_ais_lat( $lat ) {
480
+	private function mk_ais_lat($lat) {
481 481
 		//$lat = 1.2569;
482
-		if ($lat<0.0) {
482
+		if ($lat < 0.0) {
483 483
 			$lat = -$lat;
484
-			$neg=true;
485
-		} else $neg=false;
484
+			$neg = true;
485
+		} else $neg = false;
486 486
 		$latd = 0x00000000;
487
-		$latd = intval ($lat * 600000.0);
488
-		if ($neg==true) {
487
+		$latd = intval($lat*600000.0);
488
+		if ($neg == true) {
489 489
 			$latd = ~$latd;
490
-			$latd+=1;
490
+			$latd += 1;
491 491
 			$latd &= 0x07FFFFFF;
492 492
 		}
493 493
 		return $latd;
494 494
 	}
495 495
 
496
-	private function mk_ais_lon( $lon ) {
496
+	private function mk_ais_lon($lon) {
497 497
 		//$lon = 103.851;
498
-		if ($lon<0.0) {
498
+		if ($lon < 0.0) {
499 499
 			$lon = -$lon;
500
-			$neg=true;
501
-		} else $neg=false;
500
+			$neg = true;
501
+		} else $neg = false;
502 502
 		$lond = 0x00000000;
503
-		$lond = intval ($lon * 600000.0);
504
-		if ($neg==true) {
503
+		$lond = intval($lon*600000.0);
504
+		if ($neg == true) {
505 505
 			$lond = ~$lond;
506
-			$lond+=1;
506
+			$lond += 1;
507 507
 			$lond &= 0x0FFFFFFF;
508 508
 		}
509 509
 		return $lond;
@@ -511,8 +511,8 @@  discard block
 block discarded – undo
511 511
 
512 512
 	private function char2bin($name, $max_len) {
513 513
 		$len = strlen($name);
514
-		if ($len > $max_len) $name = substr($name,0,$max_len);
515
-		if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len) * 6);
514
+		if ($len > $max_len) $name = substr($name, 0, $max_len);
515
+		if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len)*6);
516 516
 		else $pad = '';
517 517
 		$rv = '';
518 518
 		$ais_chars = array(
@@ -529,26 +529,26 @@  discard block
 block discarded – undo
529 529
 		if ($_a) foreach ($_a as $_1) {
530 530
 			if (isset($ais_chars[$_1])) $dec = $ais_chars[$_1];
531 531
 			else $dec = 0;
532
-			$bin = str_pad(decbin( $dec ), 6, '0', STR_PAD_LEFT);
532
+			$bin = str_pad(decbin($dec), 6, '0', STR_PAD_LEFT);
533 533
 			$rv .= $bin;
534 534
 			//echo "$_1 $dec ($bin)<br/>";
535 535
 		}
536 536
 		return $rv.$pad;
537 537
 	}
538 538
 
539
-	private function mk_ais($_enc, $_part=1,$_total=1,$_seq='',$_ch='A') {
539
+	private function mk_ais($_enc, $_part = 1, $_total = 1, $_seq = '', $_ch = 'A') {
540 540
 		$len_bit = strlen($_enc);
541
-		$rem6 = $len_bit % 6;
541
+		$rem6 = $len_bit%6;
542 542
 		$pad6_len = 0;
543 543
 		if ($rem6) $pad6_len = 6 - $rem6;
544 544
 		//echo  $pad6_len.'<br>';
545 545
 		$_enc .= str_repeat("0", $pad6_len); // pad the text...
546
-		$len_enc = strlen($_enc) / 6;
546
+		$len_enc = strlen($_enc)/6;
547 547
 		//echo $_enc.' '.$len_enc.'<br/>';
548 548
 		$itu = '';
549
-		for ($i=0; $i<$len_enc; $i++) {
550
-			$offset = $i * 6;
551
-			$dec = bindec(substr($_enc,$offset,6));
549
+		for ($i = 0; $i < $len_enc; $i++) {
550
+			$offset = $i*6;
551
+			$dec = bindec(substr($_enc, $offset, 6));
552 552
 			if ($dec < 40) $dec += 48;
553 553
 			else $dec += 56;
554 554
 			//echo chr($dec)." $dec<br/>";
@@ -558,15 +558,15 @@  discard block
 block discarded – undo
558 558
 		$chksum = 0;
559 559
 		$itu = "AIVDM,$_part,$_total,$_seq,$_ch,".$itu.",0";
560 560
 		$len_itu = strlen($itu);
561
-		for ($i=0; $i<$len_itu; $i++) {
562
-			$chksum ^= ord( $itu[$i] );
561
+		for ($i = 0; $i < $len_itu; $i++) {
562
+			$chksum ^= ord($itu[$i]);
563 563
 		}
564
-		$hex_arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
565
-		$lsb = $chksum & 0x0F;
566
-		if ($lsb >=0 && $lsb <= 15 ) $lsbc = $hex_arr[$lsb];
564
+		$hex_arr = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
565
+		$lsb = $chksum&0x0F;
566
+		if ($lsb >= 0 && $lsb <= 15) $lsbc = $hex_arr[$lsb];
567 567
 		else $lsbc = '0';
568
-		$msb = (($chksum & 0xF0) >> 4) & 0x0F;
569
-		if ($msb >=0 && $msb <= 15 ) $msbc = $hex_arr[$msb];
568
+		$msb = (($chksum&0xF0) >> 4)&0x0F;
569
+		if ($msb >= 0 && $msb <= 15) $msbc = $hex_arr[$msb];
570 570
 		else $msbc = '0';
571 571
 		$itu = '!'.$itu."*{$msbc}{$lsbc}\r\n";
572 572
 		return $itu;
@@ -591,14 +591,14 @@  discard block
 block discarded – undo
591 591
 
592 592
 	public function mmsitype($mmsi) {
593 593
 		if (strlen($mmsi) == 9) {
594
-			if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
595
-			elseif (substr($mmsi,0,3) == '972') return 'MOB (Man Overboard) device';
596
-			elseif (substr($mmsi,0,3) == '970') return 'AIS SART (Search and Rescue Transmitter)';
597
-			elseif (substr($mmsi,0,3) == '111') return 'SAR (Search and Rescue) aircraft';
598
-			elseif (substr($mmsi,0,2) == '98') return 'Auxiliary craft associated with a parent ship';
599
-			elseif (substr($mmsi,0,2) == '99') return 'Aids to Navigation';
600
-			elseif (substr($mmsi,0,2) == '00') return 'Coastal stations';
601
-			elseif (substr($mmsi,0,1) == '0') return 'Group of ships';
594
+			if (substr($mmsi, 0, 3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
595
+			elseif (substr($mmsi, 0, 3) == '972') return 'MOB (Man Overboard) device';
596
+			elseif (substr($mmsi, 0, 3) == '970') return 'AIS SART (Search and Rescue Transmitter)';
597
+			elseif (substr($mmsi, 0, 3) == '111') return 'SAR (Search and Rescue) aircraft';
598
+			elseif (substr($mmsi, 0, 2) == '98') return 'Auxiliary craft associated with a parent ship';
599
+			elseif (substr($mmsi, 0, 2) == '99') return 'Aids to Navigation';
600
+			elseif (substr($mmsi, 0, 2) == '00') return 'Coastal stations';
601
+			elseif (substr($mmsi, 0, 1) == '0') return 'Group of ships';
602 602
 			else return 'Ship';
603 603
 		}
604 604
 
@@ -609,19 +609,19 @@  discard block
 block discarded – undo
609 609
 		global $globalDebug;
610 610
 		$result = array();
611 611
 		$data = new stdClass();
612
-		$start = strpos($buffer,"VDM");
612
+		$start = strpos($buffer, "VDM");
613 613
 		$tst = substr($buffer, $start - 3);
614
-		$data = $this->process_ais_raw( $tst, "" );
614
+		$data = $this->process_ais_raw($tst, "");
615 615
 		if (!is_object($data)) {
616 616
 			//if ($globalDebug) echo '==== Line format not supported : '.$buffer."\n";
617 617
 			return array();
618 618
 		}
619 619
 		if ($data->lon != 0) $result['longitude'] = $data->lon;
620 620
 		if ($data->lat != 0) $result['latitude'] = $data->lat;
621
-		$result['ident'] = trim(str_replace('@','',$data->name));
621
+		$result['ident'] = trim(str_replace('@', '', $data->name));
622 622
 		$result['timestamp'] = $data->ts;
623 623
 		$result['mmsi'] = $data->mmsi;
624
-		if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') $result['mmsi'] = '3'.$result['mmsi'];
624
+		if (strlen($result['mmsi']) == 8 && substr($result['mmsi'], 0, 3) == '669') $result['mmsi'] = '3'.$result['mmsi'];
625 625
 		$result['mmsi_type'] = $this->mmsitype($result['mmsi']);
626 626
 		if ($data->sog != -1.0) $result['speed'] = $data->sog;
627 627
 		if ($data->heading !== '') $result['heading'] = $data->heading;
@@ -631,16 +631,16 @@  discard block
 block discarded – undo
631 631
 		if ($data->type !== '') $result['type'] = $data->type;
632 632
 		if ($data->typeid !== '') $result['typeid'] = $data->typeid;
633 633
 		if ($data->imo !== '') $result['imo'] = $data->imo;
634
-		if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@','',$data->callsign));
634
+		if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@', '', $data->callsign));
635 635
 		if (is_numeric($data->eta_month) && $data->eta_month != 0 && is_numeric($data->eta_day) && $data->eta_day != 0 && $data->eta_hour !== '' && $data->eta_minute !== '') {
636
-			$eta_ts = strtotime(date('Y').'-'.sprintf("%02d",$data->eta_month).'-'.sprintf("%02d",$data->eta_day).' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00');
636
+			$eta_ts = strtotime(date('Y').'-'.sprintf("%02d", $data->eta_month).'-'.sprintf("%02d", $data->eta_day).' '.sprintf("%02d", $data->eta_hour).':'.sprintf("%02d", $data->eta_minute).':00');
637 637
 			if ($eta_ts != '') $result['eta_ts'] = $eta_ts;
638 638
 		} elseif (is_numeric($data->eta_hour) && is_numeric($data->eta_minute)) {
639
-			$eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00');
639
+			$eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d", $data->eta_hour).':'.sprintf("%02d", $data->eta_minute).':00');
640 640
 			if ($eta_ts != '') $result['eta_ts'] = $eta_ts;
641 641
 		}
642 642
 		if ($data->destination != '') {
643
-			$dest = trim(str_replace('@','',$data->destination));
643
+			$dest = trim(str_replace('@', '', $data->destination));
644 644
 			if ($dest != '') $result['destination'] = $dest;
645 645
 		}
646 646
 		$result['all'] = (array) $data;
Please login to merge, or discard this patch.
Braces   +331 added lines, -143 removed lines patch added patch discarded remove patch
@@ -35,7 +35,9 @@  discard block
 block discarded – undo
35 35
 			$temp += 1;
36 36
 			$flat = (float)($temp / (60.0 * 10000.0));
37 37
 			$flat *= -1.0;
38
-		} else $flat = (float)($temp / (60.0 * 10000.0));
38
+		} else {
39
+			$flat = (float)($temp / (60.0 * 10000.0));
40
+		}
39 41
 		return $flat; // float
40 42
 	}
41 43
 
@@ -47,7 +49,9 @@  discard block
 block discarded – undo
47 49
 			$temp += 1;
48 50
 			$flon = (float)($temp / (60.0 * 10000.0));
49 51
 			$flon *= -1.0;
50
-		} else $flon = (float)($temp / (60.0 * 10000.0));
52
+		} else {
53
+			$flon = (float)($temp / (60.0 * 10000.0));
54
+		}
51 55
 		return $flon;
52 56
 	}
53 57
 
@@ -70,10 +74,8 @@  discard block
 block discarded – undo
70 74
     */
71 75
 	private function asciidec_2_8bit($ascii) {
72 76
 		//only process in the following range: 48-87, 96-119
73
-		if ($ascii < 48) { }
74
-		else {
75
-			if($ascii>119) { }
76
-			else {
77
+		if ($ascii < 48) { } else {
78
+			if($ascii>119) { } else {
77 79
 				if ($ascii>87 && $ascii<96) ;
78 80
 				else {
79 81
 					$ascii=$ascii+40;
@@ -175,7 +177,9 @@  discard block
 block discarded – undo
175 177
 			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,57,28)));
176 178
 			$ro->lat = $this->make_latf(bindec(substr($_aisdata,85,27)));
177 179
 			$ro->heading = bindec(substr($_aisdata,124,9));
178
-			if ($ro->heading == 511) $ro->heading = '';
180
+			if ($ro->heading == 511) {
181
+				$ro->heading = '';
182
+			}
179 183
 			$ro->cls = 2; // class B
180 184
 		} else if ($ro->id == 19) {
181 185
 			$ro->cog = bindec(substr($_aisdata,112,12))/10;
@@ -185,7 +189,9 @@  discard block
 block discarded – undo
185 189
 			$ro->name = $this->binchar($_aisdata,143,120);
186 190
 			$ro->cls = 2; // class B
187 191
 			$ro->heading = bindec(substr($_aisdata,124,9));
188
-			if ($ro->heading == 511) $ro->heading = '';
192
+			if ($ro->heading == 511) {
193
+				$ro->heading = '';
194
+			}
189 195
 			$ro->typeid = bindec(substr($_aisdata,263,8));
190 196
 			$ro->type = $this->getShipType($ro->typeid);
191 197
 			//$ro->to_bow = bindec(substr($_aisdata,271,9));
@@ -216,9 +222,13 @@  discard block
 block discarded – undo
216 222
 			$ro->cls = 2; // class B
217 223
 		} else if ($ro->id == 27) {
218 224
 			$ro->cog = bindec(substr($_aisdata,85,9));
219
-			if ($ro->cog == 511) $ro->cog = 0.0;
225
+			if ($ro->cog == 511) {
226
+				$ro->cog = 0.0;
227
+			}
220 228
 			$ro->sog = bindec(substr($_aisdata,79,6));
221
-			if ($ro->sog == 63) $ro->sog = 0.0;
229
+			if ($ro->sog == 63) {
230
+				$ro->sog = 0.0;
231
+			}
222 232
 			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,44,18))*10);
223 233
 			$ro->lat = $this->make_latf(bindec(substr($_aisdata,62,17))*10);
224 234
 			$ro->cls = 1; // class A
@@ -267,88 +277,171 @@  discard block
 block discarded – undo
267 277
 	}
268 278
 	
269 279
 	public function getShipType($code) {
270
-		if ($code == 0) return 'Not available (default)';
271
-		elseif ($code >= 1 && $code <= 19) return 'Reserved for future use';
272
-		elseif ($code == 20) return 'Wing in ground (WIG), all ships of this type';
273
-		elseif ($code == 21) return 'Wing in ground (WIG), Hazardous category A';
274
-		elseif ($code == 22) return 'Wing in ground (WIG), Hazardous category B';
275
-		elseif ($code == 23) return 'Wing in ground (WIG), Hazardous category C';
276
-		elseif ($code == 24) return 'Wing in ground (WIG), Hazardous category D';
277
-		elseif ($code == 25) return 'Wing in ground (WIG), Reserved for future use';
278
-		elseif ($code == 26) return 'Wing in ground (WIG), Reserved for future use';
279
-		elseif ($code == 27) return 'Wing in ground (WIG), Reserved for future use';
280
-		elseif ($code == 28) return 'Wing in ground (WIG), Reserved for future use';
281
-		elseif ($code == 29) return 'Wing in ground (WIG), Reserved for future use';
282
-		elseif ($code == 30) return 'Fishing';
283
-		elseif ($code == 31) return 'Towing';
284
-		elseif ($code == 32) return 'Towing: length exceeds 200m or breadth exceeds 25m';
285
-		elseif ($code == 33) return 'Dredging or underwater ops';
286
-		elseif ($code == 34) return 'Diving ops';
287
-		elseif ($code == 35) return 'Military ops';
288
-		elseif ($code == 36) return 'Sailing';
289
-		elseif ($code == 37) return 'Pleasure Craft';
290
-		elseif ($code == 38) return 'Reserved';
291
-		elseif ($code == 39) return 'Reserved';
292
-		elseif ($code == 40) return 'High speed craft (HSC), all ships of this type';
293
-		elseif ($code == 41) return 'High speed craft (HSC), Hazardous category A';
294
-		elseif ($code == 42) return 'High speed craft (HSC), Hazardous category B';
295
-		elseif ($code == 43) return 'High speed craft (HSC), Hazardous category C';
296
-		elseif ($code == 44) return 'High speed craft (HSC), Hazardous category D';
297
-		elseif ($code == 45) return 'High speed craft (HSC), Reserved for future use';
298
-		elseif ($code == 46) return 'High speed craft (HSC), Reserved for future use';
299
-		elseif ($code == 47) return 'High speed craft (HSC), Reserved for future use';
300
-		elseif ($code == 48) return 'High speed craft (HSC), Reserved for future use';
301
-		elseif ($code == 49) return 'High speed craft (HSC), No additional information';
302
-		elseif ($code == 50) return 'Pilot Vessel';
303
-		elseif ($code == 51) return 'Search and Rescue vessel';
304
-		elseif ($code == 52) return 'Tug';
305
-		elseif ($code == 53) return 'Port Tender';
306
-		elseif ($code == 54) return 'Anti-pollution equipment';
307
-		elseif ($code == 55) return 'Law Enforcement';
308
-		elseif ($code == 56) return 'Spare - Local Vessel';
309
-		elseif ($code == 57) return 'Spare - Local Vessel';
310
-		elseif ($code == 58) return 'Medical Transport';
311
-		elseif ($code == 59) return 'Noncombatant ship according to RR Resolution No. 18';
312
-		elseif ($code == 60) return 'Passenger, all ships of this type';
313
-		elseif ($code == 61) return 'Passenger, Hazardous category A';
314
-		elseif ($code == 62) return 'Passenger, Hazardous category B';
315
-		elseif ($code == 63) return 'Passenger, Hazardous category C';
316
-		elseif ($code == 64) return 'Passenger, Hazardous category D';
317
-		elseif ($code == 65) return 'Passenger, Reserved for future use';
318
-		elseif ($code == 66) return 'Passenger, Reserved for future use';
319
-		elseif ($code == 67) return 'Passenger, Reserved for future use';
320
-		elseif ($code == 68) return 'Passenger, Reserved for future use';
321
-		elseif ($code == 69) return 'Passenger, No additional information';
322
-		elseif ($code == 70) return 'Cargo, all ships of this type';
323
-		elseif ($code == 71) return 'Cargo, Hazardous category A';
324
-		elseif ($code == 72) return 'Cargo, Hazardous category B';
325
-		elseif ($code == 73) return 'Cargo, Hazardous category C';
326
-		elseif ($code == 74) return 'Cargo, Hazardous category D';
327
-		elseif ($code == 75) return 'Cargo, Reserved for future use';
328
-		elseif ($code == 76) return 'Cargo, Reserved for future use';
329
-		elseif ($code == 77) return 'Cargo, Reserved for future use';
330
-		elseif ($code == 78) return 'Cargo, Reserved for future use';
331
-		elseif ($code == 79) return 'Cargo, No additional information';
332
-		elseif ($code == 80) return 'Tanker, all ships of this type';
333
-		elseif ($code == 81) return 'Tanker, Hazardous category A';
334
-		elseif ($code == 82) return 'Tanker, Hazardous category B';
335
-		elseif ($code == 83) return 'Tanker, Hazardous category C';
336
-		elseif ($code == 84) return 'Tanker, Hazardous category D';
337
-		elseif ($code == 85) return 'Tanker, Reserved for future use';
338
-		elseif ($code == 86) return 'Tanker, Reserved for future use';
339
-		elseif ($code == 87) return 'Tanker, Reserved for future use';
340
-		elseif ($code == 88) return 'Tanker, Reserved for future use';
341
-		elseif ($code == 89) return 'Tanker, No additional information';
342
-		elseif ($code == 90) return 'Other Type, all ships of this type';
343
-		elseif ($code == 91) return 'Other Type, Hazardous category A';
344
-		elseif ($code == 92) return 'Other Type, Hazardous category B';
345
-		elseif ($code == 93) return 'Other Type, Hazardous category C';
346
-		elseif ($code == 94) return 'Other Type, Hazardous category D';
347
-		elseif ($code == 95) return 'Other Type, Reserved for future use';
348
-		elseif ($code == 96) return 'Other Type, Reserved for future use';
349
-		elseif ($code == 97) return 'Other Type, Reserved for future use';
350
-		elseif ($code == 98) return 'Other Type, Reserved for future use';
351
-		elseif ($code == 99) return 'Other Type, no additional information';
280
+		if ($code == 0) {
281
+			return 'Not available (default)';
282
+		} elseif ($code >= 1 && $code <= 19) {
283
+			return 'Reserved for future use';
284
+		} elseif ($code == 20) {
285
+			return 'Wing in ground (WIG), all ships of this type';
286
+		} elseif ($code == 21) {
287
+			return 'Wing in ground (WIG), Hazardous category A';
288
+		} elseif ($code == 22) {
289
+			return 'Wing in ground (WIG), Hazardous category B';
290
+		} elseif ($code == 23) {
291
+			return 'Wing in ground (WIG), Hazardous category C';
292
+		} elseif ($code == 24) {
293
+			return 'Wing in ground (WIG), Hazardous category D';
294
+		} elseif ($code == 25) {
295
+			return 'Wing in ground (WIG), Reserved for future use';
296
+		} elseif ($code == 26) {
297
+			return 'Wing in ground (WIG), Reserved for future use';
298
+		} elseif ($code == 27) {
299
+			return 'Wing in ground (WIG), Reserved for future use';
300
+		} elseif ($code == 28) {
301
+			return 'Wing in ground (WIG), Reserved for future use';
302
+		} elseif ($code == 29) {
303
+			return 'Wing in ground (WIG), Reserved for future use';
304
+		} elseif ($code == 30) {
305
+			return 'Fishing';
306
+		} elseif ($code == 31) {
307
+			return 'Towing';
308
+		} elseif ($code == 32) {
309
+			return 'Towing: length exceeds 200m or breadth exceeds 25m';
310
+		} elseif ($code == 33) {
311
+			return 'Dredging or underwater ops';
312
+		} elseif ($code == 34) {
313
+			return 'Diving ops';
314
+		} elseif ($code == 35) {
315
+			return 'Military ops';
316
+		} elseif ($code == 36) {
317
+			return 'Sailing';
318
+		} elseif ($code == 37) {
319
+			return 'Pleasure Craft';
320
+		} elseif ($code == 38) {
321
+			return 'Reserved';
322
+		} elseif ($code == 39) {
323
+			return 'Reserved';
324
+		} elseif ($code == 40) {
325
+			return 'High speed craft (HSC), all ships of this type';
326
+		} elseif ($code == 41) {
327
+			return 'High speed craft (HSC), Hazardous category A';
328
+		} elseif ($code == 42) {
329
+			return 'High speed craft (HSC), Hazardous category B';
330
+		} elseif ($code == 43) {
331
+			return 'High speed craft (HSC), Hazardous category C';
332
+		} elseif ($code == 44) {
333
+			return 'High speed craft (HSC), Hazardous category D';
334
+		} elseif ($code == 45) {
335
+			return 'High speed craft (HSC), Reserved for future use';
336
+		} elseif ($code == 46) {
337
+			return 'High speed craft (HSC), Reserved for future use';
338
+		} elseif ($code == 47) {
339
+			return 'High speed craft (HSC), Reserved for future use';
340
+		} elseif ($code == 48) {
341
+			return 'High speed craft (HSC), Reserved for future use';
342
+		} elseif ($code == 49) {
343
+			return 'High speed craft (HSC), No additional information';
344
+		} elseif ($code == 50) {
345
+			return 'Pilot Vessel';
346
+		} elseif ($code == 51) {
347
+			return 'Search and Rescue vessel';
348
+		} elseif ($code == 52) {
349
+			return 'Tug';
350
+		} elseif ($code == 53) {
351
+			return 'Port Tender';
352
+		} elseif ($code == 54) {
353
+			return 'Anti-pollution equipment';
354
+		} elseif ($code == 55) {
355
+			return 'Law Enforcement';
356
+		} elseif ($code == 56) {
357
+			return 'Spare - Local Vessel';
358
+		} elseif ($code == 57) {
359
+			return 'Spare - Local Vessel';
360
+		} elseif ($code == 58) {
361
+			return 'Medical Transport';
362
+		} elseif ($code == 59) {
363
+			return 'Noncombatant ship according to RR Resolution No. 18';
364
+		} elseif ($code == 60) {
365
+			return 'Passenger, all ships of this type';
366
+		} elseif ($code == 61) {
367
+			return 'Passenger, Hazardous category A';
368
+		} elseif ($code == 62) {
369
+			return 'Passenger, Hazardous category B';
370
+		} elseif ($code == 63) {
371
+			return 'Passenger, Hazardous category C';
372
+		} elseif ($code == 64) {
373
+			return 'Passenger, Hazardous category D';
374
+		} elseif ($code == 65) {
375
+			return 'Passenger, Reserved for future use';
376
+		} elseif ($code == 66) {
377
+			return 'Passenger, Reserved for future use';
378
+		} elseif ($code == 67) {
379
+			return 'Passenger, Reserved for future use';
380
+		} elseif ($code == 68) {
381
+			return 'Passenger, Reserved for future use';
382
+		} elseif ($code == 69) {
383
+			return 'Passenger, No additional information';
384
+		} elseif ($code == 70) {
385
+			return 'Cargo, all ships of this type';
386
+		} elseif ($code == 71) {
387
+			return 'Cargo, Hazardous category A';
388
+		} elseif ($code == 72) {
389
+			return 'Cargo, Hazardous category B';
390
+		} elseif ($code == 73) {
391
+			return 'Cargo, Hazardous category C';
392
+		} elseif ($code == 74) {
393
+			return 'Cargo, Hazardous category D';
394
+		} elseif ($code == 75) {
395
+			return 'Cargo, Reserved for future use';
396
+		} elseif ($code == 76) {
397
+			return 'Cargo, Reserved for future use';
398
+		} elseif ($code == 77) {
399
+			return 'Cargo, Reserved for future use';
400
+		} elseif ($code == 78) {
401
+			return 'Cargo, Reserved for future use';
402
+		} elseif ($code == 79) {
403
+			return 'Cargo, No additional information';
404
+		} elseif ($code == 80) {
405
+			return 'Tanker, all ships of this type';
406
+		} elseif ($code == 81) {
407
+			return 'Tanker, Hazardous category A';
408
+		} elseif ($code == 82) {
409
+			return 'Tanker, Hazardous category B';
410
+		} elseif ($code == 83) {
411
+			return 'Tanker, Hazardous category C';
412
+		} elseif ($code == 84) {
413
+			return 'Tanker, Hazardous category D';
414
+		} elseif ($code == 85) {
415
+			return 'Tanker, Reserved for future use';
416
+		} elseif ($code == 86) {
417
+			return 'Tanker, Reserved for future use';
418
+		} elseif ($code == 87) {
419
+			return 'Tanker, Reserved for future use';
420
+		} elseif ($code == 88) {
421
+			return 'Tanker, Reserved for future use';
422
+		} elseif ($code == 89) {
423
+			return 'Tanker, No additional information';
424
+		} elseif ($code == 90) {
425
+			return 'Other Type, all ships of this type';
426
+		} elseif ($code == 91) {
427
+			return 'Other Type, Hazardous category A';
428
+		} elseif ($code == 92) {
429
+			return 'Other Type, Hazardous category B';
430
+		} elseif ($code == 93) {
431
+			return 'Other Type, Hazardous category C';
432
+		} elseif ($code == 94) {
433
+			return 'Other Type, Hazardous category D';
434
+		} elseif ($code == 95) {
435
+			return 'Other Type, Reserved for future use';
436
+		} elseif ($code == 96) {
437
+			return 'Other Type, Reserved for future use';
438
+		} elseif ($code == 97) {
439
+			return 'Other Type, Reserved for future use';
440
+		} elseif ($code == 98) {
441
+			return 'Other Type, Reserved for future use';
442
+		} elseif ($code == 99) {
443
+			return 'Other Type, no additional information';
444
+		}
352 445
 	}
353 446
 
354 447
 	public function process_ais_itu($_itu, $_len, $_filler, $aux /*, $ais_ch*/) {
@@ -386,19 +479,34 @@  discard block
 block discarded – undo
386 479
 		// assume 1st ! is valid
387 480
 		// find * ensure that it is at correct position
388 481
 		$end = strrpos ( $rawdata , '*' );
389
-		if ($end === FALSE) return -1; // check for NULLS!!!
482
+		if ($end === FALSE) {
483
+			return -1;
484
+		}
485
+		// check for NULLS!!!
390 486
 		$cs = substr( $rawdata, $end + 1 );
391
-		if ( strlen($cs) != 2 ) return -1; // correct cs length
487
+		if ( strlen($cs) != 2 ) {
488
+			return -1;
489
+		}
490
+		// correct cs length
392 491
 		$dcs = (int)hexdec( $cs );
393
-		for ( $alias=1; $alias<$end; $alias++) $chksum ^= ord( $rawdata[$alias] ); // perform XOR for NMEA checksum
492
+		for ( $alias=1; $alias<$end; $alias++) {
493
+			$chksum ^= ord( $rawdata[$alias] );
494
+		}
495
+		// perform XOR for NMEA checksum
394 496
 		if ( $chksum == $dcs ) { // NMEA checksum pass
395 497
 			$pcs = explode(',', $rawdata);
396 498
 			// !AI??? identifier
397 499
 			$num_seq = (int)$pcs[1]; // number of sequences
398 500
 			$seq = (int)$pcs[2]; // get sequence
399 501
 			// get msg sequence id
400
-			if ($pcs[3] == '') $msg_sid = -1; // non-multipart message, set to -1
401
-			else $msg_sid = (int)$pcs[3]; // multipart message
502
+			if ($pcs[3] == '') {
503
+				$msg_sid = -1;
504
+			}
505
+			// non-multipart message, set to -1
506
+			else {
507
+				$msg_sid = (int)$pcs[3];
508
+			}
509
+			// multipart message
402 510
 			$ais_ch = $pcs[4]; // get AIS channel
403 511
 			// message sequence checking
404 512
 			if ($num_seq < 1 || $num_seq > 9) {
@@ -459,10 +567,18 @@  discard block
 block discarded – undo
459 567
 				//DEBUG echo "[$start $end $tst]\n";
460 568
 				$result = $this->process_ais_raw( $tst, "" );
461 569
 				$last_pos = $end + 1;
462
-			} else break;
570
+			} else {
571
+				break;
572
+			}
573
+		}
574
+		if ($last_pos > 0) {
575
+			$cbuf = substr($cbuf, $last_pos);
576
+		}
577
+		// move...
578
+		if (strlen($cbuf) > 1024) {
579
+			$cbuf = "";
463 580
 		}
464
-		if ($last_pos > 0) $cbuf = substr($cbuf, $last_pos); // move...
465
-		if (strlen($cbuf) > 1024) $cbuf = ""; // prevent overflow simple mode...
581
+		// prevent overflow simple mode...
466 582
 		return $result;
467 583
 	}
468 584
 
@@ -482,7 +598,9 @@  discard block
 block discarded – undo
482 598
 		if ($lat<0.0) {
483 599
 			$lat = -$lat;
484 600
 			$neg=true;
485
-		} else $neg=false;
601
+		} else {
602
+			$neg=false;
603
+		}
486 604
 		$latd = 0x00000000;
487 605
 		$latd = intval ($lat * 600000.0);
488 606
 		if ($neg==true) {
@@ -498,7 +616,9 @@  discard block
 block discarded – undo
498 616
 		if ($lon<0.0) {
499 617
 			$lon = -$lon;
500 618
 			$neg=true;
501
-		} else $neg=false;
619
+		} else {
620
+			$neg=false;
621
+		}
502 622
 		$lond = 0x00000000;
503 623
 		$lond = intval ($lon * 600000.0);
504 624
 		if ($neg==true) {
@@ -511,9 +631,14 @@  discard block
 block discarded – undo
511 631
 
512 632
 	private function char2bin($name, $max_len) {
513 633
 		$len = strlen($name);
514
-		if ($len > $max_len) $name = substr($name,0,$max_len);
515
-		if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len) * 6);
516
-		else $pad = '';
634
+		if ($len > $max_len) {
635
+			$name = substr($name,0,$max_len);
636
+		}
637
+		if ($len < $max_len) {
638
+			$pad = str_repeat('0', ($max_len - $len) * 6);
639
+		} else {
640
+			$pad = '';
641
+		}
517 642
 		$rv = '';
518 643
 		$ais_chars = array(
519 644
 		    '@'=>0, 'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 'I'=>9,
@@ -526,9 +651,12 @@  discard block
 block discarded – undo
526 651
 		);
527 652
 		// "
528 653
 		$_a = str_split($name);
529
-		if ($_a) foreach ($_a as $_1) {
654
+		if ($_a) {
655
+			foreach ($_a as $_1) {
530 656
 			if (isset($ais_chars[$_1])) $dec = $ais_chars[$_1];
531
-			else $dec = 0;
657
+		} else {
658
+				$dec = 0;
659
+			}
532 660
 			$bin = str_pad(decbin( $dec ), 6, '0', STR_PAD_LEFT);
533 661
 			$rv .= $bin;
534 662
 			//echo "$_1 $dec ($bin)<br/>";
@@ -540,7 +668,9 @@  discard block
 block discarded – undo
540 668
 		$len_bit = strlen($_enc);
541 669
 		$rem6 = $len_bit % 6;
542 670
 		$pad6_len = 0;
543
-		if ($rem6) $pad6_len = 6 - $rem6;
671
+		if ($rem6) {
672
+			$pad6_len = 6 - $rem6;
673
+		}
544 674
 		//echo  $pad6_len.'<br>';
545 675
 		$_enc .= str_repeat("0", $pad6_len); // pad the text...
546 676
 		$len_enc = strlen($_enc) / 6;
@@ -549,8 +679,11 @@  discard block
 block discarded – undo
549 679
 		for ($i=0; $i<$len_enc; $i++) {
550 680
 			$offset = $i * 6;
551 681
 			$dec = bindec(substr($_enc,$offset,6));
552
-			if ($dec < 40) $dec += 48;
553
-			else $dec += 56;
682
+			if ($dec < 40) {
683
+				$dec += 48;
684
+			} else {
685
+				$dec += 56;
686
+			}
554 687
 			//echo chr($dec)." $dec<br/>";
555 688
 			$itu .= chr($dec);
556 689
 		}
@@ -563,25 +696,41 @@  discard block
 block discarded – undo
563 696
 		}
564 697
 		$hex_arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
565 698
 		$lsb = $chksum & 0x0F;
566
-		if ($lsb >=0 && $lsb <= 15 ) $lsbc = $hex_arr[$lsb];
567
-		else $lsbc = '0';
699
+		if ($lsb >=0 && $lsb <= 15 ) {
700
+			$lsbc = $hex_arr[$lsb];
701
+		} else {
702
+			$lsbc = '0';
703
+		}
568 704
 		$msb = (($chksum & 0xF0) >> 4) & 0x0F;
569
-		if ($msb >=0 && $msb <= 15 ) $msbc = $hex_arr[$msb];
570
-		else $msbc = '0';
705
+		if ($msb >=0 && $msb <= 15 ) {
706
+			$msbc = $hex_arr[$msb];
707
+		} else {
708
+			$msbc = '0';
709
+		}
571 710
 		$itu = '!'.$itu."*{$msbc}{$lsbc}\r\n";
572 711
 		return $itu;
573 712
 	}
574 713
 
575 714
 	public function parse($buffer) {
576 715
 		$data = $this->process_ais_buf($buffer);
577
-		if (!is_object($data)) return array();
578
-		if ($data->lon != 0) $result['longitude'] = $data->lon;
579
-		if ($data->lat != 0) $result['latitude'] = $data->lat;
716
+		if (!is_object($data)) {
717
+			return array();
718
+		}
719
+		if ($data->lon != 0) {
720
+			$result['longitude'] = $data->lon;
721
+		}
722
+		if ($data->lat != 0) {
723
+			$result['latitude'] = $data->lat;
724
+		}
580 725
 		$result['ident'] = trim($data->name);
581 726
 		$result['timestamp'] = $data->ts;
582 727
 		$result['mmsi'] = $data->mmsi;
583
-		if ($data->sog != -1.0) $result['speed'] = $data->sog;
584
-		if ($data->cog != 0) $result['heading'] = $data->cog;
728
+		if ($data->sog != -1.0) {
729
+			$result['speed'] = $data->sog;
730
+		}
731
+		if ($data->cog != 0) {
732
+			$result['heading'] = $data->cog;
733
+		}
585 734
 		/*
586 735
 		    $ro->cls = 0; // AIS class undefined, also indicate unparsed msg
587 736
 		    $ro->id = bindec(substr($_aisdata,0,6));
@@ -591,15 +740,25 @@  discard block
 block discarded – undo
591 740
 
592 741
 	public function mmsitype($mmsi) {
593 742
 		if (strlen($mmsi) == 9) {
594
-			if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
595
-			elseif (substr($mmsi,0,3) == '972') return 'MOB (Man Overboard) device';
596
-			elseif (substr($mmsi,0,3) == '970') return 'AIS SART (Search and Rescue Transmitter)';
597
-			elseif (substr($mmsi,0,3) == '111') return 'SAR (Search and Rescue) aircraft';
598
-			elseif (substr($mmsi,0,2) == '98') return 'Auxiliary craft associated with a parent ship';
599
-			elseif (substr($mmsi,0,2) == '99') return 'Aids to Navigation';
600
-			elseif (substr($mmsi,0,2) == '00') return 'Coastal stations';
601
-			elseif (substr($mmsi,0,1) == '0') return 'Group of ships';
602
-			else return 'Ship';
743
+			if (substr($mmsi,0,3) == '974') {
744
+				return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
745
+			} elseif (substr($mmsi,0,3) == '972') {
746
+				return 'MOB (Man Overboard) device';
747
+			} elseif (substr($mmsi,0,3) == '970') {
748
+				return 'AIS SART (Search and Rescue Transmitter)';
749
+			} elseif (substr($mmsi,0,3) == '111') {
750
+				return 'SAR (Search and Rescue) aircraft';
751
+			} elseif (substr($mmsi,0,2) == '98') {
752
+				return 'Auxiliary craft associated with a parent ship';
753
+			} elseif (substr($mmsi,0,2) == '99') {
754
+				return 'Aids to Navigation';
755
+			} elseif (substr($mmsi,0,2) == '00') {
756
+				return 'Coastal stations';
757
+			} elseif (substr($mmsi,0,1) == '0') {
758
+				return 'Group of ships';
759
+			} else {
760
+				return 'Ship';
761
+			}
603 762
 		}
604 763
 
605 764
 	
@@ -616,32 +775,61 @@  discard block
 block discarded – undo
616 775
 			//if ($globalDebug) echo '==== Line format not supported : '.$buffer."\n";
617 776
 			return array();
618 777
 		}
619
-		if ($data->lon != 0) $result['longitude'] = $data->lon;
620
-		if ($data->lat != 0) $result['latitude'] = $data->lat;
778
+		if ($data->lon != 0) {
779
+			$result['longitude'] = $data->lon;
780
+		}
781
+		if ($data->lat != 0) {
782
+			$result['latitude'] = $data->lat;
783
+		}
621 784
 		$result['ident'] = trim(str_replace('@','',$data->name));
622 785
 		$result['timestamp'] = $data->ts;
623 786
 		$result['mmsi'] = $data->mmsi;
624
-		if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') $result['mmsi'] = '3'.$result['mmsi'];
787
+		if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') {
788
+			$result['mmsi'] = '3'.$result['mmsi'];
789
+		}
625 790
 		$result['mmsi_type'] = $this->mmsitype($result['mmsi']);
626
-		if ($data->sog != -1.0) $result['speed'] = $data->sog;
627
-		if ($data->heading !== '') $result['heading'] = $data->heading;
628
-		elseif ($data->cog != 0) $result['heading'] = $data->cog;
629
-		if ($data->status != '') $result['status'] = $data->status;
630
-		if ($data->statusid !== '') $result['statusid'] = $data->statusid;
631
-		if ($data->type !== '') $result['type'] = $data->type;
632
-		if ($data->typeid !== '') $result['typeid'] = $data->typeid;
633
-		if ($data->imo !== '') $result['imo'] = $data->imo;
634
-		if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@','',$data->callsign));
791
+		if ($data->sog != -1.0) {
792
+			$result['speed'] = $data->sog;
793
+		}
794
+		if ($data->heading !== '') {
795
+			$result['heading'] = $data->heading;
796
+		} elseif ($data->cog != 0) {
797
+			$result['heading'] = $data->cog;
798
+		}
799
+		if ($data->status != '') {
800
+			$result['status'] = $data->status;
801
+		}
802
+		if ($data->statusid !== '') {
803
+			$result['statusid'] = $data->statusid;
804
+		}
805
+		if ($data->type !== '') {
806
+			$result['type'] = $data->type;
807
+		}
808
+		if ($data->typeid !== '') {
809
+			$result['typeid'] = $data->typeid;
810
+		}
811
+		if ($data->imo !== '') {
812
+			$result['imo'] = $data->imo;
813
+		}
814
+		if ($data->callsign !== '') {
815
+			$result['callsign'] = trim(str_replace('@','',$data->callsign));
816
+		}
635 817
 		if (is_numeric($data->eta_month) && $data->eta_month != 0 && is_numeric($data->eta_day) && $data->eta_day != 0 && $data->eta_hour !== '' && $data->eta_minute !== '') {
636 818
 			$eta_ts = strtotime(date('Y').'-'.sprintf("%02d",$data->eta_month).'-'.sprintf("%02d",$data->eta_day).' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00');
637
-			if ($eta_ts != '') $result['eta_ts'] = $eta_ts;
819
+			if ($eta_ts != '') {
820
+				$result['eta_ts'] = $eta_ts;
821
+			}
638 822
 		} elseif (is_numeric($data->eta_hour) && is_numeric($data->eta_minute)) {
639 823
 			$eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00');
640
-			if ($eta_ts != '') $result['eta_ts'] = $eta_ts;
824
+			if ($eta_ts != '') {
825
+				$result['eta_ts'] = $eta_ts;
826
+			}
641 827
 		}
642 828
 		if ($data->destination != '') {
643 829
 			$dest = trim(str_replace('@','',$data->destination));
644
-			if ($dest != '') $result['destination'] = $dest;
830
+			if ($dest != '') {
831
+				$result['destination'] = $dest;
832
+			}
645 833
 		}
646 834
 		$result['all'] = (array) $data;
647 835
 		/*
Please login to merge, or discard this patch.
require/class.SpotterImport.php 4 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -46,6 +46,10 @@
 block discarded – undo
46 46
 
47 47
     }
48 48
 
49
+    /**
50
+     * @param string $id
51
+     * @param string $ident
52
+     */
49 53
     public function get_Schedule($id,$ident) {
50 54
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
51 55
 	// Get schedule here, so it's done only one time
Please login to merge, or discard this patch.
Indentation   +422 added lines, -422 removed lines patch added patch discarded remove patch
@@ -8,20 +8,20 @@  discard block
 block discarded – undo
8 8
 require_once(dirname(__FILE__).'/class.Stats.php');
9 9
 require_once(dirname(__FILE__).'/class.Source.php');
10 10
 if (isset($globalServerAPRS) && $globalServerAPRS) {
11
-    require_once(dirname(__FILE__).'/class.APRS.php');
11
+	require_once(dirname(__FILE__).'/class.APRS.php');
12 12
 }
13 13
 
14 14
 class SpotterImport {
15
-    private $all_flights = array();
16
-    private $last_delete_hourly = 0;
17
-    private $last_delete = 0;
18
-    private $stats = array();
19
-    private $tmd = 0;
20
-    private $source_location = array();
21
-    public $db = null;
22
-    public $nb = 0;
15
+	private $all_flights = array();
16
+	private $last_delete_hourly = 0;
17
+	private $last_delete = 0;
18
+	private $stats = array();
19
+	private $tmd = 0;
20
+	private $source_location = array();
21
+	public $db = null;
22
+	public $nb = 0;
23 23
 
24
-    public function __construct($dbc = null) {
24
+	public function __construct($dbc = null) {
25 25
 	global $globalBeta, $globalServerAPRS, $APRSSpotter, $globalNoDB;
26 26
 	if (!(isset($globalNoDB) && $globalNoDB)) {
27 27
 		$Connection = new Connection($dbc);
@@ -33,14 +33,14 @@  discard block
 block discarded – undo
33 33
 		$currentdate = date('Y-m-d');
34 34
 		$sourcestat = $Stats->getStatsSource($currentdate);
35 35
 		if (!empty($sourcestat)) {
36
-		    foreach($sourcestat as $srcst) {
37
-		    	$type = $srcst['stats_type'];
36
+			foreach($sourcestat as $srcst) {
37
+				$type = $srcst['stats_type'];
38 38
 			if ($type == 'polar' || $type == 'hist') {
39
-			    $source = $srcst['source_name'];
40
-			    $data = $srcst['source_data'];
41
-			    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
42
-	    		}
43
-		    }
39
+				$source = $srcst['source_name'];
40
+				$data = $srcst['source_data'];
41
+				$this->stats[$currentdate][$source][$type] = json_decode($data,true);
42
+				}
43
+			}
44 44
 		}
45 45
 	}
46 46
 	if (isset($globalServerAPRS) && $globalServerAPRS) {
@@ -48,9 +48,9 @@  discard block
 block discarded – undo
48 48
 		//$APRSSpotter->connect();
49 49
 	}
50 50
 
51
-    }
51
+	}
52 52
 
53
-    public function get_Schedule($id,$ident) {
53
+	public function get_Schedule($id,$ident) {
54 54
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
55 55
 	// Get schedule here, so it's done only one time
56 56
 	
@@ -70,42 +70,42 @@  discard block
 block discarded – undo
70 70
 	$operator = $Spotter->getOperator($ident);
71 71
 	$scheduleexist = false;
72 72
 	if ($Schedule->checkSchedule($operator) == 0) {
73
-	    $operator = $Translation->checkTranslation($ident);
74
-	    if ($Schedule->checkSchedule($operator) == 0) {
73
+		$operator = $Translation->checkTranslation($ident);
74
+		if ($Schedule->checkSchedule($operator) == 0) {
75 75
 		$schedule = $Schedule->fetchSchedule($operator);
76 76
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
77
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
78
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
79
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
80
-		    // Should also check if route schedule = route from DB
81
-		    if ($schedule['DepartureAirportIATA'] != '') {
77
+			if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
78
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
79
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
80
+			// Should also check if route schedule = route from DB
81
+			if ($schedule['DepartureAirportIATA'] != '') {
82 82
 			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
83
-			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
84
-			    if (trim($airport_icao) != '') {
83
+				$airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
84
+				if (trim($airport_icao) != '') {
85 85
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
86 86
 				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
87
-			    }
87
+				}
88
+			}
88 89
 			}
89
-		    }
90
-		    if ($schedule['ArrivalAirportIATA'] != '') {
90
+			if ($schedule['ArrivalAirportIATA'] != '') {
91 91
 			if ($this->all_flights[$id]['arrival_airport'] != $Spotter->getAirportIcao($schedule['ArrivalAirportIATA'])) {
92
-			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
93
-			    if (trim($airport_icao) != '') {
92
+				$airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
93
+				if (trim($airport_icao) != '') {
94 94
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
95 95
 				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
96
-			    }
96
+				}
97 97
 			}
98
-		    }
99
-		    $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
98
+			}
99
+			$Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
100 100
 		}
101
-	    } else $scheduleexist = true;
101
+		} else $scheduleexist = true;
102 102
 	} else $scheduleexist = true;
103 103
 	// close connection, at least one way will work ?
104
-       if ($scheduleexist) {
104
+	   if ($scheduleexist) {
105 105
 		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
106
-    		$sch = $Schedule->getSchedule($operator);
106
+			$sch = $Schedule->getSchedule($operator);
107 107
 		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time']));
108
-       }
108
+	   }
109 109
 	$Spotter->db = null;
110 110
 	$Schedule->db = null;
111 111
 	$Translation->db = null;
@@ -120,78 +120,78 @@  discard block
 block discarded – undo
120 120
 	}
121 121
 	  */
122 122
 	}
123
-    }
123
+	}
124 124
 
125
-    public function checkAll() {
125
+	public function checkAll() {
126 126
 	global $globalDebug, $globalNoImport;
127 127
 	if ($globalDebug) echo "Update last seen flights data...\n";
128 128
 	if (!isset($globalNoImport) || $globalNoImport === FALSE) {
129
-	    foreach ($this->all_flights as $key => $flight) {
129
+		foreach ($this->all_flights as $key => $flight) {
130 130
 		if (isset($this->all_flights[$key]['id'])) {
131
-		    //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
132
-    		    $Spotter = new Spotter($this->db);
133
-        	    $real_arrival = $this->arrival($key);
134
-        	    if (isset($this->all_flights[$key]['altitude'])) $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
135
-        	}
136
-	    }
131
+			//echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
132
+				$Spotter = new Spotter($this->db);
133
+				$real_arrival = $this->arrival($key);
134
+				if (isset($this->all_flights[$key]['altitude'])) $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
135
+			}
136
+		}
137
+	}
137 138
 	}
138
-    }
139 139
 
140
-    public function arrival($key) {
140
+	public function arrival($key) {
141 141
 	global $globalClosestMinDist, $globalDebug;
142 142
 	if ($globalDebug) echo 'Update arrival...'."\n";
143 143
 	$Spotter = new Spotter($this->db);
144
-        $airport_icao = '';
145
-        $airport_time = '';
146
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
144
+		$airport_icao = '';
145
+		$airport_time = '';
146
+		if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
147 147
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
148
-	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
149
-    	    if (isset($closestAirports[0])) {
150
-        	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
151
-        	    $airport_icao = $closestAirports[0]['icao'];
152
-        	    $airport_time = $this->all_flights[$key]['datetime'];
153
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
154
-        	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
155
-        	    foreach ($closestAirports as $airport) {
156
-        		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
157
-        		    $airport_icao = $airport['icao'];
158
-        		    $airport_time = $this->all_flights[$key]['datetime'];
159
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
160
-        		    break;
161
-        		}
162
-        	    }
163
-        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
164
-        		$airport_icao = $closestAirports[0]['icao'];
165
-        		$airport_time = $this->all_flights[$key]['datetime'];
166
-        	} else {
167
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
168
-        	}
169
-    	    } else {
170
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
171
-    	    }
148
+		$closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
149
+			if (isset($closestAirports[0])) {
150
+			if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
151
+				$airport_icao = $closestAirports[0]['icao'];
152
+				$airport_time = $this->all_flights[$key]['datetime'];
153
+				if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
154
+			} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
155
+				foreach ($closestAirports as $airport) {
156
+				if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
157
+					$airport_icao = $airport['icao'];
158
+					$airport_time = $this->all_flights[$key]['datetime'];
159
+					if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
160
+					break;
161
+				}
162
+				}
163
+			} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
164
+				$airport_icao = $closestAirports[0]['icao'];
165
+				$airport_time = $this->all_flights[$key]['datetime'];
166
+			} else {
167
+				if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
168
+			}
169
+			} else {
170
+				if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
171
+			}
172 172
 
173
-        } else {
174
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
175
-        }
176
-        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
177
-    }
173
+		} else {
174
+			if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
175
+		}
176
+		return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
177
+	}
178 178
 
179 179
 
180 180
 
181
-    public function del() {
181
+	public function del() {
182 182
 	global $globalDebug, $globalNoImport, $globalNoDB;
183 183
 	// Delete old infos
184 184
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
185 185
 	foreach ($this->all_flights as $key => $flight) {
186
-	    if (isset($flight['lastupdate'])) {
186
+		if (isset($flight['lastupdate'])) {
187 187
 		if ($flight['lastupdate'] < (time()-5900)) {
188
-		    $this->delKey($key);
188
+			$this->delKey($key);
189 189
 		}
190
-	    }
190
+		}
191
+	}
191 192
 	}
192
-    }
193 193
 
194
-    public function delKey($key) {
194
+	public function delKey($key) {
195 195
 	global $globalDebug, $globalNoImport, $globalNoDB;
196 196
 	// Delete old infos
197 197
 	if (isset($this->all_flights[$key]['id'])) {
@@ -206,9 +206,9 @@  discard block
 block discarded – undo
206 206
 		}
207 207
 	}
208 208
 	unset($this->all_flights[$key]);
209
-    }
209
+	}
210 210
 
211
-    public function add($line) {
211
+	public function add($line) {
212 212
 	global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights, $globalServerAPRS, $APRSSpotter, $globalNoImport, $globalNoDB, $globalVA, $globalAircraftMaxUpdate, $globalAircraftMinUpdate, $globalLiveInterval;
213 213
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
214 214
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
@@ -234,20 +234,20 @@  discard block
 block discarded – undo
234 234
 	
235 235
 	// SBS format is CSV format
236 236
 	if(is_array($line) && (isset($line['hex']) || isset($line['id']))) {
237
-	    //print_r($line);
238
-	    if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']);
239
-  	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
237
+		//print_r($line);
238
+		if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']);
239
+  		if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
240 240
 
241 241
 		// Increment message number
242 242
 		if (isset($line['sourcestats']) && $line['sourcestats'] === TRUE) {
243
-		    $current_date = date('Y-m-d');
244
-		    if (isset($line['source_name'])) $source = $line['source_name'];
245
-		    else $source = '';
246
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
247
-		    if (!isset($this->stats[$current_date][$source]['msg'])) {
248
-		    	$this->stats[$current_date][$source]['msg']['date'] = time();
249
-		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
250
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
243
+			$current_date = date('Y-m-d');
244
+			if (isset($line['source_name'])) $source = $line['source_name'];
245
+			else $source = '';
246
+			if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
247
+			if (!isset($this->stats[$current_date][$source]['msg'])) {
248
+				$this->stats[$current_date][$source]['msg']['date'] = time();
249
+				$this->stats[$current_date][$source]['msg']['nb'] = 1;
250
+			} else $this->stats[$current_date][$source]['msg']['nb'] += 1;
251 251
 		}
252 252
 		
253 253
 		/*
@@ -263,54 +263,54 @@  discard block
 block discarded – undo
263 263
 		//$this->db = $dbc;
264 264
 
265 265
 		//$hex = trim($line['hex']);
266
-	        if (!isset($line['id'])) $id = trim($line['hex']);
267
-	        else $id = trim($line['id']);
266
+			if (!isset($line['id'])) $id = trim($line['hex']);
267
+			else $id = trim($line['id']);
268 268
 		
269 269
 		if (!isset($this->all_flights[$id])) {
270
-		    if ($globalDebug) echo 'New flight...'."\n";
271
-		    $this->all_flights[$id] = array();
272
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
273
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '','altitude_previous' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
274
-		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
275
-		    if (!isset($line['id'])) {
270
+			if ($globalDebug) echo 'New flight...'."\n";
271
+			$this->all_flights[$id] = array();
272
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
273
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '','altitude_previous' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
274
+			if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
275
+			if (!isset($line['id'])) {
276 276
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
277 277
 //			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
278 278
 //			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
279 279
 			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
280
-		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
281
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
282
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
280
+				//else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
281
+			 } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
282
+			if ($globalAllFlights !== FALSE) $dataFound = true;
283 283
 		}
284 284
 		if (isset($line['source_type']) && $line['source_type'] != '') {
285
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
285
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
286 286
 		}
287 287
 		
288 288
 		//print_r($this->all_flights);
289 289
 		if (isset($line['hex']) && !isset($this->all_flights[$id]['hex']) && ctype_xdigit($line['hex'])) {
290
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
291
-		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
290
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
291
+			//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
292 292
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
293
-		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
294
-		    if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????') && $line['format_source'] != 'whazzup' && $line['format_source'] != 'vatsimtxt' && $line['format_source'] != 'pireps' && $line['format_source'] != 'phpvmacars' && $line['format_source'] != 'vam' && $line['format_source'] != 'flightgearsp' && $line['format_source'] != 'flightgearmp') {
293
+			//} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
294
+			if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????') && $line['format_source'] != 'whazzup' && $line['format_source'] != 'vatsimtxt' && $line['format_source'] != 'pireps' && $line['format_source'] != 'phpvmacars' && $line['format_source'] != 'vam' && $line['format_source'] != 'flightgearsp' && $line['format_source'] != 'flightgearmp') {
295 295
 			$timeelapsed = microtime(true);
296 296
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
297
-			    $Spotter = new Spotter($this->db);
298
-			    if (isset($this->all_flights[$id]['source_type'])) {
297
+				$Spotter = new Spotter($this->db);
298
+				if (isset($this->all_flights[$id]['source_type'])) {
299 299
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']),$this->all_flights[$id]['source_type']);
300
-			    } else {
300
+				} else {
301 301
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
302
-			    }
303
-			    $Spotter->db = null;
304
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
305
-			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
302
+				}
303
+				$Spotter->db = null;
304
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
305
+				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
306 306
 			}
307
-		    }
308
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
309
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
307
+			}
308
+			if ($globalAllFlights !== FALSE) $dataFound = true;
309
+			if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
310 310
 		}
311
-	        if (isset($line['id']) && !isset($line['hex'])) {
312
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
313
-	        }
311
+			if (isset($line['id']) && !isset($line['hex'])) {
312
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
313
+			}
314 314
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
315 315
 			$icao = $line['aircraft_icao'];
316 316
 			$Spotter = new Spotter($this->db);
@@ -339,9 +339,9 @@  discard block
 block discarded – undo
339 339
 		}
340 340
 		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
341 341
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60 && strtotime($line['datetime']) < time()+20*60) {
342
-		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
342
+			if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
343 343
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
344
-		    } else {
344
+			} else {
345 345
 				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
346 346
 				elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
347 347
 				/*
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
 				print_r($line);
351 351
 				*/
352 352
 				return '';
353
-		    }
353
+			}
354 354
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) {
355 355
 			if ($globalDebug) echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n";
356 356
 			return '';
@@ -367,21 +367,21 @@  discard block
 block discarded – undo
367 367
 		}
368 368
 
369 369
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') {
370
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
370
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
371 371
 		}
372 372
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
373
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
373
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
374 374
 		}
375 375
 		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
376
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => trim($line['pilot_id'])));
376
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => trim($line['pilot_id'])));
377 377
 		}
378 378
 		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
379
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => trim($line['pilot_name'])));
379
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => trim($line['pilot_name'])));
380 380
 		}
381 381
  
382 382
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) {
383 383
 
384
-		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
384
+			if ($this->all_flights[$id]['addedSpotter'] == 1) {
385 385
 			if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
386 386
 				if ($globalDebug) echo '---!!!! New ident, reset aircraft data...'."\n";
387 387
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
@@ -390,23 +390,23 @@  discard block
 block discarded – undo
390 390
 				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
391 391
 				elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
392 392
 			} else {
393
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
394
-			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
393
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
394
+				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
395 395
 				$timeelapsed = microtime(true);
396
-            			$Spotter = new Spotter($this->db);
397
-            			$fromsource = NULL;
398
-            			if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
399
-            			elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
396
+						$Spotter = new Spotter($this->db);
397
+						$fromsource = NULL;
398
+						if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
399
+						elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
400 400
 				elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
401 401
 				elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
402 402
 				elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
403
-            			$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
403
+						$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
404 404
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
405 405
 				$Spotter->db = null;
406 406
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
407
-			    }
407
+				}
408 408
 			}
409
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
409
+			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
410 410
 		    
411 411
 /*
412 412
 		    if (!isset($line['id'])) {
@@ -416,63 +416,63 @@  discard block
 block discarded – undo
416 416
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
417 417
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
418 418
   */
419
-		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
419
+			if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
420 420
 
421
-		    //$putinarchive = true;
422
-		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
421
+			//$putinarchive = true;
422
+			if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
423 423
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
424
-		    }
425
-		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
424
+			}
425
+			if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
426 426
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
427
-		    }
428
-		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
429
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
430
-		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
427
+			}
428
+			if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
429
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
430
+			} elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
431 431
 			$timeelapsed = microtime(true);
432 432
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
433 433
 				$Spotter = new Spotter($this->db);
434 434
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
435 435
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
436
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
436
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
437 437
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
438
-                        }
439
-		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
438
+						}
439
+			} elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
440 440
 			$timeelapsed = microtime(true);
441 441
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
442
-			    $Spotter = new Spotter($this->db);
443
-			    $route = $Spotter->getRouteInfo(trim($line['ident']));
444
-			    if (!isset($route['fromairport_icao']) && !isset($route['toairport_icao'])) {
442
+				$Spotter = new Spotter($this->db);
443
+				$route = $Spotter->getRouteInfo(trim($line['ident']));
444
+				if (!isset($route['fromairport_icao']) && !isset($route['toairport_icao'])) {
445 445
 				$Translation = new Translation($this->db);
446 446
 				$ident = $Translation->checkTranslation(trim($line['ident']));
447 447
 				$route = $Spotter->getRouteInfo($ident);
448 448
 				$Translation->db = null;
449
-			    }
450
-			    $Spotter->db = null;
451
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
452
-                    	}
449
+				}
450
+				$Spotter->db = null;
451
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
452
+						}
453 453
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
454
-			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
455
-			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
454
+				//if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
455
+				if ($route['fromairport_icao'] != $route['toairport_icao']) {
456 456
 				//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['FromAirport_ICAO'],'arrival_airport' => $route['ToAirport_ICAO'],'route_stop' => $route['RouteStop']));
457
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
458
-		    	    }
457
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
458
+					}
459 459
 			}
460 460
 			if (!isset($globalFork)) $globalFork = TRUE;
461 461
 			if (!$globalVA && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
462 462
 				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
463 463
 			}
464
-		    }
464
+			}
465 465
 		}
466 466
 
467 467
 		if (isset($line['speed']) && $line['speed'] != '' && $line['speed'] != 0) {
468 468
 		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
469
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
470
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
471
-		    //$dataFound = true;
469
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
470
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
471
+			//$dataFound = true;
472 472
 		} else if (!isset($this->all_flights[$id]['speed_fromsrc']) && isset($this->all_flights[$id]['time_last_coord']) && $this->all_flights[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
473
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
474
-		    if ($distance > 1000 && $distance < 10000) {
475
-		    // use datetime
473
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
474
+			if ($distance > 1000 && $distance < 10000) {
475
+			// use datetime
476 476
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
477 477
 			$speed = $speed*3.6;
478 478
 			if ($speed < 1000) {
@@ -481,48 +481,48 @@  discard block
 block discarded – undo
481 481
 	  		} else {
482 482
 	  			if ($globalDebug) echo "ø IGNORED : Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
483 483
 	  		}
484
-		    }
484
+			}
485 485
 		}
486 486
 
487 487
 
488 488
 
489
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
490
-	    	    if (ctype_digit(strval($line['latitude'])) || ctype_digit(strval($line['longitude']))) {
491
-	    	    	if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
492
-	    	    	return false;
493
-	    	    }
494
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
495
-	    	    else unset($timediff);
496
-	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
497
-	    	    else unset($timediff_archive);
498
-	    	    if ($this->tmd > 5
499
-	    	        || (isset($line['format_source']) 
500
-	    	    	    && $line['format_source'] == 'airwhere' 
501
-	    	    	    && ((!isset($this->all_flights[$id]['latitude']) 
502
-	    	    		|| !isset($this->all_flights[$id]['longitude'])) 
503
-	    	    		|| (isset($this->all_flights[$id]['latitude']) 
504
-	    	    		    && isset($this->all_flights[$id]['longitude']) 
505
-	    	    		    && $this->all_flights[$id]['latitude'] != $line['latitude'] 
506
-	    	    		    && $this->all_flights[$id]['longitude'] != $line['longitude']
507
-	    	    		)
508
-	    	    	    )
509
-	    	    	)
510
-	    		|| (isset($globalVA) && $globalVA) 
511
-	    	    	|| (isset($globalIVAO) && $globalIVAO)
512
-	    	    	|| (isset($globalVATSIM) && $globalVATSIM)
513
-	    	    	|| (isset($globalphpVMS) && $globalphpVMS)
514
-	    	    	|| (isset($globalVAM) && $globalVAM)
515
-	    	    	|| !isset($timediff)
516
-	    	    	|| $timediff > $globalLiveInterval
517
-	    	    	|| ($timediff > 30 
518
-	    	    	    && isset($this->all_flights[$id]['latitude']) 
519
-	    	    	    && isset($this->all_flights[$id]['longitude']) 
520
-	    	    	    && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'))
521
-	    	    	    )
522
-	    	    	) {
489
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
490
+				if (ctype_digit(strval($line['latitude'])) || ctype_digit(strval($line['longitude']))) {
491
+					if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
492
+					return false;
493
+				}
494
+				if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
495
+				else unset($timediff);
496
+				if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
497
+				else unset($timediff_archive);
498
+				if ($this->tmd > 5
499
+					|| (isset($line['format_source']) 
500
+						&& $line['format_source'] == 'airwhere' 
501
+						&& ((!isset($this->all_flights[$id]['latitude']) 
502
+						|| !isset($this->all_flights[$id]['longitude'])) 
503
+						|| (isset($this->all_flights[$id]['latitude']) 
504
+							&& isset($this->all_flights[$id]['longitude']) 
505
+							&& $this->all_flights[$id]['latitude'] != $line['latitude'] 
506
+							&& $this->all_flights[$id]['longitude'] != $line['longitude']
507
+						)
508
+						)
509
+					)
510
+				|| (isset($globalVA) && $globalVA) 
511
+					|| (isset($globalIVAO) && $globalIVAO)
512
+					|| (isset($globalVATSIM) && $globalVATSIM)
513
+					|| (isset($globalphpVMS) && $globalphpVMS)
514
+					|| (isset($globalVAM) && $globalVAM)
515
+					|| !isset($timediff)
516
+					|| $timediff > $globalLiveInterval
517
+					|| ($timediff > 30 
518
+						&& isset($this->all_flights[$id]['latitude']) 
519
+						&& isset($this->all_flights[$id]['longitude']) 
520
+						&& $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'))
521
+						)
522
+					) {
523 523
 
524 524
 			if ((isset($timediff) && !isset($timediff_archive)) || (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude']))) {
525
-			    if ((isset($timediff_archive) && $timediff_archive > $globalAircraftMaxUpdate)
525
+				if ((isset($timediff_archive) && $timediff_archive > $globalAircraftMaxUpdate)
526 526
 				|| (isset($line['format_source']) && $line['format_source'] == 'airwhere') 
527 527
 				|| !$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
528 528
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
@@ -530,9 +530,9 @@  discard block
 block discarded – undo
530 530
 				$this->all_flights[$id]['putinarchive'] = true;
531 531
 				$this->tmd = 0;
532 532
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
533
-				    if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
534
-				    $timeelapsed = microtime(true);
535
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
533
+					if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
534
+					$timeelapsed = microtime(true);
535
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
536 536
 					$Spotter = new Spotter($this->db);
537 537
 					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
538 538
 					if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
@@ -540,11 +540,11 @@  discard block
 block discarded – undo
540 540
 					$Spotter->db = null;
541 541
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
542 542
 					if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
543
-				    }
543
+					}
544 544
 				}
545 545
 				$this->all_flights[$id]['time_last_archive_coord'] = time();
546
-			    } 
547
-			    /*
546
+				} 
547
+				/*
548 548
 			    else {
549 549
 				if (!isset($timediff)) echo 'NO TIMEDIFF';
550 550
 				else {
@@ -558,16 +558,16 @@  discard block
 block discarded – undo
558 558
 			}
559 559
 
560 560
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
561
-			    //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
561
+				//if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
562 562
 				if (!isset($this->all_flights[$id]['archive_latitude'])) {
563 563
 					$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
564 564
 					$this->all_flights[$id]['time_last_coord'] = time();
565 565
 				}
566 566
 				//if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs' || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > 0.0001)) {
567 567
 				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > 0.0001)) {
568
-				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
569
-				    $dataFound = true;
570
-				    $this->all_flights[$id]['time_last_coord'] = time();
568
+					$this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
569
+					$dataFound = true;
570
+					$this->all_flights[$id]['time_last_coord'] = time();
571 571
 				}
572 572
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
573 573
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
@@ -578,24 +578,24 @@  discard block
 block discarded – undo
578 578
 				    //$putinarchive = true;
579 579
 				}
580 580
 				*/
581
-			    /*
581
+				/*
582 582
 			    } elseif (isset($this->all_flights[$id]['latitude'])) {
583 583
 				if ($globalDebug) echo '!!! Strange latitude value - diff : '.abs($this->all_flights[$id]['latitude']-$line['latitude']).'- previous lat : '.$this->all_flights[$id]['latitude'].'- new lat : '.$line['latitude']."\n";
584 584
 			    }
585 585
 			    */
586 586
 			}
587 587
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
588
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
589
-			    //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
588
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
589
+				//if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
590 590
 				if (!isset($this->all_flights[$id]['archive_longitude'])) {
591 591
 					$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
592 592
 					$this->all_flights[$id]['time_last_coord'] = time();
593 593
 				}
594 594
 				//if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs' || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > 0.0001)) {
595 595
 				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > 0.0001)) {
596
-				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
597
-				    $dataFound = true;
598
-				    $this->all_flights[$id]['time_last_coord'] = time();
596
+					$this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
597
+					$dataFound = true;
598
+					$this->all_flights[$id]['time_last_coord'] = time();
599 599
 				}
600 600
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
601 601
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
@@ -613,77 +613,77 @@  discard block
 block discarded – undo
613 613
 			    */
614 614
 			}
615 615
 
616
-		    } else if ($globalDebug && $timediff > 30) {
616
+			} else if ($globalDebug && $timediff > 30) {
617 617
 			$this->tmd = $this->tmd + 1;
618 618
 			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
619 619
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
620 620
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
621 621
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
622
-		    }
622
+			}
623 623
 		}
624 624
 		if (isset($line['last_update']) && $line['last_update'] != '') {
625
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
626
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
625
+			if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
626
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
627 627
 		}
628 628
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
629
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
630
-		    //$dataFound = true;
629
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
630
+			//$dataFound = true;
631 631
 		}
632 632
 		if (isset($line['format_source']) && $line['format_source'] != '') {
633
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
633
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
634 634
 		}
635 635
 		if (isset($line['source_name']) && $line['source_name'] != '') {
636
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
636
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
637 637
 		}
638 638
 		if (isset($line['emergency']) && $line['emergency'] != '') {
639
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
640
-		    //$dataFound = true;
639
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
640
+			//$dataFound = true;
641 641
 		}
642 642
 		if (isset($line['ground']) && $line['ground'] != '') {
643
-		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
643
+			if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
644 644
 			// Here we force archive of flight because after ground it's a new one (or should be)
645 645
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
646 646
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
647 647
 			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
648
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
648
+				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
649 649
 			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
650
-		    }
651
-		    if ($line['ground'] != 1) $line['ground'] = 0;
652
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
653
-		    //$dataFound = true;
650
+			}
651
+			if ($line['ground'] != 1) $line['ground'] = 0;
652
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
653
+			//$dataFound = true;
654 654
 		}
655 655
 		if (isset($line['squawk']) && $line['squawk'] != '') {
656
-		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
657
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
658
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
659
-			    $highlight = '';
660
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
661
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
662
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
663
-			    if ($highlight != '') {
656
+			if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
657
+				if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
658
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
659
+				$highlight = '';
660
+				if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
661
+				if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
662
+				if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
663
+				if ($highlight != '') {
664 664
 				$timeelapsed = microtime(true);
665 665
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
666
-				    $Spotter = new Spotter($this->db);
667
-				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
668
-				    $Spotter->db = null;
669
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
666
+					$Spotter = new Spotter($this->db);
667
+					$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
668
+					$Spotter->db = null;
669
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
670 670
 				}
671 671
 				//$putinarchive = true;
672 672
 				//$highlight = '';
673
-			    }
673
+				}
674 674
 			    
675
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
676
-		    //$dataFound = true;
675
+			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
676
+			//$dataFound = true;
677 677
 		}
678 678
 
679 679
 		if (isset($line['altitude']) && $line['altitude'] != '') {
680
-		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
680
+			//if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
681 681
 			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
682 682
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
683 683
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
684 684
 			//$dataFound = true;
685
-		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
686
-		    if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
685
+			//} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
686
+			if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
687 687
 			if (isset($this->all_flights[$id]['over_country']) && $this->all_flights[$id]['over_country'] != '' && isset($this->all_flights[$id]['altitude_previous']) && $this->all_flights[$id]['altitude_previous'] != '' && $this->all_flights[$id]['altitude_previous'] < $this->all_flights[$id]['altitude_real'] && isset($this->all_flights[$id]['lastupdate']) && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
688 688
 				if ($globalDebug) echo '--- Reset because of altitude'."\n";
689 689
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
@@ -692,27 +692,27 @@  discard block
 block discarded – undo
692 692
 				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
693 693
 				elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
694 694
 			}
695
-		    }
696
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
695
+			}
696
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
697 697
 		}
698 698
 
699 699
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
700
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
700
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
701 701
 		}
702 702
 		
703 703
 		if (isset($line['heading']) && $line['heading'] != '') {
704
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
705
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
706
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
707
-		    //$dataFound = true;
704
+			if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
705
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
706
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
707
+			//$dataFound = true;
708 708
   		} elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) {
709
-  		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
710
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
711
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
712
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['id']." : ".$heading."\n";
709
+  			$heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
710
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
711
+			if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
712
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['id']." : ".$heading."\n";
713 713
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
714
-  		    // If not enough messages and ACARS set heading to 0
715
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
714
+  			// If not enough messages and ACARS set heading to 0
715
+  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
716 716
   		}
717 717
 		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
718 718
 		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
@@ -725,125 +725,125 @@  discard block
 block discarded – undo
725 725
 		//if ($dataFound === true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['heading'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
726 726
 		//if ($dataFound === true && isset($this->all_flights[$id]['hex'])) {
727 727
 		if ($dataFound === true && isset($this->all_flights[$id]['id'])) {
728
-		    $this->all_flights[$id]['lastupdate'] = time();
729
-		    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
730
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
731
-			    //print_r($this->all_flights);
732
-			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
733
-			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
734
-			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
728
+			$this->all_flights[$id]['lastupdate'] = time();
729
+			if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
730
+				if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
731
+				//print_r($this->all_flights);
732
+				//echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
733
+				//$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
734
+				if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
735 735
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
736
-				    if ($globalDebug) echo "Check if aircraft is already in DB...";
737
-				    $timeelapsed = microtime(true);
738
-				    $SpotterLive = new SpotterLive($this->db);
739
-				    if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
736
+					if ($globalDebug) echo "Check if aircraft is already in DB...";
737
+					$timeelapsed = microtime(true);
738
+					$SpotterLive = new SpotterLive($this->db);
739
+					if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
740 740
 					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
741 741
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
742
-				    } elseif (isset($line['id'])) {
742
+					} elseif (isset($line['id'])) {
743 743
 					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
744 744
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
745
-				    } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
745
+					} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
746 746
 					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
747 747
 					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
748
-				    } else $recent_ident = '';
749
-				    $SpotterLive->db=null;
750
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
751
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
748
+					} else $recent_ident = '';
749
+					$SpotterLive->db=null;
750
+					if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
751
+					elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
752 752
 				} else $recent_ident = '';
753
-			    } else {
753
+				} else {
754 754
 				$recent_ident = '';
755 755
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
756
-			    }
757
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
758
-			    if($recent_ident == "")
759
-			    {
756
+				}
757
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
758
+				if($recent_ident == "")
759
+				{
760 760
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
761 761
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
762 762
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
763 763
 				//adds the spotter data for the archive
764 764
 				$ignoreImport = false;
765 765
 				foreach($globalAirportIgnore as $airportIgnore) {
766
-				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
766
+					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
767 767
 					$ignoreImport = true;
768
-				    }
768
+					}
769 769
 				}
770 770
 				if (count($globalAirportAccept) > 0) {
771
-				    $ignoreImport = true;
772
-				    foreach($globalAirportIgnore as $airportIgnore) {
771
+					$ignoreImport = true;
772
+					foreach($globalAirportIgnore as $airportIgnore) {
773 773
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
774
-					    $ignoreImport = false;
774
+						$ignoreImport = false;
775
+					}
775 776
 					}
776
-				    }
777 777
 				}
778 778
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
779
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
779
+					foreach($globalAirlineIgnore as $airlineIgnore) {
780 780
 					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
781
-					    $ignoreImport = true;
781
+						$ignoreImport = true;
782
+					}
782 783
 					}
783
-				    }
784 784
 				}
785 785
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
786
-				    $ignoreImport = true;
787
-				    foreach($globalAirlineAccept as $airlineAccept) {
786
+					$ignoreImport = true;
787
+					foreach($globalAirlineAccept as $airlineAccept) {
788 788
 					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
789
-					    $ignoreImport = false;
789
+						$ignoreImport = false;
790
+					}
790 791
 					}
791
-				    }
792 792
 				}
793 793
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
794
-				    $ignoreImport = true;
795
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
794
+					$ignoreImport = true;
795
+					foreach($globalPilotIdAccept as $pilotIdAccept) {
796 796
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
797
-					    $ignoreImport = false;
797
+						$ignoreImport = false;
798
+					}
798 799
 					}
799
-				    }
800 800
 				}
801 801
 				
802 802
 				if (!$ignoreImport) {
803
-				    $highlight = '';
804
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
805
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
806
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
807
-				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
808
-				    $timeelapsed = microtime(true);
809
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
803
+					$highlight = '';
804
+					if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
805
+					if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
806
+					if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
807
+					if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
808
+					$timeelapsed = microtime(true);
809
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
810 810
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
811
-					    $Spotter = new Spotter($this->db);
812
-					    $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']);
813
-					    $Spotter->db = null;
814
-					    if ($globalDebug && isset($result)) echo $result."\n";
811
+						$Spotter = new Spotter($this->db);
812
+						$result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']);
813
+						$Spotter->db = null;
814
+						if ($globalDebug && isset($result)) echo $result."\n";
815 815
 					}
816
-				    }
817
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
818
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
816
+					}
817
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
818
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
819 819
 
820
-				    // Add source stat in DB
821
-				    $Stats = new Stats($this->db);
822
-				    if (!empty($this->stats)) {
820
+					// Add source stat in DB
821
+					$Stats = new Stats($this->db);
822
+					if (!empty($this->stats)) {
823 823
 					if ($globalDebug) echo 'Add source stats : ';
824
-				        foreach($this->stats as $date => $data) {
825
-					    foreach($data as $source => $sourced) {
826
-					        //print_r($sourced);
827
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
828
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
829
-				    		if (isset($sourced['msg'])) {
830
-				    		    if (time() - $sourced['msg']['date'] > 10) {
831
-				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
832
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
833
-			    			        unset($this->stats[$date][$source]['msg']);
834
-			    			    }
835
-			    			}
836
-			    		    }
837
-			    		    if ($date != date('Y-m-d')) {
838
-			    			unset($this->stats[$date]);
839
-			    		    }
840
-				    	}
841
-				    	if ($globalDebug) echo 'Done'."\n";
824
+						foreach($this->stats as $date => $data) {
825
+						foreach($data as $source => $sourced) {
826
+							//print_r($sourced);
827
+								if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
828
+								if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
829
+							if (isset($sourced['msg'])) {
830
+								if (time() - $sourced['msg']['date'] > 10) {
831
+									$nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
832
+									echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
833
+									unset($this->stats[$date][$source]['msg']);
834
+								}
835
+							}
836
+							}
837
+							if ($date != date('Y-m-d')) {
838
+							unset($this->stats[$date]);
839
+							}
840
+						}
841
+						if ($globalDebug) echo 'Done'."\n";
842 842
 
843
-				    }
844
-				    $Stats->db = null;
845
-				    }
846
-				    $this->del();
843
+					}
844
+					$Stats->db = null;
845
+					}
846
+					$this->del();
847 847
 				} elseif ($globalDebug) echo 'Ignore data'."\n";
848 848
 				//$ignoreImport = false;
849 849
 				$this->all_flights[$id]['addedSpotter'] = 1;
@@ -861,41 +861,41 @@  discard block
 block discarded – undo
861 861
 			*/
862 862
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
863 863
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
864
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
865
-				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
866
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
864
+					if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
865
+					//SpotterLive->deleteLiveSpotterDataNotUpdated();
866
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
867 867
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
868
-					    $SpotterLive = new SpotterLive($this->db);
869
-					    $SpotterLive->deleteLiveSpotterData();
870
-					    $SpotterLive->db=null;
868
+						$SpotterLive = new SpotterLive($this->db);
869
+						$SpotterLive->deleteLiveSpotterData();
870
+						$SpotterLive->db=null;
871 871
 					}
872
-				    }
873
-				    if ($globalDebug) echo " Done\n";
874
-				    $this->last_delete = time();
872
+					}
873
+					if ($globalDebug) echo " Done\n";
874
+					$this->last_delete = time();
875 875
 				}
876
-			    } else {
876
+				} else {
877 877
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt'|| $line['format_source'] === 'planeupdatefaa'  || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'famaprs' || $line['format_source'] === 'airwhere')) {
878
-				    $this->all_flights[$id]['id'] = $recent_ident;
879
-				    $this->all_flights[$id]['addedSpotter'] = 1;
878
+					$this->all_flights[$id]['id'] = $recent_ident;
879
+					$this->all_flights[$id]['addedSpotter'] = 1;
880 880
 				}
881 881
 				if (isset($globalDaemon) && !$globalDaemon) {
882
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
882
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
883 883
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
884
-					    $Spotter = new Spotter($this->db);
885
-					    $Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']);
886
-					    $Spotter->db = null;
884
+						$Spotter = new Spotter($this->db);
885
+						$Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']);
886
+						$Spotter->db = null;
887
+					}
887 888
 					}
888
-				    }
889 889
 				}
890 890
 				
891
-			    }
891
+				}
892 892
 			}
893
-		    }
894
-		    //adds the spotter LIVE data
895
-		    //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
896
-		    //echo "\nAdd in Live !! \n";
897
-		    //echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n";
898
-		    if ($globalDebug) {
893
+			}
894
+			//adds the spotter LIVE data
895
+			//SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
896
+			//echo "\nAdd in Live !! \n";
897
+			//echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n";
898
+			if ($globalDebug) {
899 899
 			if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
900 900
 				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";
901 901
 				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
@@ -903,60 +903,60 @@  discard block
 block discarded – undo
903 903
 				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";
904 904
 				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";
905 905
 			}
906
-		    }
907
-		    $ignoreImport = false;
908
-		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
909
-		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
906
+			}
907
+			$ignoreImport = false;
908
+			if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
909
+			if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
910 910
 
911
-		    foreach($globalAirportIgnore as $airportIgnore) {
912
-		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
913
-			    $ignoreImport = true;
911
+			foreach($globalAirportIgnore as $airportIgnore) {
912
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
913
+				$ignoreImport = true;
914
+			}
914 915
 			}
915
-		    }
916
-		    if (count($globalAirportAccept) > 0) {
917
-		        $ignoreImport = true;
918
-		        foreach($globalAirportIgnore as $airportIgnore) {
919
-			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
916
+			if (count($globalAirportAccept) > 0) {
917
+				$ignoreImport = true;
918
+				foreach($globalAirportIgnore as $airportIgnore) {
919
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
920 920
 				$ignoreImport = false;
921
-			    }
921
+				}
922 922
 			}
923
-		    }
924
-		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
923
+			}
924
+			if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
925 925
 			foreach($globalAirlineIgnore as $airlineIgnore) {
926
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
926
+				if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
927 927
 				$ignoreImport = true;
928
-			    }
928
+				}
929 929
 			}
930
-		    }
931
-		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
930
+			}
931
+			if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
932 932
 			$ignoreImport = true;
933 933
 			foreach($globalAirlineAccept as $airlineAccept) {
934
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
934
+				if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
935 935
 				$ignoreImport = false;
936
-			    }
936
+				}
937
+			}
937 938
 			}
938
-		    }
939
-		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
939
+			if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
940 940
 			$ignoreImport = true;
941 941
 			foreach($globalPilotIdAccept as $pilotIdAccept) {
942
-			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
943
-			        $ignoreImport = false;
944
-			    }
942
+				if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
943
+					$ignoreImport = false;
944
+				}
945
+			}
945 946
 			}
946
-		    }
947 947
 
948
-		    if (!$ignoreImport) {
948
+			if (!$ignoreImport) {
949 949
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
950 950
 				if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
951 951
 				$timeelapsed = microtime(true);
952 952
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
953
-				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
953
+					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
954 954
 					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
955 955
 					$SpotterLive = new SpotterLive($this->db);
956 956
 					$result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
957 957
 					$SpotterLive->db = null;
958 958
 					if ($globalDebug) echo $result."\n";
959
-				    }
959
+					}
960 960
 				}
961 961
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) {
962 962
 					$APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
@@ -968,7 +968,7 @@  discard block
 block discarded – undo
968 968
 				//if ($line['format_source'] != 'aprs') {
969 969
 				//if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt')) {
970 970
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
971
-				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
971
+					if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
972 972
 					$source = $this->all_flights[$id]['source_name'];
973 973
 					if ($source == '') $source = $this->all_flights[$id]['format_source'];
974 974
 					if (!isset($this->source_location[$source])) {
@@ -994,7 +994,7 @@  discard block
 block discarded – undo
994 994
 					if ($stats_heading == 16) $stats_heading = 0;
995 995
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
996 996
 						for ($i=0;$i<=15;$i++) {
997
-						    $this->stats[$current_date][$source]['polar'][$i] = 0;
997
+							$this->stats[$current_date][$source]['polar'][$i] = 0;
998 998
 						}
999 999
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
1000 1000
 					} else {
@@ -1007,17 +1007,17 @@  discard block
 block discarded – undo
1007 1007
 					//var_dump($this->stats);
1008 1008
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
1009 1009
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
1010
-						    end($this->stats[$current_date][$source]['hist']);
1011
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
1010
+							end($this->stats[$current_date][$source]['hist']);
1011
+							$mini = key($this->stats[$current_date][$source]['hist'])+10;
1012 1012
 						} else $mini = 0;
1013 1013
 						for ($i=$mini;$i<=$distance;$i+=10) {
1014
-						    $this->stats[$current_date][$source]['hist'][$i] = 0;
1014
+							$this->stats[$current_date][$source]['hist'][$i] = 0;
1015 1015
 						}
1016 1016
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
1017 1017
 					} else {
1018 1018
 						$this->stats[$current_date][$source]['hist'][$distance] += 1;
1019 1019
 					}
1020
-				    }
1020
+					}
1021 1021
 				}
1022 1022
 
1023 1023
 				$this->all_flights[$id]['lastupdate'] = time();
@@ -1027,7 +1027,7 @@  discard block
 block discarded – undo
1027 1027
 			//$this->del();
1028 1028
 			
1029 1029
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
1030
-			    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
1030
+				if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
1031 1031
 				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1032 1032
 				$SpotterLive = new SpotterLive($this->db);
1033 1033
 				$SpotterLive->deleteLiveSpotterDataNotUpdated();
@@ -1035,19 +1035,19 @@  discard block
 block discarded – undo
1035 1035
 				//SpotterLive->deleteLiveSpotterData();
1036 1036
 				if ($globalDebug) echo " Done\n";
1037 1037
 				$this->last_delete_hourly = time();
1038
-			    } else {
1038
+				} else {
1039 1039
 				$this->del();
1040 1040
 				$this->last_delete_hourly = time();
1041
-			    }
1041
+				}
1042 1042
 			}
1043 1043
 			
1044
-		    }
1045
-		    //$ignoreImport = false;
1044
+			}
1045
+			//$ignoreImport = false;
1046 1046
 		}
1047 1047
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
1048 1048
 		if ($send) return $this->all_flights[$id];
1049
-	    }
1049
+		}
1050
+	}
1050 1051
 	}
1051
-    }
1052 1052
 }
1053 1053
 ?>
Please login to merge, or discard this patch.
Spacing   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -33,12 +33,12 @@  discard block
 block discarded – undo
33 33
 		$currentdate = date('Y-m-d');
34 34
 		$sourcestat = $Stats->getStatsSource($currentdate);
35 35
 		if (!empty($sourcestat)) {
36
-		    foreach($sourcestat as $srcst) {
36
+		    foreach ($sourcestat as $srcst) {
37 37
 		    	$type = $srcst['stats_type'];
38 38
 			if ($type == 'polar' || $type == 'hist') {
39 39
 			    $source = $srcst['source_name'];
40 40
 			    $data = $srcst['source_data'];
41
-			    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
41
+			    $this->stats[$currentdate][$source][$type] = json_decode($data, true);
42 42
 	    		}
43 43
 		    }
44 44
 		}
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 
51 51
     }
52 52
 
53
-    public function get_Schedule($id,$ident) {
53
+    public function get_Schedule($id, $ident) {
54 54
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
55 55
 	// Get schedule here, so it's done only one time
56 56
 	
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
 		$schedule = $Schedule->fetchSchedule($operator);
76 76
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
77 77
 		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
78
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
79
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
78
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $schedule['DepartureTime']));
79
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $schedule['ArrivalTime']));
80 80
 		    // Should also check if route schedule = route from DB
81 81
 		    if ($schedule['DepartureAirportIATA'] != '') {
82 82
 			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 			    }
97 97
 			}
98 98
 		    }
99
-		    $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
99
+		    $Schedule->addSchedule($operator, $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['arrival_airport_time'], $schedule['Source']);
100 100
 		}
101 101
 	    } else $scheduleexist = true;
102 102
 	} else $scheduleexist = true;
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
        if ($scheduleexist) {
105 105
 		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
106 106
     		$sch = $Schedule->getSchedule($operator);
107
-		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time']));
107
+		$this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport' => $sch['arrival_airport_icao'], 'departure_airport' => $sch['departure_airport_icao'], 'departure_airport_time' => $sch['departure_airport_time'], 'arrival_airport_time' => $sch['arrival_airport_time']));
108 108
        }
109 109
 	$Spotter->db = null;
110 110
 	$Schedule->db = null;
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 		    //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
132 132
     		    $Spotter = new Spotter($this->db);
133 133
         	    $real_arrival = $this->arrival($key);
134
-        	    if (isset($this->all_flights[$key]['altitude'])) $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
134
+        	    if (isset($this->all_flights[$key]['altitude'])) $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'], $this->all_flights[$key]['ident'], $this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $this->all_flights[$key]['altitude'], $this->all_flights[$key]['ground'], $this->all_flights[$key]['speed'], $this->all_flights[$key]['datetime'], $real_arrival['airport_icao'], $real_arrival['airport_time']);
135 135
         	}
136 136
 	    }
137 137
 	}
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
         $airport_time = '';
146 146
         if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
147 147
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
148
-	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
148
+	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $globalClosestMinDist);
149 149
     	    if (isset($closestAirports[0])) {
150 150
         	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
151 151
         	    $airport_icao = $closestAirports[0]['icao'];
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
         		    break;
161 161
         		}
162 162
         	    }
163
-        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
163
+        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude'] + 5000))) {
164 164
         		$airport_icao = $closestAirports[0]['icao'];
165 165
         		$airport_time = $this->all_flights[$key]['datetime'];
166 166
         	} else {
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
         } else {
174 174
         	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
175 175
         }
176
-        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
176
+        return array('airport_icao' => $airport_icao, 'airport_time' => $airport_time);
177 177
     }
178 178
 
179 179
 
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
185 185
 	foreach ($this->all_flights as $key => $flight) {
186 186
 	    if (isset($flight['lastupdate'])) {
187
-		if ($flight['lastupdate'] < (time()-5900)) {
187
+		if ($flight['lastupdate'] < (time() - 5900)) {
188 188
 		    $this->delKey($key);
189 189
 		}
190 190
 	    }
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 			$real_arrival = $this->arrival($key);
201 201
 			$Spotter = new Spotter($this->db);
202 202
 			if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
203
-				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
203
+				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'], $this->all_flights[$key]['ident'], $this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $this->all_flights[$key]['altitude'], $this->all_flights[$key]['ground'], $this->all_flights[$key]['speed'], $this->all_flights[$key]['datetime'], $real_arrival['airport_icao'], $real_arrival['airport_time']);
204 204
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
205 205
 			}
206 206
 		}
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 	$send = false;
234 234
 	
235 235
 	// SBS format is CSV format
236
-	if(is_array($line) && (isset($line['hex']) || isset($line['id']))) {
236
+	if (is_array($line) && (isset($line['hex']) || isset($line['id']))) {
237 237
 	    //print_r($line);
238 238
 	    if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']);
239 239
   	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
@@ -269,25 +269,25 @@  discard block
 block discarded – undo
269 269
 		if (!isset($this->all_flights[$id])) {
270 270
 		    if ($globalDebug) echo 'New flight...'."\n";
271 271
 		    $this->all_flights[$id] = array();
272
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
273
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '','altitude_previous' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
274
-		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
272
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
273
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => '', 'departure_airport' => '', 'arrival_airport' => '', 'latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '', 'altitude_real' => '', 'altitude_previous' => '', 'heading' => '', 'departure_airport_time' => '', 'arrival_airport_time' => '', 'squawk' => '', 'route_stop' => '', 'registration' => '', 'pilot_id' => '', 'pilot_name' => '', 'waypoints' => '', 'ground' => '0', 'format_source' => '', 'source_name' => '', 'over_country' => '', 'verticalrate' => '', 'noarchive' => false, 'putinarchive' => true, 'source_type' => ''));
274
+		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('lastupdate' => time()));
275 275
 		    if (!isset($line['id'])) {
276 276
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
277 277
 //			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
278 278
 //			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
279
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
279
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $id.'-'.date('YmdHi')));
280 280
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
281
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
281
+		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
282 282
 		    if ($globalAllFlights !== FALSE) $dataFound = true;
283 283
 		}
284 284
 		if (isset($line['source_type']) && $line['source_type'] != '') {
285
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
285
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('source_type' => $line['source_type']));
286 286
 		}
287 287
 		
288 288
 		//print_r($this->all_flights);
289 289
 		if (isset($line['hex']) && !isset($this->all_flights[$id]['hex']) && ctype_xdigit($line['hex'])) {
290
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
290
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('hex' => trim($line['hex'])));
291 291
 		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
292 292
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
293 293
 		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
@@ -296,27 +296,27 @@  discard block
 block discarded – undo
296 296
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
297 297
 			    $Spotter = new Spotter($this->db);
298 298
 			    if (isset($this->all_flights[$id]['source_type'])) {
299
-				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']),$this->all_flights[$id]['source_type']);
299
+				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']), $this->all_flights[$id]['source_type']);
300 300
 			    } else {
301 301
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
302 302
 			    }
303 303
 			    $Spotter->db = null;
304
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
305
-			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
304
+			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
305
+			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
306 306
 			}
307 307
 		    }
308 308
 		    if ($globalAllFlights !== FALSE) $dataFound = true;
309 309
 		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
310 310
 		}
311 311
 	        if (isset($line['id']) && !isset($line['hex'])) {
312
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
312
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('hex' => ''));
313 313
 	        }
314 314
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
315 315
 			$icao = $line['aircraft_icao'];
316 316
 			$Spotter = new Spotter($this->db);
317 317
 			if (isset($Spotter->aircraft_correct_icaotype[$icao])) $icao = $Spotter->aircraft_correct_icaotype[$icao];
318 318
 			$Spotter->db = null;
319
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $icao));
319
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $icao));
320 320
 		}
321 321
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_name'])) {
322 322
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 				$Spotter = new Spotter($this->db);
325 325
 				$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
326 326
 				$Spotter->db = null;
327
-				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
327
+				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
328 328
 			}
329 329
 		}
330 330
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) {
@@ -332,15 +332,15 @@  discard block
 block discarded – undo
332 332
 			elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
333 333
 			elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
334 334
 			elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
335
-			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
335
+			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
336 336
 		}
337 337
 		if (!isset($this->all_flights[$id]['aircraft_icao'])) {
338
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
338
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => 'NA'));
339 339
 		}
340 340
 		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
341
-		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60 && strtotime($line['datetime']) < time()+20*60) {
341
+		if (isset($line['datetime']) && strtotime($line['datetime']) > time() - 20*60 && strtotime($line['datetime']) < time() + 20*60) {
342 342
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
343
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
343
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => $line['datetime']));
344 344
 		    } else {
345 345
 				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
346 346
 				elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
@@ -351,32 +351,32 @@  discard block
 block discarded – undo
351 351
 				*/
352 352
 				return '';
353 353
 		    }
354
-		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) {
354
+		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time() - 20*60) {
355 355
 			if ($globalDebug) echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n";
356 356
 			return '';
357
-		} elseif (isset($line['datetime']) && strtotime($line['datetime']) > time()+20*60) {
357
+		} elseif (isset($line['datetime']) && strtotime($line['datetime']) > time() + 20*60) {
358 358
 			if ($globalDebug) echo "!!! Date is in the future ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n
359 359
 			";
360 360
 			return '';
361 361
 		} elseif (!isset($line['datetime'])) {
362 362
 			date_default_timezone_set('UTC');
363
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
363
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => date('Y-m-d H:i:s')));
364 364
 		} else {
365 365
 			if ($globalDebug) echo "!!! Unknow date error ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!";
366 366
 			return '';
367 367
 		}
368 368
 
369 369
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') {
370
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
370
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('registration' => $line['registration']));
371 371
 		}
372 372
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
373
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
373
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('waypoints' => $line['waypoints']));
374 374
 		}
375 375
 		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
376
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => trim($line['pilot_id'])));
376
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_id' => trim($line['pilot_id'])));
377 377
 		}
378 378
 		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
379
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => trim($line['pilot_name'])));
379
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_name' => trim($line['pilot_name'])));
380 380
 		}
381 381
  
382 382
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) {
@@ -384,13 +384,13 @@  discard block
 block discarded – undo
384 384
 		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
385 385
 			if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
386 386
 				if ($globalDebug) echo '---!!!! New ident, reset aircraft data...'."\n";
387
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
388
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
389
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
390
-				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
391
-				elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
387
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
388
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1));
389
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $id.'-'.date('YmdHi')));
390
+				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
391
+				elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
392 392
 			} else {
393
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
393
+			    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => trim($line['ident'])));
394 394
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
395 395
 				$timeelapsed = microtime(true);
396 396
             			$Spotter = new Spotter($this->db);
@@ -400,13 +400,13 @@  discard block
 block discarded – undo
400 400
 				elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
401 401
 				elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
402 402
 				elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
403
-            			$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
403
+            			$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $fromsource);
404 404
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
405 405
 				$Spotter->db = null;
406
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
406
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
407 407
 			    }
408 408
 			}
409
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
409
+		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => trim($line['ident'])));
410 410
 		    
411 411
 /*
412 412
 		    if (!isset($line['id'])) {
@@ -416,25 +416,25 @@  discard block
 block discarded – undo
416 416
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
417 417
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
418 418
   */
419
-		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
419
+		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
420 420
 
421 421
 		    //$putinarchive = true;
422 422
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
423
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
423
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $line['departure_airport_time']));
424 424
 		    }
425 425
 		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
426
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
426
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $line['arrival_airport_time']));
427 427
 		    }
428 428
 		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
429
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
429
+		    		$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport' => $line['departure_airport_icao'], 'arrival_airport' => $line['arrival_airport_icao'], 'route_stop' => ''));
430 430
 		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
431 431
 			$timeelapsed = microtime(true);
432 432
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
433 433
 				$Spotter = new Spotter($this->db);
434 434
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
435 435
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
436
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
437
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
436
+		    		$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport' => $line['departure_airport_icao'], 'arrival_airport' => $line['arrival_airport_icao'], 'route_stop' => ''));
437
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
438 438
                         }
439 439
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
440 440
 			$timeelapsed = microtime(true);
@@ -448,35 +448,35 @@  discard block
 block discarded – undo
448 448
 				$Translation->db = null;
449 449
 			    }
450 450
 			    $Spotter->db = null;
451
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
451
+			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
452 452
                     	}
453 453
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
454 454
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
455 455
 			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
456 456
 				//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['FromAirport_ICAO'],'arrival_airport' => $route['ToAirport_ICAO'],'route_stop' => $route['RouteStop']));
457
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
457
+		    		$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport' => $route['fromairport_icao'], 'arrival_airport' => $route['toairport_icao'], 'route_stop' => $route['routestop']));
458 458
 		    	    }
459 459
 			}
460 460
 			if (!isset($globalFork)) $globalFork = TRUE;
461 461
 			if (!$globalVA && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
462
-				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
462
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id, trim($line['ident']));
463 463
 			}
464 464
 		    }
465 465
 		}
466 466
 
467 467
 		if (isset($line['speed']) && $line['speed'] != '' && $line['speed'] != 0) {
468 468
 		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
469
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
470
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
469
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($line['speed'])));
470
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed_fromsrc' => true));
471 471
 		    //$dataFound = true;
472 472
 		} else if (!isset($this->all_flights[$id]['speed_fromsrc']) && isset($this->all_flights[$id]['time_last_coord']) && $this->all_flights[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
473
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
473
+		    $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm');
474 474
 		    if ($distance > 1000 && $distance < 10000) {
475 475
 		    // use datetime
476 476
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
477 477
 			$speed = $speed*3.6;
478 478
 			if ($speed < 1000) {
479
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
479
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($speed)));
480 480
 	  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
481 481
 	  		} else {
482 482
 	  			if ($globalDebug) echo "ø IGNORED : Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
@@ -491,9 +491,9 @@  discard block
 block discarded – undo
491 491
 	    	    	if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
492 492
 	    	    	return false;
493 493
 	    	    }
494
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
494
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time() - $this->all_flights[$id]['time_last_coord']);
495 495
 	    	    else unset($timediff);
496
-	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
496
+	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time() - $this->all_flights[$id]['time_last_archive_coord']);
497 497
 	    	    else unset($timediff_archive);
498 498
 	    	    if ($this->tmd > 5
499 499
 	    	        || (isset($line['format_source']) 
@@ -517,14 +517,14 @@  discard block
 block discarded – undo
517 517
 	    	    	|| ($timediff > 30 
518 518
 	    	    	    && isset($this->all_flights[$id]['latitude']) 
519 519
 	    	    	    && isset($this->all_flights[$id]['longitude']) 
520
-	    	    	    && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'))
520
+	    	    	    && $Common->withinThreshold($timediff, $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm'))
521 521
 	    	    	    )
522 522
 	    	    	) {
523 523
 
524 524
 			if ((isset($timediff) && !isset($timediff_archive)) || (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude']))) {
525 525
 			    if ((isset($timediff_archive) && $timediff_archive > $globalAircraftMaxUpdate)
526 526
 				|| (isset($line['format_source']) && $line['format_source'] == 'airwhere') 
527
-				|| !$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
527
+				|| !$Common->checkLine($this->all_flights[$id]['archive_latitude'], $this->all_flights[$id]['archive_longitude'], $this->all_flights[$id]['livedb_latitude'], $this->all_flights[$id]['livedb_longitude'], $line['latitude'], $line['longitude'])) {
528 528
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
529 529
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
530 530
 				$this->all_flights[$id]['putinarchive'] = true;
@@ -534,11 +534,11 @@  discard block
 block discarded – undo
534 534
 				    $timeelapsed = microtime(true);
535 535
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
536 536
 					$Spotter = new Spotter($this->db);
537
-					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
537
+					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']);
538 538
 					if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
539 539
 					else $this->all_flights[$id]['over_country'] = '';
540 540
 					$Spotter->db = null;
541
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
541
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
542 542
 					if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
543 543
 				    }
544 544
 				}
@@ -564,13 +564,13 @@  discard block
 block discarded – undo
564 564
 					$this->all_flights[$id]['time_last_coord'] = time();
565 565
 				}
566 566
 				//if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs' || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > 0.0001)) {
567
-				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > 0.0001)) {
567
+				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude'] - $line['latitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude'] - $line['latitude']) > 0.0001)) {
568 568
 				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
569 569
 				    $dataFound = true;
570 570
 				    $this->all_flights[$id]['time_last_coord'] = time();
571 571
 				}
572 572
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
573
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
573
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('latitude' => $line['latitude']));
574 574
 				/*
575 575
 				if (abs($this->all_flights[$id]['archive_latitude']-$this->all_flights[$id]['latitude']) > 0.3) {
576 576
 				    $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
@@ -592,13 +592,13 @@  discard block
 block discarded – undo
592 592
 					$this->all_flights[$id]['time_last_coord'] = time();
593 593
 				}
594 594
 				//if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs' || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > 0.0001)) {
595
-				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > 0.0001)) {
595
+				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude'] - $line['longitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude'] - $line['longitude']) > 0.0001)) {
596 596
 				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
597 597
 				    $dataFound = true;
598 598
 				    $this->all_flights[$id]['time_last_coord'] = time();
599 599
 				}
600 600
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
601
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
601
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('longitude' => $line['longitude']));
602 602
 				/*
603 603
 				if (abs($this->all_flights[$id]['archive_longitude']-$this->all_flights[$id]['longitude']) > 0.3) {
604 604
 				    $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
@@ -616,46 +616,46 @@  discard block
 block discarded – undo
616 616
 		    } else if ($globalDebug && $timediff > 30) {
617 617
 			$this->tmd = $this->tmd + 1;
618 618
 			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
619
-			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
620
-			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
619
+			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')."m -";
620
+			echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - ";
621 621
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
622 622
 		    }
623 623
 		}
624 624
 		if (isset($line['last_update']) && $line['last_update'] != '') {
625 625
 		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
626
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
626
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('last_update' => $line['last_update']));
627 627
 		}
628 628
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
629
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
629
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('verticalrate' => $line['verticalrate']));
630 630
 		    //$dataFound = true;
631 631
 		}
632 632
 		if (isset($line['format_source']) && $line['format_source'] != '') {
633
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
633
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('format_source' => $line['format_source']));
634 634
 		}
635 635
 		if (isset($line['source_name']) && $line['source_name'] != '') {
636
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
636
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('source_name' => $line['source_name']));
637 637
 		}
638 638
 		if (isset($line['emergency']) && $line['emergency'] != '') {
639
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
639
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('emergency' => $line['emergency']));
640 640
 		    //$dataFound = true;
641 641
 		}
642 642
 		if (isset($line['ground']) && $line['ground'] != '') {
643 643
 		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
644 644
 			// Here we force archive of flight because after ground it's a new one (or should be)
645
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
646
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
647
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
648
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
649
-			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
645
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
646
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1));
647
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $id.'-'.date('YmdHi')));
648
+		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
649
+			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
650 650
 		    }
651 651
 		    if ($line['ground'] != 1) $line['ground'] = 0;
652
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
652
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ground' => $line['ground']));
653 653
 		    //$dataFound = true;
654 654
 		}
655 655
 		if (isset($line['squawk']) && $line['squawk'] != '') {
656 656
 		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
657 657
 			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
658
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
658
+			    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk']));
659 659
 			    $highlight = '';
660 660
 			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
661 661
 			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
@@ -664,59 +664,59 @@  discard block
 block discarded – undo
664 664
 				$timeelapsed = microtime(true);
665 665
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
666 666
 				    $Spotter = new Spotter($this->db);
667
-				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
667
+				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'], $highlight);
668 668
 				    $Spotter->db = null;
669
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
669
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
670 670
 				}
671 671
 				//$putinarchive = true;
672 672
 				//$highlight = '';
673 673
 			    }
674 674
 			    
675
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
675
+		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk']));
676 676
 		    //$dataFound = true;
677 677
 		}
678 678
 
679 679
 		if (isset($line['altitude']) && $line['altitude'] != '') {
680 680
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
681
-			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
682
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
683
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
681
+			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100) - $this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
682
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude' => round($line['altitude']/100)));
683
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude_real' => $line['altitude']));
684 684
 			//$dataFound = true;
685 685
 		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
686 686
 		    if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
687 687
 			if (isset($this->all_flights[$id]['over_country']) && $this->all_flights[$id]['over_country'] != '' && isset($this->all_flights[$id]['altitude_previous']) && $this->all_flights[$id]['altitude_previous'] != '' && $this->all_flights[$id]['altitude_previous'] < $this->all_flights[$id]['altitude_real'] && isset($this->all_flights[$id]['lastupdate']) && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
688 688
 				if ($globalDebug) echo '--- Reset because of altitude'."\n";
689
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
690
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
691
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
692
-				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
693
-				elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
689
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
690
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1));
691
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $id.'-'.date('YmdHi')));
692
+				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
693
+				elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
694 694
 			}
695 695
 		    }
696
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
696
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude_previous' => $line['altitude']));
697 697
 		}
698 698
 
699 699
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
700
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
700
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('noarchive' => true));
701 701
 		}
702 702
 		
703 703
 		if (isset($line['heading']) && $line['heading'] != '') {
704
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
705
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
706
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
704
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading'] - round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
705
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($line['heading'])));
706
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading_fromsrc' => true));
707 707
 		    //$dataFound = true;
708 708
   		} elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) {
709
-  		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
710
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
711
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
709
+  		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'], $this->all_flights[$id]['archive_longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
710
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($heading)));
711
+		    if (abs($this->all_flights[$id]['heading'] - round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
712 712
   		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['id']." : ".$heading."\n";
713 713
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
714 714
   		    // If not enough messages and ACARS set heading to 0
715
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
715
+  		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => 0));
716 716
   		}
717
-		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
718
-		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
719
-		elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalMinupdate) $dataFound = false;
717
+		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
718
+		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
719
+		elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalMinupdate) $dataFound = false;
720 720
 
721 721
 //		print_r($this->all_flights[$id]);
722 722
 		//gets the callsign from the last hour
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
 		if ($dataFound === true && isset($this->all_flights[$id]['id'])) {
728 728
 		    $this->all_flights[$id]['lastupdate'] = time();
729 729
 		    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
730
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
730
+		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == '' || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
731 731
 			    //print_r($this->all_flights);
732 732
 			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
733 733
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
@@ -738,61 +738,61 @@  discard block
 block discarded – undo
738 738
 				    $SpotterLive = new SpotterLive($this->db);
739 739
 				    if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
740 740
 					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
741
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
741
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
742 742
 				    } elseif (isset($line['id'])) {
743 743
 					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
744
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
744
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
745 745
 				    } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
746 746
 					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
747
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
747
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
748 748
 				    } else $recent_ident = '';
749
-				    $SpotterLive->db=null;
749
+				    $SpotterLive->db = null;
750 750
 				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
751 751
 				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
752 752
 				} else $recent_ident = '';
753 753
 			    } else {
754 754
 				$recent_ident = '';
755
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
755
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 0));
756 756
 			    }
757 757
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
758
-			    if($recent_ident == "")
758
+			    if ($recent_ident == "")
759 759
 			    {
760 760
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
761 761
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
762 762
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
763 763
 				//adds the spotter data for the archive
764 764
 				$ignoreImport = false;
765
-				foreach($globalAirportIgnore as $airportIgnore) {
765
+				foreach ($globalAirportIgnore as $airportIgnore) {
766 766
 				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
767 767
 					$ignoreImport = true;
768 768
 				    }
769 769
 				}
770 770
 				if (count($globalAirportAccept) > 0) {
771 771
 				    $ignoreImport = true;
772
-				    foreach($globalAirportIgnore as $airportIgnore) {
772
+				    foreach ($globalAirportIgnore as $airportIgnore) {
773 773
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
774 774
 					    $ignoreImport = false;
775 775
 					}
776 776
 				    }
777 777
 				}
778 778
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
779
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
780
-					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
779
+				    foreach ($globalAirlineIgnore as $airlineIgnore) {
780
+					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineIgnore)) {
781 781
 					    $ignoreImport = true;
782 782
 					}
783 783
 				    }
784 784
 				}
785 785
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
786 786
 				    $ignoreImport = true;
787
-				    foreach($globalAirlineAccept as $airlineAccept) {
788
-					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
787
+				    foreach ($globalAirlineAccept as $airlineAccept) {
788
+					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineAccept)) {
789 789
 					    $ignoreImport = false;
790 790
 					}
791 791
 				    }
792 792
 				}
793 793
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
794 794
 				    $ignoreImport = true;
795
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
795
+				    foreach ($globalPilotIdAccept as $pilotIdAccept) {
796 796
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
797 797
 					    $ignoreImport = false;
798 798
 					}
@@ -804,32 +804,32 @@  discard block
 block discarded – undo
804 804
 				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
805 805
 				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
806 806
 				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
807
-				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
807
+				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
808 808
 				    $timeelapsed = microtime(true);
809 809
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
810 810
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
811 811
 					    $Spotter = new Spotter($this->db);
812
-					    $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']);
812
+					    $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'], $this->all_flights[$id]['route_stop'], $highlight, $this->all_flights[$id]['hex'], $this->all_flights[$id]['registration'], $this->all_flights[$id]['pilot_id'], $this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['format_source'], $this->all_flights[$id]['source_name'], $this->all_flights[$id]['source_type']);
813 813
 					    $Spotter->db = null;
814 814
 					    if ($globalDebug && isset($result)) echo $result."\n";
815 815
 					}
816 816
 				    }
817
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
817
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
818 818
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
819 819
 
820 820
 				    // Add source stat in DB
821 821
 				    $Stats = new Stats($this->db);
822 822
 				    if (!empty($this->stats)) {
823 823
 					if ($globalDebug) echo 'Add source stats : ';
824
-				        foreach($this->stats as $date => $data) {
825
-					    foreach($data as $source => $sourced) {
824
+				        foreach ($this->stats as $date => $data) {
825
+					    foreach ($data as $source => $sourced) {
826 826
 					        //print_r($sourced);
827
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
828
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
827
+				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']), $source, 'polar', $date);
828
+				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']), $source, 'hist', $date);
829 829
 				    		if (isset($sourced['msg'])) {
830 830
 				    		    if (time() - $sourced['msg']['date'] > 10) {
831 831
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
832
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
832
+				    		        echo $Stats->addStatSource($nbmsg, $source, 'msg', $date);
833 833
 			    			        unset($this->stats[$date][$source]['msg']);
834 834
 			    			    }
835 835
 			    			}
@@ -867,14 +867,14 @@  discard block
 block discarded – undo
867 867
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
868 868
 					    $SpotterLive = new SpotterLive($this->db);
869 869
 					    $SpotterLive->deleteLiveSpotterData();
870
-					    $SpotterLive->db=null;
870
+					    $SpotterLive->db = null;
871 871
 					}
872 872
 				    }
873 873
 				    if ($globalDebug) echo " Done\n";
874 874
 				    $this->last_delete = time();
875 875
 				}
876 876
 			    } else {
877
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt'|| $line['format_source'] === 'planeupdatefaa'  || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'famaprs' || $line['format_source'] === 'airwhere')) {
877
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'famaprs' || $line['format_source'] === 'airwhere')) {
878 878
 				    $this->all_flights[$id]['id'] = $recent_ident;
879 879
 				    $this->all_flights[$id]['addedSpotter'] = 1;
880 880
 				}
@@ -882,7 +882,7 @@  discard block
 block discarded – undo
882 882
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
883 883
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
884 884
 					    $Spotter = new Spotter($this->db);
885
-					    $Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']);
885
+					    $Spotter->updateLatestSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['arrival_airport_time']);
886 886
 					    $Spotter->db = null;
887 887
 					}
888 888
 				    }
@@ -908,37 +908,37 @@  discard block
 block discarded – undo
908 908
 		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
909 909
 		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
910 910
 
911
-		    foreach($globalAirportIgnore as $airportIgnore) {
911
+		    foreach ($globalAirportIgnore as $airportIgnore) {
912 912
 		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
913 913
 			    $ignoreImport = true;
914 914
 			}
915 915
 		    }
916 916
 		    if (count($globalAirportAccept) > 0) {
917 917
 		        $ignoreImport = true;
918
-		        foreach($globalAirportIgnore as $airportIgnore) {
918
+		        foreach ($globalAirportIgnore as $airportIgnore) {
919 919
 			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
920 920
 				$ignoreImport = false;
921 921
 			    }
922 922
 			}
923 923
 		    }
924 924
 		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
925
-			foreach($globalAirlineIgnore as $airlineIgnore) {
926
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
925
+			foreach ($globalAirlineIgnore as $airlineIgnore) {
926
+			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineIgnore)) {
927 927
 				$ignoreImport = true;
928 928
 			    }
929 929
 			}
930 930
 		    }
931 931
 		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
932 932
 			$ignoreImport = true;
933
-			foreach($globalAirlineAccept as $airlineAccept) {
934
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
933
+			foreach ($globalAirlineAccept as $airlineAccept) {
934
+			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineAccept)) {
935 935
 				$ignoreImport = false;
936 936
 			    }
937 937
 			}
938 938
 		    }
939 939
 		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
940 940
 			$ignoreImport = true;
941
-			foreach($globalPilotIdAccept as $pilotIdAccept) {
941
+			foreach ($globalPilotIdAccept as $pilotIdAccept) {
942 942
 			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
943 943
 			        $ignoreImport = false;
944 944
 			    }
@@ -946,23 +946,23 @@  discard block
 block discarded – undo
946 946
 		    }
947 947
 
948 948
 		    if (!$ignoreImport) {
949
-			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
950
-				if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
949
+			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
950
+				if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
951 951
 				$timeelapsed = microtime(true);
952 952
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
953 953
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
954 954
 					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
955 955
 					$SpotterLive = new SpotterLive($this->db);
956
-					$result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
956
+					$result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'], $this->all_flights[$id]['route_stop'], $this->all_flights[$id]['hex'], $this->all_flights[$id]['putinarchive'], $this->all_flights[$id]['registration'], $this->all_flights[$id]['pilot_id'], $this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['format_source'], $this->all_flights[$id]['source_name'], $this->all_flights[$id]['over_country']);
957 957
 					$SpotterLive->db = null;
958 958
 					if ($globalDebug) echo $result."\n";
959 959
 				    }
960 960
 				}
961 961
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) {
962
-					$APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
962
+					$APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'], $this->all_flights[$id]['route_stop'], $this->all_flights[$id]['hex'], $this->all_flights[$id]['putinarchive'], $this->all_flights[$id]['registration'], $this->all_flights[$id]['pilot_id'], $this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['format_source'], $this->all_flights[$id]['source_name'], $this->all_flights[$id]['over_country']);
963 963
 				}
964 964
 				$this->all_flights[$id]['putinarchive'] = false;
965
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
965
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
966 966
 
967 967
 				// Put statistics in $this->stats variable
968 968
 				//if ($line['format_source'] != 'aprs') {
@@ -981,19 +981,19 @@  discard block
 block discarded – undo
981 981
 							$latitude = $globalCenterLatitude;
982 982
 							$longitude = $globalCenterLongitude;
983 983
 						}
984
-						$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude);
984
+						$this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude);
985 985
 					} else {
986 986
 						$latitude = $this->source_location[$source]['latitude'];
987 987
 						$longitude = $this->source_location[$source]['longitude'];
988 988
 					}
989
-					$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
989
+					$stats_heading = $Common->getHeading($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
990 990
 					//$stats_heading = $stats_heading%22.5;
991 991
 					$stats_heading = round($stats_heading/22.5);
992
-					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
992
+					$stats_distance = $Common->distance($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
993 993
 					$current_date = date('Y-m-d');
994 994
 					if ($stats_heading == 16) $stats_heading = 0;
995 995
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
996
-						for ($i=0;$i<=15;$i++) {
996
+						for ($i = 0; $i <= 15; $i++) {
997 997
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
998 998
 						}
999 999
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
@@ -1008,9 +1008,9 @@  discard block
 block discarded – undo
1008 1008
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
1009 1009
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
1010 1010
 						    end($this->stats[$current_date][$source]['hist']);
1011
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
1011
+						    $mini = key($this->stats[$current_date][$source]['hist']) + 10;
1012 1012
 						} else $mini = 0;
1013
-						for ($i=$mini;$i<=$distance;$i+=10) {
1013
+						for ($i = $mini; $i <= $distance; $i += 10) {
1014 1014
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
1015 1015
 						}
1016 1016
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
@@ -1023,7 +1023,7 @@  discard block
 block discarded – undo
1023 1023
 				$this->all_flights[$id]['lastupdate'] = time();
1024 1024
 				if ($this->all_flights[$id]['putinarchive']) $send = true;
1025 1025
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1026
-			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1026
+			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude'])."\n";
1027 1027
 			//$this->del();
1028 1028
 			
1029 1029
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
Please login to merge, or discard this patch.
Braces   +398 added lines, -142 removed lines patch added patch discarded remove patch
@@ -63,7 +63,9 @@  discard block
 block discarded – undo
63 63
 	$dbc = $this->db;
64 64
 	$this->all_flights[$id]['schedule_check'] = true;
65 65
 	if ($globalSchedulesFetch) {
66
-	if ($globalDebug) echo 'Getting schedule info...'."\n";
66
+	if ($globalDebug) {
67
+		echo 'Getting schedule info...'."\n";
68
+	}
67 69
 	$Spotter = new Spotter($dbc);
68 70
 	$Schedule = new Schedule($dbc);
69 71
 	$Translation = new Translation($dbc);
@@ -74,7 +76,9 @@  discard block
 block discarded – undo
74 76
 	    if ($Schedule->checkSchedule($operator) == 0) {
75 77
 		$schedule = $Schedule->fetchSchedule($operator);
76 78
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
77
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
79
+		    if ($globalDebug) {
80
+		    	echo "-> Schedule info for ".$operator." (".$ident.")\n";
81
+		    }
78 82
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
79 83
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
80 84
 		    // Should also check if route schedule = route from DB
@@ -83,7 +87,9 @@  discard block
 block discarded – undo
83 87
 			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
84 88
 			    if (trim($airport_icao) != '') {
85 89
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
86
-				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
90
+				if ($globalDebug) {
91
+					echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
92
+				}
87 93
 			    }
88 94
 			}
89 95
 		    }
@@ -92,17 +98,25 @@  discard block
 block discarded – undo
92 98
 			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
93 99
 			    if (trim($airport_icao) != '') {
94 100
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
95
-				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
101
+				if ($globalDebug) {
102
+					echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
103
+				}
96 104
 			    }
97 105
 			}
98 106
 		    }
99 107
 		    $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
100 108
 		}
101
-	    } else $scheduleexist = true;
102
-	} else $scheduleexist = true;
109
+	    } else {
110
+	    	$scheduleexist = true;
111
+	    }
112
+	} else {
113
+		$scheduleexist = true;
114
+	}
103 115
 	// close connection, at least one way will work ?
104 116
        if ($scheduleexist) {
105
-		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
117
+		if ($globalDebug) {
118
+			echo "-> get arrival/departure airport info for ".$ident."\n";
119
+		}
106 120
     		$sch = $Schedule->getSchedule($operator);
107 121
 		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time']));
108 122
        }
@@ -124,14 +138,18 @@  discard block
 block discarded – undo
124 138
 
125 139
     public function checkAll() {
126 140
 	global $globalDebug, $globalNoImport;
127
-	if ($globalDebug) echo "Update last seen flights data...\n";
141
+	if ($globalDebug) {
142
+		echo "Update last seen flights data...\n";
143
+	}
128 144
 	if (!isset($globalNoImport) || $globalNoImport === FALSE) {
129 145
 	    foreach ($this->all_flights as $key => $flight) {
130 146
 		if (isset($this->all_flights[$key]['id'])) {
131 147
 		    //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
132 148
     		    $Spotter = new Spotter($this->db);
133 149
         	    $real_arrival = $this->arrival($key);
134
-        	    if (isset($this->all_flights[$key]['altitude'])) $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
150
+        	    if (isset($this->all_flights[$key]['altitude'])) {
151
+        	    	$Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
152
+        	    }
135 153
         	}
136 154
 	    }
137 155
 	}
@@ -139,24 +157,32 @@  discard block
 block discarded – undo
139 157
 
140 158
     public function arrival($key) {
141 159
 	global $globalClosestMinDist, $globalDebug;
142
-	if ($globalDebug) echo 'Update arrival...'."\n";
160
+	if ($globalDebug) {
161
+		echo 'Update arrival...'."\n";
162
+	}
143 163
 	$Spotter = new Spotter($this->db);
144 164
         $airport_icao = '';
145 165
         $airport_time = '';
146
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
166
+        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') {
167
+        	$globalClosestMinDist = 50;
168
+        }
147 169
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
148 170
 	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
149 171
     	    if (isset($closestAirports[0])) {
150 172
         	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
151 173
         	    $airport_icao = $closestAirports[0]['icao'];
152 174
         	    $airport_time = $this->all_flights[$key]['datetime'];
153
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
175
+        	    if ($globalDebug) {
176
+        	    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
177
+        	    }
154 178
         	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
155 179
         	    foreach ($closestAirports as $airport) {
156 180
         		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
157 181
         		    $airport_icao = $airport['icao'];
158 182
         		    $airport_time = $this->all_flights[$key]['datetime'];
159
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
183
+        		    if ($globalDebug) {
184
+        		    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
185
+        		    }
160 186
         		    break;
161 187
         		}
162 188
         	    }
@@ -164,14 +190,20 @@  discard block
 block discarded – undo
164 190
         		$airport_icao = $closestAirports[0]['icao'];
165 191
         		$airport_time = $this->all_flights[$key]['datetime'];
166 192
         	} else {
167
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
193
+        		if ($globalDebug) {
194
+        			echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
195
+        		}
168 196
         	}
169 197
     	    } else {
170
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
198
+    		    if ($globalDebug) {
199
+    		    	echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
200
+    		    }
171 201
     	    }
172 202
 
173 203
         } else {
174
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
204
+        	if ($globalDebug) {
205
+        		echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
206
+        	}
175 207
         }
176 208
         return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
177 209
     }
@@ -181,7 +213,9 @@  discard block
 block discarded – undo
181 213
     public function del() {
182 214
 	global $globalDebug, $globalNoImport, $globalNoDB;
183 215
 	// Delete old infos
184
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
216
+	if ($globalDebug) {
217
+		echo 'Delete old values and update latest data...'."\n";
218
+	}
185 219
 	foreach ($this->all_flights as $key => $flight) {
186 220
 	    if (isset($flight['lastupdate'])) {
187 221
 		if ($flight['lastupdate'] < (time()-5900)) {
@@ -195,13 +229,17 @@  discard block
 block discarded – undo
195 229
 	global $globalDebug, $globalNoImport, $globalNoDB;
196 230
 	// Delete old infos
197 231
 	if (isset($this->all_flights[$key]['id'])) {
198
-		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
232
+		if ($globalDebug) {
233
+			echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
234
+		}
199 235
 		if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
200 236
 			$real_arrival = $this->arrival($key);
201 237
 			$Spotter = new Spotter($this->db);
202 238
 			if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
203 239
 				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
204
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
240
+				if ($globalDebug && $result != 'success') {
241
+					echo '!!! ERROR : '.$result."\n";
242
+				}
205 243
 			}
206 244
 		}
207 245
 	}
@@ -211,9 +249,13 @@  discard block
 block discarded – undo
211 249
     public function add($line) {
212 250
 	global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights, $globalServerAPRS, $APRSSpotter, $globalNoImport, $globalNoDB, $globalVA, $globalAircraftMaxUpdate, $globalAircraftMinUpdate, $globalLiveInterval;
213 251
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
214
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
215
-	if (!isset($globalAircraftMaxUpdate) || $globalAircraftMaxUpdate == '') $globalAircraftMaxUpdate = 3000;
216
-/*
252
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
253
+		$globalCoordMinChange = '0.02';
254
+	}
255
+	if (!isset($globalAircraftMaxUpdate) || $globalAircraftMaxUpdate == '') {
256
+		$globalAircraftMaxUpdate = 3000;
257
+	}
258
+	/*
217 259
 	$Spotter = new Spotter();
218 260
 	$dbc = $Spotter->db;
219 261
 	$SpotterLive = new SpotterLive($dbc);
@@ -235,19 +277,28 @@  discard block
 block discarded – undo
235 277
 	// SBS format is CSV format
236 278
 	if(is_array($line) && (isset($line['hex']) || isset($line['id']))) {
237 279
 	    //print_r($line);
238
-	    if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']);
280
+	    if (isset($line['hex'])) {
281
+	    	$line['hex'] = strtoupper($line['hex']);
282
+	    }
239 283
   	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
240 284
 
241 285
 		// Increment message number
242 286
 		if (isset($line['sourcestats']) && $line['sourcestats'] === TRUE) {
243 287
 		    $current_date = date('Y-m-d');
244
-		    if (isset($line['source_name'])) $source = $line['source_name'];
245
-		    else $source = '';
246
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
288
+		    if (isset($line['source_name'])) {
289
+		    	$source = $line['source_name'];
290
+		    } else {
291
+		    	$source = '';
292
+		    }
293
+		    if ($source == '' || $line['format_source'] == 'aprs') {
294
+		    	$source = $line['format_source'];
295
+		    }
247 296
 		    if (!isset($this->stats[$current_date][$source]['msg'])) {
248 297
 		    	$this->stats[$current_date][$source]['msg']['date'] = time();
249 298
 		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
250
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
299
+		    } else {
300
+		    	$this->stats[$current_date][$source]['msg']['nb'] += 1;
301
+		    }
251 302
 		}
252 303
 		
253 304
 		/*
@@ -263,23 +314,38 @@  discard block
 block discarded – undo
263 314
 		//$this->db = $dbc;
264 315
 
265 316
 		//$hex = trim($line['hex']);
266
-	        if (!isset($line['id'])) $id = trim($line['hex']);
267
-	        else $id = trim($line['id']);
317
+	        if (!isset($line['id'])) {
318
+	        	$id = trim($line['hex']);
319
+	        } else {
320
+	        	$id = trim($line['id']);
321
+	        }
268 322
 		
269 323
 		if (!isset($this->all_flights[$id])) {
270
-		    if ($globalDebug) echo 'New flight...'."\n";
324
+		    if ($globalDebug) {
325
+		    	echo 'New flight...'."\n";
326
+		    }
271 327
 		    $this->all_flights[$id] = array();
272 328
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
273 329
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '','altitude_previous' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
274
-		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
330
+		    if (isset($globalDaemon) && $globalDaemon === FALSE) {
331
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
332
+		    }
275 333
 		    if (!isset($line['id'])) {
276
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
277
-//			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
334
+			if (!isset($globalDaemon)) {
335
+				$globalDaemon = TRUE;
336
+			}
337
+			//			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
278 338
 //			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
279
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
339
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
340
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
341
+			}
280 342
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
281
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
282
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
343
+		     } else {
344
+		     	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
345
+		     }
346
+		    if ($globalAllFlights !== FALSE) {
347
+		    	$dataFound = true;
348
+		    }
283 349
 		}
284 350
 		if (isset($line['source_type']) && $line['source_type'] != '') {
285 351
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
@@ -301,12 +367,20 @@  discard block
 block discarded – undo
301 367
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
302 368
 			    }
303 369
 			    $Spotter->db = null;
304
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
305
-			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
370
+			    if ($globalDebugTimeElapsed) {
371
+			    	echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
372
+			    }
373
+			    if ($aircraft_icao != '') {
374
+			    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
375
+			    }
306 376
 			}
307 377
 		    }
308
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
309
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
378
+		    if ($globalAllFlights !== FALSE) {
379
+		    	$dataFound = true;
380
+		    }
381
+		    if ($globalDebug) {
382
+		    	echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
383
+		    }
310 384
 		}
311 385
 	        if (isset($line['id']) && !isset($line['hex'])) {
312 386
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
@@ -314,7 +388,9 @@  discard block
 block discarded – undo
314 388
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
315 389
 			$icao = $line['aircraft_icao'];
316 390
 			$Spotter = new Spotter($this->db);
317
-			if (isset($Spotter->aircraft_correct_icaotype[$icao])) $icao = $Spotter->aircraft_correct_icaotype[$icao];
391
+			if (isset($Spotter->aircraft_correct_icaotype[$icao])) {
392
+				$icao = $Spotter->aircraft_correct_icaotype[$icao];
393
+			}
318 394
 			$Spotter->db = null;
319 395
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $icao));
320 396
 		}
@@ -324,15 +400,24 @@  discard block
 block discarded – undo
324 400
 				$Spotter = new Spotter($this->db);
325 401
 				$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
326 402
 				$Spotter->db = null;
327
-				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
403
+				if ($aircraft_icao != '') {
404
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
405
+				}
328 406
 			}
329 407
 		}
330 408
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) {
331
-			if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
332
-			elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
333
-			elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
334
-			elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
335
-			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
409
+			if ($line['aircraft_type'] == 'PARA_GLIDER') {
410
+				$aircraft_icao = 'GLID';
411
+			} elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') {
412
+				$aircraft_icao = 'UHEL';
413
+			} elseif ($line['aircraft_type'] == 'TOW_PLANE') {
414
+				$aircraft_icao = 'TOWPLANE';
415
+			} elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') {
416
+				$aircraft_icao = 'POWAIRC';
417
+			}
418
+			if (isset($aircraft_icao)) {
419
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
420
+			}
336 421
 		}
337 422
 		if (!isset($this->all_flights[$id]['aircraft_icao'])) {
338 423
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
@@ -342,8 +427,11 @@  discard block
 block discarded – undo
342 427
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
343 428
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
344 429
 		    } else {
345
-				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
346
-				elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
430
+				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
431
+					echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
432
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
433
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
434
+				}
347 435
 				/*
348 436
 				echo strtotime($line['datetime']).' > '.strtotime($this->all_flights[$id]['datetime']);
349 437
 				print_r($this->all_flights[$id]);
@@ -352,17 +440,23 @@  discard block
 block discarded – undo
352 440
 				return '';
353 441
 		    }
354 442
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) {
355
-			if ($globalDebug) echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n";
443
+			if ($globalDebug) {
444
+				echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n";
445
+			}
356 446
 			return '';
357 447
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) > time()+20*60) {
358
-			if ($globalDebug) echo "!!! Date is in the future ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n
448
+			if ($globalDebug) {
449
+				echo "!!! Date is in the future ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n
359 450
 			";
451
+			}
360 452
 			return '';
361 453
 		} elseif (!isset($line['datetime'])) {
362 454
 			date_default_timezone_set('UTC');
363 455
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
364 456
 		} else {
365
-			if ($globalDebug) echo "!!! Unknow date error ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!";
457
+			if ($globalDebug) {
458
+				echo "!!! Unknow date error ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!";
459
+			}
366 460
 			return '';
367 461
 		}
368 462
 
@@ -383,30 +477,48 @@  discard block
 block discarded – undo
383 477
 
384 478
 		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
385 479
 			if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
386
-				if ($globalDebug) echo '---!!!! New ident, reset aircraft data...'."\n";
480
+				if ($globalDebug) {
481
+					echo '---!!!! New ident, reset aircraft data...'."\n";
482
+				}
387 483
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
388 484
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
389
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
390
-				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
391
-				elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
485
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
486
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
487
+				} elseif (isset($line['id'])) {
488
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
489
+				} elseif (isset($this->all_flights[$id]['ident'])) {
490
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
491
+				}
392 492
 			} else {
393 493
 			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
394 494
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
395 495
 				$timeelapsed = microtime(true);
396 496
             			$Spotter = new Spotter($this->db);
397 497
             			$fromsource = NULL;
398
-            			if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
399
-            			elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
400
-				elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
401
-				elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
402
-				elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
498
+            			if (isset($globalAirlinesSource) && $globalAirlinesSource != '') {
499
+            				$fromsource = $globalAirlinesSource;
500
+            			} elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') {
501
+            				$fromsource = 'vatsim';
502
+            			} elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') {
503
+					$fromsource = 'ivao';
504
+				} elseif (isset($globalVATSIM) && $globalVATSIM) {
505
+					$fromsource = 'vatsim';
506
+				} elseif (isset($globalIVAO) && $globalIVAO) {
507
+					$fromsource = 'ivao';
508
+				}
403 509
             			$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
404
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
510
+				if ($globalDebug && $result != 'success') {
511
+					echo '!!! ERROR : '.$result."\n";
512
+				}
405 513
 				$Spotter->db = null;
406
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
514
+				if ($globalDebugTimeElapsed) {
515
+					echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
516
+				}
407 517
 			    }
408 518
 			}
409
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
519
+		    } else {
520
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
521
+		    }
410 522
 		    
411 523
 /*
412 524
 		    if (!isset($line['id'])) {
@@ -416,7 +528,9 @@  discard block
 block discarded – undo
416 528
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
417 529
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
418 530
   */
419
-		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
531
+		    if (!isset($this->all_flights[$id]['id'])) {
532
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
533
+		    }
420 534
 
421 535
 		    //$putinarchive = true;
422 536
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
@@ -434,7 +548,9 @@  discard block
 block discarded – undo
434 548
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
435 549
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
436 550
 		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
437
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
551
+				if ($globalDebugTimeElapsed) {
552
+					echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
553
+				}
438 554
                         }
439 555
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
440 556
 			$timeelapsed = microtime(true);
@@ -448,7 +564,9 @@  discard block
 block discarded – undo
448 564
 				$Translation->db = null;
449 565
 			    }
450 566
 			    $Spotter->db = null;
451
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
567
+			    if ($globalDebugTimeElapsed) {
568
+			    	echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
569
+			    }
452 570
                     	}
453 571
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
454 572
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
@@ -457,9 +575,13 @@  discard block
 block discarded – undo
457 575
 		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
458 576
 		    	    }
459 577
 			}
460
-			if (!isset($globalFork)) $globalFork = TRUE;
578
+			if (!isset($globalFork)) {
579
+				$globalFork = TRUE;
580
+			}
461 581
 			if (!$globalVA && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
462
-				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
582
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) {
583
+					$this->get_Schedule($id,trim($line['ident']));
584
+				}
463 585
 			}
464 586
 		    }
465 587
 		}
@@ -477,9 +599,13 @@  discard block
 block discarded – undo
477 599
 			$speed = $speed*3.6;
478 600
 			if ($speed < 1000) {
479 601
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
480
-	  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
602
+	  			if ($globalDebug) {
603
+	  				echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
604
+	  			}
481 605
 	  		} else {
482
-	  			if ($globalDebug) echo "ø IGNORED : Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
606
+	  			if ($globalDebug) {
607
+	  				echo "ø IGNORED : Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
608
+	  			}
483 609
 	  		}
484 610
 		    }
485 611
 		}
@@ -488,13 +614,21 @@  discard block
 block discarded – undo
488 614
 
489 615
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
490 616
 	    	    if (ctype_digit(strval($line['latitude'])) || ctype_digit(strval($line['longitude']))) {
491
-	    	    	if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
617
+	    	    	if ($globalDebug) {
618
+	    	    		echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
619
+	    	    	}
492 620
 	    	    	return false;
493 621
 	    	    }
494
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
495
-	    	    else unset($timediff);
496
-	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
497
-	    	    else unset($timediff_archive);
622
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) {
623
+	    	    	$timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
624
+	    	    } else {
625
+	    	    	unset($timediff);
626
+	    	    }
627
+	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) {
628
+	    	    	$timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
629
+	    	    } else {
630
+	    	    	unset($timediff_archive);
631
+	    	    }
498 632
 	    	    if ($this->tmd > 5
499 633
 	    	        || (isset($line['format_source']) 
500 634
 	    	    	    && $line['format_source'] == 'airwhere' 
@@ -530,16 +664,25 @@  discard block
 block discarded – undo
530 664
 				$this->all_flights[$id]['putinarchive'] = true;
531 665
 				$this->tmd = 0;
532 666
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
533
-				    if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
667
+				    if ($globalDebug) {
668
+				    	echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
669
+				    }
534 670
 				    $timeelapsed = microtime(true);
535 671
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
536 672
 					$Spotter = new Spotter($this->db);
537 673
 					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
538
-					if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
539
-					else $this->all_flights[$id]['over_country'] = '';
674
+					if (!empty($all_country)) {
675
+						$this->all_flights[$id]['over_country'] = $all_country['iso2'];
676
+					} else {
677
+						$this->all_flights[$id]['over_country'] = '';
678
+					}
540 679
 					$Spotter->db = null;
541
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
542
-					if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
680
+					if ($globalDebugTimeElapsed) {
681
+						echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
682
+					}
683
+					if ($globalDebug) {
684
+						echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
685
+					}
543 686
 				    }
544 687
 				}
545 688
 				$this->all_flights[$id]['time_last_archive_coord'] = time();
@@ -585,7 +728,9 @@  discard block
 block discarded – undo
585 728
 			    */
586 729
 			}
587 730
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
588
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
731
+			    if ($line['longitude'] > 180) {
732
+			    	$line['longitude'] = $line['longitude'] - 360;
733
+			    }
589 734
 			    //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
590 735
 				if (!isset($this->all_flights[$id]['archive_longitude'])) {
591 736
 					$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
@@ -622,7 +767,9 @@  discard block
 block discarded – undo
622 767
 		    }
623 768
 		}
624 769
 		if (isset($line['last_update']) && $line['last_update'] != '') {
625
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
770
+		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) {
771
+		    	$dataFound = true;
772
+		    }
626 773
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
627 774
 		}
628 775
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
@@ -644,53 +791,79 @@  discard block
 block discarded – undo
644 791
 			// Here we force archive of flight because after ground it's a new one (or should be)
645 792
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
646 793
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
647
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
648
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
649
-			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
794
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
795
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
796
+			} elseif (isset($line['id'])) {
797
+		        	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
798
+		        } elseif (isset($this->all_flights[$id]['ident'])) {
799
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
800
+			}
801
+		    }
802
+		    if ($line['ground'] != 1) {
803
+		    	$line['ground'] = 0;
650 804
 		    }
651
-		    if ($line['ground'] != 1) $line['ground'] = 0;
652 805
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
653 806
 		    //$dataFound = true;
654 807
 		}
655 808
 		if (isset($line['squawk']) && $line['squawk'] != '') {
656 809
 		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
657
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
810
+			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) {
811
+			    	$this->all_flights[$id]['putinarchive'] = true;
812
+			    }
658 813
 			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
659 814
 			    $highlight = '';
660
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
661
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
662
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
815
+			    if ($this->all_flights[$id]['squawk'] == '7500') {
816
+			    	$highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
817
+			    }
818
+			    if ($this->all_flights[$id]['squawk'] == '7600') {
819
+			    	$highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
820
+			    }
821
+			    if ($this->all_flights[$id]['squawk'] == '7700') {
822
+			    	$highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
823
+			    }
663 824
 			    if ($highlight != '') {
664 825
 				$timeelapsed = microtime(true);
665 826
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
666 827
 				    $Spotter = new Spotter($this->db);
667 828
 				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
668 829
 				    $Spotter->db = null;
669
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
830
+				    if ($globalDebugTimeElapsed) {
831
+				    	echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
832
+				    }
670 833
 				}
671 834
 				//$putinarchive = true;
672 835
 				//$highlight = '';
673 836
 			    }
674 837
 			    
675
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
838
+		    } else {
839
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
840
+		    }
676 841
 		    //$dataFound = true;
677 842
 		}
678 843
 
679 844
 		if (isset($line['altitude']) && $line['altitude'] != '') {
680 845
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
681
-			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
846
+			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) {
847
+				$this->all_flights[$id]['putinarchive'] = true;
848
+			}
682 849
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
683 850
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
684 851
 			//$dataFound = true;
685 852
 		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
686 853
 		    if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
687 854
 			if (isset($this->all_flights[$id]['over_country']) && $this->all_flights[$id]['over_country'] != '' && isset($this->all_flights[$id]['altitude_previous']) && $this->all_flights[$id]['altitude_previous'] != '' && $this->all_flights[$id]['altitude_previous'] < $this->all_flights[$id]['altitude_real'] && isset($this->all_flights[$id]['lastupdate']) && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
688
-				if ($globalDebug) echo '--- Reset because of altitude'."\n";
855
+				if ($globalDebug) {
856
+					echo '--- Reset because of altitude'."\n";
857
+				}
689 858
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
690 859
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
691
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
692
-				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
693
-				elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
860
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
861
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
862
+				} elseif (isset($line['id'])) {
863
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
864
+				} elseif (isset($this->all_flights[$id]['ident'])) {
865
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
866
+				}
694 867
 			}
695 868
 		    }
696 869
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
@@ -701,22 +874,32 @@  discard block
 block discarded – undo
701 874
 		}
702 875
 		
703 876
 		if (isset($line['heading']) && $line['heading'] != '') {
704
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
877
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) {
878
+		    	$this->all_flights[$id]['putinarchive'] = true;
879
+		    }
705 880
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
706 881
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
707 882
 		    //$dataFound = true;
708 883
   		} elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) {
709 884
   		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
710 885
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
711
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
712
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['id']." : ".$heading."\n";
886
+		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) {
887
+		    	$this->all_flights[$id]['putinarchive'] = true;
888
+		    }
889
+  		    if ($globalDebug) {
890
+  		    	echo "ø Calculated Heading for ".$this->all_flights[$id]['id']." : ".$heading."\n";
891
+  		    }
713 892
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
714 893
   		    // If not enough messages and ACARS set heading to 0
715 894
   		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
716 895
   		}
717
-		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
718
-		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
719
-		elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalMinupdate) $dataFound = false;
896
+		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) {
897
+			$dataFound = false;
898
+		} elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) {
899
+			$dataFound = false;
900
+		} elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalMinupdate) {
901
+			$dataFound = false;
902
+		}
720 903
 
721 904
 //		print_r($this->all_flights[$id]);
722 905
 		//gets the callsign from the last hour
@@ -733,23 +916,38 @@  discard block
 block discarded – undo
733 916
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
734 917
 			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
735 918
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
736
-				    if ($globalDebug) echo "Check if aircraft is already in DB...";
919
+				    if ($globalDebug) {
920
+				    	echo "Check if aircraft is already in DB...";
921
+				    }
737 922
 				    $timeelapsed = microtime(true);
738 923
 				    $SpotterLive = new SpotterLive($this->db);
739 924
 				    if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
740 925
 					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
741
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
926
+					if ($globalDebugTimeElapsed) {
927
+						echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
928
+					}
742 929
 				    } elseif (isset($line['id'])) {
743 930
 					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
744
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
931
+					if ($globalDebugTimeElapsed) {
932
+						echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
933
+					}
745 934
 				    } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
746 935
 					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
747
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
748
-				    } else $recent_ident = '';
936
+					if ($globalDebugTimeElapsed) {
937
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
938
+					}
939
+				    } else {
940
+				    	$recent_ident = '';
941
+				    }
749 942
 				    $SpotterLive->db=null;
750
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
751
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
752
-				} else $recent_ident = '';
943
+				    if ($globalDebug && $recent_ident == '') {
944
+				    	echo " Not in DB.\n";
945
+				    } elseif ($globalDebug && $recent_ident != '') {
946
+				    	echo " Already in DB.\n";
947
+				    }
948
+				} else {
949
+					$recent_ident = '';
950
+				}
753 951
 			    } else {
754 952
 				$recent_ident = '';
755 953
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
@@ -757,7 +955,9 @@  discard block
 block discarded – undo
757 955
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
758 956
 			    if($recent_ident == "")
759 957
 			    {
760
-				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
958
+				if ($globalDebug) {
959
+					echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
960
+				}
761 961
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
762 962
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
763 963
 				//adds the spotter data for the archive
@@ -801,31 +1001,49 @@  discard block
 block discarded – undo
801 1001
 				
802 1002
 				if (!$ignoreImport) {
803 1003
 				    $highlight = '';
804
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
805
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
806
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
807
-				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
1004
+				    if ($this->all_flights[$id]['squawk'] == '7500') {
1005
+				    	$highlight = 'Squawk 7500 : Hijack';
1006
+				    }
1007
+				    if ($this->all_flights[$id]['squawk'] == '7600') {
1008
+				    	$highlight = 'Squawk 7600 : Lost Comm (radio failure)';
1009
+				    }
1010
+				    if ($this->all_flights[$id]['squawk'] == '7700') {
1011
+				    	$highlight = 'Squawk 7700 : Emergency';
1012
+				    }
1013
+				    if (!isset($this->all_flights[$id]['id'])) {
1014
+				    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
1015
+				    }
808 1016
 				    $timeelapsed = microtime(true);
809 1017
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
810 1018
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
811 1019
 					    $Spotter = new Spotter($this->db);
812 1020
 					    $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']);
813 1021
 					    $Spotter->db = null;
814
-					    if ($globalDebug && isset($result)) echo $result."\n";
1022
+					    if ($globalDebug && isset($result)) {
1023
+					    	echo $result."\n";
1024
+					    }
815 1025
 					}
816 1026
 				    }
817
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1027
+				    if ($globalDebugTimeElapsed) {
1028
+				    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1029
+				    }
818 1030
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
819 1031
 
820 1032
 				    // Add source stat in DB
821 1033
 				    $Stats = new Stats($this->db);
822 1034
 				    if (!empty($this->stats)) {
823
-					if ($globalDebug) echo 'Add source stats : ';
1035
+					if ($globalDebug) {
1036
+						echo 'Add source stats : ';
1037
+					}
824 1038
 				        foreach($this->stats as $date => $data) {
825 1039
 					    foreach($data as $source => $sourced) {
826 1040
 					        //print_r($sourced);
827
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
828
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
1041
+				    	        if (isset($sourced['polar'])) {
1042
+				    	        	echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
1043
+				    	        }
1044
+				    	        if (isset($sourced['hist'])) {
1045
+				    	        	echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
1046
+				    	        }
829 1047
 				    		if (isset($sourced['msg'])) {
830 1048
 				    		    if (time() - $sourced['msg']['date'] > 10) {
831 1049
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
@@ -838,13 +1056,17 @@  discard block
 block discarded – undo
838 1056
 			    			unset($this->stats[$date]);
839 1057
 			    		    }
840 1058
 				    	}
841
-				    	if ($globalDebug) echo 'Done'."\n";
1059
+				    	if ($globalDebug) {
1060
+				    		echo 'Done'."\n";
1061
+				    	}
842 1062
 
843 1063
 				    }
844 1064
 				    $Stats->db = null;
845 1065
 				    }
846 1066
 				    $this->del();
847
-				} elseif ($globalDebug) echo 'Ignore data'."\n";
1067
+				} elseif ($globalDebug) {
1068
+					echo 'Ignore data'."\n";
1069
+				}
848 1070
 				//$ignoreImport = false;
849 1071
 				$this->all_flights[$id]['addedSpotter'] = 1;
850 1072
 				//print_r($this->all_flights[$id]);
@@ -861,7 +1083,9 @@  discard block
 block discarded – undo
861 1083
 			*/
862 1084
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
863 1085
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
864
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
1086
+				    if ($globalDebug) {
1087
+				    	echo "---- Deleting Live Spotter data older than 9 hours...";
1088
+				    }
865 1089
 				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
866 1090
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
867 1091
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
@@ -870,7 +1094,9 @@  discard block
 block discarded – undo
870 1094
 					    $SpotterLive->db=null;
871 1095
 					}
872 1096
 				    }
873
-				    if ($globalDebug) echo " Done\n";
1097
+				    if ($globalDebug) {
1098
+				    	echo " Done\n";
1099
+				    }
874 1100
 				    $this->last_delete = time();
875 1101
 				}
876 1102
 			    } else {
@@ -897,11 +1123,17 @@  discard block
 block discarded – undo
897 1123
 		    //echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n";
898 1124
 		    if ($globalDebug) {
899 1125
 			if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
900
-				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";
901
-				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
1126
+				if (isset($this->all_flights[$id]['source_name'])) {
1127
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";
1128
+				} else {
1129
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
1130
+				}
902 1131
 			} else {
903
-				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";
904
-				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";
1132
+				if (isset($this->all_flights[$id]['source_name'])) {
1133
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";
1134
+				} else {
1135
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";
1136
+				}
905 1137
 			}
906 1138
 		    }
907 1139
 		    $ignoreImport = false;
@@ -947,22 +1179,30 @@  discard block
 block discarded – undo
947 1179
 
948 1180
 		    if (!$ignoreImport) {
949 1181
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
950
-				if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
1182
+				if (!isset($this->all_flights[$id]['id'])) {
1183
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
1184
+				}
951 1185
 				$timeelapsed = microtime(true);
952 1186
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
953 1187
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
954
-					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1188
+					if ($globalDebug) {
1189
+						echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1190
+					}
955 1191
 					$SpotterLive = new SpotterLive($this->db);
956 1192
 					$result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
957 1193
 					$SpotterLive->db = null;
958
-					if ($globalDebug) echo $result."\n";
1194
+					if ($globalDebug) {
1195
+						echo $result."\n";
1196
+					}
959 1197
 				    }
960 1198
 				}
961 1199
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) {
962 1200
 					$APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
963 1201
 				}
964 1202
 				$this->all_flights[$id]['putinarchive'] = false;
965
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1203
+				if ($globalDebugTimeElapsed) {
1204
+					echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1205
+				}
966 1206
 
967 1207
 				// Put statistics in $this->stats variable
968 1208
 				//if ($line['format_source'] != 'aprs') {
@@ -970,7 +1210,9 @@  discard block
 block discarded – undo
970 1210
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
971 1211
 				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
972 1212
 					$source = $this->all_flights[$id]['source_name'];
973
-					if ($source == '') $source = $this->all_flights[$id]['format_source'];
1213
+					if ($source == '') {
1214
+						$source = $this->all_flights[$id]['format_source'];
1215
+					}
974 1216
 					if (!isset($this->source_location[$source])) {
975 1217
 						$Location = new Source();
976 1218
 						$coord = $Location->getLocationInfobySourceName($source);
@@ -991,7 +1233,9 @@  discard block
 block discarded – undo
991 1233
 					$stats_heading = round($stats_heading/22.5);
992 1234
 					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
993 1235
 					$current_date = date('Y-m-d');
994
-					if ($stats_heading == 16) $stats_heading = 0;
1236
+					if ($stats_heading == 16) {
1237
+						$stats_heading = 0;
1238
+					}
995 1239
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
996 1240
 						for ($i=0;$i<=15;$i++) {
997 1241
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
@@ -1009,7 +1253,9 @@  discard block
 block discarded – undo
1009 1253
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
1010 1254
 						    end($this->stats[$current_date][$source]['hist']);
1011 1255
 						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
1012
-						} else $mini = 0;
1256
+						} else {
1257
+							$mini = 0;
1258
+						}
1013 1259
 						for ($i=$mini;$i<=$distance;$i+=10) {
1014 1260
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
1015 1261
 						}
@@ -1021,19 +1267,27 @@  discard block
 block discarded – undo
1021 1267
 				}
1022 1268
 
1023 1269
 				$this->all_flights[$id]['lastupdate'] = time();
1024
-				if ($this->all_flights[$id]['putinarchive']) $send = true;
1270
+				if ($this->all_flights[$id]['putinarchive']) {
1271
+					$send = true;
1272
+				}
1025 1273
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1026
-			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1274
+			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
1275
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1276
+			}
1027 1277
 			//$this->del();
1028 1278
 			
1029 1279
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
1030 1280
 			    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
1031
-				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1281
+				if ($globalDebug) {
1282
+					echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1283
+				}
1032 1284
 				$SpotterLive = new SpotterLive($this->db);
1033 1285
 				$SpotterLive->deleteLiveSpotterDataNotUpdated();
1034 1286
 				$SpotterLive->db = null;
1035 1287
 				//SpotterLive->deleteLiveSpotterData();
1036
-				if ($globalDebug) echo " Done\n";
1288
+				if ($globalDebug) {
1289
+					echo " Done\n";
1290
+				}
1037 1291
 				$this->last_delete_hourly = time();
1038 1292
 			    } else {
1039 1293
 				$this->del();
@@ -1045,7 +1299,9 @@  discard block
 block discarded – undo
1045 1299
 		    //$ignoreImport = false;
1046 1300
 		}
1047 1301
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
1048
-		if ($send) return $this->all_flights[$id];
1302
+		if ($send) {
1303
+			return $this->all_flights[$id];
1304
+		}
1049 1305
 	    }
1050 1306
 	}
1051 1307
     }
Please login to merge, or discard this patch.
accident.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 require_once(dirname(__FILE__).'/require/settings.php');
3
-$date = filter_input(INPUT_POST,'date',FILTER_SANITIZE_STRING);
3
+$date = filter_input(INPUT_POST, 'date', FILTER_SANITIZE_STRING);
4 4
 if ($date == '') $date = date('Y-m-d');
5 5
 header('Location: '.$globalURL.'/accident/'.$date);
6 6
 ?>
7 7
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 require_once(dirname(__FILE__).'/require/settings.php');
3 3
 $date = filter_input(INPUT_POST,'date',FILTER_SANITIZE_STRING);
4
-if ($date == '') $date = date('Y-m-d');
4
+if ($date == '') {
5
+	$date = date('Y-m-d');
6
+}
5 7
 header('Location: '.$globalURL.'/accident/'.$date);
6 8
 ?>
7 9
\ No newline at end of file
Please login to merge, or discard this patch.
statistics-fatalities-year.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -19,13 +19,13 @@  discard block
 block discarded – undo
19 19
 print '<div id="chart" class="chart" width="100%"></div><script>';
20 20
 $year_data = '';
21 21
 $year_cnt = '';
22
-foreach($date_array as $year_item)
22
+foreach ($date_array as $year_item)
23 23
 {
24 24
 	$year_data .= '"'.$year_item['year'].'-01-01",';
25 25
 	$year_cnt .= $year_item['count'].',';
26 26
 }
27 27
 $year_data = "['x',".substr($year_data, 0, -1)."]";
28
-$year_cnt = "['flights',".substr($year_cnt,0,-1)."]";
28
+$year_cnt = "['flights',".substr($year_cnt, 0, -1)."]";
29 29
 print 'c3.generate({
30 30
     bindto: "#chart",
31 31
     data: { x: "x",
@@ -35,12 +35,12 @@  discard block
 block discarded – undo
35 35
 
36 36
 if (!empty($date_array))
37 37
 {
38
-	foreach($date_array as $key => $row) {
38
+	foreach ($date_array as $key => $row) {
39 39
 		$years[$key] = $row['year'];
40 40
 		$counts[$key] = $row['count'];
41 41
 	}
42 42
 	//array_multisort($years,SORT_DESC,$date_array);
43
-	array_multisort($counts,SORT_DESC,$date_array);
43
+	array_multisort($counts, SORT_DESC, $date_array);
44 44
 	print '<div class="table-responsive">';
45 45
 	print '<table class="common-date table-striped">';
46 46
 	print '<thead>';
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	print '</thead>';
51 51
 	print '<tbody>';
52 52
 	$i = 1;
53
-	foreach($date_array as $date_item)
53
+	foreach ($date_array as $date_item)
54 54
 	{
55 55
 		print '<tr>';
56 56
 		print '<td><strong>'.$i.'</strong></td>';
Please login to merge, or discard this patch.
statistics-route-airport.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 $route_array = $Spotter->countAllRoutes();
19 19
 print '<div id="chart" class="chart" width="100%"></div><script>';
20 20
 $route_data = '';
21
-foreach($route_array as $route_item)
21
+foreach ($route_array as $route_item)
22 22
 {
23 23
 	$route_data .= '[ "'.$route_item['airport_departure_icao'].' - '.$route_item['airport_arrival_icao'].'",'.$route_item['route_count'].'],';
24 24
 }
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	print '</thead>';
47 47
 	print '<tbody>';
48 48
 	$i = 1;
49
-	foreach($route_array as $route_item)
49
+	foreach ($route_array as $route_item)
50 50
 	{
51 51
 		print '<tr>';
52 52
 		print '<td><strong>'.$i.'</strong></td>';
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -5,7 +5,9 @@
 block discarded – undo
5 5
 $Spotter = new Spotter();
6 6
 $title = _("Statistics").' - '._("Most common Route by Airport");
7 7
 require_once('header.php');
8
-if (!isset($filter_name)) $filter_name = '';
8
+if (!isset($filter_name)) {
9
+	$filter_name = '';
10
+}
9 11
 include('statistics-sub-menu.php'); 
10 12
 
11 13
 print '<script type="text/javascript" src="'.$globalURL.'/js/d3.min.js"></script>';
Please login to merge, or discard this patch.
require/class.Connection.php 4 patches
Braces   +80 added lines, -31 removed lines patch added patch discarded remove patch
@@ -72,8 +72,11 @@  discard block
 block discarded – undo
72 72
 				$globalDBSname = $globalDBname;
73 73
 				$globalDBSuser = $globalDBuser;
74 74
 				$globalDBSpass = $globalDBpass;
75
-				if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport == '') $globalDBSport = 3306;
76
-				else $globalDBSport = $globalDBport;
75
+				if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport == '') {
76
+					$globalDBSport = 3306;
77
+				} else {
78
+					$globalDBSport = $globalDBport;
79
+				}
77 80
 			} else {
78 81
 				$DBname = 'default';
79 82
 				$globalDBSdriver = $globalDBdriver;
@@ -81,8 +84,11 @@  discard block
 block discarded – undo
81 84
 				$globalDBSname = $globalDBname;
82 85
 				$globalDBSuser = $user;
83 86
 				$globalDBSpass = $pass;
84
-				if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport == '') $globalDBSport = 3306;
85
-				else $globalDBSport = $globalDBport;
87
+				if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport == '') {
88
+					$globalDBSport = 3306;
89
+				} else {
90
+					$globalDBSport = $globalDBport;
91
+				}
86 92
 			}
87 93
 		} else {
88 94
 			$globalDBSdriver = $globalDB[$DBname]['driver'];
@@ -90,11 +96,16 @@  discard block
 block discarded – undo
90 96
 			$globalDBSname = $globalDB[$DBname]['name'];
91 97
 			$globalDBSuser = $globalDB[$DBname]['user'];
92 98
 			$globalDBSpass = $globalDB[$DBname]['pass'];
93
-			if (isset($globalDB[$DBname]['port'])) $globalDBSport = $globalDB[$DBname]['port'];
94
-			else $globalDBSport = 3306;
99
+			if (isset($globalDB[$DBname]['port'])) {
100
+				$globalDBSport = $globalDB[$DBname]['port'];
101
+			} else {
102
+				$globalDBSport = 3306;
103
+			}
95 104
 		}
96 105
 		// Set number of try to connect to DB
97
-		if (!isset($globalDBretry) || $globalDBretry == '' || $globalDBretry === NULL) $globalDBretry = 5;
106
+		if (!isset($globalDBretry) || $globalDBretry == '' || $globalDBretry === NULL) {
107
+			$globalDBretry = 5;
108
+		}
98 109
 		$i = 0;
99 110
 		while (true) {
100 111
 			try {
@@ -103,10 +114,16 @@  discard block
 block discarded – undo
103 114
 					$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
104 115
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
105 116
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER);
106
-					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,500);
107
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
108
-					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
109
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
117
+					if (!isset($globalDBTimeOut)) {
118
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,500);
119
+					} else {
120
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
121
+					}
122
+					if (!isset($globalDBPersistent)) {
123
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
124
+					} else {
125
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
126
+					}
110 127
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
111 128
 					$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
112 129
 					// Workaround against "ONLY_FULL_GROUP_BY" mode
@@ -120,23 +137,35 @@  discard block
 block discarded – undo
120 137
 					//$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
121 138
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
122 139
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER);
123
-					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200);
124
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
125
-					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
126
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
140
+					if (!isset($globalDBTimeOut)) {
141
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200);
142
+					} else {
143
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
144
+					}
145
+					if (!isset($globalDBPersistent)) {
146
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
147
+					} else {
148
+						$this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
149
+					}
127 150
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
128 151
 					$this->dbs[$DBname]->exec('SET timezone="UTC"');
129 152
 				}
130 153
 				break;
131 154
 			} catch(PDOException $e) {
132 155
 				$i++;
133
-				if (isset($globalDebug) && $globalDebug) echo 'Error connecting to DB: '.$globalDBSname.' - Error: '.$e->getMessage()."\n";
156
+				if (isset($globalDebug) && $globalDebug) {
157
+					echo 'Error connecting to DB: '.$globalDBSname.' - Error: '.$e->getMessage()."\n";
158
+				}
134 159
 				//exit;
135
-				if ($i > $globalDBretry) return false;
160
+				if ($i > $globalDBretry) {
161
+					return false;
162
+				}
136 163
 				//return false;
137 164
 			}
138 165
 		}
139
-		if ($DBname === 'default') $this->db = $this->dbs['default'];
166
+		if ($DBname === 'default') {
167
+			$this->db = $this->dbs['default'];
168
+		}
140 169
 		return true;
141 170
 	}
142 171
 
@@ -148,7 +177,9 @@  discard block
 block discarded – undo
148 177
 		} else {
149 178
 			$query = "SELECT * FROM pg_catalog.pg_tables WHERE tablename = '".$table."'";
150 179
 		}
151
-		if ($this->db == NULL) return false;
180
+		if ($this->db == NULL) {
181
+			return false;
182
+		}
152 183
 		try {
153 184
 			//$Connection = new Connection();
154 185
 			$results = $this->db->query($query);
@@ -157,21 +188,28 @@  discard block
 block discarded – undo
157 188
 		}
158 189
 		if($results->rowCount()>0) {
159 190
 		    return true; 
191
+		} else {
192
+			return false;
160 193
 		}
161
-		else return false;
162 194
 	}
163 195
 
164 196
 	public function connectionExists()
165 197
 	{
166 198
 		global $globalDBdriver, $globalDBCheckConnection;
167
-		if (isset($globalDBCheckConnection) && $globalDBCheckConnection === FALSE) return true;
199
+		if (isset($globalDBCheckConnection) && $globalDBCheckConnection === FALSE) {
200
+			return true;
201
+		}
168 202
 		$query = "SELECT 1 + 1";
169
-		if ($this->db === null) return false;
203
+		if ($this->db === null) {
204
+			return false;
205
+		}
170 206
 		try {
171 207
 			$sum = @$this->db->query($query);
172 208
 			if ($sum instanceof \PDOStatement) {
173 209
 				$sum = $sum->fetchColumn(0);
174
-			} else $sum = 0;
210
+			} else {
211
+				$sum = 0;
212
+			}
175 213
 			if (intval($sum) !== 2) {
176 214
 			     return false;
177 215
 			}
@@ -206,8 +244,9 @@  discard block
 block discarded – undo
206 244
 		$nb = $results->fetchAll(PDO::FETCH_ASSOC);
207 245
 		if($nb[0]['nb'] > 0) {
208 246
 			return true; 
247
+		} else {
248
+			return false;
209 249
 		}
210
-		else return false;
211 250
 	}
212 251
 
213 252
 	/*
@@ -257,9 +296,12 @@  discard block
 block discarded – undo
257 296
 			}
258 297
 			$result = $sth->fetch(PDO::FETCH_ASSOC);
259 298
 			$sth->closeCursor();
260
-			if ($result['nb'] > 0) return true;
261
-			else return false;
262
-/*		} else {
299
+			if ($result['nb'] > 0) {
300
+				return true;
301
+			} else {
302
+				return false;
303
+			}
304
+			/*		} else {
263 305
 			$query = "SELECT * FROM ".$table." LIMIT 0";
264 306
 			try {
265 307
 				$results = $this->db->query($query);
@@ -298,7 +340,9 @@  discard block
 block discarded – undo
298 340
 				$sth->closeCursor();
299 341
 				return $result['value'];
300 342
 			}
301
-		} else return $version;
343
+		} else {
344
+			return $version;
345
+		}
302 346
 	}
303 347
 	
304 348
 	/*
@@ -307,9 +351,14 @@  discard block
 block discarded – undo
307 351
 	*/
308 352
 	public function latest() {
309 353
 	    global $globalNoDB;
310
-	    if (isset($globalNoDB) && $globalNoDB === TRUE) return true;
311
-	    if ($this->check_schema_version() == $this->latest_schema) return true;
312
-	    else return false;
354
+	    if (isset($globalNoDB) && $globalNoDB === TRUE) {
355
+	    	return true;
356
+	    }
357
+	    if ($this->check_schema_version() == $this->latest_schema) {
358
+	    	return true;
359
+	    } else {
360
+	    	return false;
361
+	    }
313 362
 	}
314 363
 
315 364
 }
Please login to merge, or discard this patch.
Doc Comments   +20 added lines patch added patch discarded remove patch
@@ -6,6 +6,9 @@  discard block
 block discarded – undo
6 6
 	public $dbs = array();
7 7
 	public $latest_schema = 44;
8 8
 	
9
+	/**
10
+	 * @param string $dbname
11
+	 */
9 12
 	public function __construct($dbc = null,$dbname = null,$user = null,$pass = null) {
10 13
 	    global $globalDBdriver, $globalNoDB;
11 14
 	    if (isset($globalNoDB) && $globalNoDB === TRUE) {
@@ -141,6 +144,9 @@  discard block
 block discarded – undo
141 144
 		return true;
142 145
 	}
143 146
 
147
+	/**
148
+	 * @param string $table
149
+	 */
144 150
 	public function tableExists($table)
145 151
 	{
146 152
 		global $globalDBdriver, $globalDBname;
@@ -190,6 +196,11 @@  discard block
 block discarded – undo
190 196
 	/*
191 197
 	* Check if index exist
192 198
 	*/
199
+
200
+	/**
201
+	 * @param string $table
202
+	 * @param string $index
203
+	 */
193 204
 	public function indexExists($table,$index)
194 205
 	{
195 206
 		global $globalDBdriver, $globalDBname;
@@ -232,6 +243,10 @@  discard block
 block discarded – undo
232 243
 		return $columns;
233 244
 	}
234 245
 
246
+	/**
247
+	 * @param string $table
248
+	 * @param string $column
249
+	 */
235 250
 	public function getColumnType($table,$column) {
236 251
 		$select = $this->db->query('SELECT '.$column.' FROM '.$table);
237 252
 		$tomet = $select->getColumnMeta(0);
@@ -242,6 +257,11 @@  discard block
 block discarded – undo
242 257
 	* Check if a column name exist in a table
243 258
 	* @return Boolean column exist or not
244 259
 	*/
260
+
261
+	/**
262
+	 * @param string $table
263
+	 * @param string $name
264
+	 */
245 265
 	public function checkColumnName($table,$name)
246 266
 	{
247 267
 		global $globalDBdriver, $globalDBname;
Please login to merge, or discard this patch.
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -7,35 +7,35 @@  discard block
 block discarded – undo
7 7
 	public $latest_schema = 44;
8 8
 	
9 9
 	public function __construct($dbc = null,$dbname = null,$user = null,$pass = null) {
10
-	    global $globalDBdriver, $globalNoDB;
11
-	    if (isset($globalNoDB) && $globalNoDB === TRUE) {
10
+		global $globalDBdriver, $globalNoDB;
11
+		if (isset($globalNoDB) && $globalNoDB === TRUE) {
12 12
 		$this->db = null;
13
-	    } else {
13
+		} else {
14 14
 		if ($dbc === null) {
15
-		    if ($this->db === null && $dbname === null) {
15
+			if ($this->db === null && $dbname === null) {
16 16
 			if ($user === null && $pass === null) {
17
-			    $this->createDBConnection();
17
+				$this->createDBConnection();
18 18
 			} else {
19
-			    $this->createDBConnection(null,$user,$pass);
19
+				$this->createDBConnection(null,$user,$pass);
20 20
 			}
21
-		    } else {
21
+			} else {
22 22
 			$this->createDBConnection($dbname);
23
-		    }
23
+			}
24 24
 		} elseif ($dbname === null || $dbname === 'default') {
25
-	    	    $this->db = $dbc;
26
-	    	    if ($this->connectionExists() === false) {
25
+				$this->db = $dbc;
26
+				if ($this->connectionExists() === false) {
27 27
 			/*
28 28
 			echo 'Restart Connection !!!'."\n";
29 29
 			$e = new \Exception;
30 30
 			var_dump($e->getTraceAsString());
31 31
 			*/
32 32
 			$this->createDBConnection();
33
-		    }
33
+			}
34 34
 		} else {
35
-		    //$this->connectionExists();
36
-		    $this->dbs[$dbname] = $dbc;
35
+			//$this->connectionExists();
36
+			$this->dbs[$dbname] = $dbc;
37
+		}
37 38
 		}
38
-	    }
39 39
 	}
40 40
 
41 41
 	public function db() {
@@ -56,11 +56,11 @@  discard block
 block discarded – undo
56 56
 	}
57 57
 
58 58
 	/**
59
-	* Creates the database connection
60
-	*
61
-	* @return Boolean of the database connection
62
-	*
63
-	*/
59
+	 * Creates the database connection
60
+	 *
61
+	 * @return Boolean of the database connection
62
+	 *
63
+	 */
64 64
 
65 65
 	public function createDBConnection($DBname = null, $user = null, $pass = null)
66 66
 	{
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 			return false;
158 158
 		}
159 159
 		if($results->rowCount()>0) {
160
-		    return true; 
160
+			return true; 
161 161
 		}
162 162
 		else return false;
163 163
 	}
@@ -174,14 +174,14 @@  discard block
 block discarded – undo
174 174
 				$sum = $sum->fetchColumn(0);
175 175
 			} else $sum = 0;
176 176
 			if (intval($sum) !== 2) {
177
-			     return false;
177
+				 return false;
178 178
 			}
179 179
 			
180 180
 		} catch(PDOException $e) {
181 181
 			if($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) {
182
-            			throw $e;
183
-	                }
184
-	                //echo 'error ! '.$e->getMessage();
182
+						throw $e;
183
+					}
184
+					//echo 'error ! '.$e->getMessage();
185 185
 			return false;
186 186
 		}
187 187
 		return true; 
@@ -285,8 +285,8 @@  discard block
 block discarded – undo
285 285
 		$version = 0;
286 286
 		if ($this->tableExists('aircraft')) {
287 287
 			if (!$this->tableExists('config')) {
288
-	    			$version = '1';
289
-	    			return $version;
288
+					$version = '1';
289
+					return $version;
290 290
 			} else {
291 291
 				$query = "SELECT value FROM config WHERE name = 'schema_version' LIMIT 1";
292 292
 				try {
@@ -307,10 +307,10 @@  discard block
 block discarded – undo
307 307
 	* @return Boolean if latest version or not
308 308
 	*/
309 309
 	public function latest() {
310
-	    global $globalNoDB;
311
-	    if (isset($globalNoDB) && $globalNoDB === TRUE) return true;
312
-	    if ($this->check_schema_version() == $this->latest_schema) return true;
313
-	    else return false;
310
+		global $globalNoDB;
311
+		if (isset($globalNoDB) && $globalNoDB === TRUE) return true;
312
+		if ($this->check_schema_version() == $this->latest_schema) return true;
313
+		else return false;
314 314
 	}
315 315
 
316 316
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 require_once(dirname(__FILE__).'/settings.php');
3 3
 
4
-class Connection{
4
+class Connection {
5 5
 	public $db = null;
6 6
 	public $dbs = array();
7 7
 	public $latest_schema = 44;
8 8
 	
9
-	public function __construct($dbc = null,$dbname = null,$user = null,$pass = null) {
9
+	public function __construct($dbc = null, $dbname = null, $user = null, $pass = null) {
10 10
 	    global $globalDBdriver, $globalNoDB;
11 11
 	    if (isset($globalNoDB) && $globalNoDB === TRUE) {
12 12
 		$this->db = null;
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 			if ($user === null && $pass === null) {
17 17
 			    $this->createDBConnection();
18 18
 			} else {
19
-			    $this->createDBConnection(null,$user,$pass);
19
+			    $this->createDBConnection(null, $user, $pass);
20 20
 			}
21 21
 		    } else {
22 22
 			$this->createDBConnection($dbname);
@@ -100,14 +100,14 @@  discard block
 block discarded – undo
100 100
 		while (true) {
101 101
 			try {
102 102
 				if ($globalDBSdriver == 'mysql') {
103
-					$this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;charset=utf8", $globalDBSuser,  $globalDBSpass);
103
+					$this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;charset=utf8", $globalDBSuser, $globalDBSpass);
104 104
 					$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
105 105
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
106
-					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER);
107
-					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,500);
108
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
109
-					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
110
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
106
+					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
107
+					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, 500);
108
+					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, $globalDBTimeOut);
109
+					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, true);
110
+					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, $globalDBPersistent);
111 111
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
112 112
 					$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
113 113
 					// Workaround against "ONLY_FULL_GROUP_BY" mode
@@ -117,19 +117,19 @@  discard block
 block discarded – undo
117 117
 					$this->dbs[$DBname]->exec('SET SESSION time_zone = "+00:00"');
118 118
 					//$this->dbs[$DBname]->exec('SET @@session.time_zone = "+00:00"');
119 119
 				} else {
120
-					$this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;options='--client_encoding=utf8'", $globalDBSuser,  $globalDBSpass);
120
+					$this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;options='--client_encoding=utf8'", $globalDBSuser, $globalDBSpass);
121 121
 					//$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
122 122
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
123
-					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER);
124
-					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200);
125
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut);
126
-					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true);
127
-					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent);
123
+					$this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
124
+					if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, 200);
125
+					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, $globalDBTimeOut);
126
+					if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, true);
127
+					else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, $globalDBPersistent);
128 128
 					$this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
129 129
 					$this->dbs[$DBname]->exec('SET timezone="UTC"');
130 130
 				}
131 131
 				break;
132
-			} catch(PDOException $e) {
132
+			} catch (PDOException $e) {
133 133
 				$i++;
134 134
 				if (isset($globalDebug) && $globalDebug) echo 'Error connecting to DB: '.$globalDBSname.' - Error: '.$e->getMessage()."\n";
135 135
 				//exit;
@@ -153,10 +153,10 @@  discard block
 block discarded – undo
153 153
 		try {
154 154
 			//$Connection = new Connection();
155 155
 			$results = $this->db->query($query);
156
-		} catch(PDOException $e) {
156
+		} catch (PDOException $e) {
157 157
 			return false;
158 158
 		}
159
-		if($results->rowCount()>0) {
159
+		if ($results->rowCount() > 0) {
160 160
 		    return true; 
161 161
 		}
162 162
 		else return false;
@@ -177,8 +177,8 @@  discard block
 block discarded – undo
177 177
 			     return false;
178 178
 			}
179 179
 			
180
-		} catch(PDOException $e) {
181
-			if($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) {
180
+		} catch (PDOException $e) {
181
+			if ($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) {
182 182
             			throw $e;
183 183
 	                }
184 184
 	                //echo 'error ! '.$e->getMessage();
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 	/*
191 191
 	* Check if index exist
192 192
 	*/
193
-	public function indexExists($table,$index)
193
+	public function indexExists($table, $index)
194 194
 	{
195 195
 		global $globalDBdriver, $globalDBname;
196 196
 		if ($globalDBdriver == 'mysql') {
@@ -201,11 +201,11 @@  discard block
 block discarded – undo
201 201
 		try {
202 202
 			//$Connection = new Connection();
203 203
 			$results = $this->db->query($query);
204
-		} catch(PDOException $e) {
204
+		} catch (PDOException $e) {
205 205
 			return false;
206 206
 		}
207 207
 		$nb = $results->fetchAll(PDO::FETCH_ASSOC);
208
-		if($nb[0]['nb'] > 0) {
208
+		if ($nb[0]['nb'] > 0) {
209 209
 			return true; 
210 210
 		}
211 211
 		else return false;
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 		$query = "SELECT * FROM ".$table." LIMIT 0";
221 221
 		try {
222 222
 			$results = $this->db->query($query);
223
-		} catch(PDOException $e) {
223
+		} catch (PDOException $e) {
224 224
 			return "error : ".$e->getMessage()."\n";
225 225
 		}
226 226
 		$columns = array();
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 		return $columns;
233 233
 	}
234 234
 
235
-	public function getColumnType($table,$column) {
235
+	public function getColumnType($table, $column) {
236 236
 		$select = $this->db->query('SELECT '.$column.' FROM '.$table);
237 237
 		$tomet = $select->getColumnMeta(0);
238 238
 		return $tomet['native_type'];
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 	* Check if a column name exist in a table
243 243
 	* @return Boolean column exist or not
244 244
 	*/
245
-	public function checkColumnName($table,$name)
245
+	public function checkColumnName($table, $name)
246 246
 	{
247 247
 		global $globalDBdriver, $globalDBname;
248 248
 		if ($globalDBdriver == 'mysql') {
@@ -252,8 +252,8 @@  discard block
 block discarded – undo
252 252
 		}
253 253
 			try {
254 254
 				$sth = $this->db()->prepare($query);
255
-				$sth->execute(array(':database' => $globalDBname,':table' => $table,':name' => $name));
256
-			} catch(PDOException $e) {
255
+				$sth->execute(array(':database' => $globalDBname, ':table' => $table, ':name' => $name));
256
+			} catch (PDOException $e) {
257 257
 				echo "error : ".$e->getMessage()."\n";
258 258
 			}
259 259
 			$result = $sth->fetch(PDO::FETCH_ASSOC);
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 				try {
293 293
 					$sth = $this->db->prepare($query);
294 294
 					$sth->execute();
295
-				} catch(PDOException $e) {
295
+				} catch (PDOException $e) {
296 296
 					return "error : ".$e->getMessage()."\n";
297 297
 				}
298 298
 				$result = $sth->fetch(PDO::FETCH_ASSOC);
Please login to merge, or discard this patch.
incident.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 require_once(dirname(__FILE__).'/require/settings.php');
3
-$date = filter_input(INPUT_POST,'date',FILTER_SANITIZE_STRING);
3
+$date = filter_input(INPUT_POST, 'date', FILTER_SANITIZE_STRING);
4 4
 if ($date == '') $date = date('Y-m-d');
5 5
 header('Location: '.$globalURL.'/incident/'.$date);
6 6
 ?>
7 7
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 require_once(dirname(__FILE__).'/require/settings.php');
3 3
 $date = filter_input(INPUT_POST,'date',FILTER_SANITIZE_STRING);
4
-if ($date == '') $date = date('Y-m-d');
4
+if ($date == '') {
5
+	$date = date('Y-m-d');
6
+}
5 7
 header('Location: '.$globalURL.'/incident/'.$date);
6 8
 ?>
7 9
\ No newline at end of file
Please login to merge, or discard this patch.