Completed
Push — master ( 04cc20...60bf6d )
by Yannick
08:30
created
scripts/daemon-spotter.php 1 patch
Spacing   +136 added lines, -136 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','nodaemon','idsource::'));
52
+$options = getopt('s::', array('source::', 'server', 'nodaemon', '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'])) {
@@ -65,27 +65,27 @@  discard block
 block discarded – undo
65 65
 else $id_source = 1;
66 66
 if (isset($globalServer) && $globalServer) {
67 67
     if ($globalDebug) echo "Using Server Mode\n";
68
-    $SI=new SpotterServer();
68
+    $SI = new SpotterServer();
69 69
 /*
70 70
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
71 71
     $SI = new adsb2aprs();
72 72
     $SI->connect();
73 73
 */
74
-} else $SI=new SpotterImport($Connection->db);
74
+} else $SI = new SpotterImport($Connection->db);
75 75
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
76 76
 if (isset($globalMarine) && $globalMarine) {
77 77
     $AIS = new AIS();
78 78
     $MI = new MarineImport($Connection->db);
79 79
 }
80 80
 //$APRS=new APRS($Connection->db);
81
-$SBS=new SBS();
82
-$ACARS=new ACARS($Connection->db);
83
-$Common=new Common();
81
+$SBS = new SBS();
82
+$ACARS = new ACARS($Connection->db);
83
+$Common = new Common();
84 84
 date_default_timezone_set('UTC');
85 85
 //$servertz = system('date +%Z');
86 86
 // signal handler - playing nice with sockets and dump1090
