Completed
Push — master ( 41b901...22364b )
by Yannick
06:33
created
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   +124 added lines, -124 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 && susbtr($result['mmsi'],0,3) == '669') $result['mmsi'] = '3'.$result['mmsi'];
624
+		if (strlen($result['mmsi']) == 8 && susbtr($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;
Please login to merge, or discard this patch.
Braces   +319 added lines, -139 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);
463 576
 		}
464
-		if ($last_pos > 0) $cbuf = substr($cbuf, $last_pos); // move...
465
-		if (strlen($cbuf) > 1024) $cbuf = ""; // prevent overflow simple mode...
577
+		// move...
578
+		if (strlen($cbuf) > 1024) {
579
+			$cbuf = "";
580
+		}
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,24 +775,45 @@  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 && susbtr($result['mmsi'],0,3) == '669') $result['mmsi'] = '3'.$result['mmsi'];
787
+		if (strlen($result['mmsi']) == 8 && susbtr($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->type != '') $result['type'] = $data->type;
631
-		if ($data->imo != '') $result['imo'] = $data->imo;
632
-		if ($data->callsign != '') $result['callsign'] = $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->type != '') {
803
+			$result['type'] = $data->type;
804
+		}
805
+		if ($data->imo != '') {
806
+			$result['imo'] = $data->imo;
807
+		}
808
+		if ($data->callsign != '') {
809
+			$result['callsign'] = $data->callsign;
810
+		}
633 811
 		if ($data->eta_month != '' && $data->eta_day != '' && $data->eta_hour != '' && $data->eta_minute != '') {
634 812
 			$result['eta_ts'] = strtotime(date('Y').'-'.$data->eta_month.'-'.$data->eta_day.' '.$data->eta_hour.':'.$data->eta_minute.':00');
635 813
 		}
636
-		if ($data->destination != '') $result['destination'] = $data->destination;
814
+		if ($data->destination != '') {
815
+			$result['destination'] = $data->destination;
816
+		}
637 817
 		$result['all'] = (array) $data;
638 818
 		/*
639 819
 		    $ro->cls = 0; // AIS class undefined, also indicate unparsed msg
Please login to merge, or discard this patch.
require/class.Marine.php 4 patches
Doc Comments   +2 added lines, -21 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 	/**
16 16
 	* Get SQL query part for filter used
17 17
 	* @param Array $filter the filter
18
-	* @return Array the SQL part
18
+	* @return string the SQL part
19 19
 	*/
20 20
 	
21 21
 	public function getFilter($filter = array(),$where = false,$and = false) {
@@ -552,25 +552,6 @@  discard block
 block discarded – undo
552 552
 	*
553 553
 	* @param String $fammarine_id the ID
554 554
 	* @param String $ident the marine ident
555
-	* @param String $departure_airport_icao the departure airport
556
-	* @param String $arrival_airport_icao the arrival airport
557
-	* @param String $latitude latitude of flight
558
-	* @param String $longitude latitude of flight
559
-	* @param String $waypoints waypoints of flight
560
-	* @param String $heading heading of flight
561
-	* @param String $groundspeed speed of flight
562
-	* @param String $date date of flight
563
-	* @param String $departure_airport_time departure time of flight
564
-	* @param String $arrival_airport_time arrival time of flight
565
-	* @param String $squawk squawk code of flight
566
-	* @param String $route_stop route stop of flight
567
-	* @param String $highlight highlight or not
568
-	* @param String $ModeS ModesS code of flight
569
-	* @param String $registration registration code of flight
570
-	* @param String $pilot_id pilot id of flight (for virtual airlines)
571
-	* @param String $pilot_name pilot name of flight (for virtual airlines)
572
-	* @param String $verticalrate vertival rate of flight
573
-	* @return String success or false
574 555
 	*/
575 556
 	public function addMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $mmsi = '',$type = '',$imo = '',$callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$format_source = '', $source_name = '')
576 557
 	{
@@ -1444,7 +1425,7 @@  discard block
 block discarded – undo
1444 1425
 	/**
1445 1426
 	* Parses the direction degrees to working
1446 1427
 	*
1447
-	* @param Float $direction the direction in degrees
1428
+	* @param integer $direction the direction in degrees
1448 1429
 	* @return Array the direction information
1449 1430
 	*
1450 1431
 	*/
Please login to merge, or discard this patch.
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -13,10 +13,10 @@  discard block
 block discarded – undo
13 13
 	}
14 14
 
15 15
 	/**
16
-	* Get SQL query part for filter used
17
-	* @param Array $filter the filter
18
-	* @return Array the SQL part
19
-	*/
16
+	 * Get SQL query part for filter used
17
+	 * @param Array $filter the filter
18
+	 * @return Array the SQL part
19
+	 */
20 20
 	
21 21
 	public function getFilter($filter = array(),$where = false,$and = false) {
22 22
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
@@ -80,14 +80,14 @@  discard block
 block discarded – undo
80 80
 	}
81 81
 
82 82
 	/**
83
-	* Executes the SQL statements to get the spotter information
84
-	*
85
-	* @param String $query the SQL query
86
-	* @param Array $params parameter of the query
87
-	* @param String $limitQuery the limit query
88
-	* @return Array the spotter information
89
-	*
90
-	*/
83
+	 * Executes the SQL statements to get the spotter information
84
+	 *
85
+	 * @param String $query the SQL query
86
+	 * @param Array $params parameter of the query
87
+	 * @param String $limitQuery the limit query
88
+	 * @return Array the spotter information
89
+	 *
90
+	 */
91 91
 	public function getDataFromDB($query, $params = array(), $limitQuery = '',$schedules = false)
92 92
 	{
93 93
 		date_default_timezone_set('UTC');
@@ -199,11 +199,11 @@  discard block
 block discarded – undo
199 199
 	
200 200
 	
201 201
 	/**
202
-	* Gets all the spotter information based on the latest data entry
203
-	*
204
-	* @return Array the spotter information
205
-	*
206
-	*/
202
+	 * Gets all the spotter information based on the latest data entry
203
+	 *
204
+	 * @return Array the spotter information
205
+	 *
206
+	 */
207 207
 	public function getLatestMarineData($limit = '', $sort = '', $filter = array())
208 208
 	{
209 209
 		global $global_query;
@@ -261,11 +261,11 @@  discard block
 block discarded – undo
261 261
 	}
262 262
 
263 263
 	/**
264
-	* Gets all the spotter information based on the callsign
265
-	*
266
-	* @return Array the spotter information
267
-	*
268
-	*/
264
+	 * Gets all the spotter information based on the callsign
265
+	 *
266
+	 * @return Array the spotter information
267
+	 *
268
+	 */
269 269
 	public function getMarineDataByIdent($ident = '', $limit = '', $sort = '', $filter = array())
270 270
 	{
271 271
 		global $global_query;
@@ -376,12 +376,12 @@  discard block
 block discarded – undo
376 376
 
377 377
 
378 378
 	/**
379
-	* Gets all source name
380
-	*
381
-	* @param String type format of source
382
-	* @return Array list of source name
383
-	*
384
-	*/
379
+	 * Gets all source name
380
+	 *
381
+	 * @param String type format of source
382
+	 * @return Array list of source name
383
+	 *
384
+	 */
385 385
 	public function getAllSourceName($type = '',$filters = array())
386 386
 	{
387 387
 		$filter_query = $this->getFilter($filters,true,true);
@@ -411,11 +411,11 @@  discard block
 block discarded – undo
411 411
 
412 412
 
413 413
 	/**
414
-	* Gets a list of all idents/callsigns
415
-	*
416
-	* @return Array list of ident/callsign names
417
-	*
418
-	*/
414
+	 * Gets a list of all idents/callsigns
415
+	 *
416
+	 * @return Array list of ident/callsign names
417
+	 *
418
+	 */
419 419
 	public function getAllIdents($filters = array())
420 420
 	{
421 421
 		$filter_query = $this->getFilter($filters,true,true);
@@ -439,11 +439,11 @@  discard block
 block discarded – undo
439 439
 	}
440 440
 
441 441
 	/**
442
-	* Gets all info from a mmsi
443
-	*
444
-	* @return Array list of mmsi info
445
-	*
446
-	*/
442
+	 * Gets all info from a mmsi
443
+	 *
444
+	 * @return Array list of mmsi info
445
+	 *
446
+	 */
447 447
 	public function getIdentity($mmsi)
448 448
 	{
449 449
 		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
@@ -500,18 +500,18 @@  discard block
 block discarded – undo
500 500
 	
501 501
 	
502 502
 	/**
503
-	* Update ident tracker data
504
-	*
505
-	* @param String $fammarine_id the ID
506
-	* @param String $ident the marine ident
507
-	* @return String success or false
508
-	*
509
-	*/	
503
+	 * Update ident tracker data
504
+	 *
505
+	 * @param String $fammarine_id the ID
506
+	 * @param String $ident the marine ident
507
+	 * @return String success or false
508
+	 *
509
+	 */	
510 510
 	public function updateIdentMarineData($fammarine_id = '', $ident = '',$fromsource = NULL)
511 511
 	{
512 512
 
513 513
 		$query = 'UPDATE marine_output SET ident = :ident WHERE fammarine_id = :fammarine_id';
514
-                $query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident);
514
+				$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident);
515 515
 
516 516
 		try {
517 517
 			$sth = $this->db->prepare($query);
@@ -524,17 +524,17 @@  discard block
 block discarded – undo
524 524
 
525 525
 	}
526 526
 	/**
527
-	* Update latest marine data
528
-	*
529
-	* @param String $fammarine_id the ID
530
-	* @param String $ident the marine ident
531
-	* @return String success or false
532
-	*
533
-	*/	
527
+	 * Update latest marine data
528
+	 *
529
+	 * @param String $fammarine_id the ID
530
+	 * @param String $ident the marine ident
531
+	 * @return String success or false
532
+	 *
533
+	 */	
534 534
 	public function updateLatestMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $groundspeed = NULL, $date = '')
535 535
 	{
536 536
 		$query = 'UPDATE marine_output SET ident = :ident, last_latitude = :last_latitude, last_longitude = :last_longitude, last_seen = :last_seen, last_ground_speed = :last_ground_speed WHERE fammarine_id = :fammarine_id';
537
-                $query_values = array(':fammarine_id' => $fammarine_id,':last_latitude' => $latitude,':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed,':last_seen' => $date,':ident' => $ident);
537
+				$query_values = array(':fammarine_id' => $fammarine_id,':last_latitude' => $latitude,':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed,':last_seen' => $date,':ident' => $ident);
538 538
 
539 539
 		try {
540 540
 			$sth = $this->db->prepare($query);
@@ -548,30 +548,30 @@  discard block
 block discarded – undo
548 548
 	}
549 549
 
550 550
 	/**
551
-	* Adds a new spotter data
552
-	*
553
-	* @param String $fammarine_id the ID
554
-	* @param String $ident the marine ident
555
-	* @param String $departure_airport_icao the departure airport
556
-	* @param String $arrival_airport_icao the arrival airport
557
-	* @param String $latitude latitude of flight
558
-	* @param String $longitude latitude of flight
559
-	* @param String $waypoints waypoints of flight
560
-	* @param String $heading heading of flight
561
-	* @param String $groundspeed speed of flight
562
-	* @param String $date date of flight
563
-	* @param String $departure_airport_time departure time of flight
564
-	* @param String $arrival_airport_time arrival time of flight
565
-	* @param String $squawk squawk code of flight
566
-	* @param String $route_stop route stop of flight
567
-	* @param String $highlight highlight or not
568
-	* @param String $ModeS ModesS code of flight
569
-	* @param String $registration registration code of flight
570
-	* @param String $pilot_id pilot id of flight (for virtual airlines)
571
-	* @param String $pilot_name pilot name of flight (for virtual airlines)
572
-	* @param String $verticalrate vertival rate of flight
573
-	* @return String success or false
574
-	*/
551
+	 * Adds a new spotter data
552
+	 *
553
+	 * @param String $fammarine_id the ID
554
+	 * @param String $ident the marine ident
555
+	 * @param String $departure_airport_icao the departure airport
556
+	 * @param String $arrival_airport_icao the arrival airport
557
+	 * @param String $latitude latitude of flight
558
+	 * @param String $longitude latitude of flight
559
+	 * @param String $waypoints waypoints of flight
560
+	 * @param String $heading heading of flight
561
+	 * @param String $groundspeed speed of flight
562
+	 * @param String $date date of flight
563
+	 * @param String $departure_airport_time departure time of flight
564
+	 * @param String $arrival_airport_time arrival time of flight
565
+	 * @param String $squawk squawk code of flight
566
+	 * @param String $route_stop route stop of flight
567
+	 * @param String $highlight highlight or not
568
+	 * @param String $ModeS ModesS code of flight
569
+	 * @param String $registration registration code of flight
570
+	 * @param String $pilot_id pilot id of flight (for virtual airlines)
571
+	 * @param String $pilot_name pilot name of flight (for virtual airlines)
572
+	 * @param String $verticalrate vertival rate of flight
573
+	 * @return String success or false
574
+	 */
575 575
 	public function addMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $mmsi = '',$type = '',$imo = '',$callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$format_source = '', $source_name = '')
576 576
 	{
577 577
 		global $globalURL;
@@ -659,13 +659,13 @@  discard block
 block discarded – undo
659 659
 		$arrival_code = filter_var($arrival_code,FILTER_SANITIZE_STRING);
660 660
 		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING);
661 661
 	
662
-                if ($latitude == '' && $longitude == '') {
663
-            		$latitude = 0;
664
-            		$longitude = 0;
665
-            	}
666
-                if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
667
-                if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
668
-                if ($arrival_date == '') $arrival_date = NULL;
662
+				if ($latitude == '' && $longitude == '') {
663
+					$latitude = 0;
664
+					$longitude = 0;
665
+				}
666
+				if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
667
+				if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
668
+				if ($arrival_date == '') $arrival_date = NULL;
669 669
 		$query  = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo,arrival_port_name,arrival_port_date) 
670 670
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:speed,:date,:format_source, :source_name,:mmsi,:type,:status,:imo,:arrival_port_name,:arrival_port_date)";
671 671
 
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 			$sth->execute($query_values);
677 677
 			$this->db = null;
678 678
 		} catch (PDOException $e) {
679
-		    return "error : ".$e->getMessage();
679
+			return "error : ".$e->getMessage();
680 680
 		}
681 681
 		
682 682
 		return "success";
@@ -685,11 +685,11 @@  discard block
 block discarded – undo
685 685
 	
686 686
   
687 687
 	/**
688
-	* Gets the aircraft ident within the last hour
689
-	*
690
-	* @return String the ident
691
-	*
692
-	*/
688
+	 * Gets the aircraft ident within the last hour
689
+	 *
690
+	 * @return String the ident
691
+	 *
692
+	 */
693 693
 	public function getIdentFromLastHour($ident)
694 694
 	{
695 695
 		global $globalDBdriver, $globalTimezone;
@@ -705,11 +705,11 @@  discard block
 block discarded – undo
705 705
 								AND marine_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
706 706
 								AND marine_output.date < now() AT TIME ZONE 'UTC'";
707 707
 			$query_data = array(':ident' => $ident);
708
-    		}
708
+			}
709 709
 		
710 710
 		$sth = $this->db->prepare($query);
711 711
 		$sth->execute($query_data);
712
-    		$ident_result='';
712
+			$ident_result='';
713 713
 		while($row = $sth->fetch(PDO::FETCH_ASSOC))
714 714
 		{
715 715
 			$ident_result = $row['ident'];
@@ -720,11 +720,11 @@  discard block
 block discarded – undo
720 720
 	
721 721
 	
722 722
 	/**
723
-	* Gets the aircraft data from the last 20 seconds
724
-	*
725
-	* @return Array the spotter data
726
-	*
727
-	*/
723
+	 * Gets the aircraft data from the last 20 seconds
724
+	 *
725
+	 * @return Array the spotter data
726
+	 *
727
+	 */
728 728
 	public function getRealTimeData($q = '')
729 729
 	{
730 730
 		global $globalDBdriver;
@@ -762,11 +762,11 @@  discard block
 block discarded – undo
762 762
 	
763 763
 
764 764
 	/**
765
-	* Gets all number of flight over countries
766
-	*
767
-	* @return Array the airline country list
768
-	*
769
-	*/
765
+	 * Gets all number of flight over countries
766
+	 *
767
+	 * @return Array the airline country list
768
+	 *
769
+	 */
770 770
 /*
771 771
 	public function countAllTrackedOverCountries($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array())
772 772
 	{
@@ -817,11 +817,11 @@  discard block
 block discarded – undo
817 817
 	
818 818
 	
819 819
 	/**
820
-	* Gets all callsigns that have flown over
821
-	*
822
-	* @return Array the callsign list
823
-	*
824
-	*/
820
+	 * Gets all callsigns that have flown over
821
+	 *
822
+	 * @return Array the callsign list
823
+	 *
824
+	 */
825 825
 	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array(),$year = '', $month = '', $day = '')
826 826
 	{
827 827
 		global $globalDBdriver;
@@ -888,11 +888,11 @@  discard block
 block discarded – undo
888 888
 
889 889
 
890 890
 	/**
891
-	* Counts all dates
892
-	*
893
-	* @return Array the date list
894
-	*
895
-	*/
891
+	 * Counts all dates
892
+	 *
893
+	 * @return Array the date list
894
+	 *
895
+	 */
896 896
 	public function countAllDates($filters = array())
897 897
 	{
898 898
 		global $globalTimezone, $globalDBdriver;
@@ -938,11 +938,11 @@  discard block
 block discarded – undo
938 938
 	
939 939
 	
940 940
 	/**
941
-	* Counts all dates during the last 7 days
942
-	*
943
-	* @return Array the date list
944
-	*
945
-	*/
941
+	 * Counts all dates during the last 7 days
942
+	 *
943
+	 * @return Array the date list
944
+	 *
945
+	 */
946 946
 	public function countAllDatesLast7Days($filters = array())
947 947
 	{
948 948
 		global $globalTimezone, $globalDBdriver;
@@ -964,7 +964,7 @@  discard block
 block discarded – undo
964 964
 			$query .= " GROUP BY date_name 
965 965
 								ORDER BY date_name ASC";
966 966
 			$query_data = array(':offset' => $offset);
967
-    		}
967
+			}
968 968
 		
969 969
 		$sth = $this->db->prepare($query);
970 970
 		$sth->execute($query_data);
@@ -984,11 +984,11 @@  discard block
 block discarded – undo
984 984
 	}
985 985
 
986 986
 	/**
987
-	* Counts all dates during the last month
988
-	*
989
-	* @return Array the date list
990
-	*
991
-	*/
987
+	 * Counts all dates during the last month
988
+	 *
989
+	 * @return Array the date list
990
+	 *
991
+	 */
992 992
 	public function countAllDatesLastMonth($filters = array())
993 993
 	{
994 994
 		global $globalTimezone, $globalDBdriver;
@@ -1010,7 +1010,7 @@  discard block
 block discarded – undo
1010 1010
 			$query .= " GROUP BY date_name 
1011 1011
 								ORDER BY date_name ASC";
1012 1012
 			$query_data = array(':offset' => $offset);
1013
-    		}
1013
+			}
1014 1014
 		
1015 1015
 		$sth = $this->db->prepare($query);
1016 1016
 		$sth->execute($query_data);
@@ -1032,11 +1032,11 @@  discard block
 block discarded – undo
1032 1032
 
1033 1033
 
1034 1034
 	/**
1035
-	* Counts all month
1036
-	*
1037
-	* @return Array the month list
1038
-	*
1039
-	*/
1035
+	 * Counts all month
1036
+	 *
1037
+	 * @return Array the month list
1038
+	 *
1039
+	 */
1040 1040
 	public function countAllMonths($filters = array())
1041 1041
 	{
1042 1042
 		global $globalTimezone, $globalDBdriver;
@@ -1081,11 +1081,11 @@  discard block
 block discarded – undo
1081 1081
 	
1082 1082
 
1083 1083
 	/**
1084
-	* Counts all dates during the last year
1085
-	*
1086
-	* @return Array the date list
1087
-	*
1088
-	*/
1084
+	 * Counts all dates during the last year
1085
+	 *
1086
+	 * @return Array the date list
1087
+	 *
1088
+	 */
1089 1089
 	public function countAllMonthsLastYear($filters)
1090 1090
 	{
1091 1091
 		global $globalTimezone, $globalDBdriver;
@@ -1107,7 +1107,7 @@  discard block
 block discarded – undo
1107 1107
 			$query .= " GROUP BY year_name, month_name
1108 1108
 								ORDER BY year_name, month_name ASC";
1109 1109
 			$query_data = array(':offset' => $offset);
1110
-    		}
1110
+			}
1111 1111
 		
1112 1112
 		$sth = $this->db->prepare($query);
1113 1113
 		$sth->execute($query_data);
@@ -1130,11 +1130,11 @@  discard block
 block discarded – undo
1130 1130
 	
1131 1131
 	
1132 1132
 	/**
1133
-	* Counts all hours
1134
-	*
1135
-	* @return Array the hour list
1136
-	*
1137
-	*/
1133
+	 * Counts all hours
1134
+	 *
1135
+	 * @return Array the hour list
1136
+	 *
1137
+	 */
1138 1138
 	public function countAllHours($orderby,$filters = array())
1139 1139
 	{
1140 1140
 		global $globalTimezone, $globalDBdriver;
@@ -1197,11 +1197,11 @@  discard block
 block discarded – undo
1197 1197
 	
1198 1198
 	
1199 1199
 	/**
1200
-	* Counts all hours by date
1201
-	*
1202
-	* @return Array the hour list
1203
-	*
1204
-	*/
1200
+	 * Counts all hours by date
1201
+	 *
1202
+	 * @return Array the hour list
1203
+	 *
1204
+	 */
1205 1205
 	public function countAllHoursByDate($date, $filters = array())
1206 1206
 	{
1207 1207
 		global $globalTimezone, $globalDBdriver;
@@ -1245,11 +1245,11 @@  discard block
 block discarded – undo
1245 1245
 	
1246 1246
 	
1247 1247
 	/**
1248
-	* Counts all hours by a ident/callsign
1249
-	*
1250
-	* @return Array the hour list
1251
-	*
1252
-	*/
1248
+	 * Counts all hours by a ident/callsign
1249
+	 *
1250
+	 * @return Array the hour list
1251
+	 *
1252
+	 */
1253 1253
 	public function countAllHoursByIdent($ident, $filters = array())
1254 1254
 	{
1255 1255
 		global $globalTimezone, $globalDBdriver;
@@ -1294,11 +1294,11 @@  discard block
 block discarded – undo
1294 1294
 	
1295 1295
 	
1296 1296
 	/**
1297
-	* Counts all flights that have flown over
1298
-	*
1299
-	* @return Integer the number of flights
1300
-	*
1301
-	*/
1297
+	 * Counts all flights that have flown over
1298
+	 *
1299
+	 * @return Integer the number of flights
1300
+	 *
1301
+	 */
1302 1302
 	public function countOverallTracked($filters = array(),$year = '',$month = '')
1303 1303
 	{
1304 1304
 		global $globalDBdriver;
@@ -1333,11 +1333,11 @@  discard block
 block discarded – undo
1333 1333
 	
1334 1334
   
1335 1335
 	/**
1336
-	* Counts all hours of today
1337
-	*
1338
-	* @return Array the hour list
1339
-	*
1340
-	*/
1336
+	 * Counts all hours of today
1337
+	 *
1338
+	 * @return Array the hour list
1339
+	 *
1340
+	 */
1341 1341
 	public function countAllHoursFromToday($filters = array())
1342 1342
 	{
1343 1343
 		global $globalTimezone, $globalDBdriver;
@@ -1377,12 +1377,12 @@  discard block
 block discarded – undo
1377 1377
 	}
1378 1378
     
1379 1379
     
1380
-     /**
1381
-	* Gets the Barrie Spotter ID based on the FlightAware ID
1382
-	*
1383
-	* @return Integer the Barrie Spotter ID
1380
+	 /**
1381
+	  * Gets the Barrie Spotter ID based on the FlightAware ID
1382
+	  *
1383
+	  * @return Integer the Barrie Spotter ID
1384 1384
 q	*
1385
-	*/
1385
+	  */
1386 1386
 	public function getMarineIDBasedOnFamMarineID($fammarine_id)
1387 1387
 	{
1388 1388
 		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
@@ -1403,13 +1403,13 @@  discard block
 block discarded – undo
1403 1403
   
1404 1404
  
1405 1405
 	/**
1406
-	* Parses a date string
1407
-	*
1408
-	* @param String $dateString the date string
1409
-	* @param String $timezone the timezone of a user
1410
-	* @return Array the time information
1411
-	*
1412
-	*/
1406
+	 * Parses a date string
1407
+	 *
1408
+	 * @param String $dateString the date string
1409
+	 * @param String $timezone the timezone of a user
1410
+	 * @return Array the time information
1411
+	 *
1412
+	 */
1413 1413
 	public function parseDateString($dateString, $timezone = '')
1414 1414
 	{
1415 1415
 		$time_array = array();
@@ -1442,12 +1442,12 @@  discard block
 block discarded – undo
1442 1442
 	}
1443 1443
 	
1444 1444
 	/**
1445
-	* Parses the direction degrees to working
1446
-	*
1447
-	* @param Float $direction the direction in degrees
1448
-	* @return Array the direction information
1449
-	*
1450
-	*/
1445
+	 * Parses the direction degrees to working
1446
+	 *
1447
+	 * @param Float $direction the direction in degrees
1448
+	 * @return Array the direction information
1449
+	 *
1450
+	 */
1451 1451
 	public function parseDirection($direction = 0)
1452 1452
 	{
1453 1453
 		if ($direction == '') $direction = 0;
@@ -1526,12 +1526,12 @@  discard block
 block discarded – undo
1526 1526
 	
1527 1527
 	
1528 1528
 	/**
1529
-	* Gets Country from latitude/longitude
1530
-	*
1531
-	* @param Float $latitude latitute of the flight
1532
-	* @param Float $longitude longitute of the flight
1533
-	* @return String the countrie
1534
-	*/
1529
+	 * Gets Country from latitude/longitude
1530
+	 *
1531
+	 * @param Float $latitude latitute of the flight
1532
+	 * @param Float $longitude longitute of the flight
1533
+	 * @return String the countrie
1534
+	 */
1535 1535
 	public function getCountryFromLatitudeLongitude($latitude,$longitude)
1536 1536
 	{
1537 1537
 		global $globalDBdriver, $globalDebug;
@@ -1568,11 +1568,11 @@  discard block
 block discarded – undo
1568 1568
 	}
1569 1569
 
1570 1570
 	/**
1571
-	* Gets Country from iso2
1572
-	*
1573
-	* @param String $iso2 ISO2 country code
1574
-	* @return String the countrie
1575
-	*/
1571
+	 * Gets Country from iso2
1572
+	 *
1573
+	 * @param String $iso2 ISO2 country code
1574
+	 * @return String the countrie
1575
+	 */
1576 1576
 	public function getCountryFromISO2($iso2)
1577 1577
 	{
1578 1578
 		global $globalDBdriver, $globalDebug;
@@ -1601,12 +1601,12 @@  discard block
 block discarded – undo
1601 1601
 
1602 1602
 	
1603 1603
 	/**
1604
-	* Gets the short url from bit.ly
1605
-	*
1606
-	* @param String $url the full url
1607
-	* @return String the bit.ly url
1608
-	*
1609
-	*/
1604
+	 * Gets the short url from bit.ly
1605
+	 *
1606
+	 * @param String $url the full url
1607
+	 * @return String the bit.ly url
1608
+	 *
1609
+	 */
1610 1610
 	public function getBitlyURL($url)
1611 1611
 	{
1612 1612
 		global $globalBitlyAccessToken;
Please login to merge, or discard this patch.
Spacing   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 require_once(dirname(__FILE__).'/class.Image.php');
5 5
 $global_query = "SELECT marine_output.* FROM marine_output";
6 6
 
7
-class Marine{
7
+class Marine {
8 8
 	public $db;
9 9
 	
10 10
 	public function __construct($dbc = null) {
@@ -18,33 +18,33 @@  discard block
 block discarded – undo
18 18
 	* @return Array the SQL part
19 19
 	*/
20 20
 	
21
-	public function getFilter($filter = array(),$where = false,$and = false) {
21
+	public function getFilter($filter = array(), $where = false, $and = false) {
22 22
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
23 23
 		$filters = array();
24 24
 		if (is_array($globalStatsFilters) && isset($globalStatsFilters[$globalFilterName])) {
25 25
 			if (isset($globalStatsFilters[$globalFilterName][0]['source'])) {
26 26
 				$filters = $globalStatsFilters[$globalFilterName];
27 27
 			} else {
28
-				$filter = array_merge($filter,$globalStatsFilters[$globalFilterName]);
28
+				$filter = array_merge($filter, $globalStatsFilters[$globalFilterName]);
29 29
 			}
30 30
 		}
31 31
 		if (isset($filter[0]['source'])) {
32
-			$filters = array_merge($filters,$filter);
32
+			$filters = array_merge($filters, $filter);
33 33
 		}
34
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
34
+		if (is_array($globalFilter)) $filter = array_merge($filter, $globalFilter);
35 35
 		$filter_query_join = '';
36 36
 		$filter_query_where = '';
37
-		foreach($filters as $flt) {
37
+		foreach ($filters as $flt) {
38 38
 			if (isset($flt['idents']) && !empty($flt['idents'])) {
39 39
 				if (isset($flt['source'])) {
40
-					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','",$flt['idents'])."') AND spotter_output.format_source IN ('".implode("','",$flt['source'])."')) spfi ON spfi.fammarine_id = marine_output.fammarine_id";
40
+					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','", $flt['idents'])."') AND spotter_output.format_source IN ('".implode("','", $flt['source'])."')) spfi ON spfi.fammarine_id = marine_output.fammarine_id";
41 41
 				} else {
42
-					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','",$flt['idents'])."')) spfi ON spfi.fammarine_id = marine_output.fammarine_id";
42
+					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','", $flt['idents'])."')) spfi ON spfi.fammarine_id = marine_output.fammarine_id";
43 43
 				}
44 44
 			}
45 45
 		}
46 46
 		if (isset($filter['source']) && !empty($filter['source'])) {
47
-			$filter_query_where .= " AND format_source IN ('".implode("','",$filter['source'])."')";
47
+			$filter_query_where .= " AND format_source IN ('".implode("','", $filter['source'])."')";
48 48
 		}
49 49
 		if (isset($filter['ident']) && !empty($filter['ident'])) {
50 50
 			$filter_query_where .= " AND ident = '".$filter['ident']."'";
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
74 74
 		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
75 75
 		if ($filter_query_where != '') {
76
-			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
76
+			$filter_query_where = preg_replace('/^ AND/', ' WHERE', $filter_query_where);
77 77
 		}
78 78
 		$filter_query = $filter_query_join.$filter_query_where;
79 79
 		return $filter_query;
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	* @return Array the spotter information
89 89
 	*
90 90
 	*/
91
-	public function getDataFromDB($query, $params = array(), $limitQuery = '',$schedules = false)
91
+	public function getDataFromDB($query, $params = array(), $limitQuery = '', $schedules = false)
92 92
 	{
93 93
 		date_default_timezone_set('UTC');
94 94
 		if (!is_string($query))
@@ -108,13 +108,13 @@  discard block
 block discarded – undo
108 108
 			$sth = $this->db->prepare($query.$limitQuery);
109 109
 			$sth->execute($params);
110 110
 		} catch (PDOException $e) {
111
-			printf("Invalid query : %s\nWhole query: %s\n",$e->getMessage(), $query.$limitQuery);
111
+			printf("Invalid query : %s\nWhole query: %s\n", $e->getMessage(), $query.$limitQuery);
112 112
 			exit();
113 113
 		}
114 114
 		
115 115
 		$num_rows = 0;
116 116
 		$spotter_array = array();
117
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
117
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
118 118
 		{
119 119
 			$num_rows++;
120 120
 			$temp_array = array();
@@ -169,17 +169,17 @@  discard block
 block discarded – undo
169 169
 				{
170 170
 					$temp_array['date'] = "about ".$dateArray['hours']." hours ago";
171 171
 				} else {
172
-					$temp_array['date'] = date("M j Y, g:i a",strtotime($row['date']." UTC"));
172
+					$temp_array['date'] = date("M j Y, g:i a", strtotime($row['date']." UTC"));
173 173
 				}
174 174
 				$temp_array['date_minutes_past'] = $dateArray['minutes'];
175
-				$temp_array['date_iso_8601'] = date("c",strtotime($row['date']." UTC"));
176
-				$temp_array['date_rfc_2822'] = date("r",strtotime($row['date']." UTC"));
175
+				$temp_array['date_iso_8601'] = date("c", strtotime($row['date']." UTC"));
176
+				$temp_array['date_rfc_2822'] = date("r", strtotime($row['date']." UTC"));
177 177
 				$temp_array['date_unix'] = strtotime($row['date']." UTC");
178 178
 				if (isset($row['last_seen']) && $row['last_seen'] != '') {
179 179
 					if (strtotime($row['last_seen']) > strtotime($row['date'])) {
180 180
 						$temp_array['duration'] = strtotime($row['last_seen']) - strtotime($row['date']);
181
-						$temp_array['last_seen_date_iso_8601'] = date("c",strtotime($row['last_seen']." UTC"));
182
-						$temp_array['last_seen_date_rfc_2822'] = date("r",strtotime($row['last_seen']." UTC"));
181
+						$temp_array['last_seen_date_iso_8601'] = date("c", strtotime($row['last_seen']." UTC"));
182
+						$temp_array['last_seen_date_rfc_2822'] = date("r", strtotime($row['last_seen']." UTC"));
183 183
 						$temp_array['last_seen_date_unix'] = strtotime($row['last_seen']." UTC");
184 184
 					}
185 185
 				}
@@ -216,8 +216,8 @@  discard block
 block discarded – undo
216 216
 		{
217 217
 			$limit_array = explode(",", $limit);
218 218
 			
219
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
220
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
219
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
220
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
221 221
 			
222 222
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
223 223
 			{
@@ -234,9 +234,9 @@  discard block
 block discarded – undo
234 234
 			$orderby_query = " ORDER BY marine_output.date DESC";
235 235
 		}
236 236
 
237
-		$query  = $global_query.$filter_query." ".$orderby_query;
237
+		$query = $global_query.$filter_query." ".$orderby_query;
238 238
 
239
-		$spotter_array = $this->getDataFromDB($query, array(),$limit_query,true);
239
+		$spotter_array = $this->getDataFromDB($query, array(), $limit_query, true);
240 240
 
241 241
 		return $spotter_array;
242 242
 	}
@@ -255,8 +255,8 @@  discard block
 block discarded – undo
255 255
 		if ($id == '') return array();
256 256
 		$additional_query = "marine_output.fammarine_id = :id";
257 257
 		$query_values = array(':id' => $id);
258
-		$query  = $global_query." WHERE ".$additional_query." ";
259
-		$spotter_array = $this->getDataFromDB($query,$query_values);
258
+		$query = $global_query." WHERE ".$additional_query." ";
259
+		$spotter_array = $this->getDataFromDB($query, $query_values);
260 260
 		return $spotter_array;
261 261
 	}
262 262
 
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 		$query_values = array();
276 276
 		$limit_query = '';
277 277
 		$additional_query = '';
278
-		$filter_query = $this->getFilter($filter,true,true);
278
+		$filter_query = $this->getFilter($filter, true, true);
279 279
 		if ($ident != "")
280 280
 		{
281 281
 			if (!is_string($ident))
@@ -291,8 +291,8 @@  discard block
 block discarded – undo
291 291
 		{
292 292
 			$limit_array = explode(",", $limit);
293 293
 			
294
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
295
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
294
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
295
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
296 296
 			
297 297
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
298 298
 			{
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 		return $spotter_array;
317 317
 	}
318 318
 	
319
-	public function getSpotterDataByDate($date = '', $limit = '', $sort = '',$filter = array())
319
+	public function getSpotterDataByDate($date = '', $limit = '', $sort = '', $filter = array())
320 320
 	{
321 321
 		global $global_query, $globalTimezone, $globalDBdriver;
322 322
 		
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 		$limit_query = '';
325 325
 		$additional_query = '';
326 326
 
327
-		$filter_query = $this->getFilter($filter,true,true);
327
+		$filter_query = $this->getFilter($filter, true, true);
328 328
 		
329 329
 		if ($date != "")
330 330
 		{
@@ -350,8 +350,8 @@  discard block
 block discarded – undo
350 350
 		{
351 351
 			$limit_array = explode(",", $limit);
352 352
 			
353
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
354
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
353
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
354
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
355 355
 			
356 356
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
357 357
 			{
@@ -382,11 +382,11 @@  discard block
 block discarded – undo
382 382
 	* @return Array list of source name
383 383
 	*
384 384
 	*/
385
-	public function getAllSourceName($type = '',$filters = array())
385
+	public function getAllSourceName($type = '', $filters = array())
386 386
 	{
387
-		$filter_query = $this->getFilter($filters,true,true);
387
+		$filter_query = $this->getFilter($filters, true, true);
388 388
 		$query_values = array();
389
-		$query  = "SELECT DISTINCT marine_output.source_name 
389
+		$query = "SELECT DISTINCT marine_output.source_name 
390 390
 				FROM marine_output".$filter_query." marine_output.source_name <> ''";
391 391
 		if ($type != '') {
392 392
 			$query_values = array(':type' => $type);
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
 		$source_array = array();
402 402
 		$temp_array = array();
403 403
 		
404
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
404
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
405 405
 		{
406 406
 			$temp_array['source_name'] = $row['source_name'];
407 407
 			$source_array[] = $temp_array;
@@ -418,8 +418,8 @@  discard block
 block discarded – undo
418 418
 	*/
419 419
 	public function getAllIdents($filters = array())
420 420
 	{
421
-		$filter_query = $this->getFilter($filters,true,true);
422
-		$query  = "SELECT DISTINCT marine_output.ident
421
+		$filter_query = $this->getFilter($filters, true, true);
422
+		$query = "SELECT DISTINCT marine_output.ident
423 423
 								FROM marine_output".$filter_query." marine_output.ident <> '' 
424 424
 								ORDER BY marine_output.date ASC LIMIT 700 OFFSET 0";
425 425
 
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
 		$ident_array = array();
430 430
 		$temp_array = array();
431 431
 		
432
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
432
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
433 433
 		{
434 434
 			$temp_array['ident'] = $row['ident'];
435 435
 			$ident_array[] = $temp_array;
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
 	*/
447 447
 	public function getIdentity($mmsi)
448 448
 	{
449
-		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
449
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_NUMBER_INT);
450 450
 		$query  = "SELECT * FROM marine_identity WHERE mmsi = :mmsi LIMIT 1";
451 451
 		$sth = $this->db->prepare($query);
452 452
 		$sth->execute(array(':mmsi' => $mmsi));
@@ -471,12 +471,12 @@  discard block
 block discarded – undo
471 471
 		} else $offset = '+00:00';
472 472
 
473 473
 		if ($globalDBdriver == 'mysql') {
474
-			$query  = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date
474
+			$query = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date
475 475
 								FROM marine_output
476 476
 								WHERE marine_output.date <> '' 
477 477
 								ORDER BY marine_output.date ASC LIMIT 0,200";
478 478
 		} else {
479
-			$query  = "SELECT DISTINCT to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date
479
+			$query = "SELECT DISTINCT to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date
480 480
 								FROM marine_output
481 481
 								WHERE marine_output.date <> '' 
482 482
 								ORDER BY marine_output.date ASC LIMIT 0,200";
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
 		$date_array = array();
489 489
 		$temp_array = array();
490 490
 		
491
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
491
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
492 492
 		{
493 493
 			$temp_array['date'] = $row['date'];
494 494
 
@@ -507,11 +507,11 @@  discard block
 block discarded – undo
507 507
 	* @return String success or false
508 508
 	*
509 509
 	*/	
510
-	public function updateIdentMarineData($fammarine_id = '', $ident = '',$fromsource = NULL)
510
+	public function updateIdentMarineData($fammarine_id = '', $ident = '', $fromsource = NULL)
511 511
 	{
512 512
 
513 513
 		$query = 'UPDATE marine_output SET ident = :ident WHERE fammarine_id = :fammarine_id';
514
-                $query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident);
514
+                $query_values = array(':fammarine_id' => $fammarine_id, ':ident' => $ident);
515 515
 
516 516
 		try {
517 517
 			$sth = $this->db->prepare($query);
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
 	public function updateLatestMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $groundspeed = NULL, $date = '')
535 535
 	{
536 536
 		$query = 'UPDATE marine_output SET ident = :ident, last_latitude = :last_latitude, last_longitude = :last_longitude, last_seen = :last_seen, last_ground_speed = :last_ground_speed WHERE fammarine_id = :fammarine_id';
537
-                $query_values = array(':fammarine_id' => $fammarine_id,':last_latitude' => $latitude,':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed,':last_seen' => $date,':ident' => $ident);
537
+                $query_values = array(':fammarine_id' => $fammarine_id, ':last_latitude' => $latitude, ':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed, ':last_seen' => $date, ':ident' => $ident);
538 538
 
539 539
 		try {
540 540
 			$sth = $this->db->prepare($query);
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
 	* @param String $verticalrate vertival rate of flight
573 573
 	* @return String success or false
574 574
 	*/
575
-	public function addMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $mmsi = '',$type = '',$imo = '',$callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$format_source = '', $source_name = '')
575
+	public function addMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $mmsi = '', $type = '', $imo = '', $callsign = '', $arrival_code = '', $arrival_date = '', $status = '', $format_source = '', $source_name = '')
576 576
 	{
577 577
 		global $globalURL;
578 578
 		
@@ -639,25 +639,25 @@  discard block
 block discarded – undo
639 639
 		}
640 640
 
641 641
     
642
-		if ($date == "" || strtotime($date) < time()-20*60)
642
+		if ($date == "" || strtotime($date) < time() - 20*60)
643 643
 		{
644 644
 			$date = date("Y-m-d H:i:s", time());
645 645
 		}
646 646
 
647
-		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
648
-		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
649
-		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
650
-		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
651
-		$heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT);
652
-		$groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
653
-		$format_source = filter_var($format_source,FILTER_SANITIZE_STRING);
654
-		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
655
-		$type = filter_var($type,FILTER_SANITIZE_STRING);
656
-		$status = filter_var($status,FILTER_SANITIZE_STRING);
657
-		$imo = filter_var($imo,FILTER_SANITIZE_STRING);
658
-		$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
659
-		$arrival_code = filter_var($arrival_code,FILTER_SANITIZE_STRING);
660
-		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING);
647
+		$fammarine_id = filter_var($fammarine_id, FILTER_SANITIZE_STRING);
648
+		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
649
+		$latitude = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
650
+		$longitude = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
651
+		$heading = filter_var($heading, FILTER_SANITIZE_NUMBER_INT);
652
+		$groundspeed = filter_var($groundspeed, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
653
+		$format_source = filter_var($format_source, FILTER_SANITIZE_STRING);
654
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_NUMBER_INT);
655
+		$type = filter_var($type, FILTER_SANITIZE_STRING);
656
+		$status = filter_var($status, FILTER_SANITIZE_STRING);
657
+		$imo = filter_var($imo, FILTER_SANITIZE_STRING);
658
+		$callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
659
+		$arrival_code = filter_var($arrival_code, FILTER_SANITIZE_STRING);
660
+		$arrival_date = filter_var($arrival_date, FILTER_SANITIZE_STRING);
661 661
 	
662 662
                 if ($latitude == '' && $longitude == '') {
663 663
             		$latitude = 0;
@@ -666,10 +666,10 @@  discard block
 block discarded – undo
666 666
                 if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
667 667
                 if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
668 668
                 if ($arrival_date == '') $arrival_date = NULL;
669
-		$query  = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo,arrival_port_name,arrival_port_date) 
669
+		$query = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo,arrival_port_name,arrival_port_date) 
670 670
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:speed,:date,:format_source, :source_name,:mmsi,:type,:status,:imo,:arrival_port_name,:arrival_port_date)";
671 671
 
672
-		$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident,':latitude' => $latitude,':longitude' => $longitude,':heading' => $heading,':speed' => $groundspeed,':date' => $date,':format_source' => $format_source, ':source_name' => $source_name,':mmsi' => $mmsi,':type' => $type,':status' => $status,':imo' => $imo,':arrival_port_name' => $arrival_code,':arrival_port_date' => $arrival_date);
672
+		$query_values = array(':fammarine_id' => $fammarine_id, ':ident' => $ident, ':latitude' => $latitude, ':longitude' => $longitude, ':heading' => $heading, ':speed' => $groundspeed, ':date' => $date, ':format_source' => $format_source, ':source_name' => $source_name, ':mmsi' => $mmsi, ':type' => $type, ':status' => $status, ':imo' => $imo, ':arrival_port_name' => $arrival_code, ':arrival_port_date' => $arrival_date);
673 673
 		try {
674 674
 		        
675 675
 			$sth = $this->db->prepare($query);
@@ -694,13 +694,13 @@  discard block
 block discarded – undo
694 694
 	{
695 695
 		global $globalDBdriver, $globalTimezone;
696 696
 		if ($globalDBdriver == 'mysql') {
697
-			$query  = "SELECT marine_output.ident FROM marine_output 
697
+			$query = "SELECT marine_output.ident FROM marine_output 
698 698
 								WHERE marine_output.ident = :ident 
699 699
 								AND marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) 
700 700
 								AND marine_output.date < UTC_TIMESTAMP()";
701 701
 			$query_data = array(':ident' => $ident);
702 702
 		} else {
703
-			$query  = "SELECT marine_output.ident FROM marine_output 
703
+			$query = "SELECT marine_output.ident FROM marine_output 
704 704
 								WHERE marine_output.ident = :ident 
705 705
 								AND marine_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
706 706
 								AND marine_output.date < now() AT TIME ZONE 'UTC'";
@@ -709,8 +709,8 @@  discard block
 block discarded – undo
709 709
 		
710 710
 		$sth = $this->db->prepare($query);
711 711
 		$sth->execute($query_data);
712
-    		$ident_result='';
713
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
712
+    		$ident_result = '';
713
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
714 714
 		{
715 715
 			$ident_result = $row['ident'];
716 716
 		}
@@ -736,8 +736,8 @@  discard block
 block discarded – undo
736 736
 				return false;
737 737
 			} else {
738 738
 				$q_array = explode(" ", $q);
739
-				foreach ($q_array as $q_item){
740
-					$q_item = filter_var($q_item,FILTER_SANITIZE_STRING);
739
+				foreach ($q_array as $q_item) {
740
+					$q_item = filter_var($q_item, FILTER_SANITIZE_STRING);
741 741
 					$additional_query .= " AND (";
742 742
 					$additional_query .= "(marine_output.ident like '%".$q_item."%')";
743 743
 					$additional_query .= ")";
@@ -745,11 +745,11 @@  discard block
 block discarded – undo
745 745
 			}
746 746
 		}
747 747
 		if ($globalDBdriver == 'mysql') {
748
-			$query  = "SELECT marine_output.* FROM marine_output 
748
+			$query = "SELECT marine_output.* FROM marine_output 
749 749
 				WHERE marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 20 SECOND) ".$additional_query." 
750 750
 				AND marine_output.date < UTC_TIMESTAMP()";
751 751
 		} else {
752
-			$query  = "SELECT marine_output.* FROM marine_output 
752
+			$query = "SELECT marine_output.* FROM marine_output 
753 753
 				WHERE marine_output.date::timestamp >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '20 SECONDS' ".$additional_query." 
754 754
 				AND marine_output.date::timestamp < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'";
755 755
 		}
@@ -822,11 +822,11 @@  discard block
 block discarded – undo
822 822
 	* @return Array the callsign list
823 823
 	*
824 824
 	*/
825
-	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array(),$year = '', $month = '', $day = '')
825
+	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '', $filters = array(), $year = '', $month = '', $day = '')
826 826
 	{
827 827
 		global $globalDBdriver;
828
-		$filter_query = $this->getFilter($filters,true,true);
829
-		$query  = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count 
828
+		$filter_query = $this->getFilter($filters, true, true);
829
+		$query = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count 
830 830
                     FROM marine_output".$filter_query." marine_output.ident <> ''";
831 831
 		 if ($olderthanmonths > 0) {
832 832
 			if ($globalDBdriver == 'mysql') $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
@@ -840,28 +840,28 @@  discard block
 block discarded – undo
840 840
 		if ($year != '') {
841 841
 			if ($globalDBdriver == 'mysql') {
842 842
 				$query .= " AND YEAR(marine_output.date) = :year";
843
-				$query_values = array_merge($query_values,array(':year' => $year));
843
+				$query_values = array_merge($query_values, array(':year' => $year));
844 844
 			} else {
845 845
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
846
-				$query_values = array_merge($query_values,array(':year' => $year));
846
+				$query_values = array_merge($query_values, array(':year' => $year));
847 847
 			}
848 848
 		}
849 849
 		if ($month != '') {
850 850
 			if ($globalDBdriver == 'mysql') {
851 851
 				$query .= " AND MONTH(marine_output.date) = :month";
852
-				$query_values = array_merge($query_values,array(':month' => $month));
852
+				$query_values = array_merge($query_values, array(':month' => $month));
853 853
 			} else {
854 854
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
855
-				$query_values = array_merge($query_values,array(':month' => $month));
855
+				$query_values = array_merge($query_values, array(':month' => $month));
856 856
 			}
857 857
 		}
858 858
 		if ($day != '') {
859 859
 			if ($globalDBdriver == 'mysql') {
860 860
 				$query .= " AND DAY(marine_output.date) = :day";
861
-				$query_values = array_merge($query_values,array(':day' => $day));
861
+				$query_values = array_merge($query_values, array(':day' => $day));
862 862
 			} else {
863 863
 				$query .= " AND EXTRACT(DAY FROM marine_output.date) = :day";
864
-				$query_values = array_merge($query_values,array(':day' => $day));
864
+				$query_values = array_merge($query_values, array(':day' => $day));
865 865
 			}
866 866
 		}
867 867
 		$query .= " GROUP BY marine_output.ident ORDER BY callsign_icao_count DESC";
@@ -873,7 +873,7 @@  discard block
 block discarded – undo
873 873
 		$callsign_array = array();
874 874
 		$temp_array = array();
875 875
         
876
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
876
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
877 877
 		{
878 878
 			$temp_array['callsign_icao'] = $row['ident'];
879 879
 			$temp_array['airline_name'] = $row['airline_name'];
@@ -925,7 +925,7 @@  discard block
 block discarded – undo
925 925
 		$date_array = array();
926 926
 		$temp_array = array();
927 927
         
928
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
928
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
929 929
 		{
930 930
 			$temp_array['date_name'] = $row['date_name'];
931 931
 			$temp_array['date_count'] = $row['date_count'];
@@ -951,7 +951,7 @@  discard block
 block discarded – undo
951 951
 			$datetime = new DateTime();
952 952
 			$offset = $datetime->format('P');
953 953
 		} else $offset = '+00:00';
954
-		$filter_query = $this->getFilter($filters,true,true);
954
+		$filter_query = $this->getFilter($filters, true, true);
955 955
 		if ($globalDBdriver == 'mysql') {
956 956
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
957 957
 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY)";
@@ -972,7 +972,7 @@  discard block
 block discarded – undo
972 972
 		$date_array = array();
973 973
 		$temp_array = array();
974 974
         
975
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
975
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
976 976
 		{
977 977
 			$temp_array['date_name'] = $row['date_name'];
978 978
 			$temp_array['date_count'] = $row['date_count'];
@@ -997,7 +997,7 @@  discard block
 block discarded – undo
997 997
 			$datetime = new DateTime();
998 998
 			$offset = $datetime->format('P');
999 999
 		} else $offset = '+00:00';
1000
-		$filter_query = $this->getFilter($filters,true,true);
1000
+		$filter_query = $this->getFilter($filters, true, true);
1001 1001
 		if ($globalDBdriver == 'mysql') {
1002 1002
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
1003 1003
 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MONTH)";
@@ -1018,7 +1018,7 @@  discard block
 block discarded – undo
1018 1018
 		$date_array = array();
1019 1019
 		$temp_array = array();
1020 1020
         
1021
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1021
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1022 1022
 		{
1023 1023
 			$temp_array['date_name'] = $row['date_name'];
1024 1024
 			$temp_array['date_count'] = $row['date_count'];
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
 		$date_array = array();
1066 1066
 		$temp_array = array();
1067 1067
         
1068
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1068
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1069 1069
 		{
1070 1070
 			$temp_array['month_name'] = $row['month_name'];
1071 1071
 			$temp_array['year_name'] = $row['year_name'];
@@ -1094,7 +1094,7 @@  discard block
 block discarded – undo
1094 1094
 			$datetime = new DateTime();
1095 1095
 			$offset = $datetime->format('P');
1096 1096
 		} else $offset = '+00:00';
1097
-		$filter_query = $this->getFilter($filters,true,true);
1097
+		$filter_query = $this->getFilter($filters, true, true);
1098 1098
 		if ($globalDBdriver == 'mysql') {
1099 1099
 			$query  = "SELECT MONTH(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS month_name, YEAR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS year_name, count(*) as date_count
1100 1100
 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 YEAR)";
@@ -1115,7 +1115,7 @@  discard block
 block discarded – undo
1115 1115
 		$date_array = array();
1116 1116
 		$temp_array = array();
1117 1117
         
1118
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1118
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1119 1119
 		{
1120 1120
 			$temp_array['year_name'] = $row['year_name'];
1121 1121
 			$temp_array['month_name'] = $row['month_name'];
@@ -1135,7 +1135,7 @@  discard block
 block discarded – undo
1135 1135
 	* @return Array the hour list
1136 1136
 	*
1137 1137
 	*/
1138
-	public function countAllHours($orderby,$filters = array())
1138
+	public function countAllHours($orderby, $filters = array())
1139 1139
 	{
1140 1140
 		global $globalTimezone, $globalDBdriver;
1141 1141
 		if ($globalTimezone != '') {
@@ -1183,7 +1183,7 @@  discard block
 block discarded – undo
1183 1183
 		$hour_array = array();
1184 1184
 		$temp_array = array();
1185 1185
         
1186
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1186
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1187 1187
 		{
1188 1188
 			$temp_array['hour_name'] = $row['hour_name'];
1189 1189
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1205,8 +1205,8 @@  discard block
 block discarded – undo
1205 1205
 	public function countAllHoursByDate($date, $filters = array())
1206 1206
 	{
1207 1207
 		global $globalTimezone, $globalDBdriver;
1208
-		$filter_query = $this->getFilter($filters,true,true);
1209
-		$date = filter_var($date,FILTER_SANITIZE_STRING);
1208
+		$filter_query = $this->getFilter($filters, true, true);
1209
+		$date = filter_var($date, FILTER_SANITIZE_STRING);
1210 1210
 		if ($globalTimezone != '') {
1211 1211
 			date_default_timezone_set($globalTimezone);
1212 1212
 			$datetime = new DateTime($date);
@@ -1214,12 +1214,12 @@  discard block
 block discarded – undo
1214 1214
 		} else $offset = '+00:00';
1215 1215
 
1216 1216
 		if ($globalDBdriver == 'mysql') {
1217
-			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1217
+			$query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1218 1218
 								FROM marine_output".$filter_query." DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) = :date
1219 1219
 								GROUP BY hour_name 
1220 1220
 								ORDER BY hour_name ASC";
1221 1221
 		} else {
1222
-			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1222
+			$query = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1223 1223
 								FROM marine_output".$filter_query." to_char(marine_output.date AT TIME ZONE INTERVAL :offset, 'YYYY-mm-dd') = :date
1224 1224
 								GROUP BY hour_name 
1225 1225
 								ORDER BY hour_name ASC";
@@ -1231,7 +1231,7 @@  discard block
 block discarded – undo
1231 1231
 		$hour_array = array();
1232 1232
 		$temp_array = array();
1233 1233
         
1234
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1234
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1235 1235
 		{
1236 1236
 			$temp_array['hour_name'] = $row['hour_name'];
1237 1237
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1253,8 +1253,8 @@  discard block
 block discarded – undo
1253 1253
 	public function countAllHoursByIdent($ident, $filters = array())
1254 1254
 	{
1255 1255
 		global $globalTimezone, $globalDBdriver;
1256
-		$filter_query = $this->getFilter($filters,true,true);
1257
-		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
1256
+		$filter_query = $this->getFilter($filters, true, true);
1257
+		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
1258 1258
 		if ($globalTimezone != '') {
1259 1259
 			date_default_timezone_set($globalTimezone);
1260 1260
 			$datetime = new DateTime();
@@ -1262,12 +1262,12 @@  discard block
 block discarded – undo
1262 1262
 		} else $offset = '+00:00';
1263 1263
 
1264 1264
 		if ($globalDBdriver == 'mysql') {
1265
-			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1265
+			$query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1266 1266
 								FROM marine_output".$filter_query." marine_output.ident = :ident 
1267 1267
 								GROUP BY hour_name 
1268 1268
 								ORDER BY hour_name ASC";
1269 1269
 		} else {
1270
-			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1270
+			$query = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1271 1271
 								FROM marine_output".$filter_query." marine_output.ident = :ident 
1272 1272
 								GROUP BY hour_name 
1273 1273
 								ORDER BY hour_name ASC";
@@ -1275,12 +1275,12 @@  discard block
 block discarded – undo
1275 1275
       
1276 1276
 		
1277 1277
 		$sth = $this->db->prepare($query);
1278
-		$sth->execute(array(':ident' => $ident,':offset' => $offset));
1278
+		$sth->execute(array(':ident' => $ident, ':offset' => $offset));
1279 1279
       
1280 1280
 		$hour_array = array();
1281 1281
 		$temp_array = array();
1282 1282
         
1283
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1283
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1284 1284
 		{
1285 1285
 			$temp_array['hour_name'] = $row['hour_name'];
1286 1286
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1299,32 +1299,32 @@  discard block
 block discarded – undo
1299 1299
 	* @return Integer the number of flights
1300 1300
 	*
1301 1301
 	*/
1302
-	public function countOverallTracked($filters = array(),$year = '',$month = '')
1302
+	public function countOverallTracked($filters = array(), $year = '', $month = '')
1303 1303
 	{
1304 1304
 		global $globalDBdriver;
1305
-		$queryi  = "SELECT COUNT(marine_output.marine_id) AS flight_count FROM marine_output";
1305
+		$queryi = "SELECT COUNT(marine_output.marine_id) AS flight_count FROM marine_output";
1306 1306
 		$query_values = array();
1307 1307
 		$query = '';
1308 1308
 		if ($year != '') {
1309 1309
 			if ($globalDBdriver == 'mysql') {
1310 1310
 				$query .= " AND YEAR(marine_output.date) = :year";
1311
-				$query_values = array_merge($query_values,array(':year' => $year));
1311
+				$query_values = array_merge($query_values, array(':year' => $year));
1312 1312
 			} else {
1313 1313
 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year";
1314
-				$query_values = array_merge($query_values,array(':year' => $year));
1314
+				$query_values = array_merge($query_values, array(':year' => $year));
1315 1315
 			}
1316 1316
 		}
1317 1317
 		if ($month != '') {
1318 1318
 			if ($globalDBdriver == 'mysql') {
1319 1319
 				$query .= " AND MONTH(marine_output.date) = :month";
1320
-				$query_values = array_merge($query_values,array(':month' => $month));
1320
+				$query_values = array_merge($query_values, array(':month' => $month));
1321 1321
 			} else {
1322 1322
 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month";
1323
-				$query_values = array_merge($query_values,array(':month' => $month));
1323
+				$query_values = array_merge($query_values, array(':month' => $month));
1324 1324
 			}
1325 1325
 		}
1326 1326
 		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1327
-		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1327
+		else $queryi .= $this->getFilter($filters, true, true).substr($query, 4);
1328 1328
 		
1329 1329
 		$sth = $this->db->prepare($queryi);
1330 1330
 		$sth->execute($query_values);
@@ -1341,7 +1341,7 @@  discard block
 block discarded – undo
1341 1341
 	public function countAllHoursFromToday($filters = array())
1342 1342
 	{
1343 1343
 		global $globalTimezone, $globalDBdriver;
1344
-		$filter_query = $this->getFilter($filters,true,true);
1344
+		$filter_query = $this->getFilter($filters, true, true);
1345 1345
 		if ($globalTimezone != '') {
1346 1346
 			date_default_timezone_set($globalTimezone);
1347 1347
 			$datetime = new DateTime();
@@ -1349,12 +1349,12 @@  discard block
 block discarded – undo
1349 1349
 		} else $offset = '+00:00';
1350 1350
 
1351 1351
 		if ($globalDBdriver == 'mysql') {
1352
-			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1352
+			$query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
1353 1353
 								FROM marine_output".$filter_query." DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) = CURDATE()
1354 1354
 								GROUP BY hour_name 
1355 1355
 								ORDER BY hour_name ASC";
1356 1356
 		} else {
1357
-			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1357
+			$query = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count
1358 1358
 								FROM marine_output".$filter_query." to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = CAST(NOW() AS date)
1359 1359
 								GROUP BY hour_name 
1360 1360
 								ORDER BY hour_name ASC";
@@ -1366,7 +1366,7 @@  discard block
 block discarded – undo
1366 1366
 		$hour_array = array();
1367 1367
 		$temp_array = array();
1368 1368
         
1369
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1369
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1370 1370
 		{
1371 1371
 			$temp_array['hour_name'] = $row['hour_name'];
1372 1372
 			$temp_array['hour_count'] = $row['hour_count'];
@@ -1385,9 +1385,9 @@  discard block
 block discarded – undo
1385 1385
 	*/
1386 1386
 	public function getMarineIDBasedOnFamMarineID($fammarine_id)
1387 1387
 	{
1388
-		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
1388
+		$fammarine_id = filter_var($fammarine_id, FILTER_SANITIZE_STRING);
1389 1389
 
1390
-		$query  = "SELECT marine_output.marine_id
1390
+		$query = "SELECT marine_output.marine_id
1391 1391
 				FROM marine_output 
1392 1392
 				WHERE marine_output.fammarine_id = '".$fammarine_id."'";
1393 1393
         
@@ -1395,7 +1395,7 @@  discard block
 block discarded – undo
1395 1395
 		$sth = $this->db->prepare($query);
1396 1396
 		$sth->execute();
1397 1397
 
1398
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
1398
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
1399 1399
 		{
1400 1400
 			return $row['marine_id'];
1401 1401
 		}
@@ -1420,23 +1420,23 @@  discard block
 block discarded – undo
1420 1420
 		}
1421 1421
 		
1422 1422
 		$current_date = date("Y-m-d H:i:s");
1423
-		$date = date("Y-m-d H:i:s",strtotime($dateString." UTC"));
1423
+		$date = date("Y-m-d H:i:s", strtotime($dateString." UTC"));
1424 1424
 		
1425 1425
 		$diff = abs(strtotime($current_date) - strtotime($date));
1426 1426
 
1427
-		$time_array['years'] = floor($diff / (365*60*60*24)); 
1427
+		$time_array['years'] = floor($diff/(365*60*60*24)); 
1428 1428
 		$years = $time_array['years'];
1429 1429
 		
1430
-		$time_array['months'] = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
1430
+		$time_array['months'] = floor(($diff - $years*365*60*60*24)/(30*60*60*24));
1431 1431
 		$months = $time_array['months'];
1432 1432
 		
1433
-		$time_array['days'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
1433
+		$time_array['days'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24)/(60*60*24));
1434 1434
 		$days = $time_array['days'];
1435
-		$time_array['hours'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/ (60*60));
1435
+		$time_array['hours'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/(60*60));
1436 1436
 		$hours = $time_array['hours'];
1437
-		$time_array['minutes'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/ 60);
1437
+		$time_array['minutes'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/60);
1438 1438
 		$minutes = $time_array['minutes'];
1439
-		$time_array['seconds'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minutes*60));  
1439
+		$time_array['seconds'] = floor(($diff - $years*365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minutes*60));  
1440 1440
 		
1441 1441
 		return $time_array;
1442 1442
 	}
@@ -1459,63 +1459,63 @@  discard block
 block discarded – undo
1459 1459
 			$temp_array['direction_degree'] = $direction;
1460 1460
 			$temp_array['direction_shortname'] = "N";
1461 1461
 			$temp_array['direction_fullname'] = "North";
1462
-		} elseif ($direction >= 22.5 && $direction < 45){
1462
+		} elseif ($direction >= 22.5 && $direction < 45) {
1463 1463
 			$temp_array['direction_degree'] = $direction;
1464 1464
 			$temp_array['direction_shortname'] = "NNE";
1465 1465
 			$temp_array['direction_fullname'] = "North-Northeast";
1466
-		} elseif ($direction >= 45 && $direction < 67.5){
1466
+		} elseif ($direction >= 45 && $direction < 67.5) {
1467 1467
 			$temp_array['direction_degree'] = $direction;
1468 1468
 			$temp_array['direction_shortname'] = "NE";
1469 1469
 			$temp_array['direction_fullname'] = "Northeast";
1470
-		} elseif ($direction >= 67.5 && $direction < 90){
1470
+		} elseif ($direction >= 67.5 && $direction < 90) {
1471 1471
 			$temp_array['direction_degree'] = $direction;
1472 1472
 			$temp_array['direction_shortname'] = "ENE";
1473 1473
 			$temp_array['direction_fullname'] = "East-Northeast";
1474
-		} elseif ($direction >= 90 && $direction < 112.5){
1474
+		} elseif ($direction >= 90 && $direction < 112.5) {
1475 1475
 			$temp_array['direction_degree'] = $direction;
1476 1476
 			$temp_array['direction_shortname'] = "E";
1477 1477
 			$temp_array['direction_fullname'] = "East";
1478
-		} elseif ($direction >= 112.5 && $direction < 135){
1478
+		} elseif ($direction >= 112.5 && $direction < 135) {
1479 1479
 			$temp_array['direction_degree'] = $direction;
1480 1480
 			$temp_array['direction_shortname'] = "ESE";
1481 1481
 			$temp_array['direction_fullname'] = "East-Southeast";
1482
-		} elseif ($direction >= 135 && $direction < 157.5){
1482
+		} elseif ($direction >= 135 && $direction < 157.5) {
1483 1483
 			$temp_array['direction_degree'] = $direction;
1484 1484
 			$temp_array['direction_shortname'] = "SE";
1485 1485
 			$temp_array['direction_fullname'] = "Southeast";
1486
-		} elseif ($direction >= 157.5 && $direction < 180){
1486
+		} elseif ($direction >= 157.5 && $direction < 180) {
1487 1487
 			$temp_array['direction_degree'] = $direction;
1488 1488
 			$temp_array['direction_shortname'] = "SSE";
1489 1489
 			$temp_array['direction_fullname'] = "South-Southeast";
1490
-		} elseif ($direction >= 180 && $direction < 202.5){
1490
+		} elseif ($direction >= 180 && $direction < 202.5) {
1491 1491
 			$temp_array['direction_degree'] = $direction;
1492 1492
 			$temp_array['direction_shortname'] = "S";
1493 1493
 			$temp_array['direction_fullname'] = "South";
1494
-		} elseif ($direction >= 202.5 && $direction < 225){
1494
+		} elseif ($direction >= 202.5 && $direction < 225) {
1495 1495
 			$temp_array['direction_degree'] = $direction;
1496 1496
 			$temp_array['direction_shortname'] = "SSW";
1497 1497
 			$temp_array['direction_fullname'] = "South-Southwest";
1498
-		} elseif ($direction >= 225 && $direction < 247.5){
1498
+		} elseif ($direction >= 225 && $direction < 247.5) {
1499 1499
 			$temp_array['direction_degree'] = $direction;
1500 1500
 			$temp_array['direction_shortname'] = "SW";
1501 1501
 			$temp_array['direction_fullname'] = "Southwest";
1502
-		} elseif ($direction >= 247.5 && $direction < 270){
1502
+		} elseif ($direction >= 247.5 && $direction < 270) {
1503 1503
 			$temp_array['direction_degree'] = $direction;
1504 1504
 			$temp_array['direction_shortname'] = "WSW";
1505 1505
 			$temp_array['direction_fullname'] = "West-Southwest";
1506
-		} elseif ($direction >= 270 && $direction < 292.5){
1506
+		} elseif ($direction >= 270 && $direction < 292.5) {
1507 1507
 			$temp_array['direction_degree'] = $direction;
1508 1508
 			$temp_array['direction_shortname'] = "W";
1509 1509
 			$temp_array['direction_fullname'] = "West";
1510
-		} elseif ($direction >= 292.5 && $direction < 315){
1510
+		} elseif ($direction >= 292.5 && $direction < 315) {
1511 1511
 			$temp_array['direction_degree'] = $direction;
1512 1512
 			$temp_array['direction_shortname'] = "WNW";
1513 1513
 			$temp_array['direction_fullname'] = "West-Northwest";
1514
-		} elseif ($direction >= 315 && $direction < 337.5){
1514
+		} elseif ($direction >= 315 && $direction < 337.5) {
1515 1515
 			$temp_array['direction_degree'] = $direction;
1516 1516
 			$temp_array['direction_shortname'] = "NW";
1517 1517
 			$temp_array['direction_fullname'] = "Northwest";
1518
-		} elseif ($direction >= 337.5 && $direction < 360){
1518
+		} elseif ($direction >= 337.5 && $direction < 360) {
1519 1519
 			$temp_array['direction_degree'] = $direction;
1520 1520
 			$temp_array['direction_shortname'] = "NNW";
1521 1521
 			$temp_array['direction_fullname'] = "North-Northwest";
@@ -1532,11 +1532,11 @@  discard block
 block discarded – undo
1532 1532
 	* @param Float $longitude longitute of the flight
1533 1533
 	* @return String the countrie
1534 1534
 	*/
1535
-	public function getCountryFromLatitudeLongitude($latitude,$longitude)
1535
+	public function getCountryFromLatitudeLongitude($latitude, $longitude)
1536 1536
 	{
1537 1537
 		global $globalDBdriver, $globalDebug;
1538
-		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1539
-		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1538
+		$latitude = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
1539
+		$longitude = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
1540 1540
 	
1541 1541
 		$Connection = new Connection($this->db);
1542 1542
 		if (!$Connection->tableExists('countries')) return '';
@@ -1576,7 +1576,7 @@  discard block
 block discarded – undo
1576 1576
 	public function getCountryFromISO2($iso2)
1577 1577
 	{
1578 1578
 		global $globalDBdriver, $globalDebug;
1579
-		$iso2 = filter_var($iso2,FILTER_SANITIZE_STRING);
1579
+		$iso2 = filter_var($iso2, FILTER_SANITIZE_STRING);
1580 1580
 	
1581 1581
 		$Connection = new Connection($this->db);
1582 1582
 		if (!$Connection->tableExists('countries')) return '';
@@ -1624,7 +1624,7 @@  discard block
 block discarded – undo
1624 1624
 		
1625 1625
 		$bitly_data = json_decode($bitly_data);
1626 1626
 		$bitly_url = '';
1627
-		if ($bitly_data->status_txt = "OK"){
1627
+		if ($bitly_data->status_txt = "OK") {
1628 1628
 			$bitly_url = $bitly_data->data->url;
1629 1629
 		}
1630 1630
 
@@ -1634,7 +1634,7 @@  discard block
 block discarded – undo
1634 1634
 
1635 1635
 	public function getOrderBy()
1636 1636
 	{
1637
-		$orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY marine_output.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY marine_output.aircraft_icao DESC"),"manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY marine_output.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY marine_output.aircraft_manufacturer DESC"),"airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY marine_output.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY marine_output.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY marine_output.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY marine_output.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY marine_output.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY marine_output.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY marine_output.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY marine_output.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY marine_output.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY marine_output.date DESC"),"distance_asc" => array("key" => "distance_asc","value" => "Distance - ASC","sql" => "ORDER BY distance ASC"),"distance_desc" => array("key" => "distance_desc","value" => "Distance - DESC","sql" => "ORDER BY distance DESC"));
1637
+		$orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY marine_output.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY marine_output.aircraft_icao DESC"), "manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY marine_output.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY marine_output.aircraft_manufacturer DESC"), "airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY marine_output.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY marine_output.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY marine_output.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY marine_output.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY marine_output.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY marine_output.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY marine_output.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY marine_output.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY marine_output.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY marine_output.date DESC"), "distance_asc" => array("key" => "distance_asc", "value" => "Distance - ASC", "sql" => "ORDER BY distance ASC"), "distance_desc" => array("key" => "distance_desc", "value" => "Distance - DESC", "sql" => "ORDER BY distance DESC"));
1638 1638
 		
1639 1639
 		return $orderby;
1640 1640
 		
Please login to merge, or discard this patch.
Braces   +145 added lines, -52 removed lines patch added patch discarded remove patch
@@ -31,7 +31,9 @@  discard block
 block discarded – undo
31 31
 		if (isset($filter[0]['source'])) {
32 32
 			$filters = array_merge($filters,$filter);
33 33
 		}
34
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
34
+		if (is_array($globalFilter)) {
35
+			$filter = array_merge($filter,$globalFilter);
36
+		}
35 37
 		$filter_query_join = '';
36 38
 		$filter_query_where = '';
37 39
 		foreach($filters as $flt) {
@@ -70,8 +72,11 @@  discard block
 block discarded – undo
70 72
 				$filter_query_where .= " AND EXTRACT(DAY FROM marine_output.date) = '".$filter['day']."'";
71 73
 			}
72 74
 		}
73
-		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
74
-		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
75
+		if ($filter_query_where == '' && $where) {
76
+			$filter_query_where = ' WHERE';
77
+		} elseif ($filter_query_where != '' && $and) {
78
+			$filter_query_where .= ' AND';
79
+		}
75 80
 		if ($filter_query_where != '') {
76 81
 			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
77 82
 		}
@@ -125,25 +130,40 @@  discard block
 block discarded – undo
125 130
 				$temp_array['spotter_id'] = $row['spotter_archive_id'];
126 131
 			} elseif (isset($row['spotter_archive_output_id'])) {
127 132
 				$temp_array['spotter_id'] = $row['spotter_archive_output_id'];
128
-			*/} 
129
-			elseif (isset($row['marineid'])) {
133
+			*/} elseif (isset($row['marineid'])) {
130 134
 				$temp_array['marineid'] = $row['marineid'];
131 135
 			} else {
132 136
 				$temp_array['marineid'] = '';
133 137
 			}
134
-			if (isset($row['fammarine_id'])) $temp_array['fammarine_id'] = $row['fammarine_id'];
135
-			if (isset($row['mmsi'])) $temp_array['mmsi'] = $row['mmsi'];
136
-			if (isset($row['type'])) $temp_array['type'] = $row['type'];
138
+			if (isset($row['fammarine_id'])) {
139
+				$temp_array['fammarine_id'] = $row['fammarine_id'];
140
+			}
141
+			if (isset($row['mmsi'])) {
142
+				$temp_array['mmsi'] = $row['mmsi'];
143
+			}
144
+			if (isset($row['type'])) {
145
+				$temp_array['type'] = $row['type'];
146
+			}
137 147
 			$temp_array['ident'] = $row['ident'];
138
-			if (isset($row['latitude'])) $temp_array['latitude'] = $row['latitude'];
139
-			if (isset($row['longitude'])) $temp_array['longitude'] = $row['longitude'];
140
-			if (isset($row['format_source'])) $temp_array['format_source'] = $row['format_source'];
148
+			if (isset($row['latitude'])) {
149
+				$temp_array['latitude'] = $row['latitude'];
150
+			}
151
+			if (isset($row['longitude'])) {
152
+				$temp_array['longitude'] = $row['longitude'];
153
+			}
154
+			if (isset($row['format_source'])) {
155
+				$temp_array['format_source'] = $row['format_source'];
156
+			}
141 157
 			if (isset($row['heading'])) {
142 158
 				$temp_array['heading'] = $row['heading'];
143 159
 				$heading_direction = $this->parseDirection($row['heading']);
144
-				if (isset($heading_direction[0]['direction_fullname'])) $temp_array['heading_name'] = $heading_direction[0]['direction_fullname'];
160
+				if (isset($heading_direction[0]['direction_fullname'])) {
161
+					$temp_array['heading_name'] = $heading_direction[0]['direction_fullname'];
162
+				}
163
+			}
164
+			if (isset($row['ground_speed'])) {
165
+				$temp_array['ground_speed'] = $row['ground_speed'];
145 166
 			}
146
-			if (isset($row['ground_speed'])) $temp_array['ground_speed'] = $row['ground_speed'];
147 167
 			
148 168
 			if (isset($row['date'])) {
149 169
 				$dateArray = $this->parseDateString($row['date']);
@@ -186,13 +206,21 @@  discard block
 block discarded – undo
186 206
 			}
187 207
 			
188 208
 			$fromsource = NULL;
189
-			if (isset($row['source_name']) && $row['source_name'] != '') $temp_array['source_name'] = $row['source_name'];
190
-			if (isset($row['over_country']) && $row['over_country'] != '') $temp_array['over_country'] = $row['over_country'];
191
-			if (isset($row['distance']) && $row['distance'] != '') $temp_array['distance'] = $row['distance'];
209
+			if (isset($row['source_name']) && $row['source_name'] != '') {
210
+				$temp_array['source_name'] = $row['source_name'];
211
+			}
212
+			if (isset($row['over_country']) && $row['over_country'] != '') {
213
+				$temp_array['over_country'] = $row['over_country'];
214
+			}
215
+			if (isset($row['distance']) && $row['distance'] != '') {
216
+				$temp_array['distance'] = $row['distance'];
217
+			}
192 218
 			$temp_array['query_number_rows'] = $num_rows;
193 219
 			$spotter_array[] = $temp_array;
194 220
 		}
195
-		if ($num_rows == 0) return array();
221
+		if ($num_rows == 0) {
222
+			return array();
223
+		}
196 224
 		$spotter_array[0]['query_number_rows'] = $num_rows;
197 225
 		return $spotter_array;
198 226
 	}	
@@ -223,8 +251,12 @@  discard block
 block discarded – undo
223 251
 			{
224 252
 				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
225 253
 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
226
-			} else $limit_query = "";
227
-		} else $limit_query = "";
254
+			} else {
255
+				$limit_query = "";
256
+			}
257
+		} else {
258
+			$limit_query = "";
259
+		}
228 260
 		
229 261
 		if ($sort != "")
230 262
 		{
@@ -252,7 +284,9 @@  discard block
 block discarded – undo
252 284
 		global $global_query;
253 285
 		
254 286
 		date_default_timezone_set('UTC');
255
-		if ($id == '') return array();
287
+		if ($id == '') {
288
+			return array();
289
+		}
256 290
 		$additional_query = "marine_output.fammarine_id = :id";
257 291
 		$query_values = array(':id' => $id);
258 292
 		$query  = $global_query." WHERE ".$additional_query." ";
@@ -395,8 +429,11 @@  discard block
 block discarded – undo
395 429
 		$query .= " ORDER BY marine_output.source_name ASC";
396 430
 
397 431
 		$sth = $this->db->prepare($query);
398
-		if (!empty($query_values)) $sth->execute($query_values);
399
-		else $sth->execute();
432
+		if (!empty($query_values)) {
433
+			$sth->execute($query_values);
434
+		} else {
435
+			$sth->execute();
436
+		}
400 437
 
401 438
 		$source_array = array();
402 439
 		$temp_array = array();
@@ -451,8 +488,11 @@  discard block
 block discarded – undo
451 488
 		$sth = $this->db->prepare($query);
452 489
 		$sth->execute(array(':mmsi' => $mmsi));
453 490
 		$result = $sth->fetchAll(PDO::FETCH_ASSOC);
454
-		if (isset($result[0])) return $result[0];
455
-		else return array();
491
+		if (isset($result[0])) {
492
+			return $result[0];
493
+		} else {
494
+			return array();
495
+		}
456 496
 	}
457 497
 
458 498
 	/*
@@ -468,7 +508,9 @@  discard block
 block discarded – undo
468 508
 			date_default_timezone_set($globalTimezone);
469 509
 			$datetime = new DateTime();
470 510
 			$offset = $datetime->format('P');
471
-		} else $offset = '+00:00';
511
+		} else {
512
+			$offset = '+00:00';
513
+		}
472 514
 
473 515
 		if ($globalDBdriver == 'mysql') {
474 516
 			$query  = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date
@@ -663,9 +705,15 @@  discard block
 block discarded – undo
663 705
             		$latitude = 0;
664 706
             		$longitude = 0;
665 707
             	}
666
-                if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
667
-                if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
668
-                if ($arrival_date == '') $arrival_date = NULL;
708
+                if ($heading == '' || $Common->isInteger($heading) === false) {
709
+                	$heading = 0;
710
+                }
711
+                if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) {
712
+                	$groundspeed = 0;
713
+                }
714
+                if ($arrival_date == '') {
715
+                	$arrival_date = NULL;
716
+                }
669 717
 		$query  = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo,arrival_port_name,arrival_port_date) 
670 718
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:speed,:date,:format_source, :source_name,:mmsi,:type,:status,:imo,:arrival_port_name,:arrival_port_date)";
671 719
 
@@ -829,12 +877,18 @@  discard block
 block discarded – undo
829 877
 		$query  = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count 
830 878
                     FROM marine_output".$filter_query." marine_output.ident <> ''";
831 879
 		 if ($olderthanmonths > 0) {
832
-			if ($globalDBdriver == 'mysql') $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
833
-			else $query .= " AND marine_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'";
880
+			if ($globalDBdriver == 'mysql') {
881
+				$query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
882
+			} else {
883
+				$query .= " AND marine_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'";
884
+			}
834 885
 		}
835 886
 		if ($sincedate != '') {
836
-			if ($globalDBdriver == 'mysql') $query .= " AND marine_output.date > '".$sincedate."'";
837
-			else $query .= " AND marine_output.date > CAST('".$sincedate."' AS TIMESTAMP)";
887
+			if ($globalDBdriver == 'mysql') {
888
+				$query .= " AND marine_output.date > '".$sincedate."'";
889
+			} else {
890
+				$query .= " AND marine_output.date > CAST('".$sincedate."' AS TIMESTAMP)";
891
+			}
838 892
 		}
839 893
 		$query_values = array();
840 894
 		if ($year != '') {
@@ -865,7 +919,9 @@  discard block
 block discarded – undo
865 919
 			}
866 920
 		}
867 921
 		$query .= " GROUP BY marine_output.ident ORDER BY callsign_icao_count DESC";
868
-		if ($limit) $query .= " LIMIT 10 OFFSET 0";
922
+		if ($limit) {
923
+			$query .= " LIMIT 10 OFFSET 0";
924
+		}
869 925
       		
870 926
 		$sth = $this->db->prepare($query);
871 927
 		$sth->execute($query_values);
@@ -900,7 +956,9 @@  discard block
 block discarded – undo
900 956
 			date_default_timezone_set($globalTimezone);
901 957
 			$datetime = new DateTime();
902 958
 			$offset = $datetime->format('P');
903
-		} else $offset = '+00:00';
959
+		} else {
960
+			$offset = '+00:00';
961
+		}
904 962
 
905 963
 		if ($globalDBdriver == 'mysql') {
906 964
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
@@ -950,7 +1008,9 @@  discard block
 block discarded – undo
950 1008
 			date_default_timezone_set($globalTimezone);
951 1009
 			$datetime = new DateTime();
952 1010
 			$offset = $datetime->format('P');
953
-		} else $offset = '+00:00';
1011
+		} else {
1012
+			$offset = '+00:00';
1013
+		}
954 1014
 		$filter_query = $this->getFilter($filters,true,true);
955 1015
 		if ($globalDBdriver == 'mysql') {
956 1016
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
@@ -996,7 +1056,9 @@  discard block
 block discarded – undo
996 1056
 			date_default_timezone_set($globalTimezone);
997 1057
 			$datetime = new DateTime();
998 1058
 			$offset = $datetime->format('P');
999
-		} else $offset = '+00:00';
1059
+		} else {
1060
+			$offset = '+00:00';
1061
+		}
1000 1062
 		$filter_query = $this->getFilter($filters,true,true);
1001 1063
 		if ($globalDBdriver == 'mysql') {
1002 1064
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
@@ -1044,7 +1106,9 @@  discard block
 block discarded – undo
1044 1106
 			date_default_timezone_set($globalTimezone);
1045 1107
 			$datetime = new DateTime();
1046 1108
 			$offset = $datetime->format('P');
1047
-		} else $offset = '+00:00';
1109
+		} else {
1110
+			$offset = '+00:00';
1111
+		}
1048 1112
 
1049 1113
 		if ($globalDBdriver == 'mysql') {
1050 1114
 			$query  = "SELECT YEAR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS month_name, count(*) as date_count
@@ -1093,7 +1157,9 @@  discard block
 block discarded – undo
1093 1157
 			date_default_timezone_set($globalTimezone);
1094 1158
 			$datetime = new DateTime();
1095 1159
 			$offset = $datetime->format('P');
1096
-		} else $offset = '+00:00';
1160
+		} else {
1161
+			$offset = '+00:00';
1162
+		}
1097 1163
 		$filter_query = $this->getFilter($filters,true,true);
1098 1164
 		if ($globalDBdriver == 'mysql') {
1099 1165
 			$query  = "SELECT MONTH(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS month_name, YEAR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS year_name, count(*) as date_count
@@ -1142,7 +1208,9 @@  discard block
 block discarded – undo
1142 1208
 			date_default_timezone_set($globalTimezone);
1143 1209
 			$datetime = new DateTime();
1144 1210
 			$offset = $datetime->format('P');
1145
-		} else $offset = '+00:00';
1211
+		} else {
1212
+			$offset = '+00:00';
1213
+		}
1146 1214
 
1147 1215
 		$orderby_sql = '';
1148 1216
 		if ($orderby == "hour")
@@ -1211,7 +1279,9 @@  discard block
 block discarded – undo
1211 1279
 			date_default_timezone_set($globalTimezone);
1212 1280
 			$datetime = new DateTime($date);
1213 1281
 			$offset = $datetime->format('P');
1214
-		} else $offset = '+00:00';
1282
+		} else {
1283
+			$offset = '+00:00';
1284
+		}
1215 1285
 
1216 1286
 		if ($globalDBdriver == 'mysql') {
1217 1287
 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
@@ -1259,7 +1329,9 @@  discard block
 block discarded – undo
1259 1329
 			date_default_timezone_set($globalTimezone);
1260 1330
 			$datetime = new DateTime();
1261 1331
 			$offset = $datetime->format('P');
1262
-		} else $offset = '+00:00';
1332
+		} else {
1333
+			$offset = '+00:00';
1334
+		}
1263 1335
 
1264 1336
 		if ($globalDBdriver == 'mysql') {
1265 1337
 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
@@ -1323,8 +1395,11 @@  discard block
 block discarded – undo
1323 1395
 				$query_values = array_merge($query_values,array(':month' => $month));
1324 1396
 			}
1325 1397
 		}
1326
-		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1327
-		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1398
+		if (empty($query_values)) {
1399
+			$queryi .= $this->getFilter($filters);
1400
+		} else {
1401
+			$queryi .= $this->getFilter($filters,true,true).substr($query,4);
1402
+		}
1328 1403
 		
1329 1404
 		$sth = $this->db->prepare($queryi);
1330 1405
 		$sth->execute($query_values);
@@ -1346,7 +1421,9 @@  discard block
 block discarded – undo
1346 1421
 			date_default_timezone_set($globalTimezone);
1347 1422
 			$datetime = new DateTime();
1348 1423
 			$offset = $datetime->format('P');
1349
-		} else $offset = '+00:00';
1424
+		} else {
1425
+			$offset = '+00:00';
1426
+		}
1350 1427
 
1351 1428
 		if ($globalDBdriver == 'mysql') {
1352 1429
 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
@@ -1450,7 +1527,9 @@  discard block
 block discarded – undo
1450 1527
 	*/
1451 1528
 	public function parseDirection($direction = 0)
1452 1529
 	{
1453
-		if ($direction == '') $direction = 0;
1530
+		if ($direction == '') {
1531
+			$direction = 0;
1532
+		}
1454 1533
 		$direction_array = array();
1455 1534
 		$temp_array = array();
1456 1535
 
@@ -1539,7 +1618,9 @@  discard block
 block discarded – undo
1539 1618
 		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1540 1619
 	
1541 1620
 		$Connection = new Connection($this->db);
1542
-		if (!$Connection->tableExists('countries')) return '';
1621
+		if (!$Connection->tableExists('countries')) {
1622
+			return '';
1623
+		}
1543 1624
 	
1544 1625
 		try {
1545 1626
 			/*
@@ -1559,9 +1640,13 @@  discard block
 block discarded – undo
1559 1640
 			$sth->closeCursor();
1560 1641
 			if (count($row) > 0) {
1561 1642
 				return $row;
1562
-			} else return '';
1643
+			} else {
1644
+				return '';
1645
+			}
1563 1646
 		} catch (PDOException $e) {
1564
-			if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n";
1647
+			if (isset($globalDebug) && $globalDebug) {
1648
+				echo 'Error : '.$e->getMessage()."\n";
1649
+			}
1565 1650
 			return '';
1566 1651
 		}
1567 1652
 	
@@ -1579,7 +1664,9 @@  discard block
 block discarded – undo
1579 1664
 		$iso2 = filter_var($iso2,FILTER_SANITIZE_STRING);
1580 1665
 	
1581 1666
 		$Connection = new Connection($this->db);
1582
-		if (!$Connection->tableExists('countries')) return '';
1667
+		if (!$Connection->tableExists('countries')) {
1668
+			return '';
1669
+		}
1583 1670
 	
1584 1671
 		try {
1585 1672
 			$query = "SELECT name,iso2,iso3 FROM countries WHERE iso2 = :iso2 LIMIT 1";
@@ -1591,9 +1678,13 @@  discard block
 block discarded – undo
1591 1678
 			$sth->closeCursor();
1592 1679
 			if (count($row) > 0) {
1593 1680
 				return $row;
1594
-			} else return '';
1681
+			} else {
1682
+				return '';
1683
+			}
1595 1684
 		} catch (PDOException $e) {
1596
-			if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n";
1685
+			if (isset($globalDebug) && $globalDebug) {
1686
+				echo 'Error : '.$e->getMessage()."\n";
1687
+			}
1597 1688
 			return '';
1598 1689
 		}
1599 1690
 	
@@ -1611,7 +1702,9 @@  discard block
 block discarded – undo
1611 1702
 	{
1612 1703
 		global $globalBitlyAccessToken;
1613 1704
 		
1614
-		if ($globalBitlyAccessToken == '') return $url;
1705
+		if ($globalBitlyAccessToken == '') {
1706
+			return $url;
1707
+		}
1615 1708
         
1616 1709
 		$google_url = 'https://api-ssl.bitly.com/v3/shorten?access_token='.$globalBitlyAccessToken.'&longUrl='.$url;
1617 1710
 		
Please login to merge, or discard this patch.
require/class.MarineLive.php 4 patches
Doc Comments   +1 added lines, -5 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 	/**
15 15
 	* Get SQL query part for filter used
16 16
 	* @param Array $filter the filter
17
-	* @return Array the SQL part
17
+	* @return string the SQL part
18 18
 	*/
19 19
 	public function getFilter($filter = array(),$where = false,$and = false) {
20 20
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
@@ -762,10 +762,6 @@  discard block
 block discarded – undo
762 762
 	*
763 763
 	* @param String $fammarine_id the ID from flightaware
764 764
 	* @param String $ident the flight ident
765
-	* @param String $aircraft_icao the aircraft type
766
-	* @param String $departure_airport_icao the departure airport
767
-	* @param String $arrival_airport_icao the arrival airport
768
-	* @return String success or false
769 765
 	*
770 766
 	*/
771 767
 	public function addLiveMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $putinarchive = false, $mmsi = '',$type = '',$imo = '', $callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$noarchive = false,$format_source = '', $source_name = '', $over_country = '')
Please login to merge, or discard this patch.
Indentation   +187 added lines, -187 removed lines patch added patch discarded remove patch
@@ -12,10 +12,10 @@  discard block
 block discarded – undo
12 12
 
13 13
 
14 14
 	/**
15
-	* Get SQL query part for filter used
16
-	* @param Array $filter the filter
17
-	* @return Array the SQL part
18
-	*/
15
+	 * Get SQL query part for filter used
16
+	 * @param Array $filter the filter
17
+	 * @return Array the SQL part
18
+	 */
19 19
 	public function getFilter($filter = array(),$where = false,$and = false) {
20 20
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
21 21
 		$filters = array();
@@ -86,11 +86,11 @@  discard block
 block discarded – undo
86 86
 	}
87 87
 
88 88
 	/**
89
-	* Gets all the spotter information based on the latest data entry
90
-	*
91
-	* @return Array the spotter information
92
-	*
93
-	*/
89
+	 * Gets all the spotter information based on the latest data entry
90
+	 *
91
+	 * @return Array the spotter information
92
+	 *
93
+	 */
94 94
 	public function getLiveMarineData($limit = '', $sort = '', $filter = array())
95 95
 	{
96 96
 		global $globalDBdriver, $globalLiveInterval;
@@ -132,11 +132,11 @@  discard block
 block discarded – undo
132 132
 	}
133 133
 
134 134
 	/**
135
-	* Gets Minimal Live Spotter data
136
-	*
137
-	* @return Array the spotter information
138
-	*
139
-	*/
135
+	 * Gets Minimal Live Spotter data
136
+	 *
137
+	 * @return Array the spotter information
138
+	 *
139
+	 */
140 140
 	public function getMinLiveMarineData($filter = array())
141 141
 	{
142 142
 		global $globalDBdriver, $globalLiveInterval;
@@ -166,11 +166,11 @@  discard block
 block discarded – undo
166 166
 	}
167 167
 
168 168
 	/**
169
-	* Gets Minimal Live Spotter data since xx seconds
170
-	*
171
-	* @return Array the spotter information
172
-	*
173
-	*/
169
+	 * Gets Minimal Live Spotter data since xx seconds
170
+	 *
171
+	 * @return Array the spotter information
172
+	 *
173
+	 */
174 174
 	public function getMinLastLiveMarineData($filter = array())
175 175
 	{
176 176
 		global $globalDBdriver, $globalLiveInterval;
@@ -183,13 +183,13 @@  discard block
 block discarded – undo
183 183
 			$query  = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
184 184
 			FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= marine_live.date AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
185 185
 			ORDER BY marine_live.fammarine_id, marine_live.date";
186
-                } else {
186
+				} else {
187 187
 			$query  = "SELECT marine_live.ident, marine_live.fammarine_id, marine_live.type,marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
188 188
 			FROM marine_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= marine_live.date AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
189 189
 			ORDER BY marine_live.fammarine_id, marine_live.date";
190 190
 		}
191 191
 
192
-    		try {
192
+			try {
193 193
 			$sth = $this->db->prepare($query);
194 194
 			$sth->execute();
195 195
 		} catch(PDOException $e) {
@@ -201,11 +201,11 @@  discard block
 block discarded – undo
201 201
 	}
202 202
 
203 203
 	/**
204
-	* Gets number of latest data entry
205
-	*
206
-	* @return String number of entry
207
-	*
208
-	*/
204
+	 * Gets number of latest data entry
205
+	 *
206
+	 * @return String number of entry
207
+	 *
208
+	 */
209 209
 	public function getLiveMarineCount($filter = array())
210 210
 	{
211 211
 		global $globalDBdriver, $globalLiveInterval;
@@ -230,11 +230,11 @@  discard block
 block discarded – undo
230 230
 	}
231 231
 
232 232
 	/**
233
-	* Gets all the spotter information based on the latest data entry and coord
234
-	*
235
-	* @return Array the spotter information
236
-	*
237
-	*/
233
+	 * Gets all the spotter information based on the latest data entry and coord
234
+	 *
235
+	 * @return Array the spotter information
236
+	 *
237
+	 */
238 238
 	public function getLiveMarineDatabyCoord($coord, $filter = array())
239 239
 	{
240 240
 		global $globalDBdriver, $globalLiveInterval;
@@ -258,11 +258,11 @@  discard block
 block discarded – undo
258 258
 	}
259 259
 
260 260
 	/**
261
-	* Gets all the spotter information based on a user's latitude and longitude
262
-	*
263
-	* @return Array the spotter information
264
-	*
265
-	*/
261
+	 * Gets all the spotter information based on a user's latitude and longitude
262
+	 *
263
+	 * @return Array the spotter information
264
+	 *
265
+	 */
266 266
 	public function getLatestMarineForLayar($lat, $lng, $radius, $interval)
267 267
 	{
268 268
 		$Marine = new Marine($this->db);
@@ -275,134 +275,134 @@  discard block
 block discarded – undo
275 275
 		if ($lng != '')
276 276
 		{
277 277
 			if (!is_numeric($lng))
278
-                        {
279
-                                return false;
280
-                        }
281
-                }
282
-
283
-                if ($radius != '')
284
-                {
285
-                        if (!is_numeric($radius))
286
-                        {
287
-                                return false;
288
-                        }
289
-                }
278
+						{
279
+								return false;
280
+						}
281
+				}
282
+
283
+				if ($radius != '')
284
+				{
285
+						if (!is_numeric($radius))
286
+						{
287
+								return false;
288
+						}
289
+				}
290 290
 		$additional_query = '';
291 291
 		if ($interval != '')
292
-                {
293
-                        if (!is_string($interval))
294
-                        {
295
-                                //$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
296
-			        return false;
297
-                        } else {
298
-                if ($interval == '1m')
299
-                {
300
-                    $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
301
-                } else if ($interval == '15m'){
302
-                    $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= marine_live.date ';
303
-                } 
304
-            }
305
-                } else {
306
-         $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';   
307
-        }
308
-
309
-                $query  = "SELECT marine_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM marine_live 
292
+				{
293
+						if (!is_string($interval))
294
+						{
295
+								//$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
296
+					return false;
297
+						} else {
298
+				if ($interval == '1m')
299
+				{
300
+					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
301
+				} else if ($interval == '15m'){
302
+					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= marine_live.date ';
303
+				} 
304
+			}
305
+				} else {
306
+		 $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';   
307
+		}
308
+
309
+				$query  = "SELECT marine_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM marine_live 
310 310
                    WHERE marine_live.latitude <> '' 
311 311
                                    AND marine_live.longitude <> '' 
312 312
                    ".$additional_query."
313 313
                    HAVING distance < :radius  
314 314
                                    ORDER BY distance";
315 315
 
316
-                $spotter_array = $Marine->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius));
316
+				$spotter_array = $Marine->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius));
317 317
 
318
-                return $spotter_array;
319
-        }
318
+				return $spotter_array;
319
+		}
320 320
 
321 321
     
322
-        /**
323
-	* Gets all the spotter information based on a particular callsign
324
-	*
325
-	* @return Array the spotter information
326
-	*
327
-	*/
322
+		/**
323
+		 * Gets all the spotter information based on a particular callsign
324
+		 *
325
+		 * @return Array the spotter information
326
+		 *
327
+		 */
328 328
 	public function getLastLiveMarineDataByIdent($ident)
329 329
 	{
330 330
 		$Marine = new Marine($this->db);
331 331
 		date_default_timezone_set('UTC');
332 332
 
333 333
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
334
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
334
+				$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
335 335
 
336 336
 		$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident),'',true);
337 337
 
338 338
 		return $spotter_array;
339 339
 	}
340 340
 
341
-        /**
342
-	* Gets all the spotter information based on a particular callsign
343
-	*
344
-	* @return Array the spotter information
345
-	*
346
-	*/
341
+		/**
342
+		 * Gets all the spotter information based on a particular callsign
343
+		 *
344
+		 * @return Array the spotter information
345
+		 *
346
+		 */
347 347
 	public function getDateLiveMarineDataByIdent($ident,$date)
348 348
 	{
349 349
 		$Marine = new Marine($this->db);
350 350
 		date_default_timezone_set('UTC');
351 351
 
352 352
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
353
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
353
+				$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
354 354
 
355
-                $date = date('c',$date);
355
+				$date = date('c',$date);
356 356
 		$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident,':date' => $date));
357 357
 
358 358
 		return $spotter_array;
359 359
 	}
360 360
 
361
-        /**
362
-	* Gets last spotter information based on a particular callsign
363
-	*
364
-	* @return Array the spotter information
365
-	*
366
-	*/
361
+		/**
362
+		 * Gets last spotter information based on a particular callsign
363
+		 *
364
+		 * @return Array the spotter information
365
+		 *
366
+		 */
367 367
 	public function getLastLiveMarineDataById($id)
368 368
 	{
369 369
 		$Marine = new Marine($this->db);
370 370
 		date_default_timezone_set('UTC');
371 371
 
372 372
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
373
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
373
+				$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
374 374
 
375 375
 		$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id),'',true);
376 376
 
377 377
 		return $spotter_array;
378 378
 	}
379 379
 
380
-        /**
381
-	* Gets last spotter information based on a particular callsign
382
-	*
383
-	* @return Array the spotter information
384
-	*
385
-	*/
380
+		/**
381
+		 * Gets last spotter information based on a particular callsign
382
+		 *
383
+		 * @return Array the spotter information
384
+		 *
385
+		 */
386 386
 	public function getDateLiveMarineDataById($id,$date)
387 387
 	{
388 388
 		$Marine = new Marine($this->db);
389 389
 		date_default_timezone_set('UTC');
390 390
 
391 391
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
392
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
393
-                $date = date('c',$date);
392
+				$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
393
+				$date = date('c',$date);
394 394
 		$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id,':date' => $date),'',true);
395 395
 
396 396
 		return $spotter_array;
397 397
 	}
398 398
 
399 399
 
400
-        /**
401
-	* Gets all the spotter information based on a particular id
402
-	*
403
-	* @return Array the spotter information
404
-	*
405
-	*/
400
+		/**
401
+		 * Gets all the spotter information based on a particular id
402
+		 *
403
+		 * @return Array the spotter information
404
+		 *
405
+		 */
406 406
 	public function getAllLiveMarineDataById($id,$liveinterval = false)
407 407
 	{
408 408
 		global $globalDBdriver, $globalLiveInterval;
@@ -430,18 +430,18 @@  discard block
 block discarded – undo
430 430
 		return $spotter_array;
431 431
 	}
432 432
 
433
-        /**
434
-	* Gets all the spotter information based on a particular ident
435
-	*
436
-	* @return Array the spotter information
437
-	*
438
-	*/
433
+		/**
434
+		 * Gets all the spotter information based on a particular ident
435
+		 *
436
+		 * @return Array the spotter information
437
+		 *
438
+		 */
439 439
 	public function getAllLiveMarineDataByIdent($ident)
440 440
 	{
441 441
 		date_default_timezone_set('UTC');
442 442
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
443 443
 		$query  = self::$global_query.' WHERE marine_live.ident = :ident';
444
-    		try {
444
+			try {
445 445
 			
446 446
 			$sth = $this->db->prepare($query);
447 447
 			$sth->execute(array(':ident' => $ident));
@@ -455,23 +455,23 @@  discard block
 block discarded – undo
455 455
 
456 456
 
457 457
 	/**
458
-	* Deletes all info in the table
459
-	*
460
-	* @return String success or false
461
-	*
462
-	*/
458
+	 * Deletes all info in the table
459
+	 *
460
+	 * @return String success or false
461
+	 *
462
+	 */
463 463
 	public function deleteLiveMarineData()
464 464
 	{
465 465
 		global $globalDBdriver;
466 466
 		if ($globalDBdriver == 'mysql') {
467 467
 			//$query  = "DELETE FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE) >= marine_live.date";
468 468
 			$query  = 'DELETE FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 9 HOUR) >= marine_live.date';
469
-            		//$query  = "DELETE FROM marine_live WHERE marine_live.id IN (SELECT marine_live.id FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= marine_live.date)";
469
+					//$query  = "DELETE FROM marine_live WHERE marine_live.id IN (SELECT marine_live.id FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= marine_live.date)";
470 470
 		} else {
471 471
 			$query  = "DELETE FROM marine_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= marine_live.date";
472 472
 		}
473 473
         
474
-    		try {
474
+			try {
475 475
 			
476 476
 			$sth = $this->db->prepare($query);
477 477
 			$sth->execute();
@@ -483,18 +483,18 @@  discard block
 block discarded – undo
483 483
 	}
484 484
 
485 485
 	/**
486
-	* Deletes all info in the table for aircraft not seen since 2 HOUR
487
-	*
488
-	* @return String success or false
489
-	*
490
-	*/
486
+	 * Deletes all info in the table for aircraft not seen since 2 HOUR
487
+	 *
488
+	 * @return String success or false
489
+	 *
490
+	 */
491 491
 	public function deleteLiveMarineDataNotUpdated()
492 492
 	{
493 493
 		global $globalDBdriver, $globalDebug;
494 494
 		if ($globalDBdriver == 'mysql') {
495 495
 			//$query = 'SELECT fammarine_id FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) >= marine_live.date AND marine_live.fammarine_id NOT IN (SELECT fammarine_id FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) < marine_live.date) LIMIT 800 OFFSET 0';
496
-    			$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 1200 OFFSET 0";
497
-    			try {
496
+				$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 1200 OFFSET 0";
497
+				try {
498 498
 				
499 499
 				$sth = $this->db->prepare($query);
500 500
 				$sth->execute();
@@ -502,8 +502,8 @@  discard block
 block discarded – undo
502 502
 				return "error";
503 503
 			}
504 504
 			$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
505
-                        $i = 0;
506
-                        $j =0;
505
+						$i = 0;
506
+						$j =0;
507 507
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
508 508
 			foreach($all as $row)
509 509
 			{
@@ -511,20 +511,20 @@  discard block
 block discarded – undo
511 511
 				$j++;
512 512
 				if ($j == 30) {
513 513
 					if ($globalDebug) echo ".";
514
-				    	try {
514
+						try {
515 515
 						
516 516
 						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
517 517
 						$sth->execute();
518 518
 					} catch(PDOException $e) {
519 519
 						return "error";
520 520
 					}
521
-                                	$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
522
-                                	$j = 0;
521
+									$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
522
+									$j = 0;
523 523
 				}
524 524
 				$query_delete .= "'".$row['fammarine_id']."',";
525 525
 			}
526 526
 			if ($i > 0) {
527
-    				try {
527
+					try {
528 528
 					
529 529
 					$sth = $this->db->prepare(substr($query_delete,0,-1).")");
530 530
 					$sth->execute();
@@ -535,9 +535,9 @@  discard block
 block discarded – undo
535 535
 			return "success";
536 536
 		} elseif ($globalDBdriver == 'pgsql') {
537 537
 			//$query = "SELECT fammarine_id FROM marine_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= marine_live.date AND marine_live.fammarine_id NOT IN (SELECT fammarine_id FROM marine_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' < marine_live.date) LIMIT 800 OFFSET 0";
538
-    			//$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0";
539
-    			$query = "DELETE FROM marine_live WHERE fammarine_id IN (SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0)";
540
-    			try {
538
+				//$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0";
539
+				$query = "DELETE FROM marine_live WHERE fammarine_id IN (SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0)";
540
+				try {
541 541
 				
542 542
 				$sth = $this->db->prepare($query);
543 543
 				$sth->execute();
@@ -581,17 +581,17 @@  discard block
 block discarded – undo
581 581
 	}
582 582
 
583 583
 	/**
584
-	* Deletes all info in the table for an ident
585
-	*
586
-	* @return String success or false
587
-	*
588
-	*/
584
+	 * Deletes all info in the table for an ident
585
+	 *
586
+	 * @return String success or false
587
+	 *
588
+	 */
589 589
 	public function deleteLiveMarineDataByIdent($ident)
590 590
 	{
591 591
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
592 592
 		$query  = 'DELETE FROM marine_live WHERE ident = :ident';
593 593
         
594
-    		try {
594
+			try {
595 595
 			
596 596
 			$sth = $this->db->prepare($query);
597 597
 			$sth->execute(array(':ident' => $ident));
@@ -603,17 +603,17 @@  discard block
 block discarded – undo
603 603
 	}
604 604
 
605 605
 	/**
606
-	* Deletes all info in the table for an id
607
-	*
608
-	* @return String success or false
609
-	*
610
-	*/
606
+	 * Deletes all info in the table for an id
607
+	 *
608
+	 * @return String success or false
609
+	 *
610
+	 */
611 611
 	public function deleteLiveMarineDataById($id)
612 612
 	{
613 613
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
614 614
 		$query  = 'DELETE FROM marine_live WHERE fammarine_id = :id';
615 615
         
616
-    		try {
616
+			try {
617 617
 			
618 618
 			$sth = $this->db->prepare($query);
619 619
 			$sth->execute(array(':id' => $id));
@@ -626,11 +626,11 @@  discard block
 block discarded – undo
626 626
 
627 627
 
628 628
 	/**
629
-	* Gets the aircraft ident within the last hour
630
-	*
631
-	* @return String the ident
632
-	*
633
-	*/
629
+	 * Gets the aircraft ident within the last hour
630
+	 *
631
+	 * @return String the ident
632
+	 *
633
+	 */
634 634
 	public function getIdentFromLastHour($ident)
635 635
 	{
636 636
 		global $globalDBdriver, $globalTimezone;
@@ -656,14 +656,14 @@  discard block
 block discarded – undo
656 656
 			$ident_result = $row['ident'];
657 657
 		}
658 658
 		return $ident_result;
659
-        }
659
+		}
660 660
 
661 661
 	/**
662
-	* Check recent aircraft
663
-	*
664
-	* @return String the ident
665
-	*
666
-	*/
662
+	 * Check recent aircraft
663
+	 *
664
+	 * @return String the ident
665
+	 *
666
+	 */
667 667
 	public function checkIdentRecent($ident)
668 668
 	{
669 669
 		global $globalDBdriver, $globalTimezone;
@@ -689,14 +689,14 @@  discard block
 block discarded – undo
689 689
 			$ident_result = $row['fammarine_id'];
690 690
 		}
691 691
 		return $ident_result;
692
-        }
692
+		}
693 693
 
694 694
 	/**
695
-	* Check recent aircraft by id
696
-	*
697
-	* @return String the ident
698
-	*
699
-	*/
695
+	 * Check recent aircraft by id
696
+	 *
697
+	 * @return String the ident
698
+	 *
699
+	 */
700 700
 	public function checkIdRecent($id)
701 701
 	{
702 702
 		global $globalDBdriver, $globalTimezone;
@@ -722,14 +722,14 @@  discard block
 block discarded – undo
722 722
 			$ident_result = $row['fammarine_id'];
723 723
 		}
724 724
 		return $ident_result;
725
-        }
725
+		}
726 726
 
727 727
 	/**
728
-	* Check recent aircraft by mmsi
729
-	*
730
-	* @return String the ident
731
-	*
732
-	*/
728
+	 * Check recent aircraft by mmsi
729
+	 *
730
+	 * @return String the ident
731
+	 *
732
+	 */
733 733
 	public function checkMMSIRecent($mmsi)
734 734
 	{
735 735
 		global $globalDBdriver, $globalTimezone;
@@ -755,19 +755,19 @@  discard block
 block discarded – undo
755 755
 			$ident_result = $row['fammarine_id'];
756 756
 		}
757 757
 		return $ident_result;
758
-        }
758
+		}
759 759
 
760 760
 	/**
761
-	* Adds a new spotter data
762
-	*
763
-	* @param String $fammarine_id the ID from flightaware
764
-	* @param String $ident the flight ident
765
-	* @param String $aircraft_icao the aircraft type
766
-	* @param String $departure_airport_icao the departure airport
767
-	* @param String $arrival_airport_icao the arrival airport
768
-	* @return String success or false
769
-	*
770
-	*/
761
+	 * Adds a new spotter data
762
+	 *
763
+	 * @param String $fammarine_id the ID from flightaware
764
+	 * @param String $ident the flight ident
765
+	 * @param String $aircraft_icao the aircraft type
766
+	 * @param String $departure_airport_icao the departure airport
767
+	 * @param String $arrival_airport_icao the arrival airport
768
+	 * @return String success or false
769
+	 *
770
+	 */
771 771
 	public function addLiveMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $putinarchive = false, $mmsi = '',$type = '',$imo = '', $callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$noarchive = false,$format_source = '', $source_name = '', $over_country = '')
772 772
 	{
773 773
 		global $globalURL, $globalArchive, $globalDebug;
@@ -838,9 +838,9 @@  discard block
 block discarded – undo
838 838
 		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING);
839 839
 		
840 840
 
841
-            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
842
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
843
-            	if ($arrival_date == '') $arrival_date = NULL;
841
+				if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
842
+				if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
843
+				if ($arrival_date == '') $arrival_date = NULL;
844 844
 		$query  = 'INSERT INTO marine_live (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, over_country, mmsi, type,status,imo,arrival_port_name,arrival_port_date) 
845 845
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:groundspeed,:date,:format_source, :source_name, :over_country,:mmsi,:type,:status,:imo,:arrival_port_name,:arrival_port_date)';
846 846
 
@@ -849,9 +849,9 @@  discard block
 block discarded – undo
849 849
 			
850 850
 			$sth = $this->db->prepare($query);
851 851
 			$sth->execute($query_values);
852
-                } catch(PDOException $e) {
853
-                	return "error : ".$e->getMessage();
854
-                }
852
+				} catch(PDOException $e) {
853
+					return "error : ".$e->getMessage();
854
+				}
855 855
 		/*
856 856
 		if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) {
857 857
 		    if ($globalDebug) echo '(Add to SBS archive : ';
Please login to merge, or discard this patch.
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -16,33 +16,33 @@  discard block
 block discarded – undo
16 16
 	* @param Array $filter the filter
17 17
 	* @return Array the SQL part
18 18
 	*/
19
-	public function getFilter($filter = array(),$where = false,$and = false) {
19
+	public function getFilter($filter = array(), $where = false, $and = false) {
20 20
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
21 21
 		$filters = array();
22 22
 		if (is_array($globalStatsFilters) && isset($globalStatsFilters[$globalFilterName])) {
23 23
 			if (isset($globalStatsFilters[$globalFilterName][0]['source'])) {
24 24
 				$filters = $globalStatsFilters[$globalFilterName];
25 25
 			} else {
26
-				$filter = array_merge($filter,$globalStatsFilters[$globalFilterName]);
26
+				$filter = array_merge($filter, $globalStatsFilters[$globalFilterName]);
27 27
 			}
28 28
 		}
29 29
 		if (isset($filter[0]['source'])) {
30
-			$filters = array_merge($filters,$filter);
30
+			$filters = array_merge($filters, $filter);
31 31
 		}
32
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
32
+		if (is_array($globalFilter)) $filter = array_merge($filter, $globalFilter);
33 33
 		$filter_query_join = '';
34 34
 		$filter_query_where = '';
35
-		foreach($filters as $flt) {
35
+		foreach ($filters as $flt) {
36 36
 			if (isset($flt['idents']) && !empty($flt['idents'])) {
37 37
 				if (isset($flt['source'])) {
38
-					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','",$flt['idents'])."') AND marine_output.format_source IN ('".implode("','",$flt['source'])."')) spid ON spid.fammarine_id = marine_live.fammarine_id";
38
+					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','", $flt['idents'])."') AND marine_output.format_source IN ('".implode("','", $flt['source'])."')) spid ON spid.fammarine_id = marine_live.fammarine_id";
39 39
 				} else {
40
-					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','",$flt['idents'])."')) spid ON spid.fammarine_id = marine_live.fammarine_id";
40
+					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','", $flt['idents'])."')) spid ON spid.fammarine_id = marine_live.fammarine_id";
41 41
 				}
42 42
 			}
43 43
 		}
44 44
 		if (isset($filter['source']) && !empty($filter['source'])) {
45
-			$filter_query_where .= " AND format_source IN ('".implode("','",$filter['source'])."')";
45
+			$filter_query_where .= " AND format_source IN ('".implode("','", $filter['source'])."')";
46 46
 		}
47 47
 		if (isset($filter['ident']) && !empty($filter['ident'])) {
48 48
 			$filter_query_where .= " AND ident = '".$filter['ident']."'";
@@ -71,15 +71,15 @@  discard block
 block discarded – undo
71 71
 					$filter_query_date .= " AND EXTRACT(DAY FROM marine_output.date) = '".$filter['day']."'";
72 72
 				}
73 73
 			}
74
-			$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output".preg_replace('/^ AND/',' WHERE',$filter_query_date).") sd ON sd.fammarine_id = marine_live.fammarine_id";
74
+			$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output".preg_replace('/^ AND/', ' WHERE', $filter_query_date).") sd ON sd.fammarine_id = marine_live.fammarine_id";
75 75
 		}
76 76
 		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
77
-			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
77
+			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','", $filter['source_aprs'])."')";
78 78
 		}
79 79
 		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
80 80
 		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
81 81
 		if ($filter_query_where != '') {
82
-			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
82
+			$filter_query_where = preg_replace('/^ AND/', ' WHERE', $filter_query_where);
83 83
 		}
84 84
 		$filter_query = $filter_query_join.$filter_query_where;
85 85
 		return $filter_query;
@@ -102,8 +102,8 @@  discard block
 block discarded – undo
102 102
 		if ($limit != '')
103 103
 		{
104 104
 			$limit_array = explode(',', $limit);
105
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
106
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
105
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
106
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
107 107
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
108 108
 			{
109 109
 				$limit_query = ' LIMIT '.$limit_array[1].' OFFSET '.$limit_array[0];
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 		} else {
127 127
 			$query  = "SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate".$filter_query.$orderby_query;
128 128
 		}
129
-		$spotter_array = $Marine->getDataFromDB($query.$limit_query,array(),'',true);
129
+		$spotter_array = $Marine->getDataFromDB($query.$limit_query, array(), '', true);
130 130
 
131 131
 		return $spotter_array;
132 132
 	}
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 		global $globalDBdriver, $globalLiveInterval;
143 143
 		date_default_timezone_set('UTC');
144 144
 
145
-		$filter_query = $this->getFilter($filter,true,true);
145
+		$filter_query = $this->getFilter($filter, true, true);
146 146
 
147 147
 		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
148 148
 		if ($globalDBdriver == 'mysql') {
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 		try {
157 157
 			$sth = $this->db->prepare($query);
158 158
 			$sth->execute();
159
-		} catch(PDOException $e) {
159
+		} catch (PDOException $e) {
160 160
 			echo $e->getMessage();
161 161
 			die;
162 162
 		}
@@ -176,15 +176,15 @@  discard block
 block discarded – undo
176 176
 		global $globalDBdriver, $globalLiveInterval;
177 177
 		date_default_timezone_set('UTC');
178 178
 
179
-		$filter_query = $this->getFilter($filter,true,true);
179
+		$filter_query = $this->getFilter($filter, true, true);
180 180
 
181 181
 		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
182 182
 		if ($globalDBdriver == 'mysql') {
183
-			$query  = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
183
+			$query = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
184 184
 			FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= marine_live.date AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
185 185
 			ORDER BY marine_live.fammarine_id, marine_live.date";
186 186
                 } else {
187
-			$query  = "SELECT marine_live.ident, marine_live.fammarine_id, marine_live.type,marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
187
+			$query = "SELECT marine_live.ident, marine_live.fammarine_id, marine_live.type,marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
188 188
 			FROM marine_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= marine_live.date AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
189 189
 			ORDER BY marine_live.fammarine_id, marine_live.date";
190 190
 		}
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
     		try {
193 193
 			$sth = $this->db->prepare($query);
194 194
 			$sth->execute();
195
-		} catch(PDOException $e) {
195
+		} catch (PDOException $e) {
196 196
 			echo $e->getMessage();
197 197
 			die;
198 198
 		}
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 	public function getLiveMarineCount($filter = array())
210 210
 	{
211 211
 		global $globalDBdriver, $globalLiveInterval;
212
-		$filter_query = $this->getFilter($filter,true,true);
212
+		$filter_query = $this->getFilter($filter, true, true);
213 213
 
214 214
 		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
215 215
 		if ($globalDBdriver == 'mysql') {
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 		try {
221 221
 			$sth = $this->db->prepare($query);
222 222
 			$sth->execute();
223
-		} catch(PDOException $e) {
223
+		} catch (PDOException $e) {
224 224
 			echo $e->getMessage();
225 225
 			die;
226 226
 		}
@@ -243,10 +243,10 @@  discard block
 block discarded – undo
243 243
 		$filter_query = $this->getFilter($filter);
244 244
 
245 245
 		if (is_array($coord)) {
246
-			$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
247
-			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
248
-			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
249
-			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
246
+			$minlong = filter_var($coord[0], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
247
+			$minlat = filter_var($coord[1], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
248
+			$maxlong = filter_var($coord[2], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
249
+			$maxlat = filter_var($coord[3], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
250 250
 		} else return array();
251 251
 		if ($globalDBdriver == 'mysql') {
252 252
 			$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND marine_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND marine_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.' GROUP BY marine_live.fammarine_id'.$filter_query;
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
                 if ($interval == '1m')
299 299
                 {
300 300
                     $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
301
-                } else if ($interval == '15m'){
301
+                } else if ($interval == '15m') {
302 302
                     $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= marine_live.date ';
303 303
                 } 
304 304
             }
@@ -306,14 +306,14 @@  discard block
 block discarded – undo
306 306
          $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';   
307 307
         }
308 308
 
309
-                $query  = "SELECT marine_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM marine_live 
309
+                $query = "SELECT marine_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM marine_live 
310 310
                    WHERE marine_live.latitude <> '' 
311 311
                                    AND marine_live.longitude <> '' 
312 312
                    ".$additional_query."
313 313
                    HAVING distance < :radius  
314 314
                                    ORDER BY distance";
315 315
 
316
-                $spotter_array = $Marine->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius));
316
+                $spotter_array = $Marine->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng, ':radius' => $radius));
317 317
 
318 318
                 return $spotter_array;
319 319
         }
@@ -331,9 +331,9 @@  discard block
 block discarded – undo
331 331
 		date_default_timezone_set('UTC');
332 332
 
333 333
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
334
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
334
+                $query = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
335 335
 
336
-		$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident),'',true);
336
+		$spotter_array = $Marine->getDataFromDB($query, array(':ident' => $ident), '', true);
337 337
 
338 338
 		return $spotter_array;
339 339
 	}
@@ -344,16 +344,16 @@  discard block
 block discarded – undo
344 344
 	* @return Array the spotter information
345 345
 	*
346 346
 	*/
347
-	public function getDateLiveMarineDataByIdent($ident,$date)
347
+	public function getDateLiveMarineDataByIdent($ident, $date)
348 348
 	{
349 349
 		$Marine = new Marine($this->db);
350 350
 		date_default_timezone_set('UTC');
351 351
 
352 352
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
353
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
353
+                $query = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
354 354
 
355
-                $date = date('c',$date);
356
-		$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident,':date' => $date));
355
+                $date = date('c', $date);
356
+		$spotter_array = $Marine->getDataFromDB($query, array(':ident' => $ident, ':date' => $date));
357 357
 
358 358
 		return $spotter_array;
359 359
 	}
@@ -370,9 +370,9 @@  discard block
 block discarded – undo
370 370
 		date_default_timezone_set('UTC');
371 371
 
372 372
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
373
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
373
+                $query = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
374 374
 
375
-		$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id),'',true);
375
+		$spotter_array = $Marine->getDataFromDB($query, array(':id' => $id), '', true);
376 376
 
377 377
 		return $spotter_array;
378 378
 	}
@@ -383,15 +383,15 @@  discard block
 block discarded – undo
383 383
 	* @return Array the spotter information
384 384
 	*
385 385
 	*/
386
-	public function getDateLiveMarineDataById($id,$date)
386
+	public function getDateLiveMarineDataById($id, $date)
387 387
 	{
388 388
 		$Marine = new Marine($this->db);
389 389
 		date_default_timezone_set('UTC');
390 390
 
391 391
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
392
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
393
-                $date = date('c',$date);
394
-		$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id,':date' => $date),'',true);
392
+                $query = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
393
+                $date = date('c', $date);
394
+		$spotter_array = $Marine->getDataFromDB($query, array(':id' => $id, ':date' => $date), '', true);
395 395
 
396 396
 		return $spotter_array;
397 397
 	}
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
 	* @return Array the spotter information
404 404
 	*
405 405
 	*/
406
-	public function getAllLiveMarineDataById($id,$liveinterval = false)
406
+	public function getAllLiveMarineDataById($id, $liveinterval = false)
407 407
 	{
408 408
 		global $globalDBdriver, $globalLiveInterval;
409 409
 		date_default_timezone_set('UTC');
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
 		try {
423 423
 			$sth = $this->db->prepare($query);
424 424
 			$sth->execute(array(':id' => $id));
425
-		} catch(PDOException $e) {
425
+		} catch (PDOException $e) {
426 426
 			echo $e->getMessage();
427 427
 			die;
428 428
 		}
@@ -440,12 +440,12 @@  discard block
 block discarded – undo
440 440
 	{
441 441
 		date_default_timezone_set('UTC');
442 442
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
443
-		$query  = self::$global_query.' WHERE marine_live.ident = :ident';
443
+		$query = self::$global_query.' WHERE marine_live.ident = :ident';
444 444
     		try {
445 445
 			
446 446
 			$sth = $this->db->prepare($query);
447 447
 			$sth->execute(array(':ident' => $ident));
448
-		} catch(PDOException $e) {
448
+		} catch (PDOException $e) {
449 449
 			echo $e->getMessage();
450 450
 			die;
451 451
 		}
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
 			
476 476
 			$sth = $this->db->prepare($query);
477 477
 			$sth->execute();
478
-		} catch(PDOException $e) {
478
+		} catch (PDOException $e) {
479 479
 			return "error";
480 480
 		}
481 481
 
@@ -498,14 +498,14 @@  discard block
 block discarded – undo
498 498
 				
499 499
 				$sth = $this->db->prepare($query);
500 500
 				$sth->execute();
501
-			} catch(PDOException $e) {
501
+			} catch (PDOException $e) {
502 502
 				return "error";
503 503
 			}
504 504
 			$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
505 505
                         $i = 0;
506
-                        $j =0;
506
+                        $j = 0;
507 507
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
508
-			foreach($all as $row)
508
+			foreach ($all as $row)
509 509
 			{
510 510
 				$i++;
511 511
 				$j++;
@@ -513,9 +513,9 @@  discard block
 block discarded – undo
513 513
 					if ($globalDebug) echo ".";
514 514
 				    	try {
515 515
 						
516
-						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
516
+						$sth = $this->db->prepare(substr($query_delete, 0, -1).")");
517 517
 						$sth->execute();
518
-					} catch(PDOException $e) {
518
+					} catch (PDOException $e) {
519 519
 						return "error";
520 520
 					}
521 521
                                 	$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
@@ -526,9 +526,9 @@  discard block
 block discarded – undo
526 526
 			if ($i > 0) {
527 527
     				try {
528 528
 					
529
-					$sth = $this->db->prepare(substr($query_delete,0,-1).")");
529
+					$sth = $this->db->prepare(substr($query_delete, 0, -1).")");
530 530
 					$sth->execute();
531
-				} catch(PDOException $e) {
531
+				} catch (PDOException $e) {
532 532
 					return "error";
533 533
 				}
534 534
 			}
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
 				
542 542
 				$sth = $this->db->prepare($query);
543 543
 				$sth->execute();
544
-			} catch(PDOException $e) {
544
+			} catch (PDOException $e) {
545 545
 				return "error";
546 546
 			}
547 547
 /*			$query_delete = "DELETE FROM marine_live WHERE fammarine_id IN (";
@@ -589,13 +589,13 @@  discard block
 block discarded – undo
589 589
 	public function deleteLiveMarineDataByIdent($ident)
590 590
 	{
591 591
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
592
-		$query  = 'DELETE FROM marine_live WHERE ident = :ident';
592
+		$query = 'DELETE FROM marine_live WHERE ident = :ident';
593 593
         
594 594
     		try {
595 595
 			
596 596
 			$sth = $this->db->prepare($query);
597 597
 			$sth->execute(array(':ident' => $ident));
598
-		} catch(PDOException $e) {
598
+		} catch (PDOException $e) {
599 599
 			return "error";
600 600
 		}
601 601
 
@@ -611,13 +611,13 @@  discard block
 block discarded – undo
611 611
 	public function deleteLiveMarineDataById($id)
612 612
 	{
613 613
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
614
-		$query  = 'DELETE FROM marine_live WHERE fammarine_id = :id';
614
+		$query = 'DELETE FROM marine_live WHERE fammarine_id = :id';
615 615
         
616 616
     		try {
617 617
 			
618 618
 			$sth = $this->db->prepare($query);
619 619
 			$sth->execute(array(':id' => $id));
620
-		} catch(PDOException $e) {
620
+		} catch (PDOException $e) {
621 621
 			return "error";
622 622
 		}
623 623
 
@@ -635,13 +635,13 @@  discard block
 block discarded – undo
635 635
 	{
636 636
 		global $globalDBdriver, $globalTimezone;
637 637
 		if ($globalDBdriver == 'mysql') {
638
-			$query  = 'SELECT marine_live.ident FROM marine_live 
638
+			$query = 'SELECT marine_live.ident FROM marine_live 
639 639
 				WHERE marine_live.ident = :ident 
640 640
 				AND marine_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) 
641 641
 				AND marine_live.date < UTC_TIMESTAMP()';
642 642
 			$query_data = array(':ident' => $ident);
643 643
 		} else {
644
-			$query  = "SELECT marine_live.ident FROM marine_live 
644
+			$query = "SELECT marine_live.ident FROM marine_live 
645 645
 				WHERE marine_live.ident = :ident 
646 646
 				AND marine_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
647 647
 				AND marine_live.date < now() AT TIME ZONE 'UTC'";
@@ -650,8 +650,8 @@  discard block
 block discarded – undo
650 650
 		
651 651
 		$sth = $this->db->prepare($query);
652 652
 		$sth->execute($query_data);
653
-		$ident_result='';
654
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
653
+		$ident_result = '';
654
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
655 655
 		{
656 656
 			$ident_result = $row['ident'];
657 657
 		}
@@ -668,13 +668,13 @@  discard block
 block discarded – undo
668 668
 	{
669 669
 		global $globalDBdriver, $globalTimezone;
670 670
 		if ($globalDBdriver == 'mysql') {
671
-			$query  = 'SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
671
+			$query = 'SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
672 672
 				WHERE marine_live.ident = :ident 
673 673
 				AND marine_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE)'; 
674 674
 //				AND marine_live.date < UTC_TIMESTAMP()";
675 675
 			$query_data = array(':ident' => $ident);
676 676
 		} else {
677
-			$query  = "SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
677
+			$query = "SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
678 678
 				WHERE marine_live.ident = :ident 
679 679
 				AND marine_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '30 MINUTES'";
680 680
 //				AND marine_live.date < now() AT TIME ZONE 'UTC'";
@@ -683,8 +683,8 @@  discard block
 block discarded – undo
683 683
 		
684 684
 		$sth = $this->db->prepare($query);
685 685
 		$sth->execute($query_data);
686
-		$ident_result='';
687
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
686
+		$ident_result = '';
687
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
688 688
 		{
689 689
 			$ident_result = $row['fammarine_id'];
690 690
 		}
@@ -701,13 +701,13 @@  discard block
 block discarded – undo
701 701
 	{
702 702
 		global $globalDBdriver, $globalTimezone;
703 703
 		if ($globalDBdriver == 'mysql') {
704
-			$query  = 'SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
704
+			$query = 'SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
705 705
 				WHERE marine_live.fammarine_id = :id 
706 706
 				AND marine_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 10 HOUR)'; 
707 707
 //				AND marine_live.date < UTC_TIMESTAMP()";
708 708
 			$query_data = array(':id' => $id);
709 709
 		} else {
710
-			$query  = "SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
710
+			$query = "SELECT marine_live.ident, marine_live.fammarine_id FROM marine_live 
711 711
 				WHERE marine_live.fammarine_id = :id 
712 712
 				AND marine_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '10 HOUR'";
713 713
 //				AND marine_live.date < now() AT TIME ZONE 'UTC'";
@@ -716,8 +716,8 @@  discard block
 block discarded – undo
716 716
 		
717 717
 		$sth = $this->db->prepare($query);
718 718
 		$sth->execute($query_data);
719
-		$ident_result='';
720
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
719
+		$ident_result = '';
720
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
721 721
 		{
722 722
 			$ident_result = $row['fammarine_id'];
723 723
 		}
@@ -734,13 +734,13 @@  discard block
 block discarded – undo
734 734
 	{
735 735
 		global $globalDBdriver, $globalTimezone;
736 736
 		if ($globalDBdriver == 'mysql') {
737
-			$query  = 'SELECT marine_live.fammarine_id FROM marine_live 
737
+			$query = 'SELECT marine_live.fammarine_id FROM marine_live 
738 738
 				WHERE marine_live.mmsi = :mmsi 
739 739
 				AND marine_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 10 HOUR)'; 
740 740
 //				AND marine_live.date < UTC_TIMESTAMP()";
741 741
 			$query_data = array(':mmsi' => $mmsi);
742 742
 		} else {
743
-			$query  = "SELECT marine_live.fammarine_id FROM marine_live 
743
+			$query = "SELECT marine_live.fammarine_id FROM marine_live 
744 744
 				WHERE marine_live.mmsi = :mmsi 
745 745
 				AND marine_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '10 HOUR'";
746 746
 //				AND marine_live.date < now() AT TIME ZONE 'UTC'";
@@ -749,8 +749,8 @@  discard block
 block discarded – undo
749 749
 		
750 750
 		$sth = $this->db->prepare($query);
751 751
 		$sth->execute($query_data);
752
-		$ident_result='';
753
-		while($row = $sth->fetch(PDO::FETCH_ASSOC))
752
+		$ident_result = '';
753
+		while ($row = $sth->fetch(PDO::FETCH_ASSOC))
754 754
 		{
755 755
 			$ident_result = $row['fammarine_id'];
756 756
 		}
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
 	* @return String success or false
769 769
 	*
770 770
 	*/
771
-	public function addLiveMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $putinarchive = false, $mmsi = '',$type = '',$imo = '', $callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$noarchive = false,$format_source = '', $source_name = '', $over_country = '')
771
+	public function addLiveMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $putinarchive = false, $mmsi = '', $type = '', $imo = '', $callsign = '', $arrival_code = '', $arrival_date = '', $status = '', $noarchive = false, $format_source = '', $source_name = '', $over_country = '')
772 772
 	{
773 773
 		global $globalURL, $globalArchive, $globalDebug;
774 774
 		$Common = new Common();
@@ -820,36 +820,36 @@  discard block
 block discarded – undo
820 820
 		if ($date == '') $date = date("Y-m-d H:i:s", time());
821 821
 
822 822
         
823
-		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
824
-		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
825
-		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
826
-		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
827
-		$heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT);
828
-		$groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
829
-		$format_source = filter_var($format_source,FILTER_SANITIZE_STRING);
830
-		$source_name = filter_var($source_name,FILTER_SANITIZE_STRING);
831
-		$over_country = filter_var($over_country,FILTER_SANITIZE_STRING);
832
-		$type = filter_var($type,FILTER_SANITIZE_STRING);
833
-		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
834
-		$status = filter_var($status,FILTER_SANITIZE_STRING);
835
-		$imo = filter_var($imo,FILTER_SANITIZE_STRING);
836
-		$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
837
-		$arrival_code = filter_var($arrival_code,FILTER_SANITIZE_STRING);
838
-		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING);
823
+		$fammarine_id = filter_var($fammarine_id, FILTER_SANITIZE_STRING);
824
+		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
825
+		$latitude = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
826
+		$longitude = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
827
+		$heading = filter_var($heading, FILTER_SANITIZE_NUMBER_INT);
828
+		$groundspeed = filter_var($groundspeed, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
829
+		$format_source = filter_var($format_source, FILTER_SANITIZE_STRING);
830
+		$source_name = filter_var($source_name, FILTER_SANITIZE_STRING);
831
+		$over_country = filter_var($over_country, FILTER_SANITIZE_STRING);
832
+		$type = filter_var($type, FILTER_SANITIZE_STRING);
833
+		$mmsi = filter_var($mmsi, FILTER_SANITIZE_NUMBER_INT);
834
+		$status = filter_var($status, FILTER_SANITIZE_STRING);
835
+		$imo = filter_var($imo, FILTER_SANITIZE_STRING);
836
+		$callsign = filter_var($callsign, FILTER_SANITIZE_STRING);
837
+		$arrival_code = filter_var($arrival_code, FILTER_SANITIZE_STRING);
838
+		$arrival_date = filter_var($arrival_date, FILTER_SANITIZE_STRING);
839 839
 		
840 840
 
841
-            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
842
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
841
+            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
842
+            	if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
843 843
             	if ($arrival_date == '') $arrival_date = NULL;
844
-		$query  = 'INSERT INTO marine_live (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, over_country, mmsi, type,status,imo,arrival_port_name,arrival_port_date) 
844
+		$query = 'INSERT INTO marine_live (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, over_country, mmsi, type,status,imo,arrival_port_name,arrival_port_date) 
845 845
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:groundspeed,:date,:format_source, :source_name, :over_country,:mmsi,:type,:status,:imo,:arrival_port_name,:arrival_port_date)';
846 846
 
847
-		$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident,':latitude' => $latitude,':longitude' => $longitude,':heading' => $heading,':groundspeed' => $groundspeed,':date' => $date, ':format_source' => $format_source, ':source_name' => $source_name, ':over_country' => $over_country,':mmsi' => $mmsi,':type' => $type,':status' => $status,':imo' => $imo,':arrival_port_name' => $arrival_code,':arrival_port_date' => $arrival_date);
847
+		$query_values = array(':fammarine_id' => $fammarine_id, ':ident' => $ident, ':latitude' => $latitude, ':longitude' => $longitude, ':heading' => $heading, ':groundspeed' => $groundspeed, ':date' => $date, ':format_source' => $format_source, ':source_name' => $source_name, ':over_country' => $over_country, ':mmsi' => $mmsi, ':type' => $type, ':status' => $status, ':imo' => $imo, ':arrival_port_name' => $arrival_code, ':arrival_port_date' => $arrival_date);
848 848
 		try {
849 849
 			
850 850
 			$sth = $this->db->prepare($query);
851 851
 			$sth->execute($query_values);
852
-                } catch(PDOException $e) {
852
+                } catch (PDOException $e) {
853 853
                 	return "error : ".$e->getMessage();
854 854
                 }
855 855
 		/*
@@ -866,7 +866,7 @@  discard block
 block discarded – undo
866 866
 
867 867
 	public function getOrderBy()
868 868
 	{
869
-		$orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY marine_live.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY marine_live.aircraft_icao DESC"),"manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY marine_live.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY marine_live.aircraft_manufacturer DESC"),"airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY marine_live.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY marine_live.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY marine_live.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY marine_live.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY marine_live.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY marine_live.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY marine_live.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY marine_live.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY marine_live.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY marine_live.date DESC"));
869
+		$orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY marine_live.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY marine_live.aircraft_icao DESC"), "manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY marine_live.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY marine_live.aircraft_manufacturer DESC"), "airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY marine_live.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY marine_live.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY marine_live.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY marine_live.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY marine_live.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY marine_live.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY marine_live.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY marine_live.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY marine_live.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY marine_live.date DESC"));
870 870
 		return $orderby;
871 871
 	}
872 872
 
Please login to merge, or discard this patch.
Braces   +59 added lines, -20 removed lines patch added patch discarded remove patch
@@ -29,7 +29,9 @@  discard block
 block discarded – undo
29 29
 		if (isset($filter[0]['source'])) {
30 30
 			$filters = array_merge($filters,$filter);
31 31
 		}
32
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
32
+		if (is_array($globalFilter)) {
33
+			$filter = array_merge($filter,$globalFilter);
34
+		}
33 35
 		$filter_query_join = '';
34 36
 		$filter_query_where = '';
35 37
 		foreach($filters as $flt) {
@@ -76,8 +78,11 @@  discard block
 block discarded – undo
76 78
 		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
77 79
 			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
78 80
 		}
79
-		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
80
-		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
81
+		if ($filter_query_where == '' && $where) {
82
+			$filter_query_where = ' WHERE';
83
+		} elseif ($filter_query_where != '' && $and) {
84
+			$filter_query_where .= ' AND';
85
+		}
81 86
 		if ($filter_query_where != '') {
82 87
 			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
83 88
 		}
@@ -119,7 +124,9 @@  discard block
 block discarded – undo
119 124
 			}
120 125
 		}
121 126
 
122
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
127
+		if (!isset($globalLiveInterval)) {
128
+			$globalLiveInterval = '200';
129
+		}
123 130
 		if ($globalDBdriver == 'mysql') {
124 131
 			//$query  = "SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate";
125 132
 			$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate'.$filter_query.$orderby_query;
@@ -144,7 +151,9 @@  discard block
 block discarded – undo
144 151
 
145 152
 		$filter_query = $this->getFilter($filter,true,true);
146 153
 
147
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
154
+		if (!isset($globalLiveInterval)) {
155
+			$globalLiveInterval = '200';
156
+		}
148 157
 		if ($globalDBdriver == 'mysql') {
149 158
 			$query  = 'SELECT marine_live.mmsi, marine_live.ident, marine_live.type,marine_live.fammarine_id, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
150 159
 			FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate'.$filter_query." marine_live.latitude <> 0 AND marine_live.longitude <> 0";
@@ -178,7 +187,9 @@  discard block
 block discarded – undo
178 187
 
179 188
 		$filter_query = $this->getFilter($filter,true,true);
180 189
 
181
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
190
+		if (!isset($globalLiveInterval)) {
191
+			$globalLiveInterval = '200';
192
+		}
182 193
 		if ($globalDBdriver == 'mysql') {
183 194
 			$query  = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
184 195
 			FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= marine_live.date AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
@@ -211,7 +222,9 @@  discard block
 block discarded – undo
211 222
 		global $globalDBdriver, $globalLiveInterval;
212 223
 		$filter_query = $this->getFilter($filter,true,true);
213 224
 
214
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
225
+		if (!isset($globalLiveInterval)) {
226
+			$globalLiveInterval = '200';
227
+		}
215 228
 		if ($globalDBdriver == 'mysql') {
216 229
 			$query = 'SELECT COUNT(DISTINCT marine_live.fammarine_id) as nb FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
217 230
 		} else {
@@ -239,7 +252,9 @@  discard block
 block discarded – undo
239 252
 	{
240 253
 		global $globalDBdriver, $globalLiveInterval;
241 254
 		$Spotter = new Spotter($this->db);
242
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
255
+		if (!isset($globalLiveInterval)) {
256
+			$globalLiveInterval = '200';
257
+		}
243 258
 		$filter_query = $this->getFilter($filter);
244 259
 
245 260
 		if (is_array($coord)) {
@@ -247,7 +262,9 @@  discard block
 block discarded – undo
247 262
 			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
248 263
 			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
249 264
 			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
250
-		} else return array();
265
+		} else {
266
+			return array();
267
+		}
251 268
 		if ($globalDBdriver == 'mysql') {
252 269
 			$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND marine_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND marine_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.' GROUP BY marine_live.fammarine_id'.$filter_query;
253 270
 		} else {
@@ -411,11 +428,15 @@  discard block
 block discarded – undo
411 428
 		//$query  = self::$global_query.' WHERE marine_live.fammarine_id = :id ORDER BY date';
412 429
 		if ($globalDBdriver == 'mysql') {
413 430
 			$query = 'SELECT marine_live.* FROM marine_live WHERE marine_live.fammarine_id = :id';
414
-			if ($liveinterval) $query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
431
+			if ($liveinterval) {
432
+				$query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
433
+			}
415 434
 			$query .= ' ORDER BY date';
416 435
 		} else {
417 436
 			$query = 'SELECT marine_live.* FROM marine_live WHERE marine_live.fammarine_id = :id';
418
-			if ($liveinterval) $query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
437
+			if ($liveinterval) {
438
+				$query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
439
+			}
419 440
 			$query .= ' ORDER BY date';
420 441
 		}
421 442
 
@@ -510,7 +531,9 @@  discard block
 block discarded – undo
510 531
 				$i++;
511 532
 				$j++;
512 533
 				if ($j == 30) {
513
-					if ($globalDebug) echo ".";
534
+					if ($globalDebug) {
535
+						echo ".";
536
+					}
514 537
 				    	try {
515 538
 						
516 539
 						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
@@ -790,7 +813,9 @@  discard block
 block discarded – undo
790 813
 			{
791 814
 				return false;
792 815
 			}
793
-		} else return '';
816
+		} else {
817
+			return '';
818
+		}
794 819
 
795 820
 		if ($longitude != '')
796 821
 		{
@@ -798,7 +823,9 @@  discard block
 block discarded – undo
798 823
 			{
799 824
 				return false;
800 825
 			}
801
-		} else return '';
826
+		} else {
827
+			return '';
828
+		}
802 829
 
803 830
 
804 831
 		if ($heading != '')
@@ -807,7 +834,9 @@  discard block
 block discarded – undo
807 834
 			{
808 835
 				return false;
809 836
 			}
810
-		} else $heading = 0;
837
+		} else {
838
+			$heading = 0;
839
+		}
811 840
 
812 841
 		if ($groundspeed != '')
813 842
 		{
@@ -815,9 +844,13 @@  discard block
 block discarded – undo
815 844
 			{
816 845
 				return false;
817 846
 			}
818
-		} else $groundspeed = 0;
847
+		} else {
848
+			$groundspeed = 0;
849
+		}
819 850
 		date_default_timezone_set('UTC');
820
-		if ($date == '') $date = date("Y-m-d H:i:s", time());
851
+		if ($date == '') {
852
+			$date = date("Y-m-d H:i:s", time());
853
+		}
821 854
 
822 855
         
823 856
 		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
@@ -838,9 +871,15 @@  discard block
 block discarded – undo
838 871
 		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING);
839 872
 		
840 873
 
841
-            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
842
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
843
-            	if ($arrival_date == '') $arrival_date = NULL;
874
+            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) {
875
+            		$groundspeed = 0;
876
+            	}
877
+            	if ($heading == '' || $Common->isInteger($heading) === false ) {
878
+            		$heading = 0;
879
+            	}
880
+            	if ($arrival_date == '') {
881
+            		$arrival_date = NULL;
882
+            	}
844 883
 		$query  = 'INSERT INTO marine_live (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, over_country, mmsi, type,status,imo,arrival_port_name,arrival_port_date) 
845 884
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:groundspeed,:date,:format_source, :source_name, :over_country,:mmsi,:type,:status,:imo,:arrival_port_name,:arrival_port_date)';
846 885
 
Please login to merge, or discard this patch.
install/class.update_schema.php 2 patches
Spacing   +168 added lines, -168 removed lines patch added patch discarded remove patch
@@ -14,11 +14,11 @@  discard block
 block discarded – undo
14 14
             try {
15 15
             	$sth = $Connection->db->prepare($query);
16 16
 		$sth->execute();
17
-    	    } catch(PDOException $e) {
17
+    	    } catch (PDOException $e) {
18 18
 		return "error : ".$e->getMessage()."\n";
19 19
     	    }
20 20
     	    while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
21
-    		$Schedule->addSchedule($row['ident'],$row['departure_airport_icao'],$row['departure_airport_time'],$row['arrival_airport_icao'],$row['arrival_airport_time']);
21
+    		$Schedule->addSchedule($row['ident'], $row['departure_airport_icao'], $row['departure_airport_time'], $row['arrival_airport_icao'], $row['arrival_airport_time']);
22 22
     	    }
23 23
 	
24 24
 	}
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
         	try {
51 51
             	    $sth = $Connection->db->prepare($query);
52 52
 		    $sth->execute();
53
-    		} catch(PDOException $e) {
53
+    		} catch (PDOException $e) {
54 54
 		    return "error (add new columns to routes table) : ".$e->getMessage()."\n";
55 55
     		}
56 56
     		// Copy schedules data to routes table
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
         	try {
61 61
             	    $sth = $Connection->db->prepare($query);
62 62
 		    $sth->execute();
63
-    		} catch(PDOException $e) {
63
+    		} catch (PDOException $e) {
64 64
 		    return "error (delete schedule table) : ".$e->getMessage()."\n";
65 65
     		}
66 66
     		// Add source column
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     		try {
69 69
             	    $sth = $Connection->db->prepare($query);
70 70
 		    $sth->execute();
71
-    		} catch(PDOException $e) {
71
+    		} catch (PDOException $e) {
72 72
 		    return "error (add source column to aircraft_modes) : ".$e->getMessage()."\n";
73 73
     		}
74 74
 		// Delete unused column
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
     		try {
77 77
             	    $sth = $Connection->db->prepare($query);
78 78
 		    $sth->execute();
79
-    		} catch(PDOException $e) {
79
+    		} catch (PDOException $e) {
80 80
 		    return "error (Delete unused column of aircraft_modes) : ".$e->getMessage()."\n";
81 81
     		}
82 82
 		// Add ModeS column
@@ -84,14 +84,14 @@  discard block
 block discarded – undo
84 84
     		try {
85 85
             	    $sth = $Connection->db->prepare($query);
86 86
 		    $sth->execute();
87
-    		} catch(PDOException $e) {
87
+    		} catch (PDOException $e) {
88 88
 		    return "error (Add ModeS column in spotter_output) : ".$e->getMessage()."\n";
89 89
     		}
90 90
 		$query = "ALTER TABLE `spotter_live`  ADD `ModeS` VARCHAR(255)";
91 91
     		try {
92 92
             	    $sth = $Connection->db->prepare($query);
93 93
 		    $sth->execute();
94
-    		} catch(PDOException $e) {
94
+    		} catch (PDOException $e) {
95 95
 		    return "error (Add ModeS column in spotter_live) : ".$e->getMessage()."\n";
96 96
     		}
97 97
     		// Add auto_increment for aircraft_modes
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
     		try {
100 100
             	    $sth = $Connection->db->prepare($query);
101 101
 		    $sth->execute();
102
-    		} catch(PDOException $e) {
102
+    		} catch (PDOException $e) {
103 103
 		    return "error (Add Auto increment in aircraft_modes) : ".$e->getMessage()."\n";
104 104
     		}
105 105
     		$error = '';
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
         	try {
111 111
             	    $sth = $Connection->db->prepare($query);
112 112
 		    $sth->execute();
113
-    		} catch(PDOException $e) {
113
+    		} catch (PDOException $e) {
114 114
 		    return "error (update schema_version) : ".$e->getMessage()."\n";
115 115
     		}
116 116
 		return $error;
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
         	try {
124 124
             	    $sth = $Connection->db->prepare($query);
125 125
 		    $sth->execute();
126
-    		} catch(PDOException $e) {
126
+    		} catch (PDOException $e) {
127 127
 		    return "error (add new columns to routes table) : ".$e->getMessage()."\n";
128 128
     		}
129 129
     		$error = '';
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
         	try {
135 135
             	    $sth = $Connection->db->prepare($query);
136 136
 		    $sth->execute();
137
-    		} catch(PDOException $e) {
137
+    		} catch (PDOException $e) {
138 138
 		    return "error (update schema_version) : ".$e->getMessage()."\n";
139 139
     		}
140 140
 		return $error;
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
         	try {
148 148
             	    $sth = $Connection->db->prepare($query);
149 149
 		    $sth->execute();
150
-    		} catch(PDOException $e) {
150
+    		} catch (PDOException $e) {
151 151
 		    return "error (add new columns to aircraft_modes) : ".$e->getMessage()."\n";
152 152
     		}
153 153
     		// Add image_source_website column to spotter_image
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
         	try {
156 156
             	    $sth = $Connection->db->prepare($query);
157 157
 		    $sth->execute();
158
-    		} catch(PDOException $e) {
158
+    		} catch (PDOException $e) {
159 159
 		    return "error (add new columns to spotter_image) : ".$e->getMessage()."\n";
160 160
     		}
161 161
     		$error = '';
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
         	try {
165 165
             	    $sth = $Connection->db->prepare($query);
166 166
 		    $sth->execute();
167
-    		} catch(PDOException $e) {
167
+    		} catch (PDOException $e) {
168 168
 		    return "error (update schema_version) : ".$e->getMessage()."\n";
169 169
     		}
170 170
 		return $error;
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
         	    try {
183 183
             		$sth = $Connection->db->prepare($query);
184 184
 			$sth->execute();
185
-    		    } catch(PDOException $e) {
185
+    		    } catch (PDOException $e) {
186 186
 			return "error (update schema_version) : ".$e->getMessage()."\n";
187 187
     		    }
188 188
     		}
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
         	try {
197 197
             	    $sth = $Connection->db->prepare($query);
198 198
 		    $sth->execute();
199
-    		} catch(PDOException $e) {
199
+    		} catch (PDOException $e) {
200 200
 		    return "error (add new columns to translation) : ".$e->getMessage()."\n";
201 201
     		}
202 202
     		// Add aircraft_shadow column to aircraft
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
         	try {
205 205
             	    $sth = $Connection->db->prepare($query);
206 206
 		    $sth->execute();
207
-    		} catch(PDOException $e) {
207
+    		} catch (PDOException $e) {
208 208
 		    return "error (add new column to aircraft) : ".$e->getMessage()."\n";
209 209
     		}
210 210
     		// Add aircraft_shadow column to spotter_live
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
         	try {
213 213
             	    $sth = $Connection->db->prepare($query);
214 214
 		    $sth->execute();
215
-    		} catch(PDOException $e) {
215
+    		} catch (PDOException $e) {
216 216
 		    return "error (add new column to spotter_live) : ".$e->getMessage()."\n";
217 217
     		}
218 218
     		$error = '';
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
         	try {
226 226
             	    $sth = $Connection->db->prepare($query);
227 227
 		    $sth->execute();
228
-    		} catch(PDOException $e) {
228
+    		} catch (PDOException $e) {
229 229
 		    return "error (update schema_version) : ".$e->getMessage()."\n";
230 230
     		}
231 231
 		return $error;
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 
234 234
 	private static function update_from_6() {
235 235
     		$Connection = new Connection();
236
-    		if (!$Connection->indexExists('spotter_output','flightaware_id')) {
236
+    		if (!$Connection->indexExists('spotter_output', 'flightaware_id')) {
237 237
     		    $query = "ALTER TABLE spotter_output ADD INDEX(flightaware_id);
238 238
 			ALTER TABLE spotter_output ADD INDEX(date);
239 239
 			ALTER TABLE spotter_output ADD INDEX(ident);
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
         	    try {
251 251
             		$sth = $Connection->db->prepare($query);
252 252
 			$sth->execute();
253
-    		    } catch(PDOException $e) {
253
+    		    } catch (PDOException $e) {
254 254
 			return "error (add some indexes) : ".$e->getMessage()."\n";
255 255
     		    }
256 256
     		}
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
         	try {
266 266
             	    $sth = $Connection->db->prepare($query);
267 267
 		    $sth->execute();
268
-    		} catch(PDOException $e) {
268
+    		} catch (PDOException $e) {
269 269
 		    return "error (update schema_version) : ".$e->getMessage()."\n";
270 270
     		}
271 271
 		return $error;
@@ -274,12 +274,12 @@  discard block
 block discarded – undo
274 274
 	private static function update_from_7() {
275 275
 		global $globalDBname, $globalDBdriver;
276 276
     		$Connection = new Connection();
277
-    		$query="ALTER TABLE spotter_live ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL;
277
+    		$query = "ALTER TABLE spotter_live ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL;
278 278
     			ALTER TABLE spotter_output ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL;";
279 279
         	try {
280 280
             	    $sth = $Connection->db->prepare($query);
281 281
 		    $sth->execute();
282
-    		} catch(PDOException $e) {
282
+    		} catch (PDOException $e) {
283 283
 		    return "error (add pilot column to spotter_live and spotter_output) : ".$e->getMessage()."\n";
284 284
     		}
285 285
     		if ($globalDBdriver == 'mysql') {
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
 		    try {
288 288
             		$sth = $Connection->db->prepare($query);
289 289
 			$sth->execute();
290
-    		    } catch(PDOException $e) {
290
+    		    } catch (PDOException $e) {
291 291
 			return "error (problem when select engine for spotter_engine) : ".$e->getMessage()."\n";
292 292
     		    }
293 293
     		    $row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -299,15 +299,15 @@  discard block
 block discarded – undo
299 299
 				DROP TABLE spotter_archive;
300 300
 				RENAME TABLE copy TO spotter_archive;";
301 301
             	    } else {
302
-    			$query="ALTER TABLE spotter_archive ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL";
302
+    			$query = "ALTER TABLE spotter_archive ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL";
303 303
             	    }
304 304
                 } else {
305
-    		    $query="ALTER TABLE spotter_archive ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL";
305
+    		    $query = "ALTER TABLE spotter_archive ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL";
306 306
                 }
307 307
         	try {
308 308
             	    $sth = $Connection->db->prepare($query);
309 309
 		    $sth->execute();
310
-    		} catch(PDOException $e) {
310
+    		} catch (PDOException $e) {
311 311
 		    return "error (add pilot column to spotter_archive) : ".$e->getMessage()."\n";
312 312
     		}
313 313
 
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
         	try {
321 321
             	    $sth = $Connection->db->prepare($query);
322 322
 		    $sth->execute();
323
-    		} catch(PDOException $e) {
323
+    		} catch (PDOException $e) {
324 324
 		    return "error (update schema_version) : ".$e->getMessage()."\n";
325 325
     		}
326 326
 		return $error;
@@ -339,14 +339,14 @@  discard block
 block discarded – undo
339 339
         	try {
340 340
             	    $sth = $Connection->db->prepare($query);
341 341
 		    $sth->execute();
342
-    		} catch(PDOException $e) {
342
+    		} catch (PDOException $e) {
343 343
 		    return "error (insert last_update values) : ".$e->getMessage()."\n";
344 344
     		}
345 345
 		$query = "UPDATE `config` SET `value` = '9' WHERE `name` = 'schema_version'";
346 346
         	try {
347 347
             	    $sth = $Connection->db->prepare($query);
348 348
 		    $sth->execute();
349
-    		} catch(PDOException $e) {
349
+    		} catch (PDOException $e) {
350 350
 		    return "error (update schema_version) : ".$e->getMessage()."\n";
351 351
     		}
352 352
 		return $error;
@@ -354,12 +354,12 @@  discard block
 block discarded – undo
354 354
 
355 355
 	private static function update_from_9() {
356 356
     		$Connection = new Connection();
357
-    		$query="ALTER TABLE spotter_live ADD verticalrate INT(11) NULL;
357
+    		$query = "ALTER TABLE spotter_live ADD verticalrate INT(11) NULL;
358 358
     			ALTER TABLE spotter_output ADD verticalrate INT(11) NULL;";
359 359
         	try {
360 360
             	    $sth = $Connection->db->prepare($query);
361 361
 		    $sth->execute();
362
-    		} catch(PDOException $e) {
362
+    		} catch (PDOException $e) {
363 363
 		    return "error (add verticalrate column to spotter_live and spotter_output) : ".$e->getMessage()."\n";
364 364
     		}
365 365
 		$error = '';
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
         	try {
372 372
             	    $sth = $Connection->db->prepare($query);
373 373
 		    $sth->execute();
374
-    		} catch(PDOException $e) {
374
+    		} catch (PDOException $e) {
375 375
 		    return "error (update schema_version) : ".$e->getMessage()."\n";
376 376
     		}
377 377
 		return $error;
@@ -379,11 +379,11 @@  discard block
 block discarded – undo
379 379
 
380 380
 	private static function update_from_10() {
381 381
     		$Connection = new Connection();
382
-    		$query="ALTER TABLE atc CHANGE `type` `type` ENUM('Observer','Flight Information','Delivery','Tower','Approach','ACC','Departure','Ground','Flight Service Station','Control Radar or Centre') CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL";
382
+    		$query = "ALTER TABLE atc CHANGE `type` `type` ENUM('Observer','Flight Information','Delivery','Tower','Approach','ACC','Departure','Ground','Flight Service Station','Control Radar or Centre') CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL";
383 383
         	try {
384 384
             	    $sth = $Connection->db->prepare($query);
385 385
 		    $sth->execute();
386
-    		} catch(PDOException $e) {
386
+    		} catch (PDOException $e) {
387 387
 		    return "error (add new enum to ATC table) : ".$e->getMessage()."\n";
388 388
     		}
389 389
 		$error = '';
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
         	try {
402 402
             	    $sth = $Connection->db->prepare($query);
403 403
 		    $sth->execute();
404
-    		} catch(PDOException $e) {
404
+    		} catch (PDOException $e) {
405 405
 		    return "error (update schema_version) : ".$e->getMessage()."\n";
406 406
     		}
407 407
 		return $error;
@@ -410,18 +410,18 @@  discard block
 block discarded – undo
410 410
 	private static function update_from_11() {
411 411
 		global $globalDBdriver, $globalDBname;
412 412
     		$Connection = new Connection();
413
-    		$query="ALTER TABLE spotter_output ADD owner_name VARCHAR(255) NULL DEFAULT NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE, ADD last_ground BOOLEAN NOT NULL DEFAULT FALSE, ADD last_seen DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, ADD last_latitude FLOAT NULL, ADD last_longitude FLOAT NULL, ADD last_altitude INT(11) NULL, ADD last_ground_speed INT(11), ADD real_arrival_airport_icao VARCHAR(999), ADD real_arrival_airport_time VARCHAR(20),ADD real_departure_airport_icao VARCHAR(999), ADD real_departure_airport_time VARCHAR(20)";
413
+    		$query = "ALTER TABLE spotter_output ADD owner_name VARCHAR(255) NULL DEFAULT NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE, ADD last_ground BOOLEAN NOT NULL DEFAULT FALSE, ADD last_seen DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, ADD last_latitude FLOAT NULL, ADD last_longitude FLOAT NULL, ADD last_altitude INT(11) NULL, ADD last_ground_speed INT(11), ADD real_arrival_airport_icao VARCHAR(999), ADD real_arrival_airport_time VARCHAR(20),ADD real_departure_airport_icao VARCHAR(999), ADD real_departure_airport_time VARCHAR(20)";
414 414
         	try {
415 415
             	    $sth = $Connection->db->prepare($query);
416 416
 		    $sth->execute();
417
-    		} catch(PDOException $e) {
417
+    		} catch (PDOException $e) {
418 418
 		    return "error (add owner_name & format_source column to spotter_output) : ".$e->getMessage()."\n";
419 419
     		}
420
-    		$query="ALTER TABLE spotter_live ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE";
420
+    		$query = "ALTER TABLE spotter_live ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE";
421 421
         	try {
422 422
             	    $sth = $Connection->db->prepare($query);
423 423
 		    $sth->execute();
424
-    		} catch(PDOException $e) {
424
+    		} catch (PDOException $e) {
425 425
 		    return "error (format_source column to spotter_live) : ".$e->getMessage()."\n";
426 426
     		}
427 427
     		if ($globalDBdriver == 'mysql') {
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
 		    try {
430 430
             		$sth = $Connection->db->prepare($query);
431 431
 			$sth->execute();
432
-    		    } catch(PDOException $e) {
432
+    		    } catch (PDOException $e) {
433 433
 			return "error (problem when select engine for spotter_engine) : ".$e->getMessage()."\n";
434 434
     		    }
435 435
     		    $row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -441,15 +441,15 @@  discard block
 block discarded – undo
441 441
 				DROP TABLE spotter_archive;
442 442
 				RENAME TABLE copy TO spotter_archive;";
443 443
             	    } else {
444
-    			$query="ALTER TABLE spotter_archive ADD verticalrate INT(11) NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE";
444
+    			$query = "ALTER TABLE spotter_archive ADD verticalrate INT(11) NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE";
445 445
             	    }
446 446
                 } else {
447
-    		    $query="ALTER TABLE spotter_archive ADD verticalrate INT(11) NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE";
447
+    		    $query = "ALTER TABLE spotter_archive ADD verticalrate INT(11) NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE";
448 448
                 }
449 449
         	try {
450 450
             	    $sth = $Connection->db->prepare($query);
451 451
 		    $sth->execute();
452
-    		} catch(PDOException $e) {
452
+    		} catch (PDOException $e) {
453 453
 		    return "error (add columns to spotter_archive) : ".$e->getMessage()."\n";
454 454
     		}
455 455
 
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
         	try {
460 460
             	    $sth = $Connection->db->prepare($query);
461 461
 		    $sth->execute();
462
-    		} catch(PDOException $e) {
462
+    		} catch (PDOException $e) {
463 463
 		    return "error (update schema_version) : ".$e->getMessage()."\n";
464 464
     		}
465 465
 		return $error;
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
         	try {
488 488
             	    $sth = $Connection->db->prepare($query);
489 489
 		    $sth->execute();
490
-    		} catch(PDOException $e) {
490
+    		} catch (PDOException $e) {
491 491
 		    return "error (update schema_version) : ".$e->getMessage()."\n";
492 492
     		}
493 493
 		return $error;
@@ -495,12 +495,12 @@  discard block
 block discarded – undo
495 495
 
496 496
 	private static function update_from_13() {
497 497
     		$Connection = new Connection();
498
-    		if (!$Connection->checkColumnName('spotter_archive_output','real_departure_airport_icao')) {
499
-    			$query="ALTER TABLE spotter_archive_output ADD real_departure_airport_icao VARCHAR(20), ADD real_departure_airport_time VARCHAR(20)";
498
+    		if (!$Connection->checkColumnName('spotter_archive_output', 'real_departure_airport_icao')) {
499
+    			$query = "ALTER TABLE spotter_archive_output ADD real_departure_airport_icao VARCHAR(20), ADD real_departure_airport_time VARCHAR(20)";
500 500
 			try {
501 501
 				$sth = $Connection->db->prepare($query);
502 502
 				$sth->execute();
503
-	    		} catch(PDOException $e) {
503
+	    		} catch (PDOException $e) {
504 504
 				return "error (update spotter_archive_output) : ".$e->getMessage()."\n";
505 505
     			}
506 506
 		}
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
         	try {
510 510
             	    $sth = $Connection->db->prepare($query);
511 511
 		    $sth->execute();
512
-    		} catch(PDOException $e) {
512
+    		} catch (PDOException $e) {
513 513
 		    return "error (update schema_version) : ".$e->getMessage()."\n";
514 514
     		}
515 515
 		return $error;
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
         	try {
528 528
             	    $sth = $Connection->db->prepare($query);
529 529
 		    $sth->execute();
530
-    		} catch(PDOException $e) {
530
+    		} catch (PDOException $e) {
531 531
 		    return "error (update schema_version) : ".$e->getMessage()."\n";
532 532
     		}
533 533
 		return $error;
@@ -538,11 +538,11 @@  discard block
 block discarded – undo
538 538
     		$Connection = new Connection();
539 539
 		$error = '';
540 540
     		// Add tables
541
-    		$query="ALTER TABLE `stats` CHANGE `stats_date` `stats_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP";
541
+    		$query = "ALTER TABLE `stats` CHANGE `stats_date` `stats_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP";
542 542
         	try {
543 543
             	    $sth = $Connection->db->prepare($query);
544 544
 		    $sth->execute();
545
-    		} catch(PDOException $e) {
545
+    		} catch (PDOException $e) {
546 546
 		    return "error (update stats) : ".$e->getMessage()."\n";
547 547
     		}
548 548
 		if ($error != '') return $error;
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
         	try {
551 551
             	    $sth = $Connection->db->prepare($query);
552 552
 		    $sth->execute();
553
-    		} catch(PDOException $e) {
553
+    		} catch (PDOException $e) {
554 554
 		    return "error (update schema_version) : ".$e->getMessage()."\n";
555 555
     		}
556 556
 		return $error;
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
         	try {
572 572
             	    $sth = $Connection->db->prepare($query);
573 573
 		    $sth->execute();
574
-    		} catch(PDOException $e) {
574
+    		} catch (PDOException $e) {
575 575
 		    return "error (update schema_version) : ".$e->getMessage()."\n";
576 576
     		}
577 577
 		return $error;
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
         	try {
590 590
             	    $sth = $Connection->db->prepare($query);
591 591
 		    $sth->execute();
592
-    		} catch(PDOException $e) {
592
+    		} catch (PDOException $e) {
593 593
 		    return "error (update schema_version) : ".$e->getMessage()."\n";
594 594
     		}
595 595
 		return $error;
@@ -598,12 +598,12 @@  discard block
 block discarded – undo
598 598
     		$Connection = new Connection();
599 599
 		$error = '';
600 600
     		// Modify stats_airport table
601
-    		if (!$Connection->checkColumnName('stats_airport','airport_name')) {
601
+    		if (!$Connection->checkColumnName('stats_airport', 'airport_name')) {
602 602
     			$query = "ALTER TABLE `stats_airport` ADD `stats_type` VARCHAR(50) NOT NULL DEFAULT 'yearly', ADD `airport_name` VARCHAR(255) NOT NULL, ADD `date` DATE NULL DEFAULT NULL, DROP INDEX `airport_icao`, ADD UNIQUE `airport_icao` (`airport_icao`, `type`, `date`)";
603 603
     	        	try {
604 604
 	            	    $sth = $Connection->db->prepare($query);
605 605
 			    $sth->execute();
606
-    			} catch(PDOException $e) {
606
+    			} catch (PDOException $e) {
607 607
 			    return "error (update stats) : ".$e->getMessage()."\n";
608 608
     			}
609 609
     		}
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
         	try {
613 613
             	    $sth = $Connection->db->prepare($query);
614 614
 		    $sth->execute();
615
-    		} catch(PDOException $e) {
615
+    		} catch (PDOException $e) {
616 616
 		    return "error (update schema_version) : ".$e->getMessage()."\n";
617 617
     		}
618 618
 		return $error;
@@ -629,73 +629,73 @@  discard block
 block discarded – undo
629 629
         	try {
630 630
             	    $sth = $Connection->db->prepare($query);
631 631
 		    $sth->execute();
632
-    		} catch(PDOException $e) {
632
+    		} catch (PDOException $e) {
633 633
 		    return "error (remove primary key on spotter_archive) : ".$e->getMessage()."\n";
634 634
     		}
635 635
 		$query = "alter table spotter_archive add spotter_archive_id INT(11)";
636 636
         	try {
637 637
             	    $sth = $Connection->db->prepare($query);
638 638
 		    $sth->execute();
639
-    		} catch(PDOException $e) {
639
+    		} catch (PDOException $e) {
640 640
 		    return "error (add id again on spotter_archive) : ".$e->getMessage()."\n";
641 641
     		}
642
-		if (!$Connection->checkColumnName('spotter_archive','over_country')) {
642
+		if (!$Connection->checkColumnName('spotter_archive', 'over_country')) {
643 643
 			// Add column over_country
644 644
     			$query = "ALTER TABLE `spotter_archive` ADD `over_country` VARCHAR(5) NULL DEFAULT NULL";
645 645
 			try {
646 646
             			$sth = $Connection->db->prepare($query);
647 647
 				$sth->execute();
648
-			} catch(PDOException $e) {
648
+			} catch (PDOException $e) {
649 649
 				return "error (add over_country) : ".$e->getMessage()."\n";
650 650
 			}
651 651
 		}
652
-		if (!$Connection->checkColumnName('spotter_live','over_country')) {
652
+		if (!$Connection->checkColumnName('spotter_live', 'over_country')) {
653 653
 			// Add column over_country
654 654
     			$query = "ALTER TABLE `spotter_live` ADD `over_country` VARCHAR(5) NULL DEFAULT NULL";
655 655
 			try {
656 656
             			$sth = $Connection->db->prepare($query);
657 657
 				$sth->execute();
658
-			} catch(PDOException $e) {
658
+			} catch (PDOException $e) {
659 659
 				return "error (add over_country) : ".$e->getMessage()."\n";
660 660
 			}
661 661
 		}
662
-		if (!$Connection->checkColumnName('spotter_output','source_name')) {
662
+		if (!$Connection->checkColumnName('spotter_output', 'source_name')) {
663 663
 			// Add source_name to spotter_output, spotter_live, spotter_archive, spotter_archive_output
664 664
     			$query = "ALTER TABLE `spotter_output` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`";
665 665
 			try {
666 666
 				$sth = $Connection->db->prepare($query);
667 667
 				$sth->execute();
668
-			} catch(PDOException $e) {
668
+			} catch (PDOException $e) {
669 669
 				return "error (add source_name column) : ".$e->getMessage()."\n";
670 670
     			}
671 671
     		}
672
-		if (!$Connection->checkColumnName('spotter_live','source_name')) {
672
+		if (!$Connection->checkColumnName('spotter_live', 'source_name')) {
673 673
 			// Add source_name to spotter_output, spotter_live, spotter_archive, spotter_archive_output
674 674
     			$query = "ALTER TABLE `spotter_live` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`";
675 675
 			try {
676 676
 				$sth = $Connection->db->prepare($query);
677 677
 				$sth->execute();
678
-			} catch(PDOException $e) {
678
+			} catch (PDOException $e) {
679 679
 				return "error (add source_name column) : ".$e->getMessage()."\n";
680 680
     			}
681 681
     		}
682
-		if (!$Connection->checkColumnName('spotter_archive_output','source_name')) {
682
+		if (!$Connection->checkColumnName('spotter_archive_output', 'source_name')) {
683 683
 			// Add source_name to spotter_output, spotter_live, spotter_archive, spotter_archive_output
684 684
     			$query = "ALTER TABLE `spotter_archive_output` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`";
685 685
 			try {
686 686
 				$sth = $Connection->db->prepare($query);
687 687
 				$sth->execute();
688
-			} catch(PDOException $e) {
688
+			} catch (PDOException $e) {
689 689
 				return "error (add source_name column) : ".$e->getMessage()."\n";
690 690
     			}
691 691
     		}
692
-		if (!$Connection->checkColumnName('spotter_archive','source_name')) {
692
+		if (!$Connection->checkColumnName('spotter_archive', 'source_name')) {
693 693
 			// Add source_name to spotter_output, spotter_live, spotter_archive, spotter_archive_output
694 694
     			$query = "ALTER TABLE `spotter_archive` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`;";
695 695
 			try {
696 696
 				$sth = $Connection->db->prepare($query);
697 697
 				$sth->execute();
698
-			} catch(PDOException $e) {
698
+			} catch (PDOException $e) {
699 699
 				return "error (add source_name column) : ".$e->getMessage()."\n";
700 700
     			}
701 701
     		}
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
         	try {
705 705
             	    $sth = $Connection->db->prepare($query);
706 706
 		    $sth->execute();
707
-    		} catch(PDOException $e) {
707
+    		} catch (PDOException $e) {
708 708
 		    return "error (update schema_version) : ".$e->getMessage()."\n";
709 709
     		}
710 710
 		return $error;
@@ -719,13 +719,13 @@  discard block
 block discarded – undo
719 719
 			$error .= create_db::import_file('../db/airlines.sql');
720 720
 			if ($error != '') return 'Import airlines.sql : '.$error;
721 721
 		}
722
-		if (!$Connection->checkColumnName('aircraft_modes','type_flight')) {
722
+		if (!$Connection->checkColumnName('aircraft_modes', 'type_flight')) {
723 723
 			// Add column over_country
724 724
     			$query = "ALTER TABLE `aircraft_modes` ADD `type_flight` VARCHAR(50) NULL DEFAULT NULL;";
725 725
         		try {
726 726
 				$sth = $Connection->db->prepare($query);
727 727
 				$sth->execute();
728
-			} catch(PDOException $e) {
728
+			} catch (PDOException $e) {
729 729
 				return "error (add over_country) : ".$e->getMessage()."\n";
730 730
     			}
731 731
     		}
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
         	try {
742 742
             	    $sth = $Connection->db->prepare($query);
743 743
 		    $sth->execute();
744
-    		} catch(PDOException $e) {
744
+    		} catch (PDOException $e) {
745 745
 		    return "error (update schema_version) : ".$e->getMessage()."\n";
746 746
     		}
747 747
 		return $error;
@@ -750,13 +750,13 @@  discard block
 block discarded – undo
750 750
 	private static function update_from_21() {
751 751
 		$Connection = new Connection();
752 752
 		$error = '';
753
-		if (!$Connection->checkColumnName('stats_airport','stats_type')) {
753
+		if (!$Connection->checkColumnName('stats_airport', 'stats_type')) {
754 754
 			// Rename type to stats_type
755 755
 			$query = "ALTER TABLE `stats_airport` CHANGE `type` `stats_type` VARCHAR(50);ALTER TABLE `stats` CHANGE `type` `stats_type` VARCHAR(50);ALTER TABLE `stats_flight` CHANGE `type` `stats_type` VARCHAR(50);";
756 756
 			try {
757 757
 				$sth = $Connection->db->prepare($query);
758 758
 				$sth->execute();
759
-			} catch(PDOException $e) {
759
+			} catch (PDOException $e) {
760 760
 				return "error (rename type to stats_type on stats*) : ".$e->getMessage()."\n";
761 761
 			}
762 762
 			if ($error != '') return $error;
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
         	try {
766 766
             	    $sth = $Connection->db->prepare($query);
767 767
 		    $sth->execute();
768
-    		} catch(PDOException $e) {
768
+    		} catch (PDOException $e) {
769 769
 		    return "error (update schema_version) : ".$e->getMessage()."\n";
770 770
     		}
771 771
 		return $error;
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
         	try {
789 789
             	    $sth = $Connection->db->prepare($query);
790 790
 		    $sth->execute();
791
-    		} catch(PDOException $e) {
791
+    		} catch (PDOException $e) {
792 792
 		    return "error (update schema_version) : ".$e->getMessage()."\n";
793 793
     		}
794 794
 		return $error;
@@ -815,17 +815,17 @@  discard block
 block discarded – undo
815 815
 			try {
816 816
 				$sth = $Connection->db->prepare($query);
817 817
 				$sth->execute();
818
-			} catch(PDOException $e) {
818
+			} catch (PDOException $e) {
819 819
 				return "error (create index on spotter_archive) : ".$e->getMessage()."\n";
820 820
 			}
821 821
 		}
822
-		if (!$Connection->checkColumnName('stats_aircraft','aircraft_manufacturer')) {
822
+		if (!$Connection->checkColumnName('stats_aircraft', 'aircraft_manufacturer')) {
823 823
 			// Add aircraft_manufacturer to stats_aircraft
824 824
     			$query = "ALTER TABLE stats_aircraft ADD aircraft_manufacturer VARCHAR(255) NULL";
825 825
 			try {
826 826
 				$sth = $Connection->db->prepare($query);
827 827
 				$sth->execute();
828
-			} catch(PDOException $e) {
828
+			} catch (PDOException $e) {
829 829
 				return "error (add aircraft_manufacturer column) : ".$e->getMessage()."\n";
830 830
     			}
831 831
     		}
@@ -834,7 +834,7 @@  discard block
 block discarded – undo
834 834
 		try {
835 835
 			$sth = $Connection->db->prepare($query);
836 836
 			$sth->execute();
837
-		} catch(PDOException $e) {
837
+		} catch (PDOException $e) {
838 838
 			return "error (update schema_version) : ".$e->getMessage()."\n";
839 839
 		}
840 840
 		return $error;
@@ -850,23 +850,23 @@  discard block
 block discarded – undo
850 850
 			$error .= create_db::import_file('../db/pgsql/airlines.sql');
851 851
 		}
852 852
 		if ($error != '') return 'Import airlines.sql : '.$error;
853
-		if (!$Connection->checkColumnName('airlines','forsource')) {
853
+		if (!$Connection->checkColumnName('airlines', 'forsource')) {
854 854
 			// Add forsource to airlines
855 855
 			$query = "ALTER TABLE airlines ADD forsource VARCHAR(255) NULL DEFAULT NULL";
856 856
 			try {
857 857
 				$sth = $Connection->db->prepare($query);
858 858
 				$sth->execute();
859
-			} catch(PDOException $e) {
859
+			} catch (PDOException $e) {
860 860
 				return "error (add forsource column) : ".$e->getMessage()."\n";
861 861
 			}
862 862
 		}
863
-		if (!$Connection->checkColumnName('stats_aircraft','stats_airline')) {
863
+		if (!$Connection->checkColumnName('stats_aircraft', 'stats_airline')) {
864 864
 			// Add forsource to airlines
865 865
 			$query = "ALTER TABLE stats_aircraft ADD stats_airline VARCHAR(255) NULL DEFAULT '', ADD filter_name VARCHAR(255) NULL DEFAULT ''";
866 866
 			try {
867 867
 				$sth = $Connection->db->prepare($query);
868 868
 				$sth->execute();
869
-			} catch(PDOException $e) {
869
+			} catch (PDOException $e) {
870 870
 				return "error (add stats_airline & filter_name column in stats_aircraft) : ".$e->getMessage()."\n";
871 871
 			}
872 872
 			// Add unique key
@@ -878,17 +878,17 @@  discard block
 block discarded – undo
878 878
 			try {
879 879
 				$sth = $Connection->db->prepare($query);
880 880
 				$sth->execute();
881
-			} catch(PDOException $e) {
881
+			} catch (PDOException $e) {
882 882
 				return "error (add unique key in stats_aircraft) : ".$e->getMessage()."\n";
883 883
 			}
884 884
 		}
885
-		if (!$Connection->checkColumnName('stats_airport','stats_airline')) {
885
+		if (!$Connection->checkColumnName('stats_airport', 'stats_airline')) {
886 886
 			// Add forsource to airlines
887 887
 			$query = "ALTER TABLE stats_airport ADD stats_airline VARCHAR(255) NULL DEFAULT '', ADD filter_name VARCHAR(255) NULL DEFAULT ''";
888 888
 			try {
889 889
 				$sth = $Connection->db->prepare($query);
890 890
 				$sth->execute();
891
-			} catch(PDOException $e) {
891
+			} catch (PDOException $e) {
892 892
 				return "error (add filter_name column in stats_airport) : ".$e->getMessage()."\n";
893 893
 			}
894 894
 			// Add unique key
@@ -900,17 +900,17 @@  discard block
 block discarded – undo
900 900
 			try {
901 901
 				$sth = $Connection->db->prepare($query);
902 902
 				$sth->execute();
903
-			} catch(PDOException $e) {
903
+			} catch (PDOException $e) {
904 904
 				return "error (add unique key in stats_airport) : ".$e->getMessage()."\n";
905 905
 			}
906 906
 		}
907
-		if (!$Connection->checkColumnName('stats_country','stats_airline')) {
907
+		if (!$Connection->checkColumnName('stats_country', 'stats_airline')) {
908 908
 			// Add forsource to airlines
909 909
 			$query = "ALTER TABLE stats_country ADD stats_airline VARCHAR(255) NULL DEFAULT '', ADD filter_name VARCHAR(255) NULL DEFAULT ''";
910 910
 			try {
911 911
 				$sth = $Connection->db->prepare($query);
912 912
 				$sth->execute();
913
-			} catch(PDOException $e) {
913
+			} catch (PDOException $e) {
914 914
 				return "error (add stats_airline & filter_name column in stats_country) : ".$e->getMessage()."\n";
915 915
 			}
916 916
 			// Add unique key
@@ -922,36 +922,36 @@  discard block
 block discarded – undo
922 922
 			try {
923 923
 				$sth = $Connection->db->prepare($query);
924 924
 				$sth->execute();
925
-			} catch(PDOException $e) {
925
+			} catch (PDOException $e) {
926 926
 				return "error (add unique key in stats_airline) : ".$e->getMessage()."\n";
927 927
 			}
928 928
 		}
929
-		if (!$Connection->checkColumnName('stats_flight','stats_airline')) {
929
+		if (!$Connection->checkColumnName('stats_flight', 'stats_airline')) {
930 930
 			// Add forsource to airlines
931 931
 			$query = "ALTER TABLE stats_flight ADD stats_airline VARCHAR(255) NULL DEFAULT '', ADD filter_name VARCHAR(255) NULL DEFAULT ''";
932 932
 			try {
933 933
 				$sth = $Connection->db->prepare($query);
934 934
 				$sth->execute();
935
-			} catch(PDOException $e) {
935
+			} catch (PDOException $e) {
936 936
 				return "error (add stats_airline & filter_name column in stats_flight) : ".$e->getMessage()."\n";
937 937
 			}
938 938
 		}
939
-		if (!$Connection->checkColumnName('stats','stats_airline')) {
939
+		if (!$Connection->checkColumnName('stats', 'stats_airline')) {
940 940
 			// Add forsource to airlines
941 941
 			$query = "ALTER TABLE stats ADD stats_airline VARCHAR(255) NULL DEFAULT '', ADD filter_name VARCHAR(255) NULL DEFAULT ''";
942 942
 			try {
943 943
 				$sth = $Connection->db->prepare($query);
944 944
 				$sth->execute();
945
-			} catch(PDOException $e) {
945
+			} catch (PDOException $e) {
946 946
 				return "error (add stats_airline & filter_name column in stats) : ".$e->getMessage()."\n";
947 947
 			}
948
-			if ($globalDBdriver == 'mysql' && $Connection->indexExists('stats','type')) {
948
+			if ($globalDBdriver == 'mysql' && $Connection->indexExists('stats', 'type')) {
949 949
 				// Add unique key
950 950
 				$query = "drop index type on stats;ALTER TABLE stats ADD UNIQUE stats_type (stats_type,stats_date,stats_airline,filter_name);";
951 951
 				try {
952 952
 					$sth = $Connection->db->prepare($query);
953 953
 					$sth->execute();
954
-				} catch(PDOException $e) {
954
+				} catch (PDOException $e) {
955 955
 					return "error (add unique key in stats) : ".$e->getMessage()."\n";
956 956
 				}
957 957
 			} else {
@@ -964,18 +964,18 @@  discard block
 block discarded – undo
964 964
 				try {
965 965
 					$sth = $Connection->db->prepare($query);
966 966
 					$sth->execute();
967
-				} catch(PDOException $e) {
967
+				} catch (PDOException $e) {
968 968
 					return "error (add unique key in stats) : ".$e->getMessage()."\n";
969 969
 				}
970 970
 			}
971 971
 		}
972
-		if (!$Connection->checkColumnName('stats_registration','stats_airline')) {
972
+		if (!$Connection->checkColumnName('stats_registration', 'stats_airline')) {
973 973
 			// Add forsource to airlines
974 974
 			$query = "ALTER TABLE stats_registration ADD stats_airline VARCHAR(255) NULL DEFAULT '', ADD filter_name VARCHAR(255) NULL DEFAULT ''";
975 975
 			try {
976 976
 				$sth = $Connection->db->prepare($query);
977 977
 				$sth->execute();
978
-			} catch(PDOException $e) {
978
+			} catch (PDOException $e) {
979 979
 				return "error (add stats_airline & filter_name column in stats_registration) : ".$e->getMessage()."\n";
980 980
 			}
981 981
 			// Add unique key
@@ -987,17 +987,17 @@  discard block
 block discarded – undo
987 987
 			try {
988 988
 				$sth = $Connection->db->prepare($query);
989 989
 				$sth->execute();
990
-			} catch(PDOException $e) {
990
+			} catch (PDOException $e) {
991 991
 				return "error (add unique key in stats_registration) : ".$e->getMessage()."\n";
992 992
 			}
993 993
 		}
994
-		if (!$Connection->checkColumnName('stats_callsign','filter_name')) {
994
+		if (!$Connection->checkColumnName('stats_callsign', 'filter_name')) {
995 995
 			// Add forsource to airlines
996 996
 			$query = "ALTER TABLE stats_callsign ADD filter_name VARCHAR(255) NULL DEFAULT ''";
997 997
 			try {
998 998
 				$sth = $Connection->db->prepare($query);
999 999
 				$sth->execute();
1000
-			} catch(PDOException $e) {
1000
+			} catch (PDOException $e) {
1001 1001
 				return "error (add filter_name column in stats_callsign) : ".$e->getMessage()."\n";
1002 1002
 			}
1003 1003
 			// Add unique key
@@ -1009,17 +1009,17 @@  discard block
 block discarded – undo
1009 1009
 			try {
1010 1010
 				$sth = $Connection->db->prepare($query);
1011 1011
 				$sth->execute();
1012
-			} catch(PDOException $e) {
1012
+			} catch (PDOException $e) {
1013 1013
 				return "error (add unique key in stats_callsign) : ".$e->getMessage()."\n";
1014 1014
 			}
1015 1015
 		}
1016
-		if (!$Connection->checkColumnName('stats_airline','filter_name')) {
1016
+		if (!$Connection->checkColumnName('stats_airline', 'filter_name')) {
1017 1017
 			// Add forsource to airlines
1018 1018
 			$query = "ALTER TABLE stats_airline ADD filter_name VARCHAR(255) NULL DEFAULT ''";
1019 1019
 			try {
1020 1020
 				$sth = $Connection->db->prepare($query);
1021 1021
 				$sth->execute();
1022
-			} catch(PDOException $e) {
1022
+			} catch (PDOException $e) {
1023 1023
 				return "error (add filter_name column in stats_airline) : ".$e->getMessage()."\n";
1024 1024
 			}
1025 1025
 			// Add unique key
@@ -1031,7 +1031,7 @@  discard block
 block discarded – undo
1031 1031
 			try {
1032 1032
 				$sth = $Connection->db->prepare($query);
1033 1033
 				$sth->execute();
1034
-			} catch(PDOException $e) {
1034
+			} catch (PDOException $e) {
1035 1035
 				return "error (add unique key in stats_callsign) : ".$e->getMessage()."\n";
1036 1036
 			}
1037 1037
 		}
@@ -1040,7 +1040,7 @@  discard block
 block discarded – undo
1040 1040
 		try {
1041 1041
 			$sth = $Connection->db->prepare($query);
1042 1042
 			$sth->execute();
1043
-		} catch(PDOException $e) {
1043
+		} catch (PDOException $e) {
1044 1044
 			return "error (update schema_version) : ".$e->getMessage()."\n";
1045 1045
 		}
1046 1046
 		return $error;
@@ -1050,13 +1050,13 @@  discard block
 block discarded – undo
1050 1050
 		global $globalDBdriver;
1051 1051
 		$Connection = new Connection();
1052 1052
 		$error = '';
1053
-		if (!$Connection->checkColumnName('stats_owner','stats_airline')) {
1053
+		if (!$Connection->checkColumnName('stats_owner', 'stats_airline')) {
1054 1054
 			// Add forsource to airlines
1055 1055
 			$query = "ALTER TABLE stats_owner ADD stats_airline VARCHAR(255) NULL DEFAULT '', ADD filter_name VARCHAR(255) NULL DEFAULT ''";
1056 1056
 			try {
1057 1057
 				$sth = $Connection->db->prepare($query);
1058 1058
 				$sth->execute();
1059
-			} catch(PDOException $e) {
1059
+			} catch (PDOException $e) {
1060 1060
 				return "error (add stats_airline & filter_name column in stats_owner) : ".$e->getMessage()."\n";
1061 1061
 			}
1062 1062
 			// Add unique key
@@ -1068,17 +1068,17 @@  discard block
 block discarded – undo
1068 1068
 			try {
1069 1069
 				$sth = $Connection->db->prepare($query);
1070 1070
 				$sth->execute();
1071
-			} catch(PDOException $e) {
1071
+			} catch (PDOException $e) {
1072 1072
 				return "error (add unique key in stats_owner) : ".$e->getMessage()."\n";
1073 1073
 			}
1074 1074
 		}
1075
-		if (!$Connection->checkColumnName('stats_pilot','stats_airline')) {
1075
+		if (!$Connection->checkColumnName('stats_pilot', 'stats_airline')) {
1076 1076
 			// Add forsource to airlines
1077 1077
 			$query = "ALTER TABLE stats_pilot ADD stats_airline VARCHAR(255) NULL DEFAULT '', ADD filter_name VARCHAR(255) NULL DEFAULT ''";
1078 1078
 			try {
1079 1079
 				$sth = $Connection->db->prepare($query);
1080 1080
 				$sth->execute();
1081
-			} catch(PDOException $e) {
1081
+			} catch (PDOException $e) {
1082 1082
 				return "error (add stats_airline & filter_name column in stats_pilot) : ".$e->getMessage()."\n";
1083 1083
 			}
1084 1084
 			// Add unique key
@@ -1090,7 +1090,7 @@  discard block
 block discarded – undo
1090 1090
 			try {
1091 1091
 				$sth = $Connection->db->prepare($query);
1092 1092
 				$sth->execute();
1093
-			} catch(PDOException $e) {
1093
+			} catch (PDOException $e) {
1094 1094
 				return "error (add unique key in stats_pilot) : ".$e->getMessage()."\n";
1095 1095
 			}
1096 1096
 		}
@@ -1098,7 +1098,7 @@  discard block
 block discarded – undo
1098 1098
 		try {
1099 1099
 			$sth = $Connection->db->prepare($query);
1100 1100
 			$sth->execute();
1101
-		} catch(PDOException $e) {
1101
+		} catch (PDOException $e) {
1102 1102
 			return "error (update schema_version) : ".$e->getMessage()."\n";
1103 1103
 		}
1104 1104
 		return $error;
@@ -1108,12 +1108,12 @@  discard block
 block discarded – undo
1108 1108
 		global $globalDBdriver;
1109 1109
 		$Connection = new Connection();
1110 1110
 		$error = '';
1111
-		if (!$Connection->checkColumnName('atc','format_source')) {
1111
+		if (!$Connection->checkColumnName('atc', 'format_source')) {
1112 1112
 			$query = "ALTER TABLE atc ADD format_source VARCHAR(255) DEFAULT NULL, ADD source_name VARCHAR(255) DEFAULT NULL";
1113 1113
 			try {
1114 1114
 				$sth = $Connection->db->prepare($query);
1115 1115
 				$sth->execute();
1116
-			} catch(PDOException $e) {
1116
+			} catch (PDOException $e) {
1117 1117
 				return "error (add format_source & source_name column in atc) : ".$e->getMessage()."\n";
1118 1118
 			}
1119 1119
 		}
@@ -1121,7 +1121,7 @@  discard block
 block discarded – undo
1121 1121
 		try {
1122 1122
 			$sth = $Connection->db->prepare($query);
1123 1123
 			$sth->execute();
1124
-		} catch(PDOException $e) {
1124
+		} catch (PDOException $e) {
1125 1125
 			return "error (update schema_version) : ".$e->getMessage()."\n";
1126 1126
 		}
1127 1127
 		return $error;
@@ -1131,13 +1131,13 @@  discard block
 block discarded – undo
1131 1131
 		global $globalDBdriver;
1132 1132
 		$Connection = new Connection();
1133 1133
 		$error = '';
1134
-		if (!$Connection->checkColumnName('stats_pilot','format_source')) {
1134
+		if (!$Connection->checkColumnName('stats_pilot', 'format_source')) {
1135 1135
 			// Add forsource to airlines
1136 1136
 			$query = "ALTER TABLE stats_pilot ADD format_source VARCHAR(255) NULL DEFAULT ''";
1137 1137
 			try {
1138 1138
 				$sth = $Connection->db->prepare($query);
1139 1139
 				$sth->execute();
1140
-			} catch(PDOException $e) {
1140
+			} catch (PDOException $e) {
1141 1141
 				return "error (add format_source column in stats_pilot) : ".$e->getMessage()."\n";
1142 1142
 			}
1143 1143
 			// Add unique key
@@ -1149,7 +1149,7 @@  discard block
 block discarded – undo
1149 1149
 			try {
1150 1150
 				$sth = $Connection->db->prepare($query);
1151 1151
 				$sth->execute();
1152
-			} catch(PDOException $e) {
1152
+			} catch (PDOException $e) {
1153 1153
 				return "error (modify unique key in stats_pilot) : ".$e->getMessage()."\n";
1154 1154
 			}
1155 1155
 		}
@@ -1157,7 +1157,7 @@  discard block
 block discarded – undo
1157 1157
 		try {
1158 1158
 			$sth = $Connection->db->prepare($query);
1159 1159
 			$sth->execute();
1160
-		} catch(PDOException $e) {
1160
+		} catch (PDOException $e) {
1161 1161
 			return "error (update schema_version) : ".$e->getMessage()."\n";
1162 1162
 		}
1163 1163
 		return $error;
@@ -1167,23 +1167,23 @@  discard block
 block discarded – undo
1167 1167
 		global $globalDBdriver;
1168 1168
 		$Connection = new Connection();
1169 1169
 		$error = '';
1170
-		if ($globalDBdriver == 'mysql' && !$Connection->indexExists('spotter_live','latitude')) {
1170
+		if ($globalDBdriver == 'mysql' && !$Connection->indexExists('spotter_live', 'latitude')) {
1171 1171
 			// Add unique key
1172 1172
 			$query = "alter table spotter_live add index(latitude,longitude)";
1173 1173
 			try {
1174 1174
 				$sth = $Connection->db->prepare($query);
1175 1175
 				$sth->execute();
1176
-			} catch(PDOException $e) {
1176
+			} catch (PDOException $e) {
1177 1177
 				return "error (add index latitude,longitude on spotter_live) : ".$e->getMessage()."\n";
1178 1178
 			}
1179 1179
                 }
1180
-		if (!$Connection->checkColumnName('aircraft','mfr')) {
1180
+		if (!$Connection->checkColumnName('aircraft', 'mfr')) {
1181 1181
 			// Add mfr to aircraft
1182 1182
 			$query = "ALTER TABLE aircraft ADD mfr VARCHAR(255) NULL";
1183 1183
 			try {
1184 1184
 				$sth = $Connection->db->prepare($query);
1185 1185
 				$sth->execute();
1186
-			} catch(PDOException $e) {
1186
+			} catch (PDOException $e) {
1187 1187
 				return "error (add mfr column in aircraft) : ".$e->getMessage()."\n";
1188 1188
 			}
1189 1189
 		}
@@ -1199,7 +1199,7 @@  discard block
 block discarded – undo
1199 1199
 		try {
1200 1200
 			$sth = $Connection->db->prepare($query);
1201 1201
 			$sth->execute();
1202
-		} catch(PDOException $e) {
1202
+		} catch (PDOException $e) {
1203 1203
 			return "error (update schema_version) : ".$e->getMessage()."\n";
1204 1204
 		}
1205 1205
 		return $error;
@@ -1209,13 +1209,13 @@  discard block
 block discarded – undo
1209 1209
 		global $globalDBdriver;
1210 1210
 		$Connection = new Connection();
1211 1211
 		$error = '';
1212
-		if ($Connection->checkColumnName('aircraft','mfr')) {
1212
+		if ($Connection->checkColumnName('aircraft', 'mfr')) {
1213 1213
 			// drop mfr to aircraft
1214 1214
 			$query = "ALTER TABLE aircraft DROP COLUMN mfr";
1215 1215
 			try {
1216 1216
 				$sth = $Connection->db->prepare($query);
1217 1217
 				$sth->execute();
1218
-			} catch(PDOException $e) {
1218
+			} catch (PDOException $e) {
1219 1219
 				return "error (drop mfr column in aircraft) : ".$e->getMessage()."\n";
1220 1220
 			}
1221 1221
 		}
@@ -1231,7 +1231,7 @@  discard block
 block discarded – undo
1231 1231
 		try {
1232 1232
 			$sth = $Connection->db->prepare($query);
1233 1233
 			$sth->execute();
1234
-		} catch(PDOException $e) {
1234
+		} catch (PDOException $e) {
1235 1235
 			return "error (update schema_version) : ".$e->getMessage()."\n";
1236 1236
 		}
1237 1237
 		return $error;
@@ -1241,33 +1241,33 @@  discard block
 block discarded – undo
1241 1241
 		global $globalDBdriver;
1242 1242
 		$Connection = new Connection();
1243 1243
 		$error = '';
1244
-		if (!$Connection->indexExists('notam','ref_idx')) {
1244
+		if (!$Connection->indexExists('notam', 'ref_idx')) {
1245 1245
 			// Add index key
1246 1246
 			$query = "create index ref_idx on notam (ref)";
1247 1247
 			try {
1248 1248
 				$sth = $Connection->db->prepare($query);
1249 1249
 				$sth->execute();
1250
-			} catch(PDOException $e) {
1250
+			} catch (PDOException $e) {
1251 1251
 				return "error (add index ref on notam) : ".$e->getMessage()."\n";
1252 1252
 			}
1253 1253
                 }
1254
-		if (!$Connection->indexExists('accidents','registration_idx')) {
1254
+		if (!$Connection->indexExists('accidents', 'registration_idx')) {
1255 1255
 			// Add index key
1256 1256
 			$query = "create index registration_idx on accidents (registration)";
1257 1257
 			try {
1258 1258
 				$sth = $Connection->db->prepare($query);
1259 1259
 				$sth->execute();
1260
-			} catch(PDOException $e) {
1260
+			} catch (PDOException $e) {
1261 1261
 				return "error (add index registration on accidents) : ".$e->getMessage()."\n";
1262 1262
 			}
1263 1263
                 }
1264
-		if (!$Connection->indexExists('accidents','rdts')) {
1264
+		if (!$Connection->indexExists('accidents', 'rdts')) {
1265 1265
 			// Add index key
1266 1266
 			$query = "create index rdts on accidents (registration,date,type,source)";
1267 1267
 			try {
1268 1268
 				$sth = $Connection->db->prepare($query);
1269 1269
 				$sth->execute();
1270
-			} catch(PDOException $e) {
1270
+			} catch (PDOException $e) {
1271 1271
 				return "error (add index registration, date, type & source on accidents) : ".$e->getMessage()."\n";
1272 1272
 			}
1273 1273
                 }
@@ -1276,7 +1276,7 @@  discard block
 block discarded – undo
1276 1276
 		try {
1277 1277
 			$sth = $Connection->db->prepare($query);
1278 1278
 			$sth->execute();
1279
-		} catch(PDOException $e) {
1279
+		} catch (PDOException $e) {
1280 1280
 			return "error (update schema_version) : ".$e->getMessage()."\n";
1281 1281
 		}
1282 1282
 		return $error;
@@ -1286,23 +1286,23 @@  discard block
 block discarded – undo
1286 1286
 		global $globalDBdriver;
1287 1287
 		$Connection = new Connection();
1288 1288
 		$error = '';
1289
-		if (!$Connection->checkColumnName('accidents','airline_name')) {
1289
+		if (!$Connection->checkColumnName('accidents', 'airline_name')) {
1290 1290
 			// Add airline_name to accidents
1291 1291
 			$query = "ALTER TABLE accidents ADD airline_name VARCHAR(255) NULL";
1292 1292
 			try {
1293 1293
 				$sth = $Connection->db->prepare($query);
1294 1294
 				$sth->execute();
1295
-			} catch(PDOException $e) {
1295
+			} catch (PDOException $e) {
1296 1296
 				return "error (add airline_name column in accidents) : ".$e->getMessage()."\n";
1297 1297
 			}
1298 1298
 		}
1299
-		if (!$Connection->checkColumnName('accidents','airline_icao')) {
1299
+		if (!$Connection->checkColumnName('accidents', 'airline_icao')) {
1300 1300
 			// Add airline_icao to accidents
1301 1301
 			$query = "ALTER TABLE accidents ADD airline_icao VARCHAR(10) NULL";
1302 1302
 			try {
1303 1303
 				$sth = $Connection->db->prepare($query);
1304 1304
 				$sth->execute();
1305
-			} catch(PDOException $e) {
1305
+			} catch (PDOException $e) {
1306 1306
 				return "error (add airline_icao column in accidents) : ".$e->getMessage()."\n";
1307 1307
 			}
1308 1308
 		}
@@ -1310,7 +1310,7 @@  discard block
 block discarded – undo
1310 1310
 		try {
1311 1311
 			$sth = $Connection->db->prepare($query);
1312 1312
 			$sth->execute();
1313
-		} catch(PDOException $e) {
1313
+		} catch (PDOException $e) {
1314 1314
 			return "error (update schema_version) : ".$e->getMessage()."\n";
1315 1315
 		}
1316 1316
 		return $error;
@@ -1320,13 +1320,13 @@  discard block
 block discarded – undo
1320 1320
 		global $globalDBdriver, $globalVATSIM, $globalIVAO;
1321 1321
 		$Connection = new Connection();
1322 1322
 		$error = '';
1323
-		if (!$Connection->checkColumnName('airlines','alliance')) {
1323
+		if (!$Connection->checkColumnName('airlines', 'alliance')) {
1324 1324
 			// Add alliance to airlines
1325 1325
 			$query = "ALTER TABLE airlines ADD alliance VARCHAR(255) NULL";
1326 1326
 			try {
1327 1327
 				$sth = $Connection->db->prepare($query);
1328 1328
 				$sth->execute();
1329
-			} catch(PDOException $e) {
1329
+			} catch (PDOException $e) {
1330 1330
 				return "error (add alliance column in airlines) : ".$e->getMessage()."\n";
1331 1331
 			}
1332 1332
 		}
@@ -1353,7 +1353,7 @@  discard block
 block discarded – undo
1353 1353
 		try {
1354 1354
 			$sth = $Connection->db->prepare($query);
1355 1355
 			$sth->execute();
1356
-		} catch(PDOException $e) {
1356
+		} catch (PDOException $e) {
1357 1357
 			return "error (update schema_version) : ".$e->getMessage()."\n";
1358 1358
 		}
1359 1359
 		return $error;
@@ -1363,13 +1363,13 @@  discard block
 block discarded – undo
1363 1363
 		global $globalDBdriver, $globalVATSIM, $globalIVAO;
1364 1364
 		$Connection = new Connection();
1365 1365
 		$error = '';
1366
-		if (!$Connection->checkColumnName('airlines','ban_eu')) {
1366
+		if (!$Connection->checkColumnName('airlines', 'ban_eu')) {
1367 1367
 			// Add ban_eu to airlines
1368 1368
 			$query = "ALTER TABLE airlines ADD ban_eu INTEGER NOT NULL DEFAULT '0'";
1369 1369
 			try {
1370 1370
 				$sth = $Connection->db->prepare($query);
1371 1371
 				$sth->execute();
1372
-			} catch(PDOException $e) {
1372
+			} catch (PDOException $e) {
1373 1373
 				return "error (add ban_eu column in airlines) : ".$e->getMessage()."\n";
1374 1374
 			}
1375 1375
 		}
@@ -1377,7 +1377,7 @@  discard block
 block discarded – undo
1377 1377
 		try {
1378 1378
 			$sth = $Connection->db->prepare($query);
1379 1379
 			$sth->execute();
1380
-		} catch(PDOException $e) {
1380
+		} catch (PDOException $e) {
1381 1381
 			return "error (update schema_version) : ".$e->getMessage()."\n";
1382 1382
 		}
1383 1383
 		return $error;
@@ -1388,19 +1388,19 @@  discard block
 block discarded – undo
1388 1388
 		$Connection = new Connection();
1389 1389
 		$error = '';
1390 1390
 		if ($globalDBdriver == 'mysql') {
1391
-			if ($Connection->getColumnType('spotter_output','date') == 'TIMESTAMP' && $Connection->getColumnType('spotter_output','last_seen') != 'TIMESTAMP') {
1391
+			if ($Connection->getColumnType('spotter_output', 'date') == 'TIMESTAMP' && $Connection->getColumnType('spotter_output', 'last_seen') != 'TIMESTAMP') {
1392 1392
 				$query = "ALTER TABLE spotter_output CHANGE date date TIMESTAMP NULL DEFAULT NULL";
1393 1393
 				try {
1394 1394
 					$sth = $Connection->db->prepare($query);
1395 1395
 					$sth->execute();
1396
-				} catch(PDOException $e) {
1396
+				} catch (PDOException $e) {
1397 1397
 					return "error (delete default timestamp spotter_output) : ".$e->getMessage()."\n";
1398 1398
 				}
1399 1399
 				$query = "ALTER TABLE spotter_output MODIFY COLUMN last_seen timestamp not null default current_timestamp()";
1400 1400
 				try {
1401 1401
 					$sth = $Connection->db->prepare($query);
1402 1402
 					$sth->execute();
1403
-				} catch(PDOException $e) {
1403
+				} catch (PDOException $e) {
1404 1404
 					return "error (convert spotter_output last_seen to timestamp) : ".$e->getMessage()."\n";
1405 1405
 				}
1406 1406
 				
@@ -1408,7 +1408,7 @@  discard block
 block discarded – undo
1408 1408
 				try {
1409 1409
 					$sth = $Connection->db->prepare($query);
1410 1410
 					$sth->execute();
1411
-				} catch(PDOException $e) {
1411
+				} catch (PDOException $e) {
1412 1412
 					return "error (delete default timestamp spotter_output) : ".$e->getMessage()."\n";
1413 1413
 				}
1414 1414
 				/*$query = "SELECT date,last_seen FROM spotter_output WHERE last_seen < date ORDER BY date DESC LIMIT 150";
@@ -1459,7 +1459,7 @@  discard block
 block discarded – undo
1459 1459
 				try {
1460 1460
 					$sth = $Connection->db->prepare($query);
1461 1461
 					$sth->execute();
1462
-				} catch(PDOException $e) {
1462
+				} catch (PDOException $e) {
1463 1463
 					return "error (fix date) : ".$e->getMessage()."\n";
1464 1464
 				}
1465 1465
 			}
@@ -1544,7 +1544,7 @@  discard block
 block discarded – undo
1544 1544
 		try {
1545 1545
 			$sth = $Connection->db->prepare($query);
1546 1546
 			$sth->execute();
1547
-		} catch(PDOException $e) {
1547
+		} catch (PDOException $e) {
1548 1548
 			return "error (update schema_version) : ".$e->getMessage()."\n";
1549 1549
 		}
1550 1550
 		return $error;
@@ -1553,13 +1553,13 @@  discard block
 block discarded – undo
1553 1553
 		global $globalDBdriver;
1554 1554
 		$Connection = new Connection();
1555 1555
 		$error = '';
1556
-		if (!$Connection->indexExists('accidents','type')) {
1556
+		if (!$Connection->indexExists('accidents', 'type')) {
1557 1557
 			// Add index key
1558 1558
 			$query = "create index type on accidents (type,date)";
1559 1559
 			try {
1560 1560
 				$sth = $Connection->db->prepare($query);
1561 1561
 				$sth->execute();
1562
-			} catch(PDOException $e) {
1562
+			} catch (PDOException $e) {
1563 1563
 				return "error (add index type on accidents) : ".$e->getMessage()."\n";
1564 1564
 			}
1565 1565
                 }
@@ -1567,7 +1567,7 @@  discard block
 block discarded – undo
1567 1567
 		try {
1568 1568
 			$sth = $Connection->db->prepare($query);
1569 1569
 			$sth->execute();
1570
-		} catch(PDOException $e) {
1570
+		} catch (PDOException $e) {
1571 1571
 			return "error (update schema_version) : ".$e->getMessage()."\n";
1572 1572
 		}
1573 1573
 		return $error;
@@ -1577,12 +1577,12 @@  discard block
 block discarded – undo
1577 1577
 		global $globalDBdriver;
1578 1578
 		$Connection = new Connection();
1579 1579
 		$error = '';
1580
-		if (!$Connection->checkColumnName('aircraft_modes','source_type')) {
1580
+		if (!$Connection->checkColumnName('aircraft_modes', 'source_type')) {
1581 1581
 			$query = "ALTER TABLE aircraft_modes ADD source_type VARCHAR(255) DEFAULT 'modes'";
1582 1582
 			try {
1583 1583
 				$sth = $Connection->db->prepare($query);
1584 1584
 				$sth->execute();
1585
-			} catch(PDOException $e) {
1585
+			} catch (PDOException $e) {
1586 1586
 				return "error (add source_type column in aircraft_modes) : ".$e->getMessage()."\n";
1587 1587
 			}
1588 1588
 		}
@@ -1636,7 +1636,7 @@  discard block
 block discarded – undo
1636 1636
 		try {
1637 1637
 			$sth = $Connection->db->prepare($query);
1638 1638
 			$sth->execute();
1639
-		} catch(PDOException $e) {
1639
+		} catch (PDOException $e) {
1640 1640
 			return "error (update schema_version) : ".$e->getMessage()."\n";
1641 1641
 		}
1642 1642
 		return $error;
@@ -1658,7 +1658,7 @@  discard block
 block discarded – undo
1658 1658
 		    try {
1659 1659
             		$sth = $Connection->db->prepare($query);
1660 1660
 		        $sth->execute();
1661
-		    } catch(PDOException $e) {
1661
+		    } catch (PDOException $e) {
1662 1662
 			return "error : ".$e->getMessage()."\n";
1663 1663
     		    }
1664 1664
     		    $result = $sth->fetch(PDO::FETCH_ASSOC);
Please login to merge, or discard this patch.
Braces   +323 added lines, -120 removed lines patch added patch discarded remove patch
@@ -258,7 +258,9 @@  discard block
 block discarded – undo
258 258
     		// Update table countries
259 259
     		if ($Connection->tableExists('airspace')) {
260 260
     		    $error .= update_db::update_countries();
261
-		    if ($error != '') return $error;
261
+		    if ($error != '') {
262
+		    	return $error;
263
+		    }
262 264
 		}
263 265
 		// Update schema_version to 7
264 266
 		$query = "UPDATE `config` SET `value` = '7' WHERE `name` = 'schema_version'";
@@ -314,7 +316,9 @@  discard block
 block discarded – undo
314 316
     		$error = '';
315 317
     		// Update table aircraft
316 318
 		$error .= create_db::import_file('../db/source_location.sql');
317
-		if ($error != '') return $error;
319
+		if ($error != '') {
320
+			return $error;
321
+		}
318 322
 		// Update schema_version to 6
319 323
 		$query = "UPDATE `config` SET `value` = '8' WHERE `name` = 'schema_version'";
320 324
         	try {
@@ -331,7 +335,9 @@  discard block
 block discarded – undo
331 335
     		$error = '';
332 336
     		// Update table aircraft
333 337
 		$error .= create_db::import_file('../db/notam.sql');
334
-		if ($error != '') return $error;
338
+		if ($error != '') {
339
+			return $error;
340
+		}
335 341
 		$query = "DELETE FROM config WHERE name = 'last_update_db';
336 342
                         INSERT INTO config (name,value) VALUES ('last_update_db',NOW());
337 343
                         DELETE FROM config WHERE name = 'last_update_notam_db';
@@ -365,7 +371,9 @@  discard block
 block discarded – undo
365 371
 		$error = '';
366 372
     		// Update table atc
367 373
 		$error .= create_db::import_file('../db/atc.sql');
368
-		if ($error != '') return $error;
374
+		if ($error != '') {
375
+			return $error;
376
+		}
369 377
 		
370 378
 		$query = "UPDATE `config` SET `value` = '10' WHERE `name` = 'schema_version'";
371 379
         	try {
@@ -389,13 +397,21 @@  discard block
 block discarded – undo
389 397
 		$error = '';
390 398
     		// Add tables
391 399
 		$error .= create_db::import_file('../db/aircraft_owner.sql');
392
-		if ($error != '') return $error;
400
+		if ($error != '') {
401
+			return $error;
402
+		}
393 403
 		$error .= create_db::import_file('../db/metar.sql');
394
-		if ($error != '') return $error;
404
+		if ($error != '') {
405
+			return $error;
406
+		}
395 407
 		$error .= create_db::import_file('../db/taf.sql');
396
-		if ($error != '') return $error;
408
+		if ($error != '') {
409
+			return $error;
410
+		}
397 411
 		$error .= create_db::import_file('../db/airport.sql');
398
-		if ($error != '') return $error;
412
+		if ($error != '') {
413
+			return $error;
414
+		}
399 415
 		
400 416
 		$query = "UPDATE `config` SET `value` = '11' WHERE `name` = 'schema_version'";
401 417
         	try {
@@ -469,19 +485,33 @@  discard block
 block discarded – undo
469 485
 		$error = '';
470 486
     		// Add tables
471 487
 		$error .= create_db::import_file('../db/stats.sql');
472
-		if ($error != '') return $error;
488
+		if ($error != '') {
489
+			return $error;
490
+		}
473 491
 		$error .= create_db::import_file('../db/stats_aircraft.sql');
474
-		if ($error != '') return $error;
492
+		if ($error != '') {
493
+			return $error;
494
+		}
475 495
 		$error .= create_db::import_file('../db/stats_airline.sql');
476
-		if ($error != '') return $error;
496
+		if ($error != '') {
497
+			return $error;
498
+		}
477 499
 		$error .= create_db::import_file('../db/stats_airport.sql');
478
-		if ($error != '') return $error;
500
+		if ($error != '') {
501
+			return $error;
502
+		}
479 503
 		$error .= create_db::import_file('../db/stats_owner.sql');
480
-		if ($error != '') return $error;
504
+		if ($error != '') {
505
+			return $error;
506
+		}
481 507
 		$error .= create_db::import_file('../db/stats_pilot.sql');
482
-		if ($error != '') return $error;
508
+		if ($error != '') {
509
+			return $error;
510
+		}
483 511
 		$error .= create_db::import_file('../db/spotter_archive_output.sql');
484
-		if ($error != '') return $error;
512
+		if ($error != '') {
513
+			return $error;
514
+		}
485 515
 		
486 516
 		$query = "UPDATE `config` SET `value` = '13' WHERE `name` = 'schema_version'";
487 517
         	try {
@@ -521,7 +551,9 @@  discard block
 block discarded – undo
521 551
     		// Add tables
522 552
     		if (!$Connection->tableExists('stats_flight')) {
523 553
 			$error .= create_db::import_file('../db/stats_flight.sql');
524
-			if ($error != '') return $error;
554
+			if ($error != '') {
555
+				return $error;
556
+			}
525 557
 		}
526 558
 		$query = "UPDATE `config` SET `value` = '15' WHERE `name` = 'schema_version'";
527 559
         	try {
@@ -545,7 +577,9 @@  discard block
 block discarded – undo
545 577
     		} catch(PDOException $e) {
546 578
 		    return "error (update stats) : ".$e->getMessage()."\n";
547 579
     		}
548
-		if ($error != '') return $error;
580
+		if ($error != '') {
581
+			return $error;
582
+		}
549 583
 		$query = "UPDATE `config` SET `value` = '16' WHERE `name` = 'schema_version'";
550 584
         	try {
551 585
             	    $sth = $Connection->db->prepare($query);
@@ -566,7 +600,9 @@  discard block
 block discarded – undo
566 600
     		if (!$Connection->tableExists('stats_callsign')) {
567 601
 			$error .= create_db::import_file('../db/stats_callsign.sql');
568 602
 		}
569
-		if ($error != '') return $error;
603
+		if ($error != '') {
604
+			return $error;
605
+		}
570 606
 		$query = "UPDATE `config` SET `value` = '17' WHERE `name` = 'schema_version'";
571 607
         	try {
572 608
             	    $sth = $Connection->db->prepare($query);
@@ -584,7 +620,9 @@  discard block
 block discarded – undo
584 620
     		if (!$Connection->tableExists('stats_country')) {
585 621
 			$error .= create_db::import_file('../db/stats_country.sql');
586 622
 		}
587
-		if ($error != '') return $error;
623
+		if ($error != '') {
624
+			return $error;
625
+		}
588 626
 		$query = "UPDATE `config` SET `value` = '18' WHERE `name` = 'schema_version'";
589 627
         	try {
590 628
             	    $sth = $Connection->db->prepare($query);
@@ -607,7 +645,9 @@  discard block
 block discarded – undo
607 645
 			    return "error (update stats) : ".$e->getMessage()."\n";
608 646
     			}
609 647
     		}
610
-		if ($error != '') return $error;
648
+		if ($error != '') {
649
+			return $error;
650
+		}
611 651
 		$query = "UPDATE `config` SET `value` = '19' WHERE `name` = 'schema_version'";
612 652
         	try {
613 653
             	    $sth = $Connection->db->prepare($query);
@@ -623,7 +663,9 @@  discard block
 block discarded – undo
623 663
 		$error = '';
624 664
     		// Update airport table
625 665
 		$error .= create_db::import_file('../db/airport.sql');
626
-		if ($error != '') return 'Import airport.sql : '.$error;
666
+		if ($error != '') {
667
+			return 'Import airport.sql : '.$error;
668
+		}
627 669
 		// Remove primary key on Spotter_Archive
628 670
 		$query = "alter table spotter_archive drop spotter_archive_id";
629 671
         	try {
@@ -699,7 +741,9 @@  discard block
 block discarded – undo
699 741
 				return "error (add source_name column) : ".$e->getMessage()."\n";
700 742
     			}
701 743
     		}
702
-		if ($error != '') return $error;
744
+		if ($error != '') {
745
+			return $error;
746
+		}
703 747
 		$query = "UPDATE `config` SET `value` = '20' WHERE `name` = 'schema_version'";
704 748
         	try {
705 749
             	    $sth = $Connection->db->prepare($query);
@@ -717,7 +761,9 @@  discard block
 block discarded – undo
717 761
     		// Update airline table
718 762
     		if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS) {
719 763
 			$error .= create_db::import_file('../db/airlines.sql');
720
-			if ($error != '') return 'Import airlines.sql : '.$error;
764
+			if ($error != '') {
765
+				return 'Import airlines.sql : '.$error;
766
+			}
721 767
 		}
722 768
 		if (!$Connection->checkColumnName('aircraft_modes','type_flight')) {
723 769
 			// Add column over_country
@@ -729,7 +775,9 @@  discard block
 block discarded – undo
729 775
 				return "error (add over_country) : ".$e->getMessage()."\n";
730 776
     			}
731 777
     		}
732
-		if ($error != '') return $error;
778
+		if ($error != '') {
779
+			return $error;
780
+		}
733 781
 		/*
734 782
     		if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS) {
735 783
 			// Force update ModeS (this will put type_flight data
@@ -759,7 +807,9 @@  discard block
 block discarded – undo
759 807
 			} catch(PDOException $e) {
760 808
 				return "error (rename type to stats_type on stats*) : ".$e->getMessage()."\n";
761 809
 			}
762
-			if ($error != '') return $error;
810
+			if ($error != '') {
811
+				return $error;
812
+			}
763 813
 		}
764 814
 		$query = "UPDATE `config` SET `value` = '22' WHERE `name` = 'schema_version'";
765 815
         	try {
@@ -782,7 +832,9 @@  discard block
 block discarded – undo
782 832
 			} else {
783 833
 				$error .= create_db::import_file('../db/pgsql/stats_source.sql');
784 834
 			}
785
-			if ($error != '') return $error;
835
+			if ($error != '') {
836
+				return $error;
837
+			}
786 838
 		}
787 839
 		$query = "UPDATE config SET value = '23' WHERE name = 'schema_version'";
788 840
         	try {
@@ -804,12 +856,16 @@  discard block
 block discarded – undo
804 856
 		if ($globalDBdriver == 'mysql') {
805 857
 			if (!$Connection->tableExists('tle')) {
806 858
 				$error .= create_db::import_file('../db/tle.sql');
807
-				if ($error != '') return $error;
859
+				if ($error != '') {
860
+					return $error;
861
+				}
808 862
 			}
809 863
 		} else {
810 864
 			if (!$Connection->tableExists('tle')) {
811 865
 				$error .= create_db::import_file('../db/pgsql/tle.sql');
812
-				if ($error != '') return $error;
866
+				if ($error != '') {
867
+					return $error;
868
+				}
813 869
 			}
814 870
 			$query = "create index flightaware_id_idx ON spotter_archive USING btree(flightaware_id)";
815 871
 			try {
@@ -849,7 +905,9 @@  discard block
 block discarded – undo
849 905
 		} else {
850 906
 			$error .= create_db::import_file('../db/pgsql/airlines.sql');
851 907
 		}
852
-		if ($error != '') return 'Import airlines.sql : '.$error;
908
+		if ($error != '') {
909
+			return 'Import airlines.sql : '.$error;
910
+		}
853 911
 		if (!$Connection->checkColumnName('airlines','forsource')) {
854 912
 			// Add forsource to airlines
855 913
 			$query = "ALTER TABLE airlines ADD forsource VARCHAR(255) NULL DEFAULT NULL";
@@ -1332,20 +1390,28 @@  discard block
 block discarded – undo
1332 1390
 		}
1333 1391
 		if ($globalDBdriver == 'mysql') {
1334 1392
 			$error .= create_db::import_file('../db/airlines.sql');
1335
-			if ($error != '') return $error;
1393
+			if ($error != '') {
1394
+				return $error;
1395
+			}
1336 1396
 		} else {
1337 1397
 			$error .= create_db::import_file('../db/pgsql/airlines.sql');
1338
-			if ($error != '') return $error;
1398
+			if ($error != '') {
1399
+				return $error;
1400
+			}
1339 1401
 		}
1340 1402
 		if ((isset($globalVATSIM) && $globalVATSIM) || (isset($globalIVAO) && $globalIVAO)) {
1341 1403
 			include_once(dirname(__FILE__).'/class.update_db.php');
1342 1404
 			if (isset($globalVATSIM) && $globalVATSIM) {
1343 1405
 				$error .= update_db::update_vatsim();
1344
-				if ($error != '') return $error;
1406
+				if ($error != '') {
1407
+					return $error;
1408
+				}
1345 1409
 			}
1346 1410
 			if (isset($globalIVAO) && $globalIVAO && file_exists('tmp/ivae_feb2013.zip')) {
1347 1411
 				$error .= update_db::update_IVAO();
1348
-				if ($error != '') return $error;
1412
+				if ($error != '') {
1413
+					return $error;
1414
+				}
1349 1415
 			}
1350 1416
 		}
1351 1417
 
@@ -1607,30 +1673,54 @@  discard block
 block discarded – undo
1607 1673
 		*/
1608 1674
 		if ($globalDBdriver == 'mysql') {
1609 1675
 			$error .= create_db::import_file('../db/tracker_output.sql');
1610
-			if ($error != '') return $error;
1676
+			if ($error != '') {
1677
+				return $error;
1678
+			}
1611 1679
 			$error .= create_db::import_file('../db/tracker_live.sql');
1612
-			if ($error != '') return $error;
1680
+			if ($error != '') {
1681
+				return $error;
1682
+			}
1613 1683
 			$error .= create_db::import_file('../db/marine_output.sql');
1614
-			if ($error != '') return $error;
1684
+			if ($error != '') {
1685
+				return $error;
1686
+			}
1615 1687
 			$error .= create_db::import_file('../db/marine_live.sql');
1616
-			if ($error != '') return $error;
1688
+			if ($error != '') {
1689
+				return $error;
1690
+			}
1617 1691
 			$error .= create_db::import_file('../db/marine_identity.sql');
1618
-			if ($error != '') return $error;
1692
+			if ($error != '') {
1693
+				return $error;
1694
+			}
1619 1695
 			$error .= create_db::import_file('../db/marine_mid.sql');
1620
-			if ($error != '') return $error;
1696
+			if ($error != '') {
1697
+				return $error;
1698
+			}
1621 1699
 		} else {
1622 1700
 			$error .= create_db::import_file('../db/pgsql/tracker_output.sql');
1623
-			if ($error != '') return $error;
1701
+			if ($error != '') {
1702
+				return $error;
1703
+			}
1624 1704
 			$error .= create_db::import_file('../db/pgsql/tracker_live.sql');
1625
-			if ($error != '') return $error;
1705
+			if ($error != '') {
1706
+				return $error;
1707
+			}
1626 1708
 			$error .= create_db::import_file('../db/pgsql/marine_output.sql');
1627
-			if ($error != '') return $error;
1709
+			if ($error != '') {
1710
+				return $error;
1711
+			}
1628 1712
 			$error .= create_db::import_file('../db/pgsql/marine_live.sql');
1629
-			if ($error != '') return $error;
1713
+			if ($error != '') {
1714
+				return $error;
1715
+			}
1630 1716
 			$error .= create_db::import_file('../db/pgsql/marine_identity.sql');
1631
-			if ($error != '') return $error;
1717
+			if ($error != '') {
1718
+				return $error;
1719
+			}
1632 1720
 			$error .= create_db::import_file('../db/pgsql/marine_mid.sql');
1633
-			if ($error != '') return $error;
1721
+			if ($error != '') {
1722
+				return $error;
1723
+			}
1634 1724
 		}
1635 1725
 		$query = "UPDATE config SET value = '37' WHERE name = 'schema_version'";
1636 1726
 		try {
@@ -1650,8 +1740,11 @@  discard block
 block discarded – undo
1650 1740
     	    if ($Connection->tableExists('aircraft')) {
1651 1741
     		if (!$Connection->tableExists('config')) {
1652 1742
     		    $version = '1';
1653
-    		    if ($update) return self::update_from_1();
1654
-    		    else return $version;
1743
+    		    if ($update) {
1744
+    		    	return self::update_from_1();
1745
+    		    } else {
1746
+    		    	return $version;
1747
+    		    }
1655 1748
 		} else {
1656 1749
     		    $Connection = new Connection();
1657 1750
 		    $query = "SELECT value FROM config WHERE name = 'schema_version' LIMIT 1";
@@ -1665,150 +1758,260 @@  discard block
 block discarded – undo
1665 1758
     		    if ($update) {
1666 1759
     			if ($result['value'] == '2') {
1667 1760
     			    $error = self::update_from_2();
1668
-    			    if ($error != '') return $error;
1669
-    			    else return self::check_version(true);
1761
+    			    if ($error != '') {
1762
+    			    	return $error;
1763
+    			    } else {
1764
+    			    	return self::check_version(true);
1765
+    			    }
1670 1766
     			} elseif ($result['value'] == '3') {
1671 1767
     			    $error = self::update_from_3();
1672
-    			    if ($error != '') return $error;
1673
-    			    else return self::check_version(true);
1768
+    			    if ($error != '') {
1769
+    			    	return $error;
1770
+    			    } else {
1771
+    			    	return self::check_version(true);
1772
+    			    }
1674 1773
     			} elseif ($result['value'] == '4') {
1675 1774
     			    $error = self::update_from_4();
1676
-    			    if ($error != '') return $error;
1677
-    			    else return self::check_version(true);
1775
+    			    if ($error != '') {
1776
+    			    	return $error;
1777
+    			    } else {
1778
+    			    	return self::check_version(true);
1779
+    			    }
1678 1780
     			} elseif ($result['value'] == '5') {
1679 1781
     			    $error = self::update_from_5();
1680
-    			    if ($error != '') return $error;
1681
-    			    else return self::check_version(true);
1782
+    			    if ($error != '') {
1783
+    			    	return $error;
1784
+    			    } else {
1785
+    			    	return self::check_version(true);
1786
+    			    }
1682 1787
     			} elseif ($result['value'] == '6') {
1683 1788
     			    $error = self::update_from_6();
1684
-    			    if ($error != '') return $error;
1685
-    			    else return self::check_version(true);
1789
+    			    if ($error != '') {
1790
+    			    	return $error;
1791
+    			    } else {
1792
+    			    	return self::check_version(true);
1793
+    			    }
1686 1794
     			} elseif ($result['value'] == '7') {
1687 1795
     			    $error = self::update_from_7();
1688
-    			    if ($error != '') return $error;
1689
-    			    else return self::check_version(true);
1796
+    			    if ($error != '') {
1797
+    			    	return $error;
1798
+    			    } else {
1799
+    			    	return self::check_version(true);
1800
+    			    }
1690 1801
     			} elseif ($result['value'] == '8') {
1691 1802
     			    $error = self::update_from_8();
1692
-    			    if ($error != '') return $error;
1693
-    			    else return self::check_version(true);
1803
+    			    if ($error != '') {
1804
+    			    	return $error;
1805
+    			    } else {
1806
+    			    	return self::check_version(true);
1807
+    			    }
1694 1808
     			} elseif ($result['value'] == '9') {
1695 1809
     			    $error = self::update_from_9();
1696
-    			    if ($error != '') return $error;
1697
-    			    else return self::check_version(true);
1810
+    			    if ($error != '') {
1811
+    			    	return $error;
1812
+    			    } else {
1813
+    			    	return self::check_version(true);
1814
+    			    }
1698 1815
     			} elseif ($result['value'] == '10') {
1699 1816
     			    $error = self::update_from_10();
1700
-    			    if ($error != '') return $error;
1701
-    			    else return self::check_version(true);
1817
+    			    if ($error != '') {
1818
+    			    	return $error;
1819
+    			    } else {
1820
+    			    	return self::check_version(true);
1821
+    			    }
1702 1822
     			} elseif ($result['value'] == '11') {
1703 1823
     			    $error = self::update_from_11();
1704
-    			    if ($error != '') return $error;
1705
-    			    else return self::check_version(true);
1824
+    			    if ($error != '') {
1825
+    			    	return $error;
1826
+    			    } else {
1827
+    			    	return self::check_version(true);
1828
+    			    }
1706 1829
     			} elseif ($result['value'] == '12') {
1707 1830
     			    $error = self::update_from_12();
1708
-    			    if ($error != '') return $error;
1709
-    			    else return self::check_version(true);
1831
+    			    if ($error != '') {
1832
+    			    	return $error;
1833
+    			    } else {
1834
+    			    	return self::check_version(true);
1835
+    			    }
1710 1836
     			} elseif ($result['value'] == '13') {
1711 1837
     			    $error = self::update_from_13();
1712
-    			    if ($error != '') return $error;
1713
-    			    else return self::check_version(true);
1838
+    			    if ($error != '') {
1839
+    			    	return $error;
1840
+    			    } else {
1841
+    			    	return self::check_version(true);
1842
+    			    }
1714 1843
     			} elseif ($result['value'] == '14') {
1715 1844
     			    $error = self::update_from_14();
1716
-    			    if ($error != '') return $error;
1717
-    			    else return self::check_version(true);
1845
+    			    if ($error != '') {
1846
+    			    	return $error;
1847
+    			    } else {
1848
+    			    	return self::check_version(true);
1849
+    			    }
1718 1850
     			} elseif ($result['value'] == '15') {
1719 1851
     			    $error = self::update_from_15();
1720
-    			    if ($error != '') return $error;
1721
-    			    else return self::check_version(true);
1852
+    			    if ($error != '') {
1853
+    			    	return $error;
1854
+    			    } else {
1855
+    			    	return self::check_version(true);
1856
+    			    }
1722 1857
     			} elseif ($result['value'] == '16') {
1723 1858
     			    $error = self::update_from_16();
1724
-    			    if ($error != '') return $error;
1725
-    			    else return self::check_version(true);
1859
+    			    if ($error != '') {
1860
+    			    	return $error;
1861
+    			    } else {
1862
+    			    	return self::check_version(true);
1863
+    			    }
1726 1864
     			} elseif ($result['value'] == '17') {
1727 1865
     			    $error = self::update_from_17();
1728
-    			    if ($error != '') return $error;
1729
-    			    else return self::check_version(true);
1866
+    			    if ($error != '') {
1867
+    			    	return $error;
1868
+    			    } else {
1869
+    			    	return self::check_version(true);
1870
+    			    }
1730 1871
     			} elseif ($result['value'] == '18') {
1731 1872
     			    $error = self::update_from_18();
1732
-    			    if ($error != '') return $error;
1733
-    			    else return self::check_version(true);
1873
+    			    if ($error != '') {
1874
+    			    	return $error;
1875
+    			    } else {
1876
+    			    	return self::check_version(true);
1877
+    			    }
1734 1878
     			} elseif ($result['value'] == '19') {
1735 1879
     			    $error = self::update_from_19();
1736
-    			    if ($error != '') return $error;
1737
-    			    else return self::check_version(true);
1880
+    			    if ($error != '') {
1881
+    			    	return $error;
1882
+    			    } else {
1883
+    			    	return self::check_version(true);
1884
+    			    }
1738 1885
     			} elseif ($result['value'] == '20') {
1739 1886
     			    $error = self::update_from_20();
1740
-    			    if ($error != '') return $error;
1741
-    			    else return self::check_version(true);
1887
+    			    if ($error != '') {
1888
+    			    	return $error;
1889
+    			    } else {
1890
+    			    	return self::check_version(true);
1891
+    			    }
1742 1892
     			} elseif ($result['value'] == '21') {
1743 1893
     			    $error = self::update_from_21();
1744
-    			    if ($error != '') return $error;
1745
-    			    else return self::check_version(true);
1894
+    			    if ($error != '') {
1895
+    			    	return $error;
1896
+    			    } else {
1897
+    			    	return self::check_version(true);
1898
+    			    }
1746 1899
     			} elseif ($result['value'] == '22') {
1747 1900
     			    $error = self::update_from_22();
1748
-    			    if ($error != '') return $error;
1749
-    			    else return self::check_version(true);
1901
+    			    if ($error != '') {
1902
+    			    	return $error;
1903
+    			    } else {
1904
+    			    	return self::check_version(true);
1905
+    			    }
1750 1906
     			} elseif ($result['value'] == '23') {
1751 1907
     			    $error = self::update_from_23();
1752
-    			    if ($error != '') return $error;
1753
-    			    else return self::check_version(true);
1908
+    			    if ($error != '') {
1909
+    			    	return $error;
1910
+    			    } else {
1911
+    			    	return self::check_version(true);
1912
+    			    }
1754 1913
     			} elseif ($result['value'] == '24') {
1755 1914
     			    $error = self::update_from_24();
1756
-    			    if ($error != '') return $error;
1757
-    			    else return self::check_version(true);
1915
+    			    if ($error != '') {
1916
+    			    	return $error;
1917
+    			    } else {
1918
+    			    	return self::check_version(true);
1919
+    			    }
1758 1920
     			} elseif ($result['value'] == '25') {
1759 1921
     			    $error = self::update_from_25();
1760
-    			    if ($error != '') return $error;
1761
-    			    else return self::check_version(true);
1922
+    			    if ($error != '') {
1923
+    			    	return $error;
1924
+    			    } else {
1925
+    			    	return self::check_version(true);
1926
+    			    }
1762 1927
     			} elseif ($result['value'] == '26') {
1763 1928
     			    $error = self::update_from_26();
1764
-    			    if ($error != '') return $error;
1765
-    			    else return self::check_version(true);
1929
+    			    if ($error != '') {
1930
+    			    	return $error;
1931
+    			    } else {
1932
+    			    	return self::check_version(true);
1933
+    			    }
1766 1934
     			} elseif ($result['value'] == '27') {
1767 1935
     			    $error = self::update_from_27();
1768
-    			    if ($error != '') return $error;
1769
-    			    else return self::check_version(true);
1936
+    			    if ($error != '') {
1937
+    			    	return $error;
1938
+    			    } else {
1939
+    			    	return self::check_version(true);
1940
+    			    }
1770 1941
     			} elseif ($result['value'] == '28') {
1771 1942
     			    $error = self::update_from_28();
1772
-    			    if ($error != '') return $error;
1773
-    			    else return self::check_version(true);
1943
+    			    if ($error != '') {
1944
+    			    	return $error;
1945
+    			    } else {
1946
+    			    	return self::check_version(true);
1947
+    			    }
1774 1948
     			} elseif ($result['value'] == '29') {
1775 1949
     			    $error = self::update_from_29();
1776
-    			    if ($error != '') return $error;
1777
-    			    else return self::check_version(true);
1950
+    			    if ($error != '') {
1951
+    			    	return $error;
1952
+    			    } else {
1953
+    			    	return self::check_version(true);
1954
+    			    }
1778 1955
     			} elseif ($result['value'] == '30') {
1779 1956
     			    $error = self::update_from_30();
1780
-    			    if ($error != '') return $error;
1781
-    			    else return self::check_version(true);
1957
+    			    if ($error != '') {
1958
+    			    	return $error;
1959
+    			    } else {
1960
+    			    	return self::check_version(true);
1961
+    			    }
1782 1962
     			} elseif ($result['value'] == '31') {
1783 1963
     			    $error = self::update_from_31();
1784
-    			    if ($error != '') return $error;
1785
-    			    else return self::check_version(true);
1964
+    			    if ($error != '') {
1965
+    			    	return $error;
1966
+    			    } else {
1967
+    			    	return self::check_version(true);
1968
+    			    }
1786 1969
     			} elseif ($result['value'] == '32') {
1787 1970
     			    $error = self::update_from_32();
1788
-    			    if ($error != '') return $error;
1789
-    			    else return self::check_version(true);
1971
+    			    if ($error != '') {
1972
+    			    	return $error;
1973
+    			    } else {
1974
+    			    	return self::check_version(true);
1975
+    			    }
1790 1976
     			} elseif ($result['value'] == '33') {
1791 1977
     			    $error = self::update_from_33();
1792
-    			    if ($error != '') return $error;
1793
-    			    else return self::check_version(true);
1978
+    			    if ($error != '') {
1979
+    			    	return $error;
1980
+    			    } else {
1981
+    			    	return self::check_version(true);
1982
+    			    }
1794 1983
     			} elseif ($result['value'] == '34') {
1795 1984
     			    $error = self::update_from_34();
1796
-    			    if ($error != '') return $error;
1797
-    			    else return self::check_version(true);
1985
+    			    if ($error != '') {
1986
+    			    	return $error;
1987
+    			    } else {
1988
+    			    	return self::check_version(true);
1989
+    			    }
1798 1990
     			} elseif ($result['value'] == '35') {
1799 1991
     			    $error = self::update_from_35();
1800
-    			    if ($error != '') return $error;
1801
-    			    else return self::check_version(true);
1992
+    			    if ($error != '') {
1993
+    			    	return $error;
1994
+    			    } else {
1995
+    			    	return self::check_version(true);
1996
+    			    }
1802 1997
     			} elseif ($result['value'] == '36') {
1803 1998
     			    $error = self::update_from_36();
1804
-    			    if ($error != '') return $error;
1805
-    			    else return self::check_version(true);
1806
-    			} else return '';
1999
+    			    if ($error != '') {
2000
+    			    	return $error;
2001
+    			    } else {
2002
+    			    	return self::check_version(true);
2003
+    			    }
2004
+    			} else {
2005
+    				return '';
2006
+    			}
2007
+    		    } else {
2008
+    		    	return $result['value'];
1807 2009
     		    }
1808
-    		    else return $result['value'];
1809 2010
 		}
1810 2011
 		
1811
-	    } else return $version;
2012
+	    } else {
2013
+	    	return $version;
2014
+	    }
1812 2015
     	}
1813 2016
     	
1814 2017
 }
Please login to merge, or discard this patch.
scripts/daemon-spotter.php 3 patches
Indentation   +836 added lines, -836 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
 require_once(dirname(__FILE__).'/../require/class.Common.php');
16 16
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
17 17
 if (isset($globalMarine) && $globalMarine) {
18
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
19
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
18
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
19
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
20 20
 }
21 21
 
22 22
 if (!isset($globalDebug)) $globalDebug = FALSE;
@@ -24,52 +24,52 @@  discard block
 block discarded – undo
24 24
 // Check if schema is at latest version
25 25
 $Connection = new Connection();
26 26
 if ($Connection->latest() === false) {
27
-    echo "You MUST update to latest schema. Run install/index.php";
28
-    exit();
27
+	echo "You MUST update to latest schema. Run install/index.php";
28
+	exit();
29 29
 }
30 30
 if (PHP_SAPI != 'cli') {
31
-    echo "This script MUST be called from console, not a web browser.";
31
+	echo "This script MUST be called from console, not a web browser.";
32 32
 //    exit();
33 33
 }
34 34
 
35 35
 // This is to be compatible with old version of settings.php
36 36
 if (!isset($globalSources)) {
37
-    if (isset($globalSBS1Hosts)) {
38
-        //$hosts = $globalSBS1Hosts;
39
-        foreach ($globalSBS1Hosts as $host) {
40
-	    $globalSources[] = array('host' => $host);
41
-    	}
42
-    } else {
43
-        if (!isset($globalSBS1Host)) {
44
-	    echo '$globalSources MUST be defined !';
45
-	    die;
37
+	if (isset($globalSBS1Hosts)) {
38
+		//$hosts = $globalSBS1Hosts;
39
+		foreach ($globalSBS1Hosts as $host) {
40
+		$globalSources[] = array('host' => $host);
41
+		}
42
+	} else {
43
+		if (!isset($globalSBS1Host)) {
44
+		echo '$globalSources MUST be defined !';
45
+		die;
46 46
 	}
47 47
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
48 48
 	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
49
-    }
49
+	}
50 50
 }
51 51
 
52 52
 $options = getopt('s::',array('source::','server','idsource::'));
53 53
 //if (isset($options['s'])) $hosts = array($options['s']);
54 54
 //elseif (isset($options['source'])) $hosts = array($options['source']);
55 55
 if (isset($options['s'])) {
56
-    $globalSources = array();
57
-    $globalSources[] = array('host' => $options['s']);
56
+	$globalSources = array();
57
+	$globalSources[] = array('host' => $options['s']);
58 58
 } elseif (isset($options['source'])) {
59
-    $globalSources = array();
60
-    $globalSources[] = array('host' => $options['source']);
59
+	$globalSources = array();
60
+	$globalSources[] = array('host' => $options['source']);
61 61
 }
62 62
 if (isset($options['server'])) $globalServer = TRUE;
63 63
 if (isset($options['idsource'])) $id_source = $options['idsource'];
64 64
 else $id_source = 1;
65 65
 if (isset($globalServer) && $globalServer) {
66
-    if ($globalDebug) echo "Using Server Mode\n";
67
-    $SI=new SpotterServer();
66
+	if ($globalDebug) echo "Using Server Mode\n";
67
+	$SI=new SpotterServer();
68 68
 } else $SI=new SpotterImport($Connection->db);
69 69
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
70 70
 if (isset($globalMarine) && $globalMarine) {
71
-    $AIS = new AIS();
72
-    $MI = new MarineImport($Connection->db);
71
+	$AIS = new AIS();
72
+	$MI = new MarineImport($Connection->db);
73 73
 }
74 74
 //$APRS=new APRS($Connection->db);
75 75
 $SBS=new SBS();
@@ -79,12 +79,12 @@  discard block
 block discarded – undo
79 79
 //$servertz = system('date +%Z');
80 80
 // signal handler - playing nice with sockets and dump1090
81 81
 if (function_exists('pcntl_fork')) {
82
-    pcntl_signal(SIGINT,  function() {
83
-        global $sockets;
84
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
85
-        die("Bye!\n");
86
-    });
87
-    pcntl_signal_dispatch();
82
+	pcntl_signal(SIGINT,  function() {
83
+		global $sockets;
84
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
85
+		die("Bye!\n");
86
+	});
87
+	pcntl_signal_dispatch();
88 88
 }
89 89
 
90 90
 // let's try and connect
@@ -94,169 +94,169 @@  discard block
 block discarded – undo
94 94
 $reset = 0;
95 95
 
96 96
 function create_socket($host, $port, &$errno, &$errstr) {
97
-    $ip = gethostbyname($host);
98
-    $s = socket_create(AF_INET, SOCK_STREAM, 0);
99
-    $r = @socket_connect($s, $ip, $port);
100
-    if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
101
-    if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
102
-        return $s;
103
-    }
104
-    $errno = socket_last_error($s);
105
-    $errstr = socket_strerror($errno);
106
-    socket_close($s);
107
-    return false;
97
+	$ip = gethostbyname($host);
98
+	$s = socket_create(AF_INET, SOCK_STREAM, 0);
99
+	$r = @socket_connect($s, $ip, $port);
100
+	if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
101
+	if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
102
+		return $s;
103
+	}
104
+	$errno = socket_last_error($s);
105
+	$errstr = socket_strerror($errno);
106
+	socket_close($s);
107
+	return false;
108 108
 }
109 109
 
110 110
 function create_socket_udp($host, $port, &$errno, &$errstr) {
111
-    echo "Create an UDP socket...\n";
112
-    $ip = gethostbyname($host);
113
-    $s = socket_create(AF_INET, SOCK_DGRAM, 0);
114
-    $r = @socket_bind($s, $ip, $port);
115
-    if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
116
-        return $s;
117
-    }
118
-    $errno = socket_last_error($s);
119
-    $errstr = socket_strerror($errno);
120
-    socket_close($s);
121
-    return false;
111
+	echo "Create an UDP socket...\n";
112
+	$ip = gethostbyname($host);
113
+	$s = socket_create(AF_INET, SOCK_DGRAM, 0);
114
+	$r = @socket_bind($s, $ip, $port);
115
+	if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
116
+		return $s;
117
+	}
118
+	$errno = socket_last_error($s);
119
+	$errstr = socket_strerror($errno);
120
+	socket_close($s);
121
+	return false;
122 122
 }
123 123
 
124 124
 function connect_all($hosts) {
125
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
126
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
127
-    $reset++;
128
-    if ($globalDebug) echo 'Connect to all...'."\n";
129
-    foreach ($hosts as $id => $value) {
125
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
126
+	global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
127
+	$reset++;
128
+	if ($globalDebug) echo 'Connect to all...'."\n";
129
+	foreach ($hosts as $id => $value) {
130 130
 	$host = $value['host'];
131 131
 	$globalSources[$id]['last_exec'] = 0;
132 132
 	// Here we check type of source(s)
133 133
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
134
-            if (preg_match('/deltadb.txt$/i',$host)) {
135
-        	//$formats[$id] = 'deltadbtxt';
136
-        	$globalSources[$id]['format'] = 'deltadbtxt';
137
-        	//$last_exec['deltadbtxt'] = 0;
138
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
139
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
140
-        	//$formats[$id] = 'vatsimtxt';
141
-        	$globalSources[$id]['format'] = 'vatsimtxt';
142
-        	//$last_exec['vatsimtxt'] = 0;
143
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
144
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
145
-        	//$formats[$id] = 'aircraftlistjson';
146
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
147
-        	//$last_exec['aircraftlistjson'] = 0;
148
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
149
-    	    } else if (preg_match('/opensky/i',$host)) {
150
-        	//$formats[$id] = 'aircraftlistjson';
151
-        	$globalSources[$id]['format'] = 'opensky';
152
-        	//$last_exec['aircraftlistjson'] = 0;
153
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
154
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
155
-        	//$formats[$id] = 'radarvirtueljson';
156
-        	$globalSources[$id]['format'] = 'radarvirtueljson';
157
-        	//$last_exec['radarvirtueljson'] = 0;
158
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
159
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
160
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
161
-        	    exit(0);
162
-        	}
163
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
164
-        	//$formats[$id] = 'planeupdatefaa';
165
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
166
-        	//$last_exec['planeupdatefaa'] = 0;
167
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
168
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
169
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
170
-        	    exit(0);
171
-        	}
172
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
173
-        	//$formats[$id] = 'phpvmacars';
174
-        	$globalSources[$id]['format'] = 'phpvmacars';
175
-        	//$last_exec['phpvmacars'] = 0;
176
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
177
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
178
-        	//$formats[$id] = 'phpvmacars';
179
-        	$globalSources[$id]['format'] = 'vam';
180
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
181
-            } else if (preg_match('/whazzup/i',$host)) {
182
-        	//$formats[$id] = 'whazzup';
183
-        	$globalSources[$id]['format'] = 'whazzup';
184
-        	//$last_exec['whazzup'] = 0;
185
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
186
-            } else if (preg_match('/recentpireps/i',$host)) {
187
-        	//$formats[$id] = 'pirepsjson';
188
-        	$globalSources[$id]['format'] = 'pirepsjson';
189
-        	//$last_exec['pirepsjson'] = 0;
190
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
191
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
192
-        	//$formats[$id] = 'fr24json';
193
-        	$globalSources[$id]['format'] = 'fr24json';
194
-        	//$last_exec['fr24json'] = 0;
195
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
196
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
197
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
198
-        	    exit(0);
199
-        	}
200
-            //} else if (preg_match('/10001/',$host)) {
201
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
202
-        	//$formats[$id] = 'tsv';
203
-        	$globalSources[$id]['format'] = 'tsv';
204
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
205
-            }
206
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
207
-    		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
208
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
209
-    		    if ($idf !== false) {
210
-    			$httpfeeds[$id] = $idf;
211
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
212
-    		    }
213
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
214
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
215
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
216
-	    $hostport = explode(':',$host);
217
-	    if (isset($hostport[1])) {
134
+			if (preg_match('/deltadb.txt$/i',$host)) {
135
+			//$formats[$id] = 'deltadbtxt';
136
+			$globalSources[$id]['format'] = 'deltadbtxt';
137
+			//$last_exec['deltadbtxt'] = 0;
138
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
139
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
140
+			//$formats[$id] = 'vatsimtxt';
141
+			$globalSources[$id]['format'] = 'vatsimtxt';
142
+			//$last_exec['vatsimtxt'] = 0;
143
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
144
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
145
+			//$formats[$id] = 'aircraftlistjson';
146
+			$globalSources[$id]['format'] = 'aircraftlistjson';
147
+			//$last_exec['aircraftlistjson'] = 0;
148
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
149
+			} else if (preg_match('/opensky/i',$host)) {
150
+			//$formats[$id] = 'aircraftlistjson';
151
+			$globalSources[$id]['format'] = 'opensky';
152
+			//$last_exec['aircraftlistjson'] = 0;
153
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
154
+			} else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
155
+			//$formats[$id] = 'radarvirtueljson';
156
+			$globalSources[$id]['format'] = 'radarvirtueljson';
157
+			//$last_exec['radarvirtueljson'] = 0;
158
+			if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
159
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
160
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
161
+				exit(0);
162
+			}
163
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
164
+			//$formats[$id] = 'planeupdatefaa';
165
+			$globalSources[$id]['format'] = 'planeupdatefaa';
166
+			//$last_exec['planeupdatefaa'] = 0;
167
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
168
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
169
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
170
+				exit(0);
171
+			}
172
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
173
+			//$formats[$id] = 'phpvmacars';
174
+			$globalSources[$id]['format'] = 'phpvmacars';
175
+			//$last_exec['phpvmacars'] = 0;
176
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
177
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
178
+			//$formats[$id] = 'phpvmacars';
179
+			$globalSources[$id]['format'] = 'vam';
180
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
181
+			} else if (preg_match('/whazzup/i',$host)) {
182
+			//$formats[$id] = 'whazzup';
183
+			$globalSources[$id]['format'] = 'whazzup';
184
+			//$last_exec['whazzup'] = 0;
185
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
186
+			} else if (preg_match('/recentpireps/i',$host)) {
187
+			//$formats[$id] = 'pirepsjson';
188
+			$globalSources[$id]['format'] = 'pirepsjson';
189
+			//$last_exec['pirepsjson'] = 0;
190
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
191
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
192
+			//$formats[$id] = 'fr24json';
193
+			$globalSources[$id]['format'] = 'fr24json';
194
+			//$last_exec['fr24json'] = 0;
195
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
196
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
197
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
198
+				exit(0);
199
+			}
200
+			//} else if (preg_match('/10001/',$host)) {
201
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
202
+			//$formats[$id] = 'tsv';
203
+			$globalSources[$id]['format'] = 'tsv';
204
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
205
+			}
206
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
207
+			if ($globalSources[$id]['format'] == 'aisnmeahttp') {
208
+				$idf = fopen($globalSources[$id]['host'],'r',false,$context);
209
+				if ($idf !== false) {
210
+				$httpfeeds[$id] = $idf;
211
+				if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
212
+				}
213
+				elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
214
+			} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
215
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
216
+		$hostport = explode(':',$host);
217
+		if (isset($hostport[1])) {
218 218
 		$port = $hostport[1];
219 219
 		$hostn = $hostport[0];
220
-	    } else {
220
+		} else {
221 221
 		$port = $globalSources[$id]['port'];
222 222
 		$hostn = $globalSources[$id]['host'];
223
-	    }
224
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
225
-        	$s = create_socket($hostn,$port, $errno, $errstr);
226
-    	    } else {
227
-        	$s = create_socket_udp($hostn,$port, $errno, $errstr);
228
-	    }
229
-	    if ($s) {
230
-    	        $sockets[$id] = $s;
231
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
232
-		    if (preg_match('/aprs/',$hostn)) {
223
+		}
224
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
225
+			$s = create_socket($hostn,$port, $errno, $errstr);
226
+			} else {
227
+			$s = create_socket_udp($hostn,$port, $errno, $errstr);
228
+		}
229
+		if ($s) {
230
+				$sockets[$id] = $s;
231
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
232
+			if (preg_match('/aprs/',$hostn)) {
233 233
 			//$formats[$id] = 'aprs';
234 234
 			$globalSources[$id]['format'] = 'aprs';
235 235
 			//$aprs_connect = 0;
236 236
 			//$use_aprs = true;
237
-    		    } elseif ($port == '10001') {
238
-        		//$formats[$id] = 'tsv';
239
-        		$globalSources[$id]['format'] = 'tsv';
240
-		    } elseif ($port == '30002') {
241
-        		//$formats[$id] = 'raw';
242
-        		$globalSources[$id]['format'] = 'raw';
243
-		    } elseif ($port == '5001') {
244
-        		//$formats[$id] = 'raw';
245
-        		$globalSources[$id]['format'] = 'flightgearmp';
246
-		    } elseif ($port == '30005') {
237
+				} elseif ($port == '10001') {
238
+				//$formats[$id] = 'tsv';
239
+				$globalSources[$id]['format'] = 'tsv';
240
+			} elseif ($port == '30002') {
241
+				//$formats[$id] = 'raw';
242
+				$globalSources[$id]['format'] = 'raw';
243
+			} elseif ($port == '5001') {
244
+				//$formats[$id] = 'raw';
245
+				$globalSources[$id]['format'] = 'flightgearmp';
246
+			} elseif ($port == '30005') {
247 247
 			// Not yet supported
248
-        		//$formats[$id] = 'beast';
249
-        		$globalSources[$id]['format'] = 'beast';
250
-		    //} else $formats[$id] = 'sbs';
251
-		    } else $globalSources[$id]['format'] = 'sbs';
252
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
248
+				//$formats[$id] = 'beast';
249
+				$globalSources[$id]['format'] = 'beast';
250
+			//} else $formats[$id] = 'sbs';
251
+			} else $globalSources[$id]['format'] = 'sbs';
252
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
253 253
 		}
254 254
 		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
255
-            } else {
255
+			} else {
256 256
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
257
-    	    }
258
-        }
259
-    }
257
+			}
258
+		}
259
+	}
260 260
 }
261 261
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
262 262
 
@@ -279,9 +279,9 @@  discard block
 block discarded – undo
279 279
 //connect_all($globalSources);
280 280
 
281 281
 if (isset($globalProxy) && $globalProxy) {
282
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
282
+	$context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
283 283
 } else {
284
-    $context = stream_context_create(array('http' => array('timeout' => $timeout)));
284
+	$context = stream_context_create(array('http' => array('timeout' => $timeout)));
285 285
 }
286 286
 
287 287
 // APRS Configuration
@@ -290,18 +290,18 @@  discard block
 block discarded – undo
290 290
 	die;
291 291
 }
292 292
 foreach ($globalSources as $key => $source) {
293
-    if (!isset($source['format'])) {
294
-        $globalSources[$key]['format'] = 'auto';
295
-    }
293
+	if (!isset($source['format'])) {
294
+		$globalSources[$key]['format'] = 'auto';
295
+	}
296 296
 }
297 297
 connect_all($globalSources);
298 298
 foreach ($globalSources as $key => $source) {
299
-    if (isset($source['format']) && $source['format'] == 'aprs') {
299
+	if (isset($source['format']) && $source['format'] == 'aprs') {
300 300
 	$aprs_connect = 0;
301 301
 	$use_aprs = true;
302 302
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
303 303
 	break;
304
-    }
304
+	}
305 305
 }
306 306
 
307 307
 if ($use_aprs) {
@@ -340,190 +340,190 @@  discard block
 block discarded – undo
340 340
 
341 341
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
342 342
 while ($i > 0) {
343
-    if (!$globalDaemon) $i = $endtime-time();
344
-    // Delete old ATC
345
-    if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
343
+	if (!$globalDaemon) $i = $endtime-time();
344
+	// Delete old ATC
345
+	if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
346 346
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
347
-        $ATC->deleteOldATC();
348
-    }
347
+		$ATC->deleteOldATC();
348
+	}
349 349
     
350
-    //if (count($last_exec) > 0) {
351
-    if (count($last_exec) == count($globalSources)) {
350
+	//if (count($last_exec) > 0) {
351
+	if (count($last_exec) == count($globalSources)) {
352 352
 	$max = $globalMinFetch;
353 353
 	foreach ($last_exec as $last) {
354
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
354
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
355 355
 	}
356 356
 	if ($max != $globalMinFetch) {
357
-	    if ($globalDebug) echo 'Sleeping...'."\n";
358
-	    sleep($globalMinFetch-$max+2);
357
+		if ($globalDebug) echo 'Sleeping...'."\n";
358
+		sleep($globalMinFetch-$max+2);
359
+	}
359 360
 	}
360
-    }
361 361
 
362 362
     
363
-    //foreach ($formats as $id => $value) {
364
-    foreach ($globalSources as $id => $value) {
363
+	//foreach ($formats as $id => $value) {
364
+	foreach ($globalSources as $id => $value) {
365 365
 	date_default_timezone_set('UTC');
366 366
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
367 367
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
368
-	    //$buffer = $Common->getData($hosts[$id]);
369
-	    $buffer = $Common->getData($value['host']);
370
-	    if ($buffer != '') $reset = 0;
371
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
372
-	    $buffer = explode('\n',$buffer);
373
-	    foreach ($buffer as $line) {
374
-    		if ($line != '' && count($line) > 7) {
375
-    		    $line = explode(',', $line);
376
-	            $data = array();
377
-	            $data['hex'] = $line[1]; // hex
378
-	            $data['ident'] = $line[2]; // ident
379
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
380
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
381
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
382
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
383
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
384
-	            $data['verticalrate'] = ''; // vertical rate
385
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
386
-	            $data['emergency'] = ''; // emergency
387
-		    $data['datetime'] = date('Y-m-d H:i:s');
388
-		    $data['format_source'] = 'deltadbtxt';
389
-    		    $data['id_source'] = $id_source;
390
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
391
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
392
-    		    $SI->add($data);
393
-		    unset($data);
394
-    		}
395
-    	    }
396
-    	    $last_exec[$id]['last'] = time();
368
+		//$buffer = $Common->getData($hosts[$id]);
369
+		$buffer = $Common->getData($value['host']);
370
+		if ($buffer != '') $reset = 0;
371
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
372
+		$buffer = explode('\n',$buffer);
373
+		foreach ($buffer as $line) {
374
+			if ($line != '' && count($line) > 7) {
375
+				$line = explode(',', $line);
376
+				$data = array();
377
+				$data['hex'] = $line[1]; // hex
378
+				$data['ident'] = $line[2]; // ident
379
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
380
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
381
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
382
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
383
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
384
+				$data['verticalrate'] = ''; // vertical rate
385
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
386
+				$data['emergency'] = ''; // emergency
387
+			$data['datetime'] = date('Y-m-d H:i:s');
388
+			$data['format_source'] = 'deltadbtxt';
389
+				$data['id_source'] = $id_source;
390
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
391
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
392
+				$SI->add($data);
393
+			unset($data);
394
+			}
395
+			}
396
+			$last_exec[$id]['last'] = time();
397 397
 	} elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
398
-	    date_default_timezone_set('CET');
399
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
400
-	    date_default_timezone_set('UTC');
401
-	    if ($buffer != '') $reset = 0;
402
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
403
-	    $buffer = explode('\n',$buffer);
404
-	    foreach ($buffer as $line) {
398
+		date_default_timezone_set('CET');
399
+		$buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
400
+		date_default_timezone_set('UTC');
401
+		if ($buffer != '') $reset = 0;
402
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
403
+		$buffer = explode('\n',$buffer);
404
+		foreach ($buffer as $line) {
405 405
 		if ($line != '') {
406
-		    echo "'".$line."'\n";
407
-		    $add = false;
408
-		    $ais_data = $AIS->parse_line(trim($line));
409
-		    $data = array();
410
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
411
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
412
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
413
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
414
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
415
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
416
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
417
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
418
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
419
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
420
-		    if (isset($ais_data['timestamp'])) {
406
+			echo "'".$line."'\n";
407
+			$add = false;
408
+			$ais_data = $AIS->parse_line(trim($line));
409
+			$data = array();
410
+			if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
411
+			if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
412
+			if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
413
+			if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
414
+			if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
415
+			if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
416
+			if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
417
+			if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
418
+			if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
419
+			if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
420
+			if (isset($ais_data['timestamp'])) {
421 421
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
422 422
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
423
-			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
424
-			    $add = true;
423
+				$last_exec[$id]['timestamp'] = $ais_data['timestamp'];
424
+				$add = true;
425 425
 			}
426
-		    } else {
426
+			} else {
427 427
 			$data['datetime'] = date('Y-m-d H:i:s');
428 428
 			$add = true;
429
-		    }
430
-		    $data['format_source'] = 'aisnmeatxt';
431
-    		    $data['id_source'] = $id_source;
432
-		    print_r($data);
433
-		    echo 'Add...'."\n";
434
-		    if ($add && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
435
-		    unset($data);
429
+			}
430
+			$data['format_source'] = 'aisnmeatxt';
431
+				$data['id_source'] = $id_source;
432
+			print_r($data);
433
+			echo 'Add...'."\n";
434
+			if ($add && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
435
+			unset($data);
436 436
 		}
437
-    	    }
438
-    	    $last_exec[$id]['last'] = time();
437
+			}
438
+			$last_exec[$id]['last'] = time();
439 439
 	} elseif ($value['format'] == 'aisnmeahttp') {
440
-	    $arr = $httpfeeds;
441
-	    $w = $e = null;
440
+		$arr = $httpfeeds;
441
+		$w = $e = null;
442 442
 	    
443
-	    if (isset($arr[$id])) {
444
-	    $nn = stream_select($arr,$w,$e,$timeout);
445
-	    if ($nn > 0) {
443
+		if (isset($arr[$id])) {
444
+		$nn = stream_select($arr,$w,$e,$timeout);
445
+		if ($nn > 0) {
446 446
 		foreach ($httpfeeds as $feed) {
447
-		    $buffer = stream_get_line($feed,2000,"\n");
448
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
449
-		    $buffer = explode('\n',$buffer);
450
-		    foreach ($buffer as $line) {
447
+			$buffer = stream_get_line($feed,2000,"\n");
448
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
449
+			$buffer = explode('\n',$buffer);
450
+			foreach ($buffer as $line) {
451 451
 			if ($line != '') {
452
-			    $ais_data = $AIS->parse_line(trim($line));
453
-			    $data = array();
454
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
455
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
456
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
457
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
458
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
459
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
460
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
461
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
462
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
463
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
464
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
465
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
466
-			    if (isset($ais_data['timestamp'])) {
452
+				$ais_data = $AIS->parse_line(trim($line));
453
+				$data = array();
454
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
455
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
456
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
457
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
458
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
459
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
460
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
461
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
462
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
463
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
464
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
465
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
466
+				if (isset($ais_data['timestamp'])) {
467 467
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
468
-			    } else {
468
+				} else {
469 469
 				$data['datetime'] = date('Y-m-d H:i:s');
470
-			    }
471
-			    $data['format_source'] = 'aisnmeahttp';
472
-			    $data['id_source'] = $id_source;
473
-			    if ($ais_data['mmsi_type'] == 'Ship') $MI->add($data);
474
-			    unset($data);
470
+				}
471
+				$data['format_source'] = 'aisnmeahttp';
472
+				$data['id_source'] = $id_source;
473
+				if ($ais_data['mmsi_type'] == 'Ship') $MI->add($data);
474
+				unset($data);
475 475
 			}
476
-		    }
476
+			}
477
+		}
477 478
 		}
478 479
 		}
479
-	    }
480 480
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
481
-	    echo 'download...';
482
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
483
-	    echo 'done !'."\n";
484
-	    if ($buffer != '') $reset = 0;
485
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
486
-	    $buffer = explode('\n',$buffer);
487
-	    foreach ($buffer as $line) {
481
+		echo 'download...';
482
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
483
+		echo 'done !'."\n";
484
+		if ($buffer != '') $reset = 0;
485
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
486
+		$buffer = explode('\n',$buffer);
487
+		foreach ($buffer as $line) {
488 488
 		if ($line != '') {
489
-		    $data = array();
490
-		    $data['mmsi'] = (int)substr($line,0,9);
491
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
492
-		    //$data['status'] = substr($line,21,2);
493
-		    //$data['type'] = substr($line,24,3);
494
-		    $data['latitude'] = substr($line,29,9);
495
-		    $data['longitude'] = substr($line,41,9);
496
-		    $data['speed'] = round(substr($line,51,5));
497
-		    //$data['course'] = substr($line,57,5);
498
-		    $data['heading'] = round(substr($line,63,3));
499
-		    //$data['draft'] = substr($line,67,4);
500
-		    //$data['length'] = substr($line,72,3);
501
-		    //$data['beam'] = substr($line,76,2);
502
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
503
-		    //$data['callsign'] = trim(substr($line,100,7);
504
-		    //$data['dest'] = substr($line,108,20);
505
-		    //$data['etaDate'] = substr($line,129,5);
506
-		    //$data['etaTime'] = substr($line,135,5);
507
-		    $data['format_source'] = 'shipplotter';
508
-    		    $data['id_source'] = $id_source;
509
-		    print_r($data);
510
-		    echo 'Add...'."\n";
511
-		    $MI->add($data);
512
-		    unset($data);
489
+			$data = array();
490
+			$data['mmsi'] = (int)substr($line,0,9);
491
+			$data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
492
+			//$data['status'] = substr($line,21,2);
493
+			//$data['type'] = substr($line,24,3);
494
+			$data['latitude'] = substr($line,29,9);
495
+			$data['longitude'] = substr($line,41,9);
496
+			$data['speed'] = round(substr($line,51,5));
497
+			//$data['course'] = substr($line,57,5);
498
+			$data['heading'] = round(substr($line,63,3));
499
+			//$data['draft'] = substr($line,67,4);
500
+			//$data['length'] = substr($line,72,3);
501
+			//$data['beam'] = substr($line,76,2);
502
+			$data['ident'] = trim(utf8_encode(substr($line,79,20)));
503
+			//$data['callsign'] = trim(substr($line,100,7);
504
+			//$data['dest'] = substr($line,108,20);
505
+			//$data['etaDate'] = substr($line,129,5);
506
+			//$data['etaTime'] = substr($line,135,5);
507
+			$data['format_source'] = 'shipplotter';
508
+				$data['id_source'] = $id_source;
509
+			print_r($data);
510
+			echo 'Add...'."\n";
511
+			$MI->add($data);
512
+			unset($data);
513 513
 		}
514
-    	    }
515
-    	    $last_exec[$id]['last'] = time();
514
+			}
515
+			$last_exec[$id]['last'] = time();
516 516
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
517 517
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
518
-	    //$buffer = $Common->getData($hosts[$id]);
519
-	    $buffer = $Common->getData($value['host']);
520
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
521
-	    $buffer = explode('\n',$buffer);
522
-	    $reset = 0;
523
-	    foreach ($buffer as $line) {
524
-    		if ($line != '') {
525
-    		    $line = explode(':', $line);
526
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
518
+		//$buffer = $Common->getData($hosts[$id]);
519
+		$buffer = $Common->getData($value['host']);
520
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
521
+		$buffer = explode('\n',$buffer);
522
+		$reset = 0;
523
+		foreach ($buffer as $line) {
524
+			if ($line != '') {
525
+				$line = explode(':', $line);
526
+				if (count($line) > 30 && $line[0] != 'callsign') {
527 527
 			$data = array();
528 528
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
529 529
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -536,36 +536,36 @@  discard block
 block discarded – undo
536 536
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
537 537
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
538 538
 			$data['latitude'] = $line[5]; // lat
539
-	        	$data['longitude'] = $line[6]; // long
540
-	        	$data['verticalrate'] = ''; // vertical rate
541
-	        	$data['squawk'] = ''; // squawk
542
-	        	$data['emergency'] = ''; // emergency
543
-	        	$data['waypoints'] = $line[30];
539
+				$data['longitude'] = $line[6]; // long
540
+				$data['verticalrate'] = ''; // vertical rate
541
+				$data['squawk'] = ''; // squawk
542
+				$data['emergency'] = ''; // emergency
543
+				$data['waypoints'] = $line[30];
544 544
 			$data['datetime'] = date('Y-m-d H:i:s');
545 545
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
546 546
 			//if (isset($line[37])) $data['last_update'] = $line[37];
547
-		        $data['departure_airport_icao'] = $line[11];
548
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
549
-		        $data['arrival_airport_icao'] = $line[13];
547
+				$data['departure_airport_icao'] = $line[11];
548
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
549
+				$data['arrival_airport_icao'] = $line[13];
550 550
 			$data['frequency'] = $line[4];
551 551
 			$data['type'] = $line[18];
552 552
 			$data['range'] = $line[19];
553 553
 			if (isset($line[35])) $data['info'] = $line[35];
554
-    			$data['id_source'] = $id_source;
555
-	    		//$data['arrival_airport_time'] = ;
556
-	    		if ($line[9] != '') {
557
-	    		    $aircraft_data = explode('/',$line[9]);
558
-	    		    if (isset($aircraft_data[1])) {
559
-	    			$data['aircraft_icao'] = $aircraft_data[1];
560
-	    		    }
561
-        		}
562
-	    		/*
554
+				$data['id_source'] = $id_source;
555
+				//$data['arrival_airport_time'] = ;
556
+				if ($line[9] != '') {
557
+					$aircraft_data = explode('/',$line[9]);
558
+					if (isset($aircraft_data[1])) {
559
+					$data['aircraft_icao'] = $aircraft_data[1];
560
+					}
561
+				}
562
+				/*
563 563
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
564 564
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
565 565
 	    		*/
566
-	    		$data['format_source'] = $value['format'];
566
+				$data['format_source'] = $value['format'];
567 567
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
568
-    			if ($line[3] == 'PILOT') $SI->add($data);
568
+				if ($line[3] == 'PILOT') $SI->add($data);
569 569
 			elseif ($line[3] == 'ATC') {
570 570
 				//print_r($data);
571 571
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -583,247 +583,247 @@  discard block
 block discarded – undo
583 583
 				if (!isset($data['source_name'])) $data['source_name'] = '';
584 584
 				if (isset($ATC)) echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
585 585
 			}
586
-    			unset($data);
587
-    		    }
588
-    		}
589
-    	    }
590
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
591
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
592
-    	    $last_exec[$id]['last'] = time();
593
-    	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
594
-    	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
595
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
596
-	    if ($buffer != '') {
597
-	    $all_data = json_decode($buffer,true);
598
-	    if (isset($all_data['acList'])) {
586
+				unset($data);
587
+				}
588
+			}
589
+			}
590
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
591
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
592
+			$last_exec[$id]['last'] = time();
593
+		//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
594
+		} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
595
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
596
+		if ($buffer != '') {
597
+		$all_data = json_decode($buffer,true);
598
+		if (isset($all_data['acList'])) {
599 599
 		$reset = 0;
600 600
 		foreach ($all_data['acList'] as $line) {
601
-		    $data = array();
602
-		    $data['hex'] = $line['Icao']; // hex
603
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
604
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
605
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
606
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
607
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
608
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
609
-		    //$data['verticalrate'] = $line['']; // verticale rate
610
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
611
-		    $data['emergency'] = ''; // emergency
612
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
613
-		    /*
601
+			$data = array();
602
+			$data['hex'] = $line['Icao']; // hex
603
+			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
604
+			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
605
+			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
606
+			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
607
+			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
608
+			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
609
+			//$data['verticalrate'] = $line['']; // verticale rate
610
+			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
611
+			$data['emergency'] = ''; // emergency
612
+			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
613
+			/*
614 614
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
615 615
 		    else $data['datetime'] = date('Y-m-d H:i:s');
616 616
 		    */
617
-		    $data['datetime'] = date('Y-m-d H:i:s');
618
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
619
-	    	    $data['format_source'] = 'aircraftlistjson';
620
-		    $data['id_source'] = $id_source;
621
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
622
-		    if (isset($data['datetime'])) $SI->add($data);
623
-		    unset($data);
617
+			$data['datetime'] = date('Y-m-d H:i:s');
618
+			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
619
+				$data['format_source'] = 'aircraftlistjson';
620
+			$data['id_source'] = $id_source;
621
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
622
+			if (isset($data['datetime'])) $SI->add($data);
623
+			unset($data);
624 624
 		}
625
-	    } else {
625
+		} else {
626 626
 		$reset = 0;
627 627
 		foreach ($all_data as $line) {
628
-		    $data = array();
629
-		    $data['hex'] = $line['hex']; // hex
630
-		    $data['ident'] = $line['flight']; // ident
631
-		    $data['altitude'] = $line['altitude']; // altitude
632
-		    $data['speed'] = $line['speed']; // speed
633
-		    $data['heading'] = $line['track']; // heading
634
-		    $data['latitude'] = $line['lat']; // lat
635
-		    $data['longitude'] = $line['lon']; // long
636
-		    $data['verticalrate'] = $line['vrt']; // verticale rate
637
-		    $data['squawk'] = $line['squawk']; // squawk
638
-		    $data['emergency'] = ''; // emergency
639
-		    $data['datetime'] = date('Y-m-d H:i:s');
640
-	    	    $data['format_source'] = 'aircraftlistjson';
641
-    		    $data['id_source'] = $id_source;
642
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
643
-		    $SI->add($data);
644
-		    unset($data);
628
+			$data = array();
629
+			$data['hex'] = $line['hex']; // hex
630
+			$data['ident'] = $line['flight']; // ident
631
+			$data['altitude'] = $line['altitude']; // altitude
632
+			$data['speed'] = $line['speed']; // speed
633
+			$data['heading'] = $line['track']; // heading
634
+			$data['latitude'] = $line['lat']; // lat
635
+			$data['longitude'] = $line['lon']; // long
636
+			$data['verticalrate'] = $line['vrt']; // verticale rate
637
+			$data['squawk'] = $line['squawk']; // squawk
638
+			$data['emergency'] = ''; // emergency
639
+			$data['datetime'] = date('Y-m-d H:i:s');
640
+				$data['format_source'] = 'aircraftlistjson';
641
+				$data['id_source'] = $id_source;
642
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
643
+			$SI->add($data);
644
+			unset($data);
645
+		}
645 646
 		}
646
-	    }
647
-	    }
648
-    	    //$last_exec['aircraftlistjson'] = time();
649
-    	    $last_exec[$id]['last'] = time();
650
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
651
-    	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
652
-	    $buffer = $Common->getData($value['host']);
653
-	    $all_data = json_decode($buffer,true);
654
-	    if (isset($all_data['planes'])) {
647
+		}
648
+			//$last_exec['aircraftlistjson'] = time();
649
+			$last_exec[$id]['last'] = time();
650
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
651
+		} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
652
+		$buffer = $Common->getData($value['host']);
653
+		$all_data = json_decode($buffer,true);
654
+		if (isset($all_data['planes'])) {
655 655
 		$reset = 0;
656 656
 		foreach ($all_data['planes'] as $key => $line) {
657
-		    $data = array();
658
-		    $data['hex'] = $key; // hex
659
-		    $data['ident'] = $line[3]; // ident
660
-		    $data['altitude'] = $line[6]; // altitude
661
-		    $data['speed'] = $line[8]; // speed
662
-		    $data['heading'] = $line[7]; // heading
663
-		    $data['latitude'] = $line[4]; // lat
664
-		    $data['longitude'] = $line[5]; // long
665
-		    //$data['verticalrate'] = $line[]; // verticale rate
666
-		    $data['squawk'] = $line[10]; // squawk
667
-		    $data['emergency'] = ''; // emergency
668
-		    $data['registration'] = $line[2];
669
-		    $data['aircraft_icao'] = $line[0];
670
-		    $deparr = explode('-',$line[1]);
671
-		    if (count($deparr) == 2) {
657
+			$data = array();
658
+			$data['hex'] = $key; // hex
659
+			$data['ident'] = $line[3]; // ident
660
+			$data['altitude'] = $line[6]; // altitude
661
+			$data['speed'] = $line[8]; // speed
662
+			$data['heading'] = $line[7]; // heading
663
+			$data['latitude'] = $line[4]; // lat
664
+			$data['longitude'] = $line[5]; // long
665
+			//$data['verticalrate'] = $line[]; // verticale rate
666
+			$data['squawk'] = $line[10]; // squawk
667
+			$data['emergency'] = ''; // emergency
668
+			$data['registration'] = $line[2];
669
+			$data['aircraft_icao'] = $line[0];
670
+			$deparr = explode('-',$line[1]);
671
+			if (count($deparr) == 2) {
672 672
 			$data['departure_airport_icao'] = $deparr[0];
673 673
 			$data['arrival_airport_icao'] = $deparr[1];
674
-		    }
675
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
676
-	    	    $data['format_source'] = 'planeupdatefaa';
677
-    		    $data['id_source'] = $id_source;
678
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
679
-		    $SI->add($data);
680
-		    unset($data);
674
+			}
675
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
676
+				$data['format_source'] = 'planeupdatefaa';
677
+				$data['id_source'] = $id_source;
678
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
679
+			$SI->add($data);
680
+			unset($data);
681 681
 		}
682
-	    }
683
-    	    //$last_exec['planeupdatefaa'] = time();
684
-    	    $last_exec[$id]['last'] = time();
685
-    	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
686
-	    $buffer = $Common->getData($value['host']);
687
-	    $all_data = json_decode($buffer,true);
688
-	    if (isset($all_data['states'])) {
682
+		}
683
+			//$last_exec['planeupdatefaa'] = time();
684
+			$last_exec[$id]['last'] = time();
685
+		} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
686
+		$buffer = $Common->getData($value['host']);
687
+		$all_data = json_decode($buffer,true);
688
+		if (isset($all_data['states'])) {
689 689
 		$reset = 0;
690 690
 		foreach ($all_data['states'] as $key => $line) {
691
-		    $data = array();
692
-		    $data['hex'] = $line[0]; // hex
693
-		    $data['ident'] = trim($line[1]); // ident
694
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
695
-		    $data['speed'] = round($line[9]*1.94384); // speed
696
-		    $data['heading'] = round($line[10]); // heading
697
-		    $data['latitude'] = $line[5]; // lat
698
-		    $data['longitude'] = $line[6]; // long
699
-		    $data['verticalrate'] = $line[11]; // verticale rate
700
-		    //$data['squawk'] = $line[10]; // squawk
701
-		    //$data['emergency'] = ''; // emergency
702
-		    //$data['registration'] = $line[2];
703
-		    //$data['aircraft_icao'] = $line[0];
704
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
705
-	    	    $data['format_source'] = 'opensky';
706
-    		    $data['id_source'] = $id_source;
707
-		    $SI->add($data);
708
-		    unset($data);
691
+			$data = array();
692
+			$data['hex'] = $line[0]; // hex
693
+			$data['ident'] = trim($line[1]); // ident
694
+			$data['altitude'] = round($line[7]*3.28084); // altitude
695
+			$data['speed'] = round($line[9]*1.94384); // speed
696
+			$data['heading'] = round($line[10]); // heading
697
+			$data['latitude'] = $line[5]; // lat
698
+			$data['longitude'] = $line[6]; // long
699
+			$data['verticalrate'] = $line[11]; // verticale rate
700
+			//$data['squawk'] = $line[10]; // squawk
701
+			//$data['emergency'] = ''; // emergency
702
+			//$data['registration'] = $line[2];
703
+			//$data['aircraft_icao'] = $line[0];
704
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
705
+				$data['format_source'] = 'opensky';
706
+				$data['id_source'] = $id_source;
707
+			$SI->add($data);
708
+			unset($data);
709
+		}
709 710
 		}
710
-	    }
711
-    	    //$last_exec['planeupdatefaa'] = time();
712
-    	    $last_exec[$id]['last'] = time();
713
-    	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
714
-    	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
715
-	    //$buffer = $Common->getData($hosts[$id]);
716
-	    $buffer = $Common->getData($value['host']);
717
-	    $all_data = json_decode($buffer,true);
718
-	    if (!empty($all_data)) $reset = 0;
719
-	    foreach ($all_data as $key => $line) {
711
+			//$last_exec['planeupdatefaa'] = time();
712
+			$last_exec[$id]['last'] = time();
713
+		//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
714
+		} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
715
+		//$buffer = $Common->getData($hosts[$id]);
716
+		$buffer = $Common->getData($value['host']);
717
+		$all_data = json_decode($buffer,true);
718
+		if (!empty($all_data)) $reset = 0;
719
+		foreach ($all_data as $key => $line) {
720 720
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
721
-		    $data = array();
722
-		    $data['hex'] = $line[0];
723
-		    $data['ident'] = $line[16]; //$line[13]
724
-	    	    $data['altitude'] = $line[4]; // altitude
725
-	    	    $data['speed'] = $line[5]; // speed
726
-	    	    $data['heading'] = $line[3]; // heading
727
-	    	    $data['latitude'] = $line[1]; // lat
728
-	    	    $data['longitude'] = $line[2]; // long
729
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
730
-	    	    $data['squawk'] = $line[6]; // squawk
731
-	    	    $data['aircraft_icao'] = $line[8];
732
-	    	    $data['registration'] = $line[9];
733
-		    $data['departure_airport_iata'] = $line[11];
734
-		    $data['arrival_airport_iata'] = $line[12];
735
-	    	    $data['emergency'] = ''; // emergency
736
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
737
-	    	    $data['format_source'] = 'fr24json';
738
-    		    $data['id_source'] = $id_source;
739
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
740
-		    $SI->add($data);
741
-		    unset($data);
721
+			$data = array();
722
+			$data['hex'] = $line[0];
723
+			$data['ident'] = $line[16]; //$line[13]
724
+				$data['altitude'] = $line[4]; // altitude
725
+				$data['speed'] = $line[5]; // speed
726
+				$data['heading'] = $line[3]; // heading
727
+				$data['latitude'] = $line[1]; // lat
728
+				$data['longitude'] = $line[2]; // long
729
+				$data['verticalrate'] = $line[15]; // verticale rate
730
+				$data['squawk'] = $line[6]; // squawk
731
+				$data['aircraft_icao'] = $line[8];
732
+				$data['registration'] = $line[9];
733
+			$data['departure_airport_iata'] = $line[11];
734
+			$data['arrival_airport_iata'] = $line[12];
735
+				$data['emergency'] = ''; // emergency
736
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
737
+				$data['format_source'] = 'fr24json';
738
+				$data['id_source'] = $id_source;
739
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
740
+			$SI->add($data);
741
+			unset($data);
742
+		}
742 743
 		}
743
-	    }
744
-    	    //$last_exec['fr24json'] = time();
745
-    	    $last_exec[$id]['last'] = time();
746
-    	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
747
-    	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
748
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
749
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
750
-	    //echo $buffer;
751
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
752
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
753
-	    $all_data = json_decode($buffer,true);
754
-	    if (json_last_error() != JSON_ERROR_NONE) {
744
+			//$last_exec['fr24json'] = time();
745
+			$last_exec[$id]['last'] = time();
746
+		//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
747
+		} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
748
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
749
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
750
+		//echo $buffer;
751
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
752
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
753
+		$all_data = json_decode($buffer,true);
754
+		if (json_last_error() != JSON_ERROR_NONE) {
755 755
 		die(json_last_error_msg());
756
-	    }
757
-	    if (isset($all_data['mrkrs'])) {
756
+		}
757
+		if (isset($all_data['mrkrs'])) {
758 758
 		$reset = 0;
759 759
 		foreach ($all_data['mrkrs'] as $key => $line) {
760
-		    if (isset($line['inf'])) {
760
+			if (isset($line['inf'])) {
761 761
 			$data = array();
762 762
 			$data['hex'] = $line['inf']['ia'];
763 763
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
764
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
765
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
766
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
767
-	    		$data['latitude'] = $line['pt'][0]; // lat
768
-	    		$data['longitude'] = $line['pt'][1]; // long
769
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
770
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
771
-	    		//$data['aircraft_icao'] = $line[8];
772
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
764
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
765
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
766
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
767
+				$data['latitude'] = $line['pt'][0]; // lat
768
+				$data['longitude'] = $line['pt'][1]; // long
769
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
770
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
771
+				//$data['aircraft_icao'] = $line[8];
772
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
773 773
 			//$data['departure_airport_iata'] = $line[11];
774 774
 			//$data['arrival_airport_iata'] = $line[12];
775
-	    		//$data['emergency'] = ''; // emergency
775
+				//$data['emergency'] = ''; // emergency
776 776
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
777
-	    		$data['format_source'] = 'radarvirtueljson';
778
-    			$data['id_source'] = $id_source;
777
+				$data['format_source'] = 'radarvirtueljson';
778
+				$data['id_source'] = $id_source;
779 779
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
780 780
 			$SI->add($data);
781 781
 			unset($data);
782
-		    }
782
+			}
783 783
 		}
784
-	    }
785
-    	    //$last_exec['radarvirtueljson'] = time();
786
-    	    $last_exec[$id]['last'] = time();
787
-    	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
788
-    	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
789
-	    //$buffer = $Common->getData($hosts[$id]);
790
-	    $buffer = $Common->getData($value['host'].'?'.time());
791
-	    $all_data = json_decode(utf8_encode($buffer),true);
784
+		}
785
+			//$last_exec['radarvirtueljson'] = time();
786
+			$last_exec[$id]['last'] = time();
787
+		//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
788
+		} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
789
+		//$buffer = $Common->getData($hosts[$id]);
790
+		$buffer = $Common->getData($value['host'].'?'.time());
791
+		$all_data = json_decode(utf8_encode($buffer),true);
792 792
 	    
793
-	    if (isset($all_data['pireps'])) {
793
+		if (isset($all_data['pireps'])) {
794 794
 		$reset = 0;
795
-	        foreach ($all_data['pireps'] as $line) {
796
-		    $data = array();
797
-		    $data['id'] = $line['id'];
798
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
799
-		    $data['ident'] = $line['callsign']; // ident
800
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
801
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
802
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
803
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
804
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
805
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
806
-		    $data['latitude'] = $line['lat']; // lat
807
-		    $data['longitude'] = $line['lon']; // long
808
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
809
-		    //$data['squawk'] = $line['squawk']; // squawk
810
-		    //$data['emergency'] = ''; // emergency
811
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
812
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
813
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
814
-		    //$data['arrival_airport_time'] = $line['arrtime'];
815
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
816
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
817
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
818
-		    else $data['info'] = '';
819
-		    $data['format_source'] = 'pireps';
820
-    		    $data['id_source'] = $id_source;
821
-		    $data['datetime'] = date('Y-m-d H:i:s');
822
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
823
-		    if ($line['icon'] == 'plane') {
795
+			foreach ($all_data['pireps'] as $line) {
796
+			$data = array();
797
+			$data['id'] = $line['id'];
798
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
799
+			$data['ident'] = $line['callsign']; // ident
800
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
801
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
802
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
803
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
804
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
805
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
806
+			$data['latitude'] = $line['lat']; // lat
807
+			$data['longitude'] = $line['lon']; // long
808
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
809
+			//$data['squawk'] = $line['squawk']; // squawk
810
+			//$data['emergency'] = ''; // emergency
811
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
812
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
813
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
814
+			//$data['arrival_airport_time'] = $line['arrtime'];
815
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
816
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
817
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
818
+			else $data['info'] = '';
819
+			$data['format_source'] = 'pireps';
820
+				$data['id_source'] = $id_source;
821
+			$data['datetime'] = date('Y-m-d H:i:s');
822
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
823
+			if ($line['icon'] == 'plane') {
824 824
 			$SI->add($data);
825
-		    //    print_r($data);
826
-    		    } elseif ($line['icon'] == 'ct') {
825
+			//    print_r($data);
826
+				} elseif ($line['icon'] == 'ct') {
827 827
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
828 828
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
829 829
 			$typec = substr($data['ident'],-3);
@@ -838,188 +838,188 @@  discard block
 block discarded – undo
838 838
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
839 839
 			else $data['type'] = 'Observer';
840 840
 			if (isset($ATC)) echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);
841
-		    }
842
-		    unset($data);
841
+			}
842
+			unset($data);
843 843
 		}
844
-	    }
845
-    	    //$last_exec['pirepsjson'] = time();
846
-    	    $last_exec[$id]['last'] = time();
847
-    	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
848
-    	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
849
-	    //$buffer = $Common->getData($hosts[$id]);
850
-	    if ($globalDebug) echo 'Get Data...'."\n";
851
-	    $buffer = $Common->getData($value['host']);
852
-	    $all_data = json_decode($buffer,true);
853
-	    if ($buffer != '' && is_array($all_data)) {
844
+		}
845
+			//$last_exec['pirepsjson'] = time();
846
+			$last_exec[$id]['last'] = time();
847
+		//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
848
+		} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
849
+		//$buffer = $Common->getData($hosts[$id]);
850
+		if ($globalDebug) echo 'Get Data...'."\n";
851
+		$buffer = $Common->getData($value['host']);
852
+		$all_data = json_decode($buffer,true);
853
+		if ($buffer != '' && is_array($all_data)) {
854 854
 		$reset = 0;
855 855
 		foreach ($all_data as $line) {
856
-	    	    $data = array();
857
-	    	    //$data['id'] = $line['id']; // id not usable
858
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
859
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
860
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
861
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
862
-	    	    $data['ident'] = $line['flightnum']; // ident
863
-	    	    $data['altitude'] = $line['alt']; // altitude
864
-	    	    $data['speed'] = $line['gs']; // speed
865
-	    	    $data['heading'] = $line['heading']; // heading
866
-	    	    $data['latitude'] = $line['lat']; // lat
867
-	    	    $data['longitude'] = $line['lng']; // long
868
-	    	    $data['verticalrate'] = ''; // verticale rate
869
-	    	    $data['squawk'] = ''; // squawk
870
-	    	    $data['emergency'] = ''; // emergency
871
-	    	    //$data['datetime'] = $line['lastupdate'];
872
-	    	    $data['last_update'] = $line['lastupdate'];
873
-		    $data['datetime'] = date('Y-m-d H:i:s');
874
-	    	    $data['departure_airport_icao'] = $line['depicao'];
875
-	    	    $data['departure_airport_time'] = $line['deptime'];
876
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
877
-    		    $data['arrival_airport_time'] = $line['arrtime'];
878
-    		    $data['registration'] = $line['aircraft'];
879
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
880
-		    if (isset($line['aircraftname'])) {
856
+				$data = array();
857
+				//$data['id'] = $line['id']; // id not usable
858
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
859
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
860
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
861
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
862
+				$data['ident'] = $line['flightnum']; // ident
863
+				$data['altitude'] = $line['alt']; // altitude
864
+				$data['speed'] = $line['gs']; // speed
865
+				$data['heading'] = $line['heading']; // heading
866
+				$data['latitude'] = $line['lat']; // lat
867
+				$data['longitude'] = $line['lng']; // long
868
+				$data['verticalrate'] = ''; // verticale rate
869
+				$data['squawk'] = ''; // squawk
870
+				$data['emergency'] = ''; // emergency
871
+				//$data['datetime'] = $line['lastupdate'];
872
+				$data['last_update'] = $line['lastupdate'];
873
+			$data['datetime'] = date('Y-m-d H:i:s');
874
+				$data['departure_airport_icao'] = $line['depicao'];
875
+				$data['departure_airport_time'] = $line['deptime'];
876
+				$data['arrival_airport_icao'] = $line['arricao'];
877
+				$data['arrival_airport_time'] = $line['arrtime'];
878
+				$data['registration'] = $line['aircraft'];
879
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
880
+			if (isset($line['aircraftname'])) {
881 881
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
882 882
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
883
-	    		$aircraft_data = explode('-',$line['aircraftname']);
884
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
885
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
886
-	    		else {
887
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
888
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
889
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
890
-	    		}
891
-	    	    }
892
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
893
-    		    $data['id_source'] = $id_source;
894
-	    	    $data['format_source'] = 'phpvmacars';
895
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
896
-		    $SI->add($data);
897
-		    unset($data);
883
+				$aircraft_data = explode('-',$line['aircraftname']);
884
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
885
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
886
+				else {
887
+					$aircraft_data = explode(' ',$line['aircraftname']);
888
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
889
+					else $data['aircraft_icao'] = $line['aircraftname'];
890
+				}
891
+				}
892
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
893
+				$data['id_source'] = $id_source;
894
+				$data['format_source'] = 'phpvmacars';
895
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
896
+			$SI->add($data);
897
+			unset($data);
898 898
 		}
899 899
 		if ($globalDebug) echo 'No more data...'."\n";
900 900
 		unset($buffer);
901 901
 		unset($all_data);
902
-	    }
903
-    	    //$last_exec['phpvmacars'] = time();
904
-    	    $last_exec[$id]['last'] = time();
905
-    	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
906
-	    //$buffer = $Common->getData($hosts[$id]);
907
-	    if ($globalDebug) echo 'Get Data...'."\n";
908
-	    $buffer = $Common->getData($value['host']);
909
-	    $all_data = json_decode($buffer,true);
910
-	    if ($buffer != '' && is_array($all_data)) {
902
+		}
903
+			//$last_exec['phpvmacars'] = time();
904
+			$last_exec[$id]['last'] = time();
905
+		} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
906
+		//$buffer = $Common->getData($hosts[$id]);
907
+		if ($globalDebug) echo 'Get Data...'."\n";
908
+		$buffer = $Common->getData($value['host']);
909
+		$all_data = json_decode($buffer,true);
910
+		if ($buffer != '' && is_array($all_data)) {
911 911
 		$reset = 0;
912 912
 		foreach ($all_data as $line) {
913
-	    	    $data = array();
914
-	    	    //$data['id'] = $line['id']; // id not usable
915
-	    	    $data['id'] = trim($line['flight_id']);
916
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
917
-	    	    $data['pilot_name'] = $line['pilot_name'];
918
-	    	    $data['pilot_id'] = $line['pilot_id'];
919
-	    	    $data['ident'] = trim($line['callsign']); // ident
920
-	    	    $data['altitude'] = $line['altitude']; // altitude
921
-	    	    $data['speed'] = $line['gs']; // speed
922
-	    	    $data['heading'] = $line['heading']; // heading
923
-	    	    $data['latitude'] = $line['latitude']; // lat
924
-	    	    $data['longitude'] = $line['longitude']; // long
925
-	    	    $data['verticalrate'] = ''; // verticale rate
926
-	    	    $data['squawk'] = ''; // squawk
927
-	    	    $data['emergency'] = ''; // emergency
928
-	    	    //$data['datetime'] = $line['lastupdate'];
929
-	    	    $data['last_update'] = $line['last_update'];
930
-		    $data['datetime'] = date('Y-m-d H:i:s');
931
-	    	    $data['departure_airport_icao'] = $line['departure'];
932
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
933
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
934
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
935
-    		    //$data['registration'] = $line['aircraft'];
936
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
937
-	    	    $data['aircraft_icao'] = $line['plane_type'];
938
-    		    $data['id_source'] = $id_source;
939
-	    	    $data['format_source'] = 'vam';
940
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
941
-		    $SI->add($data);
942
-		    unset($data);
913
+				$data = array();
914
+				//$data['id'] = $line['id']; // id not usable
915
+				$data['id'] = trim($line['flight_id']);
916
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
917
+				$data['pilot_name'] = $line['pilot_name'];
918
+				$data['pilot_id'] = $line['pilot_id'];
919
+				$data['ident'] = trim($line['callsign']); // ident
920
+				$data['altitude'] = $line['altitude']; // altitude
921
+				$data['speed'] = $line['gs']; // speed
922
+				$data['heading'] = $line['heading']; // heading
923
+				$data['latitude'] = $line['latitude']; // lat
924
+				$data['longitude'] = $line['longitude']; // long
925
+				$data['verticalrate'] = ''; // verticale rate
926
+				$data['squawk'] = ''; // squawk
927
+				$data['emergency'] = ''; // emergency
928
+				//$data['datetime'] = $line['lastupdate'];
929
+				$data['last_update'] = $line['last_update'];
930
+			$data['datetime'] = date('Y-m-d H:i:s');
931
+				$data['departure_airport_icao'] = $line['departure'];
932
+				//$data['departure_airport_time'] = $line['departure_time'];
933
+				$data['arrival_airport_icao'] = $line['arrival'];
934
+				//$data['arrival_airport_time'] = $line['arrival_time'];
935
+				//$data['registration'] = $line['aircraft'];
936
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
937
+				$data['aircraft_icao'] = $line['plane_type'];
938
+				$data['id_source'] = $id_source;
939
+				$data['format_source'] = 'vam';
940
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
941
+			$SI->add($data);
942
+			unset($data);
943 943
 		}
944 944
 		if ($globalDebug) echo 'No more data...'."\n";
945 945
 		unset($buffer);
946 946
 		unset($all_data);
947
-	    }
948
-    	    //$last_exec['phpvmacars'] = time();
949
-    	    $last_exec[$id]['last'] = time();
947
+		}
948
+			//$last_exec['phpvmacars'] = time();
949
+			$last_exec[$id]['last'] = time();
950 950
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
951 951
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais') {
952
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
953
-    	    //$last_exec[$id]['last'] = time();
952
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
953
+			//$last_exec[$id]['last'] = time();
954 954
 
955
-	    //$read = array( $sockets[$id] );
956
-	    $read = $sockets;
957
-	    $write = NULL;
958
-	    $e = NULL;
959
-	    $n = socket_select($read, $write, $e, $timeout);
960
-	    if ($e != NULL) var_dump($e);
961
-	    if ($n > 0) {
955
+		//$read = array( $sockets[$id] );
956
+		$read = $sockets;
957
+		$write = NULL;
958
+		$e = NULL;
959
+		$n = socket_select($read, $write, $e, $timeout);
960
+		if ($e != NULL) var_dump($e);
961
+		if ($n > 0) {
962 962
 		$reset = 0;
963 963
 		foreach ($read as $nb => $r) {
964
-		    //$value = $formats[$nb];
965
-		    $format = $globalSources[$nb]['format'];
966
-        	    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
967
-        		$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
968
-        	    } else {
969
-	    	        $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
970
-	    	    }
971
-        	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
972
-        	    //echo $buffer."\n";
973
-		    // lets play nice and handle signals such as ctrl-c/kill properly
974
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
975
-		    $error = false;
976
-		    //$SI::del();
977
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
978
-		    // SBS format is CSV format
979
-		    if ($buffer != '') {
964
+			//$value = $formats[$nb];
965
+			$format = $globalSources[$nb]['format'];
966
+				if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
967
+				$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
968
+				} else {
969
+					$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
970
+				}
971
+				//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
972
+				//echo $buffer."\n";
973
+			// lets play nice and handle signals such as ctrl-c/kill properly
974
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
975
+			$error = false;
976
+			//$SI::del();
977
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
978
+			// SBS format is CSV format
979
+			if ($buffer != '') {
980 980
 			$tt[$format] = 0;
981 981
 			if ($format == 'acarssbs3') {
982
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
983
-			    $ACARS->add(trim($buffer));
984
-			    $ACARS->deleteLiveAcarsData();
982
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
983
+				$ACARS->add(trim($buffer));
984
+				$ACARS->deleteLiveAcarsData();
985 985
 			} elseif ($format == 'raw') {
986
-			    // AVR format
987
-			    $data = $SBS->parse($buffer);
988
-			    if (is_array($data)) {
986
+				// AVR format
987
+				$data = $SBS->parse($buffer);
988
+				if (is_array($data)) {
989 989
 				$data['datetime'] = date('Y-m-d H:i:s');
990 990
 				$data['format_source'] = 'raw';
991 991
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
992
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
993
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
994
-                            }
995
-                        } elseif ($format == 'ais') {
996
-			    $ais_data = $AIS->parse_line(trim($buffer));
997
-			    $data = array();
998
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
999
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1000
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1001
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1002
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1003
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1004
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1005
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1006
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1007
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1008
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1009
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
992
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
993
+								if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
994
+							}
995
+						} elseif ($format == 'ais') {
996
+				$ais_data = $AIS->parse_line(trim($buffer));
997
+				$data = array();
998
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
999
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1000
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1001
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1002
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1003
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1004
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1005
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1006
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1007
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1008
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1009
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1010 1010
 
1011
-			    if (isset($ais_data['timestamp'])) {
1011
+				if (isset($ais_data['timestamp'])) {
1012 1012
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1013
-			    } else {
1013
+				} else {
1014 1014
 				$data['datetime'] = date('Y-m-d H:i:s');
1015
-			    }
1016
-			    $data['format_source'] = 'aisnmea';
1017
-    			    $data['id_source'] = $id_source;
1018
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1019
-			    unset($data);
1020
-                        } elseif ($format == 'flightgearsp') {
1021
-                    	    //echo $buffer."\n";
1022
-                    	    if (strlen($buffer) > 5) {
1015
+				}
1016
+				$data['format_source'] = 'aisnmea';
1017
+					$data['id_source'] = $id_source;
1018
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1019
+				unset($data);
1020
+						} elseif ($format == 'flightgearsp') {
1021
+							//echo $buffer."\n";
1022
+							if (strlen($buffer) > 5) {
1023 1023
 				$line = explode(',',$buffer);
1024 1024
 				$data = array();
1025 1025
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1035,120 +1035,120 @@  discard block
 block discarded – undo
1035 1035
 				$data['format_source'] = 'flightgearsp';
1036 1036
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1037 1037
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1038
-			    }
1039
-                        } elseif ($format == 'acars') {
1040
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1041
-			    $ACARS->add(trim($buffer));
1042
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1043
-			    $ACARS->deleteLiveAcarsData();
1038
+				}
1039
+						} elseif ($format == 'acars') {
1040
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1041
+				$ACARS->add(trim($buffer));
1042
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1043
+				$ACARS->deleteLiveAcarsData();
1044 1044
 			} elseif ($format == 'flightgearmp') {
1045
-			    if (substr($buffer,0,1) != '#') {
1045
+				if (substr($buffer,0,1) != '#') {
1046 1046
 				$data = array();
1047 1047
 				//echo $buffer."\n";
1048 1048
 				$line = explode(' ',$buffer);
1049 1049
 				if (count($line) == 11) {
1050
-				    $userserver = explode('@',$line[0]);
1051
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1052
-				    $data['ident'] = $userserver[0];
1053
-				    $data['registration'] = $userserver[0];
1054
-				    $data['latitude'] = $line[4];
1055
-				    $data['longitude'] = $line[5];
1056
-				    $data['altitude'] = $line[6];
1057
-				    $data['datetime'] = date('Y-m-d H:i:s');
1058
-				    $aircraft_type = $line[10];
1059
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1060
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1061
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1050
+					$userserver = explode('@',$line[0]);
1051
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1052
+					$data['ident'] = $userserver[0];
1053
+					$data['registration'] = $userserver[0];
1054
+					$data['latitude'] = $line[4];
1055
+					$data['longitude'] = $line[5];
1056
+					$data['altitude'] = $line[6];
1057
+					$data['datetime'] = date('Y-m-d H:i:s');
1058
+					$aircraft_type = $line[10];
1059
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1060
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1061
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1062
+				}
1062 1063
 				}
1063
-			    }
1064 1064
 			} elseif ($format == 'beast') {
1065
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1066
-			    die;
1065
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1066
+				die;
1067 1067
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1068
-			    $line = explode("\t", $buffer);
1069
-			    for($k = 0; $k < count($line); $k=$k+2) {
1068
+				$line = explode("\t", $buffer);
1069
+				for($k = 0; $k < count($line); $k=$k+2) {
1070 1070
 				$key = $line[$k];
1071
-			        $lined[$key] = $line[$k+1];
1072
-			    }
1073
-    			    if (count($lined) > 3) {
1074
-    				$data['hex'] = $lined['hexid'];
1075
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1076
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1077
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1078
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1079
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1080
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1081
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1082
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1083
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1084
-    				$data['id_source'] = $id_source;
1085
-    				$data['format_source'] = 'tsv';
1086
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1087
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1088
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1089
-    				unset($lined);
1090
-    				unset($data);
1091
-    			    } else $error = true;
1071
+					$lined[$key] = $line[$k+1];
1072
+				}
1073
+					if (count($lined) > 3) {
1074
+					$data['hex'] = $lined['hexid'];
1075
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1076
+					$data['datetime'] = date('Y-m-d H:i:s');;
1077
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1078
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1079
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1080
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1081
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1082
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1083
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1084
+					$data['id_source'] = $id_source;
1085
+					$data['format_source'] = 'tsv';
1086
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1087
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1088
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1089
+					unset($lined);
1090
+					unset($data);
1091
+					} else $error = true;
1092 1092
 			} elseif ($format == 'aprs' && $use_aprs) {
1093
-			    if ($aprs_connect == 0) {
1093
+				if ($aprs_connect == 0) {
1094 1094
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1095 1095
 				$aprs_connect = 1;
1096
-			    }
1096
+				}
1097 1097
 			    
1098
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1098
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1099 1099
 				$aprs_last_tx = time();
1100 1100
 				$data_aprs = "# Keep alive";
1101 1101
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1102
-			    }
1102
+				}
1103 1103
 			    
1104
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1105
-			    $buffer = str_replace('APRS <- ','',$buffer);
1106
-			    $buffer = str_replace('APRS -> ','',$buffer);
1107
-			    //echo $buffer."\n";
1108
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1104
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1105
+				$buffer = str_replace('APRS <- ','',$buffer);
1106
+				$buffer = str_replace('APRS -> ','',$buffer);
1107
+				//echo $buffer."\n";
1108
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1109 1109
 				$line = $APRS->parse($buffer);
1110 1110
 				//print_r($line);
1111 1111
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1112 1112
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && isset($line['ident'])) {
1113
-				    $aprs_last_tx = time();
1114
-				    $data = array();
1115
-				    //print_r($line);
1116
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1117
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1118
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1119
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1120
-				    $data['ident'] = $line['ident'];
1121
-				    $data['latitude'] = $line['latitude'];
1122
-				    $data['longitude'] = $line['longitude'];
1123
-				    //$data['verticalrate'] = $line[16];
1124
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1125
-				    else $data['speed'] = 0;
1126
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1127
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1128
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1129
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1130
-				    //else $data['heading'] = 0;
1131
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1132
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1133
-    				    $data['id_source'] = $id_source;
1134
-				    $data['format_source'] = 'aprs';
1135
-				    $data['source_name'] = $line['source'];
1136
-				    $data['source_type'] = 'flarm';
1137
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1138
-				    $currentdate = date('Y-m-d H:i:s');
1139
-				    $aprsdate = strtotime($data['datetime']);
1140
-				    // Accept data if time <= system time + 20s
1141
-				    if (isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1113
+					$aprs_last_tx = time();
1114
+					$data = array();
1115
+					//print_r($line);
1116
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1117
+					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1118
+					else $data['datetime'] = date('Y-m-d H:i:s');
1119
+					//$data['datetime'] = date('Y-m-d H:i:s');
1120
+					$data['ident'] = $line['ident'];
1121
+					$data['latitude'] = $line['latitude'];
1122
+					$data['longitude'] = $line['longitude'];
1123
+					//$data['verticalrate'] = $line[16];
1124
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1125
+					else $data['speed'] = 0;
1126
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1127
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1128
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1129
+					if (isset($line['heading'])) $data['heading'] = $line['heading'];
1130
+					//else $data['heading'] = 0;
1131
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1132
+					if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1133
+						$data['id_source'] = $id_source;
1134
+					$data['format_source'] = 'aprs';
1135
+					$data['source_name'] = $line['source'];
1136
+					$data['source_type'] = 'flarm';
1137
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1138
+					$currentdate = date('Y-m-d H:i:s');
1139
+					$aprsdate = strtotime($data['datetime']);
1140
+					// Accept data if time <= system time + 20s
1141
+					if (isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1142 1142
 					$send = $SI->add($data);
1143
-				    } elseif (isset($line['stealth'])) {
1143
+					} elseif (isset($line['stealth'])) {
1144 1144
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1145 1145
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1146
-				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1147
-				    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1146
+					//} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1147
+					} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1148 1148
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1149 1149
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1150
-				    }
1151
-				    unset($data);
1150
+					}
1151
+					unset($data);
1152 1152
 				} 
1153 1153
 				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1154 1154
 					echo '!! Weather Station not yet supported'."\n";
@@ -1158,12 +1158,12 @@  discard block
 block discarded – undo
1158 1158
 				}
1159 1159
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1160 1160
 				//elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1161
-			    }
1161
+				}
1162 1162
 			} else {
1163
-			    $line = explode(',', $buffer);
1164
-    			    if (count($line) > 20) {
1165
-    			    	$data['hex'] = $line[4];
1166
-    				/*
1163
+				$line = explode(',', $buffer);
1164
+					if (count($line) > 20) {
1165
+						$data['hex'] = $line[4];
1166
+					/*
1167 1167
     				$data['datetime'] = $line[6].' '.$line[7];
1168 1168
     					date_default_timezone_set($globalTimezone);
1169 1169
     					$datetime = new DateTime($data['datetime']);
@@ -1171,29 +1171,29 @@  discard block
 block discarded – undo
1171 1171
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1172 1172
     					date_default_timezone_set('UTC');
1173 1173
     				*/
1174
-    				// Force datetime to current UTC datetime
1175
-    				date_default_timezone_set('UTC');
1176
-    				$data['datetime'] = date('Y-m-d H:i:s');
1177
-    				$data['ident'] = trim($line[10]);
1178
-    				$data['latitude'] = $line[14];
1179
-    				$data['longitude'] = $line[15];
1180
-    				$data['verticalrate'] = $line[16];
1181
-    				$data['emergency'] = $line[20];
1182
-    				$data['speed'] = $line[12];
1183
-    				$data['squawk'] = $line[17];
1184
-    				$data['altitude'] = $line[11];
1185
-    				$data['heading'] = $line[13];
1186
-    				$data['ground'] = $line[21];
1187
-    				$data['emergency'] = $line[19];
1188
-    				$data['format_source'] = 'sbs';
1174
+					// Force datetime to current UTC datetime
1175
+					date_default_timezone_set('UTC');
1176
+					$data['datetime'] = date('Y-m-d H:i:s');
1177
+					$data['ident'] = trim($line[10]);
1178
+					$data['latitude'] = $line[14];
1179
+					$data['longitude'] = $line[15];
1180
+					$data['verticalrate'] = $line[16];
1181
+					$data['emergency'] = $line[20];
1182
+					$data['speed'] = $line[12];
1183
+					$data['squawk'] = $line[17];
1184
+					$data['altitude'] = $line[11];
1185
+					$data['heading'] = $line[13];
1186
+					$data['ground'] = $line[21];
1187
+					$data['emergency'] = $line[19];
1188
+					$data['format_source'] = 'sbs';
1189 1189
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1190
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1191
-    				$data['id_source'] = $id_source;
1192
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1193
-    				else $error = true;
1194
-    				unset($data);
1195
-    			    } else $error = true;
1196
-			    if ($error) {
1190
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1191
+					$data['id_source'] = $id_source;
1192
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1193
+					else $error = true;
1194
+					unset($data);
1195
+					} else $error = true;
1196
+				if ($error) {
1197 1197
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1198 1198
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1199 1199
 				} else {
@@ -1209,13 +1209,13 @@  discard block
 block discarded – undo
1209 1209
 					connect_all($sourceer);
1210 1210
 					$sourceer = array();
1211 1211
 				}
1212
-			    }
1212
+				}
1213 1213
 			}
1214 1214
 			// Sleep for xxx microseconds
1215 1215
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1216
-		    } else {
1216
+			} else {
1217 1217
 			if ($format == 'flightgearmp') {
1218
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1218
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1219 1219
 				//@socket_close($r);
1220 1220
 				sleep($globalMinFetch);
1221 1221
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1224,9 +1224,9 @@  discard block
 block discarded – undo
1224 1224
 				break;
1225 1225
 				
1226 1226
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1227
-			    if (isset($tt[$format])) $tt[$format]++;
1228
-			    else $tt[$format] = 0;
1229
-			    if ($tt[$format] > 30) {
1227
+				if (isset($tt[$format])) $tt[$format]++;
1228
+				else $tt[$format] = 0;
1229
+				if ($tt[$format] > 30) {
1230 1230
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1231 1231
 				//@socket_close($r);
1232 1232
 				sleep(2);
@@ -1237,23 +1237,23 @@  discard block
 block discarded – undo
1237 1237
 				//connect_all($globalSources);
1238 1238
 				$tt[$format]=0;
1239 1239
 				break;
1240
-			    }
1240
+				}
1241
+			}
1241 1242
 			}
1242
-		    }
1243 1243
 		}
1244
-	    } else {
1244
+		} else {
1245 1245
 		$error = socket_strerror(socket_last_error());
1246 1246
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1247 1247
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1248 1248
 			if (isset($globalDebug)) echo "Restarting...\n";
1249 1249
 			// Restart the script if possible
1250 1250
 			if (is_array($sockets)) {
1251
-			    if ($globalDebug) echo "Shutdown all sockets...";
1251
+				if ($globalDebug) echo "Shutdown all sockets...";
1252 1252
 			    
1253
-			    foreach ($sockets as $sock) {
1253
+				foreach ($sockets as $sock) {
1254 1254
 				@socket_shutdown($sock,2);
1255 1255
 				@socket_close($sock);
1256
-			    }
1256
+				}
1257 1257
 			    
1258 1258
 			}
1259 1259
 			if ($globalDebug) echo "Restart all connections...";
@@ -1264,13 +1264,13 @@  discard block
 block discarded – undo
1264 1264
 			if ($reset > 40) exit('Too many attempts...');
1265 1265
 			connect_all($globalSources);
1266 1266
 		}
1267
-	    }
1267
+		}
1268 1268
 	}
1269 1269
 	if ($globalDaemon === false) {
1270
-	    if ($globalDebug) echo 'Check all...'."\n";
1271
-	    $SI->checkAll();
1270
+		if ($globalDebug) echo 'Check all...'."\n";
1271
+		$SI->checkAll();
1272
+	}
1272 1273
 	}
1273
-    }
1274 1274
 }
1275 1275
 
1276 1276
 ?>
Please login to merge, or discard this patch.
Spacing   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -45,11 +45,11 @@  discard block
 block discarded – undo
45 45
 	    die;
46 46
 	}
47 47
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
48
-	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
48
+	$globalSources[] = array('host' => $globalSBS1Host, 'port' => $globalSBS1Port);
49 49
     }
50 50
 }
51 51
 
52
-$options = getopt('s::',array('source::','server','idsource::'));
52
+$options = getopt('s::', array('source::', 'server', 'idsource::'));
53 53
 //if (isset($options['s'])) $hosts = array($options['s']);
54 54
 //elseif (isset($options['source'])) $hosts = array($options['source']);
55 55
 if (isset($options['s'])) {
@@ -64,22 +64,22 @@  discard block
 block discarded – undo
64 64
 else $id_source = 1;
65 65
 if (isset($globalServer) && $globalServer) {
66 66
     if ($globalDebug) echo "Using Server Mode\n";
67
-    $SI=new SpotterServer();
68
-} else $SI=new SpotterImport($Connection->db);
67
+    $SI = new SpotterServer();
68
+} else $SI = new SpotterImport($Connection->db);
69 69
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
70 70
 if (isset($globalMarine) && $globalMarine) {
71 71
     $AIS = new AIS();
72 72
     $MI = new MarineImport($Connection->db);
73 73
 }
74 74
 //$APRS=new APRS($Connection->db);
75
-$SBS=new SBS();
76
-$ACARS=new ACARS($Connection->db);
77
-$Common=new Common();
75
+$SBS = new SBS();
76
+$ACARS = new ACARS($Connection->db);
77
+$Common = new Common();
78 78
 date_default_timezone_set('UTC');
79 79
 //$servertz = system('date +%Z');
80 80
 // signal handler - playing nice with sockets and dump1090
81 81
 if (function_exists('pcntl_fork')) {
82
-    pcntl_signal(SIGINT,  function() {
82
+    pcntl_signal(SIGINT, function() {
83 83
         global $sockets;
84 84
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
85 85
         die("Bye!\n");
@@ -123,35 +123,35 @@  discard block
 block discarded – undo
123 123
 
124 124
 function connect_all($hosts) {
125 125
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
126
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
126
+    global $sockets, $httpfeeds, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset, $context;
127 127
     $reset++;
128 128
     if ($globalDebug) echo 'Connect to all...'."\n";
129 129
     foreach ($hosts as $id => $value) {
130 130
 	$host = $value['host'];
131 131
 	$globalSources[$id]['last_exec'] = 0;
132 132
 	// Here we check type of source(s)
133
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
134
-            if (preg_match('/deltadb.txt$/i',$host)) {
133
+	if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
134
+            if (preg_match('/deltadb.txt$/i', $host)) {
135 135
         	//$formats[$id] = 'deltadbtxt';
136 136
         	$globalSources[$id]['format'] = 'deltadbtxt';
137 137
         	//$last_exec['deltadbtxt'] = 0;
138 138
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
139
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
139
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
140 140
         	//$formats[$id] = 'vatsimtxt';
141 141
         	$globalSources[$id]['format'] = 'vatsimtxt';
142 142
         	//$last_exec['vatsimtxt'] = 0;
143 143
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
144
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
144
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
145 145
         	//$formats[$id] = 'aircraftlistjson';
146 146
         	$globalSources[$id]['format'] = 'aircraftlistjson';
147 147
         	//$last_exec['aircraftlistjson'] = 0;
148 148
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
149
-    	    } else if (preg_match('/opensky/i',$host)) {
149
+    	    } else if (preg_match('/opensky/i', $host)) {
150 150
         	//$formats[$id] = 'aircraftlistjson';
151 151
         	$globalSources[$id]['format'] = 'opensky';
152 152
         	//$last_exec['aircraftlistjson'] = 0;
153 153
         	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
154
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
154
+    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i', $host)) {
155 155
         	//$formats[$id] = 'radarvirtueljson';
156 156
         	$globalSources[$id]['format'] = 'radarvirtueljson';
157 157
         	//$last_exec['radarvirtueljson'] = 0;
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
161 161
         	    exit(0);
162 162
         	}
163
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
163
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
164 164
         	//$formats[$id] = 'planeupdatefaa';
165 165
         	$globalSources[$id]['format'] = 'planeupdatefaa';
166 166
         	//$last_exec['planeupdatefaa'] = 0;
@@ -169,26 +169,26 @@  discard block
 block discarded – undo
169 169
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
170 170
         	    exit(0);
171 171
         	}
172
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
172
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
173 173
         	//$formats[$id] = 'phpvmacars';
174 174
         	$globalSources[$id]['format'] = 'phpvmacars';
175 175
         	//$last_exec['phpvmacars'] = 0;
176 176
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
177
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
177
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
178 178
         	//$formats[$id] = 'phpvmacars';
179 179
         	$globalSources[$id]['format'] = 'vam';
180 180
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
181
-            } else if (preg_match('/whazzup/i',$host)) {
181
+            } else if (preg_match('/whazzup/i', $host)) {
182 182
         	//$formats[$id] = 'whazzup';
183 183
         	$globalSources[$id]['format'] = 'whazzup';
184 184
         	//$last_exec['whazzup'] = 0;
185 185
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
186
-            } else if (preg_match('/recentpireps/i',$host)) {
186
+            } else if (preg_match('/recentpireps/i', $host)) {
187 187
         	//$formats[$id] = 'pirepsjson';
188 188
         	$globalSources[$id]['format'] = 'pirepsjson';
189 189
         	//$last_exec['pirepsjson'] = 0;
190 190
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
191
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
191
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
192 192
         	//$formats[$id] = 'fr24json';
193 193
         	$globalSources[$id]['format'] = 'fr24json';
194 194
         	//$last_exec['fr24json'] = 0;
@@ -198,22 +198,22 @@  discard block
 block discarded – undo
198 198
         	    exit(0);
199 199
         	}
200 200
             //} else if (preg_match('/10001/',$host)) {
201
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
201
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
202 202
         	//$formats[$id] = 'tsv';
203 203
         	$globalSources[$id]['format'] = 'tsv';
204 204
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
205 205
             }
206
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
206
+        } elseif (filter_var($host, FILTER_VALIDATE_URL)) {
207 207
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
208
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
208
+    		    $idf = fopen($globalSources[$id]['host'], 'r', false, $context);
209 209
     		    if ($idf !== false) {
210 210
     			$httpfeeds[$id] = $idf;
211 211
         		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
212 212
     		    }
213 213
     		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
214 214
     		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
215
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
216
-	    $hostport = explode(':',$host);
215
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
216
+	    $hostport = explode(':', $host);
217 217
 	    if (isset($hostport[1])) {
218 218
 		$port = $hostport[1];
219 219
 		$hostn = $hostport[0];
@@ -222,14 +222,14 @@  discard block
 block discarded – undo
222 222
 		$hostn = $globalSources[$id]['host'];
223 223
 	    }
224 224
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
225
-        	$s = create_socket($hostn,$port, $errno, $errstr);
225
+        	$s = create_socket($hostn, $port, $errno, $errstr);
226 226
     	    } else {
227
-        	$s = create_socket_udp($hostn,$port, $errno, $errstr);
227
+        	$s = create_socket_udp($hostn, $port, $errno, $errstr);
228 228
 	    }
229 229
 	    if ($s) {
230 230
     	        $sockets[$id] = $s;
231 231
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
232
-		    if (preg_match('/aprs/',$hostn)) {
232
+		    if (preg_match('/aprs/', $hostn)) {
233 233
 			//$formats[$id] = 'aprs';
234 234
 			$globalSources[$id]['format'] = 'aprs';
235 235
 			//$aprs_connect = 0;
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
272 272
 else $timeout = 20;
273 273
 $errno = '';
274
-$errstr='';
274
+$errstr = '';
275 275
 
276 276
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
277 277
 /* Initiate connections to all the hosts simultaneously */
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 //connect_all($globalSources);
280 280
 
281 281
 if (isset($globalProxy) && $globalProxy) {
282
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
282
+    $context = stream_context_create(array('http' => array('timeout' => $timeout, 'proxy' => $globalProxy, 'request_fulluri' => true)));
283 283
 } else {
284 284
     $context = stream_context_create(array('http' => array('timeout' => $timeout)));
285 285
 }
@@ -306,16 +306,16 @@  discard block
 block discarded – undo
306 306
 
307 307
 if ($use_aprs) {
308 308
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
309
-	$APRS=new APRS();
309
+	$APRS = new APRS();
310 310
 	$aprs_connect = 0;
311 311
 	$aprs_keep = 120;
312 312
 	$aprs_last_tx = time();
313 313
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
314
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
314
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
315 315
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
316
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
316
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
317 317
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
318
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
318
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
319 319
 	if ($aprs_full) $aprs_filter = '';
320 320
 
321 321
 	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version} filter {$aprs_filter}\n";
@@ -327,12 +327,12 @@  discard block
 block discarded – undo
327 327
 sleep(1);
328 328
 if ($globalDebug) echo "SCAN MODE \n\n";
329 329
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
330
-$endtime = time()+$globalCronEnd;
330
+$endtime = time() + $globalCronEnd;
331 331
 $i = 1;
332 332
 $tt = array();
333 333
 // Delete all ATC
334 334
 if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
335
-	$ATC=new ATC($Connection->db);
335
+	$ATC = new ATC($Connection->db);
336 336
 }
337 337
 if (!$globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
338 338
 	$ATC->deleteAll();
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
 
341 341
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
342 342
 while ($i > 0) {
343
-    if (!$globalDaemon) $i = $endtime-time();
343
+    if (!$globalDaemon) $i = $endtime - time();
344 344
     // Delete old ATC
345 345
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
346 346
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
 	}
356 356
 	if ($max != $globalMinFetch) {
357 357
 	    if ($globalDebug) echo 'Sleeping...'."\n";
358
-	    sleep($globalMinFetch-$max+2);
358
+	    sleep($globalMinFetch - $max + 2);
359 359
 	}
360 360
     }
361 361
 
@@ -368,8 +368,8 @@  discard block
 block discarded – undo
368 368
 	    //$buffer = $Common->getData($hosts[$id]);
369 369
 	    $buffer = $Common->getData($value['host']);
370 370
 	    if ($buffer != '') $reset = 0;
371
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
372
-	    $buffer = explode('\n',$buffer);
371
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
372
+	    $buffer = explode('\n', $buffer);
373 373
 	    foreach ($buffer as $line) {
374 374
     		if ($line != '' && count($line) > 7) {
375 375
     		    $line = explode(',', $line);
@@ -396,11 +396,11 @@  discard block
 block discarded – undo
396 396
     	    $last_exec[$id]['last'] = time();
397 397
 	} elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
398 398
 	    date_default_timezone_set('CET');
399
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
399
+	    $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host']));
400 400
 	    date_default_timezone_set('UTC');
401 401
 	    if ($buffer != '') $reset = 0;
402
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
403
-	    $buffer = explode('\n',$buffer);
402
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
403
+	    $buffer = explode('\n', $buffer);
404 404
 	    foreach ($buffer as $line) {
405 405
 		if ($line != '') {
406 406
 		    echo "'".$line."'\n";
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
 		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
419 419
 		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
420 420
 		    if (isset($ais_data['timestamp'])) {
421
-			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
421
+			$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
422 422
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
423 423
 			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
424 424
 			    $add = true;
@@ -441,12 +441,12 @@  discard block
 block discarded – undo
441 441
 	    $w = $e = null;
442 442
 	    
443 443
 	    if (isset($arr[$id])) {
444
-	    $nn = stream_select($arr,$w,$e,$timeout);
444
+	    $nn = stream_select($arr, $w, $e, $timeout);
445 445
 	    if ($nn > 0) {
446 446
 		foreach ($httpfeeds as $feed) {
447
-		    $buffer = stream_get_line($feed,2000,"\n");
448
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
449
-		    $buffer = explode('\n',$buffer);
447
+		    $buffer = stream_get_line($feed, 2000, "\n");
448
+		    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
449
+		    $buffer = explode('\n', $buffer);
450 450
 		    foreach ($buffer as $line) {
451 451
 			if ($line != '') {
452 452
 			    $ais_data = $AIS->parse_line(trim($line));
@@ -462,9 +462,9 @@  discard block
 block discarded – undo
462 462
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
463 463
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
464 464
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
465
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
465
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
466 466
 			    if (isset($ais_data['timestamp'])) {
467
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
467
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
468 468
 			    } else {
469 469
 				$data['datetime'] = date('Y-m-d H:i:s');
470 470
 			    }
@@ -479,27 +479,27 @@  discard block
 block discarded – undo
479 479
 	    }
480 480
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
481 481
 	    echo 'download...';
482
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
482
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
483 483
 	    echo 'done !'."\n";
484 484
 	    if ($buffer != '') $reset = 0;
485
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
486
-	    $buffer = explode('\n',$buffer);
485
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
486
+	    $buffer = explode('\n', $buffer);
487 487
 	    foreach ($buffer as $line) {
488 488
 		if ($line != '') {
489 489
 		    $data = array();
490
-		    $data['mmsi'] = (int)substr($line,0,9);
491
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
490
+		    $data['mmsi'] = (int) substr($line, 0, 9);
491
+		    $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10));
492 492
 		    //$data['status'] = substr($line,21,2);
493 493
 		    //$data['type'] = substr($line,24,3);
494
-		    $data['latitude'] = substr($line,29,9);
495
-		    $data['longitude'] = substr($line,41,9);
496
-		    $data['speed'] = round(substr($line,51,5));
494
+		    $data['latitude'] = substr($line, 29, 9);
495
+		    $data['longitude'] = substr($line, 41, 9);
496
+		    $data['speed'] = round(substr($line, 51, 5));
497 497
 		    //$data['course'] = substr($line,57,5);
498
-		    $data['heading'] = round(substr($line,63,3));
498
+		    $data['heading'] = round(substr($line, 63, 3));
499 499
 		    //$data['draft'] = substr($line,67,4);
500 500
 		    //$data['length'] = substr($line,72,3);
501 501
 		    //$data['beam'] = substr($line,76,2);
502
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
502
+		    $data['ident'] = trim(utf8_encode(substr($line, 79, 20)));
503 503
 		    //$data['callsign'] = trim(substr($line,100,7);
504 504
 		    //$data['dest'] = substr($line,108,20);
505 505
 		    //$data['etaDate'] = substr($line,129,5);
@@ -517,8 +517,8 @@  discard block
 block discarded – undo
517 517
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
518 518
 	    //$buffer = $Common->getData($hosts[$id]);
519 519
 	    $buffer = $Common->getData($value['host']);
520
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
521
-	    $buffer = explode('\n',$buffer);
520
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
521
+	    $buffer = explode('\n', $buffer);
522 522
 	    $reset = 0;
523 523
 	    foreach ($buffer as $line) {
524 524
     		if ($line != '') {
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
530 530
 			$data['pilot_id'] = $line[1];
531 531
 			$data['pilot_name'] = $line[2];
532
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
532
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
533 533
 			$data['ident'] = $line[0]; // ident
534 534
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
535 535
 			$data['speed'] = $line[8]; // speed
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
546 546
 			//if (isset($line[37])) $data['last_update'] = $line[37];
547 547
 		        $data['departure_airport_icao'] = $line[11];
548
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
548
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
549 549
 		        $data['arrival_airport_icao'] = $line[13];
550 550
 			$data['frequency'] = $line[4];
551 551
 			$data['type'] = $line[18];
@@ -554,7 +554,7 @@  discard block
 block discarded – undo
554 554
     			$data['id_source'] = $id_source;
555 555
 	    		//$data['arrival_airport_time'] = ;
556 556
 	    		if ($line[9] != '') {
557
-	    		    $aircraft_data = explode('/',$line[9]);
557
+	    		    $aircraft_data = explode('/', $line[9]);
558 558
 	    		    if (isset($aircraft_data[1])) {
559 559
 	    			$data['aircraft_icao'] = $aircraft_data[1];
560 560
 	    		    }
@@ -568,9 +568,9 @@  discard block
 block discarded – undo
568 568
     			if ($line[3] == 'PILOT') $SI->add($data);
569 569
 			elseif ($line[3] == 'ATC') {
570 570
 				//print_r($data);
571
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
572
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
573
-				$typec = substr($data['ident'],-3);
571
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
572
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
573
+				$typec = substr($data['ident'], -3);
574 574
 				if ($typec == 'APP') $data['type'] = 'Approach';
575 575
 				elseif ($typec == 'TWR') $data['type'] = 'Tower';
576 576
 				elseif ($typec == 'OBS') $data['type'] = 'Observer';
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
 				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
582 582
 				elseif ($data['type'] == '') $data['type'] = 'Observer';
583 583
 				if (!isset($data['source_name'])) $data['source_name'] = '';
584
-				if (isset($ATC)) echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
584
+				if (isset($ATC)) echo $ATC->add($data['ident'], $data['frequency'], $data['latitude'], $data['longitude'], $data['range'], $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source'], $data['source_name']);
585 585
 			}
586 586
     			unset($data);
587 587
     		    }
@@ -592,9 +592,9 @@  discard block
 block discarded – undo
592 592
     	    $last_exec[$id]['last'] = time();
593 593
     	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
594 594
     	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
595
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
595
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
596 596
 	    if ($buffer != '') {
597
-	    $all_data = json_decode($buffer,true);
597
+	    $all_data = json_decode($buffer, true);
598 598
 	    if (isset($all_data['acList'])) {
599 599
 		$reset = 0;
600 600
 		foreach ($all_data['acList'] as $line) {
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
     	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
651 651
     	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
652 652
 	    $buffer = $Common->getData($value['host']);
653
-	    $all_data = json_decode($buffer,true);
653
+	    $all_data = json_decode($buffer, true);
654 654
 	    if (isset($all_data['planes'])) {
655 655
 		$reset = 0;
656 656
 		foreach ($all_data['planes'] as $key => $line) {
@@ -667,12 +667,12 @@  discard block
 block discarded – undo
667 667
 		    $data['emergency'] = ''; // emergency
668 668
 		    $data['registration'] = $line[2];
669 669
 		    $data['aircraft_icao'] = $line[0];
670
-		    $deparr = explode('-',$line[1]);
670
+		    $deparr = explode('-', $line[1]);
671 671
 		    if (count($deparr) == 2) {
672 672
 			$data['departure_airport_icao'] = $deparr[0];
673 673
 			$data['arrival_airport_icao'] = $deparr[1];
674 674
 		    }
675
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
675
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
676 676
 	    	    $data['format_source'] = 'planeupdatefaa';
677 677
     		    $data['id_source'] = $id_source;
678 678
 		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -684,7 +684,7 @@  discard block
 block discarded – undo
684 684
     	    $last_exec[$id]['last'] = time();
685 685
     	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
686 686
 	    $buffer = $Common->getData($value['host']);
687
-	    $all_data = json_decode($buffer,true);
687
+	    $all_data = json_decode($buffer, true);
688 688
 	    if (isset($all_data['states'])) {
689 689
 		$reset = 0;
690 690
 		foreach ($all_data['states'] as $key => $line) {
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
 		    //$data['emergency'] = ''; // emergency
702 702
 		    //$data['registration'] = $line[2];
703 703
 		    //$data['aircraft_icao'] = $line[0];
704
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
704
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
705 705
 	    	    $data['format_source'] = 'opensky';
706 706
     		    $data['id_source'] = $id_source;
707 707
 		    $SI->add($data);
@@ -714,7 +714,7 @@  discard block
 block discarded – undo
714 714
     	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
715 715
 	    //$buffer = $Common->getData($hosts[$id]);
716 716
 	    $buffer = $Common->getData($value['host']);
717
-	    $all_data = json_decode($buffer,true);
717
+	    $all_data = json_decode($buffer, true);
718 718
 	    if (!empty($all_data)) $reset = 0;
719 719
 	    foreach ($all_data as $key => $line) {
720 720
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -746,11 +746,11 @@  discard block
 block discarded – undo
746 746
     	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
747 747
     	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
748 748
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
749
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
749
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
750 750
 	    //echo $buffer;
751
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
752
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
753
-	    $all_data = json_decode($buffer,true);
751
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
752
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
753
+	    $all_data = json_decode($buffer, true);
754 754
 	    if (json_last_error() != JSON_ERROR_NONE) {
755 755
 		die(json_last_error_msg());
756 756
 	    }
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
 			//$data['departure_airport_iata'] = $line[11];
774 774
 			//$data['arrival_airport_iata'] = $line[12];
775 775
 	    		//$data['emergency'] = ''; // emergency
776
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
776
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
777 777
 	    		$data['format_source'] = 'radarvirtueljson';
778 778
     			$data['id_source'] = $id_source;
779 779
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -788,14 +788,14 @@  discard block
 block discarded – undo
788 788
     	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
789 789
 	    //$buffer = $Common->getData($hosts[$id]);
790 790
 	    $buffer = $Common->getData($value['host'].'?'.time());
791
-	    $all_data = json_decode(utf8_encode($buffer),true);
791
+	    $all_data = json_decode(utf8_encode($buffer), true);
792 792
 	    
793 793
 	    if (isset($all_data['pireps'])) {
794 794
 		$reset = 0;
795 795
 	        foreach ($all_data['pireps'] as $line) {
796 796
 		    $data = array();
797 797
 		    $data['id'] = $line['id'];
798
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
798
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
799 799
 		    $data['ident'] = $line['callsign']; // ident
800 800
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
801 801
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -824,9 +824,9 @@  discard block
 block discarded – undo
824 824
 			$SI->add($data);
825 825
 		    //    print_r($data);
826 826
     		    } elseif ($line['icon'] == 'ct') {
827
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
828
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
829
-			$typec = substr($data['ident'],-3);
827
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
828
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
829
+			$typec = substr($data['ident'], -3);
830 830
 			$data['type'] = '';
831 831
 			if ($typec == 'APP') $data['type'] = 'Approach';
832 832
 			elseif ($typec == 'TWR') $data['type'] = 'Tower';
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
 			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
838 838
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
839 839
 			else $data['type'] = 'Observer';
840
-			if (isset($ATC)) echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);
840
+			if (isset($ATC)) echo $ATC->add($data['ident'], '', $data['latitude'], $data['longitude'], '0', $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source']);
841 841
 		    }
842 842
 		    unset($data);
843 843
 		}
@@ -849,14 +849,14 @@  discard block
 block discarded – undo
849 849
 	    //$buffer = $Common->getData($hosts[$id]);
850 850
 	    if ($globalDebug) echo 'Get Data...'."\n";
851 851
 	    $buffer = $Common->getData($value['host']);
852
-	    $all_data = json_decode($buffer,true);
852
+	    $all_data = json_decode($buffer, true);
853 853
 	    if ($buffer != '' && is_array($all_data)) {
854 854
 		$reset = 0;
855 855
 		foreach ($all_data as $line) {
856 856
 	    	    $data = array();
857 857
 	    	    //$data['id'] = $line['id']; // id not usable
858 858
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
859
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
859
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
860 860
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
861 861
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
862 862
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -879,12 +879,12 @@  discard block
 block discarded – undo
879 879
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
880 880
 		    if (isset($line['aircraftname'])) {
881 881
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
882
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
883
-	    		$aircraft_data = explode('-',$line['aircraftname']);
882
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
883
+	    		$aircraft_data = explode('-', $line['aircraftname']);
884 884
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
885 885
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
886 886
 	    		else {
887
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
887
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
888 888
 	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
889 889
 	    		    else $data['aircraft_icao'] = $line['aircraftname'];
890 890
 	    		}
@@ -906,14 +906,14 @@  discard block
 block discarded – undo
906 906
 	    //$buffer = $Common->getData($hosts[$id]);
907 907
 	    if ($globalDebug) echo 'Get Data...'."\n";
908 908
 	    $buffer = $Common->getData($value['host']);
909
-	    $all_data = json_decode($buffer,true);
909
+	    $all_data = json_decode($buffer, true);
910 910
 	    if ($buffer != '' && is_array($all_data)) {
911 911
 		$reset = 0;
912 912
 		foreach ($all_data as $line) {
913 913
 	    	    $data = array();
914 914
 	    	    //$data['id'] = $line['id']; // id not usable
915 915
 	    	    $data['id'] = trim($line['flight_id']);
916
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
916
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
917 917
 	    	    $data['pilot_name'] = $line['pilot_name'];
918 918
 	    	    $data['pilot_id'] = $line['pilot_id'];
919 919
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -964,9 +964,9 @@  discard block
 block discarded – undo
964 964
 		    //$value = $formats[$nb];
965 965
 		    $format = $globalSources[$nb]['format'];
966 966
         	    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
967
-        		$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
967
+        		$buffer = socket_read($r, 6000, PHP_NORMAL_READ);
968 968
         	    } else {
969
-	    	        $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
969
+	    	        $az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
970 970
 	    	    }
971 971
         	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
972 972
         	    //echo $buffer."\n";
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
 		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
975 975
 		    $error = false;
976 976
 		    //$SI::del();
977
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
977
+		    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
978 978
 		    // SBS format is CSV format
979 979
 		    if ($buffer != '') {
980 980
 			$tt[$format] = 0;
@@ -1006,10 +1006,10 @@  discard block
 block discarded – undo
1006 1006
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1007 1007
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1008 1008
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1009
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1009
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1010 1010
 
1011 1011
 			    if (isset($ais_data['timestamp'])) {
1012
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1012
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1013 1013
 			    } else {
1014 1014
 				$data['datetime'] = date('Y-m-d H:i:s');
1015 1015
 			    }
@@ -1020,10 +1020,10 @@  discard block
 block discarded – undo
1020 1020
                         } elseif ($format == 'flightgearsp') {
1021 1021
                     	    //echo $buffer."\n";
1022 1022
                     	    if (strlen($buffer) > 5) {
1023
-				$line = explode(',',$buffer);
1023
+				$line = explode(',', $buffer);
1024 1024
 				$data = array();
1025 1025
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1026
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1026
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1027 1027
 				$data['ident'] = $line[6];
1028 1028
 				$data['aircraft_name'] = $line[7];
1029 1029
 				$data['longitude'] = $line[1];
@@ -1034,21 +1034,21 @@  discard block
 block discarded – undo
1034 1034
 				$data['datetime'] = date('Y-m-d H:i:s');
1035 1035
 				$data['format_source'] = 'flightgearsp';
1036 1036
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1037
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1037
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1038 1038
 			    }
1039 1039
                         } elseif ($format == 'acars') {
1040 1040
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1041 1041
 			    $ACARS->add(trim($buffer));
1042
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1042
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1043 1043
 			    $ACARS->deleteLiveAcarsData();
1044 1044
 			} elseif ($format == 'flightgearmp') {
1045
-			    if (substr($buffer,0,1) != '#') {
1045
+			    if (substr($buffer, 0, 1) != '#') {
1046 1046
 				$data = array();
1047 1047
 				//echo $buffer."\n";
1048
-				$line = explode(' ',$buffer);
1048
+				$line = explode(' ', $buffer);
1049 1049
 				if (count($line) == 11) {
1050
-				    $userserver = explode('@',$line[0]);
1051
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1050
+				    $userserver = explode('@', $line[0]);
1051
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1052 1052
 				    $data['ident'] = $userserver[0];
1053 1053
 				    $data['registration'] = $userserver[0];
1054 1054
 				    $data['latitude'] = $line[4];
@@ -1056,24 +1056,24 @@  discard block
 block discarded – undo
1056 1056
 				    $data['altitude'] = $line[6];
1057 1057
 				    $data['datetime'] = date('Y-m-d H:i:s');
1058 1058
 				    $aircraft_type = $line[10];
1059
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1060
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1059
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1060
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1061 1061
 				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1062 1062
 				}
1063 1063
 			    }
1064 1064
 			} elseif ($format == 'beast') {
1065 1065
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1066 1066
 			    die;
1067
-			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1067
+			} elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') {
1068 1068
 			    $line = explode("\t", $buffer);
1069
-			    for($k = 0; $k < count($line); $k=$k+2) {
1069
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1070 1070
 				$key = $line[$k];
1071
-			        $lined[$key] = $line[$k+1];
1071
+			        $lined[$key] = $line[$k + 1];
1072 1072
 			    }
1073 1073
     			    if (count($lined) > 3) {
1074 1074
     				$data['hex'] = $lined['hexid'];
1075 1075
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1076
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1076
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1077 1077
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1078 1078
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1079 1079
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1091,21 +1091,21 @@  discard block
 block discarded – undo
1091 1091
     			    } else $error = true;
1092 1092
 			} elseif ($format == 'aprs' && $use_aprs) {
1093 1093
 			    if ($aprs_connect == 0) {
1094
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1094
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
1095 1095
 				$aprs_connect = 1;
1096 1096
 			    }
1097 1097
 			    
1098
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1098
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
1099 1099
 				$aprs_last_tx = time();
1100 1100
 				$data_aprs = "# Keep alive";
1101
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1101
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1102 1102
 			    }
1103 1103
 			    
1104 1104
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1105
-			    $buffer = str_replace('APRS <- ','',$buffer);
1106
-			    $buffer = str_replace('APRS -> ','',$buffer);
1105
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1106
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1107 1107
 			    //echo $buffer."\n";
1108
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1108
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
1109 1109
 				$line = $APRS->parse($buffer);
1110 1110
 				//print_r($line);
1111 1111
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
@@ -1114,7 +1114,7 @@  discard block
 block discarded – undo
1114 1114
 				    $data = array();
1115 1115
 				    //print_r($line);
1116 1116
 				    if (isset($line['address'])) $data['hex'] = $line['address'];
1117
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1117
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1118 1118
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1119 1119
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1120 1120
 				    $data['ident'] = $line['ident'];
@@ -1138,7 +1138,7 @@  discard block
 block discarded – undo
1138 1138
 				    $currentdate = date('Y-m-d H:i:s');
1139 1139
 				    $aprsdate = strtotime($data['datetime']);
1140 1140
 				    // Accept data if time <= system time + 20s
1141
-				    if (isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1141
+				    if (isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate) + 20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1142 1142
 					$send = $SI->add($data);
1143 1143
 				    } elseif (isset($line['stealth'])) {
1144 1144
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
@@ -1235,7 +1235,7 @@  discard block
 block discarded – undo
1235 1235
 				connect_all($sourceee);
1236 1236
 				$sourceee = array();
1237 1237
 				//connect_all($globalSources);
1238
-				$tt[$format]=0;
1238
+				$tt[$format] = 0;
1239 1239
 				break;
1240 1240
 			    }
1241 1241
 			}
@@ -1244,14 +1244,14 @@  discard block
 block discarded – undo
1244 1244
 	    } else {
1245 1245
 		$error = socket_strerror(socket_last_error());
1246 1246
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1247
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1247
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
1248 1248
 			if (isset($globalDebug)) echo "Restarting...\n";
1249 1249
 			// Restart the script if possible
1250 1250
 			if (is_array($sockets)) {
1251 1251
 			    if ($globalDebug) echo "Shutdown all sockets...";
1252 1252
 			    
1253 1253
 			    foreach ($sockets as $sock) {
1254
-				@socket_shutdown($sock,2);
1254
+				@socket_shutdown($sock, 2);
1255 1255
 				@socket_close($sock);
1256 1256
 			    }
1257 1257
 			    
Please login to merge, or discard this patch.
Braces   +699 added lines, -241 removed lines patch added patch discarded remove patch
@@ -13,13 +13,17 @@  discard block
 block discarded – undo
13 13
 require_once(dirname(__FILE__).'/../require/class.SBS.php');
14 14
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
15 15
 require_once(dirname(__FILE__).'/../require/class.Common.php');
16
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
16
+if (isset($globalTracker) && $globalTracker) {
17
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
18
+}
17 19
 if (isset($globalMarine) && $globalMarine) {
18 20
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
19 21
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
20 22
 }
21 23
 
22
-if (!isset($globalDebug)) $globalDebug = FALSE;
24
+if (!isset($globalDebug)) {
25
+	$globalDebug = FALSE;
26
+}
23 27
 
24 28
 // Check if schema is at latest version
25 29
 $Connection = new Connection();
@@ -59,14 +63,25 @@  discard block
 block discarded – undo
59 63
     $globalSources = array();
60 64
     $globalSources[] = array('host' => $options['source']);
61 65
 }
62
-if (isset($options['server'])) $globalServer = TRUE;
63
-if (isset($options['idsource'])) $id_source = $options['idsource'];
64
-else $id_source = 1;
66
+if (isset($options['server'])) {
67
+	$globalServer = TRUE;
68
+}
69
+if (isset($options['idsource'])) {
70
+	$id_source = $options['idsource'];
71
+} else {
72
+	$id_source = 1;
73
+}
65 74
 if (isset($globalServer) && $globalServer) {
66
-    if ($globalDebug) echo "Using Server Mode\n";
75
+    if ($globalDebug) {
76
+    	echo "Using Server Mode\n";
77
+    }
67 78
     $SI=new SpotterServer();
68
-} else $SI=new SpotterImport($Connection->db);
69
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
79
+} else {
80
+	$SI=new SpotterImport($Connection->db);
81
+}
82
+if (isset($globalTracker) && $globalTracker) {
83
+	$TI = new TrackerImport($Connection->db);
84
+}
70 85
 if (isset($globalMarine) && $globalMarine) {
71 86
     $AIS = new AIS();
72 87
     $MI = new MarineImport($Connection->db);
@@ -88,7 +103,9 @@  discard block
 block discarded – undo
88 103
 }
89 104
 
90 105
 // let's try and connect
91
-if ($globalDebug) echo "Connecting...\n";
106
+if ($globalDebug) {
107
+	echo "Connecting...\n";
108
+}
92 109
 $use_aprs = false;
93 110
 $aprs_full = false;
94 111
 $reset = 0;
@@ -97,7 +114,9 @@  discard block
 block discarded – undo
97 114
     $ip = gethostbyname($host);
98 115
     $s = socket_create(AF_INET, SOCK_STREAM, 0);
99 116
     $r = @socket_connect($s, $ip, $port);
100
-    if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
117
+    if (!socket_set_nonblock($s)) {
118
+    	echo "Unable to set nonblock on socket\n";
119
+    }
101 120
     if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
102 121
         return $s;
103 122
     }
@@ -125,7 +144,9 @@  discard block
 block discarded – undo
125 144
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
126 145
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
127 146
     $reset++;
128
-    if ($globalDebug) echo 'Connect to all...'."\n";
147
+    if ($globalDebug) {
148
+    	echo 'Connect to all...'."\n";
149
+    }
129 150
     foreach ($hosts as $id => $value) {
130 151
 	$host = $value['host'];
131 152
 	$globalSources[$id]['last_exec'] = 0;
@@ -135,27 +156,37 @@  discard block
 block discarded – undo
135 156
         	//$formats[$id] = 'deltadbtxt';
136 157
         	$globalSources[$id]['format'] = 'deltadbtxt';
137 158
         	//$last_exec['deltadbtxt'] = 0;
138
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
159
+        	if ($globalDebug) {
160
+        		echo "Connect to deltadb source (".$host.")...\n";
161
+        	}
139 162
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
140 163
         	//$formats[$id] = 'vatsimtxt';
141 164
         	$globalSources[$id]['format'] = 'vatsimtxt';
142 165
         	//$last_exec['vatsimtxt'] = 0;
143
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
166
+        	if ($globalDebug) {
167
+        		echo "Connect to vatsim source (".$host.")...\n";
168
+        	}
144 169
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
145 170
         	//$formats[$id] = 'aircraftlistjson';
146 171
         	$globalSources[$id]['format'] = 'aircraftlistjson';
147 172
         	//$last_exec['aircraftlistjson'] = 0;
148
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
173
+        	if ($globalDebug) {
174
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
175
+        	}
149 176
     	    } else if (preg_match('/opensky/i',$host)) {
150 177
         	//$formats[$id] = 'aircraftlistjson';
151 178
         	$globalSources[$id]['format'] = 'opensky';
152 179
         	//$last_exec['aircraftlistjson'] = 0;
153
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
180
+        	if ($globalDebug) {
181
+        		echo "Connect to opensky source (".$host.")...\n";
182
+        	}
154 183
     	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
155 184
         	//$formats[$id] = 'radarvirtueljson';
156 185
         	$globalSources[$id]['format'] = 'radarvirtueljson';
157 186
         	//$last_exec['radarvirtueljson'] = 0;
158
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
187
+        	if ($globalDebug) {
188
+        		echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
189
+        	}
159 190
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
160 191
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
161 192
         	    exit(0);
@@ -164,7 +195,9 @@  discard block
 block discarded – undo
164 195
         	//$formats[$id] = 'planeupdatefaa';
165 196
         	$globalSources[$id]['format'] = 'planeupdatefaa';
166 197
         	//$last_exec['planeupdatefaa'] = 0;
167
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
198
+        	if ($globalDebug) {
199
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
200
+        	}
168 201
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
169 202
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
170 203
         	    exit(0);
@@ -173,26 +206,36 @@  discard block
 block discarded – undo
173 206
         	//$formats[$id] = 'phpvmacars';
174 207
         	$globalSources[$id]['format'] = 'phpvmacars';
175 208
         	//$last_exec['phpvmacars'] = 0;
176
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
209
+        	if ($globalDebug) {
210
+        		echo "Connect to phpvmacars source (".$host.")...\n";
211
+        	}
177 212
             } else if (preg_match('/VAM-json.php$/i',$host)) {
178 213
         	//$formats[$id] = 'phpvmacars';
179 214
         	$globalSources[$id]['format'] = 'vam';
180
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
215
+        	if ($globalDebug) {
216
+        		echo "Connect to Vam source (".$host.")...\n";
217
+        	}
181 218
             } else if (preg_match('/whazzup/i',$host)) {
182 219
         	//$formats[$id] = 'whazzup';
183 220
         	$globalSources[$id]['format'] = 'whazzup';
184 221
         	//$last_exec['whazzup'] = 0;
185
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
222
+        	if ($globalDebug) {
223
+        		echo "Connect to whazzup source (".$host.")...\n";
224
+        	}
186 225
             } else if (preg_match('/recentpireps/i',$host)) {
187 226
         	//$formats[$id] = 'pirepsjson';
188 227
         	$globalSources[$id]['format'] = 'pirepsjson';
189 228
         	//$last_exec['pirepsjson'] = 0;
190
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
229
+        	if ($globalDebug) {
230
+        		echo "Connect to pirepsjson source (".$host.")...\n";
231
+        	}
191 232
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
192 233
         	//$formats[$id] = 'fr24json';
193 234
         	$globalSources[$id]['format'] = 'fr24json';
194 235
         	//$last_exec['fr24json'] = 0;
195
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
236
+        	if ($globalDebug) {
237
+        		echo "Connect to fr24 source (".$host.")...\n";
238
+        	}
196 239
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
197 240
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
198 241
         	    exit(0);
@@ -201,17 +244,24 @@  discard block
 block discarded – undo
201 244
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
202 245
         	//$formats[$id] = 'tsv';
203 246
         	$globalSources[$id]['format'] = 'tsv';
204
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
247
+        	if ($globalDebug) {
248
+        		echo "Connect to tsv source (".$host.")...\n";
249
+        	}
205 250
             }
206 251
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
207 252
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
208 253
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
209 254
     		    if ($idf !== false) {
210 255
     			$httpfeeds[$id] = $idf;
211
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
256
+        		if ($globalDebug) {
257
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
258
+        		}
259
+    		    } elseif ($globalDebug) {
260
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
212 261
     		    }
213
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
214
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
262
+    		} elseif ($globalDebug) {
263
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
264
+    		}
215 265
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
216 266
 	    $hostport = explode(':',$host);
217 267
 	    if (isset($hostport[1])) {
@@ -248,17 +298,25 @@  discard block
 block discarded – undo
248 298
         		//$formats[$id] = 'beast';
249 299
         		$globalSources[$id]['format'] = 'beast';
250 300
 		    //} else $formats[$id] = 'sbs';
251
-		    } else $globalSources[$id]['format'] = 'sbs';
301
+		    } else {
302
+		    	$globalSources[$id]['format'] = 'sbs';
303
+		    }
252 304
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
253 305
 		}
254
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
306
+		if ($globalDebug) {
307
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
308
+		}
255 309
             } else {
256
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
310
+		if ($globalDebug) {
311
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
312
+		}
257 313
     	    }
258 314
         }
259 315
     }
260 316
 }
261
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
317
+if (!isset($globalMinFetch)) {
318
+	$globalMinFetch = 15;
319
+}
262 320
 
263 321
 // Initialize all
264 322
 $status = array();
@@ -267,13 +325,19 @@  discard block
 block discarded – undo
267 325
 $formats = array();
268 326
 $last_exec = array();
269 327
 $time = time();
270
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
271
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
272
-else $timeout = 20;
328
+if (isset($globalSourcesTimeout)) {
329
+	$timeout = $globalSourcesTimeOut;
330
+} else if (isset($globalSBS1TimeOut)) {
331
+	$timeout = $globalSBS1TimeOut;
332
+} else {
333
+	$timeout = 20;
334
+}
273 335
 $errno = '';
274 336
 $errstr='';
275 337
 
276
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
338
+if (!isset($globalDaemon)) {
339
+	$globalDaemon = TRUE;
340
+}
277 341
 /* Initiate connections to all the hosts simultaneously */
278 342
 //connect_all($hosts);
279 343
 //connect_all($globalSources);
@@ -299,7 +363,9 @@  discard block
 block discarded – undo
299 363
     if (isset($source['format']) && $source['format'] == 'aprs') {
300 364
 	$aprs_connect = 0;
301 365
 	$use_aprs = true;
302
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
366
+	if (isset($source['port']) && $source['port'] == '10152') {
367
+		$aprs_full = true;
368
+	}
303 369
 	break;
304 370
     }
305 371
 }
@@ -310,23 +376,43 @@  discard block
 block discarded – undo
310 376
 	$aprs_connect = 0;
311 377
 	$aprs_keep = 120;
312 378
 	$aprs_last_tx = time();
313
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
314
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
315
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
316
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
317
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
318
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
319
-	if ($aprs_full) $aprs_filter = '';
379
+	if (isset($globalAPRSversion)) {
380
+		$aprs_version = $globalAPRSversion;
381
+	} else {
382
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
383
+	}
384
+	if (isset($globalAPRSssid)) {
385
+		$aprs_ssid = $globalAPRSssid;
386
+	} else {
387
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
388
+	}
389
+	if (isset($globalAPRSfilter)) {
390
+		$aprs_filter = $globalAPRSfilter;
391
+	} else {
392
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
393
+	}
394
+	if ($aprs_full) {
395
+		$aprs_filter = '';
396
+	}
320 397
 
321
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version} filter {$aprs_filter}\n";
322
-	else $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version}\n";
323
-}
398
+	if ($aprs_filter != '') {
399
+		$aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version} filter {$aprs_filter}\n";
400
+	} else {
401
+		$aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version}\n";
402
+	}
403
+	}
324 404
 
325 405
 // connected - lets do some work
326
-if ($globalDebug) echo "Connected!\n";
406
+if ($globalDebug) {
407
+	echo "Connected!\n";
408
+}
327 409
 sleep(1);
328
-if ($globalDebug) echo "SCAN MODE \n\n";
329
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
410
+if ($globalDebug) {
411
+	echo "SCAN MODE \n\n";
412
+}
413
+if (!isset($globalCronEnd)) {
414
+	$globalCronEnd = 60;
415
+}
330 416
 $endtime = time()+$globalCronEnd;
331 417
 $i = 1;
332 418
 $tt = array();
@@ -340,10 +426,14 @@  discard block
 block discarded – undo
340 426
 
341 427
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
342 428
 while ($i > 0) {
343
-    if (!$globalDaemon) $i = $endtime-time();
429
+    if (!$globalDaemon) {
430
+    	$i = $endtime-time();
431
+    }
344 432
     // Delete old ATC
345 433
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
346
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
434
+	if ($globalDebug) {
435
+		echo 'Delete old ATC...'."\n";
436
+	}
347 437
         $ATC->deleteOldATC();
348 438
     }
349 439
     
@@ -351,10 +441,14 @@  discard block
 block discarded – undo
351 441
     if (count($last_exec) == count($globalSources)) {
352 442
 	$max = $globalMinFetch;
353 443
 	foreach ($last_exec as $last) {
354
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
444
+	    if ((time() - $last['last']) < $max) {
445
+	    	$max = time() - $last['last'];
446
+	    }
355 447
 	}
356 448
 	if ($max != $globalMinFetch) {
357
-	    if ($globalDebug) echo 'Sleeping...'."\n";
449
+	    if ($globalDebug) {
450
+	    	echo 'Sleeping...'."\n";
451
+	    }
358 452
 	    sleep($globalMinFetch-$max+2);
359 453
 	}
360 454
     }
@@ -363,11 +457,15 @@  discard block
 block discarded – undo
363 457
     //foreach ($formats as $id => $value) {
364 458
     foreach ($globalSources as $id => $value) {
365 459
 	date_default_timezone_set('UTC');
366
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
460
+	if (!isset($last_exec[$id]['last'])) {
461
+		$last_exec[$id]['last'] = 0;
462
+	}
367 463
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
368 464
 	    //$buffer = $Common->getData($hosts[$id]);
369 465
 	    $buffer = $Common->getData($value['host']);
370
-	    if ($buffer != '') $reset = 0;
466
+	    if ($buffer != '') {
467
+	    	$reset = 0;
468
+	    }
371 469
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
372 470
 	    $buffer = explode('\n',$buffer);
373 471
 	    foreach ($buffer as $line) {
@@ -376,19 +474,38 @@  discard block
 block discarded – undo
376 474
 	            $data = array();
377 475
 	            $data['hex'] = $line[1]; // hex
378 476
 	            $data['ident'] = $line[2]; // ident
379
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
380
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
381
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
382
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
383
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
477
+	            if (isset($line[3])) {
478
+	            	$data['altitude'] = $line[3];
479
+	            }
480
+	            // altitude
481
+	            if (isset($line[4])) {
482
+	            	$data['speed'] = $line[4];
483
+	            }
484
+	            // speed
485
+	            if (isset($line[5])) {
486
+	            	$data['heading'] = $line[5];
487
+	            }
488
+	            // heading
489
+	            if (isset($line[6])) {
490
+	            	$data['latitude'] = $line[6];
491
+	            }
492
+	            // lat
493
+	            if (isset($line[7])) {
494
+	            	$data['longitude'] = $line[7];
495
+	            }
496
+	            // long
384 497
 	            $data['verticalrate'] = ''; // vertical rate
385 498
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
386 499
 	            $data['emergency'] = ''; // emergency
387 500
 		    $data['datetime'] = date('Y-m-d H:i:s');
388 501
 		    $data['format_source'] = 'deltadbtxt';
389 502
     		    $data['id_source'] = $id_source;
390
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
391
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
503
+		    if (isset($value['name']) && $value['name'] != '') {
504
+		    	$data['source_name'] = $value['name'];
505
+		    }
506
+		    if (isset($value['sourcestats'])) {
507
+		    	$data['sourcestats'] = $value['sourcestats'];
508
+		    }
392 509
     		    $SI->add($data);
393 510
 		    unset($data);
394 511
     		}
@@ -398,7 +515,9 @@  discard block
 block discarded – undo
398 515
 	    date_default_timezone_set('CET');
399 516
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
400 517
 	    date_default_timezone_set('UTC');
401
-	    if ($buffer != '') $reset = 0;
518
+	    if ($buffer != '') {
519
+	    	$reset = 0;
520
+	    }
402 521
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
403 522
 	    $buffer = explode('\n',$buffer);
404 523
 	    foreach ($buffer as $line) {
@@ -407,16 +526,36 @@  discard block
 block discarded – undo
407 526
 		    $add = false;
408 527
 		    $ais_data = $AIS->parse_line(trim($line));
409 528
 		    $data = array();
410
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
411
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
412
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
413
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
414
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
415
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
416
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
417
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
418
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
419
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
529
+		    if (isset($ais_data['ident'])) {
530
+		    	$data['ident'] = $ais_data['ident'];
531
+		    }
532
+		    if (isset($ais_data['mmsi'])) {
533
+		    	$data['mmsi'] = $ais_data['mmsi'];
534
+		    }
535
+		    if (isset($ais_data['speed'])) {
536
+		    	$data['speed'] = $ais_data['speed'];
537
+		    }
538
+		    if (isset($ais_data['heading'])) {
539
+		    	$data['heading'] = $ais_data['heading'];
540
+		    }
541
+		    if (isset($ais_data['latitude'])) {
542
+		    	$data['latitude'] = $ais_data['latitude'];
543
+		    }
544
+		    if (isset($ais_data['longitude'])) {
545
+		    	$data['longitude'] = $ais_data['longitude'];
546
+		    }
547
+		    if (isset($ais_data['status'])) {
548
+		    	$data['status'] = $ais_data['status'];
549
+		    }
550
+		    if (isset($ais_data['type'])) {
551
+		    	$data['type'] = $ais_data['type'];
552
+		    }
553
+		    if (isset($ais_data['imo'])) {
554
+		    	$data['imo'] = $ais_data['imo'];
555
+		    }
556
+		    if (isset($ais_data['callsign'])) {
557
+		    	$data['callsign'] = $ais_data['callsign'];
558
+		    }
420 559
 		    if (isset($ais_data['timestamp'])) {
421 560
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
422 561
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -431,7 +570,9 @@  discard block
 block discarded – undo
431 570
     		    $data['id_source'] = $id_source;
432 571
 		    print_r($data);
433 572
 		    echo 'Add...'."\n";
434
-		    if ($add && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
573
+		    if ($add && $ais_data['mmsi_type'] == 'Ship') {
574
+		    	$MI->add($data);
575
+		    }
435 576
 		    unset($data);
436 577
 		}
437 578
     	    }
@@ -451,18 +592,42 @@  discard block
 block discarded – undo
451 592
 			if ($line != '') {
452 593
 			    $ais_data = $AIS->parse_line(trim($line));
453 594
 			    $data = array();
454
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
455
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
456
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
457
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
458
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
459
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
460
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
461
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
462
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
463
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
464
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
465
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
595
+			    if (isset($ais_data['ident'])) {
596
+			    	$data['ident'] = $ais_data['ident'];
597
+			    }
598
+			    if (isset($ais_data['mmsi'])) {
599
+			    	$data['mmsi'] = $ais_data['mmsi'];
600
+			    }
601
+			    if (isset($ais_data['speed'])) {
602
+			    	$data['speed'] = $ais_data['speed'];
603
+			    }
604
+			    if (isset($ais_data['heading'])) {
605
+			    	$data['heading'] = $ais_data['heading'];
606
+			    }
607
+			    if (isset($ais_data['latitude'])) {
608
+			    	$data['latitude'] = $ais_data['latitude'];
609
+			    }
610
+			    if (isset($ais_data['longitude'])) {
611
+			    	$data['longitude'] = $ais_data['longitude'];
612
+			    }
613
+			    if (isset($ais_data['status'])) {
614
+			    	$data['status'] = $ais_data['status'];
615
+			    }
616
+			    if (isset($ais_data['type'])) {
617
+			    	$data['type'] = $ais_data['type'];
618
+			    }
619
+			    if (isset($ais_data['imo'])) {
620
+			    	$data['imo'] = $ais_data['imo'];
621
+			    }
622
+			    if (isset($ais_data['callsign'])) {
623
+			    	$data['callsign'] = $ais_data['callsign'];
624
+			    }
625
+			    if (isset($ais_data['destination'])) {
626
+			    	$data['arrival_code'] = $ais_data['destination'];
627
+			    }
628
+			    if (isset($ais_data['eta_ts'])) {
629
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
630
+			    }
466 631
 			    if (isset($ais_data['timestamp'])) {
467 632
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
468 633
 			    } else {
@@ -470,7 +635,9 @@  discard block
 block discarded – undo
470 635
 			    }
471 636
 			    $data['format_source'] = 'aisnmeahttp';
472 637
 			    $data['id_source'] = $id_source;
473
-			    if ($ais_data['mmsi_type'] == 'Ship') $MI->add($data);
638
+			    if ($ais_data['mmsi_type'] == 'Ship') {
639
+			    	$MI->add($data);
640
+			    }
474 641
 			    unset($data);
475 642
 			}
476 643
 		    }
@@ -481,7 +648,9 @@  discard block
 block discarded – undo
481 648
 	    echo 'download...';
482 649
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
483 650
 	    echo 'done !'."\n";
484
-	    if ($buffer != '') $reset = 0;
651
+	    if ($buffer != '') {
652
+	    	$reset = 0;
653
+	    }
485 654
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
486 655
 	    $buffer = explode('\n',$buffer);
487 656
 	    foreach ($buffer as $line) {
@@ -525,16 +694,28 @@  discard block
 block discarded – undo
525 694
     		    $line = explode(':', $line);
526 695
     		    if (count($line) > 30 && $line[0] != 'callsign') {
527 696
 			$data = array();
528
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
529
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
697
+			if (isset($line[37]) && $line[37] != '') {
698
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
699
+			} else {
700
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
701
+			}
530 702
 			$data['pilot_id'] = $line[1];
531 703
 			$data['pilot_name'] = $line[2];
532 704
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
533 705
 			$data['ident'] = $line[0]; // ident
534
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
706
+			if ($line[7] != '' && $line[7] != 0) {
707
+				$data['altitude'] = $line[7];
708
+			}
709
+			// altitude
535 710
 			$data['speed'] = $line[8]; // speed
536
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
537
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
711
+			if (isset($line[45])) {
712
+				$data['heading'] = $line[45];
713
+			}
714
+			// heading
715
+			elseif (isset($line[38])) {
716
+				$data['heading'] = $line[38];
717
+			}
718
+			// heading
538 719
 			$data['latitude'] = $line[5]; // lat
539 720
 	        	$data['longitude'] = $line[6]; // long
540 721
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -550,7 +731,9 @@  discard block
 block discarded – undo
550 731
 			$data['frequency'] = $line[4];
551 732
 			$data['type'] = $line[18];
552 733
 			$data['range'] = $line[19];
553
-			if (isset($line[35])) $data['info'] = $line[35];
734
+			if (isset($line[35])) {
735
+				$data['info'] = $line[35];
736
+			}
554 737
     			$data['id_source'] = $id_source;
555 738
 	    		//$data['arrival_airport_time'] = ;
556 739
 	    		if ($line[9] != '') {
@@ -564,24 +747,41 @@  discard block
 block discarded – undo
564 747
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
565 748
 	    		*/
566 749
 	    		$data['format_source'] = $value['format'];
567
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
568
-    			if ($line[3] == 'PILOT') $SI->add($data);
569
-			elseif ($line[3] == 'ATC') {
750
+			if (isset($value['name']) && $value['name'] != '') {
751
+				$data['source_name'] = $value['name'];
752
+			}
753
+    			if ($line[3] == 'PILOT') {
754
+    				$SI->add($data);
755
+    			} elseif ($line[3] == 'ATC') {
570 756
 				//print_r($data);
571 757
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
572 758
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
573 759
 				$typec = substr($data['ident'],-3);
574
-				if ($typec == 'APP') $data['type'] = 'Approach';
575
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
576
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
577
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
578
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
579
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
580
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
581
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
582
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
583
-				if (!isset($data['source_name'])) $data['source_name'] = '';
584
-				if (isset($ATC)) echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
760
+				if ($typec == 'APP') {
761
+					$data['type'] = 'Approach';
762
+				} elseif ($typec == 'TWR') {
763
+					$data['type'] = 'Tower';
764
+				} elseif ($typec == 'OBS') {
765
+					$data['type'] = 'Observer';
766
+				} elseif ($typec == 'GND') {
767
+					$data['type'] = 'Ground';
768
+				} elseif ($typec == 'DEL') {
769
+					$data['type'] = 'Delivery';
770
+				} elseif ($typec == 'DEP') {
771
+					$data['type'] = 'Departure';
772
+				} elseif ($typec == 'FSS') {
773
+					$data['type'] = 'Flight Service Station';
774
+				} elseif ($typec == 'CTR') {
775
+					$data['type'] = 'Control Radar or Centre';
776
+				} elseif ($data['type'] == '') {
777
+					$data['type'] = 'Observer';
778
+				}
779
+				if (!isset($data['source_name'])) {
780
+					$data['source_name'] = '';
781
+				}
782
+				if (isset($ATC)) {
783
+					echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
784
+				}
585 785
 			}
586 786
     			unset($data);
587 787
     		    }
@@ -600,26 +800,55 @@  discard block
 block discarded – undo
600 800
 		foreach ($all_data['acList'] as $line) {
601 801
 		    $data = array();
602 802
 		    $data['hex'] = $line['Icao']; // hex
603
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
604
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
605
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
606
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
607
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
608
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
803
+		    if (isset($line['Call'])) {
804
+		    	$data['ident'] = $line['Call'];
805
+		    }
806
+		    // ident
807
+		    if (isset($line['Alt'])) {
808
+		    	$data['altitude'] = $line['Alt'];
809
+		    }
810
+		    // altitude
811
+		    if (isset($line['Spd'])) {
812
+		    	$data['speed'] = $line['Spd'];
813
+		    }
814
+		    // speed
815
+		    if (isset($line['Trak'])) {
816
+		    	$data['heading'] = $line['Trak'];
817
+		    }
818
+		    // heading
819
+		    if (isset($line['Lat'])) {
820
+		    	$data['latitude'] = $line['Lat'];
821
+		    }
822
+		    // lat
823
+		    if (isset($line['Long'])) {
824
+		    	$data['longitude'] = $line['Long'];
825
+		    }
826
+		    // long
609 827
 		    //$data['verticalrate'] = $line['']; // verticale rate
610
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
828
+		    if (isset($line['Sqk'])) {
829
+		    	$data['squawk'] = $line['Sqk'];
830
+		    }
831
+		    // squawk
611 832
 		    $data['emergency'] = ''; // emergency
612
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
833
+		    if (isset($line['Reg'])) {
834
+		    	$data['registration'] = $line['Reg'];
835
+		    }
613 836
 		    /*
614 837
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
615 838
 		    else $data['datetime'] = date('Y-m-d H:i:s');
616 839
 		    */
617 840
 		    $data['datetime'] = date('Y-m-d H:i:s');
618
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
841
+		    if (isset($line['Type'])) {
842
+		    	$data['aircraft_icao'] = $line['Type'];
843
+		    }
619 844
 	    	    $data['format_source'] = 'aircraftlistjson';
620 845
 		    $data['id_source'] = $id_source;
621
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
622
-		    if (isset($data['datetime'])) $SI->add($data);
846
+		    if (isset($value['name']) && $value['name'] != '') {
847
+		    	$data['source_name'] = $value['name'];
848
+		    }
849
+		    if (isset($data['datetime'])) {
850
+		    	$SI->add($data);
851
+		    }
623 852
 		    unset($data);
624 853
 		}
625 854
 	    } else {
@@ -639,7 +868,9 @@  discard block
 block discarded – undo
639 868
 		    $data['datetime'] = date('Y-m-d H:i:s');
640 869
 	    	    $data['format_source'] = 'aircraftlistjson';
641 870
     		    $data['id_source'] = $id_source;
642
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
871
+		    if (isset($value['name']) && $value['name'] != '') {
872
+		    	$data['source_name'] = $value['name'];
873
+		    }
643 874
 		    $SI->add($data);
644 875
 		    unset($data);
645 876
 		}
@@ -675,7 +906,9 @@  discard block
 block discarded – undo
675 906
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
676 907
 	    	    $data['format_source'] = 'planeupdatefaa';
677 908
     		    $data['id_source'] = $id_source;
678
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
909
+		    if (isset($value['name']) && $value['name'] != '') {
910
+		    	$data['source_name'] = $value['name'];
911
+		    }
679 912
 		    $SI->add($data);
680 913
 		    unset($data);
681 914
 		}
@@ -715,7 +948,9 @@  discard block
 block discarded – undo
715 948
 	    //$buffer = $Common->getData($hosts[$id]);
716 949
 	    $buffer = $Common->getData($value['host']);
717 950
 	    $all_data = json_decode($buffer,true);
718
-	    if (!empty($all_data)) $reset = 0;
951
+	    if (!empty($all_data)) {
952
+	    	$reset = 0;
953
+	    }
719 954
 	    foreach ($all_data as $key => $line) {
720 955
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
721 956
 		    $data = array();
@@ -736,7 +971,9 @@  discard block
 block discarded – undo
736 971
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
737 972
 	    	    $data['format_source'] = 'fr24json';
738 973
     		    $data['id_source'] = $id_source;
739
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
974
+		    if (isset($value['name']) && $value['name'] != '') {
975
+		    	$data['source_name'] = $value['name'];
976
+		    }
740 977
 		    $SI->add($data);
741 978
 		    unset($data);
742 979
 		}
@@ -760,23 +997,39 @@  discard block
 block discarded – undo
760 997
 		    if (isset($line['inf'])) {
761 998
 			$data = array();
762 999
 			$data['hex'] = $line['inf']['ia'];
763
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1000
+			if (isset($line['inf']['cs'])) {
1001
+				$data['ident'] = $line['inf']['cs'];
1002
+			}
1003
+			//$line[13]
764 1004
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
765
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
766
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1005
+	    		if (isset($line['inf']['gs'])) {
1006
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1007
+	    		}
1008
+	    		// speed
1009
+	    		if (isset($line['inf']['tr'])) {
1010
+	    			$data['heading'] = $line['inf']['tr'];
1011
+	    		}
1012
+	    		// heading
767 1013
 	    		$data['latitude'] = $line['pt'][0]; // lat
768 1014
 	    		$data['longitude'] = $line['pt'][1]; // long
769 1015
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
770
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1016
+	    		if (isset($line['inf']['sq'])) {
1017
+	    			$data['squawk'] = $line['inf']['sq'];
1018
+	    		}
1019
+	    		// squawk
771 1020
 	    		//$data['aircraft_icao'] = $line[8];
772
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1021
+	    		if (isset($line['inf']['rc'])) {
1022
+	    			$data['registration'] = $line['inf']['rc'];
1023
+	    		}
773 1024
 			//$data['departure_airport_iata'] = $line[11];
774 1025
 			//$data['arrival_airport_iata'] = $line[12];
775 1026
 	    		//$data['emergency'] = ''; // emergency
776 1027
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
777 1028
 	    		$data['format_source'] = 'radarvirtueljson';
778 1029
     			$data['id_source'] = $id_source;
779
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1030
+			if (isset($value['name']) && $value['name'] != '') {
1031
+				$data['source_name'] = $value['name'];
1032
+			}
780 1033
 			$SI->add($data);
781 1034
 			unset($data);
782 1035
 		    }
@@ -797,29 +1050,62 @@  discard block
 block discarded – undo
797 1050
 		    $data['id'] = $line['id'];
798 1051
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
799 1052
 		    $data['ident'] = $line['callsign']; // ident
800
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
801
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
802
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
803
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
804
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
805
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1053
+		    if (isset($line['pilotid'])) {
1054
+		    	$data['pilot_id'] = $line['pilotid'];
1055
+		    }
1056
+		    // pilot id
1057
+		    if (isset($line['name'])) {
1058
+		    	$data['pilot_name'] = $line['name'];
1059
+		    }
1060
+		    // pilot name
1061
+		    if (isset($line['alt'])) {
1062
+		    	$data['altitude'] = $line['alt'];
1063
+		    }
1064
+		    // altitude
1065
+		    if (isset($line['gs'])) {
1066
+		    	$data['speed'] = $line['gs'];
1067
+		    }
1068
+		    // speed
1069
+		    if (isset($line['heading'])) {
1070
+		    	$data['heading'] = $line['heading'];
1071
+		    }
1072
+		    // heading
1073
+		    if (isset($line['route'])) {
1074
+		    	$data['waypoints'] = $line['route'];
1075
+		    }
1076
+		    // route
806 1077
 		    $data['latitude'] = $line['lat']; // lat
807 1078
 		    $data['longitude'] = $line['lon']; // long
808 1079
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
809 1080
 		    //$data['squawk'] = $line['squawk']; // squawk
810 1081
 		    //$data['emergency'] = ''; // emergency
811
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
812
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
813
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1082
+		    if (isset($line['depicao'])) {
1083
+		    	$data['departure_airport_icao'] = $line['depicao'];
1084
+		    }
1085
+		    if (isset($line['deptime'])) {
1086
+		    	$data['departure_airport_time'] = $line['deptime'];
1087
+		    }
1088
+		    if (isset($line['arricao'])) {
1089
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1090
+		    }
814 1091
 		    //$data['arrival_airport_time'] = $line['arrtime'];
815
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
816
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
817
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
818
-		    else $data['info'] = '';
1092
+		    if (isset($line['aircraft'])) {
1093
+		    	$data['aircraft_icao'] = $line['aircraft'];
1094
+		    }
1095
+		    if (isset($line['transponder'])) {
1096
+		    	$data['squawk'] = $line['transponder'];
1097
+		    }
1098
+		    if (isset($line['atis'])) {
1099
+		    	$data['info'] = $line['atis'];
1100
+		    } else {
1101
+		    	$data['info'] = '';
1102
+		    }
819 1103
 		    $data['format_source'] = 'pireps';
820 1104
     		    $data['id_source'] = $id_source;
821 1105
 		    $data['datetime'] = date('Y-m-d H:i:s');
822
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1106
+		    if (isset($value['name']) && $value['name'] != '') {
1107
+		    	$data['source_name'] = $value['name'];
1108
+		    }
823 1109
 		    if ($line['icon'] == 'plane') {
824 1110
 			$SI->add($data);
825 1111
 		    //    print_r($data);
@@ -828,16 +1114,28 @@  discard block
 block discarded – undo
828 1114
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
829 1115
 			$typec = substr($data['ident'],-3);
830 1116
 			$data['type'] = '';
831
-			if ($typec == 'APP') $data['type'] = 'Approach';
832
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
833
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
834
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
835
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
836
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
837
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
838
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
839
-			else $data['type'] = 'Observer';
840
-			if (isset($ATC)) echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);
1117
+			if ($typec == 'APP') {
1118
+				$data['type'] = 'Approach';
1119
+			} elseif ($typec == 'TWR') {
1120
+				$data['type'] = 'Tower';
1121
+			} elseif ($typec == 'OBS') {
1122
+				$data['type'] = 'Observer';
1123
+			} elseif ($typec == 'GND') {
1124
+				$data['type'] = 'Ground';
1125
+			} elseif ($typec == 'DEL') {
1126
+				$data['type'] = 'Delivery';
1127
+			} elseif ($typec == 'DEP') {
1128
+				$data['type'] = 'Departure';
1129
+			} elseif ($typec == 'FSS') {
1130
+				$data['type'] = 'Flight Service Station';
1131
+			} elseif ($typec == 'CTR') {
1132
+				$data['type'] = 'Control Radar or Centre';
1133
+			} else {
1134
+				$data['type'] = 'Observer';
1135
+			}
1136
+			if (isset($ATC)) {
1137
+				echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);
1138
+			}
841 1139
 		    }
842 1140
 		    unset($data);
843 1141
 		}
@@ -847,7 +1145,9 @@  discard block
 block discarded – undo
847 1145
     	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
848 1146
     	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
849 1147
 	    //$buffer = $Common->getData($hosts[$id]);
850
-	    if ($globalDebug) echo 'Get Data...'."\n";
1148
+	    if ($globalDebug) {
1149
+	    	echo 'Get Data...'."\n";
1150
+	    }
851 1151
 	    $buffer = $Common->getData($value['host']);
852 1152
 	    $all_data = json_decode($buffer,true);
853 1153
 	    if ($buffer != '' && is_array($all_data)) {
@@ -855,10 +1155,16 @@  discard block
 block discarded – undo
855 1155
 		foreach ($all_data as $line) {
856 1156
 	    	    $data = array();
857 1157
 	    	    //$data['id'] = $line['id']; // id not usable
858
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1158
+	    	    if (isset($line['pilotid'])) {
1159
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1160
+	    	    }
859 1161
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
860
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
861
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1162
+	    	    if (isset($line['pilotname'])) {
1163
+	    	    	$data['pilot_name'] = $line['pilotname'];
1164
+	    	    }
1165
+	    	    if (isset($line['pilotid'])) {
1166
+	    	    	$data['pilot_id'] = $line['pilotid'];
1167
+	    	    }
862 1168
 	    	    $data['ident'] = $line['flightnum']; // ident
863 1169
 	    	    $data['altitude'] = $line['alt']; // altitude
864 1170
 	    	    $data['speed'] = $line['gs']; // speed
@@ -876,27 +1182,41 @@  discard block
 block discarded – undo
876 1182
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
877 1183
     		    $data['arrival_airport_time'] = $line['arrtime'];
878 1184
     		    $data['registration'] = $line['aircraft'];
879
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1185
+		    if (isset($line['route'])) {
1186
+		    	$data['waypoints'] = $line['route'];
1187
+		    }
1188
+		    // route
880 1189
 		    if (isset($line['aircraftname'])) {
881 1190
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
882 1191
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
883 1192
 	    		$aircraft_data = explode('-',$line['aircraftname']);
884
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
885
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
886
-	    		else {
1193
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) {
1194
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1195
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) {
1196
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1197
+	    		} else {
887 1198
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
888
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
889
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
1199
+	    		    if (isset($aircraft_data[1])) {
1200
+	    		    	$data['aircraft_icao'] = $aircraft_data[1];
1201
+	    		    } else {
1202
+	    		    	$data['aircraft_icao'] = $line['aircraftname'];
1203
+	    		    }
890 1204
 	    		}
891 1205
 	    	    }
892
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1206
+    		    if (isset($line['route'])) {
1207
+    		    	$data['waypoints'] = $line['route'];
1208
+    		    }
893 1209
     		    $data['id_source'] = $id_source;
894 1210
 	    	    $data['format_source'] = 'phpvmacars';
895
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1211
+		    if (isset($value['name']) && $value['name'] != '') {
1212
+		    	$data['source_name'] = $value['name'];
1213
+		    }
896 1214
 		    $SI->add($data);
897 1215
 		    unset($data);
898 1216
 		}
899
-		if ($globalDebug) echo 'No more data...'."\n";
1217
+		if ($globalDebug) {
1218
+			echo 'No more data...'."\n";
1219
+		}
900 1220
 		unset($buffer);
901 1221
 		unset($all_data);
902 1222
 	    }
@@ -904,7 +1224,9 @@  discard block
 block discarded – undo
904 1224
     	    $last_exec[$id]['last'] = time();
905 1225
     	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
906 1226
 	    //$buffer = $Common->getData($hosts[$id]);
907
-	    if ($globalDebug) echo 'Get Data...'."\n";
1227
+	    if ($globalDebug) {
1228
+	    	echo 'Get Data...'."\n";
1229
+	    }
908 1230
 	    $buffer = $Common->getData($value['host']);
909 1231
 	    $all_data = json_decode($buffer,true);
910 1232
 	    if ($buffer != '' && is_array($all_data)) {
@@ -933,15 +1255,22 @@  discard block
 block discarded – undo
933 1255
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
934 1256
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
935 1257
     		    //$data['registration'] = $line['aircraft'];
936
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1258
+		    if (isset($line['route'])) {
1259
+		    	$data['waypoints'] = $line['route'];
1260
+		    }
1261
+		    // route
937 1262
 	    	    $data['aircraft_icao'] = $line['plane_type'];
938 1263
     		    $data['id_source'] = $id_source;
939 1264
 	    	    $data['format_source'] = 'vam';
940
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1265
+		    if (isset($value['name']) && $value['name'] != '') {
1266
+		    	$data['source_name'] = $value['name'];
1267
+		    }
941 1268
 		    $SI->add($data);
942 1269
 		    unset($data);
943 1270
 		}
944
-		if ($globalDebug) echo 'No more data...'."\n";
1271
+		if ($globalDebug) {
1272
+			echo 'No more data...'."\n";
1273
+		}
945 1274
 		unset($buffer);
946 1275
 		unset($all_data);
947 1276
 	    }
@@ -949,7 +1278,9 @@  discard block
 block discarded – undo
949 1278
     	    $last_exec[$id]['last'] = time();
950 1279
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
951 1280
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais') {
952
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1281
+	    if (function_exists('pcntl_fork')) {
1282
+	    	pcntl_signal_dispatch();
1283
+	    }
953 1284
     	    //$last_exec[$id]['last'] = time();
954 1285
 
955 1286
 	    //$read = array( $sockets[$id] );
@@ -957,7 +1288,9 @@  discard block
 block discarded – undo
957 1288
 	    $write = NULL;
958 1289
 	    $e = NULL;
959 1290
 	    $n = socket_select($read, $write, $e, $timeout);
960
-	    if ($e != NULL) var_dump($e);
1291
+	    if ($e != NULL) {
1292
+	    	var_dump($e);
1293
+	    }
961 1294
 	    if ($n > 0) {
962 1295
 		$reset = 0;
963 1296
 		foreach ($read as $nb => $r) {
@@ -979,7 +1312,9 @@  discard block
 block discarded – undo
979 1312
 		    if ($buffer != '') {
980 1313
 			$tt[$format] = 0;
981 1314
 			if ($format == 'acarssbs3') {
982
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1315
+                    	    if ($globalDebug) {
1316
+                    	    	echo 'ACARS : '.$buffer."\n";
1317
+                    	    }
983 1318
 			    $ACARS->add(trim($buffer));
984 1319
 			    $ACARS->deleteLiveAcarsData();
985 1320
 			} elseif ($format == 'raw') {
@@ -988,25 +1323,55 @@  discard block
 block discarded – undo
988 1323
 			    if (is_array($data)) {
989 1324
 				$data['datetime'] = date('Y-m-d H:i:s');
990 1325
 				$data['format_source'] = 'raw';
991
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
992
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
993
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1326
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1327
+					$data['source_name'] = $globalSources[$nb]['name'];
1328
+				}
1329
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1330
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1331
+    				}
1332
+                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1333
+                                	$SI->add($data);
1334
+                                }
994 1335
                             }
995 1336
                         } elseif ($format == 'ais') {
996 1337
 			    $ais_data = $AIS->parse_line(trim($buffer));
997 1338
 			    $data = array();
998
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
999
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1000
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1001
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1002
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1003
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1004
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1005
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1006
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1007
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1008
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1009
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1339
+			    if (isset($ais_data['ident'])) {
1340
+			    	$data['ident'] = $ais_data['ident'];
1341
+			    }
1342
+			    if (isset($ais_data['mmsi'])) {
1343
+			    	$data['mmsi'] = $ais_data['mmsi'];
1344
+			    }
1345
+			    if (isset($ais_data['speed'])) {
1346
+			    	$data['speed'] = $ais_data['speed'];
1347
+			    }
1348
+			    if (isset($ais_data['heading'])) {
1349
+			    	$data['heading'] = $ais_data['heading'];
1350
+			    }
1351
+			    if (isset($ais_data['latitude'])) {
1352
+			    	$data['latitude'] = $ais_data['latitude'];
1353
+			    }
1354
+			    if (isset($ais_data['longitude'])) {
1355
+			    	$data['longitude'] = $ais_data['longitude'];
1356
+			    }
1357
+			    if (isset($ais_data['status'])) {
1358
+			    	$data['status'] = $ais_data['status'];
1359
+			    }
1360
+			    if (isset($ais_data['type'])) {
1361
+			    	$data['type'] = $ais_data['type'];
1362
+			    }
1363
+			    if (isset($ais_data['imo'])) {
1364
+			    	$data['imo'] = $ais_data['imo'];
1365
+			    }
1366
+			    if (isset($ais_data['callsign'])) {
1367
+			    	$data['callsign'] = $ais_data['callsign'];
1368
+			    }
1369
+			    if (isset($ais_data['destination'])) {
1370
+			    	$data['arrival_code'] = $ais_data['destination'];
1371
+			    }
1372
+			    if (isset($ais_data['eta_ts'])) {
1373
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1374
+			    }
1010 1375
 
1011 1376
 			    if (isset($ais_data['timestamp'])) {
1012 1377
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1015,7 +1380,9 @@  discard block
 block discarded – undo
1015 1380
 			    }
1016 1381
 			    $data['format_source'] = 'aisnmea';
1017 1382
     			    $data['id_source'] = $id_source;
1018
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1383
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
1384
+			    	$MI->add($data);
1385
+			    }
1019 1386
 			    unset($data);
1020 1387
                         } elseif ($format == 'flightgearsp') {
1021 1388
                     	    //echo $buffer."\n";
@@ -1033,11 +1400,15 @@  discard block
 block discarded – undo
1033 1400
 				$data['speed'] = round($line[5]*1.94384);
1034 1401
 				$data['datetime'] = date('Y-m-d H:i:s');
1035 1402
 				$data['format_source'] = 'flightgearsp';
1036
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1403
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1404
+					$SI->add($data);
1405
+				}
1037 1406
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1038 1407
 			    }
1039 1408
                         } elseif ($format == 'acars') {
1040
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1409
+                    	    if ($globalDebug) {
1410
+                    	    	echo 'ACARS : '.$buffer."\n";
1411
+                    	    }
1041 1412
 			    $ACARS->add(trim($buffer));
1042 1413
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1043 1414
 			    $ACARS->deleteLiveAcarsData();
@@ -1058,7 +1429,9 @@  discard block
 block discarded – undo
1058 1429
 				    $aircraft_type = $line[10];
1059 1430
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1060 1431
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1061
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1432
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1433
+				    	$SI->add($data);
1434
+				    }
1062 1435
 				}
1063 1436
 			    }
1064 1437
 			} elseif ($format == 'beast') {
@@ -1074,21 +1447,43 @@  discard block
 block discarded – undo
1074 1447
     				$data['hex'] = $lined['hexid'];
1075 1448
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1076 1449
     				$data['datetime'] = date('Y-m-d H:i:s');;
1077
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1078
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1079
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1080
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1081
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1082
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1083
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1450
+    				if (isset($lined['ident'])) {
1451
+    					$data['ident'] = $lined['ident'];
1452
+    				}
1453
+    				if (isset($lined['lat'])) {
1454
+    					$data['latitude'] = $lined['lat'];
1455
+    				}
1456
+    				if (isset($lined['lon'])) {
1457
+    					$data['longitude'] = $lined['lon'];
1458
+    				}
1459
+    				if (isset($lined['speed'])) {
1460
+    					$data['speed'] = $lined['speed'];
1461
+    				}
1462
+    				if (isset($lined['squawk'])) {
1463
+    					$data['squawk'] = $lined['squawk'];
1464
+    				}
1465
+    				if (isset($lined['alt'])) {
1466
+    					$data['altitude'] = $lined['alt'];
1467
+    				}
1468
+    				if (isset($lined['heading'])) {
1469
+    					$data['heading'] = $lined['heading'];
1470
+    				}
1084 1471
     				$data['id_source'] = $id_source;
1085 1472
     				$data['format_source'] = 'tsv';
1086
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1087
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1088
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1473
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1474
+    					$data['source_name'] = $globalSources[$nb]['name'];
1475
+    				}
1476
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1477
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1478
+    				}
1479
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1480
+    					$SI->add($data);
1481
+    				}
1089 1482
     				unset($lined);
1090 1483
     				unset($data);
1091
-    			    } else $error = true;
1484
+    			    } else {
1485
+    			    	$error = true;
1486
+    			    }
1092 1487
 			} elseif ($format == 'aprs' && $use_aprs) {
1093 1488
 			    if ($aprs_connect == 0) {
1094 1489
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1113,47 +1508,72 @@  discard block
 block discarded – undo
1113 1508
 				    $aprs_last_tx = time();
1114 1509
 				    $data = array();
1115 1510
 				    //print_r($line);
1116
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1117
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1118
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1511
+				    if (isset($line['address'])) {
1512
+				    	$data['hex'] = $line['address'];
1513
+				    }
1514
+				    if (isset($line['timestamp'])) {
1515
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1516
+				    } else {
1517
+				    	$data['datetime'] = date('Y-m-d H:i:s');
1518
+				    }
1119 1519
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1120 1520
 				    $data['ident'] = $line['ident'];
1121 1521
 				    $data['latitude'] = $line['latitude'];
1122 1522
 				    $data['longitude'] = $line['longitude'];
1123 1523
 				    //$data['verticalrate'] = $line[16];
1124
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1125
-				    else $data['speed'] = 0;
1126
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1127
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1128
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1129
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1524
+				    if (isset($line['speed'])) {
1525
+				    	$data['speed'] = $line['speed'];
1526
+				    } else {
1527
+				    	$data['speed'] = 0;
1528
+				    }
1529
+				    if (isset($line['altitude'])) {
1530
+				    	$data['altitude'] = $line['altitude'];
1531
+				    }
1532
+				    if (isset($line['comment'])) {
1533
+				    	$data['comment'] = $line['comment'];
1534
+				    }
1535
+				    if (isset($line['symbol'])) {
1536
+				    	$data['type'] = $line['symbol'];
1537
+				    }
1538
+				    if (isset($line['heading'])) {
1539
+				    	$data['heading'] = $line['heading'];
1540
+				    }
1130 1541
 				    //else $data['heading'] = 0;
1131
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1132
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1542
+				    if (isset($line['stealth'])) {
1543
+				    	$data['aircraft_type'] = $line['stealth'];
1544
+				    }
1545
+				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) {
1546
+				    	$data['noarchive'] = true;
1547
+				    }
1133 1548
     				    $data['id_source'] = $id_source;
1134 1549
 				    $data['format_source'] = 'aprs';
1135 1550
 				    $data['source_name'] = $line['source'];
1136 1551
 				    $data['source_type'] = 'flarm';
1137
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1552
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
1553
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1554
+    				    }
1138 1555
 				    $currentdate = date('Y-m-d H:i:s');
1139 1556
 				    $aprsdate = strtotime($data['datetime']);
1140 1557
 				    // Accept data if time <= system time + 20s
1141 1558
 				    if (isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1142 1559
 					$send = $SI->add($data);
1143 1560
 				    } elseif (isset($line['stealth'])) {
1144
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1145
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1561
+					if ($line['stealth'] != 0) {
1562
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1563
+					} else {
1564
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1565
+					}
1146 1566
 				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1147 1567
 				    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1148 1568
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1149
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1569
+					if (isset($globalTracker) && $globalTracker) {
1570
+						$send = $TI->add($data);
1571
+					}
1150 1572
 				    }
1151 1573
 				    unset($data);
1152
-				} 
1153
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1574
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1154 1575
 					echo '!! Weather Station not yet supported'."\n";
1155
-				}
1156
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle')) {
1576
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle')) {
1157 1577
 					echo '!! Car & Trucks not yet supported'."\n";
1158 1578
 				}
1159 1579
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
@@ -1186,25 +1606,42 @@  discard block
 block discarded – undo
1186 1606
     				$data['ground'] = $line[21];
1187 1607
     				$data['emergency'] = $line[19];
1188 1608
     				$data['format_source'] = 'sbs';
1189
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1190
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1609
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1610
+					$data['source_name'] = $globalSources[$nb]['name'];
1611
+				}
1612
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1613
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1614
+    				}
1191 1615
     				$data['id_source'] = $id_source;
1192
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1193
-    				else $error = true;
1616
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1617
+    					$send = $SI->add($data);
1618
+    				} else {
1619
+    					$error = true;
1620
+    				}
1194 1621
     				unset($data);
1195
-    			    } else $error = true;
1622
+    			    } else {
1623
+    			    	$error = true;
1624
+    			    }
1196 1625
 			    if ($error) {
1197 1626
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1198
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
1627
+					if ($globalDebug) {
1628
+						echo "Not a message. Ignoring... \n";
1629
+					}
1199 1630
 				} else {
1200
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
1631
+					if ($globalDebug) {
1632
+						echo "Wrong line format. Ignoring... \n";
1633
+					}
1201 1634
 					if ($globalDebug) {
1202 1635
 						echo $buffer;
1203 1636
 						print_r($line);
1204 1637
 					}
1205 1638
 					//socket_close($r);
1206
-					if ($globalDebug) echo "Reconnect after an error...\n";
1207
-					if ($format == 'aprs') $aprs_connect = 0;
1639
+					if ($globalDebug) {
1640
+						echo "Reconnect after an error...\n";
1641
+					}
1642
+					if ($format == 'aprs') {
1643
+						$aprs_connect = 0;
1644
+					}
1208 1645
 					$sourceer[$nb] = $globalSources[$nb];
1209 1646
 					connect_all($sourceer);
1210 1647
 					$sourceer = array();
@@ -1212,10 +1649,14 @@  discard block
 block discarded – undo
1212 1649
 			    }
1213 1650
 			}
1214 1651
 			// Sleep for xxx microseconds
1215
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1652
+			if (isset($globalSBSSleep)) {
1653
+				usleep($globalSBSSleep);
1654
+			}
1216 1655
 		    } else {
1217 1656
 			if ($format == 'flightgearmp') {
1218
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1657
+			    	if ($globalDebug) {
1658
+			    		echo "Reconnect FlightGear MP...";
1659
+			    	}
1219 1660
 				//@socket_close($r);
1220 1661
 				sleep($globalMinFetch);
1221 1662
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1224,10 +1665,15 @@  discard block
 block discarded – undo
1224 1665
 				break;
1225 1666
 				
1226 1667
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1227
-			    if (isset($tt[$format])) $tt[$format]++;
1228
-			    else $tt[$format] = 0;
1668
+			    if (isset($tt[$format])) {
1669
+			    	$tt[$format]++;
1670
+			    } else {
1671
+			    	$tt[$format] = 0;
1672
+			    }
1229 1673
 			    if ($tt[$format] > 30) {
1230
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1674
+				if ($globalDebug) {
1675
+					echo "ERROR : Reconnect ".$format."...";
1676
+				}
1231 1677
 				//@socket_close($r);
1232 1678
 				sleep(2);
1233 1679
 				$aprs_connect = 0;
@@ -1244,11 +1690,17 @@  discard block
 block discarded – undo
1244 1690
 	    } else {
1245 1691
 		$error = socket_strerror(socket_last_error());
1246 1692
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1247
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1248
-			if (isset($globalDebug)) echo "Restarting...\n";
1693
+			if ($globalDebug) {
1694
+				echo "ERROR : socket_select give this error ".$error . "\n";
1695
+			}
1696
+			if (isset($globalDebug)) {
1697
+				echo "Restarting...\n";
1698
+			}
1249 1699
 			// Restart the script if possible
1250 1700
 			if (is_array($sockets)) {
1251
-			    if ($globalDebug) echo "Shutdown all sockets...";
1701
+			    if ($globalDebug) {
1702
+			    	echo "Shutdown all sockets...";
1703
+			    }
1252 1704
 			    
1253 1705
 			    foreach ($sockets as $sock) {
1254 1706
 				@socket_shutdown($sock,2);
@@ -1256,18 +1708,24 @@  discard block
 block discarded – undo
1256 1708
 			    }
1257 1709
 			    
1258 1710
 			}
1259
-			if ($globalDebug) echo "Restart all connections...";
1711
+			if ($globalDebug) {
1712
+				echo "Restart all connections...";
1713
+			}
1260 1714
 			sleep(2);
1261 1715
 			$time = time();
1262 1716
 			//connect_all($hosts);
1263 1717
 			$aprs_connect = 0;
1264
-			if ($reset > 40) exit('Too many attempts...');
1718
+			if ($reset > 40) {
1719
+				exit('Too many attempts...');
1720
+			}
1265 1721
 			connect_all($globalSources);
1266 1722
 		}
1267 1723
 	    }
1268 1724
 	}
1269 1725
 	if ($globalDaemon === false) {
1270
-	    if ($globalDebug) echo 'Check all...'."\n";
1726
+	    if ($globalDebug) {
1727
+	    	echo 'Check all...'."\n";
1728
+	    }
1271 1729
 	    $SI->checkAll();
1272 1730
 	}
1273 1731
     }
Please login to merge, or discard this patch.
require/class.MarineImport.php 3 patches
Indentation   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -9,16 +9,16 @@  discard block
 block discarded – undo
9 9
 require_once(dirname(__FILE__).'/class.Source.php');
10 10
 
11 11
 class MarineImport {
12
-    private $all_tracked = array();
13
-    private $last_delete_hourly = 0;
14
-    private $last_delete = 0;
15
-    private $stats = array();
16
-    private $tmd = 0;
17
-    private $source_location = array();
18
-    public $db = null;
19
-    public $nb = 0;
12
+	private $all_tracked = array();
13
+	private $last_delete_hourly = 0;
14
+	private $last_delete = 0;
15
+	private $stats = array();
16
+	private $tmd = 0;
17
+	private $source_location = array();
18
+	public $db = null;
19
+	public $nb = 0;
20 20
 
21
-    public function __construct($dbc = null) {
21
+	public function __construct($dbc = null) {
22 22
 	global $globalBeta;
23 23
 	$Connection = new Connection($dbc);
24 24
 	$this->db = $Connection->db();
@@ -40,50 +40,50 @@  discard block
 block discarded – undo
40 40
 	    }
41 41
 	}
42 42
 	*/
43
-    }
43
+	}
44 44
 
45
-    public function checkAll() {
45
+	public function checkAll() {
46 46
 	global $globalDebug;
47 47
 	if ($globalDebug) echo "Update last seen tracked data...\n";
48 48
 	foreach ($this->all_tracked as $key => $flight) {
49
-	    if (isset($this->all_tracked[$key]['id'])) {
49
+		if (isset($this->all_tracked[$key]['id'])) {
50 50
 		//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
51
-    		$Marine = new Marine($this->db);
52
-        	$Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
53
-            }
51
+			$Marine = new Marine($this->db);
52
+			$Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
53
+			}
54
+	}
54 55
 	}
55
-    }
56 56
 
57
-    public function del() {
57
+	public function del() {
58 58
 	global $globalDebug;
59 59
 	// Delete old infos
60 60
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
61 61
 	foreach ($this->all_tracked as $key => $flight) {
62
-    	    if (isset($flight['lastupdate'])) {
63
-        	if ($flight['lastupdate'] < (time()-3000)) {
64
-            	    if (isset($this->all_tracked[$key]['id'])) {
65
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
62
+			if (isset($flight['lastupdate'])) {
63
+			if ($flight['lastupdate'] < (time()-3000)) {
64
+					if (isset($this->all_tracked[$key]['id'])) {
65
+					if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
66 66
 			/*
67 67
 			$MarineLive = new MarineLive();
68 68
             		$MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']);
69 69
 			$MarineLive->db = null;
70 70
 			*/
71
-            		//$real_arrival = $this->arrival($key);
72
-            		$Marine = new Marine($this->db);
73
-            		if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
71
+					//$real_arrival = $this->arrival($key);
72
+					$Marine = new Marine($this->db);
73
+					if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
74 74
 				$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed']);
75 75
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
76 76
 			}
77 77
 			// Put in archive
78 78
 //			$Marine->db = null;
79
-            	    }
80
-            	    unset($this->all_tracked[$key]);
81
-    	        }
82
-	    }
83
-        }
84
-    }
79
+					}
80
+					unset($this->all_tracked[$key]);
81
+				}
82
+		}
83
+		}
84
+	}
85 85
 
86
-    public function add($line) {
86
+	public function add($line) {
87 87
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked;
88 88
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
89 89
 	date_default_timezone_set('UTC');
@@ -92,8 +92,8 @@  discard block
 block discarded – undo
92 92
 	
93 93
 	// SBS format is CSV format
94 94
 	if(is_array($line) && isset($line['mmsi'])) {
95
-	    //print_r($line);
96
-  	    if (isset($line['mmsi'])) {
95
+		//print_r($line);
96
+  		if (isset($line['mmsi'])) {
97 97
 
98 98
 		/*
99 99
 		// Increment message number
@@ -109,84 +109,84 @@  discard block
 block discarded – undo
109 109
 		*/
110 110
 		
111 111
 		$Common = new Common();
112
-	        if (!isset($line['id'])) $id = trim($line['mmsi']);
113
-	        else $id = trim($line['id']);
112
+			if (!isset($line['id'])) $id = trim($line['mmsi']);
113
+			else $id = trim($line['id']);
114 114
 		
115 115
 		if (!isset($this->all_tracked[$id])) {
116
-		    $this->all_tracked[$id] = array();
117
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
118
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => ''));
119
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
120
-		    if (!isset($line['id'])) {
116
+			$this->all_tracked[$id] = array();
117
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
118
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => ''));
119
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
120
+			if (!isset($line['id'])) {
121 121
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
122 122
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
123
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
124
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
123
+			 } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
124
+			if ($globalAllTracked !== FALSE) $dataFound = true;
125 125
 		}
126 126
 		
127 127
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
128
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
129
-		    $Marine = new Marine($this->db);
130
-		    $identity = $Marine->getIdentity($line['mmsi']);
131
-		    if (!empty($identity)) {
128
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
129
+			$Marine = new Marine($this->db);
130
+			$identity = $Marine->getIdentity($line['mmsi']);
131
+			if (!empty($identity)) {
132 132
 			$this->all_tracked[$id]['ident'] = $identity['ship_name'];
133 133
 			$this->all_tracked[$id]['type'] = $identity['type'];
134
-		    }
135
-		    //print_r($identity);
136
-		    unset($Marine);
137
-		    //$dataFound = true;
134
+			}
135
+			//print_r($identity);
136
+			unset($Marine);
137
+			//$dataFound = true;
138 138
 		}
139 139
 		if (isset($line['type']) && $line['type'] != '') {
140
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
140
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
141 141
 		}
142 142
 		if (isset($line['imo']) && $line['imo'] != '') {
143
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
143
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
144 144
 		}
145 145
 		if (isset($line['callsign']) && $line['callsign'] != '') {
146
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
146
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
147 147
 		}
148 148
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
149
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
149
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
150 150
 		}
151 151
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
152
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
152
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
153 153
 		}
154 154
 
155 155
 
156 156
 		//if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9-]+$/', $line['ident'])) {
157 157
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
158
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
159
-		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
158
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
159
+			if ($this->all_tracked[$id]['addedMarine'] == 1) {
160 160
 			$timeelapsed = microtime(true);
161
-            		$Marine = new Marine($this->db);
162
-            		$fromsource = NULL;
163
-            		$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
161
+					$Marine = new Marine($this->db);
162
+					$fromsource = NULL;
163
+					$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
164 164
 			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
165 165
 			$Marine->db = null;
166 166
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
167
-		    }
168
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
167
+			}
168
+			if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
169 169
 		}
170 170
 
171 171
 		if (isset($line['speed']) && $line['speed'] != '') {
172
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
173
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
172
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
173
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
174 174
 		} else if (!isset($this->all_tracked[$id]['speed_fromsrc']) && isset($this->all_tracked[$id]['time_last_coord']) && $this->all_tracked[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
175
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
176
-		    if ($distance > 1000 && $distance < 10000) {
175
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
176
+			if ($distance > 1000 && $distance < 10000) {
177 177
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
178 178
 			$speed = $speed*3.6;
179 179
 			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
180 180
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
181
-		    }
181
+			}
182 182
 		}
183 183
 
184
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
185
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
186
-	    	    else unset($timediff);
187
-	    	    if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) {
184
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
185
+				if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
186
+				else unset($timediff);
187
+				if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) {
188 188
 			if (isset($this->all_tracked[$id]['archive_latitude']) && isset($this->all_tracked[$id]['archive_longitude']) && isset($this->all_tracked[$id]['livedb_latitude']) && isset($this->all_tracked[$id]['livedb_longitude'])) {
189
-			    if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
189
+				if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
190 190
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
191 191
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
192 192
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -200,76 +200,76 @@  discard block
 block discarded – undo
200 200
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
201 201
 				$this->tmd = 0;
202 202
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
203
-			    }
203
+				}
204 204
 			}
205 205
 
206 206
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
207 207
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
208 208
 				if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
209
-				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
210
-				    $dataFound = true;
211
-				    $this->all_tracked[$id]['time_last_coord'] = time();
209
+					$this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
210
+					$dataFound = true;
211
+					$this->all_tracked[$id]['time_last_coord'] = time();
212 212
 				}
213 213
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
214 214
 			}
215 215
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
216
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
216
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
217 217
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
218 218
 				if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
219
-				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
220
-				    $dataFound = true;
221
-				    $this->all_tracked[$id]['time_last_coord'] = time();
219
+					$this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
220
+					$dataFound = true;
221
+					$this->all_tracked[$id]['time_last_coord'] = time();
222 222
 				}
223 223
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
224 224
 			}
225 225
 
226
-		    } else if ($globalDebug && $timediff > 20) {
226
+			} else if ($globalDebug && $timediff > 20) {
227 227
 			$this->tmd = $this->tmd + 1;
228 228
 			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
229 229
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
230 230
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
231 231
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
232
-		    }
232
+			}
233 233
 		}
234 234
 		if (isset($line['last_update']) && $line['last_update'] != '') {
235
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
236
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
235
+			if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
236
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
237 237
 		}
238 238
 		if (isset($line['format_source']) && $line['format_source'] != '') {
239
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
239
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
240 240
 		}
241 241
 		if (isset($line['source_name']) && $line['source_name'] != '') {
242
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
242
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
243 243
 		}
244 244
 		if (isset($line['status']) && $line['status'] != '') {
245
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
245
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
246 246
 		}
247 247
 
248 248
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
249
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
249
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
250 250
 		}
251 251
 		
252 252
 		if (isset($line['heading']) && $line['heading'] != '') {
253
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
254
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
255
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
256
-		    //$dataFound = true;
253
+			if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
254
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
255
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
256
+			//$dataFound = true;
257 257
   		} elseif (!isset($this->all_tracked[$id]['heading_fromsrc']) && isset($this->all_tracked[$id]['archive_latitude']) && $this->all_tracked[$id]['archive_latitude'] != $this->all_tracked[$id]['latitude'] && isset($this->all_tracked[$id]['archive_longitude']) && $this->all_tracked[$id]['archive_longitude'] != $this->all_tracked[$id]['longitude']) {
258
-  		    $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
259
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
260
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
261
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
258
+  			$heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
259
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
260
+			if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
261
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
262 262
   		}
263 263
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
264 264
 
265 265
 		if (isset($line['datetime'])) {
266
-		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
266
+			if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
267 267
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
268
-		    } else {
268
+			} else {
269 269
 				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
270 270
 				elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
271 271
 				return '';
272
-		    }
272
+			}
273 273
 		} else {
274 274
 			date_default_timezone_set('UTC');
275 275
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
@@ -277,45 +277,45 @@  discard block
 block discarded – undo
277 277
 
278 278
 
279 279
 		if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) {
280
-		    $this->all_tracked[$id]['lastupdate'] = time();
281
-		    if ($this->all_tracked[$id]['addedMarine'] == 0) {
282
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == ''  || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
283
-			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
280
+			$this->all_tracked[$id]['lastupdate'] = time();
281
+			if ($this->all_tracked[$id]['addedMarine'] == 0) {
282
+				if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == ''  || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
283
+				if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
284 284
 				if ($globalDebug) echo "Check if aircraft is already in DB...";
285 285
 				$timeelapsed = microtime(true);
286 286
 				$MarineLive = new MarineLive($this->db);
287 287
 				if (isset($line['id'])) {
288
-				    $recent_ident = $MarineLive->checkIdRecent($line['id']);
289
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
288
+					$recent_ident = $MarineLive->checkIdRecent($line['id']);
289
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
290 290
 				} elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
291
-				    $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
292
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
291
+					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
292
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
293 293
 				} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
294
-				    $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
295
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
294
+					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
295
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
296 296
 				} else $recent_ident = '';
297 297
 				$MarineLive->db=null;
298 298
 				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
299 299
 				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
300
-			    } else {
300
+				} else {
301 301
 				$recent_ident = '';
302 302
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
303
-			    }
304
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
305
-			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
306
-			    {
303
+				}
304
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
305
+				if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
306
+				{
307 307
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
308 308
 				//adds the spotter data for the archive
309
-				    $highlight = '';
310
-				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
311
-				    $timeelapsed = microtime(true);
312
-				    $Marine = new Marine($this->db);
313
-				    $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
314
-				    $Marine->db = null;
315
-				    if ($globalDebug && isset($result)) echo $result."\n";
316
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
309
+					$highlight = '';
310
+					if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
311
+					$timeelapsed = microtime(true);
312
+					$Marine = new Marine($this->db);
313
+					$result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
314
+					$Marine->db = null;
315
+					if ($globalDebug && isset($result)) echo $result."\n";
316
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
317 317
 				    
318
-				    /*
318
+					/*
319 319
 				    // Add source stat in DB
320 320
 				    $Stats = new Stats($this->db);
321 321
 				    if (!empty($this->stats)) {
@@ -342,20 +342,20 @@  discard block
 block discarded – undo
342 342
 				    }
343 343
 				    $Stats->db = null;
344 344
 				    */
345
-				    $this->del();
345
+					$this->del();
346 346
 				//$ignoreImport = false;
347 347
 				$this->all_tracked[$id]['addedMarine'] = 1;
348 348
 				//print_r($this->all_tracked[$id]);
349 349
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
350
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
351
-				    //MarineLive->deleteLiveMarineDataNotUpdated();
352
-				    $MarineLive = new MarineLive($this->db);
353
-				    $MarineLive->deleteLiveMarineData();
354
-				    $MarineLive->db=null;
355
-				    if ($globalDebug) echo " Done\n";
356
-				    $this->last_delete = time();
350
+					if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
351
+					//MarineLive->deleteLiveMarineDataNotUpdated();
352
+					$MarineLive = new MarineLive($this->db);
353
+					$MarineLive->deleteLiveMarineData();
354
+					$MarineLive->db=null;
355
+					if ($globalDebug) echo " Done\n";
356
+					$this->last_delete = time();
357 357
 				}
358
-			    } elseif ($recent_ident != '') {
358
+				} elseif ($recent_ident != '') {
359 359
 				$this->all_tracked[$id]['id'] = $recent_ident;
360 360
 				$this->all_tracked[$id]['addedMarine'] = 1;
361 361
 				if (isset($globalDaemon) && !$globalDaemon) {
@@ -364,16 +364,16 @@  discard block
 block discarded – undo
364 364
 					$Marine->db = null;
365 365
 				}
366 366
 				
367
-			    }
367
+				}
368
+			}
368 369
 			}
369
-		    }
370
-		    //adds the spotter LIVE data
371
-		    if ($globalDebug) {
370
+			//adds the spotter LIVE data
371
+			if ($globalDebug) {
372 372
 			echo 'DATA : ident : '.$this->all_tracked[$id]['ident'].' - type : '.$this->all_tracked[$id]['type'].' - Latitude : '.$this->all_tracked[$id]['latitude'].' - Longitude : '.$this->all_tracked[$id]['longitude'].' - Heading : '.$this->all_tracked[$id]['heading'].' - Speed : '.$this->all_tracked[$id]['speed']."\n";
373
-		    }
374
-		    $ignoreImport = false;
373
+			}
374
+			$ignoreImport = false;
375 375
 
376
-		    if (!$ignoreImport) {
376
+			if (!$ignoreImport) {
377 377
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
378 378
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
379 379
 				$timeelapsed = microtime(true);
@@ -445,22 +445,22 @@  discard block
 block discarded – undo
445 445
 			
446 446
 			
447 447
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
448
-			    if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
449
-			    $MarineLive = new MarineLive($this->db);
450
-			    $MarineLive->deleteLiveMarineDataNotUpdated();
451
-			    $MarineLive->db = null;
452
-			    //MarineLive->deleteLiveMarineData();
453
-			    if ($globalDebug) echo " Done\n";
454
-			    $this->last_delete_hourly = time();
448
+				if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
449
+				$MarineLive = new MarineLive($this->db);
450
+				$MarineLive->deleteLiveMarineDataNotUpdated();
451
+				$MarineLive->db = null;
452
+				//MarineLive->deleteLiveMarineData();
453
+				if ($globalDebug) echo " Done\n";
454
+				$this->last_delete_hourly = time();
455 455
 			}
456 456
 			
457
-		    }
458
-		    //$ignoreImport = false;
457
+			}
458
+			//$ignoreImport = false;
459 459
 		}
460 460
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
461 461
 		if ($send) return $this->all_tracked[$id];
462
-	    }
462
+		}
463
+	}
463 464
 	}
464
-    }
465 465
 }
466 466
 ?>
Please login to merge, or discard this patch.
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 	    if (isset($this->all_tracked[$key]['id'])) {
50 50
 		//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
51 51
     		$Marine = new Marine($this->db);
52
-        	$Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
52
+        	$Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed'], $this->all_tracked[$key]['datetime']);
53 53
             }
54 54
 	}
55 55
     }
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
61 61
 	foreach ($this->all_tracked as $key => $flight) {
62 62
     	    if (isset($flight['lastupdate'])) {
63
-        	if ($flight['lastupdate'] < (time()-3000)) {
63
+        	if ($flight['lastupdate'] < (time() - 3000)) {
64 64
             	    if (isset($this->all_tracked[$key]['id'])) {
65 65
             		if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
66 66
 			/*
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
             		//$real_arrival = $this->arrival($key);
72 72
             		$Marine = new Marine($this->db);
73 73
             		if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
74
-				$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed']);
74
+				$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed']);
75 75
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
76 76
 			}
77 77
 			// Put in archive
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	$send = false;
92 92
 	
93 93
 	// SBS format is CSV format
94
-	if(is_array($line) && isset($line['mmsi'])) {
94
+	if (is_array($line) && isset($line['mmsi'])) {
95 95
 	    //print_r($line);
96 96
   	    if (isset($line['mmsi'])) {
97 97
 
@@ -114,18 +114,18 @@  discard block
 block discarded – undo
114 114
 		
115 115
 		if (!isset($this->all_tracked[$id])) {
116 116
 		    $this->all_tracked[$id] = array();
117
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
118
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => ''));
119
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
117
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('addedMarine' => 0));
118
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => '', 'latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '', 'source_name' => '', 'comment'=> '', 'type' => '', 'noarchive' => false, 'putinarchive' => true, 'over_country' => '', 'mmsi' => '', 'status' => '', 'imo' => '', 'callsign' => '', 'arrival_code' => '', 'arrival_date' => ''));
119
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('lastupdate' => time()));
120 120
 		    if (!isset($line['id'])) {
121 121
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
122
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
123
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
122
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $id.'-'.date('YmdHi')));
123
+		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $line['id']));
124 124
 		    if ($globalAllTracked !== FALSE) $dataFound = true;
125 125
 		}
126 126
 		
127 127
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
128
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
128
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('mmsi' => $line['mmsi']));
129 129
 		    $Marine = new Marine($this->db);
130 130
 		    $identity = $Marine->getIdentity($line['mmsi']);
131 131
 		    if (!empty($identity)) {
@@ -137,56 +137,56 @@  discard block
 block discarded – undo
137 137
 		    //$dataFound = true;
138 138
 		}
139 139
 		if (isset($line['type']) && $line['type'] != '') {
140
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
140
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $line['type']));
141 141
 		}
142 142
 		if (isset($line['imo']) && $line['imo'] != '') {
143
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
143
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('imo' => $line['imo']));
144 144
 		}
145 145
 		if (isset($line['callsign']) && $line['callsign'] != '') {
146
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
146
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('callsign' => $line['callsign']));
147 147
 		}
148 148
 		if (isset($line['arrival_code']) && $line['arrival_code'] != '') {
149
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code']));
149
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_code' => $line['arrival_code']));
150 150
 		}
151 151
 		if (isset($line['arrival_date']) && $line['arrival_date'] != '') {
152
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date']));
152
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_date' => $line['arrival_date']));
153 153
 		}
154 154
 
155 155
 
156 156
 		//if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9-]+$/', $line['ident'])) {
157 157
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
158
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
158
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => trim($line['ident'])));
159 159
 		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
160 160
 			$timeelapsed = microtime(true);
161 161
             		$Marine = new Marine($this->db);
162 162
             		$fromsource = NULL;
163
-            		$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
163
+            		$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $fromsource);
164 164
 			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
165 165
 			$Marine->db = null;
166
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
166
+			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
167 167
 		    }
168
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
168
+		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $this->all_tracked[$id]['ident']));
169 169
 		}
170 170
 
171 171
 		if (isset($line['speed']) && $line['speed'] != '') {
172
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
173
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
172
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($line['speed'])));
173
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed_fromsrc' => true));
174 174
 		} else if (!isset($this->all_tracked[$id]['speed_fromsrc']) && isset($this->all_tracked[$id]['time_last_coord']) && $this->all_tracked[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
175
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
175
+		    $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm');
176 176
 		    if ($distance > 1000 && $distance < 10000) {
177 177
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
178 178
 			$speed = $speed*3.6;
179
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
179
+			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($speed)));
180 180
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
181 181
 		    }
182 182
 		}
183 183
 
184 184
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
185
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
185
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time() - $this->all_tracked[$id]['time_last_coord']);
186 186
 	    	    else unset($timediff);
187
-	    	    if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) {
187
+	    	    if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff, $Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')))) {
188 188
 			if (isset($this->all_tracked[$id]['archive_latitude']) && isset($this->all_tracked[$id]['archive_longitude']) && isset($this->all_tracked[$id]['livedb_latitude']) && isset($this->all_tracked[$id]['livedb_longitude'])) {
189
-			    if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
189
+			    if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'], $this->all_tracked[$id]['archive_longitude'], $this->all_tracked[$id]['livedb_latitude'], $this->all_tracked[$id]['livedb_longitude'], $line['latitude'], $line['longitude'])) {
190 190
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
191 191
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
192 192
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -194,10 +194,10 @@  discard block
 block discarded – undo
194 194
 				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
195 195
 				$timeelapsed = microtime(true);
196 196
 				$Marine = new Marine($this->db);
197
-				$all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
197
+				$all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']);
198 198
 				if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
199 199
 				$Marine->db = null;
200
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
200
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
201 201
 				$this->tmd = 0;
202 202
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
203 203
 			    }
@@ -205,66 +205,66 @@  discard block
 block discarded – undo
205 205
 
206 206
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
207 207
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
208
-				if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
208
+				if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude'] - $line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
209 209
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
210 210
 				    $dataFound = true;
211 211
 				    $this->all_tracked[$id]['time_last_coord'] = time();
212 212
 				}
213
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
213
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('latitude' => $line['latitude']));
214 214
 			}
215 215
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
216 216
 			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
217 217
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
218
-				if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
218
+				if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude'] - $line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
219 219
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
220 220
 				    $dataFound = true;
221 221
 				    $this->all_tracked[$id]['time_last_coord'] = time();
222 222
 				}
223
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
223
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('longitude' => $line['longitude']));
224 224
 			}
225 225
 
226 226
 		    } else if ($globalDebug && $timediff > 20) {
227 227
 			$this->tmd = $this->tmd + 1;
228 228
 			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
229
-			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
230
-			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
229
+			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')."m -";
230
+			echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - ";
231 231
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
232 232
 		    }
233 233
 		}
234 234
 		if (isset($line['last_update']) && $line['last_update'] != '') {
235 235
 		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
236
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
236
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('last_update' => $line['last_update']));
237 237
 		}
238 238
 		if (isset($line['format_source']) && $line['format_source'] != '') {
239
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
239
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('format_source' => $line['format_source']));
240 240
 		}
241 241
 		if (isset($line['source_name']) && $line['source_name'] != '') {
242
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
242
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('source_name' => $line['source_name']));
243 243
 		}
244 244
 		if (isset($line['status']) && $line['status'] != '') {
245
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
245
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status' => $line['status']));
246 246
 		}
247 247
 
248 248
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
249
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
249
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('noarchive' => true));
250 250
 		}
251 251
 		
252 252
 		if (isset($line['heading']) && $line['heading'] != '') {
253
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
254
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
255
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
253
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading'] - round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
254
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($line['heading'])));
255
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading_fromsrc' => true));
256 256
 		    //$dataFound = true;
257 257
   		} elseif (!isset($this->all_tracked[$id]['heading_fromsrc']) && isset($this->all_tracked[$id]['archive_latitude']) && $this->all_tracked[$id]['archive_latitude'] != $this->all_tracked[$id]['latitude'] && isset($this->all_tracked[$id]['archive_longitude']) && $this->all_tracked[$id]['archive_longitude'] != $this->all_tracked[$id]['longitude']) {
258
-  		    $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
259
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
260
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
258
+  		    $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'], $this->all_tracked[$id]['archive_longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude']);
259
+		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($heading)));
260
+		    if (abs($this->all_tracked[$id]['heading'] - round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
261 261
   		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
262 262
   		}
263 263
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
264 264
 
265 265
 		if (isset($line['datetime'])) {
266 266
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
267
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
267
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => $line['datetime']));
268 268
 		    } else {
269 269
 				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
270 270
 				elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
@@ -272,48 +272,48 @@  discard block
 block discarded – undo
272 272
 		    }
273 273
 		} else {
274 274
 			date_default_timezone_set('UTC');
275
-			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
275
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => date('Y-m-d H:i:s')));
276 276
 		}
277 277
 
278 278
 
279 279
 		if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) {
280 280
 		    $this->all_tracked[$id]['lastupdate'] = time();
281 281
 		    if ($this->all_tracked[$id]['addedMarine'] == 0) {
282
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == ''  || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
282
+		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == '' || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
283 283
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
284 284
 				if ($globalDebug) echo "Check if aircraft is already in DB...";
285 285
 				$timeelapsed = microtime(true);
286 286
 				$MarineLive = new MarineLive($this->db);
287 287
 				if (isset($line['id'])) {
288 288
 				    $recent_ident = $MarineLive->checkIdRecent($line['id']);
289
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
289
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
290 290
 				} elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
291 291
 				    $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
292
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
292
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
293 293
 				} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
294 294
 				    $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
295
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
295
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
296 296
 				} else $recent_ident = '';
297
-				$MarineLive->db=null;
297
+				$MarineLive->db = null;
298 298
 				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
299 299
 				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
300 300
 			    } else {
301 301
 				$recent_ident = '';
302
-				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
302
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('forcenew' => 0));
303 303
 			    }
304 304
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
305
-			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
305
+			    if ($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
306 306
 			    {
307 307
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
308 308
 				//adds the spotter data for the archive
309 309
 				    $highlight = '';
310
-				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
310
+				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
311 311
 				    $timeelapsed = microtime(true);
312 312
 				    $Marine = new Marine($this->db);
313
-				    $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
313
+				    $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name']);
314 314
 				    $Marine->db = null;
315 315
 				    if ($globalDebug && isset($result)) echo $result."\n";
316
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
316
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
317 317
 				    
318 318
 				    /*
319 319
 				    // Add source stat in DB
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 				    //MarineLive->deleteLiveMarineDataNotUpdated();
352 352
 				    $MarineLive = new MarineLive($this->db);
353 353
 				    $MarineLive->deleteLiveMarineData();
354
-				    $MarineLive->db=null;
354
+				    $MarineLive->db = null;
355 355
 				    if ($globalDebug) echo " Done\n";
356 356
 				    $this->last_delete = time();
357 357
 				}
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
 				$this->all_tracked[$id]['addedMarine'] = 1;
361 361
 				if (isset($globalDaemon) && !$globalDaemon) {
362 362
 					$Marine = new Marine($this->db);
363
-					$Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime']);
363
+					$Marine->updateLatestMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime']);
364 364
 					$Marine->db = null;
365 365
 				}
366 366
 				
@@ -374,14 +374,14 @@  discard block
 block discarded – undo
374 374
 		    $ignoreImport = false;
375 375
 
376 376
 		    if (!$ignoreImport) {
377
-			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
377
+			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
378 378
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
379 379
 				$timeelapsed = microtime(true);
380 380
 				$MarineLive = new MarineLive($this->db);
381
-				$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
381
+				$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['noarchive'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['over_country']);
382 382
 				$MarineLive->db = null;
383 383
 				$this->all_tracked[$id]['putinarchive'] = false;
384
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
384
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
385 385
 
386 386
 				// Put statistics in $this->stats variable
387 387
 				/*
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
 				$this->all_tracked[$id]['lastupdate'] = time();
441 441
 				if ($this->all_tracked[$id]['putinarchive']) $send = true;
442 442
 				if ($globalDebug) echo $result."\n";
443
-			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
443
+			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude'])."\n";
444 444
 			//$this->del();
445 445
 			
446 446
 			
Please login to merge, or discard this patch.
Braces   +149 added lines, -51 removed lines patch added patch discarded remove patch
@@ -44,7 +44,9 @@  discard block
 block discarded – undo
44 44
 
45 45
     public function checkAll() {
46 46
 	global $globalDebug;
47
-	if ($globalDebug) echo "Update last seen tracked data...\n";
47
+	if ($globalDebug) {
48
+		echo "Update last seen tracked data...\n";
49
+	}
48 50
 	foreach ($this->all_tracked as $key => $flight) {
49 51
 	    if (isset($this->all_tracked[$key]['id'])) {
50 52
 		//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
@@ -57,12 +59,16 @@  discard block
 block discarded – undo
57 59
     public function del() {
58 60
 	global $globalDebug;
59 61
 	// Delete old infos
60
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
62
+	if ($globalDebug) {
63
+		echo 'Delete old values and update latest data...'."\n";
64
+	}
61 65
 	foreach ($this->all_tracked as $key => $flight) {
62 66
     	    if (isset($flight['lastupdate'])) {
63 67
         	if ($flight['lastupdate'] < (time()-3000)) {
64 68
             	    if (isset($this->all_tracked[$key]['id'])) {
65
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
69
+            		if ($globalDebug) {
70
+            			echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
71
+            		}
66 72
 			/*
67 73
 			$MarineLive = new MarineLive();
68 74
             		$MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']);
@@ -72,7 +78,9 @@  discard block
 block discarded – undo
72 78
             		$Marine = new Marine($this->db);
73 79
             		if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
74 80
 				$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed']);
75
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
81
+				if ($globalDebug && $result != 'success') {
82
+					echo '!!! ERROR : '.$result."\n";
83
+				}
76 84
 			}
77 85
 			// Put in archive
78 86
 //			$Marine->db = null;
@@ -85,7 +93,9 @@  discard block
 block discarded – undo
85 93
 
86 94
     public function add($line) {
87 95
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked;
88
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
96
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
97
+		$globalCoordMinChange = '0.02';
98
+	}
89 99
 	date_default_timezone_set('UTC');
90 100
 	$dataFound = false;
91 101
 	$send = false;
@@ -109,8 +119,11 @@  discard block
 block discarded – undo
109 119
 		*/
110 120
 		
111 121
 		$Common = new Common();
112
-	        if (!isset($line['id'])) $id = trim($line['mmsi']);
113
-	        else $id = trim($line['id']);
122
+	        if (!isset($line['id'])) {
123
+	        	$id = trim($line['mmsi']);
124
+	        } else {
125
+	        	$id = trim($line['id']);
126
+	        }
114 127
 		
115 128
 		if (!isset($this->all_tracked[$id])) {
116 129
 		    $this->all_tracked[$id] = array();
@@ -118,10 +131,16 @@  discard block
 block discarded – undo
118 131
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => ''));
119 132
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
120 133
 		    if (!isset($line['id'])) {
121
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
134
+			if (!isset($globalDaemon)) {
135
+				$globalDaemon = TRUE;
136
+			}
122 137
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
123
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
124
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
138
+		     } else {
139
+		     	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
140
+		     }
141
+		    if ($globalAllTracked !== FALSE) {
142
+		    	$dataFound = true;
143
+		    }
125 144
 		}
126 145
 		
127 146
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
@@ -161,11 +180,17 @@  discard block
 block discarded – undo
161 180
             		$Marine = new Marine($this->db);
162 181
             		$fromsource = NULL;
163 182
             		$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
164
-			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
183
+			if ($globalDebug && $result != 'success') {
184
+				echo '!!! ERROR : '.$result."\n";
185
+			}
165 186
 			$Marine->db = null;
166
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
187
+			if ($globalDebugTimeElapsed) {
188
+				echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
189
+			}
190
+		    }
191
+		    if (!isset($this->all_tracked[$id]['id'])) {
192
+		    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
167 193
 		    }
168
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
169 194
 		}
170 195
 
171 196
 		if (isset($line['speed']) && $line['speed'] != '') {
@@ -176,14 +201,21 @@  discard block
 block discarded – undo
176 201
 		    if ($distance > 1000 && $distance < 10000) {
177 202
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
178 203
 			$speed = $speed*3.6;
179
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
180
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
204
+			if ($speed < 1000) {
205
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
206
+			}
207
+  			if ($globalDebug) {
208
+  				echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
209
+  			}
181 210
 		    }
182 211
 		}
183 212
 
184 213
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
185
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
186
-	    	    else unset($timediff);
214
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) {
215
+	    	    	$timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
216
+	    	    } else {
217
+	    	    	unset($timediff);
218
+	    	    }
187 219
 	    	    if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) {
188 220
 			if (isset($this->all_tracked[$id]['archive_latitude']) && isset($this->all_tracked[$id]['archive_longitude']) && isset($this->all_tracked[$id]['livedb_latitude']) && isset($this->all_tracked[$id]['livedb_longitude'])) {
189 221
 			    if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
@@ -191,20 +223,30 @@  discard block
 block discarded – undo
191 223
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
192 224
 				$this->all_tracked[$id]['putinarchive'] = true;
193 225
 				
194
-				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
226
+				if ($globalDebug) {
227
+					echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
228
+				}
195 229
 				$timeelapsed = microtime(true);
196 230
 				$Marine = new Marine($this->db);
197 231
 				$all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
198
-				if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
232
+				if (!empty($all_country)) {
233
+					$this->all_tracked[$id]['over_country'] = $all_country['iso2'];
234
+				}
199 235
 				$Marine->db = null;
200
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
236
+				if ($globalDebugTimeElapsed) {
237
+					echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
238
+				}
201 239
 				$this->tmd = 0;
202
-				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
240
+				if ($globalDebug) {
241
+					echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
242
+				}
203 243
 			    }
204 244
 			}
205 245
 
206 246
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
207
-				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
247
+				if (!isset($this->all_tracked[$id]['archive_latitude'])) {
248
+					$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
249
+				}
208 250
 				if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
209 251
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
210 252
 				    $dataFound = true;
@@ -213,8 +255,12 @@  discard block
 block discarded – undo
213 255
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
214 256
 			}
215 257
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
216
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
217
-				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
258
+			    if ($line['longitude'] > 180) {
259
+			    	$line['longitude'] = $line['longitude'] - 360;
260
+			    }
261
+				if (!isset($this->all_tracked[$id]['archive_longitude'])) {
262
+					$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
263
+				}
218 264
 				if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
219 265
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
220 266
 				    $dataFound = true;
@@ -232,7 +278,9 @@  discard block
 block discarded – undo
232 278
 		    }
233 279
 		}
234 280
 		if (isset($line['last_update']) && $line['last_update'] != '') {
235
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
281
+		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) {
282
+		    	$dataFound = true;
283
+		    }
236 284
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
237 285
 		}
238 286
 		if (isset($line['format_source']) && $line['format_source'] != '') {
@@ -250,15 +298,21 @@  discard block
 block discarded – undo
250 298
 		}
251 299
 		
252 300
 		if (isset($line['heading']) && $line['heading'] != '') {
253
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
301
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) {
302
+		    	$this->all_tracked[$id]['putinarchive'] = true;
303
+		    }
254 304
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
255 305
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
256 306
 		    //$dataFound = true;
257 307
   		} elseif (!isset($this->all_tracked[$id]['heading_fromsrc']) && isset($this->all_tracked[$id]['archive_latitude']) && $this->all_tracked[$id]['archive_latitude'] != $this->all_tracked[$id]['latitude'] && isset($this->all_tracked[$id]['archive_longitude']) && $this->all_tracked[$id]['archive_longitude'] != $this->all_tracked[$id]['longitude']) {
258 308
   		    $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
259 309
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
260
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
261
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
310
+		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) {
311
+		    	$this->all_tracked[$id]['putinarchive'] = true;
312
+		    }
313
+  		    if ($globalDebug) {
314
+  		    	echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
315
+  		    }
262 316
   		}
263 317
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
264 318
 
@@ -266,8 +320,11 @@  discard block
 block discarded – undo
266 320
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
267 321
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
268 322
 		    } else {
269
-				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
270
-				elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
323
+				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
324
+					echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
325
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
326
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
327
+				}
271 328
 				return '';
272 329
 		    }
273 330
 		} else {
@@ -281,22 +338,35 @@  discard block
 block discarded – undo
281 338
 		    if ($this->all_tracked[$id]['addedMarine'] == 0) {
282 339
 		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == ''  || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
283 340
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
284
-				if ($globalDebug) echo "Check if aircraft is already in DB...";
341
+				if ($globalDebug) {
342
+					echo "Check if aircraft is already in DB...";
343
+				}
285 344
 				$timeelapsed = microtime(true);
286 345
 				$MarineLive = new MarineLive($this->db);
287 346
 				if (isset($line['id'])) {
288 347
 				    $recent_ident = $MarineLive->checkIdRecent($line['id']);
289
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
348
+				    if ($globalDebugTimeElapsed) {
349
+				    	echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
350
+				    }
290 351
 				} elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
291 352
 				    $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
292
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
353
+				    if ($globalDebugTimeElapsed) {
354
+				    	echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
355
+				    }
293 356
 				} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
294 357
 				    $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
295
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
296
-				} else $recent_ident = '';
358
+				    if ($globalDebugTimeElapsed) {
359
+				    	echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
360
+				    }
361
+				} else {
362
+					$recent_ident = '';
363
+				}
297 364
 				$MarineLive->db=null;
298
-				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
299
-				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
365
+				if ($globalDebug && $recent_ident == '') {
366
+					echo " Not in DB.\n";
367
+				} elseif ($globalDebug && $recent_ident != '') {
368
+					echo " Already in DB.\n";
369
+				}
300 370
 			    } else {
301 371
 				$recent_ident = '';
302 372
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
@@ -304,16 +374,24 @@  discard block
 block discarded – undo
304 374
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
305 375
 			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
306 376
 			    {
307
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
377
+				if ($globalDebug) {
378
+					echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
379
+				}
308 380
 				//adds the spotter data for the archive
309 381
 				    $highlight = '';
310
-				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
382
+				    if (!isset($this->all_tracked[$id]['id'])) {
383
+				    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
384
+				    }
311 385
 				    $timeelapsed = microtime(true);
312 386
 				    $Marine = new Marine($this->db);
313 387
 				    $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
314 388
 				    $Marine->db = null;
315
-				    if ($globalDebug && isset($result)) echo $result."\n";
316
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
389
+				    if ($globalDebug && isset($result)) {
390
+				    	echo $result."\n";
391
+				    }
392
+				    if ($globalDebugTimeElapsed) {
393
+				    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
394
+				    }
317 395
 				    
318 396
 				    /*
319 397
 				    // Add source stat in DB
@@ -347,12 +425,16 @@  discard block
 block discarded – undo
347 425
 				$this->all_tracked[$id]['addedMarine'] = 1;
348 426
 				//print_r($this->all_tracked[$id]);
349 427
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
350
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
428
+				    if ($globalDebug) {
429
+				    	echo "---- Deleting Live Marine data older than 9 hours...";
430
+				    }
351 431
 				    //MarineLive->deleteLiveMarineDataNotUpdated();
352 432
 				    $MarineLive = new MarineLive($this->db);
353 433
 				    $MarineLive->deleteLiveMarineData();
354 434
 				    $MarineLive->db=null;
355
-				    if ($globalDebug) echo " Done\n";
435
+				    if ($globalDebug) {
436
+				    	echo " Done\n";
437
+				    }
356 438
 				    $this->last_delete = time();
357 439
 				}
358 440
 			    } elseif ($recent_ident != '') {
@@ -375,13 +457,17 @@  discard block
 block discarded – undo
375 457
 
376 458
 		    if (!$ignoreImport) {
377 459
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
378
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
460
+				if ($globalDebug) {
461
+					echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
462
+				}
379 463
 				$timeelapsed = microtime(true);
380 464
 				$MarineLive = new MarineLive($this->db);
381 465
 				$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
382 466
 				$MarineLive->db = null;
383 467
 				$this->all_tracked[$id]['putinarchive'] = false;
384
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
468
+				if ($globalDebugTimeElapsed) {
469
+					echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
470
+				}
385 471
 
386 472
 				// Put statistics in $this->stats variable
387 473
 				/*
@@ -438,19 +524,29 @@  discard block
 block discarded – undo
438 524
 				*/
439 525
 
440 526
 				$this->all_tracked[$id]['lastupdate'] = time();
441
-				if ($this->all_tracked[$id]['putinarchive']) $send = true;
442
-				if ($globalDebug) echo $result."\n";
443
-			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
527
+				if ($this->all_tracked[$id]['putinarchive']) {
528
+					$send = true;
529
+				}
530
+				if ($globalDebug) {
531
+					echo $result."\n";
532
+				}
533
+			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
534
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
535
+			}
444 536
 			//$this->del();
445 537
 			
446 538
 			
447 539
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
448
-			    if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
540
+			    if ($globalDebug) {
541
+			    	echo "---- Deleting Live Marine data Not updated since 2 hour...";
542
+			    }
449 543
 			    $MarineLive = new MarineLive($this->db);
450 544
 			    $MarineLive->deleteLiveMarineDataNotUpdated();
451 545
 			    $MarineLive->db = null;
452 546
 			    //MarineLive->deleteLiveMarineData();
453
-			    if ($globalDebug) echo " Done\n";
547
+			    if ($globalDebug) {
548
+			    	echo " Done\n";
549
+			    }
454 550
 			    $this->last_delete_hourly = time();
455 551
 			}
456 552
 			
@@ -458,7 +554,9 @@  discard block
 block discarded – undo
458 554
 		    //$ignoreImport = false;
459 555
 		}
460 556
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
461
-		if ($send) return $this->all_tracked[$id];
557
+		if ($send) {
558
+			return $this->all_tracked[$id];
559
+		}
462 560
 	    }
463 561
 	}
464 562
     }
Please login to merge, or discard this patch.