Completed
Push — master ( 65a957...a0dd18 )
by Yannick
07:20
created
require/class.APRS.php 2 patches
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -2,10 +2,10 @@  discard block
 block discarded – undo
2 2
 require_once(dirname(__FILE__).'/settings.php');
3 3
 require_once(dirname(__FILE__).'/class.Common.php');
4 4
 class aprs {
5
-    private $socket;
6
-    private $connected = false;
5
+	private $socket;
6
+	private $connected = false;
7 7
 
8
-    protected $symbols = array('!' => 'Police',
8
+	protected $symbols = array('!' => 'Police',
9 9
 	'#' => 'DIGI',
10 10
 	'$' => 'Phone',
11 11
 	'%' => 'DX Cluster',
@@ -89,13 +89,13 @@  discard block
 block discarded – undo
89 89
 	'y' => 'Yagi At QTH');
90 90
 	
91 91
 
92
-    private function urshift($n, $s) {
92
+	private function urshift($n, $s) {
93 93
 	return ($n >= 0) ? ($n >> $s) :
94
-	    (($n & 0x7fffffff) >> $s) | 
94
+		(($n & 0x7fffffff) >> $s) | 
95 95
 		(0x40000000 >> ($s - 1));
96
-    }
96
+	}
97 97
 
98
-    public function parse($input) {
98
+	public function parse($input) {
99 99
 	global $globalDebug;
100 100
 	$debug = false;
101 101
 	$result = array();
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
 	
108 108
 	/* Check that end was found and body has at least one byte. */
109 109
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
110
-	    if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
111
-	    return false;
110
+		if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
111
+		return false;
112 112
 	}
113 113
 	
114 114
 	if ($debug) echo 'input : '.$input."\n";
@@ -122,31 +122,31 @@  discard block
 block discarded – undo
122 122
 	/* Parse source, target and path. */
123 123
 	//FLRDF0A52>APRS,qAS,LSTB
124 124
 	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) {
125
-	    $ident = $matches[1];
126
-	    $all_elements = $matches[2];
127
-	    if ($ident == 'AIRCRAFT') {
125
+		$ident = $matches[1];
126
+		$all_elements = $matches[2];
127
+		if ($ident == 'AIRCRAFT') {
128 128
 		$result['format_source'] = 'famaprs';
129 129
 		$result['source_type'] = 'modes';
130
-	    } elseif ($ident == 'MARINE') {
130
+		} elseif ($ident == 'MARINE') {
131 131
 		$result['format_source'] = 'famaprs';
132 132
 		$result['source_type'] = 'ais';
133
-	    } else {
133
+		} else {
134 134
 		if ($debug) echo 'ident : '.$ident."\n";
135 135
 		$result['ident'] = $ident;
136
-	    }
136
+		}
137 137
 	} else return false;
138 138
 	$elements = explode(',',$all_elements);
139 139
 	$source = end($elements);
140 140
 	$result['source'] = $source;
141 141
 	foreach ($elements as $element) {
142
-	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
143
-	        //echo "ok";
144
-	        //if ($element == 'TCPIP*') return false;
145
-	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
142
+		if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
143
+			//echo "ok";
144
+			//if ($element == 'TCPIP*') return false;
145
+		} elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
146 146
 		if ($debug) echo 'element : '.$element."\n";
147 147
 		return false;
148
-	    }
149
-	    /*
148
+		}
149
+		/*
150 150
 	    } elseif (preg_match('/^([0-9A-F]{32})$/',$element)) {
151 151
 		//echo "ok";
152 152
 	    } else {
@@ -171,49 +171,49 @@  discard block
 block discarded – undo
171 171
 	$body_parse = substr($body,1);
172 172
 	//echo 'Body : '.$body."\n";
173 173
 	if (preg_match('/^;(.){9}\*/',$body,$matches)) {
174
-	    $body_parse = substr($body_parse,10);
175
-	    $find = true;
176
-	    //echo $body_parse."\n";
174
+		$body_parse = substr($body_parse,10);
175
+		$find = true;
176
+		//echo $body_parse."\n";
177 177
 	}
178 178
 	if (preg_match('/^`(.*)\//',$body,$matches)) {
179
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
180
-	    $find = true;
181
-	    //echo $body_parse."\n";
179
+		$body_parse = substr($body_parse,strlen($matches[1])-1);
180
+		$find = true;
181
+		//echo $body_parse."\n";
182 182
 	}
183 183
 	if (preg_match("/^'(.*)\//",$body,$matches)) {
184
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
185
-	    $find = true;
186
-	    //echo $body_parse."\n";
184
+		$body_parse = substr($body_parse,strlen($matches[1])-1);
185
+		$find = true;
186
+		//echo $body_parse."\n";
187 187
 	}
188 188
 	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) {
189
-	    $find = true;
190
-	    //print_r($matches);
191
-	    $timestamp = $matches[0];
192
-	    if ($matches[4] == 'h') {
189
+		$find = true;
190
+		//print_r($matches);
191
+		$timestamp = $matches[0];
192
+		if ($matches[4] == 'h') {
193 193
 		$timestamp = strtotime($matches[1].':'.$matches[2].':'.$matches[3]);
194 194
 		//echo 'timestamp : '.$timestamp.' - now : '.time()."\n";
195 195
 		/*
196 196
 		if (time() + 3900 < $timestamp) $timestamp -= 86400;
197 197
 		elseif (time() - 82500 > $timestamp) $timestamp += 86400;
198 198
 		*/
199
-	    } elseif ($matches[4] == 'z' || $matches[4] == '/') {
199
+		} elseif ($matches[4] == 'z' || $matches[4] == '/') {
200 200
 		// This work or not ?
201 201
 		$timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]);
202
-	    }
203
-	    $body_parse = substr($body_parse,7);
204
-	    $result['timestamp'] = $timestamp;
205
-	    //echo date('Ymd H:i:s',$timestamp);
202
+		}
203
+		$body_parse = substr($body_parse,7);
204
+		$result['timestamp'] = $timestamp;
205
+		//echo date('Ymd H:i:s',$timestamp);
206 206
 	}
207 207
 	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) {
208
-	    $find = true;
209
-	    $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]);
210
-	    $body_parse = substr($body_parse,8);
211
-	    $result['timestamp'] = $timestamp;
212
-	    //echo date('Ymd H:i:s',$timestamp);
208
+		$find = true;
209
+		$timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]);
210
+		$body_parse = substr($body_parse,8);
211
+		$result['timestamp'] = $timestamp;
212
+		//echo date('Ymd H:i:s',$timestamp);
213 213
 	}
214 214
 	//if (strlen($body_parse) > 19) {
215
-	    if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) {
216
-	    $find = true;
215
+		if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) {
216
+		$find = true;
217 217
 		// 4658.70N/00707.78Ez
218 218
 		//print_r(str_split($body_parse));
219 219
 		
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 		$lon = intval($lon_deg);
231 231
 		if ($lat > 89 || $lon > 179) return false;
232 232
 	    
233
-	    /*
233
+		/*
234 234
 	    $tmp_5b = str_replace('.','',$lat_min);
235 235
 	    if (preg_match('/^([0-9]{0,4})( {0,4})$/',$tmp_5b,$matches)) {
236 236
 	        print_r($matches);
@@ -244,9 +244,9 @@  discard block
 block discarded – undo
244 244
 		$result['longitude'] = $longitude;
245 245
 		$body_parse = substr($body_parse,18);
246 246
 		$body_parse_len = strlen($body_parse);
247
-	    }
248
-	    $body_parse_len = strlen($body_parse);
249
-	    if ($body_parse_len > 0) {
247
+		}
248
+		$body_parse_len = strlen($body_parse);
249
+		if ($body_parse_len > 0) {
250 250
 		/*
251 251
 		if (!isset($result['timestamp']) && !isset($result['latitude'])) {
252 252
 			$body_split = str_split($body);
@@ -276,85 +276,85 @@  discard block
 block discarded – undo
276 276
 			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
277 277
 			if ($symbol_code != '_') {
278 278
 			}
279
-		    //$body_parse = substr($body_parse,1);
280
-		    //$body_parse = trim($body_parse);
281
-		    //$body_parse_len = strlen($body_parse);
282
-		    if ($body_parse_len >= 7) {
279
+			//$body_parse = substr($body_parse,1);
280
+			//$body_parse = trim($body_parse);
281
+			//$body_parse_len = strlen($body_parse);
282
+			if ($body_parse_len >= 7) {
283 283
 			
284
-		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
285
-		    	    $course = substr($body_parse,0,3);
286
-		    	    $tmp_s = intval($course);
287
-		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
288
-		    	    $speed = substr($body_parse,4,3);
289
-		    	    if ($speed != '...') {
290
-		    		    $result['speed'] = round($speed*1.852);
291
-		    	    }
292
-		    	    $body_parse = substr($body_parse,7);
293
-		        }
294
-		        // Check PHGR, PHG, RNG
295
-		    } 
296
-		    /*
284
+				if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
285
+					$course = substr($body_parse,0,3);
286
+					$tmp_s = intval($course);
287
+					if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
288
+					$speed = substr($body_parse,4,3);
289
+					if ($speed != '...') {
290
+						$result['speed'] = round($speed*1.852);
291
+					}
292
+					$body_parse = substr($body_parse,7);
293
+				}
294
+				// Check PHGR, PHG, RNG
295
+			} 
296
+			/*
297 297
 		    else if ($body_parse_len > 0) {
298 298
 			$rest = $body_parse;
299 299
 		    }
300 300
 		    */
301
-		    if (strlen($body_parse) > 0) {
302
-		        if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
303
-		            $altitude = intval($matches[1]);
304
-		            //$result['altitude'] = round($altitude*0.3048);
305
-		            $result['altitude'] = $altitude;
306
-		            //$body_parse = trim(substr($body_parse,strlen($matches[0])));
307
-		            $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse));
308
-		        }
309
-		    }
301
+			if (strlen($body_parse) > 0) {
302
+				if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
303
+					$altitude = intval($matches[1]);
304
+					//$result['altitude'] = round($altitude*0.3048);
305
+					$result['altitude'] = $altitude;
306
+					//$body_parse = trim(substr($body_parse,strlen($matches[0])));
307
+					$body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse));
308
+				}
309
+			}
310 310
 		    
311
-		    // Telemetry
312
-		    /*
311
+			// Telemetry
312
+			/*
313 313
 		    if (preg_match('/^([0-9]+),(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,([01]{0,8})/',$body_parse,$matches)) {
314 314
 		        // Nothing yet...
315 315
 		    }
316 316
 		    */
317
-		    // DAO
318
-		    if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
319
-			    $dao = $matches[1];
320
-			    if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
317
+			// DAO
318
+			if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
319
+				$dao = $matches[1];
320
+				if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
321 321
 				$dao_split = str_split($dao);
322
-			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
323
-			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
322
+					$lat_off = (($dao_split[1])-48.0)*0.001/60.0;
323
+					$lon_off = (($dao_split[2])-48.0)*0.001/60.0;
324 324
 			    
325 325
 				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
326 326
 				else $result['latitude'] += $lat_off;
327 327
 				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
328 328
 				else $result['longitude'] += $lon_off;
329
-			    }
330
-		            $body_parse = substr($body_parse,6);
331
-		    }
329
+				}
330
+					$body_parse = substr($body_parse,6);
331
+			}
332 332
 		    
333
-		    if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
333
+			if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
334 334
 			$result['ident'] = $matches[1];
335
-		    }
336
-		    if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
335
+			}
336
+			if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
337 337
 			$result['squawk'] = $matches[1];
338
-		    }
339
-		    if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
338
+			}
339
+			if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
340 340
 			$result['aircraft_icao'] = $matches[1];
341
-		    }
342
-		    if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) {
341
+			}
342
+			if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) {
343 343
 			$result['typeid'] = $matches[1];
344
-		    }
345
-		    if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) {
344
+			}
345
+			if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) {
346 346
 			$result['imo'] = $matches[1];
347
-		    }
348
-		    if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) {
347
+			}
348
+			if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) {
349 349
 			$result['arrival_date'] = $matches[1];
350
-		    }
351
-		    if (preg_match('/AC=([0-9A-Z]*)/',$body_parse,$matches)) {
350
+			}
351
+			if (preg_match('/AC=([0-9A-Z]*)/',$body_parse,$matches)) {
352 352
 			$result['arrival_code'] = $matches[1];
353
-		    }
354
-		    // OGN comment
353
+			}
354
+			// OGN comment
355 355
 		   // echo "Before OGN : ".$body_parse."\n";
356
-		    //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
357
-		    if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
356
+			//if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
357
+			if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
358 358
 			$id = $matches[1];
359 359
 			//$mode = substr($id,0,2);
360 360
 			$address = substr($id,2);
@@ -384,53 +384,53 @@  discard block
 block discarded – undo
384 384
 			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
385 385
 			$result['stealth'] = $stealth;
386 386
 			$result['address'] = $address;
387
-		    }
387
+			}
388 388
 		    
389
-		    //Comment
390
-		    $result['comment'] = trim($body_parse);
389
+			//Comment
390
+			$result['comment'] = trim($body_parse);
391 391
 		} else {
392
-		    // parse weather
393
-		    //$body_parse = substr($body_parse,1);
394
-		    //$body_parse_len = strlen($body_parse);
392
+			// parse weather
393
+			//$body_parse = substr($body_parse,1);
394
+			//$body_parse_len = strlen($body_parse);
395 395
 
396
-		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
397
-			    $result['wind_dir'] = intval($matches[1]);
398
-			    $result['wind_speed'] = round(intval($matches[2])*1.60934,1);
399
-			    $result['wind_gust'] = round(intval($matches[3])*1.60934,1);
400
-			    $result['temp'] = round(5/9*((intval($matches[4]))-32),1);
401
-		    	    $body_parse = substr($body_parse,strlen($matches[0])+1);
402
-		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
396
+			if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
397
+				$result['wind_dir'] = intval($matches[1]);
398
+				$result['wind_speed'] = round(intval($matches[2])*1.60934,1);
399
+				$result['wind_gust'] = round(intval($matches[3])*1.60934,1);
400
+				$result['temp'] = round(5/9*((intval($matches[4]))-32),1);
401
+					$body_parse = substr($body_parse,strlen($matches[0])+1);
402
+			} elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
403 403
 			$result['wind_dir'] = intval($matches[1]);
404 404
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
405 405
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
406 406
 			$result['temp'] = round(5/9*(($matches[4])-32),1);
407
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
408
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
407
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
408
+			} elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
409 409
 			$result['wind_dir'] = intval($matches[1]);
410 410
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
411 411
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
412
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
413
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
412
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
413
+			} elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
414 414
 			$result['wind_dir'] = intval($matches[1]);
415 415
 			$result['wind_speed'] = round($matches[2]*1.60934,1);
416 416
 			$result['wind_gust'] = round($matches[3]*1.60934,1);
417
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
418
-		    }
419
-		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
417
+				$body_parse = substr($body_parse,strlen($matches[0])+1);
418
+			}
419
+			if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
420 420
 			$result['temp'] = round(5/9*(($matches[1])-32),1);
421
-		    }
421
+			}
422 422
 		}
423 423
 		} else $result['comment'] = trim($body_parse);
424 424
 
425
-	    }
425
+		}
426 426
 	//}
427 427
 	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
428 428
 	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
429 429
 	if ($debug) print_r($result);
430 430
 	return $result;
431
-    }
431
+	}
432 432
     
433
-    function connect() {
433
+	function connect() {
434 434
 	global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass,$globalName, $globalServerAPRShost, $globalServerAPRSport;
435 435
 	$aprs_connect = 0;
436 436
 	$aprs_keep = 120;
@@ -453,24 +453,24 @@  discard block
 block discarded – undo
453 453
 		$send = socket_send( $this->socket  , $aprs_login , strlen($aprs_login) , 0 );
454 454
 		while ($msgin = socket_read($this->socket, 1000,PHP_NORMAL_READ)) {
455 455
 			if (strpos($msgin, "$aprs_ssid verified") !== FALSE) {
456
-			    echo 'APRS user verified !'."\n";
457
-			    $this->connected = true;
458
-			    return true;
459
-			    break;
456
+				echo 'APRS user verified !'."\n";
457
+				$this->connected = true;
458
+				return true;
459
+				break;
460 460
 			}
461 461
 			if (time()-$authstart > 5) {
462
-			    echo 'APRS timeout'."\n";
463
-			    break;
462
+				echo 'APRS timeout'."\n";
463
+				break;
464 464
 			}
465 465
 		}
466 466
 	}
467
-    }
467
+	}
468 468
     
469
-    function send($data) {
469
+	function send($data) {
470 470
 	if ($this->connected === false) $this->connect();
471 471
 	$send = socket_send( $this->socket  , $data , strlen($data),0);
472 472
 	if ($send === FALSE) $this->connect();
473
-    }
473
+	}
474 474
 }
475 475
 
476 476
 class APRSSpotter extends APRS {
Please login to merge, or discard this patch.
Spacing   +95 added lines, -96 removed lines patch added patch discarded remove patch
@@ -90,8 +90,7 @@  discard block
 block discarded – undo
90 90
 	
91 91
 
92 92
     private function urshift($n, $s) {
93
-	return ($n >= 0) ? ($n >> $s) :
94
-	    (($n & 0x7fffffff) >> $s) | 
93
+	return ($n >= 0) ? ($n >> $s) : (($n&0x7fffffff) >> $s)| 
95 94
 		(0x40000000 >> ($s - 1));
96 95
     }
97 96
 
@@ -103,7 +102,7 @@  discard block
 block discarded – undo
103 102
 	//$split_input = str_split($input);
104 103
 
105 104
 	/* Find the end of header checking for NULL bytes while doing it. */
106
-	$splitpos = strpos($input,':');
105
+	$splitpos = strpos($input, ':');
107 106
 	
108 107
 	/* Check that end was found and body has at least one byte. */
109 108
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
@@ -113,15 +112,15 @@  discard block
 block discarded – undo
113 112
 	
114 113
 	if ($debug) echo 'input : '.$input."\n";
115 114
 	/* Save header and body. */
116
-	$body = substr($input,$splitpos+1,$input_len);
115
+	$body = substr($input, $splitpos + 1, $input_len);
117 116
 	$body_len = strlen($body);
118
-	$header = substr($input,0,$splitpos);
117
+	$header = substr($input, 0, $splitpos);
119 118
 	//$header_len = strlen($header);
120 119
 	if ($debug) echo 'header : '.$header."\n";
121 120
 	
122 121
 	/* Parse source, target and path. */
123 122
 	//FLRDF0A52>APRS,qAS,LSTB
124
-	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) {
123
+	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/', $header, $matches)) {
125 124
 	    $ident = $matches[1];
126 125
 	    $all_elements = $matches[2];
127 126
 	    if ($ident == 'AIRCRAFT') {
@@ -135,14 +134,14 @@  discard block
 block discarded – undo
135 134
 		$result['ident'] = $ident;
136 135
 	    }
137 136
 	} else return false;
138
-	$elements = explode(',',$all_elements);
137
+	$elements = explode(',', $all_elements);
139 138
 	$source = end($elements);
140 139
 	$result['source'] = $source;
141 140
 	foreach ($elements as $element) {
142
-	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) {
141
+	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/', $element)) {
143 142
 	        //echo "ok";
144 143
 	        //if ($element == 'TCPIP*') return false;
145
-	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
144
+	    } elseif (!preg_match('/^([0-9A-F]{32})$/', $element)) {
146 145
 		if ($debug) echo 'element : '.$element."\n";
147 146
 		return false;
148 147
 	    }
@@ -155,12 +154,12 @@  discard block
 block discarded – undo
155 154
 	    */
156 155
 	}
157 156
 	
158
-	$type = substr($body,0,1);
157
+	$type = substr($body, 0, 1);
159 158
 	if ($debug) echo 'type : '.$type."\n";
160 159
 	if ($type == ';') {
161 160
 		if (isset($result['source_type']) && $result['source_type'] == 'modes') {
162
-			$result['address'] = trim(substr($body,1,9));
163
-		} else $result['ident'] = trim(substr($body,1,9));
161
+			$result['address'] = trim(substr($body, 1, 9));
162
+		} else $result['ident'] = trim(substr($body, 1, 9));
164 163
 	} elseif ($type == ',') {
165 164
 		// Invalid data or test data
166 165
 		return false;
@@ -168,24 +167,24 @@  discard block
 block discarded – undo
168 167
 	
169 168
 	// Check for Timestamp
170 169
 	$find = false;
171
-	$body_parse = substr($body,1);
170
+	$body_parse = substr($body, 1);
172 171
 	//echo 'Body : '.$body."\n";
173
-	if (preg_match('/^;(.){9}\*/',$body,$matches)) {
174
-	    $body_parse = substr($body_parse,10);
172
+	if (preg_match('/^;(.){9}\*/', $body, $matches)) {
173
+	    $body_parse = substr($body_parse, 10);
175 174
 	    $find = true;
176 175
 	    //echo $body_parse."\n";
177 176
 	}
178
-	if (preg_match('/^`(.*)\//',$body,$matches)) {
179
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
177
+	if (preg_match('/^`(.*)\//', $body, $matches)) {
178
+	    $body_parse = substr($body_parse, strlen($matches[1]) - 1);
180 179
 	    $find = true;
181 180
 	    //echo $body_parse."\n";
182 181
 	}
183
-	if (preg_match("/^'(.*)\//",$body,$matches)) {
184
-	    $body_parse = substr($body_parse,strlen($matches[1])-1);
182
+	if (preg_match("/^'(.*)\//", $body, $matches)) {
183
+	    $body_parse = substr($body_parse, strlen($matches[1]) - 1);
185 184
 	    $find = true;
186 185
 	    //echo $body_parse."\n";
187 186
 	}
188
-	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) {
187
+	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/', $body_parse, $matches)) {
189 188
 	    $find = true;
190 189
 	    //print_r($matches);
191 190
 	    $timestamp = $matches[0];
@@ -200,19 +199,19 @@  discard block
 block discarded – undo
200 199
 		// This work or not ?
201 200
 		$timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]);
202 201
 	    }
203
-	    $body_parse = substr($body_parse,7);
202
+	    $body_parse = substr($body_parse, 7);
204 203
 	    $result['timestamp'] = $timestamp;
205 204
 	    //echo date('Ymd H:i:s',$timestamp);
206 205
 	}
207
-	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) {
206
+	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/', $body_parse, $matches)) {
208 207
 	    $find = true;
209 208
 	    $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]);
210
-	    $body_parse = substr($body_parse,8);
209
+	    $body_parse = substr($body_parse, 8);
211 210
 	    $result['timestamp'] = $timestamp;
212 211
 	    //echo date('Ymd H:i:s',$timestamp);
213 212
 	}
214 213
 	//if (strlen($body_parse) > 19) {
215
-	    if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) {
214
+	    if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/', $body_parse, $matches)) {
216 215
 	    $find = true;
217 216
 		// 4658.70N/00707.78Ez
218 217
 		//print_r(str_split($body_parse));
@@ -238,11 +237,11 @@  discard block
 block discarded – undo
238 237
 	    */
239 238
 		$latitude = $lat + floatval($lat_min)/60;
240 239
 		$longitude = $lon + floatval($lon_min)/60;
241
-		if ($sind == 'S') $latitude = 0-$latitude;
242
-		if ($wind == 'W') $longitude = 0-$longitude;
240
+		if ($sind == 'S') $latitude = 0 - $latitude;
241
+		if ($wind == 'W') $longitude = 0 - $longitude;
243 242
 		$result['latitude'] = $latitude;
244 243
 		$result['longitude'] = $longitude;
245
-		$body_parse = substr($body_parse,18);
244
+		$body_parse = substr($body_parse, 18);
246 245
 		$body_parse_len = strlen($body_parse);
247 246
 	    }
248 247
 	    $body_parse_len = strlen($body_parse);
@@ -270,7 +269,7 @@  discard block
 block discarded – undo
270 269
 		//echo $body_parse;
271 270
 			//if ($type != ';' && $type != '>') {
272 271
 			if ($type != '') {
273
-			$body_parse = substr($body_parse,1);
272
+			$body_parse = substr($body_parse, 1);
274 273
 			$body_parse_len = strlen($body_parse);
275 274
 			$result['symbol_code'] = $symbol_code;
276 275
 			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
@@ -281,15 +280,15 @@  discard block
 block discarded – undo
281 280
 		    //$body_parse_len = strlen($body_parse);
282 281
 		    if ($body_parse_len >= 7) {
283 282
 			
284
-		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
285
-		    	    $course = substr($body_parse,0,3);
283
+		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/', $body_parse)) {
284
+		    	    $course = substr($body_parse, 0, 3);
286 285
 		    	    $tmp_s = intval($course);
287 286
 		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
288
-		    	    $speed = substr($body_parse,4,3);
287
+		    	    $speed = substr($body_parse, 4, 3);
289 288
 		    	    if ($speed != '...') {
290 289
 		    		    $result['speed'] = round($speed*1.852);
291 290
 		    	    }
292
-		    	    $body_parse = substr($body_parse,7);
291
+		    	    $body_parse = substr($body_parse, 7);
293 292
 		        }
294 293
 		        // Check PHGR, PHG, RNG
295 294
 		    } 
@@ -299,12 +298,12 @@  discard block
 block discarded – undo
299 298
 		    }
300 299
 		    */
301 300
 		    if (strlen($body_parse) > 0) {
302
-		        if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) {
301
+		        if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/', $body_parse, $matches)) {
303 302
 		            $altitude = intval($matches[1]);
304 303
 		            //$result['altitude'] = round($altitude*0.3048);
305 304
 		            $result['altitude'] = $altitude;
306 305
 		            //$body_parse = trim(substr($body_parse,strlen($matches[0])));
307
-		            $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse));
306
+		            $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/', '', $body_parse));
308 307
 		        }
309 308
 		    }
310 309
 		    
@@ -315,56 +314,56 @@  discard block
 block discarded – undo
315 314
 		    }
316 315
 		    */
317 316
 		    // DAO