87 87
 if (function_exists('pcntl_fork')) {
88
-    pcntl_signal(SIGINT,  function() {
88
+    pcntl_signal(SIGINT, function() {
89 89
         global $sockets;
90 90
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
91 91
         die("Bye!\n");
@@ -101,35 +101,35 @@  discard block
 block discarded – undo
101 101
 
102 102
 function connect_all($hosts) {
103 103
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
104
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
104
+    global $sockets, $httpfeeds, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset, $context;
105 105
     $reset++;
106 106
     if ($globalDebug) echo 'Connect to all...'."\n";
107 107
     foreach ($hosts as $id => $value) {
108 108
 	$host = $value['host'];
109 109
 	$globalSources[$id]['last_exec'] = 0;
110 110
 	// Here we check type of source(s)
111
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
112
-            if (preg_match('/deltadb.txt$/i',$host)) {
111
+	if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
112
+            if (preg_match('/deltadb.txt$/i', $host)) {
113 113
         	//$formats[$id] = 'deltadbtxt';
114 114
         	$globalSources[$id]['format'] = 'deltadbtxt';
115 115
         	//$last_exec['deltadbtxt'] = 0;
116 116
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
117
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
117
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
118 118
         	//$formats[$id] = 'vatsimtxt';
119 119
         	$globalSources[$id]['format'] = 'vatsimtxt';
120 120
         	//$last_exec['vatsimtxt'] = 0;
121 121
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
122
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
122
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
123 123
         	//$formats[$id] = 'aircraftlistjson';
124 124
         	$globalSources[$id]['format'] = 'aircraftlistjson';
125 125
         	//$last_exec['aircraftlistjson'] = 0;
126 126
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
127
-    	    } else if (preg_match('/opensky/i',$host)) {
127
+    	    } else if (preg_match('/opensky/i', $host)) {
128 128
         	//$formats[$id] = 'aircraftlistjson';
129 129
         	$globalSources[$id]['format'] = 'opensky';
130 130
         	//$last_exec['aircraftlistjson'] = 0;
131 131
         	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
132
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
132
+    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i', $host)) {
133 133
         	//$formats[$id] = 'radarvirtueljson';
134 134
         	$globalSources[$id]['format'] = 'radarvirtueljson';
135 135
         	//$last_exec['radarvirtueljson'] = 0;
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
139 139
         	    exit(0);
140 140
         	}
141
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
141
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
142 142
         	//$formats[$id] = 'planeupdatefaa';
143 143
         	$globalSources[$id]['format'] = 'planeupdatefaa';
144 144
         	//$last_exec['planeupdatefaa'] = 0;
@@ -147,26 +147,26 @@  discard block
 block discarded – undo
147 147
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
148 148
         	    exit(0);
149 149
         	}
150
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
150
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
151 151
         	//$formats[$id] = 'phpvmacars';
152 152
         	$globalSources[$id]['format'] = 'phpvmacars';
153 153
         	//$last_exec['phpvmacars'] = 0;
154 154
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
155
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
155
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
156 156
         	//$formats[$id] = 'phpvmacars';
157 157
         	$globalSources[$id]['format'] = 'vam';
158 158
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
159
-            } else if (preg_match('/whazzup/i',$host)) {
159
+            } else if (preg_match('/whazzup/i', $host)) {
160 160
         	//$formats[$id] = 'whazzup';
161 161
         	$globalSources[$id]['format'] = 'whazzup';
162 162
         	//$last_exec['whazzup'] = 0;
163 163
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
164
-            } else if (preg_match('/recentpireps/i',$host)) {
164
+            } else if (preg_match('/recentpireps/i', $host)) {
165 165
         	//$formats[$id] = 'pirepsjson';
166 166
         	$globalSources[$id]['format'] = 'pirepsjson';
167 167
         	//$last_exec['pirepsjson'] = 0;
168 168
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
169
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
169
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
170 170
         	//$formats[$id] = 'fr24json';
171 171
         	$globalSources[$id]['format'] = 'fr24json';
172 172
         	//$last_exec['fr24json'] = 0;
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
176 176
         	    exit(0);
177 177
         	}
178
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
178
+            } else if (preg_match(':myshiptracking.com/:i', $host)) {
179 179
         	//$formats[$id] = 'fr24json';
180 180
         	$globalSources[$id]['format'] = 'myshiptracking';
181 181
         	//$last_exec['fr24json'] = 0;
@@ -185,22 +185,22 @@  discard block
 block discarded – undo
185 185
         	    exit(0);
186 186
         	}
187 187
             //} else if (preg_match('/10001/',$host)) {
188
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
188
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
189 189
         	//$formats[$id] = 'tsv';
190 190
         	$globalSources[$id]['format'] = 'tsv';
191 191
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
192 192
             }
193
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
193
+        } elseif (filter_var($host, FILTER_VALIDATE_URL)) {
194 194
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
195
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
195
+    		    $idf = fopen($globalSources[$id]['host'], 'r', false, $context);
196 196
     		    if ($idf !== false) {
197 197
     			$httpfeeds[$id] = $idf;
198 198
         		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
199 199
     		    }
200 200
     		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
201 201
     		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
202
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
203
-	    $hostport = explode(':',$host);
202
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
203
+	    $hostport = explode(':', $host);
204 204
 	    if (isset($hostport[1])) {
205 205
 		$port = $hostport[1];
206 206
 		$hostn = $hostport[0];
@@ -210,19 +210,19 @@  discard block
 block discarded – undo
210 210
 	    }
211 211
 	    $Common = new Common();
212 212
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
213
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
213
+        	$s = $Common->create_socket($hostn, $port, $errno, $errstr);
214 214
     	    } else {
215
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
215
+        	$s = $Common->create_socket_udp($hostn, $port, $errno, $errstr);
216 216
 	    }
217 217
 	    if ($s) {
218 218
     	        $sockets[$id] = $s;
219 219
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
220
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
220
+		    if (preg_match('/aprs/', $hostn) || $port == '10152' || $port == '14580') {
221 221
 			//$formats[$id] = 'aprs';
222 222
 			$globalSources[$id]['format'] = 'aprs';
223 223
 			//$aprs_connect = 0;
224 224
 			//$use_aprs = true;
225
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
225
+		    } elseif (preg_match('/pub-vrs/', $hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
226 226
 			$globalSources[$id]['format'] = 'vrstcp';
227 227
     		    } elseif ($port == '10001') {
228 228
         		//$formats[$id] = 'tsv';
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
262 262
 else $timeout = 20;
263 263
 $errno = '';
264
-$errstr='';
264
+$errstr = '';
265 265
 
266 266
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
267 267
 /* Initiate connections to all the hosts simultaneously */
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 //connect_all($globalSources);
270 270
 
271 271
 if (isset($globalProxy) && $globalProxy) {
272
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
272
+    $context = stream_context_create(array('http' => array('timeout' => $timeout, 'proxy' => $globalProxy, 'request_fulluri' => true)));
273 273
 } else {
274 274
     $context = stream_context_create(array('http' => array('timeout' => $timeout)));
275 275
 }
@@ -296,16 +296,16 @@  discard block
 block discarded – undo
296 296
 
297 297
 if ($use_aprs) {
298 298
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
299
-	$APRS=new APRS();
299
+	$APRS = new APRS();
300 300
 	$aprs_connect = 0;
301 301
 	$aprs_keep = 120;
302 302
 	$aprs_last_tx = time();
303 303
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
304
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
304
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
305 305
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
306
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
306
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
307 307
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
308
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
308
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
309 309
 	if ($aprs_full) $aprs_filter = '';
310 310
 	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
311 311
 	else $aprs_pass = '-1';
@@ -320,12 +320,12 @@  discard block
 block discarded – undo
320 320
 sleep(1);
321 321
 if ($globalDebug) echo "SCAN MODE \n\n";
322 322
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
323
-$endtime = time()+$globalCronEnd;
323
+$endtime = time() + $globalCronEnd;
324 324
 $i = 1;
325 325
 $tt = array();
326 326
 // Delete all ATC
327 327
 if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
328
-	$ATC=new ATC($Connection->db);
328
+	$ATC = new ATC($Connection->db);
329 329
 }
330 330
 if (!$globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
331 331
 	$ATC->deleteAll();
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 
334 334
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
335 335
 while ($i > 0) {
336
-    if (!$globalDaemon) $i = $endtime-time();
336
+    if (!$globalDaemon) $i = $endtime - time();
337 337
     // Delete old ATC
338 338
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
339 339
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 	}
349 349
 	if ($max != $globalMinFetch) {
350 350
 	    if ($globalDebug) echo 'Sleeping...'."\n";
351
-	    sleep($globalMinFetch-$max+2);
351
+	    sleep($globalMinFetch - $max + 2);
352 352
 	}
353 353
     }
354 354
 
@@ -361,8 +361,8 @@  discard block
 block discarded – undo
361 361
 	    //$buffer = $Common->getData($hosts[$id]);
362 362
 	    $buffer = $Common->getData($value['host']);
363 363
 	    if ($buffer != '') $reset = 0;
364
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
365
-	    $buffer = explode('\n',$buffer);
364
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
365
+	    $buffer = explode('\n', $buffer);
366 366
 	    foreach ($buffer as $line) {
367 367
     		if ($line != '' && count($line) > 7) {
368 368
     		    $line = explode(',', $line);
@@ -389,11 +389,11 @@  discard block
 block discarded – undo
389 389
     	    $last_exec[$id]['last'] = time();
390 390
 	} elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
391 391
 	    date_default_timezone_set('CET');
392
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
392
+	    $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host']));
393 393
 	    date_default_timezone_set('UTC');
394 394
 	    if ($buffer != '') $reset = 0;
395
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
396
-	    $buffer = explode('\n',$buffer);
395
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
396
+	    $buffer = explode('\n', $buffer);
397 397
 	    foreach ($buffer as $line) {
398 398
 		if ($line != '') {
399 399
 		    echo "'".$line."'\n";
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
 		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
412 412
 		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
413 413
 		    if (isset($ais_data['timestamp'])) {
414
-			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
414
+			$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
415 415
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
416 416
 			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
417 417
 			    $add = true;
@@ -434,12 +434,12 @@  discard block
 block discarded – undo
434 434
 	    $w = $e = null;
435 435
 	    
436 436
 	    if (isset($arr[$id])) {
437
-	    $nn = stream_select($arr,$w,$e,$timeout);
437
+	    $nn = stream_select($arr, $w, $e, $timeout);
438 438
 	    if ($nn > 0) {
439 439
 		foreach ($httpfeeds as $feed) {
440
-		    $buffer = stream_get_line($feed,2000,"\n");
441
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
442
-		    $buffer = explode('\n',$buffer);
440
+		    $buffer = stream_get_line($feed, 2000, "\n");
441
+		    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
442
+		    $buffer = explode('\n', $buffer);
443 443
 		    foreach ($buffer as $line) {
444 444
 			if ($line != '') {
445 445
 			    $ais_data = $AIS->parse_line(trim($line));
@@ -455,9 +455,9 @@  discard block
 block discarded – undo
455 455
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
456 456
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
457 457
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
458
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
458
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
459 459
 			    if (isset($ais_data['timestamp'])) {
460
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
460
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
461 461
 			    } else {
462 462
 				$data['datetime'] = date('Y-m-d H:i:s');
463 463
 			    }
@@ -471,10 +471,10 @@  discard block
 block discarded – undo
471 471
 		}
472 472
 	    }
473 473
 	} elseif ($value['format'] == 'myshiptracking' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
474
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
474
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
475 475
 	    if ($buffer != '') {
476 476
 		//echo $buffer;
477
-		$all_data = json_decode($buffer,true);
477
+		$all_data = json_decode($buffer, true);
478 478
 		//print_r($all_data);
479 479
 		if (isset($all_data[0]['DATA'])) {
480 480
 		foreach ($all_data[0]['DATA'] as $line) {
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
 			//    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
490 490
 			$data['imo'] = $line['IMO'];
491 491
 			//$data['arrival_code'] = $ais_data['destination'];
492
-			$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
492
+			$data['datetime'] = date('Y-m-d H:i:s', $line['T']);
493 493
 			$data['format_source'] = 'myshiptracking';
494 494
 			$data['id_source'] = $id_source;
495 495
 			$MI->add($data);
@@ -501,9 +501,9 @@  discard block
 block discarded – undo
501 501
 	    }
502 502
     	    $last_exec[$id]['last'] = time();
503 503
 	} elseif ($value['format'] == 'boatbeaconapp' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
504
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
504
+	    $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host']));
505 505
 	    if ($buffer != '') {
506
-		$all_data = json_decode($buffer,true);
506
+		$all_data = json_decode($buffer, true);
507 507
 		if (isset($all_data[0]['mmsi'])) {
508 508
 		    foreach ($all_data as $line) {
509 509
 			if ($line != '') {
@@ -530,27 +530,27 @@  discard block
 block discarded – undo
530 530
     	    $last_exec[$id]['last'] = time();
531 531
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
532 532
 	    echo 'download...';
533
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
533
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
534 534
 	    echo 'done !'."\n";
535 535
 	    if ($buffer != '') $reset = 0;
536
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
537
-	    $buffer = explode('\n',$buffer);
536
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
537
+	    $buffer = explode('\n', $buffer);
538 538
 	    foreach ($buffer as $line) {
539 539
 		if ($line != '') {
540 540
 		    $data = array();
541
-		    $data['mmsi'] = (int)substr($line,0,9);
542
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
541
+		    $data['mmsi'] = (int) substr($line, 0, 9);
542
+		    $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10));
543 543
 		    //$data['status'] = substr($line,21,2);
544 544
 		    //$data['type'] = substr($line,24,3);
545
-		    $data['latitude'] = substr($line,29,9);
546
-		    $data['longitude'] = substr($line,41,9);
547
-		    $data['speed'] = round(substr($line,51,5));
545
+		    $data['latitude'] = substr($line, 29, 9);
546
+		    $data['longitude'] = substr($line, 41, 9);
547
+		    $data['speed'] = round(substr($line, 51, 5));
548 548
 		    //$data['course'] = substr($line,57,5);
549
-		    $data['heading'] = round(substr($line,63,3));
549
+		    $data['heading'] = round(substr($line, 63, 3));
550 550
 		    //$data['draft'] = substr($line,67,4);
551 551
 		    //$data['length'] = substr($line,72,3);
552 552
 		    //$data['beam'] = substr($line,76,2);
553
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
553
+		    $data['ident'] = trim(utf8_encode(substr($line, 79, 20)));
554 554
 		    //$data['callsign'] = trim(substr($line,100,7);
555 555
 		    //$data['dest'] = substr($line,108,20);
556 556
 		    //$data['etaDate'] = substr($line,129,5);
@@ -568,8 +568,8 @@  discard block
 block discarded – undo
568 568
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
569 569
 	    //$buffer = $Common->getData($hosts[$id]);
570 570
 	    $buffer = $Common->getData($value['host']);
571
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
572
-	    $buffer = explode('\n',$buffer);
571
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
572
+	    $buffer = explode('\n', $buffer);
573 573
 	    $reset = 0;
574 574
 	    foreach ($buffer as $line) {
575 575
     		if ($line != '') {
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
581 581
 			$data['pilot_id'] = $line[1];
582 582
 			$data['pilot_name'] = $line[2];
583
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
583
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
584 584
 			$data['ident'] = $line[0]; // ident
585 585
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
586 586
 			$data['speed'] = $line[8]; // speed
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
597 597
 			//if (isset($line[37])) $data['last_update'] = $line[37];
598 598
 		        $data['departure_airport_icao'] = $line[11];
599
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
599
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
600 600
 		        $data['arrival_airport_icao'] = $line[13];
601 601
 			$data['frequency'] = $line[4];
602 602
 			$data['type'] = $line[18];
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
     			$data['id_source'] = $id_source;
606 606
 	    		//$data['arrival_airport_time'] = ;
607 607
 	    		if ($line[9] != '') {
608
-	    		    $aircraft_data = explode('/',$line[9]);
608
+	    		    $aircraft_data = explode('/', $line[9]);
609 609
 	    		    if (isset($aircraft_data[1])) {
610 610
 	    			$data['aircraft_icao'] = $aircraft_data[1];
611 611
 	    		    }
@@ -619,9 +619,9 @@  discard block
 block discarded – undo
619 619
     			if ($line[3] == 'PILOT') $SI->add($data);
620 620
 			elseif ($line[3] == 'ATC') {
621 621
 				//print_r($data);
622
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
623
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
624
-				$typec = substr($data['ident'],-3);
622
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
623
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
624
+				$typec = substr($data['ident'], -3);
625 625
 				if ($typec == 'APP') $data['type'] = 'Approach';
626 626
 				elseif ($typec == 'TWR') $data['type'] = 'Tower';
627 627
 				elseif ($typec == 'OBS') $data['type'] = 'Observer';
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
 				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
633 633
 				elseif ($data['type'] == '') $data['type'] = 'Observer';
634 634
 				if (!isset($data['source_name'])) $data['source_name'] = '';
635
-				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']);
635
+				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']);
636 636
 			}
637 637
     			unset($data);
638 638
     		    }
@@ -643,9 +643,9 @@  discard block
 block discarded – undo
643 643
     	    $last_exec[$id]['last'] = time();
644 644
     	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
645 645
     	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
646
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
646
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
647 647
 	    if ($buffer != '') {
648
-	    $all_data = json_decode($buffer,true);
648
+	    $all_data = json_decode($buffer, true);
649 649
 	    if (isset($all_data['acList'])) {
650 650
 		$reset = 0;
651 651
 		foreach ($all_data['acList'] as $line) {
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
     	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
702 702
     	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
703 703
 	    $buffer = $Common->getData($value['host']);
704
-	    $all_data = json_decode($buffer,true);
704
+	    $all_data = json_decode($buffer, true);
705 705
 	    if (isset($all_data['planes'])) {
706 706
 		$reset = 0;
707 707
 		foreach ($all_data['planes'] as $key => $line) {
@@ -718,12 +718,12 @@  discard block
 block discarded – undo
718 718
 		    $data['emergency'] = ''; // emergency
719 719
 		    $data['registration'] = $line[2];
720 720
 		    $data['aircraft_icao'] = $line[0];
721
-		    $deparr = explode('-',$line[1]);
721
+		    $deparr = explode('-', $line[1]);
722 722
 		    if (count($deparr) == 2) {
723 723
 			$data['departure_airport_icao'] = $deparr[0];
724 724
 			$data['arrival_airport_icao'] = $deparr[1];
725 725
 		    }
726
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
726
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
727 727
 	    	    $data['format_source'] = 'planeupdatefaa';
728 728
     		    $data['id_source'] = $id_source;
729 729
 		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -735,7 +735,7 @@  discard block
 block discarded – undo
735 735
     	    $last_exec[$id]['last'] = time();
736 736
     	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
737 737
 	    $buffer = $Common->getData($value['host']);
738
-	    $all_data = json_decode($buffer,true);
738
+	    $all_data = json_decode($buffer, true);
739 739
 	    if (isset($all_data['states'])) {
740 740
 		$reset = 0;
741 741
 		foreach ($all_data['states'] as $key => $line) {
@@ -752,7 +752,7 @@  discard block
 block discarded – undo
752 752
 		    //$data['emergency'] = ''; // emergency
753 753
 		    //$data['registration'] = $line[2];
754 754
 		    //$data['aircraft_icao'] = $line[0];
755
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
755
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
756 756
 	    	    $data['format_source'] = 'opensky';
757 757
     		    $data['id_source'] = $id_source;
758 758
 		    $SI->add($data);
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
     	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
766 766
 	    //$buffer = $Common->getData($hosts[$id]);
767 767
 	    $buffer = $Common->getData($value['host']);
768
-	    $all_data = json_decode($buffer,true);
768
+	    $all_data = json_decode($buffer, true);
769 769
 	    if (!empty($all_data)) $reset = 0;
770 770
 	    foreach ($all_data as $key => $line) {
771 771
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -797,11 +797,11 @@  discard block
 block discarded – undo
797 797
     	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
798 798
     	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
799 799
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
800
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
800
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
801 801
 	    //echo $buffer;
802
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
803
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
804
-	    $all_data = json_decode($buffer,true);
802
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
803
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
804
+	    $all_data = json_decode($buffer, true);
805 805
 	    if (json_last_error() != JSON_ERROR_NONE) {
806 806
 		die(json_last_error_msg());
807 807
 	    }
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
 			//$data['departure_airport_iata'] = $line[11];
825 825
 			//$data['arrival_airport_iata'] = $line[12];
826 826
 	    		//$data['emergency'] = ''; // emergency
827
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
827
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
828 828
 	    		$data['format_source'] = 'radarvirtueljson';
829 829
     			$data['id_source'] = $id_source;
830 830
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
@@ -839,14 +839,14 @@  discard block
 block discarded – undo
839 839
     	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
840 840
 	    //$buffer = $Common->getData($hosts[$id]);
841 841
 	    $buffer = $Common->getData($value['host'].'?'.time());
842
-	    $all_data = json_decode(utf8_encode($buffer),true);
842
+	    $all_data = json_decode(utf8_encode($buffer), true);
843 843
 	    
844 844
 	    if (isset($all_data['pireps'])) {
845 845
 		$reset = 0;
846 846
 	        foreach ($all_data['pireps'] as $line) {
847 847
 		    $data = array();
848 848
 		    $data['id'] = $line['id'];
849
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
849
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
850 850
 		    $data['ident'] = $line['callsign']; // ident
851 851
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
852 852
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -875,9 +875,9 @@  discard block
 block discarded – undo
875 875
 			$SI->add($data);
876 876
 		    //    print_r($data);
877 877
     		    } elseif ($line['icon'] == 'ct') {
878
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
879
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
880
-			$typec = substr($data['ident'],-3);
878
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
879
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
880
+			$typec = substr($data['ident'], -3);
881 881
 			$data['type'] = '';
882 882
 			if ($typec == 'APP') $data['type'] = 'Approach';
883 883
 			elseif ($typec == 'TWR') $data['type'] = 'Tower';
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
 			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
889 889
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
890 890
 			else $data['type'] = 'Observer';
891
-			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']);
891
+			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']);
892 892
 		    }
893 893
 		    unset($data);
894 894
 		}
@@ -900,14 +900,14 @@  discard block
 block discarded – undo
900 900
 	    //$buffer = $Common->getData($hosts[$id]);
901 901
 	    if ($globalDebug) echo 'Get Data...'."\n";
902 902
 	    $buffer = $Common->getData($value['host']);
903
-	    $all_data = json_decode($buffer,true);
903
+	    $all_data = json_decode($buffer, true);
904 904
 	    if ($buffer != '' && is_array($all_data)) {
905 905
 		$reset = 0;
906 906
 		foreach ($all_data as $line) {
907 907
 	    	    $data = array();
908 908
 	    	    //$data['id'] = $line['id']; // id not usable
909 909
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
910
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
910
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
911 911
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
912 912
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
913 913
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -930,12 +930,12 @@  discard block
 block discarded – undo
930 930
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
931 931
 		    if (isset($line['aircraftname'])) {
932 932
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
933
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
934
-	    		$aircraft_data = explode('-',$line['aircraftname']);
933
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
934
+	    		$aircraft_data = explode('-', $line['aircraftname']);
935 935
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
936 936
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
937 937
 	    		else {
938
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
938
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
939 939
 	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
940 940
 	    		    else $data['aircraft_icao'] = $line['aircraftname'];
941 941
 	    		}
@@ -957,14 +957,14 @@  discard block
 block discarded – undo
957 957
 	    //$buffer = $Common->getData($hosts[$id]);
958 958
 	    if ($globalDebug) echo 'Get Data...'."\n";
959 959
 	    $buffer = $Common->getData($value['host']);
960
-	    $all_data = json_decode($buffer,true);
960
+	    $all_data = json_decode($buffer, true);
961 961
 	    if ($buffer != '' && is_array($all_data)) {
962 962
 		$reset = 0;
963 963
 		foreach ($all_data as $line) {
964 964
 	    	    $data = array();
965 965
 	    	    //$data['id'] = $line['id']; // id not usable
966 966
 	    	    $data['id'] = trim($line['flight_id']);
967
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
967
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
968 968
 	    	    $data['pilot_name'] = $line['pilot_name'];
969 969
 	    	    $data['pilot_id'] = $line['pilot_id'];
970 970
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -1015,9 +1015,9 @@  discard block
 block discarded – undo
1015 1015
 		    //$value = $formats[$nb];
1016 1016
 		    $format = $globalSources[$nb]['format'];
1017 1017
         	    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3' || $format == 'vrstcp') {
1018
-        		$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
1018
+        		$buffer = socket_read($r, 6000, PHP_NORMAL_READ);
1019 1019
         	    } else {
1020
-	    	        $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1020
+	    	        $az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
1021 1021
 	    	    }
1022 1022
         	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1023 1023
         	    //echo $buffer."\n";
@@ -1026,8 +1026,8 @@  discard block
 block discarded – undo
1026 1026
 		    $error = false;
1027 1027
 		    //$SI::del();
1028 1028
 		    if ($format == 'vrstcp') {
1029
-			$buffer = explode('},{',$buffer);
1030
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1029
+			$buffer = explode('},{', $buffer);
1030
+		    } else $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
1031 1031
 		    // SBS format is CSV format
1032 1032
 		    if ($buffer != '') {
1033 1033
 			$tt[$format] = 0;
@@ -1059,10 +1059,10 @@  discard block
 block discarded – undo
1059 1059
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1060 1060
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1061 1061
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1062
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1062
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1063 1063
 
1064 1064
 			    if (isset($ais_data['timestamp'])) {
1065
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1065
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1066 1066
 			    } else {
1067 1067
 				$data['datetime'] = date('Y-m-d H:i:s');
1068 1068
 			    }
@@ -1073,10 +1073,10 @@  discard block
 block discarded – undo
1073 1073
                         } elseif ($format == 'flightgearsp') {
1074 1074
                     	    //echo $buffer."\n";
1075 1075
                     	    if (strlen($buffer) > 5) {
1076
-				$line = explode(',',$buffer);
1076
+				$line = explode(',', $buffer);
1077 1077
 				$data = array();
1078 1078
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1079
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1079
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1080 1080
 				$data['ident'] = $line[6];
1081 1081
 				$data['aircraft_name'] = $line[7];
1082 1082
 				$data['longitude'] = $line[1];
@@ -1087,21 +1087,21 @@  discard block
 block discarded – undo
1087 1087
 				$data['datetime'] = date('Y-m-d H:i:s');
1088 1088
 				$data['format_source'] = 'flightgearsp';
1089 1089
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1090
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1090
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1091 1091
 			    }
1092 1092
                         } elseif ($format == 'acars') {
1093 1093
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1094 1094
 			    $ACARS->add(trim($buffer));
1095
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1095
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1096 1096
 			    $ACARS->deleteLiveAcarsData();
1097 1097
 			} elseif ($format == 'flightgearmp') {
1098
-			    if (substr($buffer,0,1) != '#') {
1098
+			    if (substr($buffer, 0, 1) != '#') {
1099 1099
 				$data = array();
1100 1100
 				//echo $buffer."\n";
1101
-				$line = explode(' ',$buffer);
1101
+				$line = explode(' ', $buffer);
1102 1102
 				if (count($line) == 11) {
1103
-				    $userserver = explode('@',$line[0]);
1104
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1103
+				    $userserver = explode('@', $line[0]);
1104
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1105 1105
 				    $data['ident'] = $userserver[0];
1106 1106
 				    $data['registration'] = $userserver[0];
1107 1107
 				    $data['latitude'] = $line[4];
@@ -1109,8 +1109,8 @@  discard block
 block discarded – undo
1109 1109
 				    $data['altitude'] = $line[6];
1110 1110
 				    $data['datetime'] = date('Y-m-d H:i:s');
1111 1111
 				    $aircraft_type = $line[10];
1112
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1113
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1112
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1113
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1114 1114
 				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1115 1115
 				}
1116 1116
 			    }
@@ -1118,8 +1118,8 @@  discard block
 block discarded – undo
1118 1118
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1119 1119
 			    die;
1120 1120
 			} elseif ($format == 'vrstcp') {
1121
-			    foreach($buffer as $all_data) {
1122
-				$line = json_decode('{'.$all_data.'}',true);
1121
+			    foreach ($buffer as $all_data) {
1122
+				$line = json_decode('{'.$all_data.'}', true);
1123 1123
 				$data = array();
1124 1124
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1125 1125
 				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1144,16 +1144,16 @@  discard block
 block discarded – undo
1144 1144
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1145 1145
 				unset($data);
1146 1146
 			    }
1147
-			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1147
+			} elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') {
1148 1148
 			    $line = explode("\t", $buffer);
1149
-			    for($k = 0; $k < count($line); $k=$k+2) {
1149
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1150 1150
 				$key = $line[$k];
1151
-			        $lined[$key] = $line[$k+1];
1151
+			        $lined[$key] = $line[$k + 1];
1152 1152
 			    }
1153 1153
     			    if (count($lined) > 3) {
1154 1154
     				$data['hex'] = $lined['hexid'];
1155 1155
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1156
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1156
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1157 1157
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1158 1158
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1159 1159
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1171,22 +1171,22 @@  discard block
 block discarded – undo
1171 1171
     			    } else $error = true;
1172 1172
 			} elseif ($format == 'aprs' && $use_aprs) {
1173 1173
 			    if ($aprs_connect == 0) {
1174
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1174
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
1175 1175
 				$aprs_connect = 1;
1176 1176
 			    }
1177 1177
 			    
1178
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1178
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
1179 1179
 				$aprs_last_tx = time();
1180 1180
 				$data_aprs = "# Keep alive";
1181
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1181
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1182 1182
 			    }
1183 1183
 			    
1184 1184
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1185 1185
 			    //echo 'APRS data : '.$buffer."\n";
1186
-			    $buffer = str_replace('APRS <- ','',$buffer);
1187
-			    $buffer = str_replace('APRS -> ','',$buffer);
1186
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1187
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1188 1188
 			    echo $buffer."\n";
1189
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1189
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
1190 1190
 				$line = $APRS->parse($buffer);
1191 1191
 				//print_r($line);
1192 1192
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
@@ -1195,7 +1195,7 @@  discard block
 block discarded – undo
1195 1195
 				    $data = array();
1196 1196
 				    //print_r($line);
1197 1197
 				    if (isset($line['address'])) $data['hex'] = $line['address'];
1198
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1198
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1199 1199
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1200 1200
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1201 1201
 				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
@@ -1221,7 +1221,7 @@  discard block
 block discarded – undo
1221 1221
 				    $currentdate = date('Y-m-d H:i:s');
1222 1222
 				    $aprsdate = strtotime($data['datetime']);
1223 1223
 				    // Accept data if time <= system time + 20s
1224
-				    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'])))) {
1224
+				    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'])))) {
1225 1225
 					$send = $SI->add($data);
1226 1226
 				    } elseif (isset($line['stealth'])) {
1227 1227
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
@@ -1318,7 +1318,7 @@  discard block
 block discarded – undo
1318 1318
 				connect_all($sourceee);
1319 1319
 				$sourceee = array();
1320 1320
 				//connect_all($globalSources);
1321
-				$tt[$format]=0;
1321
+				$tt[$format] = 0;
1322 1322
 				break;
1323 1323
 			    }
1324 1324
 			}
@@ -1327,14 +1327,14 @@  discard block
 block discarded – undo
1327 1327
 	    } else {
1328 1328
 		$error = socket_strerror(socket_last_error());
1329 1329
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1330
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1330
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
1331 1331
 			if (isset($globalDebug)) echo "Restarting...\n";
1332 1332
 			// Restart the script if possible
1333 1333
 			if (is_array($sockets)) {
1334 1334
 			    if ($globalDebug) echo "Shutdown all sockets...";
1335 1335
 			    
1336 1336
 			    foreach ($sockets as $sock) {
1337
-				@socket_shutdown($sock,2);
1337
+				@socket_shutdown($sock, 2);
1338 1338
 				@socket_close($sock);
1339 1339
 			    }
1340 1340
 			    
Please login to merge, or discard this patch.
require/class.SpotterImport.php 1 patch
Spacing   +134 added lines, -134 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,21 +822,21 @@  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'])) {
826
-				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')));
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
+				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')));
827 827
 				$timeelapsed = microtime(true);
828 828
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
829 829
 					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
830 830
 					$SpotterLive = new SpotterLive($this->db);
831
-					$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
+					$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']);
832 832
 					$SpotterLive->db = null;
833 833
 					if ($globalDebug) echo $result."\n";
834 834
 				}
835 835
 				if (isset($globalServerAPRS) && $globalServerAPRS) {
836
-					$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
+					$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']);
837 837
 				}
838 838
 				$this->all_flights[$id]['putinarchive'] = false;
839
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
839
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
840 840
 
841 841
 				// Put statistics in $this->stats variable
842 842
 				//if ($line['format_source'] != 'aprs') {
@@ -854,19 +854,19 @@  discard block
 block discarded – undo
854 854
 							$latitude = $globalCenterLatitude;
855 855
 							$longitude = $globalCenterLongitude;
856 856
 						}
857
-						$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude);
857
+						$this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude);
858 858
 					} else {
859 859
 						$latitude = $this->source_location[$source]['latitude'];
860 860
 						$longitude = $this->source_location[$source]['longitude'];
861 861
 					}
862
-					$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
862
+					$stats_heading = $Common->getHeading($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
863 863
 					//$stats_heading = $stats_heading%22.5;
864 864
 					$stats_heading = round($stats_heading/22.5);
865
-					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
865
+					$stats_distance = $Common->distance($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
866 866
 					$current_date = date('Y-m-d');
867 867
 					if ($stats_heading == 16) $stats_heading = 0;
868 868
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
869
-						for ($i=0;$i<=15;$i++) {
869
+						for ($i = 0; $i <= 15; $i++) {
870 870
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
871 871
 						}
872 872
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
@@ -881,9 +881,9 @@  discard block
 block discarded – undo
881 881
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
882 882
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
883 883
 						    end($this->stats[$current_date][$source]['hist']);
884
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
884
+						    $mini = key($this->stats[$current_date][$source]['hist']) + 10;
885 885
 						} else $mini = 0;
886
-						for ($i=$mini;$i<=$distance;$i+=10) {
886
+						for ($i = $mini; $i <= $distance; $i += 10) {
887 887
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
888 888
 						}
889 889
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
@@ -895,7 +895,7 @@  discard block
 block discarded – undo
895 895
 				$this->all_flights[$id]['lastupdate'] = time();
896 896
 				if ($this->all_flights[$id]['putinarchive']) $send = true;
897 897
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
898
-			} 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
+			} 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";
899 899
 			//$this->del();
900 900
 			
901 901
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
Please login to merge, or discard this patch.