318
-		    if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) {
317
+		    if (preg_match('/^!([0-9A-Z]{3})/', $body_parse, $matches)) {
319 318
 			    $dao = $matches[1];
320
-			    if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) {
319
+			    if (preg_match('/^([A-Z])([0-9]{2})/', $dao)) {
321 320
 				$dao_split = str_split($dao);
322
-			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
323
-			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
321
+			        $lat_off = (($dao_split[1]) - 48.0)*0.001/60.0;
322
+			        $lon_off = (($dao_split[2]) - 48.0)*0.001/60.0;
324 323
 			    
325 324
 				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
326 325
 				else $result['latitude'] += $lat_off;
327 326
 				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
328 327
 				else $result['longitude'] += $lon_off;
329 328
 			    }
330
-		            $body_parse = substr($body_parse,6);
329
+		            $body_parse = substr($body_parse, 6);
331 330
 		    }
332 331
 		    
333
-		    if (preg_match('/CS=([0-9A-Z]*)/',$body_parse,$matches)) {
332
+		    if (preg_match('/CS=([0-9A-Z]*)/', $body_parse, $matches)) {
334 333
 			$result['ident'] = $matches[1];
335 334
 		    }
336
-		    if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) {
335
+		    if (preg_match('/SQ=([0-9]{4})/', $body_parse, $matches)) {
337 336
 			$result['squawk'] = $matches[1];
338 337
 		    }
339
-		    if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) {
338
+		    if (preg_match('/AI=([0-9A-Z]{4})/', $body_parse, $matches)) {
340 339
 			$result['aircraft_icao'] = $matches[1];
341 340
 		    }
342
-		    if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) {
341
+		    if (preg_match('/TI=([0-9]*)/', $body_parse, $matches)) {
343 342
 			$result['typeid'] = $matches[1];
344 343
 		    }
345
-		    if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) {
344
+		    if (preg_match('/IMO=([0-9]{7})/', $body_parse, $matches)) {
346 345
 			$result['imo'] = $matches[1];
347 346
 		    }
348
-		    if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) {
347
+		    if (preg_match('/AD=([0-9]*)/', $body_parse, $matches)) {
349 348
 			$result['arrival_date'] = $matches[1];
350 349
 		    }
351
-		    if (preg_match('/AC=([0-9A-Z]*)/',$body_parse,$matches)) {
350
+		    if (preg_match('/AC=([0-9A-Z]*)/', $body_parse, $matches)) {
352 351
 			$result['arrival_code'] = $matches[1];
353 352
 		    }
354 353
 		    // OGN comment
355 354
 		   // echo "Before OGN : ".$body_parse."\n";
356 355
 		    //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) {
357
-		    if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) {
356
+		    if (preg_match('/^id([0-9A-F]{8})/', $body_parse, $matches)) {
358 357
 			$id = $matches[1];
359 358
 			//$mode = substr($id,0,2);
360
-			$address = substr($id,2);
359
+			$address = substr($id, 2);
361 360
 			//print_r($matches);
362
-			$addressType = (intval(substr($id,0,2),16))&3;
361
+			$addressType = (intval(substr($id, 0, 2), 16))&3;
363 362
 			if ($addressType == 0) $result['addresstype'] = "RANDOM";
364 363
 			elseif ($addressType == 1) $result['addresstype'] = "ICAO";
365 364
 			elseif ($addressType == 2) $result['addresstype'] = "FLARM";
366 365
 			elseif ($addressType == 3) $result['addresstype'] = "OGN";
367
-			$aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2);
366
+			$aircraftType = $this->urshift(((intval(substr($id, 0, 2), 16))&0b1111100), 2);
368 367
 			$result['aircrafttype_code'] = $aircraftType;
369 368
 			if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN";
370 369
 			elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER";
@@ -381,7 +380,7 @@  discard block
 block discarded – undo
381 380
 			elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP";
382 381
 			elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV";
383 382
 			elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT";
384
-			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
383
+			$stealth = (intval(substr($id, 0, 2), 16)&0b10000000) != 0;
385 384
 			$result['stealth'] = $stealth;
386 385
 			$result['address'] = $address;
387 386
 		    }
@@ -393,72 +392,72 @@  discard block
 block discarded – undo
393 392
 		    //$body_parse = substr($body_parse,1);
394 393
 		    //$body_parse_len = strlen($body_parse);
395 394
 
396
-		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
395
+		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) {
397 396
 			    $result['wind_dir'] = intval($matches[1]);
398
-			    $result['wind_speed'] = round(intval($matches[2])*1.60934,1);
399
-			    $result['wind_gust'] = round(intval($matches[3])*1.60934,1);
400
-			    $result['temp'] = round(5/9*((intval($matches[4]))-32),1);
401
-		    	    $body_parse = substr($body_parse,strlen($matches[0])+1);
402
-		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
397
+			    $result['wind_speed'] = round(intval($matches[2])*1.60934, 1);
398
+			    $result['wind_gust'] = round(intval($matches[3])*1.60934, 1);
399
+			    $result['temp'] = round(5/9*((intval($matches[4])) - 32), 1);
400
+		    	    $body_parse = substr($body_parse, strlen($matches[0]) + 1);
401
+		    } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) {
403 402
 			$result['wind_dir'] = intval($matches[1]);
404
-			$result['wind_speed'] = round($matches[2]*1.60934,1);
405
-			$result['wind_gust'] = round($matches[3]*1.60934,1);
406
-			$result['temp'] = round(5/9*(($matches[4])-32),1);
407
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
408
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) {
403
+			$result['wind_speed'] = round($matches[2]*1.60934, 1);
404
+			$result['wind_gust'] = round($matches[3]*1.60934, 1);
405
+			$result['temp'] = round(5/9*(($matches[4]) - 32), 1);
406
+		        $body_parse = substr($body_parse, strlen($matches[0]) + 1);
407
+		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) {
409 408
 			$result['wind_dir'] = intval($matches[1]);
410
-			$result['wind_speed'] = round($matches[2]*1.60934,1);
411
-			$result['wind_gust'] = round($matches[3]*1.60934,1);
412
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
413
-		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) {
409
+			$result['wind_speed'] = round($matches[2]*1.60934, 1);
410
+			$result['wind_gust'] = round($matches[3]*1.60934, 1);
411
+		        $body_parse = substr($body_parse, strlen($matches[0]) + 1);
412
+		    } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/', $body_parse, $matches)) {
414 413
 			$result['wind_dir'] = intval($matches[1]);
415
-			$result['wind_speed'] = round($matches[2]*1.60934,1);
416
-			$result['wind_gust'] = round($matches[3]*1.60934,1);
417
-		        $body_parse = substr($body_parse,strlen($matches[0])+1);
414
+			$result['wind_speed'] = round($matches[2]*1.60934, 1);
415
+			$result['wind_gust'] = round($matches[3]*1.60934, 1);
416
+		        $body_parse = substr($body_parse, strlen($matches[0]) + 1);
418 417
 		    }
419
-		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) {
420
-			$result['temp'] = round(5/9*(($matches[1])-32),1);
418
+		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/', $body_parse, $matches)) {
419
+			$result['temp'] = round(5/9*(($matches[1]) - 32), 1);
421 420
 		    }
422 421
 		}
423 422
 		} else $result['comment'] = trim($body_parse);
424 423
 
425 424
 	    }
426 425
 	//}
427
-	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
428
-	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
426
+	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'], 4);
427
+	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'], 4);
429 428
 	if ($debug) print_r($result);
430 429
 	return $result;
431 430
     }
432 431
     
433 432
     function connect() {
434
-	global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass,$globalName, $globalServerAPRShost, $globalServerAPRSport;
433
+	global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass, $globalName, $globalServerAPRShost, $globalServerAPRSport;
435 434
 	$aprs_connect = 0;
436 435
 	$aprs_keep = 120;
437 436
 	$aprs_last_tx = time();
438 437
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
439
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
438
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
440 439
 	if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid;
441
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
440
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
442 441
 	if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass;
443 442
 	else $aprs_pass = '-1';
444 443
 	
445
-	$aprs_filter  = '';
444
+	$aprs_filter = '';
446 445
 	$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
447 446
 	$Common = new Common();
448
-	$s = $Common->create_socket($globalServerAPRShost,$globalServerAPRSport,$errno,$errstr);
447
+	$s = $Common->create_socket($globalServerAPRShost, $globalServerAPRSport, $errno, $errstr);
449 448
 	if ($s !== false) {
450 449
 		echo 'Connected to APRS server! '."\n";
451 450
 		$authstart = time();
452 451
 		$this->socket = $s;
453
-		$send = socket_send( $this->socket  , $aprs_login , strlen($aprs_login) , 0 );
454
-		while ($msgin = socket_read($this->socket, 1000,PHP_NORMAL_READ)) {
452
+		$send = socket_send($this->socket, $aprs_login, strlen($aprs_login), 0);
453
+		while ($msgin = socket_read($this->socket, 1000, PHP_NORMAL_READ)) {
455 454
 			if (strpos($msgin, "$aprs_ssid verified") !== FALSE) {
456 455
 			    echo 'APRS user verified !'."\n";
457 456
 			    $this->connected = true;
458 457
 			    return true;
459 458
 			    break;
460 459
 			}
461
-			if (time()-$authstart > 5) {
460
+			if (time() - $authstart > 5) {
462 461
 			    echo 'APRS timeout'."\n";
463 462
 			    break;
464 463
 			}
@@ -468,20 +467,20 @@  discard block
 block discarded – undo
468 467
     
469 468
     function send($data) {
470 469
 	if ($this->connected === false) $this->connect();
471
-	$send = socket_send( $this->socket  , $data , strlen($data),0);
470
+	$send = socket_send($this->socket, $data, strlen($data), 0);
472 471
 	if ($send === FALSE) $this->connect();
473 472
     }
474 473
 }
475 474
 
476 475
 class APRSSpotter extends APRS {
477
-	function addLiveSpotterData($id,$ident,$aircraft_icao,$departure_airport,$arrival_airport,$latitude,$longitude,$waypoints,$altitude,$altitude_real,$heading,$speed,$datetime,$departure_airport_time,$arrival_airport_time,$squawk,$route_stop,$hex,$putinarchive,$registration,$pilot_id,$pilot_name, $verticalrate, $noarchive, $ground,$format_source,$source_name,$over_country) {
476
+	function addLiveSpotterData($id, $ident, $aircraft_icao, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $altitude_real, $heading, $speed, $datetime, $departure_airport_time, $arrival_airport_time, $squawk, $route_stop, $hex, $putinarchive, $registration, $pilot_id, $pilot_name, $verticalrate, $noarchive, $ground, $format_source, $source_name, $over_country) {
478 477
 		$Common = new Common();
479 478
 		if ($latitude != '' && $longitude != '') {
480
-			$latitude = $Common->convertDM($latitude,'latitude');
481
-			$longitude = $Common->convertDM($longitude,'longitude');
482
-			$coordinate = str_pad($latitude['deg'].number_format($latitude['min'],2,'.',''),7,'0',STR_PAD_LEFT).$latitude['NSEW'].'/'.str_pad($longitude['deg'].number_format($longitude['min'],2,'.',''),8,'0',STR_PAD_LEFT).$longitude['NSEW'];
483
-			$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'],2,'.',''))*1000));
484
-			$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'],2,'.',''))*1000));
479
+			$latitude = $Common->convertDM($latitude, 'latitude');
480
+			$longitude = $Common->convertDM($longitude, 'longitude');
481
+			$coordinate = str_pad($latitude['deg'].number_format($latitude['min'], 2, '.', ''), 7, '0', STR_PAD_LEFT).$latitude['NSEW'].'/'.str_pad($longitude['deg'].number_format($longitude['min'], 2, '.', ''), 8, '0', STR_PAD_LEFT).$longitude['NSEW'];
482
+			$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'], 2, '.', ''))*1000));
483
+			$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'], 2, '.', ''))*1000));
485 484
 			$w = $w1.$w2;
486 485
 			//$w = '00';
487 486
 			$custom = '';
@@ -498,19 +497,19 @@  discard block
 block discarded – undo
498 497
 				$custom .= 'AI='.$aircraft_icao;
499 498
 			}
500 499
 			if ($custom != '') $custom = ' '.$custom;
501
-			$this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.'   *'.date('His',strtotime($datetime)).'h'.$coordinate.'^'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude_real,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
500
+			$this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.'   *'.date('His', strtotime($datetime)).'h'.$coordinate.'^'.str_pad($heading, 3, '0', STR_PAD_LEFT).'/'.str_pad($speed, 3, '0', STR_PAD_LEFT).'/A='.str_pad($altitude_real, 6, '0', STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
502 501
 		}
503 502
 	}
504 503
 }
505 504
 class APRSMarine extends APRS {
506
-	function addLiveMarineData($id, $ident, $latitude, $longitude, $heading, $speed,$datetime, $putinarchive,$mmsi,$type,$typeid,$imo,$callsign,$arrival_code,$arrival_date,$status,$noarchive,$format_source,$source_name,$over_country) {
505
+	function addLiveMarineData($id, $ident, $latitude, $longitude, $heading, $speed, $datetime, $putinarchive, $mmsi, $type, $typeid, $imo, $callsign, $arrival_code, $arrival_date, $status, $noarchive, $format_source, $source_name, $over_country) {
507 506
 		$Common = new Common();
508 507
 		if ($latitude != '' && $longitude != '') {
509
-			$latitude = $Common->convertDM($latitude,'latitude');
510
-			$longitude = $Common->convertDM($longitude,'longitude');
511
-			$coordinate = str_pad($latitude['deg'].number_format($latitude['min'],2,'.',''),7,'0',STR_PAD_LEFT).$latitude['NSEW'].'/'.str_pad($longitude['deg'].number_format($longitude['min'],2,'.',''),8,'0',STR_PAD_LEFT).$longitude['NSEW'];
512
-			$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'],2,'.',''))*1000));
513
-			$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'],2,'.',''))*1000));
508
+			$latitude = $Common->convertDM($latitude, 'latitude');
509
+			$longitude = $Common->convertDM($longitude, 'longitude');
510
+			$coordinate = str_pad($latitude['deg'].number_format($latitude['min'], 2, '.', ''), 7, '0', STR_PAD_LEFT).$latitude['NSEW'].'/'.str_pad($longitude['deg'].number_format($longitude['min'], 2, '.', ''), 8, '0', STR_PAD_LEFT).$longitude['NSEW'];
511
+			$w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'], 2, '.', ''))*1000));
512
+			$w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'], 2, '.', ''))*1000));
514 513
 			$w = $w1.$w2;
515 514
 			//$w = '00';
516 515
 			$custom = '';
@@ -536,7 +535,7 @@  discard block
 block discarded – undo
536 535
 			}
537 536
 			if ($custom != '') $custom = ' '.$custom;
538 537
 			$altitude = 0;
539
-			$this->send('MARINE>APRS,TCPIP*:;'.$mmsi.'*'.date('His',strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
538
+			$this->send('MARINE>APRS,TCPIP*:;'.$mmsi.'*'.date('His', strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading, 3, '0', STR_PAD_LEFT).'/'.str_pad($speed, 3, '0', STR_PAD_LEFT).'/A='.str_pad($altitude, 6, '0', STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
540 539
 		}
541 540
 	}
542 541
 }
Please login to merge, or discard this patch.
require/class.SpotterImport.php 2 patches
Indentation   +358 added lines, -358 removed lines patch added patch discarded remove patch
@@ -10,16 +10,16 @@  discard block
 block discarded – undo
10 10
 require_once(dirname(__FILE__).'/class.Source.php');
11 11
 
12 12
 class SpotterImport {
13
-    private $all_flights = array();
14
-    private $last_delete_hourly = 0;
15
-    private $last_delete = 0;
16
-    private $stats = array();
17
-    private $tmd = 0;
18
-    private $source_location = array();
19
-    public $db = null;
20
-    public $nb = 0;
21
-
22
-    public function __construct($dbc = null) {
13
+	private $all_flights = array();
14
+	private $last_delete_hourly = 0;
15
+	private $last_delete = 0;
16
+	private $stats = array();
17
+	private $tmd = 0;
18
+	private $source_location = array();
19
+	public $db = null;
20
+	public $nb = 0;
21
+
22
+	public function __construct($dbc = null) {
23 23
 	global $globalBeta, $globalServerAPRS, $APRSSpotter;
24 24
 	$Connection = new Connection($dbc);
25 25
 	$this->db = $Connection->db();
@@ -30,23 +30,23 @@  discard block
 block discarded – undo
30 30
 	$currentdate = date('Y-m-d');
31 31
 	$sourcestat = $Stats->getStatsSource($currentdate);
32 32
 	if (!empty($sourcestat)) {
33
-	    foreach($sourcestat as $srcst) {
34
-	    	$type = $srcst['stats_type'];
33
+		foreach($sourcestat as $srcst) {
34
+			$type = $srcst['stats_type'];
35 35
 		if ($type == 'polar' || $type == 'hist') {
36
-		    $source = $srcst['source_name'];
37
-		    $data = $srcst['source_data'];
38
-		    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
39
-	        }
40
-	    }
36
+			$source = $srcst['source_name'];
37
+			$data = $srcst['source_data'];
38
+			$this->stats[$currentdate][$source][$type] = json_decode($data,true);
39
+			}
40
+		}
41 41
 	}
42 42
 	if (isset($globalServerAPRS) && $globalServerAPRS) {
43 43
 		$APRSSpotter = new APRSSpotter();
44 44
 		//$APRSSpotter->connect();
45 45
 	}
46 46
 
47
-    }
47
+	}
48 48
 
49
-    public function get_Schedule($id,$ident) {
49
+	public function get_Schedule($id,$ident) {
50 50
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
51 51
 	// Get schedule here, so it's done only one time
52 52
 	
@@ -66,42 +66,42 @@  discard block
 block discarded – undo
66 66
 	$operator = $Spotter->getOperator($ident);
67 67
 	$scheduleexist = false;
68 68
 	if ($Schedule->checkSchedule($operator) == 0) {
69
-	    $operator = $Translation->checkTranslation($ident);
70
-	    if ($Schedule->checkSchedule($operator) == 0) {
69
+		$operator = $Translation->checkTranslation($ident);
70
+		if ($Schedule->checkSchedule($operator) == 0) {
71 71
 		$schedule = $Schedule->fetchSchedule($operator);
72 72
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
73
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
74
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
75
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
76
-		    // Should also check if route schedule = route from DB
77
-		    if ($schedule['DepartureAirportIATA'] != '') {
73
+			if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
74
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
75
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
76
+			// Should also check if route schedule = route from DB
77
+			if ($schedule['DepartureAirportIATA'] != '') {
78 78
 			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
79
-			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
80
-			    if (trim($airport_icao) != '') {
79
+				$airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
80
+				if (trim($airport_icao) != '') {
81 81
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
82 82
 				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
83
-			    }
83
+				}
84
+			}
84 85
 			}
85
-		    }
86
-		    if ($schedule['ArrivalAirportIATA'] != '') {
86
+			if ($schedule['ArrivalAirportIATA'] != '') {
87 87
 			if ($this->all_flights[$id]['arrival_airport'] != $Spotter->getAirportIcao($schedule['ArrivalAirportIATA'])) {
88
-			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
89
-			    if (trim($airport_icao) != '') {
88
+				$airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
89
+				if (trim($airport_icao) != '') {
90 90
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
91 91
 				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
92
-			    }
92
+				}
93
+			}
93 94
 			}
94
-		    }
95
-		    $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
95
+			$Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
96 96
 		}
97
-	    } else $scheduleexist = true;
97
+		} else $scheduleexist = true;
98 98
 	} else $scheduleexist = true;
99 99
 	// close connection, at least one way will work ?
100
-       if ($scheduleexist) {
100
+	   if ($scheduleexist) {
101 101
 		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
102
-    		$sch = $Schedule->getSchedule($operator);
102
+			$sch = $Schedule->getSchedule($operator);
103 103
 		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time']));
104
-       }
104
+	   }
105 105
 	$Spotter->db = null;
106 106
 	$Schedule->db = null;
107 107
 	$Translation->db = null;
@@ -116,96 +116,96 @@  discard block
 block discarded – undo
116 116
 	}
117 117
 	  */
118 118
 	}
119
-    }
119
+	}
120 120
 
121
-    public function checkAll() {
121
+	public function checkAll() {
122 122
 	global $globalDebug, $globalNoImport;
123 123
 	if ($globalDebug) echo "Update last seen flights data...\n";
124 124
 	if (!isset($globalNoImport) || $globalNoImport === FALSE) {
125
-	    foreach ($this->all_flights as $key => $flight) {
125
+		foreach ($this->all_flights as $key => $flight) {
126 126
 		if (isset($this->all_flights[$key]['id'])) {
127
-		    //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
128
-    		    $Spotter = new Spotter($this->db);
129
-        	    $real_arrival = $this->arrival($key);
130
-        	    $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
131
-        	}
132
-	    }
127
+			//echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
128
+				$Spotter = new Spotter($this->db);
129
+				$real_arrival = $this->arrival($key);
130
+				$Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
131
+			}
132
+		}
133
+	}
133 134
 	}
134
-    }
135 135
 
136
-    public function arrival($key) {
136
+	public function arrival($key) {
137 137
 	global $globalClosestMinDist, $globalDebug;
138 138
 	if ($globalDebug) echo 'Update arrival...'."\n";
139 139
 	$Spotter = new Spotter($this->db);
140
-        $airport_icao = '';
141
-        $airport_time = '';
142
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
140
+		$airport_icao = '';
141
+		$airport_time = '';
142
+		if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
143 143
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
144
-	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
145
-    	    if (isset($closestAirports[0])) {
146
-        	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
147
-        	    $airport_icao = $closestAirports[0]['icao'];
148
-        	    $airport_time = $this->all_flights[$key]['datetime'];
149
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
150
-        	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
151
-        	    foreach ($closestAirports as $airport) {
152
-        		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
153
-        		    $airport_icao = $airport['icao'];
154
-        		    $airport_time = $this->all_flights[$key]['datetime'];
155
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
156
-        		    break;
157
-        		}
158
-        	    }
159
-        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
160
-        		$airport_icao = $closestAirports[0]['icao'];
161
-        		$airport_time = $this->all_flights[$key]['datetime'];
162
-        	} else {
163
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
164
-        	}
165
-    	    } else {
166
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
167
-    	    }
168
-
169
-        } else {
170
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
171
-        }
172
-        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
173
-    }
174
-
175
-
176
-
177
-    public function del() {
144
+		$closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
145
+			if (isset($closestAirports[0])) {
146
+			if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
147
+				$airport_icao = $closestAirports[0]['icao'];
148
+				$airport_time = $this->all_flights[$key]['datetime'];
149
+				if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
150
+			} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
151
+				foreach ($closestAirports as $airport) {
152
+				if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
153
+					$airport_icao = $airport['icao'];
154
+					$airport_time = $this->all_flights[$key]['datetime'];
155
+					if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
156
+					break;
157
+				}
158
+				}
159
+			} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
160
+				$airport_icao = $closestAirports[0]['icao'];
161
+				$airport_time = $this->all_flights[$key]['datetime'];
162
+			} else {
163
+				if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
164
+			}
165
+			} else {
166
+				if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
167
+			}
168
+
169
+		} else {
170
+			if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
171
+		}
172
+		return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
173
+	}
174
+
175
+
176
+
177
+	public function del() {
178 178
 	global $globalDebug, $globalNoImport;
179 179
 	// Delete old infos
180 180
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
181 181
 	foreach ($this->all_flights as $key => $flight) {
182
-    	    if (isset($flight['lastupdate'])) {
183
-        	if ($flight['lastupdate'] < (time()-3000)) {
184
-            	    if (isset($this->all_flights[$key]['id'])) {
185
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
182
+			if (isset($flight['lastupdate'])) {
183
+			if ($flight['lastupdate'] < (time()-3000)) {
184
+					if (isset($this->all_flights[$key]['id'])) {
185
+					if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
186 186
 			/*
187 187
 			$SpotterLive = new SpotterLive();
188 188
             		$SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']);
189 189
 			$SpotterLive->db = null;
190 190
 			*/
191 191
 			if (!isset($globalNoImport) || $globalNoImport === FALSE) {
192
-            		    $real_arrival = $this->arrival($key);
193
-            		    $Spotter = new Spotter($this->db);
194
-            	    	    if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
192
+						$real_arrival = $this->arrival($key);
193
+						$Spotter = new Spotter($this->db);
194
+							if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
195 195
 				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
196 196
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
197
-			    }
197
+				}
198 198
 			// Put in archive
199 199
 //				$Spotter->db = null;
200 200
 			}
201
-            	    }
202
-            	    unset($this->all_flights[$key]);
203
-    	        }
204
-	    }
205
-        }
206
-    }
201
+					}
202
+					unset($this->all_flights[$key]);
203
+				}
204
+		}
205
+		}
206
+	}
207 207
 
208
-    public function add($line) {
208
+	public function add($line) {
209 209
 	global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights, $globalServerAPRS, $APRSSpotter, $globalNoImport;
210 210
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
211 211
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
@@ -230,18 +230,18 @@  discard block
 block discarded – undo
230 230
 	
231 231
 	// SBS format is CSV format
232 232
 	if(is_array($line) && (isset($line['hex']) || isset($line['id']))) {
233
-	    //print_r($line);
234
-  	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
233
+		//print_r($line);
234
+  		if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
235 235
 
236 236
 		// Increment message number
237 237
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
238
-		    $current_date = date('Y-m-d');
239
-		    $source = $line['source_name'];
240
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
241
-		    if (!isset($this->stats[$current_date][$source]['msg'])) {
242
-		    	$this->stats[$current_date][$source]['msg']['date'] = time();
243
-		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
244
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
238
+			$current_date = date('Y-m-d');
239
+			$source = $line['source_name'];
240
+			if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
241
+			if (!isset($this->stats[$current_date][$source]['msg'])) {
242
+				$this->stats[$current_date][$source]['msg']['date'] = time();
243
+				$this->stats[$current_date][$source]['msg']['nb'] = 1;
244
+			} else $this->stats[$current_date][$source]['msg']['nb'] += 1;
245 245
 		}
246 246
 		
247 247
 		/*
@@ -257,34 +257,34 @@  discard block
 block discarded – undo
257 257
 		//$this->db = $dbc;
258 258
 
259 259
 		//$hex = trim($line['hex']);
260
-	        if (!isset($line['id'])) $id = trim($line['hex']);
261
-	        else $id = trim($line['id']);
260
+			if (!isset($line['id'])) $id = trim($line['hex']);
261
+			else $id = trim($line['id']);
262 262
 		
263 263
 		if (!isset($this->all_flights[$id])) {
264
-		    $this->all_flights[$id] = array();
265
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
266
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
267
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
268
-		    if (!isset($line['id'])) {
264
+			$this->all_flights[$id] = array();
265
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
266
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
267
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
268
+			if (!isset($line['id'])) {
269 269
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
270 270
 //			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
271 271
 //			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
272 272
 			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
273
-		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
274
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
275
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
273
+				//else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
274
+			 } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
275
+			if ($globalAllFlights !== FALSE) $dataFound = true;
276 276
 		}
277 277
 		if (isset($line['source_type']) && $line['source_type'] != '') {
278
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
278
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
279 279
 		}
280 280
 		
281 281
 		//print_r($this->all_flights);
282 282
 		if (isset($line['hex']) && !isset($this->all_flights[$id]['hex']) && ctype_xdigit($line['hex'])) {
283
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
284
-		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
283
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
284
+			//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
285 285
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
286
-		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
287
-		    if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????') && $line['format_source'] != 'whazzup' && $line['format_source'] != 'vatsimtxt' && $line['format_source'] != 'pireps' && $line['format_source'] != 'phpvmacars' && $line['format_source'] != 'vam' && $line['format_source'] != 'flightgearsp' && $line['format_source'] != 'flightgearmp') {
286
+			//} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
287
+			if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????') && $line['format_source'] != 'whazzup' && $line['format_source'] != 'vatsimtxt' && $line['format_source'] != 'pireps' && $line['format_source'] != 'phpvmacars' && $line['format_source'] != 'vam' && $line['format_source'] != 'flightgearsp' && $line['format_source'] != 'flightgearmp') {
288 288
 			$timeelapsed = microtime(true);
289 289
 			$Spotter = new Spotter($this->db);
290 290
 			if (isset($this->all_flights[$id]['source_type'])) {
@@ -295,9 +295,9 @@  discard block
 block discarded – undo
295 295
 			$Spotter->db = null;
296 296
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
297 297
 			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
298
-		    }
299
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
300
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
298
+			}
299
+			if ($globalAllFlights !== FALSE) $dataFound = true;
300
+			if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
301 301
 		}
302 302
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
303 303
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
@@ -321,9 +321,9 @@  discard block
 block discarded – undo
321 321
 		}
322 322
 		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
323 323
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60) {
324
-		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
324
+			if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
325 325
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
326
-		    } else {
326
+			} else {
327 327
 				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
328 328
 				elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
329 329
 				/*
@@ -332,41 +332,41 @@  discard block
 block discarded – undo
332 332
 				print_r($line);
333 333
 				*/
334 334
 				return '';
335
-		    }
335
+			}
336 336
 		} else {
337 337
 			date_default_timezone_set('UTC');
338 338
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
339 339
 		}
340 340
 
341 341
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') {
342
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
342
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
343 343
 		}
344 344
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
345
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
345
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
346 346
 		}
347 347
 		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
348
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id']));
348
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id']));
349 349
 		}
350 350
 		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
351
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name']));
351
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name']));
352 352
 		}
353 353
  
354 354
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) {
355
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
356
-		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
355
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
356
+			if ($this->all_flights[$id]['addedSpotter'] == 1) {
357 357
 			$timeelapsed = microtime(true);
358
-            		$Spotter = new Spotter($this->db);
359
-            		$fromsource = NULL;
360
-            		if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
361
-            		elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
358
+					$Spotter = new Spotter($this->db);
359
+					$fromsource = NULL;
360
+					if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
361
+					elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
362 362
 			elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
363 363
 			elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
364 364
 			elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
365
-            		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
365
+					$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
366 366
 			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
367 367
 			$Spotter->db = null;
368 368
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
369
-		    }
369
+			}
370 370
 
371 371
 /*
372 372
 		    if (!isset($line['id'])) {
@@ -376,26 +376,26 @@  discard block
 block discarded – undo
376 376
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
377 377
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
378 378
   */
379
-		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
379
+			if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
380 380
 
381
-		    //$putinarchive = true;
382
-		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
381
+			//$putinarchive = true;
382
+			if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
383 383
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
384
-		    }
385
-		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
384
+			}
385
+			if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
386 386
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
387
-		    }
388
-		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
389
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
390
-		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
387
+			}
388
+			if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
389
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
390
+			} elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
391 391
 				$timeelapsed = microtime(true);
392 392
 				$Spotter = new Spotter($this->db);
393 393
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
394 394
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
395
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
395
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
396 396
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
397 397
 
398
-		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
398
+			} elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
399 399
 			$timeelapsed = microtime(true);
400 400
 			$Spotter = new Spotter($this->db);
401 401
 			$route = $Spotter->getRouteInfo(trim($line['ident']));
@@ -409,67 +409,67 @@  discard block
 block discarded – undo
409 409
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
410 410
 
411 411
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
412
-			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
413
-			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
412
+				//if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
413
+				if ($route['fromairport_icao'] != $route['toairport_icao']) {
414 414
 				//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['FromAirport_ICAO'],'arrival_airport' => $route['ToAirport_ICAO'],'route_stop' => $route['RouteStop']));
415
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
416
-		    	    }
415
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
416
+					}
417 417
 			}
418 418
 			if (!isset($globalFork)) $globalFork = TRUE;
419 419
 			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
420 420
 				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
421 421
 			}
422
-		    }
422
+			}
423 423
 		}
424 424
 
425 425
 		if (isset($line['speed']) && $line['speed'] != '') {
426 426
 		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
427
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
428
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
429
-		    //$dataFound = true;
427
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
428
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
429
+			//$dataFound = true;
430 430
 		} else if (!isset($this->all_flights[$id]['speed_fromsrc']) && isset($this->all_flights[$id]['time_last_coord']) && $this->all_flights[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
431
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
432
-		    if ($distance > 1000 && $distance < 10000) {
433
-		    // use datetime
431
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
432
+			if ($distance > 1000 && $distance < 10000) {
433
+			// use datetime
434 434
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
435 435
 			$speed = $speed*3.6;
436 436
 			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
437 437
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
438
-		    }
438
+			}
439 439
 		}
440 440
 
441 441
 
442 442
 
443
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
444
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
445
-	    	    else unset($timediff);
446
-	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
443
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
444
+				if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
445
+				else unset($timediff);
446
+				if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
447 447
 			if (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude'])) {
448
-			    if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
448
+				if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
449 449
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
450 450
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
451 451
 				$this->all_flights[$id]['putinarchive'] = true;
452 452
 				$this->tmd = 0;
453 453
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
454
-				    if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
455
-				    $timeelapsed = microtime(true);
456
-				    $Spotter = new Spotter($this->db);
457
-				    $all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
458
-				    if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
459
-				    $Spotter->db = null;
460
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
461
-				    if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
454
+					if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
455
+					$timeelapsed = microtime(true);
456
+					$Spotter = new Spotter($this->db);
457
+					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
458
+					if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
459
+					$Spotter->db = null;
460
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
461
+					if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
462
+				}
462 463
 				}
463
-			    }
464 464
 			}
465 465
 
466 466
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
467
-			    //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
467
+				//if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
468 468
 				if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
469 469
 				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
470
-				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
471
-				    $dataFound = true;
472
-				    $this->all_flights[$id]['time_last_coord'] = time();
470
+					$this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
471
+					$dataFound = true;
472
+					$this->all_flights[$id]['time_last_coord'] = time();
473 473
 				}
474 474
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
475 475
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
@@ -480,20 +480,20 @@  discard block
 block discarded – undo
480 480
 				    //$putinarchive = true;
481 481
 				}
482 482
 				*/
483
-			    /*
483
+				/*
484 484
 			    } elseif (isset($this->all_flights[$id]['latitude'])) {
485 485
 				if ($globalDebug) echo '!!! Strange latitude value - diff : '.abs($this->all_flights[$id]['latitude']-$line['latitude']).'- previous lat : '.$this->all_flights[$id]['latitude'].'- new lat : '.$line['latitude']."\n";
486 486
 			    }
487 487
 			    */
488 488
 			}
489 489
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
490
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
491
-			    //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
490
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
491
+				//if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
492 492
 				if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
493 493
 				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
494
-				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
495
-				    $dataFound = true;
496
-				    $this->all_flights[$id]['time_last_coord'] = time();
494
+					$this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
495
+					$dataFound = true;
496
+					$this->all_flights[$id]['time_last_coord'] = time();
497 497
 				}
498 498
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
499 499
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
@@ -511,54 +511,54 @@  discard block
 block discarded – undo
511 511
 			    */
512 512
 			}
513 513
 
514
-		    } else if ($globalDebug && $timediff > 20) {
514
+			} else if ($globalDebug && $timediff > 20) {
515 515
 			$this->tmd = $this->tmd + 1;
516 516
 			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
517 517
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
518 518
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
519 519
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
520
-		    }
520
+			}
521 521
 		}
522 522
 		if (isset($line['last_update']) && $line['last_update'] != '') {
523
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
524
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
523
+			if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
524
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
525 525
 		}
526 526
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
527
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
528
-		    //$dataFound = true;
527
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
528
+			//$dataFound = true;
529 529
 		}
530 530
 		if (isset($line['format_source']) && $line['format_source'] != '') {
531
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
531
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
532 532
 		}
533 533
 		if (isset($line['source_name']) && $line['source_name'] != '') {
534
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
534
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
535 535
 		}
536 536
 		if (isset($line['emergency']) && $line['emergency'] != '') {
537
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
538
-		    //$dataFound = true;
537
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
538
+			//$dataFound = true;
539 539
 		}
540 540
 		if (isset($line['ground']) && $line['ground'] != '') {
541
-		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
541
+			if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
542 542
 			// Here we force archive of flight because after ground it's a new one (or should be)
543 543
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
544 544
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
545 545
 			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
546
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
546
+				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
547 547
 			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
548
-		    }
549
-		    if ($line['ground'] != 1) $line['ground'] = 0;
550
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
551
-		    //$dataFound = true;
548
+			}
549
+			if ($line['ground'] != 1) $line['ground'] = 0;
550
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
551
+			//$dataFound = true;
552 552
 		}
553 553
 		if (isset($line['squawk']) && $line['squawk'] != '') {
554
-		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
555
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
556
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
557
-			    $highlight = '';
558
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
559
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
560
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
561
-			    if ($highlight != '') {
554
+			if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
555
+				if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
556
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
557
+				$highlight = '';
558
+				if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
559
+				if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
560
+				if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
561
+				if ($highlight != '') {
562 562
 				$timeelapsed = microtime(true);
563 563
 				$Spotter = new Spotter($this->db);
564 564
 				$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
@@ -567,38 +567,38 @@  discard block
 block discarded – undo
567 567
 
568 568
 				//$putinarchive = true;
569 569
 				//$highlight = '';
570
-			    }
570
+				}
571 571
 			    
572
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
573
-		    //$dataFound = true;
572
+			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
573
+			//$dataFound = true;
574 574
 		}
575 575
 
576 576
 		if (isset($line['altitude']) && $line['altitude'] != '') {
577
-		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
577
+			//if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
578 578
 			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
579 579
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
580 580
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
581 581
 			//$dataFound = true;
582
-		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
582
+			//} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
583 583
   		}
584 584
 
585 585
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
586
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
586
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
587 587
 		}
588 588
 		
589 589
 		if (isset($line['heading']) && $line['heading'] != '') {
590
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
591
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
592
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
593
-		    //$dataFound = true;
590
+			if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
591
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
592
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
593
+			//$dataFound = true;
594 594
   		} elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) {
595
-  		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
596
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
597
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
598
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
595
+  			$heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
596
+			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
597
+			if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
598
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
599 599
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
600
-  		    // If not enough messages and ACARS set heading to 0
601
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
600
+  			// If not enough messages and ACARS set heading to 0
601
+  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
602 602
   		}
603 603
 		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
604 604
 		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
@@ -609,121 +609,121 @@  discard block
 block discarded – undo
609 609
 		//if ($dataFound == true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['ident'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
610 610
 		//if ($dataFound === true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['heading'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
611 611
 		if ($dataFound === true && isset($this->all_flights[$id]['hex'])) {
612
-		    $this->all_flights[$id]['lastupdate'] = time();
613
-		    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
614
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
615
-			    //print_r($this->all_flights);
616
-			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
617
-			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
618
-			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
612
+			$this->all_flights[$id]['lastupdate'] = time();
613
+			if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
614
+				if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
615
+				//print_r($this->all_flights);
616
+				//echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
617
+				//$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
618
+				if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
619 619
 				if ($globalDebug) echo "Check if aircraft is already in DB...";
620 620
 				$timeelapsed = microtime(true);
621 621
 				$SpotterLive = new SpotterLive($this->db);
622 622
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) {
623
-				    $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
624
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
623
+					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
624
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
625 625
 				} elseif (isset($line['id'])) {
626
-				    $recent_ident = $SpotterLive->checkIdRecent($line['id']);
627
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
626
+					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
627
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
628 628
 				} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
629
-				    $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
630
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
629
+					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
630
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
631 631
 				} else $recent_ident = '';
632 632
 				$SpotterLive->db=null;
633 633
 
634 634
 				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
635 635
 				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
636
-			    } else {
636
+				} else {
637 637
 				$recent_ident = '';
638 638
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
639
-			    }
640
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
641
-			    if($recent_ident == "")
642
-			    {
639
+				}
640
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
641
+				if($recent_ident == "")
642
+				{
643 643
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
644 644
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
645 645
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
646 646
 				//adds the spotter data for the archive
647 647
 				$ignoreImport = false;
648 648
 				foreach($globalAirportIgnore as $airportIgnore) {
649
-				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
649
+					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
650 650
 					$ignoreImport = true;
651
-				    }
651
+					}
652 652
 				}
653 653
 				if (count($globalAirportAccept) > 0) {
654
-				    $ignoreImport = true;
655
-				    foreach($globalAirportIgnore as $airportIgnore) {
654
+					$ignoreImport = true;
655
+					foreach($globalAirportIgnore as $airportIgnore) {
656 656
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
657
-					    $ignoreImport = false;
657
+						$ignoreImport = false;
658
+					}
658 659
 					}
659
-				    }
660 660
 				}
661 661
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
662
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
662
+					foreach($globalAirlineIgnore as $airlineIgnore) {
663 663
 					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
664
-					    $ignoreImport = true;
664
+						$ignoreImport = true;
665
+					}
665 666
 					}
666
-				    }
667 667
 				}
668 668
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
669
-				    $ignoreImport = true;
670
-				    foreach($globalAirlineAccept as $airlineAccept) {
669
+					$ignoreImport = true;
670
+					foreach($globalAirlineAccept as $airlineAccept) {
671 671
 					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
672
-					    $ignoreImport = false;
672
+						$ignoreImport = false;
673
+					}
673 674
 					}
674
-				    }
675 675
 				}
676 676
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
677
-				    $ignoreImport = true;
678
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
677
+					$ignoreImport = true;
678
+					foreach($globalPilotIdAccept as $pilotIdAccept) {
679 679
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
680
-					    $ignoreImport = false;
680
+						$ignoreImport = false;
681
+					}
681 682
 					}
682
-				    }
683 683
 				}
684 684
 				
685 685
 				if (!$ignoreImport) {
686
-				    $highlight = '';
687
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
688
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
689
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
690
-				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
691
-				    $timeelapsed = microtime(true);
692
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
686
+					$highlight = '';
687
+					if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
688
+					if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
689
+					if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
690
+					if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
691
+					$timeelapsed = microtime(true);
692
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
693 693
 					$Spotter = new Spotter($this->db);
694 694
 					$result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']);
695 695
 					$Spotter->db = null;
696 696
 					if ($globalDebug && isset($result)) echo $result."\n";
697
-				    }
698
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
697
+					}
698
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
699 699
 				    
700
-				    // Add source stat in DB
701
-				    $Stats = new Stats($this->db);
702
-				    if (!empty($this->stats)) {
700
+					// Add source stat in DB
701
+					$Stats = new Stats($this->db);
702
+					if (!empty($this->stats)) {
703 703
 					if ($globalDebug) echo 'Add source stats : ';
704
-				        foreach($this->stats as $date => $data) {
705
-					    foreach($data as $source => $sourced) {
706
-					        //print_r($sourced);
707
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
708
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
709
-				    		if (isset($sourced['msg'])) {
710
-				    		    if (time() - $sourced['msg']['date'] > 10) {
711
-				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
712
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
713
-			    			        unset($this->stats[$date][$source]['msg']);
714
-			    			    }
715
-			    			}
716
-			    		    }
717
-			    		    if ($date != date('Y-m-d')) {
718
-			    			unset($this->stats[$date]);
719
-			    		    }
720
-				    	}
721
-				    	if ($globalDebug) echo 'Done'."\n";
722
-
723
-				    }
724
-				    $Stats->db = null;
704
+						foreach($this->stats as $date => $data) {
705
+						foreach($data as $source => $sourced) {
706
+							//print_r($sourced);
707
+								if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
708
+								if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
709
+							if (isset($sourced['msg'])) {
710
+								if (time() - $sourced['msg']['date'] > 10) {
711
+									$nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
712
+									echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
713
+									unset($this->stats[$date][$source]['msg']);
714
+								}
715
+							}
716
+							}
717
+							if ($date != date('Y-m-d')) {
718
+							unset($this->stats[$date]);
719
+							}
720
+						}
721
+						if ($globalDebug) echo 'Done'."\n";
722
+
723
+					}
724
+					$Stats->db = null;
725 725
 				    
726
-				    $this->del();
726
+					$this->del();
727 727
 				} elseif ($globalDebug) echo 'Ignore data'."\n";
728 728
 				//$ignoreImport = false;
729 729
 				$this->all_flights[$id]['addedSpotter'] = 1;
@@ -741,37 +741,37 @@  discard block
 block discarded – undo
741 741
 			*/
742 742
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
743 743
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
744
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
745
-				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
746
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
744
+					if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
745
+					//SpotterLive->deleteLiveSpotterDataNotUpdated();
746
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
747 747
 					$SpotterLive = new SpotterLive($this->db);
748 748
 					$SpotterLive->deleteLiveSpotterData();
749 749
 					$SpotterLive->db=null;
750
-				    }
751
-				    if ($globalDebug) echo " Done\n";
752
-				    $this->last_delete = time();
750
+					}
751
+					if ($globalDebug) echo " Done\n";
752
+					$this->last_delete = time();
753 753
 				}
754
-			    } else {
754
+				} else {
755 755
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt'|| $line['format_source'] === 'planeupdatefaa'  || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson')) {
756
-				    $this->all_flights[$id]['id'] = $recent_ident;
757
-				    $this->all_flights[$id]['addedSpotter'] = 1;
756
+					$this->all_flights[$id]['id'] = $recent_ident;
757
+					$this->all_flights[$id]['addedSpotter'] = 1;
758 758
 				}
759 759
 				if (isset($globalDaemon) && !$globalDaemon) {
760
-				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
760
+					if (!isset($globalNoImport) || $globalNoImport === FALSE) {
761 761
 					$Spotter = new Spotter($this->db);
762 762
 					$Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']);
763 763
 					$Spotter->db = null;
764
-				    }
764
+					}
765 765
 				}
766 766
 				
767
-			    }
767
+				}
768 768
 			}
769
-		    }
770
-		    //adds the spotter LIVE data
771
-		    //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
772
-		    //echo "\nAdd in Live !! \n";
773
-		    //echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n";
774
-		    if ($globalDebug) {
769
+			}
770
+			//adds the spotter LIVE data
771
+			//SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
772
+			//echo "\nAdd in Live !! \n";
773
+			//echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n";
774
+			if ($globalDebug) {
775 775
 			if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
776 776
 				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";
777 777
 				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
@@ -779,49 +779,49 @@  discard block
 block discarded – undo
779 779
 				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";
780 780
 				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";
781 781
 			}
782
-		    }
783
-		    $ignoreImport = false;
784
-		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
785
-		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
782
+			}
783
+			$ignoreImport = false;
784
+			if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
785
+			if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
786 786
 
787
-		    foreach($globalAirportIgnore as $airportIgnore) {
788
-		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
789
-			    $ignoreImport = true;
787
+			foreach($globalAirportIgnore as $airportIgnore) {
788
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
789
+				$ignoreImport = true;
790
+			}
790 791
 			}
791
-		    }
792
-		    if (count($globalAirportAccept) > 0) {
793
-		        $ignoreImport = true;
794
-		        foreach($globalAirportIgnore as $airportIgnore) {
795
-			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
792
+			if (count($globalAirportAccept) > 0) {
793
+				$ignoreImport = true;
794
+				foreach($globalAirportIgnore as $airportIgnore) {
795
+				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
796 796
 				$ignoreImport = false;
797
-			    }
797
+				}
798 798
 			}
799
-		    }
800
-		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
799
+			}
800
+			if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
801 801
 			foreach($globalAirlineIgnore as $airlineIgnore) {
802
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
802
+				if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
803 803
 				$ignoreImport = true;
804
-			    }
804
+				}
805 805
 			}
806
-		    }
807
-		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
806
+			}
807
+			if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
808 808
 			$ignoreImport = true;
809 809
 			foreach($globalAirlineAccept as $airlineAccept) {
810
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
810
+				if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
811 811
 				$ignoreImport = false;
812
-			    }
812
+				}
813
+			}
813 814
 			}
814
-		    }
815
-		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
815
+			if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
816 816
 			$ignoreImport = true;
817 817
 			foreach($globalPilotIdAccept as $pilotIdAccept) {
818
-			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
819
-			        $ignoreImport = false;
820
-			    }
818
+				if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
819
+					$ignoreImport = false;
820
+				}
821
+			}
821 822
 			}
822
-		    }
823 823
 
824
-		    if (!$ignoreImport) {
824
+			if (!$ignoreImport) {
825 825
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
826 826
 				$timeelapsed = microtime(true);
827 827
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
@@ -866,7 +866,7 @@  discard block
 block discarded – undo
866 866
 					if ($stats_heading == 16) $stats_heading = 0;
867 867
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
868 868
 						for ($i=0;$i<=15;$i++) {
869
-						    $this->stats[$current_date][$source]['polar'][$i] = 0;
869
+							$this->stats[$current_date][$source]['polar'][$i] = 0;
870 870
 						}
871 871
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
872 872
 					} else {
@@ -879,11 +879,11 @@  discard block
 block discarded – undo
879 879
 					//var_dump($this->stats);
880 880
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
881 881
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
882
-						    end($this->stats[$current_date][$source]['hist']);
883
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
882
+							end($this->stats[$current_date][$source]['hist']);
883
+							$mini = key($this->stats[$current_date][$source]['hist'])+10;
884 884
 						} else $mini = 0;
885 885
 						for ($i=$mini;$i<=$distance;$i+=10) {
886
-						    $this->stats[$current_date][$source]['hist'][$i] = 0;
886
+							$this->stats[$current_date][$source]['hist'][$i] = 0;
887 887
 						}
888 888
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
889 889
 					} else {
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
 			//$this->del();
899 899
 			
900 900
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
901
-			    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
901
+				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
902 902
 				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
903 903
 				$SpotterLive = new SpotterLive($this->db);
904 904
 				$SpotterLive->deleteLiveSpotterDataNotUpdated();
@@ -906,19 +906,19 @@  discard block
 block discarded – undo
906 906
 				//SpotterLive->deleteLiveSpotterData();
907 907
 				if ($globalDebug) echo " Done\n";
908 908
 				$this->last_delete_hourly = time();
909
-			    } else {
909
+				} else {
910 910
 				$this->del();
911 911
 				$this->last_delete_hourly = time();
912
-			    }
912
+				}
913 913
 			}
914 914
 			
915
-		    }
916
-		    //$ignoreImport = false;
915
+			}
916
+			//$ignoreImport = false;
917 917
 		}
918 918
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
919 919
 		if ($send) return $this->all_flights[$id];
920
-	    }
920
+		}
921
+	}
921 922
 	}
922
-    }
923 923
 }
924 924
 ?>
Please login to merge, or discard this patch.
Spacing   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -30,12 +30,12 @@  discard block
 block discarded – undo
30 30
 	$currentdate = date('Y-m-d');
31 31
 	$sourcestat = $Stats->getStatsSource($currentdate);
32 32
 	if (!empty($sourcestat)) {
33
-	    foreach($sourcestat as $srcst) {
33
+	    foreach ($sourcestat as $srcst) {
34 34
 	    	$type = $srcst['stats_type'];
35 35
 		if ($type == 'polar' || $type == 'hist') {
36 36
 		    $source = $srcst['source_name'];
37 37
 		    $data = $srcst['source_data'];
38
-		    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
38
+		    $this->stats[$currentdate][$source][$type] = json_decode($data, true);
39 39
 	        }
40 40
 	    }
41 41
 	}
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 
47 47
     }
48 48
 
49
-    public function get_Schedule($id,$ident) {
49
+    public function get_Schedule($id, $ident) {
50 50
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
51 51
 	// Get schedule here, so it's done only one time
52 52
 	
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
 		$schedule = $Schedule->fetchSchedule($operator);
72 72
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
73 73
 		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
74
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
75
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
74
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $schedule['DepartureTime']));
75
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $schedule['ArrivalTime']));
76 76
 		    // Should also check if route schedule = route from DB
77 77
 		    if ($schedule['DepartureAirportIATA'] != '') {
78 78
 			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 			    }
93 93
 			}
94 94
 		    }
95
-		    $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
95
+		    $Schedule->addSchedule($operator, $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['arrival_airport_time'], $schedule['Source']);
96 96
 		}
97 97
 	    } else $scheduleexist = true;
98 98
 	} else $scheduleexist = true;
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
        if ($scheduleexist) {
101 101
 		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
102 102
     		$sch = $Schedule->getSchedule($operator);
103
-		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time']));
103
+		$this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport' => $sch['arrival_airport_icao'], 'departure_airport' => $sch['departure_airport_icao'], 'departure_airport_time' => $sch['departure_airport_time'], 'arrival_airport_time' => $sch['arrival_airport_time']));
104 104
        }
105 105
 	$Spotter->db = null;
106 106
 	$Schedule->db = null;
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 		    //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
128 128
     		    $Spotter = new Spotter($this->db);
129 129
         	    $real_arrival = $this->arrival($key);
130
-        	    $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
130
+        	    $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'], $this->all_flights[$key]['ident'], $this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $this->all_flights[$key]['altitude'], $this->all_flights[$key]['ground'], $this->all_flights[$key]['speed'], $this->all_flights[$key]['datetime'], $real_arrival['airport_icao'], $real_arrival['airport_time']);
131 131
         	}
132 132
 	    }
133 133
 	}
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
         $airport_time = '';
142 142
         if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
143 143
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
144
-	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
144
+	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $globalClosestMinDist);
145 145
     	    if (isset($closestAirports[0])) {
146 146
         	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
147 147
         	    $airport_icao = $closestAirports[0]['icao'];
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
         		    break;
157 157
         		}
158 158
         	    }
159
-        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
159
+        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude'] + 5000))) {
160 160
         		$airport_icao = $closestAirports[0]['icao'];
161 161
         		$airport_time = $this->all_flights[$key]['datetime'];
162 162
         	} else {
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
         } else {
170 170
         	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
171 171
         }
172
-        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
172
+        return array('airport_icao' => $airport_icao, 'airport_time' => $airport_time);
173 173
     }
174 174
 
175 175
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
181 181
 	foreach ($this->all_flights as $key => $flight) {
182 182
     	    if (isset($flight['lastupdate'])) {
183
-        	if ($flight['lastupdate'] < (time()-3000)) {
183
+        	if ($flight['lastupdate'] < (time() - 3000)) {
184 184
             	    if (isset($this->all_flights[$key]['id'])) {
185 185
             		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
186 186
 			/*
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
             		    $real_arrival = $this->arrival($key);
193 193
             		    $Spotter = new Spotter($this->db);
194 194
             	    	    if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
195
-				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
195
+				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'], $this->all_flights[$key]['ident'], $this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $this->all_flights[$key]['altitude'], $this->all_flights[$key]['ground'], $this->all_flights[$key]['speed'], $this->all_flights[$key]['datetime'], $real_arrival['airport_icao'], $real_arrival['airport_time']);
196 196
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
197 197
 			    }
198 198
 			// Put in archive
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 	$send = false;
230 230
 	
231 231
 	// SBS format is CSV format
232
-	if(is_array($line) && (isset($line['hex']) || isset($line['id']))) {
232
+	if (is_array($line) && (isset($line['hex']) || isset($line['id']))) {
233 233
 	    //print_r($line);
234 234
   	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
235 235
 
@@ -262,25 +262,25 @@  discard block
 block discarded – undo
262 262
 		
263 263
 		if (!isset($this->all_flights[$id])) {
264 264
 		    $this->all_flights[$id] = array();
265
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
266
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
267
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
265
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
266
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => '', 'departure_airport' => '', 'arrival_airport' => '', 'latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '', 'altitude_real' => '', 'heading' => '', 'departure_airport_time' => '', 'arrival_airport_time' => '', 'squawk' => '', 'route_stop' => '', 'registration' => '', 'pilot_id' => '', 'pilot_name' => '', 'waypoints' => '', 'ground' => '0', 'format_source' => '', 'source_name' => '', 'over_country' => '', 'verticalrate' => '', 'noarchive' => false, 'putinarchive' => true, 'source_type' => ''));
267
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('lastupdate' => time()));
268 268
 		    if (!isset($line['id'])) {
269 269
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
270 270
 //			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
271 271
 //			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
272
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
272
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $id.'-'.date('YmdHi')));
273 273
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
274
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
274
+		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
275 275
 		    if ($globalAllFlights !== FALSE) $dataFound = true;
276 276
 		}
277 277
 		if (isset($line['source_type']) && $line['source_type'] != '') {
278
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
278
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('source_type' => $line['source_type']));
279 279
 		}
280 280
 		
281 281
 		//print_r($this->all_flights);
282 282
 		if (isset($line['hex']) && !isset($this->all_flights[$id]['hex']) && ctype_xdigit($line['hex'])) {
283
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
283
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('hex' => trim($line['hex'])));
284 284
 		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
285 285
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
286 286
 		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
@@ -288,41 +288,41 @@  discard block
 block discarded – undo
288 288
 			$timeelapsed = microtime(true);
289 289
 			$Spotter = new Spotter($this->db);
290 290
 			if (isset($this->all_flights[$id]['source_type'])) {
291
-				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']),$this->all_flights[$id]['source_type']);
291
+				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']), $this->all_flights[$id]['source_type']);
292 292
 			} else {
293 293
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
294 294
 			}
295 295
 			$Spotter->db = null;
296
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
297
-			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
296
+			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
297
+			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
298 298
 		    }
299 299
 		    if ($globalAllFlights !== FALSE) $dataFound = true;
300 300
 		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
301 301
 		}
302 302
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
303
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
303
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $line['aircraft_icao']));
304 304
 		}
305 305
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_name'])) {
306 306
 			// Get aircraft ICAO from aircraft name
307 307
 			$Spotter = new Spotter($this->db);
308 308
 			$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
309 309
 			$Spotter->db = null;
310
-			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
310
+			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
311 311
 		}
312 312
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) {
313 313
 			if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
314 314
 			elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
315 315
 			elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
316 316
 			elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
317
-			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
317
+			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
318 318
 		}
319 319
 		if (!isset($this->all_flights[$id]['aircraft_icao'])) {
320
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
320
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => 'NA'));
321 321
 		}
322 322
 		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
323
-		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60) {
323
+		if (isset($line['datetime']) && strtotime($line['datetime']) > time() - 20*60) {
324 324
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
325
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
325
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => $line['datetime']));
326 326
 		    } else {
327 327
 				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
328 328
 				elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
@@ -335,24 +335,24 @@  discard block
 block discarded – undo
335 335
 		    }
336 336
 		} else {
337 337
 			date_default_timezone_set('UTC');
338
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
338
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => date('Y-m-d H:i:s')));
339 339
 		}
340 340
 
341 341
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') {
342
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
342
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('registration' => $line['registration']));
343 343
 		}
344 344
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
345
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
345
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('waypoints' => $line['waypoints']));
346 346
 		}
347 347
 		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
348
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id']));
348
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_id' => $line['pilot_id']));
349 349
 		}
350 350
 		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
351
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name']));
351
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_name' => $line['pilot_name']));
352 352
 		}
353 353
  
354 354
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) {
355
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
355
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => trim($line['ident'])));
356 356
 		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
357 357
 			$timeelapsed = microtime(true);
358 358
             		$Spotter = new Spotter($this->db);
@@ -362,10 +362,10 @@  discard block
 block discarded – undo
362 362
 			elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
363 363
 			elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
364 364
 			elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
365
-            		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
365
+            		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $fromsource);
366 366
 			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
367 367
 			$Spotter->db = null;
368
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
368
+			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
369 369
 		    }
370 370
 
371 371
 /*
@@ -376,24 +376,24 @@  discard block
 block discarded – undo
376 376
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
377 377
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
378 378
   */
379
-		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
379
+		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
380 380
 
381 381
 		    //$putinarchive = true;
382 382
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
383
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
383
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $line['departure_airport_time']));
384 384
 		    }
385 385
 		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
386
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
386
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $line['arrival_airport_time']));
387 387
 		    }
388 388
 		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
389
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
389
+		    		$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport' => $line['departure_airport_icao'], 'arrival_airport' => $line['arrival_airport_icao'], 'route_stop' => ''));
390 390
 		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
391 391
 				$timeelapsed = microtime(true);
392 392
 				$Spotter = new Spotter($this->db);
393 393
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
394 394
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
395
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
396
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
395
+		    		$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport' => $line['departure_airport_icao'], 'arrival_airport' => $line['arrival_airport_icao'], 'route_stop' => ''));
396
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
397 397
 
398 398
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
399 399
 			$timeelapsed = microtime(true);
@@ -406,34 +406,34 @@  discard block
 block discarded – undo
406 406
 				$Translation->db = null;
407 407
 			}
408 408
 			$Spotter->db = null;
409
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
409
+			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
410 410
 
411 411
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
412 412
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
413 413
 			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
414 414
 				//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['FromAirport_ICAO'],'arrival_airport' => $route['ToAirport_ICAO'],'route_stop' => $route['RouteStop']));
415
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
415
+		    		$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport' => $route['fromairport_icao'], 'arrival_airport' => $route['toairport_icao'], 'route_stop' => $route['routestop']));
416 416
 		    	    }
417 417
 			}
418 418
 			if (!isset($globalFork)) $globalFork = TRUE;
419 419
 			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
420
-				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
420
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id, trim($line['ident']));
421 421
 			}
422 422
 		    }
423 423
 		}
424 424
 
425 425
 		if (isset($line['speed']) && $line['speed'] != '') {
426 426
 		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
427
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
428
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
427
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($line['speed'])));
428
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed_fromsrc' => true));
429 429
 		    //$dataFound = true;
430 430
 		} else if (!isset($this->all_flights[$id]['speed_fromsrc']) && isset($this->all_flights[$id]['time_last_coord']) && $this->all_flights[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
431
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
431
+		    $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm');
432 432
 		    if ($distance > 1000 && $distance < 10000) {
433 433
 		    // use datetime
434 434
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
435 435
 			$speed = $speed*3.6;
436
-			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
436
+			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($speed)));
437 437
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
438 438
 		    }
439 439
 		}
@@ -441,11 +441,11 @@  discard block
 block discarded – undo
441 441
 
442 442
 
443 443
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
444
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
444
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time() - $this->all_flights[$id]['time_last_coord']);
445 445
 	    	    else unset($timediff);
446
-	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
446
+	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff, $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')))) {
447 447
 			if (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude'])) {
448
-			    if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
448
+			    if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'], $this->all_flights[$id]['archive_longitude'], $this->all_flights[$id]['livedb_latitude'], $this->all_flights[$id]['livedb_longitude'], $line['latitude'], $line['longitude'])) {
449 449
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
450 450
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
451 451
 				$this->all_flights[$id]['putinarchive'] = true;
@@ -454,10 +454,10 @@  discard block
 block discarded – undo
454 454
 				    if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
455 455
 				    $timeelapsed = microtime(true);
456 456
 				    $Spotter = new Spotter($this->db);
457
-				    $all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
457
+				    $all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']);
458 458
 				    if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
459 459
 				    $Spotter->db = null;
460
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
460
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
461 461
 				    if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
462 462
 				}
463 463
 			    }
@@ -466,13 +466,13 @@  discard block
 block discarded – undo
466 466
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
467 467
 			    //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
468 468
 				if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
469
-				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
469
+				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude'] - $line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
470 470
 				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
471 471
 				    $dataFound = true;
472 472
 				    $this->all_flights[$id]['time_last_coord'] = time();
473 473
 				}
474 474
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
475
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
475
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('latitude' => $line['latitude']));
476 476
 				/*
477 477
 				if (abs($this->all_flights[$id]['archive_latitude']-$this->all_flights[$id]['latitude']) > 0.3) {
478 478
 				    $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
@@ -490,13 +490,13 @@  discard block
 block discarded – undo
490 490
 			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
491 491
 			    //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
492 492
 				if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
493
-				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
493
+				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude'] - $line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
494 494
 				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
495 495
 				    $dataFound = true;
496 496
 				    $this->all_flights[$id]['time_last_coord'] = time();
497 497
 				}
498 498
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
499
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
499
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('longitude' => $line['longitude']));
500 500
 				/*
501 501
 				if (abs($this->all_flights[$id]['archive_longitude']-$this->all_flights[$id]['longitude']) > 0.3) {
502 502
 				    $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
@@ -514,46 +514,46 @@  discard block
 block discarded – undo
514 514
 		    } else if ($globalDebug && $timediff > 20) {
515 515
 			$this->tmd = $this->tmd + 1;
516 516
 			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
517
-			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
518
-			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
517
+			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')."m -";
518
+			echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - ";
519 519
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
520 520
 		    }
521 521
 		}
522 522
 		if (isset($line['last_update']) && $line['last_update'] != '') {
523 523
 		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
524
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
524
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('last_update' => $line['last_update']));
525 525
 		}
526 526
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
527
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
527
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('verticalrate' => $line['verticalrate']));
528 528
 		    //$dataFound = true;
529 529
 		}
530 530
 		if (isset($line['format_source']) && $line['format_source'] != '') {
531
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
531
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('format_source' => $line['format_source']));
532 532
 		}
533 533
 		if (isset($line['source_name']) && $line['source_name'] != '') {
534
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
534
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('source_name' => $line['source_name']));
535 535
 		}
536 536
 		if (isset($line['emergency']) && $line['emergency'] != '') {
537
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
537
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('emergency' => $line['emergency']));
538 538
 		    //$dataFound = true;
539 539
 		}
540 540
 		if (isset($line['ground']) && $line['ground'] != '') {
541 541
 		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
542 542
 			// Here we force archive of flight because after ground it's a new one (or should be)
543
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
544
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
545
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
546
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
547
-			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
543
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
544
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1));
545
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
546
+		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
547
+			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
548 548
 		    }
549 549
 		    if ($line['ground'] != 1) $line['ground'] = 0;
550
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
550
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ground' => $line['ground']));
551 551
 		    //$dataFound = true;
552 552
 		}
553 553
 		if (isset($line['squawk']) && $line['squawk'] != '') {
554 554
 		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
555 555
 			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
556
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
556
+			    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk']));
557 557
 			    $highlight = '';
558 558
 			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
559 559
 			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
@@ -561,47 +561,47 @@  discard block
 block discarded – undo
561 561
 			    if ($highlight != '') {
562 562
 				$timeelapsed = microtime(true);
563 563
 				$Spotter = new Spotter($this->db);
564
-				$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
564
+				$Spotter->setHighlightFlight($this->all_flights[$id]['id'], $highlight);
565 565
 				$Spotter->db = null;
566
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
566
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
567 567
 
568 568
 				//$putinarchive = true;
569 569
 				//$highlight = '';
570 570
 			    }
571 571
 			    
572
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
572
+		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk']));
573 573
 		    //$dataFound = true;
574 574
 		}
575 575
 
576 576
 		if (isset($line['altitude']) && $line['altitude'] != '') {
577 577
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
578
-			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
579
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
580
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
578
+			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100) - $this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
579
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude' => round($line['altitude']/100)));
580
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude_real' => $line['altitude']));
581 581
 			//$dataFound = true;
582 582
 		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
583 583
   		}
584 584
 
585 585
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
586
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
586
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('noarchive' => true));
587 587
 		}
588 588
 		
589 589
 		if (isset($line['heading']) && $line['heading'] != '') {
590
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
591
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
592
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
590
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading'] - round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
591
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($line['heading'])));
592
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading_fromsrc' => true));
593 593
 		    //$dataFound = true;
594 594
   		} elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) {
595
-  		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
596
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
597
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
595
+  		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'], $this->all_flights[$id]['archive_longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
596
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($heading)));
597
+		    if (abs($this->all_flights[$id]['heading'] - round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
598 598
   		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
599 599
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
600 600
   		    // If not enough messages and ACARS set heading to 0
601
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
601
+  		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => 0));
602 602
   		}
603
-		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
604
-		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
603
+		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
604
+		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
605 605
 
606 606
 //		print_r($this->all_flights[$id]);
607 607
 		//gets the callsign from the last hour
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
 		if ($dataFound === true && isset($this->all_flights[$id]['hex'])) {
612 612
 		    $this->all_flights[$id]['lastupdate'] = time();
613 613
 		    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
614
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
614
+		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == '' || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
615 615
 			    //print_r($this->all_flights);
616 616
 			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
617 617
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
@@ -621,61 +621,61 @@  discard block
 block discarded – undo
621 621
 				$SpotterLive = new SpotterLive($this->db);
622 622
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) {
623 623
 				    $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
624
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
624
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
625 625
 				} elseif (isset($line['id'])) {
626 626
 				    $recent_ident = $SpotterLive->checkIdRecent($line['id']);
627
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
627
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
628 628
 				} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
629 629
 				    $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
630
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
630
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
631 631
 				} else $recent_ident = '';
632
-				$SpotterLive->db=null;
632
+				$SpotterLive->db = null;
633 633
 
634 634
 				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
635 635
 				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
636 636
 			    } else {
637 637
 				$recent_ident = '';
638
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
638
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 0));
639 639
 			    }
640 640
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
641
-			    if($recent_ident == "")
641
+			    if ($recent_ident == "")
642 642
 			    {
643 643
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
644 644
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
645 645
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
646 646
 				//adds the spotter data for the archive
647 647
 				$ignoreImport = false;
648
-				foreach($globalAirportIgnore as $airportIgnore) {
648
+				foreach ($globalAirportIgnore as $airportIgnore) {
649 649
 				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
650 650
 					$ignoreImport = true;
651 651
 				    }
652 652
 				}
653 653
 				if (count($globalAirportAccept) > 0) {
654 654
 				    $ignoreImport = true;
655
-				    foreach($globalAirportIgnore as $airportIgnore) {
655
+				    foreach ($globalAirportIgnore as $airportIgnore) {
656 656
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
657 657
 					    $ignoreImport = false;
658 658
 					}
659 659
 				    }
660 660
 				}
661 661
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
662
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
663
-					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
662
+				    foreach ($globalAirlineIgnore as $airlineIgnore) {
663
+					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineIgnore)) {
664 664
 					    $ignoreImport = true;
665 665
 					}
666 666
 				    }
667 667
 				}
668 668
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
669 669
 				    $ignoreImport = true;
670
-				    foreach($globalAirlineAccept as $airlineAccept) {
671
-					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
670
+				    foreach ($globalAirlineAccept as $airlineAccept) {
671
+					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineAccept)) {
672 672
 					    $ignoreImport = false;
673 673
 					}
674 674
 				    }
675 675
 				}
676 676
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
677 677
 				    $ignoreImport = true;
678
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
678
+				    foreach ($globalPilotIdAccept as $pilotIdAccept) {
679 679
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
680 680
 					    $ignoreImport = false;
681 681
 					}
@@ -687,29 +687,29 @@  discard block
 block discarded – undo
687 687
 				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
688 688
 				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
689 689
 				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
690
-				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
690
+				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
691 691
 				    $timeelapsed = microtime(true);
692 692
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
693 693
 					$Spotter = new Spotter($this->db);
694
-					$result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']);
694
+					$result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'], $this->all_flights[$id]['route_stop'], $highlight, $this->all_flights[$id]['hex'], $this->all_flights[$id]['registration'], $this->all_flights[$id]['pilot_id'], $this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['format_source'], $this->all_flights[$id]['source_name'], $this->all_flights[$id]['source_type']);
695 695
 					$Spotter->db = null;
696 696
 					if ($globalDebug && isset($result)) echo $result."\n";
697 697
 				    }
698
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
698
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
699 699
 				    
700 700
 				    // Add source stat in DB
701 701
 				    $Stats = new Stats($this->db);
702 702
 				    if (!empty($this->stats)) {
703 703
 					if ($globalDebug) echo 'Add source stats : ';
704
-				        foreach($this->stats as $date => $data) {
705
-					    foreach($data as $source => $sourced) {
704
+				        foreach ($this->stats as $date => $data) {
705
+					    foreach ($data as $source => $sourced) {
706 706
 					        //print_r($sourced);
707
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
708
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
707
+				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']), $source, 'polar', $date);
708
+				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']), $source, 'hist', $date);
709 709
 				    		if (isset($sourced['msg'])) {
710 710
 				    		    if (time() - $sourced['msg']['date'] > 10) {
711 711
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
712
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
712
+				    		        echo $Stats->addStatSource($nbmsg, $source, 'msg', $date);
713 713
 			    			        unset($this->stats[$date][$source]['msg']);
714 714
 			    			    }
715 715
 			    			}
@@ -746,20 +746,20 @@  discard block
 block discarded – undo
746 746
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
747 747
 					$SpotterLive = new SpotterLive($this->db);
748 748
 					$SpotterLive->deleteLiveSpotterData();
749
-					$SpotterLive->db=null;
749
+					$SpotterLive->db = null;
750 750
 				    }
751 751
 				    if ($globalDebug) echo " Done\n";
752 752
 				    $this->last_delete = time();
753 753
 				}
754 754
 			    } else {
755
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt'|| $line['format_source'] === 'planeupdatefaa'  || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson')) {
755
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson')) {
756 756
 				    $this->all_flights[$id]['id'] = $recent_ident;
757 757
 				    $this->all_flights[$id]['addedSpotter'] = 1;
758 758
 				}
759 759
 				if (isset($globalDaemon) && !$globalDaemon) {
760 760
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
761 761
 					$Spotter = new Spotter($this->db);
762
-					$Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']);
762
+					$Spotter->updateLatestSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['arrival_airport_time']);
763 763
 					$Spotter->db = null;
764 764
 				    }
765 765
 				}
@@ -784,37 +784,37 @@  discard block
 block discarded – undo
784 784
 		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
785 785
 		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
786 786
 
787
-		    foreach($globalAirportIgnore as $airportIgnore) {
787
+		    foreach ($globalAirportIgnore as $airportIgnore) {
788 788
 		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
789 789
 			    $ignoreImport = true;
790 790
 			}
791 791
 		    }
792 792
 		    if (count($globalAirportAccept) > 0) {
793 793
 		        $ignoreImport = true;
794
-		        foreach($globalAirportIgnore as $airportIgnore) {
794
+		        foreach ($globalAirportIgnore as $airportIgnore) {
795 795
 			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
796 796
 				$ignoreImport = false;
797 797
 			    }
798 798
 			}
799 799
 		    }
800 800
 		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
801
-			foreach($globalAirlineIgnore as $airlineIgnore) {
802
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
801
+			foreach ($globalAirlineIgnore as $airlineIgnore) {
802
+			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineIgnore)) {
803 803
 				$ignoreImport = true;
804 804
 			    }
805 805
 			}
806 806
 		    }
807 807
 		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
808 808
 			$ignoreImport = true;
809
-			foreach($globalAirlineAccept as $airlineAccept) {
810
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
809
+			foreach ($globalAirlineAccept as $airlineAccept) {
810
+			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineAccept)) {
811 811
 				$ignoreImport = false;
812 812
 			    }
813 813
 			}
814 814
 		    }
815 815
 		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
816 816
 			$ignoreImport = true;
817
-			foreach($globalPilotIdAccept as $pilotIdAccept) {
817
+			foreach ($globalPilotIdAccept as $pilotIdAccept) {
818 818
 			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
819 819
 			        $ignoreImport = false;
820 820
 			    }
@@ -822,20 +822,20 @@  discard block
 block discarded – undo
822 822
 		    }
823 823
 
824 824
 		    if (!$ignoreImport) {
825
-			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
825
+			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
826 826
 				$timeelapsed = microtime(true);
827 827
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
828 828
 					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
829 829
 					$SpotterLive = new SpotterLive($this->db);
830
-					$result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
830
+					$result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'], $this->all_flights[$id]['route_stop'], $this->all_flights[$id]['hex'], $this->all_flights[$id]['putinarchive'], $this->all_flights[$id]['registration'], $this->all_flights[$id]['pilot_id'], $this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['format_source'], $this->all_flights[$id]['source_name'], $this->all_flights[$id]['over_country']);
831 831
 					$SpotterLive->db = null;
832 832
 					if ($globalDebug) echo $result."\n";
833 833
 				}
834 834
 				if (isset($globalServerAPRS) && $globalServerAPRS) {
835
-					$APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
835
+					$APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'], $this->all_flights[$id]['route_stop'], $this->all_flights[$id]['hex'], $this->all_flights[$id]['putinarchive'], $this->all_flights[$id]['registration'], $this->all_flights[$id]['pilot_id'], $this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['format_source'], $this->all_flights[$id]['source_name'], $this->all_flights[$id]['over_country']);
836 836
 				}
837 837
 				$this->all_flights[$id]['putinarchive'] = false;
838
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
838
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
839 839
 
840 840
 				// Put statistics in $this->stats variable
841 841
 				//if ($line['format_source'] != 'aprs') {
@@ -853,19 +853,19 @@  discard block
 block discarded – undo
853 853
 							$latitude = $globalCenterLatitude;
854 854
 							$longitude = $globalCenterLongitude;
855 855
 						}
856
-						$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude);
856
+						$this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude);
857 857
 					} else {
858 858
 						$latitude = $this->source_location[$source]['latitude'];
859 859
 						$longitude = $this->source_location[$source]['longitude'];
860 860
 					}
861
-					$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
861
+					$stats_heading = $Common->getHeading($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
862 862
 					//$stats_heading = $stats_heading%22.5;
863 863
 					$stats_heading = round($stats_heading/22.5);
864
-					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
864
+					$stats_distance = $Common->distance($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
865 865
 					$current_date = date('Y-m-d');
866 866
 					if ($stats_heading == 16) $stats_heading = 0;
867 867
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
868
-						for ($i=0;$i<=15;$i++) {
868
+						for ($i = 0; $i <= 15; $i++) {
869 869
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
870 870
 						}
871 871
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
@@ -880,9 +880,9 @@  discard block
 block discarded – undo
880 880
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
881 881
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
882 882
 						    end($this->stats[$current_date][$source]['hist']);
883
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
883
+						    $mini = key($this->stats[$current_date][$source]['hist']) + 10;
884 884
 						} else $mini = 0;
885
-						for ($i=$mini;$i<=$distance;$i+=10) {
885
+						for ($i = $mini; $i <= $distance; $i += 10) {
886 886
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
887 887
 						}
888 888
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
@@ -894,7 +894,7 @@  discard block
 block discarded – undo
894 894
 				$this->all_flights[$id]['lastupdate'] = time();
895 895
 				if ($this->all_flights[$id]['putinarchive']) $send = true;
896 896
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
897
-			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
897
+			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude'])."\n";
898 898
 			//$this->del();
899 899
 			
900 900
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
Please login to merge, or discard this patch.
scripts/daemon-spotter.php 2 patches
Indentation   +854 added lines, -854 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,47 +24,47 @@  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
 /*
69 69
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
70 70
     $SI = new adsb2aprs();
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
 } else $SI=new SpotterImport($Connection->db);
74 74
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
75 75
 if (isset($globalMarine) && $globalMarine) {
76
-    $AIS = new AIS();
77
-    $MI = new MarineImport($Connection->db);
76
+	$AIS = new AIS();
77
+	$MI = new MarineImport($Connection->db);
78 78
 }
79 79
 //$APRS=new APRS($Connection->db);
80 80
 $SBS=new SBS();
@@ -84,12 +84,12 @@  discard block
 block discarded – undo
84 84
 //$servertz = system('date +%Z');
85 85
 // signal handler - playing nice with sockets and dump1090
86 86
 if (function_exists('pcntl_fork')) {
87
-    pcntl_signal(SIGINT,  function() {
88
-        global $sockets;
89
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
90
-        die("Bye!\n");
91
-    });
92
-    pcntl_signal_dispatch();
87
+	pcntl_signal(SIGINT,  function() {
88
+		global $sockets;
89
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
90
+		die("Bye!\n");
91
+	});
92
+	pcntl_signal_dispatch();
93 93
 }
94 94
 
95 95
 // let's try and connect
@@ -99,151 +99,151 @@  discard block
 block discarded – undo
99 99
 $reset = 0;
100 100
 
101 101
 function connect_all($hosts) {
102
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
103
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
104
-    $reset++;
105
-    if ($globalDebug) echo 'Connect to all...'."\n";
106
-    foreach ($hosts as $id => $value) {
102
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
103
+	global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
104
+	$reset++;
105
+	if ($globalDebug) echo 'Connect to all...'."\n";
106
+	foreach ($hosts as $id => $value) {
107 107
 	$host = $value['host'];
108 108
 	$globalSources[$id]['last_exec'] = 0;
109 109
 	// Here we check type of source(s)
110 110
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
111
-            if (preg_match('/deltadb.txt$/i',$host)) {
112
-        	//$formats[$id] = 'deltadbtxt';
113
-        	$globalSources[$id]['format'] = 'deltadbtxt';
114
-        	//$last_exec['deltadbtxt'] = 0;
115
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
116
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
117
-        	//$formats[$id] = 'vatsimtxt';
118
-        	$globalSources[$id]['format'] = 'vatsimtxt';
119
-        	//$last_exec['vatsimtxt'] = 0;
120
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
121
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
122
-        	//$formats[$id] = 'aircraftlistjson';
123
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
124
-        	//$last_exec['aircraftlistjson'] = 0;
125
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
126
-    	    } else if (preg_match('/opensky/i',$host)) {
127
-        	//$formats[$id] = 'aircraftlistjson';
128
-        	$globalSources[$id]['format'] = 'opensky';
129
-        	//$last_exec['aircraftlistjson'] = 0;
130
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
131
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
132
-        	//$formats[$id] = 'radarvirtueljson';
133
-        	$globalSources[$id]['format'] = 'radarvirtueljson';
134
-        	//$last_exec['radarvirtueljson'] = 0;
135
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
136
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
137
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
138
-        	    exit(0);
139
-        	}
140
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
141
-        	//$formats[$id] = 'planeupdatefaa';
142
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
143
-        	//$last_exec['planeupdatefaa'] = 0;
144
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
145
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
146
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
147
-        	    exit(0);
148
-        	}
149
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
150
-        	//$formats[$id] = 'phpvmacars';
151
-        	$globalSources[$id]['format'] = 'phpvmacars';
152
-        	//$last_exec['phpvmacars'] = 0;
153
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
154
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
155
-        	//$formats[$id] = 'phpvmacars';
156
-        	$globalSources[$id]['format'] = 'vam';
157
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
158
-            } else if (preg_match('/whazzup/i',$host)) {
159
-        	//$formats[$id] = 'whazzup';
160
-        	$globalSources[$id]['format'] = 'whazzup';
161
-        	//$last_exec['whazzup'] = 0;
162
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
163
-            } else if (preg_match('/recentpireps/i',$host)) {
164
-        	//$formats[$id] = 'pirepsjson';
165
-        	$globalSources[$id]['format'] = 'pirepsjson';
166
-        	//$last_exec['pirepsjson'] = 0;
167
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
168
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
169
-        	//$formats[$id] = 'fr24json';
170
-        	$globalSources[$id]['format'] = 'fr24json';
171
-        	//$last_exec['fr24json'] = 0;
172
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
173
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
174
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
175
-        	    exit(0);
176
-        	}
177
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
178
-        	//$formats[$id] = 'fr24json';
179
-        	$globalSources[$id]['format'] = 'myshiptracking';
180
-        	//$last_exec['fr24json'] = 0;
181
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
182
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
183
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
184
-        	    exit(0);
185
-        	}
186
-            //} else if (preg_match('/10001/',$host)) {
187
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
188
-        	//$formats[$id] = 'tsv';
189
-        	$globalSources[$id]['format'] = 'tsv';
190
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
191
-            }
192
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
193
-    		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
194
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
195
-    		    if ($idf !== false) {
196
-    			$httpfeeds[$id] = $idf;
197
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
198
-    		    }
199
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
200
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
201
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
202
-	    $hostport = explode(':',$host);
203
-	    if (isset($hostport[1])) {
111
+			if (preg_match('/deltadb.txt$/i',$host)) {
112
+			//$formats[$id] = 'deltadbtxt';
113
+			$globalSources[$id]['format'] = 'deltadbtxt';
114
+			//$last_exec['deltadbtxt'] = 0;
115
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
116
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
117
+			//$formats[$id] = 'vatsimtxt';
118
+			$globalSources[$id]['format'] = 'vatsimtxt';
119
+			//$last_exec['vatsimtxt'] = 0;
120
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
121
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
122
+			//$formats[$id] = 'aircraftlistjson';
123
+			$globalSources[$id]['format'] = 'aircraftlistjson';
124
+			//$last_exec['aircraftlistjson'] = 0;
125
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
126
+			} else if (preg_match('/opensky/i',$host)) {
127
+			//$formats[$id] = 'aircraftlistjson';
128
+			$globalSources[$id]['format'] = 'opensky';
129
+			//$last_exec['aircraftlistjson'] = 0;
130
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
131
+			} else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
132
+			//$formats[$id] = 'radarvirtueljson';
133
+			$globalSources[$id]['format'] = 'radarvirtueljson';
134
+			//$last_exec['radarvirtueljson'] = 0;
135
+			if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
136
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
137
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
138
+				exit(0);
139
+			}
140
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
141
+			//$formats[$id] = 'planeupdatefaa';
142
+			$globalSources[$id]['format'] = 'planeupdatefaa';
143
+			//$last_exec['planeupdatefaa'] = 0;
144
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
145
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
146
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
147
+				exit(0);
148
+			}
149
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
150
+			//$formats[$id] = 'phpvmacars';
151
+			$globalSources[$id]['format'] = 'phpvmacars';
152
+			//$last_exec['phpvmacars'] = 0;
153
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
154
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
155
+			//$formats[$id] = 'phpvmacars';
156
+			$globalSources[$id]['format'] = 'vam';
157
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
158
+			} else if (preg_match('/whazzup/i',$host)) {
159
+			//$formats[$id] = 'whazzup';
160
+			$globalSources[$id]['format'] = 'whazzup';
161
+			//$last_exec['whazzup'] = 0;
162
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
163
+			} else if (preg_match('/recentpireps/i',$host)) {
164
+			//$formats[$id] = 'pirepsjson';
165
+			$globalSources[$id]['format'] = 'pirepsjson';
166
+			//$last_exec['pirepsjson'] = 0;
167
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
168
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
169
+			//$formats[$id] = 'fr24json';
170
+			$globalSources[$id]['format'] = 'fr24json';
171
+			//$last_exec['fr24json'] = 0;
172
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
173
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
174
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
175
+				exit(0);
176
+			}
177
+			} else if (preg_match(':myshiptracking.com/:i',$host)) {
178
+			//$formats[$id] = 'fr24json';
179
+			$globalSources[$id]['format'] = 'myshiptracking';
180
+			//$last_exec['fr24json'] = 0;
181
+			if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
182
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
183
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
184
+				exit(0);
185
+			}
186
+			//} else if (preg_match('/10001/',$host)) {
187
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
188
+			//$formats[$id] = 'tsv';
189
+			$globalSources[$id]['format'] = 'tsv';
190
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
191
+			}
192
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
193
+			if ($globalSources[$id]['format'] == 'aisnmeahttp') {
194
+				$idf = fopen($globalSources[$id]['host'],'r',false,$context);
195
+				if ($idf !== false) {
196
+				$httpfeeds[$id] = $idf;
197
+				if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
198
+				}
199
+				elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
200
+			} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
201
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
202
+		$hostport = explode(':',$host);
203
+		if (isset($hostport[1])) {
204 204
 		$port = $hostport[1];
205 205
 		$hostn = $hostport[0];
206
-	    } else {
206
+		} else {
207 207
 		$port = $globalSources[$id]['port'];
208 208
 		$hostn = $globalSources[$id]['host'];
209
-	    }
210
-	    $Common = new Common();
211
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
212
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
213
-    	    } else {
214
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
215
-	    }
216
-	    if ($s) {
217
-    	        $sockets[$id] = $s;
218
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
219
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
209
+		}
210
+		$Common = new Common();
211
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
212
+			$s = $Common->create_socket($hostn,$port, $errno, $errstr);
213
+			} else {
214
+			$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
215
+		}
216
+		if ($s) {
217
+				$sockets[$id] = $s;
218
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
219
+			if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
220 220
 			//$formats[$id] = 'aprs';
221 221
 			$globalSources[$id]['format'] = 'aprs';
222 222
 			//$aprs_connect = 0;
223 223
 			//$use_aprs = true;
224
-    		    } elseif ($port == '10001') {
225
-        		//$formats[$id] = 'tsv';
226
-        		$globalSources[$id]['format'] = 'tsv';
227
-		    } elseif ($port == '30002') {
228
-        		//$formats[$id] = 'raw';
229
-        		$globalSources[$id]['format'] = 'raw';
230
-		    } elseif ($port == '5001') {
231
-        		//$formats[$id] = 'raw';
232
-        		$globalSources[$id]['format'] = 'flightgearmp';
233
-		    } elseif ($port == '30005') {
224
+				} elseif ($port == '10001') {
225
+				//$formats[$id] = 'tsv';
226
+				$globalSources[$id]['format'] = 'tsv';
227
+			} elseif ($port == '30002') {
228
+				//$formats[$id] = 'raw';
229
+				$globalSources[$id]['format'] = 'raw';
230
+			} elseif ($port == '5001') {
231
+				//$formats[$id] = 'raw';
232
+				$globalSources[$id]['format'] = 'flightgearmp';
233
+			} elseif ($port == '30005') {
234 234
 			// Not yet supported
235
-        		//$formats[$id] = 'beast';
236
-        		$globalSources[$id]['format'] = 'beast';
237
-		    //} else $formats[$id] = 'sbs';
238
-		    } else $globalSources[$id]['format'] = 'sbs';
239
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
235
+				//$formats[$id] = 'beast';
236
+				$globalSources[$id]['format'] = 'beast';
237
+			//} else $formats[$id] = 'sbs';
238
+			} else $globalSources[$id]['format'] = 'sbs';
239
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
240 240
 		}
241 241
 		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
242
-            } else {
242
+			} else {
243 243
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
244
-    	    }
245
-        }
246
-    }
244
+			}
245
+		}
246
+	}
247 247
 }
248 248
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
249 249
 
@@ -266,9 +266,9 @@  discard block
 block discarded – undo
266 266
 //connect_all($globalSources);
267 267
 
268 268
 if (isset($globalProxy) && $globalProxy) {
269
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
269
+	$context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
270 270
 } else {
271
-    $context = stream_context_create(array('http' => array('timeout' => $timeout)));
271
+	$context = stream_context_create(array('http' => array('timeout' => $timeout)));
272 272
 }
273 273
 
274 274
 // APRS Configuration
@@ -277,18 +277,18 @@  discard block
 block discarded – undo
277 277
 	die;
278 278
 }
279 279
 foreach ($globalSources as $key => $source) {
280
-    if (!isset($source['format'])) {
281
-        $globalSources[$key]['format'] = 'auto';
282
-    }
280
+	if (!isset($source['format'])) {
281
+		$globalSources[$key]['format'] = 'auto';
282
+	}
283 283
 }
284 284
 connect_all($globalSources);
285 285
 foreach ($globalSources as $key => $source) {
286
-    if (isset($source['format']) && $source['format'] == 'aprs') {
286
+	if (isset($source['format']) && $source['format'] == 'aprs') {
287 287
 	$aprs_connect = 0;
288 288
 	$use_aprs = true;
289 289
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
290 290
 	break;
291
-    }
291
+	}
292 292
 }
293 293
 
294 294
 if ($use_aprs) {
@@ -330,152 +330,152 @@  discard block
 block discarded – undo
330 330
 
331 331
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
332 332
 while ($i > 0) {
333
-    if (!$globalDaemon) $i = $endtime-time();
334
-    // Delete old ATC
335
-    if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
333
+	if (!$globalDaemon) $i = $endtime-time();
334
+	// Delete old ATC
335
+	if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
336 336
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
337
-        $ATC->deleteOldATC();
338
-    }
337
+		$ATC->deleteOldATC();
338
+	}
339 339
     
340
-    //if (count($last_exec) > 0) {
341
-    if (count($last_exec) == count($globalSources)) {
340
+	//if (count($last_exec) > 0) {
341
+	if (count($last_exec) == count($globalSources)) {
342 342
 	$max = $globalMinFetch;
343 343
 	foreach ($last_exec as $last) {
344
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
344
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
345 345
 	}
346 346
 	if ($max != $globalMinFetch) {
347
-	    if ($globalDebug) echo 'Sleeping...'."\n";
348
-	    sleep($globalMinFetch-$max+2);
347
+		if ($globalDebug) echo 'Sleeping...'."\n";
348
+		sleep($globalMinFetch-$max+2);
349
+	}
349 350
 	}
350
-    }
351 351
 
352 352
     
353
-    //foreach ($formats as $id => $value) {
354
-    foreach ($globalSources as $id => $value) {
353
+	//foreach ($formats as $id => $value) {
354
+	foreach ($globalSources as $id => $value) {
355 355
 	date_default_timezone_set('UTC');
356 356
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
357 357
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
358
-	    //$buffer = $Common->getData($hosts[$id]);
359
-	    $buffer = $Common->getData($value['host']);
360
-	    if ($buffer != '') $reset = 0;
361
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
362
-	    $buffer = explode('\n',$buffer);
363
-	    foreach ($buffer as $line) {
364
-    		if ($line != '' && count($line) > 7) {
365
-    		    $line = explode(',', $line);
366
-	            $data = array();
367
-	            $data['hex'] = $line[1]; // hex
368
-	            $data['ident'] = $line[2]; // ident
369
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
370
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
371
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
372
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
373
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
374
-	            $data['verticalrate'] = ''; // vertical rate
375
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
376
-	            $data['emergency'] = ''; // emergency
377
-		    $data['datetime'] = date('Y-m-d H:i:s');
378
-		    $data['format_source'] = 'deltadbtxt';
379
-    		    $data['id_source'] = $id_source;
380
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
381
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
382
-    		    $SI->add($data);
383
-		    unset($data);
384
-    		}
385
-    	    }
386
-    	    $last_exec[$id]['last'] = time();
358
+		//$buffer = $Common->getData($hosts[$id]);
359
+		$buffer = $Common->getData($value['host']);
360
+		if ($buffer != '') $reset = 0;
361
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
362
+		$buffer = explode('\n',$buffer);
363
+		foreach ($buffer as $line) {
364
+			if ($line != '' && count($line) > 7) {
365
+				$line = explode(',', $line);
366
+				$data = array();
367
+				$data['hex'] = $line[1]; // hex
368
+				$data['ident'] = $line[2]; // ident
369
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
370
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
371
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
372
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
373
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
374
+				$data['verticalrate'] = ''; // vertical rate
375
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
376
+				$data['emergency'] = ''; // emergency
377
+			$data['datetime'] = date('Y-m-d H:i:s');
378
+			$data['format_source'] = 'deltadbtxt';
379
+				$data['id_source'] = $id_source;
380
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
381
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
382
+				$SI->add($data);
383
+			unset($data);
384
+			}
385
+			}
386
+			$last_exec[$id]['last'] = time();
387 387
 	} elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
388
-	    date_default_timezone_set('CET');
389
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
390
-	    date_default_timezone_set('UTC');
391
-	    if ($buffer != '') $reset = 0;
392
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
393
-	    $buffer = explode('\n',$buffer);
394
-	    foreach ($buffer as $line) {
388
+		date_default_timezone_set('CET');
389
+		$buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
390
+		date_default_timezone_set('UTC');
391
+		if ($buffer != '') $reset = 0;
392
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
393
+		$buffer = explode('\n',$buffer);
394
+		foreach ($buffer as $line) {
395 395
 		if ($line != '') {
396
-		    echo "'".$line."'\n";
397
-		    $add = false;
398
-		    $ais_data = $AIS->parse_line(trim($line));
399
-		    $data = array();
400
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
401
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
402
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
403
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
404
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
405
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
406
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
407
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
408
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
409
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
410
-		    if (isset($ais_data['timestamp'])) {
396
+			echo "'".$line."'\n";
397
+			$add = false;
398
+			$ais_data = $AIS->parse_line(trim($line));
399
+			$data = array();
400
+			if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
401
+			if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
402
+			if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
403
+			if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
404
+			if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
405
+			if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
406
+			if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
407
+			if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
408
+			if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
409
+			if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
410
+			if (isset($ais_data['timestamp'])) {
411 411
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
412 412
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
413
-			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
414
-			    $add = true;
413
+				$last_exec[$id]['timestamp'] = $ais_data['timestamp'];
414
+				$add = true;
415 415
 			}
416
-		    } else {
416
+			} else {
417 417
 			$data['datetime'] = date('Y-m-d H:i:s');
418 418
 			$add = true;
419
-		    }
420
-		    $data['format_source'] = 'aisnmeatxt';
421
-    		    $data['id_source'] = $id_source;
422
-		    print_r($data);
423
-		    echo 'Add...'."\n";
424
-		    if ($add && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
425
-		    unset($data);
419
+			}
420
+			$data['format_source'] = 'aisnmeatxt';
421
+				$data['id_source'] = $id_source;
422
+			print_r($data);
423
+			echo 'Add...'."\n";
424
+			if ($add && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
425
+			unset($data);
426 426
 		}
427
-    	    }
428
-    	    $last_exec[$id]['last'] = time();
427
+			}
428
+			$last_exec[$id]['last'] = time();
429 429
 	} elseif ($value['format'] == 'aisnmeahttp') {
430
-	    $arr = $httpfeeds;
431
-	    $w = $e = null;
430
+		$arr = $httpfeeds;
431
+		$w = $e = null;
432 432
 	    
433
-	    if (isset($arr[$id])) {
434
-	    $nn = stream_select($arr,$w,$e,$timeout);
435
-	    if ($nn > 0) {
433
+		if (isset($arr[$id])) {
434
+		$nn = stream_select($arr,$w,$e,$timeout);
435
+		if ($nn > 0) {
436 436
 		foreach ($httpfeeds as $feed) {
437
-		    $buffer = stream_get_line($feed,2000,"\n");
438
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
439
-		    $buffer = explode('\n',$buffer);
440
-		    foreach ($buffer as $line) {
437
+			$buffer = stream_get_line($feed,2000,"\n");
438
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
439
+			$buffer = explode('\n',$buffer);
440
+			foreach ($buffer as $line) {
441 441
 			if ($line != '') {
442
-			    $ais_data = $AIS->parse_line(trim($line));
443
-			    $data = array();
444
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
445
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
446
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
447
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
448
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
449
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
450
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
451
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
452
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
453
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
454
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
455
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
456
-			    if (isset($ais_data['timestamp'])) {
442
+				$ais_data = $AIS->parse_line(trim($line));
443
+				$data = array();
444
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
445
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
446
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
447
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
448
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
449
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
450
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
451
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
452
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
453
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
454
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
455
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
456
+				if (isset($ais_data['timestamp'])) {
457 457
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
458
-			    } else {
458
+				} else {
459 459
 				$data['datetime'] = date('Y-m-d H:i:s');
460
-			    }
461
-			    $data['format_source'] = 'aisnmeahttp';
462
-			    $data['id_source'] = $id_source;
463
-			    if ($ais_data['mmsi_type'] == 'Ship') $MI->add($data);
464
-			    unset($data);
460
+				}
461
+				$data['format_source'] = 'aisnmeahttp';
462
+				$data['id_source'] = $id_source;
463
+				if ($ais_data['mmsi_type'] == 'Ship') $MI->add($data);
464
+				unset($data);
465 465
 			}
466
-		    }
466
+			}
467
+		}
467 468
 		}
468 469
 		}
469
-	    }
470 470
 	} elseif ($value['format'] == 'myshiptracking' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
471
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
472
-	    if ($buffer != '') {
471
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
472
+		if ($buffer != '') {
473 473
 		//echo $buffer;
474 474
 		$all_data = json_decode($buffer,true);
475 475
 		//print_r($all_data);
476 476
 		if (isset($all_data[0]['DATA'])) {
477 477
 		foreach ($all_data[0]['DATA'] as $line) {
478
-		    if ($line != '') {
478
+			if ($line != '') {
479 479
 			$data = array();
480 480
 			$data['ident'] = $line['NAME'];
481 481
 			$data['mmsi'] = $line['MMSI'];
@@ -491,87 +491,87 @@  discard block
 block discarded – undo
491 491
 			$data['id_source'] = $id_source;
492 492
 			$MI->add($data);
493 493
 			unset($data);
494
-		    }
494
+			}
495 495
 		}
496 496
 		}
497 497
 		
498
-	    }
499
-    	    $last_exec[$id]['last'] = time();
498
+		}
499
+			$last_exec[$id]['last'] = time();
500 500
 	} elseif ($value['format'] == 'boatbeaconapp' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
501
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
502
-	    if ($buffer != '') {
501
+		$buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
502
+		if ($buffer != '') {
503 503
 		$all_data = json_decode($buffer,true);
504 504
 		if (isset($all_data[0]['mmsi'])) {
505
-		    foreach ($all_data as $line) {
505
+			foreach ($all_data as $line) {
506 506
 			if ($line != '') {
507
-			    $data = array();
508
-			    $data['ident'] = $line['shipname'];
509
-			    $data['callsign'] = $line['callsign'];
510
-			    $data['mmsi'] = $line['mmsi'];
511
-			    $data['speed'] = $line['sog'];
512
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
513
-			    $data['latitude'] = $line['latitude'];
514
-			    $data['longitude'] = $line['longitude'];
515
-			    $data['type_id'] = $line['shiptype'];
516
-			    $data['arrival_code'] = $line['destination'];
517
-			    $data['datetime'] = $line['time'];
518
-			    $data['format_source'] = 'boatbeaconapp';
519
-			    $data['id_source'] = $id_source;
520
-			    $MI->add($data);
521
-			    unset($data);
507
+				$data = array();
508
+				$data['ident'] = $line['shipname'];
509
+				$data['callsign'] = $line['callsign'];
510
+				$data['mmsi'] = $line['mmsi'];
511
+				$data['speed'] = $line['sog'];
512
+				if ($line['heading'] != '511') $data['heading'] = $line['heading'];
513
+				$data['latitude'] = $line['latitude'];
514
+				$data['longitude'] = $line['longitude'];
515
+				$data['type_id'] = $line['shiptype'];
516
+				$data['arrival_code'] = $line['destination'];
517
+				$data['datetime'] = $line['time'];
518
+				$data['format_source'] = 'boatbeaconapp';
519
+				$data['id_source'] = $id_source;
520
+				$MI->add($data);
521
+				unset($data);
522
+			}
522 523
 			}
523
-		    }
524 524
 		}
525 525
 		
526
-	    }
527
-    	    $last_exec[$id]['last'] = time();
526
+		}
527
+			$last_exec[$id]['last'] = time();
528 528
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
529
-	    echo 'download...';
530
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
531
-	    echo 'done !'."\n";
532
-	    if ($buffer != '') $reset = 0;
533
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
534
-	    $buffer = explode('\n',$buffer);
535
-	    foreach ($buffer as $line) {
529
+		echo 'download...';
530
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
531
+		echo 'done !'."\n";
532
+		if ($buffer != '') $reset = 0;
533
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
534
+		$buffer = explode('\n',$buffer);
535
+		foreach ($buffer as $line) {
536 536
 		if ($line != '') {
537
-		    $data = array();
538
-		    $data['mmsi'] = (int)substr($line,0,9);
539
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
540
-		    //$data['status'] = substr($line,21,2);
541
-		    //$data['type'] = substr($line,24,3);
542
-		    $data['latitude'] = substr($line,29,9);
543
-		    $data['longitude'] = substr($line,41,9);
544
-		    $data['speed'] = round(substr($line,51,5));
545
-		    //$data['course'] = substr($line,57,5);
546
-		    $data['heading'] = round(substr($line,63,3));
547
-		    //$data['draft'] = substr($line,67,4);
548
-		    //$data['length'] = substr($line,72,3);
549
-		    //$data['beam'] = substr($line,76,2);
550
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
551
-		    //$data['callsign'] = trim(substr($line,100,7);
552
-		    //$data['dest'] = substr($line,108,20);
553
-		    //$data['etaDate'] = substr($line,129,5);
554
-		    //$data['etaTime'] = substr($line,135,5);
555
-		    $data['format_source'] = 'shipplotter';
556
-    		    $data['id_source'] = $id_source;
557
-		    print_r($data);
558
-		    echo 'Add...'."\n";
559
-		    $MI->add($data);
560
-		    unset($data);
537
+			$data = array();
538
+			$data['mmsi'] = (int)substr($line,0,9);
539
+			$data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
540
+			//$data['status'] = substr($line,21,2);
541
+			//$data['type'] = substr($line,24,3);
542
+			$data['latitude'] = substr($line,29,9);
543
+			$data['longitude'] = substr($line,41,9);
544
+			$data['speed'] = round(substr($line,51,5));
545
+			//$data['course'] = substr($line,57,5);
546
+			$data['heading'] = round(substr($line,63,3));
547
+			//$data['draft'] = substr($line,67,4);
548
+			//$data['length'] = substr($line,72,3);
549
+			//$data['beam'] = substr($line,76,2);
550
+			$data['ident'] = trim(utf8_encode(substr($line,79,20)));
551
+			//$data['callsign'] = trim(substr($line,100,7);
552
+			//$data['dest'] = substr($line,108,20);
553
+			//$data['etaDate'] = substr($line,129,5);
554
+			//$data['etaTime'] = substr($line,135,5);
555
+			$data['format_source'] = 'shipplotter';
556
+				$data['id_source'] = $id_source;
557
+			print_r($data);
558
+			echo 'Add...'."\n";
559
+			$MI->add($data);
560
+			unset($data);
561 561
 		}
562
-    	    }
563
-    	    $last_exec[$id]['last'] = time();
562
+			}
563
+			$last_exec[$id]['last'] = time();
564 564
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
565 565
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
566
-	    //$buffer = $Common->getData($hosts[$id]);
567
-	    $buffer = $Common->getData($value['host']);
568
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
569
-	    $buffer = explode('\n',$buffer);
570
-	    $reset = 0;
571
-	    foreach ($buffer as $line) {
572
-    		if ($line != '') {
573
-    		    $line = explode(':', $line);
574
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
566
+		//$buffer = $Common->getData($hosts[$id]);
567
+		$buffer = $Common->getData($value['host']);
568
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
569
+		$buffer = explode('\n',$buffer);
570
+		$reset = 0;
571
+		foreach ($buffer as $line) {
572
+			if ($line != '') {
573
+				$line = explode(':', $line);
574
+				if (count($line) > 30 && $line[0] != 'callsign') {
575 575
 			$data = array();
576 576
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
577 577
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -584,36 +584,36 @@  discard block
 block discarded – undo
584 584
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
585 585
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
586 586
 			$data['latitude'] = $line[5]; // lat
587
-	        	$data['longitude'] = $line[6]; // long
588
-	        	$data['verticalrate'] = ''; // vertical rate
589
-	        	$data['squawk'] = ''; // squawk
590
-	        	$data['emergency'] = ''; // emergency
591
-	        	$data['waypoints'] = $line[30];
587
+				$data['longitude'] = $line[6]; // long
588
+				$data['verticalrate'] = ''; // vertical rate
589
+				$data['squawk'] = ''; // squawk
590
+				$data['emergency'] = ''; // emergency
591
+				$data['waypoints'] = $line[30];
592 592
 			$data['datetime'] = date('Y-m-d H:i:s');
593 593
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
594 594
 			//if (isset($line[37])) $data['last_update'] = $line[37];
595
-		        $data['departure_airport_icao'] = $line[11];
596
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
597
-		        $data['arrival_airport_icao'] = $line[13];
595
+				$data['departure_airport_icao'] = $line[11];
596
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
597
+				$data['arrival_airport_icao'] = $line[13];
598 598
 			$data['frequency'] = $line[4];
599 599
 			$data['type'] = $line[18];
600 600
 			$data['range'] = $line[19];
601 601
 			if (isset($line[35])) $data['info'] = $line[35];
602
-    			$data['id_source'] = $id_source;
603
-	    		//$data['arrival_airport_time'] = ;
604
-	    		if ($line[9] != '') {
605
-	    		    $aircraft_data = explode('/',$line[9]);
606
-	    		    if (isset($aircraft_data[1])) {
607
-	    			$data['aircraft_icao'] = $aircraft_data[1];
608
-	    		    }
609
-        		}
610
-	    		/*
602
+				$data['id_source'] = $id_source;
603
+				//$data['arrival_airport_time'] = ;
604
+				if ($line[9] != '') {
605
+					$aircraft_data = explode('/',$line[9]);
606
+					if (isset($aircraft_data[1])) {
607
+					$data['aircraft_icao'] = $aircraft_data[1];
608
+					}
609
+				}
610
+				/*
611 611
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
612 612
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
613 613
 	    		*/
614
-	    		$data['format_source'] = $value['format'];
614
+				$data['format_source'] = $value['format'];
615 615
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
616
-    			if ($line[3] == 'PILOT') $SI->add($data);
616
+				if ($line[3] == 'PILOT') $SI->add($data);
617 617
 			elseif ($line[3] == 'ATC') {
618 618
 				//print_r($data);
619 619
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -631,247 +631,247 @@  discard block
 block discarded – undo
631 631
 				if (!isset($data['source_name'])) $data['source_name'] = '';
632 632
 				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']);
633 633
 			}
634
-    			unset($data);
635
-    		    }
636
-    		}
637
-    	    }
638
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
639
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
640
-    	    $last_exec[$id]['last'] = time();
641
-    	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
642
-    	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
643
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
644
-	    if ($buffer != '') {
645
-	    $all_data = json_decode($buffer,true);
646
-	    if (isset($all_data['acList'])) {
634
+				unset($data);
635
+				}
636
+			}
637
+			}
638
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
639
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
640
+			$last_exec[$id]['last'] = time();
641
+		//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
642
+		} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
643
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
644
+		if ($buffer != '') {
645
+		$all_data = json_decode($buffer,true);
646
+		if (isset($all_data['acList'])) {
647 647
 		$reset = 0;
648 648
 		foreach ($all_data['acList'] as $line) {
649
-		    $data = array();
650
-		    $data['hex'] = $line['Icao']; // hex
651
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
652
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
653
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
654
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
655
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
656
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
657
-		    //$data['verticalrate'] = $line['']; // verticale rate
658
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
659
-		    $data['emergency'] = ''; // emergency
660
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
661
-		    /*
649
+			$data = array();
650
+			$data['hex'] = $line['Icao']; // hex
651
+			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
652
+			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
653
+			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
654
+			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
655
+			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
656
+			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
657
+			//$data['verticalrate'] = $line['']; // verticale rate
658
+			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
659
+			$data['emergency'] = ''; // emergency
660
+			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
661
+			/*
662 662
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
663 663
 		    else $data['datetime'] = date('Y-m-d H:i:s');
664 664
 		    */
665
-		    $data['datetime'] = date('Y-m-d H:i:s');
666
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
667
-	    	    $data['format_source'] = 'aircraftlistjson';
668
-		    $data['id_source'] = $id_source;
669
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
670
-		    if (isset($data['datetime'])) $SI->add($data);
671
-		    unset($data);
665
+			$data['datetime'] = date('Y-m-d H:i:s');
666
+			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
667
+				$data['format_source'] = 'aircraftlistjson';
668
+			$data['id_source'] = $id_source;
669
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
670
+			if (isset($data['datetime'])) $SI->add($data);
671
+			unset($data);
672 672
 		}
673
-	    } else {
673
+		} else {
674 674
 		$reset = 0;
675 675
 		foreach ($all_data as $line) {
676
-		    $data = array();
677
-		    $data['hex'] = $line['hex']; // hex
678
-		    $data['ident'] = $line['flight']; // ident
679
-		    $data['altitude'] = $line['altitude']; // altitude
680
-		    $data['speed'] = $line['speed']; // speed
681
-		    $data['heading'] = $line['track']; // heading
682
-		    $data['latitude'] = $line['lat']; // lat
683
-		    $data['longitude'] = $line['lon']; // long
684
-		    $data['verticalrate'] = $line['vrt']; // verticale rate
685
-		    $data['squawk'] = $line['squawk']; // squawk
686
-		    $data['emergency'] = ''; // emergency
687
-		    $data['datetime'] = date('Y-m-d H:i:s');
688
-	    	    $data['format_source'] = 'aircraftlistjson';
689
-    		    $data['id_source'] = $id_source;
690
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
691
-		    $SI->add($data);
692
-		    unset($data);
676
+			$data = array();
677
+			$data['hex'] = $line['hex']; // hex
678
+			$data['ident'] = $line['flight']; // ident
679
+			$data['altitude'] = $line['altitude']; // altitude
680
+			$data['speed'] = $line['speed']; // speed
681
+			$data['heading'] = $line['track']; // heading
682
+			$data['latitude'] = $line['lat']; // lat
683
+			$data['longitude'] = $line['lon']; // long
684
+			$data['verticalrate'] = $line['vrt']; // verticale rate
685
+			$data['squawk'] = $line['squawk']; // squawk
686
+			$data['emergency'] = ''; // emergency
687
+			$data['datetime'] = date('Y-m-d H:i:s');
688
+				$data['format_source'] = 'aircraftlistjson';
689
+				$data['id_source'] = $id_source;
690
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
691
+			$SI->add($data);
692
+			unset($data);
693
+		}
693 694
 		}
694
-	    }
695
-	    }
696
-    	    //$last_exec['aircraftlistjson'] = time();
697
-    	    $last_exec[$id]['last'] = time();
698
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
699
-    	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
700
-	    $buffer = $Common->getData($value['host']);
701
-	    $all_data = json_decode($buffer,true);
702
-	    if (isset($all_data['planes'])) {
695
+		}
696
+			//$last_exec['aircraftlistjson'] = time();
697
+			$last_exec[$id]['last'] = time();
698
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
699
+		} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
700
+		$buffer = $Common->getData($value['host']);
701
+		$all_data = json_decode($buffer,true);
702
+		if (isset($all_data['planes'])) {
703 703
 		$reset = 0;
704 704
 		foreach ($all_data['planes'] as $key => $line) {
705
-		    $data = array();
706
-		    $data['hex'] = $key; // hex
707
-		    $data['ident'] = $line[3]; // ident
708
-		    $data['altitude'] = $line[6]; // altitude
709
-		    $data['speed'] = $line[8]; // speed
710
-		    $data['heading'] = $line[7]; // heading
711
-		    $data['latitude'] = $line[4]; // lat
712
-		    $data['longitude'] = $line[5]; // long
713
-		    //$data['verticalrate'] = $line[]; // verticale rate
714
-		    $data['squawk'] = $line[10]; // squawk
715
-		    $data['emergency'] = ''; // emergency
716
-		    $data['registration'] = $line[2];
717
-		    $data['aircraft_icao'] = $line[0];
718
-		    $deparr = explode('-',$line[1]);
719
-		    if (count($deparr) == 2) {
705
+			$data = array();
706
+			$data['hex'] = $key; // hex
707
+			$data['ident'] = $line[3]; // ident
708
+			$data['altitude'] = $line[6]; // altitude
709
+			$data['speed'] = $line[8]; // speed
710
+			$data['heading'] = $line[7]; // heading
711
+			$data['latitude'] = $line[4]; // lat
712
+			$data['longitude'] = $line[5]; // long
713
+			//$data['verticalrate'] = $line[]; // verticale rate
714
+			$data['squawk'] = $line[10]; // squawk
715
+			$data['emergency'] = ''; // emergency
716
+			$data['registration'] = $line[2];
717
+			$data['aircraft_icao'] = $line[0];
718
+			$deparr = explode('-',$line[1]);
719
+			if (count($deparr) == 2) {
720 720
 			$data['departure_airport_icao'] = $deparr[0];
721 721
 			$data['arrival_airport_icao'] = $deparr[1];
722
-		    }
723
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
724
-	    	    $data['format_source'] = 'planeupdatefaa';
725
-    		    $data['id_source'] = $id_source;
726
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
727
-		    $SI->add($data);
728
-		    unset($data);
722
+			}
723
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
724
+				$data['format_source'] = 'planeupdatefaa';
725
+				$data['id_source'] = $id_source;
726
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
727
+			$SI->add($data);
728
+			unset($data);
729
+		}
729 730
 		}
730
-	    }
731
-    	    //$last_exec['planeupdatefaa'] = time();
732
-    	    $last_exec[$id]['last'] = time();
733
-    	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
734
-	    $buffer = $Common->getData($value['host']);
735
-	    $all_data = json_decode($buffer,true);
736
-	    if (isset($all_data['states'])) {
731
+			//$last_exec['planeupdatefaa'] = time();
732
+			$last_exec[$id]['last'] = time();
733
+		} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
734
+		$buffer = $Common->getData($value['host']);
735
+		$all_data = json_decode($buffer,true);
736
+		if (isset($all_data['states'])) {
737 737
 		$reset = 0;
738 738
 		foreach ($all_data['states'] as $key => $line) {
739
-		    $data = array();
740
-		    $data['hex'] = $line[0]; // hex
741
-		    $data['ident'] = trim($line[1]); // ident
742
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
743
-		    $data['speed'] = round($line[9]*1.94384); // speed
744
-		    $data['heading'] = round($line[10]); // heading
745
-		    $data['latitude'] = $line[5]; // lat
746
-		    $data['longitude'] = $line[6]; // long
747
-		    $data['verticalrate'] = $line[11]; // verticale rate
748
-		    //$data['squawk'] = $line[10]; // squawk
749
-		    //$data['emergency'] = ''; // emergency
750
-		    //$data['registration'] = $line[2];
751
-		    //$data['aircraft_icao'] = $line[0];
752
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
753
-	    	    $data['format_source'] = 'opensky';
754
-    		    $data['id_source'] = $id_source;
755
-		    $SI->add($data);
756
-		    unset($data);
739
+			$data = array();
740
+			$data['hex'] = $line[0]; // hex
741
+			$data['ident'] = trim($line[1]); // ident
742
+			$data['altitude'] = round($line[7]*3.28084); // altitude
743
+			$data['speed'] = round($line[9]*1.94384); // speed
744
+			$data['heading'] = round($line[10]); // heading
745
+			$data['latitude'] = $line[5]; // lat
746
+			$data['longitude'] = $line[6]; // long
747
+			$data['verticalrate'] = $line[11]; // verticale rate
748
+			//$data['squawk'] = $line[10]; // squawk
749
+			//$data['emergency'] = ''; // emergency
750
+			//$data['registration'] = $line[2];
751
+			//$data['aircraft_icao'] = $line[0];
752
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
753
+				$data['format_source'] = 'opensky';
754
+				$data['id_source'] = $id_source;
755
+			$SI->add($data);
756
+			unset($data);
757
+		}
757 758
 		}
758
-	    }
759
-    	    //$last_exec['planeupdatefaa'] = time();
760
-    	    $last_exec[$id]['last'] = time();
761
-    	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
762
-    	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
763
-	    //$buffer = $Common->getData($hosts[$id]);
764
-	    $buffer = $Common->getData($value['host']);
765
-	    $all_data = json_decode($buffer,true);
766
-	    if (!empty($all_data)) $reset = 0;
767
-	    foreach ($all_data as $key => $line) {
759
+			//$last_exec['planeupdatefaa'] = time();
760
+			$last_exec[$id]['last'] = time();
761
+		//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
762
+		} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
763
+		//$buffer = $Common->getData($hosts[$id]);
764
+		$buffer = $Common->getData($value['host']);
765
+		$all_data = json_decode($buffer,true);
766
+		if (!empty($all_data)) $reset = 0;
767
+		foreach ($all_data as $key => $line) {
768 768
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
769
-		    $data = array();
770
-		    $data['hex'] = $line[0];
771
-		    $data['ident'] = $line[16]; //$line[13]
772
-	    	    $data['altitude'] = $line[4]; // altitude
773
-	    	    $data['speed'] = $line[5]; // speed
774
-	    	    $data['heading'] = $line[3]; // heading
775
-	    	    $data['latitude'] = $line[1]; // lat
776
-	    	    $data['longitude'] = $line[2]; // long
777
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
778
-	    	    $data['squawk'] = $line[6]; // squawk
779
-	    	    $data['aircraft_icao'] = $line[8];
780
-	    	    $data['registration'] = $line[9];
781
-		    $data['departure_airport_iata'] = $line[11];
782
-		    $data['arrival_airport_iata'] = $line[12];
783
-	    	    $data['emergency'] = ''; // emergency
784
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
785
-	    	    $data['format_source'] = 'fr24json';
786
-    		    $data['id_source'] = $id_source;
787
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
788
-		    $SI->add($data);
789
-		    unset($data);
769
+			$data = array();
770
+			$data['hex'] = $line[0];
771
+			$data['ident'] = $line[16]; //$line[13]
772
+				$data['altitude'] = $line[4]; // altitude
773
+				$data['speed'] = $line[5]; // speed
774
+				$data['heading'] = $line[3]; // heading
775
+				$data['latitude'] = $line[1]; // lat
776
+				$data['longitude'] = $line[2]; // long
777
+				$data['verticalrate'] = $line[15]; // verticale rate
778
+				$data['squawk'] = $line[6]; // squawk
779
+				$data['aircraft_icao'] = $line[8];
780
+				$data['registration'] = $line[9];
781
+			$data['departure_airport_iata'] = $line[11];
782
+			$data['arrival_airport_iata'] = $line[12];
783
+				$data['emergency'] = ''; // emergency
784
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
785
+				$data['format_source'] = 'fr24json';
786
+				$data['id_source'] = $id_source;
787
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
788
+			$SI->add($data);
789
+			unset($data);
790
+		}
790 791
 		}
791
-	    }
792
-    	    //$last_exec['fr24json'] = time();
793
-    	    $last_exec[$id]['last'] = time();
794
-    	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
795
-    	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
796
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
797
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
798
-	    //echo $buffer;
799
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
800
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
801
-	    $all_data = json_decode($buffer,true);
802
-	    if (json_last_error() != JSON_ERROR_NONE) {
792
+			//$last_exec['fr24json'] = time();
793
+			$last_exec[$id]['last'] = time();
794
+		//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
795
+		} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
796
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
797
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
798
+		//echo $buffer;
799
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
800
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
801
+		$all_data = json_decode($buffer,true);
802
+		if (json_last_error() != JSON_ERROR_NONE) {
803 803
 		die(json_last_error_msg());
804
-	    }
805
-	    if (isset($all_data['mrkrs'])) {
804
+		}
805
+		if (isset($all_data['mrkrs'])) {
806 806
 		$reset = 0;
807 807
 		foreach ($all_data['mrkrs'] as $key => $line) {
808
-		    if (isset($line['inf'])) {
808
+			if (isset($line['inf'])) {
809 809
 			$data = array();
810 810
 			$data['hex'] = $line['inf']['ia'];
811 811
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
812
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
813
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
814
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
815
-	    		$data['latitude'] = $line['pt'][0]; // lat
816
-	    		$data['longitude'] = $line['pt'][1]; // long
817
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
818
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
819
-	    		//$data['aircraft_icao'] = $line[8];
820
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
812
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
813
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
814
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
815
+				$data['latitude'] = $line['pt'][0]; // lat
816
+				$data['longitude'] = $line['pt'][1]; // long
817
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
818
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
819
+				//$data['aircraft_icao'] = $line[8];
820
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
821 821
 			//$data['departure_airport_iata'] = $line[11];
822 822
 			//$data['arrival_airport_iata'] = $line[12];
823
-	    		//$data['emergency'] = ''; // emergency
823
+				//$data['emergency'] = ''; // emergency
824 824
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
825
-	    		$data['format_source'] = 'radarvirtueljson';
826
-    			$data['id_source'] = $id_source;
825
+				$data['format_source'] = 'radarvirtueljson';
826
+				$data['id_source'] = $id_source;
827 827
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
828 828
 			$SI->add($data);
829 829
 			unset($data);
830
-		    }
830
+			}
831 831
 		}
832
-	    }
833
-    	    //$last_exec['radarvirtueljson'] = time();
834
-    	    $last_exec[$id]['last'] = time();
835
-    	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
836
-    	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
837
-	    //$buffer = $Common->getData($hosts[$id]);
838
-	    $buffer = $Common->getData($value['host'].'?'.time());
839
-	    $all_data = json_decode(utf8_encode($buffer),true);
832
+		}
833
+			//$last_exec['radarvirtueljson'] = time();
834
+			$last_exec[$id]['last'] = time();
835
+		//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
836
+		} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
837
+		//$buffer = $Common->getData($hosts[$id]);
838
+		$buffer = $Common->getData($value['host'].'?'.time());
839
+		$all_data = json_decode(utf8_encode($buffer),true);
840 840
 	    
841
-	    if (isset($all_data['pireps'])) {
841
+		if (isset($all_data['pireps'])) {
842 842
 		$reset = 0;
843
-	        foreach ($all_data['pireps'] as $line) {
844
-		    $data = array();
845
-		    $data['id'] = $line['id'];
846
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
847
-		    $data['ident'] = $line['callsign']; // ident
848
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
849
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
850
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
851
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
852
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
853
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
854
-		    $data['latitude'] = $line['lat']; // lat
855
-		    $data['longitude'] = $line['lon']; // long
856
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
857
-		    //$data['squawk'] = $line['squawk']; // squawk
858
-		    //$data['emergency'] = ''; // emergency
859
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
860
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
861
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
862
-		    //$data['arrival_airport_time'] = $line['arrtime'];
863
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
864
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
865
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
866
-		    else $data['info'] = '';
867
-		    $data['format_source'] = 'pireps';
868
-    		    $data['id_source'] = $id_source;
869
-		    $data['datetime'] = date('Y-m-d H:i:s');
870
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
871
-		    if ($line['icon'] == 'plane') {
843
+			foreach ($all_data['pireps'] as $line) {
844
+			$data = array();
845
+			$data['id'] = $line['id'];
846
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
847
+			$data['ident'] = $line['callsign']; // ident
848
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
849
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
850
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
851
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
852
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
853
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
854
+			$data['latitude'] = $line['lat']; // lat
855
+			$data['longitude'] = $line['lon']; // long
856
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
857
+			//$data['squawk'] = $line['squawk']; // squawk
858
+			//$data['emergency'] = ''; // emergency
859
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
860
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
861
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
862
+			//$data['arrival_airport_time'] = $line['arrtime'];
863
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
864
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
865
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
866
+			else $data['info'] = '';
867
+			$data['format_source'] = 'pireps';
868
+				$data['id_source'] = $id_source;
869
+			$data['datetime'] = date('Y-m-d H:i:s');
870
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
871
+			if ($line['icon'] == 'plane') {
872 872
 			$SI->add($data);
873
-		    //    print_r($data);
874
-    		    } elseif ($line['icon'] == 'ct') {
873
+			//    print_r($data);
874
+				} elseif ($line['icon'] == 'ct') {
875 875
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
876 876
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
877 877
 			$typec = substr($data['ident'],-3);
@@ -886,188 +886,188 @@  discard block
 block discarded – undo
886 886
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
887 887
 			else $data['type'] = 'Observer';
888 888
 			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']);
889
-		    }
890
-		    unset($data);
889
+			}
890
+			unset($data);
891 891
 		}
892
-	    }
893
-    	    //$last_exec['pirepsjson'] = time();
894
-    	    $last_exec[$id]['last'] = time();
895
-    	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
896
-    	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
897
-	    //$buffer = $Common->getData($hosts[$id]);
898
-	    if ($globalDebug) echo 'Get Data...'."\n";
899
-	    $buffer = $Common->getData($value['host']);
900
-	    $all_data = json_decode($buffer,true);
901
-	    if ($buffer != '' && is_array($all_data)) {
892
+		}
893
+			//$last_exec['pirepsjson'] = time();
894
+			$last_exec[$id]['last'] = time();
895
+		//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
896
+		} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
897
+		//$buffer = $Common->getData($hosts[$id]);
898
+		if ($globalDebug) echo 'Get Data...'."\n";
899
+		$buffer = $Common->getData($value['host']);
900
+		$all_data = json_decode($buffer,true);
901
+		if ($buffer != '' && is_array($all_data)) {
902 902
 		$reset = 0;
903 903
 		foreach ($all_data as $line) {
904
-	    	    $data = array();
905
-	    	    //$data['id'] = $line['id']; // id not usable
906
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
907
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
908
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
909
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
910
-	    	    $data['ident'] = $line['flightnum']; // ident
911
-	    	    $data['altitude'] = $line['alt']; // altitude
912
-	    	    $data['speed'] = $line['gs']; // speed
913
-	    	    $data['heading'] = $line['heading']; // heading
914
-	    	    $data['latitude'] = $line['lat']; // lat
915
-	    	    $data['longitude'] = $line['lng']; // long
916
-	    	    $data['verticalrate'] = ''; // verticale rate
917
-	    	    $data['squawk'] = ''; // squawk
918
-	    	    $data['emergency'] = ''; // emergency
919
-	    	    //$data['datetime'] = $line['lastupdate'];
920
-	    	    $data['last_update'] = $line['lastupdate'];
921
-		    $data['datetime'] = date('Y-m-d H:i:s');
922
-	    	    $data['departure_airport_icao'] = $line['depicao'];
923
-	    	    $data['departure_airport_time'] = $line['deptime'];
924
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
925
-    		    $data['arrival_airport_time'] = $line['arrtime'];
926
-    		    $data['registration'] = $line['aircraft'];
927
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
928
-		    if (isset($line['aircraftname'])) {
904
+				$data = array();
905
+				//$data['id'] = $line['id']; // id not usable
906
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
907
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
908
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
909
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
910
+				$data['ident'] = $line['flightnum']; // ident
911
+				$data['altitude'] = $line['alt']; // altitude
912
+				$data['speed'] = $line['gs']; // speed
913
+				$data['heading'] = $line['heading']; // heading
914
+				$data['latitude'] = $line['lat']; // lat
915
+				$data['longitude'] = $line['lng']; // long
916
+				$data['verticalrate'] = ''; // verticale rate
917
+				$data['squawk'] = ''; // squawk
918
+				$data['emergency'] = ''; // emergency
919
+				//$data['datetime'] = $line['lastupdate'];
920
+				$data['last_update'] = $line['lastupdate'];
921
+			$data['datetime'] = date('Y-m-d H:i:s');
922
+				$data['departure_airport_icao'] = $line['depicao'];
923
+				$data['departure_airport_time'] = $line['deptime'];
924
+				$data['arrival_airport_icao'] = $line['arricao'];
925
+				$data['arrival_airport_time'] = $line['arrtime'];
926
+				$data['registration'] = $line['aircraft'];
927
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
928
+			if (isset($line['aircraftname'])) {
929 929
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
930 930
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
931
-	    		$aircraft_data = explode('-',$line['aircraftname']);
932
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
933
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
934
-	    		else {
935
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
936
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
937
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
938
-	    		}
939
-	    	    }
940
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
941
-    		    $data['id_source'] = $id_source;
942
-	    	    $data['format_source'] = 'phpvmacars';
943
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
944
-		    $SI->add($data);
945
-		    unset($data);
931
+				$aircraft_data = explode('-',$line['aircraftname']);
932
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
933
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
934
+				else {
935
+					$aircraft_data = explode(' ',$line['aircraftname']);
936
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
937
+					else $data['aircraft_icao'] = $line['aircraftname'];
938
+				}
939
+				}
940
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
941
+				$data['id_source'] = $id_source;
942
+				$data['format_source'] = 'phpvmacars';
943
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
944
+			$SI->add($data);
945
+			unset($data);
946 946
 		}
947 947
 		if ($globalDebug) echo 'No more data...'."\n";
948 948
 		unset($buffer);
949 949
 		unset($all_data);
950
-	    }
951
-    	    //$last_exec['phpvmacars'] = time();
952
-    	    $last_exec[$id]['last'] = time();
953
-    	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
954
-	    //$buffer = $Common->getData($hosts[$id]);
955
-	    if ($globalDebug) echo 'Get Data...'."\n";
956
-	    $buffer = $Common->getData($value['host']);
957
-	    $all_data = json_decode($buffer,true);
958
-	    if ($buffer != '' && is_array($all_data)) {
950
+		}
951
+			//$last_exec['phpvmacars'] = time();
952
+			$last_exec[$id]['last'] = time();
953
+		} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
954
+		//$buffer = $Common->getData($hosts[$id]);
955
+		if ($globalDebug) echo 'Get Data...'."\n";
956
+		$buffer = $Common->getData($value['host']);
957
+		$all_data = json_decode($buffer,true);
958
+		if ($buffer != '' && is_array($all_data)) {
959 959
 		$reset = 0;
960 960
 		foreach ($all_data as $line) {
961
-	    	    $data = array();
962
-	    	    //$data['id'] = $line['id']; // id not usable
963
-	    	    $data['id'] = trim($line['flight_id']);
964
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
965
-	    	    $data['pilot_name'] = $line['pilot_name'];
966
-	    	    $data['pilot_id'] = $line['pilot_id'];
967
-	    	    $data['ident'] = trim($line['callsign']); // ident
968
-	    	    $data['altitude'] = $line['altitude']; // altitude
969
-	    	    $data['speed'] = $line['gs']; // speed
970
-	    	    $data['heading'] = $line['heading']; // heading
971
-	    	    $data['latitude'] = $line['latitude']; // lat
972
-	    	    $data['longitude'] = $line['longitude']; // long
973
-	    	    $data['verticalrate'] = ''; // verticale rate
974
-	    	    $data['squawk'] = ''; // squawk
975
-	    	    $data['emergency'] = ''; // emergency
976
-	    	    //$data['datetime'] = $line['lastupdate'];
977
-	    	    $data['last_update'] = $line['last_update'];
978
-		    $data['datetime'] = date('Y-m-d H:i:s');
979
-	    	    $data['departure_airport_icao'] = $line['departure'];
980
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
981
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
982
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
983
-    		    //$data['registration'] = $line['aircraft'];
984
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
985
-	    	    $data['aircraft_icao'] = $line['plane_type'];
986
-    		    $data['id_source'] = $id_source;
987
-	    	    $data['format_source'] = 'vam';
988
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
989
-		    $SI->add($data);
990
-		    unset($data);
961
+				$data = array();
962
+				//$data['id'] = $line['id']; // id not usable
963
+				$data['id'] = trim($line['flight_id']);
964
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
965
+				$data['pilot_name'] = $line['pilot_name'];
966
+				$data['pilot_id'] = $line['pilot_id'];
967
+				$data['ident'] = trim($line['callsign']); // ident
968
+				$data['altitude'] = $line['altitude']; // altitude
969
+				$data['speed'] = $line['gs']; // speed
970
+				$data['heading'] = $line['heading']; // heading
971
+				$data['latitude'] = $line['latitude']; // lat
972
+				$data['longitude'] = $line['longitude']; // long
973
+				$data['verticalrate'] = ''; // verticale rate
974
+				$data['squawk'] = ''; // squawk
975
+				$data['emergency'] = ''; // emergency
976
+				//$data['datetime'] = $line['lastupdate'];
977
+				$data['last_update'] = $line['last_update'];
978
+			$data['datetime'] = date('Y-m-d H:i:s');
979
+				$data['departure_airport_icao'] = $line['departure'];
980
+				//$data['departure_airport_time'] = $line['departure_time'];
981
+				$data['arrival_airport_icao'] = $line['arrival'];
982
+				//$data['arrival_airport_time'] = $line['arrival_time'];
983
+				//$data['registration'] = $line['aircraft'];
984
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
985
+				$data['aircraft_icao'] = $line['plane_type'];
986
+				$data['id_source'] = $id_source;
987
+				$data['format_source'] = 'vam';
988
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
989
+			$SI->add($data);
990
+			unset($data);
991 991
 		}
992 992
 		if ($globalDebug) echo 'No more data...'."\n";
993 993
 		unset($buffer);
994 994
 		unset($all_data);
995
-	    }
996
-    	    //$last_exec['phpvmacars'] = time();
997
-    	    $last_exec[$id]['last'] = time();
995
+		}
996
+			//$last_exec['phpvmacars'] = time();
997
+			$last_exec[$id]['last'] = time();
998 998
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
999 999
 	} 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') {
1000
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1001
-    	    //$last_exec[$id]['last'] = time();
1000
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1001
+			//$last_exec[$id]['last'] = time();
1002 1002
 
1003
-	    //$read = array( $sockets[$id] );
1004
-	    $read = $sockets;
1005
-	    $write = NULL;
1006
-	    $e = NULL;
1007
-	    $n = socket_select($read, $write, $e, $timeout);
1008
-	    if ($e != NULL) var_dump($e);
1009
-	    if ($n > 0) {
1003
+		//$read = array( $sockets[$id] );
1004
+		$read = $sockets;
1005
+		$write = NULL;
1006
+		$e = NULL;
1007
+		$n = socket_select($read, $write, $e, $timeout);
1008
+		if ($e != NULL) var_dump($e);
1009
+		if ($n > 0) {
1010 1010
 		$reset = 0;
1011 1011
 		foreach ($read as $nb => $r) {
1012
-		    //$value = $formats[$nb];
1013
-		    $format = $globalSources[$nb]['format'];
1014
-        	    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1015
-        		$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
1016
-        	    } else {
1017
-	    	        $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1018
-	    	    }
1019
-        	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1020
-        	    //echo $buffer."\n";
1021
-		    // lets play nice and handle signals such as ctrl-c/kill properly
1022
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1023
-		    $error = false;
1024
-		    //$SI::del();
1025
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1026
-		    // SBS format is CSV format
1027
-		    if ($buffer != '') {
1012
+			//$value = $formats[$nb];
1013
+			$format = $globalSources[$nb]['format'];
1014
+				if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1015
+				$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
1016
+				} else {
1017
+					$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1018
+				}
1019
+				//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1020
+				//echo $buffer."\n";
1021
+			// lets play nice and handle signals such as ctrl-c/kill properly
1022
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1023
+			$error = false;
1024
+			//$SI::del();
1025
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1026
+			// SBS format is CSV format
1027
+			if ($buffer != '') {
1028 1028
 			$tt[$format] = 0;
1029 1029
 			if ($format == 'acarssbs3') {
1030
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1031
-			    $ACARS->add(trim($buffer));
1032
-			    $ACARS->deleteLiveAcarsData();
1030
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1031
+				$ACARS->add(trim($buffer));
1032
+				$ACARS->deleteLiveAcarsData();
1033 1033
 			} elseif ($format == 'raw') {
1034
-			    // AVR format
1035
-			    $data = $SBS->parse($buffer);
1036
-			    if (is_array($data)) {
1034
+				// AVR format
1035
+				$data = $SBS->parse($buffer);
1036
+				if (is_array($data)) {
1037 1037
 				$data['datetime'] = date('Y-m-d H:i:s');
1038 1038
 				$data['format_source'] = 'raw';
1039 1039
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1040
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1041
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1042
-                            }
1043
-                        } elseif ($format == 'ais') {
1044
-			    $ais_data = $AIS->parse_line(trim($buffer));
1045
-			    $data = array();
1046
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1047
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1048
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1049
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1050
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1051
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1052
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1053
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1054
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1055
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1056
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1057
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1040
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1041
+								if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1042
+							}
1043
+						} elseif ($format == 'ais') {
1044
+				$ais_data = $AIS->parse_line(trim($buffer));
1045
+				$data = array();
1046
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1047
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1048
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1049
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1050
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1051
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1052
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1053
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1054
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1055
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1056
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1057
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1058 1058
 
1059
-			    if (isset($ais_data['timestamp'])) {
1059
+				if (isset($ais_data['timestamp'])) {
1060 1060
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1061
-			    } else {
1061
+				} else {
1062 1062
 				$data['datetime'] = date('Y-m-d H:i:s');
1063
-			    }
1064
-			    $data['format_source'] = 'aisnmea';
1065
-    			    $data['id_source'] = $id_source;
1066
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1067
-			    unset($data);
1068
-                        } elseif ($format == 'flightgearsp') {
1069
-                    	    //echo $buffer."\n";
1070
-                    	    if (strlen($buffer) > 5) {
1063
+				}
1064
+				$data['format_source'] = 'aisnmea';
1065
+					$data['id_source'] = $id_source;
1066
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1067
+				unset($data);
1068
+						} elseif ($format == 'flightgearsp') {
1069
+							//echo $buffer."\n";
1070
+							if (strlen($buffer) > 5) {
1071 1071
 				$line = explode(',',$buffer);
1072 1072
 				$data = array();
1073 1073
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1083,123 +1083,123 @@  discard block
 block discarded – undo
1083 1083
 				$data['format_source'] = 'flightgearsp';
1084 1084
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1085 1085
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1086
-			    }
1087
-                        } elseif ($format == 'acars') {
1088
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1089
-			    $ACARS->add(trim($buffer));
1090
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1091
-			    $ACARS->deleteLiveAcarsData();
1086
+				}
1087
+						} elseif ($format == 'acars') {
1088
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1089
+				$ACARS->add(trim($buffer));
1090
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1091
+				$ACARS->deleteLiveAcarsData();
1092 1092
 			} elseif ($format == 'flightgearmp') {
1093
-			    if (substr($buffer,0,1) != '#') {
1093
+				if (substr($buffer,0,1) != '#') {
1094 1094
 				$data = array();
1095 1095
 				//echo $buffer."\n";
1096 1096
 				$line = explode(' ',$buffer);
1097 1097
 				if (count($line) == 11) {
1098
-				    $userserver = explode('@',$line[0]);
1099
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1100
-				    $data['ident'] = $userserver[0];
1101
-				    $data['registration'] = $userserver[0];
1102
-				    $data['latitude'] = $line[4];
1103
-				    $data['longitude'] = $line[5];
1104
-				    $data['altitude'] = $line[6];
1105
-				    $data['datetime'] = date('Y-m-d H:i:s');
1106
-				    $aircraft_type = $line[10];
1107
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1108
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1109
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1098
+					$userserver = explode('@',$line[0]);
1099
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1100
+					$data['ident'] = $userserver[0];
1101
+					$data['registration'] = $userserver[0];
1102
+					$data['latitude'] = $line[4];
1103
+					$data['longitude'] = $line[5];
1104
+					$data['altitude'] = $line[6];
1105
+					$data['datetime'] = date('Y-m-d H:i:s');
1106
+					$aircraft_type = $line[10];
1107
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1108
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1109
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1110
+				}
1110 1111
 				}
1111
-			    }
1112 1112
 			} elseif ($format == 'beast') {
1113
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1114
-			    die;
1113
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1114
+				die;
1115 1115
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1116
-			    $line = explode("\t", $buffer);
1117
-			    for($k = 0; $k < count($line); $k=$k+2) {
1116
+				$line = explode("\t", $buffer);
1117
+				for($k = 0; $k < count($line); $k=$k+2) {
1118 1118
 				$key = $line[$k];
1119
-			        $lined[$key] = $line[$k+1];
1120
-			    }
1121
-    			    if (count($lined) > 3) {
1122
-    				$data['hex'] = $lined['hexid'];
1123
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1124
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1125
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1126
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1127
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1128
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1129
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1130
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1131
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1132
-    				$data['id_source'] = $id_source;
1133
-    				$data['format_source'] = 'tsv';
1134
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1135
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1136
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1137
-    				unset($lined);
1138
-    				unset($data);
1139
-    			    } else $error = true;
1119
+					$lined[$key] = $line[$k+1];
1120
+				}
1121
+					if (count($lined) > 3) {
1122
+					$data['hex'] = $lined['hexid'];
1123
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1124
+					$data['datetime'] = date('Y-m-d H:i:s');;
1125
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1126
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1127
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1128
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1129
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1130
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1131
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1132
+					$data['id_source'] = $id_source;
1133
+					$data['format_source'] = 'tsv';
1134
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1135
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1136
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1137
+					unset($lined);
1138
+					unset($data);
1139
+					} else $error = true;
1140 1140
 			} elseif ($format == 'aprs' && $use_aprs) {
1141
-			    if ($aprs_connect == 0) {
1141
+				if ($aprs_connect == 0) {
1142 1142
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1143 1143
 				$aprs_connect = 1;
1144
-			    }
1144
+				}
1145 1145
 			    
1146
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1146
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1147 1147
 				$aprs_last_tx = time();
1148 1148
 				$data_aprs = "# Keep alive";
1149 1149
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1150
-			    }
1150
+				}
1151 1151
 			    
1152
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1153
-			    //echo 'APRS data : '.$buffer."\n";
1154
-			    $buffer = str_replace('APRS <- ','',$buffer);
1155
-			    $buffer = str_replace('APRS -> ','',$buffer);
1156
-			    echo $buffer."\n";
1157
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1152
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1153
+				//echo 'APRS data : '.$buffer."\n";
1154
+				$buffer = str_replace('APRS <- ','',$buffer);
1155
+				$buffer = str_replace('APRS -> ','',$buffer);
1156
+				echo $buffer."\n";
1157
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1158 1158
 				$line = $APRS->parse($buffer);
1159 1159
 				//print_r($line);
1160 1160
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1161 1161
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']))) {
1162
-				    $aprs_last_tx = time();
1163
-				    $data = array();
1164
-				    //print_r($line);
1165
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1166
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1167
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1168
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1169
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1170
-				    $data['latitude'] = $line['latitude'];
1171
-				    $data['longitude'] = $line['longitude'];
1172
-				    //$data['verticalrate'] = $line[16];
1173
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1174
-				    else $data['speed'] = 0;
1175
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1176
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1177
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1178
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1179
-				    //else $data['heading'] = 0;
1180
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1181
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1182
-    				    $data['id_source'] = $id_source;
1183
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1184
-				    else $data['format_source'] = 'aprs';
1185
-				    $data['source_name'] = $line['source'];
1186
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1187
-				    else $data['source_type'] = 'flarm';
1188
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1189
-				    $currentdate = date('Y-m-d H:i:s');
1190
-				    $aprsdate = strtotime($data['datetime']);
1191
-				    // Accept data if time <= system time + 20s
1192
-				    if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1162
+					$aprs_last_tx = time();
1163
+					$data = array();
1164
+					//print_r($line);
1165
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1166
+					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1167
+					else $data['datetime'] = date('Y-m-d H:i:s');
1168
+					//$data['datetime'] = date('Y-m-d H:i:s');
1169
+					if (isset($line['ident'])) $data['ident'] = $line['ident'];
1170
+					$data['latitude'] = $line['latitude'];
1171
+					$data['longitude'] = $line['longitude'];
1172
+					//$data['verticalrate'] = $line[16];
1173
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1174
+					else $data['speed'] = 0;
1175
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1176
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1177
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1178
+					if (isset($line['heading'])) $data['heading'] = $line['heading'];
1179
+					//else $data['heading'] = 0;
1180
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1181
+					if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1182
+						$data['id_source'] = $id_source;
1183
+						if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1184
+					else $data['format_source'] = 'aprs';
1185
+					$data['source_name'] = $line['source'];
1186
+					if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1187
+					else $data['source_type'] = 'flarm';
1188
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1189
+					$currentdate = date('Y-m-d H:i:s');
1190
+					$aprsdate = strtotime($data['datetime']);
1191
+					// Accept data if time <= system time + 20s
1192
+					if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1193 1193
 					$send = $SI->add($data);
1194
-				    } elseif (isset($line['stealth'])) {
1194
+					} elseif (isset($line['stealth'])) {
1195 1195
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1196 1196
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1197
-				    //} 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')) {
1198
-				    } 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') {
1197
+					//} 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')) {
1198
+					} 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') {
1199 1199
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1200 1200
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1201
-				    }
1202
-				    unset($data);
1201
+					}
1202
+					unset($data);
1203 1203
 				} 
1204 1204
 				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1205 1205
 					echo '!! Weather Station not yet supported'."\n";
@@ -1209,12 +1209,12 @@  discard block
 block discarded – undo
1209 1209
 				}
1210 1210
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1211 1211
 				//elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1212
-			    }
1212
+				}
1213 1213
 			} else {
1214
-			    $line = explode(',', $buffer);
1215
-    			    if (count($line) > 20) {
1216
-    			    	$data['hex'] = $line[4];
1217
-    				/*
1214
+				$line = explode(',', $buffer);
1215
+					if (count($line) > 20) {
1216
+						$data['hex'] = $line[4];
1217
+					/*
1218 1218
     				$data['datetime'] = $line[6].' '.$line[7];
1219 1219
     					date_default_timezone_set($globalTimezone);
1220 1220
     					$datetime = new DateTime($data['datetime']);
@@ -1222,29 +1222,29 @@  discard block
 block discarded – undo
1222 1222
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1223 1223
     					date_default_timezone_set('UTC');
1224 1224
     				*/
1225
-    				// Force datetime to current UTC datetime
1226
-    				date_default_timezone_set('UTC');
1227
-    				$data['datetime'] = date('Y-m-d H:i:s');
1228
-    				$data['ident'] = trim($line[10]);
1229
-    				$data['latitude'] = $line[14];
1230
-    				$data['longitude'] = $line[15];
1231
-    				$data['verticalrate'] = $line[16];
1232
-    				$data['emergency'] = $line[20];
1233
-    				$data['speed'] = $line[12];
1234
-    				$data['squawk'] = $line[17];
1235
-    				$data['altitude'] = $line[11];
1236
-    				$data['heading'] = $line[13];
1237
-    				$data['ground'] = $line[21];
1238
-    				$data['emergency'] = $line[19];
1239
-    				$data['format_source'] = 'sbs';
1225
+					// Force datetime to current UTC datetime
1226
+					date_default_timezone_set('UTC');
1227
+					$data['datetime'] = date('Y-m-d H:i:s');
1228
+					$data['ident'] = trim($line[10]);
1229
+					$data['latitude'] = $line[14];
1230
+					$data['longitude'] = $line[15];
1231
+					$data['verticalrate'] = $line[16];
1232
+					$data['emergency'] = $line[20];
1233
+					$data['speed'] = $line[12];
1234
+					$data['squawk'] = $line[17];
1235
+					$data['altitude'] = $line[11];
1236
+					$data['heading'] = $line[13];
1237
+					$data['ground'] = $line[21];
1238
+					$data['emergency'] = $line[19];
1239
+					$data['format_source'] = 'sbs';
1240 1240
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1241
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1242
-    				$data['id_source'] = $id_source;
1243
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1244
-    				else $error = true;
1245
-    				unset($data);
1246
-    			    } else $error = true;
1247
-			    if ($error) {
1241
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1242
+					$data['id_source'] = $id_source;
1243
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1244
+					else $error = true;
1245
+					unset($data);
1246
+					} else $error = true;
1247
+				if ($error) {
1248 1248
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1249 1249
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1250 1250
 				} else {
@@ -1260,13 +1260,13 @@  discard block
 block discarded – undo
1260 1260
 					connect_all($sourceer);
1261 1261
 					$sourceer = array();
1262 1262
 				}
1263
-			    }
1263
+				}
1264 1264
 			}
1265 1265
 			// Sleep for xxx microseconds
1266 1266
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1267
-		    } else {
1267
+			} else {
1268 1268
 			if ($format == 'flightgearmp') {
1269
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1269
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1270 1270
 				//@socket_close($r);
1271 1271
 				sleep($globalMinFetch);
1272 1272
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1275,9 +1275,9 @@  discard block
 block discarded – undo
1275 1275
 				break;
1276 1276
 				
1277 1277
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1278
-			    if (isset($tt[$format])) $tt[$format]++;
1279
-			    else $tt[$format] = 0;
1280
-			    if ($tt[$format] > 30) {
1278
+				if (isset($tt[$format])) $tt[$format]++;
1279
+				else $tt[$format] = 0;
1280
+				if ($tt[$format] > 30) {
1281 1281
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1282 1282
 				//@socket_close($r);
1283 1283
 				sleep(2);
@@ -1288,23 +1288,23 @@  discard block
 block discarded – undo
1288 1288
 				//connect_all($globalSources);
1289 1289
 				$tt[$format]=0;
1290 1290
 				break;
1291
-			    }
1291
+				}
1292
+			}
1292 1293
 			}
1293
-		    }
1294 1294
 		}
1295
-	    } else {
1295
+		} else {
1296 1296
 		$error = socket_strerror(socket_last_error());
1297 1297
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1298 1298
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1299 1299
 			if (isset($globalDebug)) echo "Restarting...\n";
1300 1300
 			// Restart the script if possible
1301 1301
 			if (is_array($sockets)) {
1302
-			    if ($globalDebug) echo "Shutdown all sockets...";
1302
+				if ($globalDebug) echo "Shutdown all sockets...";
1303 1303
 			    
1304
-			    foreach ($sockets as $sock) {
1304
+				foreach ($sockets as $sock) {
1305 1305
 				@socket_shutdown($sock,2);
1306 1306
 				@socket_close($sock);
1307
-			    }
1307
+				}
1308 1308
 			    
1309 1309
 			}
1310 1310
 			if ($globalDebug) echo "Restart all connections...";
@@ -1315,13 +1315,13 @@  discard block
 block discarded – undo
1315 1315
 			if ($reset > 40) exit('Too many attempts...');
1316 1316
 			connect_all($globalSources);
1317 1317
 		}
1318
-	    }
1318
+		}
1319 1319
 	}
1320 1320
 	if ($globalDaemon === false) {
1321
-	    if ($globalDebug) echo 'Check all...'."\n";
1322
-	    $SI->checkAll();
1321
+		if ($globalDebug) echo 'Check all...'."\n";
1322
+		$SI->checkAll();
1323
+	}
1323 1324
 	}
1324
-    }
1325 1325
 }
1326 1326
 
1327 1327
 ?>
Please login to merge, or discard this patch.
Spacing   +132 added lines, -132 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,27 +64,27 @@  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();
67
+    $SI = new SpotterServer();
68 68
 /*
69 69
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
70 70
     $SI = new adsb2aprs();
71 71
     $SI->connect();
72 72
 */
73
-} else $SI=new SpotterImport($Connection->db);
73
+} else $SI = new SpotterImport($Connection->db);
74 74
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
75 75
 if (isset($globalMarine) && $globalMarine) {
76 76
     $AIS = new AIS();
77 77
     $MI = new MarineImport($Connection->db);
78 78
 }
79 79
 //$APRS=new APRS($Connection->db);
80
-$SBS=new SBS();
81
-$ACARS=new ACARS($Connection->db);
82
-$Common=new Common();
80
+$SBS = new SBS();
81
+$ACARS = new ACARS($Connection->db);
82
+$Common = new Common();
83 83
 date_default_timezone_set('UTC');
84 84
 //$servertz = system('date +%Z');
85 85
 // signal handler - playing nice with sockets and dump1090
86 86
 if (function_exists('pcntl_fork')) {
87
-    pcntl_signal(SIGINT,  function() {
87
+    pcntl_signal(SIGINT, function() {
88 88
         global $sockets;
89 89
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
90 90
         die("Bye!\n");
@@ -100,35 +100,35 @@  discard block
 block discarded – undo
100 100
 
101 101
 function connect_all($hosts) {
102 102
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
103
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
103
+    global $sockets, $httpfeeds, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset, $context;
104 104
     $reset++;
105 105
     if ($globalDebug) echo 'Connect to all...'."\n";
106 106
     foreach ($hosts as $id => $value) {
107 107
 	$host = $value['host'];
108 108
 	$globalSources[$id]['last_exec'] = 0;
109 109
 	// Here we check type of source(s)
110
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
111
-            if (preg_match('/deltadb.txt$/i',$host)) {
110
+	if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
111
+            if (preg_match('/deltadb.txt$/i', $host)) {
112 112
         	//$formats[$id] = 'deltadbtxt';
113 113
         	$globalSources[$id]['format'] = 'deltadbtxt';
114 114
         	//$last_exec['deltadbtxt'] = 0;
115 115
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
116
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
116
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
117 117
         	//$formats[$id] = 'vatsimtxt';
118 118
         	$globalSources[$id]['format'] = 'vatsimtxt';
119 119
         	//$last_exec['vatsimtxt'] = 0;
120 120
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
121
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
121
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
122 122
         	//$formats[$id] = 'aircraftlistjson';
123 123
         	$globalSources[$id]['format'] = 'aircraftlistjson';
124 124
         	//$last_exec['aircraftlistjson'] = 0;
125 125
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
126
-    	    } else if (preg_match('/opensky/i',$host)) {
126
+    	    } else if (preg_match('/opensky/i', $host)) {
127 127
         	//$formats[$id] = 'aircraftlistjson';
128 128
         	$globalSources[$id]['format'] = 'opensky';
129 129
         	//$last_exec['aircraftlistjson'] = 0;
130 130
         	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
131
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
131
+    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i', $host)) {
132 132
         	//$formats[$id] = 'radarvirtueljson';
133 133
         	$globalSources[$id]['format'] = 'radarvirtueljson';
134 134
         	//$last_exec['radarvirtueljson'] = 0;
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
138 138
         	    exit(0);
139 139
         	}
140
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
140
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
141 141
         	//$formats[$id] = 'planeupdatefaa';
142 142
         	$globalSources[$id]['format'] = 'planeupdatefaa';
143 143
         	//$last_exec['planeupdatefaa'] = 0;
@@ -146,26 +146,26 @@  discard block
 block discarded – undo
146 146
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
147 147
         	    exit(0);
148 148
         	}
149
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
149
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
150 150
         	//$formats[$id] = 'phpvmacars';
151 151
         	$globalSources[$id]['format'] = 'phpvmacars';
152 152
         	//$last_exec['phpvmacars'] = 0;
153 153
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
154
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
154
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
155 155
         	//$formats[$id] = 'phpvmacars';
156 156
         	$globalSources[$id]['format'] = 'vam';
157 157
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
158
-            } else if (preg_match('/whazzup/i',$host)) {
158
+            } else if (preg_match('/whazzup/i', $host)) {
159 159
         	//$formats[$id] = 'whazzup';
160 160
         	$globalSources[$id]['format'] = 'whazzup';
161 161
         	//$last_exec['whazzup'] = 0;
162 162
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
163
-            } else if (preg_match('/recentpireps/i',$host)) {
163
+            } else if (preg_match('/recentpireps/i', $host)) {
164 164
         	//$formats[$id] = 'pirepsjson';
165 165
         	$globalSources[$id]['format'] = 'pirepsjson';
166 166
         	//$last_exec['pirepsjson'] = 0;
167 167
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
168
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
168
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
169 169
         	//$formats[$id] = 'fr24json';
170 170
         	$globalSources[$id]['format'] = 'fr24json';
171 171
         	//$last_exec['fr24json'] = 0;
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
175 175
         	    exit(0);
176 176
         	}
177
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
177
+            } else if (preg_match(':myshiptracking.com/:i', $host)) {
178 178
         	//$formats[$id] = 'fr24json';
179 179
         	$globalSources[$id]['format'] = 'myshiptracking';
180 180
         	//$last_exec['fr24json'] = 0;
@@ -184,22 +184,22 @@  discard block
 block discarded – undo
184 184
         	    exit(0);
185 185
         	}
186 186
             //} else if (preg_match('/10001/',$host)) {
187
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
187
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
188 188
         	//$formats[$id] = 'tsv';
189 189
         	$globalSources[$id]['format'] = 'tsv';
190 190
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
191 191
             }
192
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
192
+        } elseif (filter_var($host, FILTER_VALIDATE_URL)) {
193 193
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
194
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
194
+    		    $idf = fopen($globalSources[$id]['host'], 'r', false, $context);
195 195
     		    if ($idf !== false) {
196 196
     			$httpfeeds[$id] = $idf;
197 197
         		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
198 198
     		    }
199 199
     		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
200 200
     		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
201
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
202
-	    $hostport = explode(':',$host);
201
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
202
+	    $hostport = explode(':', $host);
203 203
 	    if (isset($hostport[1])) {
204 204
 		$port = $hostport[1];
205 205
 		$hostn = $hostport[0];
@@ -209,14 +209,14 @@  discard block
 block discarded – undo
209 209
 	    }
210 210
 	    $Common = new Common();
211 211
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
212
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
212
+        	$s = $Common->create_socket($hostn, $port, $errno, $errstr);
213 213
     	    } else {
214
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
214
+        	$s = $Common->create_socket_udp($hostn, $port, $errno, $errstr);
215 215
 	    }
216 216
 	    if ($s) {
217 217
     	        $sockets[$id] = $s;
218 218
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
219
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
219
+		    if (preg_match('/aprs/', $hostn) || $port == '10152' || $port == '14580') {
220 220
 			//$formats[$id] = 'aprs';
221 221
 			$globalSources[$id]['format'] = 'aprs';
222 222
 			//$aprs_connect = 0;
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
259 259
 else $timeout = 20;
260 260
 $errno = '';
261
-$errstr='';
261
+$errstr = '';
262 262
 
263 263
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
264 264
 /* Initiate connections to all the hosts simultaneously */
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
 //connect_all($globalSources);
267 267
 
268 268
 if (isset($globalProxy) && $globalProxy) {
269
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
269
+    $context = stream_context_create(array('http' => array('timeout' => $timeout, 'proxy' => $globalProxy, 'request_fulluri' => true)));
270 270
 } else {
271 271
     $context = stream_context_create(array('http' => array('timeout' => $timeout)));
272 272
 }
@@ -293,16 +293,16 @@  discard block
 block discarded – undo
293 293
 
294 294
 if ($use_aprs) {
295 295
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
296
-	$APRS=new APRS();
296
+	$APRS = new APRS();
297 297
 	$aprs_connect = 0;
298 298
 	$aprs_keep = 120;
299 299
 	$aprs_last_tx = time();
300 300
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
301
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
301
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
302 302
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
303
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
303
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
304 304
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
305
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
305
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
306 306
 	if ($aprs_full) $aprs_filter = '';
307 307
 	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
308 308
 	else $aprs_pass = '-1';
@@ -317,12 +317,12 @@  discard block
 block discarded – undo
317 317
 sleep(1);
318 318
 if ($globalDebug) echo "SCAN MODE \n\n";
319 319
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
320
-$endtime = time()+$globalCronEnd;
320
+$endtime = time() + $globalCronEnd;
321 321
 $i = 1;
322 322
 $tt = array();
323 323
 // Delete all ATC
324 324
 if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
325
-	$ATC=new ATC($Connection->db);
325
+	$ATC = new ATC($Connection->db);
326 326
 }
327 327
 if (!$globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
328 328
 	$ATC->deleteAll();
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 
331 331
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
332 332
 while ($i > 0) {
333
-    if (!$globalDaemon) $i = $endtime-time();
333
+    if (!$globalDaemon) $i = $endtime - time();
334 334
     // Delete old ATC
335 335
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
336 336
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 	}
346 346
 	if ($max != $globalMinFetch) {
347 347
 	    if ($globalDebug) echo 'Sleeping...'."\n";
348
-	    sleep($globalMinFetch-$max+2);
348
+	    sleep($globalMinFetch - $max + 2);
349 349
 	}
350 350
     }
351 351
 
@@ -358,8 +358,8 @@  discard block
 block discarded – undo
358 358
 	    //$buffer = $Common->getData($hosts[$id]);
359 359
 	    $buffer = $Common->getData($value['host']);
360 360
 	    if ($buffer != '') $reset = 0;
361
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
362
-	    $buffer = explode('\n',$buffer);
361
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
362
+	    $buffer = explode('\n', $buffer);
363 363
 	    foreach ($buffer as $line) {
364 364
     		if ($line != '' && count($line) > 7) {
365 365
     		    $line = explode(',', $line);
@@ -386,11 +386,11 @@  discard block
 block discarded – undo
386 386
     	    $last_exec[$id]['last'] = time();
387 387
 	} elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
388 388
 	    date_default_timezone_set('CET');
389
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
389
+	    $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host']));
390 390
 	    date_default_timezone_set('UTC');
391 391
 	    if ($buffer != '') $reset = 0;
392
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
393
-	    $buffer = explode('\n',$buffer);
392
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
393
+	    $buffer = explode('\n', $buffer);
394 394
 	    foreach ($buffer as $line) {
395 395
 		if ($line != '') {
396 396
 		    echo "'".$line."'\n";
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
 		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
409 409
 		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
410 410
 		    if (isset($ais_data['timestamp'])) {
411
-			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
411
+			$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
412 412
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
413 413
 			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
414 414
 			    $add = true;
@@ -431,12 +431,12 @@  discard block
 block discarded – undo
431 431
 	    $w = $e = null;
432 432
 	    
433 433
 	    if (isset($arr[$id])) {
434
-	    $nn = stream_select($arr,$w,$e,$timeout);
434
+	    $nn = stream_select($arr, $w, $e, $timeout);
435 435
 	    if ($nn > 0) {
436 436
 		foreach ($httpfeeds as $feed) {
437
-		    $buffer = stream_get_line($feed,2000,"\n");
438
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
439
-		    $buffer = explode('\n',$buffer);
437
+		    $buffer = stream_get_line($feed, 2000, "\n");
438
+		    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
439
+		    $buffer = explode('\n', $buffer);
440 440
 		    foreach ($buffer as $line) {
441 441
 			if ($line != '') {
442 442
 			    $ais_data = $AIS->parse_line(trim($line));
@@ -452,9 +452,9 @@  discard block
 block discarded – undo
452 452
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
453 453
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
454 454
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
455
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
455
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
456 456
 			    if (isset($ais_data['timestamp'])) {
457
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
457
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
458 458
 			    } else {
459 459
 				$data['datetime'] = date('Y-m-d H:i:s');
460 460
 			    }
@@ -468,10 +468,10 @@  discard block
 block discarded – undo
468 468
 		}
469 469
 	    }
470 470
 	} elseif ($value['format'] == 'myshiptracking' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
471
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
471
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
472 472
 	    if ($buffer != '') {
473 473
 		//echo $buffer;
474
-		$all_data = json_decode($buffer,true);
474
+		$all_data = json_decode($buffer, true);
475 475
 		//print_r($all_data);
476 476
 		if (isset($all_data[0]['DATA'])) {
477 477
 		foreach ($all_data[0]['DATA'] as $line) {
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
 			//    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
487 487
 			$data['imo'] = $line['IMO'];
488 488
 			//$data['arrival_code'] = $ais_data['destination'];
489
-			$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
489
+			$data['datetime'] = date('Y-m-d H:i:s', $line['T']);
490 490
 			$data['format_source'] = 'myshiptracking';
491 491
 			$data['id_source'] = $id_source;
492 492
 			$MI->add($data);
@@ -498,9 +498,9 @@  discard block
 block discarded – undo
498 498
 	    }
499 499
     	    $last_exec[$id]['last'] = time();
500 500
 	} elseif ($value['format'] == 'boatbeaconapp' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
501
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
501
+	    $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host']));
502 502
 	    if ($buffer != '') {
503
-		$all_data = json_decode($buffer,true);
503
+		$all_data = json_decode($buffer, true);
504 504
 		if (isset($all_data[0]['mmsi'])) {
505 505
 		    foreach ($all_data as $line) {
506 506
 			if ($line != '') {
@@ -527,27 +527,27 @@  discard block
 block discarded – undo
527 527
     	    $last_exec[$id]['last'] = time();
528 528
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
529 529
 	    echo 'download...';
530
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
530
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
531 531
 	    echo 'done !'."\n";
532 532
 	    if ($buffer != '') $reset = 0;
533
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
534
-	    $buffer = explode('\n',$buffer);
533
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
534
+	    $buffer = explode('\n', $buffer);
535 535
 	    foreach ($buffer as $line) {
536 536
 		if ($line != '') {
537 537
 		    $data = array();
538
-		    $data['mmsi'] = (int)substr($line,0,9);
539
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
538
+		    $data['mmsi'] = (int) substr($line, 0, 9);
539
+		    $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10));
540 540
 		    //$data['status'] = substr($line,21,2);
541 541
 		    //$data['type'] = substr($line,24,3);
542
-		    $data['latitude'] = substr($line,29,9);
543
-		    $data['longitude'] = substr($line,41,9);
544
-		    $data['speed'] = round(substr($line,51,5));
542
+		    $data['latitude'] = substr($line, 29, 9);
543
+		    $data['longitude'] = substr($line, 41, 9);
544
+		    $data['speed'] = round(substr($line, 51, 5));
545 545
 		    //$data['course'] = substr($line,57,5);
546
-		    $data['heading'] = round(substr($line,63,3));
546
+		    $data['heading'] = round(substr($line, 63, 3));
547 547
 		    //$data['draft'] = substr($line,67,4);
548 548
 		    //$data['length'] = substr($line,72,3);
549 549
 		    //$data['beam'] = substr($line,76,2);
550
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
550
+		    $data['ident'] = trim(utf8_encode(substr($line, 79, 20)));
551 551
 		    //$data['callsign'] = trim(substr($line,100,7);
552 552
 		    //$data['dest'] = substr($line,108,20);
553 553
 		    //$data['etaDate'] = substr($line,129,5);
@@ -565,8 +565,8 @@  discard block
 block discarded – undo
565 565
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
566 566
 	    //$buffer = $Common->getData($hosts[$id]);
567 567
 	    $buffer = $Common->getData($value['host']);
568
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
569
-	    $buffer = explode('\n',$buffer);
568
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
569
+	    $buffer = explode('\n', $buffer);
570 570
 	    $reset = 0;
571 571
 	    foreach ($buffer as $line) {
572 572
     		if ($line != '') {
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
578 578
 			$data['pilot_id'] = $line[1];
579 579
 			$data['pilot_name'] = $line[2];
580
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
580
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
581 581
 			$data['ident'] = $line[0]; // ident
582 582
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
583 583
 			$data['speed'] = $line[8]; // speed
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
594 594
 			//if (isset($line[37])) $data['last_update'] = $line[37];
595 595
 		        $data['departure_airport_icao'] = $line[11];
596
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
596
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
597 597
 		        $data['arrival_airport_icao'] = $line[13];
598 598
 			$data['frequency'] = $line[4];
599 599
 			$data['type'] = $line[18];
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
     			$data['id_source'] = $id_source;
603 603
 	    		//$data['arrival_airport_time'] = ;
604 604
 	    		if ($line[9] != '') {
605
-	    		    $aircraft_data = explode('/',$line[9]);
605
+	    		    $aircraft_data = explode('/', $line[9]);
606 606
 	    		    if (isset($aircraft_data[1])) {
607 607
 	    			$data['aircraft_icao'] = $aircraft_data[1];
608 608
 	    		    }
@@ -616,9 +616,9 @@  discard block
 block discarded – undo
616 616
     			if ($line[3] == 'PILOT') $SI->add($data);
617 617
 			elseif ($line[3] == 'ATC') {
618 618
 				//print_r($data);
619
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
620
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
621
-				$typec = substr($data['ident'],-3);
619
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
620
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
621
+				$typec = substr($data['ident'], -3);
622 622
 				if ($typec == 'APP') $data['type'] = 'Approach';
623 623
 				elseif ($typec == 'TWR') $data['type'] = 'Tower';
624 624
 				elseif ($typec == 'OBS') $data['type'] = 'Observer';
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
 				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
630 630
 				elseif ($data['type'] == '') $data['type'] = 'Observer';
631 631
 				if (!isset($data['source_name'])) $data['source_name'] = '';
632
-				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']);
632
+				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']);
633 633
 			}
634 634
     			unset($data);
635 635
     		    }
@@ -640,9 +640,9 @@  discard block
 block discarded – undo
640 640
     	    $last_exec[$id]['last'] = time();
641 641
     	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
642 642
     	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
643
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
643
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
644 644
 	    if ($buffer != '') {
645
-	    $all_data = json_decode($buffer,true);
645
+	    $all_data = json_decode($buffer, true);
646 646
 	    if (isset($all_data['acList'])) {
647 647
 		$reset = 0;
648 648
 		foreach ($all_data['acList'] as $line) {
@@ -698,7 +698,7 @@  discard block
 block discarded – undo
698 698
     	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
699 699
     	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
700 700
 	    $buffer = $Common->getData($value['host']);
701
-	    $all_data = json_decode($buffer,true);
701
+	    $all_data = json_decode($buffer, true);
702 702
 	    if (isset($all_data['planes'])) {
703 703
 		$reset = 0;
704 704
 		foreach ($all_data['planes'] as $key => $line) {
@@ -715,12 +715,12 @@  discard block
 block discarded – undo
715 715
 		    $data['emergency'] = ''; // emergency
716 716
 		    $data['registration'] = $line[2];
717 717
 		    $data['aircraft_icao'] = $line[0];
718
-		    $deparr = explode('-',$line[1]);
718
+		    $deparr = explode('-', $line[1]);
719 719
 		    if (count($deparr) == 2) {
720 720
 			$data['departure_airport_icao'] = $deparr[0];
721 721
 			$data['arrival_airport_icao'] = $deparr[1];
722 722
 		    }
723
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
723
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
724 724
 	    	    $data['format_source'] = 'planeupdatefaa';
725 725
     		    $data['id_source'] = $id_source;
726 726
 		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -732,7 +732,7 @@  discard block
 block discarded – undo
732 732
     	    $last_exec[$id]['last'] = time();
733 733
     	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
734 734
 	    $buffer = $Common->getData($value['host']);
735
-	    $all_data = json_decode($buffer,true);
735
+	    $all_data = json_decode($buffer, true);
736 736
 	    if (isset($all_data['states'])) {
737 737
 		$reset = 0;
738 738
 		foreach ($all_data['states'] as $key => $line) {
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
 		    //$data['emergency'] = ''; // emergency
750 750
 		    //$data['registration'] = $line[2];
751 751
 		    //$data['aircraft_icao'] = $line[0];
752
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
752
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
753 753
 	    	    $data['format_source'] = 'opensky';
754 754
     		    $data['id_source'] = $id_source;
755 755
 		    $SI->add($data);
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
     	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
763 763
 	    //$buffer = $Common->getData($hosts[$id]);
764 764
 	    $buffer = $Common->getData($value['host']);
765
-	    $all_data = json_decode($buffer,true);
765
+	    $all_data = json_decode($buffer, true);
766 766
 	    if (!empty($all_data)) $reset = 0;
767 767
 	    foreach ($all_data as $key => $line) {
768 768
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -794,11 +794,11 @@  discard block
 block discarded – undo
794 794
     	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
795 795
     	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
796 796
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
797
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
797
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
798 798
 	    //echo $buffer;
799
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
800
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
801
-	    $all_data = json_decode($buffer,true);
799
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
800
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
801
+	    $all_data = json_decode($buffer, true);
802 802
 	    if (json_last_error() != JSON_ERROR_NONE) {
803 803
 		die(json_last_error_msg());
804 804
 	    }
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
 			//$data['departure_airport_iata'] = $line[11];
822 822
 			//$data['arrival_airport_iata'] = $line[12];
823 823
 	    		//$data['emergency'] = ''; // emergency
824
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
824
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
825 825
 	    		$data['format_source'] = 'radarvirtueljson';
826 826
     			$data['id_source'] = $id_source;
827 827
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -836,14 +836,14 @@  discard block
 block discarded – undo
836 836
     	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
837 837
 	    //$buffer = $Common->getData($hosts[$id]);
838 838
 	    $buffer = $Common->getData($value['host'].'?'.time());
839
-	    $all_data = json_decode(utf8_encode($buffer),true);
839
+	    $all_data = json_decode(utf8_encode($buffer), true);
840 840
 	    
841 841
 	    if (isset($all_data['pireps'])) {
842 842
 		$reset = 0;
843 843
 	        foreach ($all_data['pireps'] as $line) {
844 844
 		    $data = array();
845 845
 		    $data['id'] = $line['id'];
846
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
846
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
847 847
 		    $data['ident'] = $line['callsign']; // ident
848 848
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
849 849
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -872,9 +872,9 @@  discard block
 block discarded – undo
872 872
 			$SI->add($data);
873 873
 		    //    print_r($data);
874 874
     		    } elseif ($line['icon'] == 'ct') {
875
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
876
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
877
-			$typec = substr($data['ident'],-3);
875
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
876
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
877
+			$typec = substr($data['ident'], -3);
878 878
 			$data['type'] = '';
879 879
 			if ($typec == 'APP') $data['type'] = 'Approach';
880 880
 			elseif ($typec == 'TWR') $data['type'] = 'Tower';
@@ -885,7 +885,7 @@  discard block
 block discarded – undo
885 885
 			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
886 886
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
887 887
 			else $data['type'] = 'Observer';
888
-			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']);
888
+			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']);
889 889
 		    }
890 890
 		    unset($data);
891 891
 		}
@@ -897,14 +897,14 @@  discard block
 block discarded – undo
897 897
 	    //$buffer = $Common->getData($hosts[$id]);
898 898
 	    if ($globalDebug) echo 'Get Data...'."\n";
899 899
 	    $buffer = $Common->getData($value['host']);
900
-	    $all_data = json_decode($buffer,true);
900
+	    $all_data = json_decode($buffer, true);
901 901
 	    if ($buffer != '' && is_array($all_data)) {
902 902
 		$reset = 0;
903 903
 		foreach ($all_data as $line) {
904 904
 	    	    $data = array();
905 905
 	    	    //$data['id'] = $line['id']; // id not usable
906 906
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
907
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
907
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
908 908
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
909 909
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
910 910
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -927,12 +927,12 @@  discard block
 block discarded – undo
927 927
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
928 928
 		    if (isset($line['aircraftname'])) {
929 929
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
930
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
931
-	    		$aircraft_data = explode('-',$line['aircraftname']);
930
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
931
+	    		$aircraft_data = explode('-', $line['aircraftname']);
932 932
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
933 933
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
934 934
 	    		else {
935
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
935
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
936 936
 	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
937 937
 	    		    else $data['aircraft_icao'] = $line['aircraftname'];
938 938
 	    		}
@@ -954,14 +954,14 @@  discard block
 block discarded – undo
954 954
 	    //$buffer = $Common->getData($hosts[$id]);
955 955
 	    if ($globalDebug) echo 'Get Data...'."\n";
956 956
 	    $buffer = $Common->getData($value['host']);
957
-	    $all_data = json_decode($buffer,true);
957
+	    $all_data = json_decode($buffer, true);
958 958
 	    if ($buffer != '' && is_array($all_data)) {
959 959
 		$reset = 0;
960 960
 		foreach ($all_data as $line) {
961 961
 	    	    $data = array();
962 962
 	    	    //$data['id'] = $line['id']; // id not usable
963 963
 	    	    $data['id'] = trim($line['flight_id']);
964
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
964
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
965 965
 	    	    $data['pilot_name'] = $line['pilot_name'];
966 966
 	    	    $data['pilot_id'] = $line['pilot_id'];
967 967
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -1012,9 +1012,9 @@  discard block
 block discarded – undo
1012 1012
 		    //$value = $formats[$nb];
1013 1013
 		    $format = $globalSources[$nb]['format'];
1014 1014
         	    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1015
-        		$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
1015
+        		$buffer = socket_read($r, 6000, PHP_NORMAL_READ);
1016 1016
         	    } else {
1017
-	    	        $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1017
+	    	        $az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
1018 1018
 	    	    }
1019 1019
         	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1020 1020
         	    //echo $buffer."\n";
@@ -1022,7 +1022,7 @@  discard block
 block discarded – undo
1022 1022
 		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1023 1023
 		    $error = false;
1024 1024
 		    //$SI::del();
1025
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1025
+		    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
1026 1026
 		    // SBS format is CSV format
1027 1027
 		    if ($buffer != '') {
1028 1028
 			$tt[$format] = 0;
@@ -1054,10 +1054,10 @@  discard block
 block discarded – undo
1054 1054
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1055 1055
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1056 1056
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1057
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1057
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1058 1058
 
1059 1059
 			    if (isset($ais_data['timestamp'])) {
1060
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1060
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1061 1061
 			    } else {
1062 1062
 				$data['datetime'] = date('Y-m-d H:i:s');
1063 1063
 			    }
@@ -1068,10 +1068,10 @@  discard block
 block discarded – undo
1068 1068
                         } elseif ($format == 'flightgearsp') {
1069 1069
                     	    //echo $buffer."\n";
1070 1070
                     	    if (strlen($buffer) > 5) {
1071
-				$line = explode(',',$buffer);
1071
+				$line = explode(',', $buffer);
1072 1072
 				$data = array();
1073 1073
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1074
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1074
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1075 1075
 				$data['ident'] = $line[6];
1076 1076
 				$data['aircraft_name'] = $line[7];
1077 1077
 				$data['longitude'] = $line[1];
@@ -1082,21 +1082,21 @@  discard block
 block discarded – undo
1082 1082
 				$data['datetime'] = date('Y-m-d H:i:s');
1083 1083
 				$data['format_source'] = 'flightgearsp';
1084 1084
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1085
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1085
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1086 1086
 			    }
1087 1087
                         } elseif ($format == 'acars') {
1088 1088
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1089 1089
 			    $ACARS->add(trim($buffer));
1090
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1090
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1091 1091
 			    $ACARS->deleteLiveAcarsData();
1092 1092
 			} elseif ($format == 'flightgearmp') {
1093
-			    if (substr($buffer,0,1) != '#') {
1093
+			    if (substr($buffer, 0, 1) != '#') {
1094 1094
 				$data = array();
1095 1095
 				//echo $buffer."\n";
1096
-				$line = explode(' ',$buffer);
1096
+				$line = explode(' ', $buffer);
1097 1097
 				if (count($line) == 11) {
1098
-				    $userserver = explode('@',$line[0]);
1099
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1098
+				    $userserver = explode('@', $line[0]);
1099
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1100 1100
 				    $data['ident'] = $userserver[0];
1101 1101
 				    $data['registration'] = $userserver[0];
1102 1102
 				    $data['latitude'] = $line[4];
@@ -1104,24 +1104,24 @@  discard block
 block discarded – undo
1104 1104
 				    $data['altitude'] = $line[6];
1105 1105
 				    $data['datetime'] = date('Y-m-d H:i:s');
1106 1106
 				    $aircraft_type = $line[10];
1107
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1108
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1107
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1108
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1109 1109
 				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1110 1110
 				}
1111 1111
 			    }
1112 1112
 			} elseif ($format == 'beast') {
1113 1113
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1114 1114
 			    die;
1115
-			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1115
+			} elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') {
1116 1116
 			    $line = explode("\t", $buffer);
1117
-			    for($k = 0; $k < count($line); $k=$k+2) {
1117
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1118 1118
 				$key = $line[$k];
1119
-			        $lined[$key] = $line[$k+1];
1119
+			        $lined[$key] = $line[$k + 1];
1120 1120
 			    }
1121 1121
     			    if (count($lined) > 3) {
1122 1122
     				$data['hex'] = $lined['hexid'];
1123 1123
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1124
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1124
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1125 1125
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1126 1126
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1127 1127
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1139,22 +1139,22 @@  discard block
 block discarded – undo
1139 1139
     			    } else $error = true;
1140 1140
 			} elseif ($format == 'aprs' && $use_aprs) {
1141 1141
 			    if ($aprs_connect == 0) {
1142
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1142
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
1143 1143
 				$aprs_connect = 1;
1144 1144
 			    }
1145 1145
 			    
1146
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1146
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
1147 1147
 				$aprs_last_tx = time();
1148 1148
 				$data_aprs = "# Keep alive";
1149
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1149
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1150 1150
 			    }
1151 1151
 			    
1152 1152
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1153 1153
 			    //echo 'APRS data : '.$buffer."\n";
1154
-			    $buffer = str_replace('APRS <- ','',$buffer);
1155
-			    $buffer = str_replace('APRS -> ','',$buffer);
1154
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1155
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1156 1156
 			    echo $buffer."\n";
1157
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1157
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
1158 1158
 				$line = $APRS->parse($buffer);
1159 1159
 				//print_r($line);
1160 1160
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
@@ -1163,7 +1163,7 @@  discard block
 block discarded – undo
1163 1163
 				    $data = array();
1164 1164
 				    //print_r($line);
1165 1165
 				    if (isset($line['address'])) $data['hex'] = $line['address'];
1166
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1166
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1167 1167
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1168 1168
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1169 1169
 				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
@@ -1189,7 +1189,7 @@  discard block
 block discarded – undo
1189 1189
 				    $currentdate = date('Y-m-d H:i:s');
1190 1190
 				    $aprsdate = strtotime($data['datetime']);
1191 1191
 				    // Accept data if time <= system time + 20s
1192
-				    if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1192
+				    if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate) + 20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1193 1193
 					$send = $SI->add($data);
1194 1194
 				    } elseif (isset($line['stealth'])) {
1195 1195
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
@@ -1286,7 +1286,7 @@  discard block
 block discarded – undo
1286 1286
 				connect_all($sourceee);
1287 1287
 				$sourceee = array();
1288 1288
 				//connect_all($globalSources);
1289
-				$tt[$format]=0;
1289
+				$tt[$format] = 0;
1290 1290
 				break;
1291 1291
 			    }
1292 1292
 			}
@@ -1295,14 +1295,14 @@  discard block
 block discarded – undo
1295 1295
 	    } else {
1296 1296
 		$error = socket_strerror(socket_last_error());
1297 1297
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1298
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1298
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
1299 1299
 			if (isset($globalDebug)) echo "Restarting...\n";
1300 1300
 			// Restart the script if possible
1301 1301
 			if (is_array($sockets)) {
1302 1302
 			    if ($globalDebug) echo "Shutdown all sockets...";
1303 1303
 			    
1304 1304
 			    foreach ($sockets as $sock) {
1305
-				@socket_shutdown($sock,2);
1305
+				@socket_shutdown($sock, 2);
1306 1306
 				@socket_close($sock);
1307 1307
 			    }
1308 1308
 			    
Please login to merge, or discard this patch.