Completed
Push — master ( daf7fb...178285 )
by Yannick
30:35
created
scripts/daemon-spotter.php 3 patches
Spacing   +183 added lines, -183 removed lines patch added patch discarded remove patch
@@ -50,20 +50,20 @@  discard block
 block discarded – undo
50 50
 	    die;
51 51
 	}
52 52
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
53
-	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
53
+	$globalSources[] = array('host' => $globalSBS1Host, 'port' => $globalSBS1Port);
54 54
     }
55 55
 }
56 56
 
57
-$options = getopt('s::',array('source::','server','nodaemon','idsource::','aprsserverssid::','aprsserverpass::','aprsserverhost::','aprsserverport::','format::','noaprsserver','enable-aircraft','disable-aircraft','enable-tracker','disable-tracker','enable-marine','disable-marine'));
57
+$options = getopt('s::', array('source::', 'server', 'nodaemon', 'idsource::', 'aprsserverssid::', 'aprsserverpass::', 'aprsserverhost::', 'aprsserverport::', 'format::', 'noaprsserver', 'enable-aircraft', 'disable-aircraft', 'enable-tracker', 'disable-tracker', 'enable-marine', 'disable-marine'));
58 58
 //if (isset($options['s'])) $hosts = array($options['s']);
59 59
 //elseif (isset($options['source'])) $hosts = array($options['source']);
60 60
 if (isset($options['s'])) {
61 61
     $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
62
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'], 'format' => $options['format']);
63 63
     else $globalSources[] = array('host' => $options['s']);
64 64
 } elseif (isset($options['source'])) {
65 65
     $globalSources = array();
66
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
66
+    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'], 'format' => $options['format']);
67 67
     else $globalSources[] = array('host' => $options['source']);
68 68
 }
69 69
 if (isset($options['aprsserverhost'])) {
@@ -104,13 +104,13 @@  discard block
 block discarded – undo
104 104
 else $id_source = 1;
105 105
 if (isset($globalServer) && $globalServer) {
106 106
     if ($globalDebug) echo "Using Server Mode\n";
107
-    $SI=new SpotterServer();
107
+    $SI = new SpotterServer();
108 108
 /*
109 109
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
110 110
     $SI = new adsb2aprs();
111 111
     $SI->connect();
112 112
 */
113
-} else $SI=new SpotterImport($Connection->db);
113
+} else $SI = new SpotterImport($Connection->db);
114 114
 
115 115
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
116 116
 if (isset($globalMarine) && $globalMarine) {
@@ -124,17 +124,17 @@  discard block
 block discarded – undo
124 124
     $MI = new MarineImport($Connection->db);
125 125
 }
126 126
 //$APRS=new APRS($Connection->db);
127
-$SBS=new SBS();
127
+$SBS = new SBS();
128 128
 if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
129
-	$ACARS=new ACARS($Connection->db,true);
130
-	$Source=new Source($Connection->db);
129
+	$ACARS = new ACARS($Connection->db, true);
130
+	$Source = new Source($Connection->db);
131 131
 }
132
-$Common=new Common();
132
+$Common = new Common();
133 133
 date_default_timezone_set('UTC');
134 134
 //$servertz = system('date +%Z');
135 135
 // signal handler - playing nice with sockets and dump1090
136 136
 if (function_exists('pcntl_fork')) {
137
-    pcntl_signal(SIGINT,  function() {
137
+    pcntl_signal(SIGINT, function() {
138 138
         global $sockets;
139 139
         echo "\n\nctrl-c or kill signal received. Tidying up ... ";
140 140
         die("Bye!\n");
@@ -150,30 +150,30 @@  discard block
 block discarded – undo
150 150
 
151 151
 function connect_all($hosts) {
152 152
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
153
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
153
+    global $sockets, $httpfeeds, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset, $context;
154 154
     $reset++;
155 155
     if ($globalDebug) echo 'Connect to all...'."\n";
156 156
     foreach ($hosts as $id => $value) {
157 157
 	$host = $value['host'];
158 158
 	$globalSources[$id]['last_exec'] = 0;
159 159
 	// Here we check type of source(s)
160
-	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
161
-            if (preg_match('/deltadb.txt$/i',$host)) {
160
+	if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
161
+            if (preg_match('/deltadb.txt$/i', $host)) {
162 162
         	//$formats[$id] = 'deltadbtxt';
163 163
         	$globalSources[$id]['format'] = 'deltadbtxt';
164 164
         	//$last_exec['deltadbtxt'] = 0;
165 165
         	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
166
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
166
+            } else if (preg_match('/vatsim-data.txt$/i', $host)) {
167 167
         	//$formats[$id] = 'vatsimtxt';
168 168
         	$globalSources[$id]['format'] = 'vatsimtxt';
169 169
         	//$last_exec['vatsimtxt'] = 0;
170 170
         	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
171
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
171
+    	    } else if (preg_match('/aircraftlist.json$/i', $host)) {
172 172
         	//$formats[$id] = 'aircraftlistjson';
173 173
         	$globalSources[$id]['format'] = 'aircraftlistjson';
174 174
         	//$last_exec['aircraftlistjson'] = 0;
175 175
         	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
176
-    	    } else if (preg_match('/opensky/i',$host)) {
176
+    	    } else if (preg_match('/opensky/i', $host)) {
177 177
         	//$formats[$id] = 'aircraftlistjson';
178 178
         	$globalSources[$id]['format'] = 'opensky';
179 179
         	//$last_exec['aircraftlistjson'] = 0;
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
         	    exit(0);
191 191
         	}
192 192
     	    */
193
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
193
+    	    } else if (preg_match('/planeUpdateFAA.php$/i', $host)) {
194 194
         	//$formats[$id] = 'planeupdatefaa';
195 195
         	$globalSources[$id]['format'] = 'planeupdatefaa';
196 196
         	//$last_exec['planeupdatefaa'] = 0;
@@ -199,32 +199,32 @@  discard block
 block discarded – undo
199 199
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
200 200
         	    exit(0);
201 201
         	}
202
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
202
+            } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) {
203 203
         	//$formats[$id] = 'phpvmacars';
204 204
         	$globalSources[$id]['format'] = 'phpvmacars';
205 205
         	//$last_exec['phpvmacars'] = 0;
206 206
         	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
207
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
207
+            } else if (preg_match('/VAM-json.php$/i', $host)) {
208 208
         	//$formats[$id] = 'phpvmacars';
209 209
         	$globalSources[$id]['format'] = 'vam';
210 210
         	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
211
-            } else if (preg_match('/whazzup/i',$host)) {
211
+            } else if (preg_match('/whazzup/i', $host)) {
212 212
         	//$formats[$id] = 'whazzup';
213 213
         	$globalSources[$id]['format'] = 'whazzup';
214 214
         	//$last_exec['whazzup'] = 0;
215 215
         	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
216
-            } else if (preg_match('/blitzortung/i',$host)) {
216
+            } else if (preg_match('/blitzortung/i', $host)) {
217 217
         	$globalSources[$id]['format'] = 'blitzortung';
218 218
         	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
219
-            } else if (preg_match('/airwhere/i',$host)) {
219
+            } else if (preg_match('/airwhere/i', $host)) {
220 220
         	$globalSources[$id]['format'] = 'airwhere';
221 221
         	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
222
-            } else if (preg_match('/recentpireps/i',$host)) {
222
+            } else if (preg_match('/recentpireps/i', $host)) {
223 223
         	//$formats[$id] = 'pirepsjson';
224 224
         	$globalSources[$id]['format'] = 'pirepsjson';
225 225
         	//$last_exec['pirepsjson'] = 0;
226 226
         	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
227
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
227
+            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) {
228 228
         	//$formats[$id] = 'fr24json';
229 229
         	$globalSources[$id]['format'] = 'fr24json';
230 230
         	//$last_exec['fr24json'] = 0;
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
234 234
         	    exit(0);
235 235
         	}
236
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
236
+            } else if (preg_match(':myshiptracking.com/:i', $host)) {
237 237
         	//$formats[$id] = 'fr24json';
238 238
         	$globalSources[$id]['format'] = 'myshiptracking';
239 239
         	//$last_exec['fr24json'] = 0;
@@ -243,22 +243,22 @@  discard block
 block discarded – undo
243 243
         	    exit(0);
244 244
         	}
245 245
             //} else if (preg_match('/10001/',$host)) {
246
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
246
+            } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
247 247
         	//$formats[$id] = 'tsv';
248 248
         	$globalSources[$id]['format'] = 'tsv';
249 249
         	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
250 250
             }
251
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
251
+        } elseif (filter_var($host, FILTER_VALIDATE_URL)) {
252 252
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
253
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
253
+    		    $idf = fopen($globalSources[$id]['host'], 'r', false, $context);
254 254
     		    if ($idf !== false) {
255 255
     			$httpfeeds[$id] = $idf;
256 256
         		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
257 257
     		    }
258 258
     		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
259 259
     		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
260
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
261
-	    $hostport = explode(':',$host);
260
+        } elseif (!filter_var($host, FILTER_VALIDATE_URL)) {
261
+	    $hostport = explode(':', $host);
262 262
 	    if (isset($hostport[1])) {
263 263
 		$port = $hostport[1];
264 264
 		$hostn = $hostport[0];
@@ -268,19 +268,19 @@  discard block
 block discarded – undo
268 268
 	    }
269 269
 	    $Common = new Common();
270 270
 	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
271
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
271
+        	$s = $Common->create_socket($hostn, $port, $errno, $errstr);
272 272
     	    } else {
273
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
273
+        	$s = $Common->create_socket_udp($hostn, $port, $errno, $errstr);
274 274
 	    }
275 275
 	    if ($s) {
276 276
     	        $sockets[$id] = $s;
277 277
     	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
278
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
278
+		    if (preg_match('/aprs/', $hostn) || $port == '10152' || $port == '14580') {
279 279
 			//$formats[$id] = 'aprs';
280 280
 			$globalSources[$id]['format'] = 'aprs';
281 281
 			//$aprs_connect = 0;
282 282
 			//$use_aprs = true;
283
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
283
+		    } elseif (preg_match('/pub-vrs/', $hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
284 284
 			$globalSources[$id]['format'] = 'vrstcp';
285 285
     		    } elseif ($port == '10001') {
286 286
         		//$formats[$id] = 'tsv';
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
320 320
 else $timeout = 20;
321 321
 $errno = '';
322
-$errstr='';
322
+$errstr = '';
323 323
 
324 324
 if (!isset($globalDaemon)) $globalDaemon = TRUE;
325 325
 /* Initiate connections to all the hosts simultaneously */
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 //connect_all($globalSources);
328 328
 
329 329
 if (isset($globalProxy) && $globalProxy) {
330
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
330
+    $context = stream_context_create(array('http' => array('timeout' => $timeout, 'proxy' => $globalProxy, 'request_fulluri' => true)));
331 331
 } else {
332 332
     $context = stream_context_create(array('http' => array('timeout' => $timeout)));
333 333
 }
@@ -357,16 +357,16 @@  discard block
 block discarded – undo
357 357
 
358 358
 if ($use_aprs) {
359 359
 	require_once(dirname(__FILE__).'/../require/class.APRS.php');
360
-	$APRS=new APRS();
360
+	$APRS = new APRS();
361 361
 	$aprs_connect = 0;
362 362
 	$aprs_keep = 120;
363 363
 	$aprs_last_tx = time();
364 364
 	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
365
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
365
+	else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName);
366 366
 	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
367
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
367
+	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8);
368 368
 	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
369
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
369
+	else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
370 370
 	if ($aprs_full) $aprs_filter = '';
371 371
 	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
372 372
 	else $aprs_pass = '-1';
@@ -380,12 +380,12 @@  discard block
 block discarded – undo
380 380
 sleep(1);
381 381
 if ($globalDebug) echo "SCAN MODE \n\n";
382 382
 if (!isset($globalCronEnd)) $globalCronEnd = 60;
383
-$endtime = time()+$globalCronEnd;
383
+$endtime = time() + $globalCronEnd;
384 384
 $i = 1;
385 385
 $tt = array();
386 386
 // Delete all ATC
387 387
 if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) {
388
-	$ATC=new ATC($Connection->db);
388
+	$ATC = new ATC($Connection->db);
389 389
 }
390 390
 if (!$globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
391 391
 	$ATC->deleteAll();
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
 
394 394
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
395 395
 while ($i > 0) {
396
-    if (!$globalDaemon) $i = $endtime-time();
396
+    if (!$globalDaemon) $i = $endtime - time();
397 397
     // Delete old ATC
398 398
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
399 399
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 	}
408 408
 	if ($max != $globalMinFetch) {
409 409
 	    if ($globalDebug) echo 'Sleeping...'."\n";
410
-	    sleep($globalMinFetch-$max+2);
410
+	    sleep($globalMinFetch - $max + 2);
411 411
 	}
412 412
     }
413 413
 
@@ -426,8 +426,8 @@  discard block
 block discarded – undo
426 426
 	    //$buffer = $Common->getData($hosts[$id]);
427 427
 	    $buffer = $Common->getData($value['host']);
428 428
 	    if ($buffer != '') $reset = 0;
429
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
430
-	    $buffer = explode('\n',$buffer);
429
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
430
+	    $buffer = explode('\n', $buffer);
431 431
 	    foreach ($buffer as $line) {
432 432
     		if ($line != '' && count($line) > 7) {
433 433
     		    $line = explode(',', $line);
@@ -460,11 +460,11 @@  discard block
 block discarded – undo
460 460
 	    )
461 461
 	) {
462 462
 	    date_default_timezone_set('CET');
463
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
463
+	    $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host']));
464 464
 	    date_default_timezone_set('UTC');
465 465
 	    if ($buffer != '') $reset = 0;
466
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
467
-	    $buffer = explode('\n',$buffer);
466
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
467
+	    $buffer = explode('\n', $buffer);
468 468
 	    foreach ($buffer as $line) {
469 469
 		if ($line != '') {
470 470
 		    //echo "'".$line."'\n";
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
 		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
483 483
 		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
484 484
 		    if (isset($ais_data['timestamp'])) {
485
-			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
485
+			$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
486 486
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
487 487
 			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
488 488
 			    $add = true;
@@ -505,15 +505,15 @@  discard block
 block discarded – undo
505 505
 	    $w = $e = null;
506 506
 	    
507 507
 	    if (isset($arr[$id])) {
508
-		$nn = stream_select($arr,$w,$e,$timeout);
508
+		$nn = stream_select($arr, $w, $e, $timeout);
509 509
 		if ($nn > 0) {
510 510
 		    foreach ($httpfeeds as $feed) {
511
-			$buffer = stream_get_line($feed,2000,"\n");
511
+			$buffer = stream_get_line($feed, 2000, "\n");
512 512
 			if ($buffer === FALSE) {
513 513
 			    connect_all($globalSources);
514 514
 			}
515
-			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
516
-			$buffer = explode('\n',$buffer);
515
+			$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
516
+			$buffer = explode('\n', $buffer);
517 517
 			foreach ($buffer as $line) {
518 518
 			    if ($line != '') {
519 519
 				$ais_data = $AIS->parse_line(trim($line));
@@ -531,9 +531,9 @@  discard block
 block discarded – undo
531 531
 				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
532 532
 				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
533 533
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
534
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
534
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
535 535
 				if (isset($ais_data['timestamp'])) {
536
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
536
+				    $data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
537 537
 				} else {
538 538
 				    $data['datetime'] = date('Y-m-d H:i:s');
539 539
 				}
@@ -565,10 +565,10 @@  discard block
 block discarded – undo
565 565
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
566 566
 	    )
567 567
 	) {
568
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
568
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
569 569
 	    if ($buffer != '') {
570 570
 		//echo $buffer;
571
-		$all_data = json_decode($buffer,true);
571
+		$all_data = json_decode($buffer, true);
572 572
 		//print_r($all_data);
573 573
 		if (isset($all_data[0]['DATA'])) {
574 574
 		    foreach ($all_data[0]['DATA'] as $line) {
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
 			    $data['ident'] = $line['NAME'];
578 578
 			    $data['mmsi'] = $line['MMSI'];
579 579
 			    if (strlen($data['mmsi']) > 9) {
580
-				$data['mmsi'] = substr($data['mmsi'],-9);
580
+				$data['mmsi'] = substr($data['mmsi'], -9);
581 581
 			    }
582 582
 			    $data['speed'] = $line['SOG'];
583 583
 			    $data['heading'] = $line['COG'];
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
 			    //    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
587 587
 			    $data['imo'] = $line['IMO'];
588 588
 			    //$data['arrival_code'] = $ais_data['destination'];
589
-			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
589
+			    $data['datetime'] = date('Y-m-d H:i:s', $line['T']);
590 590
 			    $data['format_source'] = 'myshiptracking';
591 591
 			    $data['id_source'] = $id_source;
592 592
 			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -603,9 +603,9 @@  discard block
 block discarded – undo
603 603
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
604 604
 	    )
605 605
 	) {
606
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
606
+	    $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host']));
607 607
 	    if ($buffer != '') {
608
-		$all_data = json_decode($buffer,true);
608
+		$all_data = json_decode($buffer, true);
609 609
 		if (isset($all_data[0]['mmsi'])) {
610 610
 		    foreach ($all_data as $line) {
611 611
 			if ($line != '') {
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
 	) {
640 640
 	    $buffer = $Common->getData($value['host']);
641 641
 	    if ($buffer != '') {
642
-		$all_data = json_decode($buffer,true);
642
+		$all_data = json_decode($buffer, true);
643 643
 		if (isset($all_data['features'][0]['id'])) {
644 644
 		    foreach ($all_data['features'] as $line) {
645 645
 			$data = array();
@@ -672,27 +672,27 @@  discard block
 block discarded – undo
672 672
 	    )
673 673
 	) {
674 674
 	    echo 'download...';
675
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
675
+	    $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter');
676 676
 	    echo 'done !'."\n";
677 677
 	    if ($buffer != '') $reset = 0;
678
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
679
-	    $buffer = explode('\n',$buffer);
678
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
679
+	    $buffer = explode('\n', $buffer);
680 680
 	    foreach ($buffer as $line) {
681 681
 		if ($line != '') {
682 682
 		    $data = array();
683
-		    $data['mmsi'] = (int)substr($line,0,9);
684
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
683
+		    $data['mmsi'] = (int) substr($line, 0, 9);
684
+		    $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10));
685 685
 		    //$data['status'] = substr($line,21,2);
686 686
 		    //$data['type'] = substr($line,24,3);
687
-		    $data['latitude'] = substr($line,29,9);
688
-		    $data['longitude'] = substr($line,41,9);
689
-		    $data['speed'] = round(substr($line,51,5));
687
+		    $data['latitude'] = substr($line, 29, 9);
688
+		    $data['longitude'] = substr($line, 41, 9);
689
+		    $data['speed'] = round(substr($line, 51, 5));
690 690
 		    //$data['course'] = substr($line,57,5);
691
-		    $data['heading'] = round(substr($line,63,3));
691
+		    $data['heading'] = round(substr($line, 63, 3));
692 692
 		    //$data['draft'] = substr($line,67,4);
693 693
 		    //$data['length'] = substr($line,72,3);
694 694
 		    //$data['beam'] = substr($line,76,2);
695
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
695
+		    $data['ident'] = trim(utf8_encode(substr($line, 79, 20)));
696 696
 		    //$data['callsign'] = trim(substr($line,100,7);
697 697
 		    //$data['dest'] = substr($line,108,20);
698 698
 		    //$data['etaDate'] = substr($line,129,5);
@@ -725,8 +725,8 @@  discard block
 block discarded – undo
725 725
 	) {
726 726
 	    //$buffer = $Common->getData($hosts[$id]);
727 727
 	    $buffer = $Common->getData($value['host']);
728
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
729
-	    $buffer = explode('\n',$buffer);
728
+    	    $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
729
+	    $buffer = explode('\n', $buffer);
730 730
 	    $reset = 0;
731 731
 	    foreach ($buffer as $line) {
732 732
     		if ($line != '') {
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
738 738
 			$data['pilot_id'] = $line[1];
739 739
 			$data['pilot_name'] = $line[2];
740
-			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
740
+			$data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT);
741 741
 			$data['ident'] = $line[0]; // ident
742 742
 			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
743 743
 			$data['speed'] = $line[8]; // speed
@@ -753,7 +753,7 @@  discard block
 block discarded – undo
753 753
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
754 754
 			//if (isset($line[37])) $data['last_update'] = $line[37];
755 755
 		        $data['departure_airport_icao'] = $line[11];
756
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
756
+		        $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':');
757 757
 		        $data['arrival_airport_icao'] = $line[13];
758 758
 			$data['frequency'] = $line[4];
759 759
 			$data['type'] = $line[18];
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
     			$data['id_source'] = $id_source;
763 763
 	    		//$data['arrival_airport_time'] = ;
764 764
 	    		if ($line[9] != '') {
765
-	    		    $aircraft_data = explode('/',$line[9]);
765
+	    		    $aircraft_data = explode('/', $line[9]);
766 766
 	    		    if (isset($aircraft_data[1])) {
767 767
 	    			$data['aircraft_icao'] = $aircraft_data[1];
768 768
 	    		    }
@@ -777,9 +777,9 @@  discard block
 block discarded – undo
777 777
     			if ($line[3] == 'PILOT') $SI->add($data);
778 778
 			elseif ($line[3] == 'ATC') {
779 779
 				//print_r($data);
780
-				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
781
-				$data['info'] = str_replace('&amp;sect;','',$data['info']);
782
-				$typec = substr($data['ident'],-3);
780
+				$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
781
+				$data['info'] = str_replace('&amp;sect;', '', $data['info']);
782
+				$typec = substr($data['ident'], -3);
783 783
 				if ($typec == 'APP') $data['type'] = 'Approach';
784 784
 				elseif ($typec == 'TWR') $data['type'] = 'Tower';
785 785
 				elseif ($typec == 'OBS') $data['type'] = 'Observer';
@@ -791,8 +791,8 @@  discard block
 block discarded – undo
791 791
 				elseif ($data['type'] == '') $data['type'] = 'Observer';
792 792
 				if (!isset($data['source_name'])) $data['source_name'] = '';
793 793
 				if (isset($ATC)) {
794
-					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) echo $ATC->update($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
795
-					else echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
794
+					if (count($ATC->getByIdent($data['ident'], $data['format_source'])) > 0) echo $ATC->update($data['ident'], $data['frequency'], $data['latitude'], $data['longitude'], $data['range'], $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source'], $data['source_name']);
795
+					else echo $ATC->add($data['ident'], $data['frequency'], $data['latitude'], $data['longitude'], $data['range'], $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source'], $data['source_name']);
796 796
 				}
797 797
 			}
798 798
     			unset($data);
@@ -808,24 +808,24 @@  discard block
 block discarded – undo
808 808
     		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
809 809
     	    )
810 810
     	) {
811
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
811
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php', 'get', '', '', '', '', '20');
812 812
 	    if ($buffer != '') {
813 813
 		$all_data = simplexml_load_string($buffer);
814
-		foreach($all_data->children() as $childdata) {
814
+		foreach ($all_data->children() as $childdata) {
815 815
 			$data = array();
816 816
 			$line = $childdata;
817 817
 			//$data['hex'] = str_pad(dechex((int)$line['pktPilotID']),6,'000000',STR_PAD_LEFT);
818
-			$data['id'] = date('Ymd').(int)$line['pktPilotID'];
819
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
820
-			$data['latitude'] = (float)$line['pktLatitude'];
821
-			$data['longitude'] = (float)$line['pktLongitude'];
822
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
823
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
824
-			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
818
+			$data['id'] = date('Ymd').(int) $line['pktPilotID'];
819
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['entryTime'].' BST'));
820
+			$data['latitude'] = (float) $line['pktLatitude'];
821
+			$data['longitude'] = (float) $line['pktLongitude'];
822
+			if ((float) $line['pktTrack'] != 0) $data['heading'] = (float) $line['pktTrack'];
823
+			if ((int) $line['pktSpeed'] != 0) $data['speed'] = (int) $line['pktSpeed'];
824
+			$data['altitude'] = round((int) $line['pktAltitude']*3.28084);
825 825
 			$data['altitude_relative'] = 'AMSL';
826
-			$data['pilot_id'] = (int)$line['pktPilotID'];
826
+			$data['pilot_id'] = (int) $line['pktPilotID'];
827 827
 			$data['aircraft_icao'] = 'PARAGLIDER';
828
-			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
828
+			$pilot_data = explode(',', $Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
829 829
 			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
830 830
 			$data['format_source'] = $value['format'];
831 831
 			$SI->add($data);
@@ -833,22 +833,22 @@  discard block
 block discarded – undo
833 833
 		}
834 834
 	    }
835 835
 	    $Source->deleteOldLocationByType('gs');
836
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
836
+	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php', 'get', '', '', '', '', '20');
837 837
 	    if ($buffer != '') {
838 838
 		$all_data = simplexml_load_string($buffer);
839
-		foreach($all_data->children() as $childdata) {
839
+		foreach ($all_data->children() as $childdata) {
840 840
 			$data = array();
841 841
 			$line = $childdata;
842
-			$data['id'] = (int)$line['gsID'];
843
-			$data['latitude'] = (float)$line['gsLatitude'];
844
-			$data['longitude'] = (float)$line['gsLongitude'];
845
-			$data['altitude'] = round((int)$line['gsHeight']*3.28084);
842
+			$data['id'] = (int) $line['gsID'];
843
+			$data['latitude'] = (float) $line['gsLatitude'];
844
+			$data['longitude'] = (float) $line['gsLongitude'];
845
+			$data['altitude'] = round((int) $line['gsHeight']*3.28084);
846 846
 			$data['altitude_relative'] = 'AMSL';
847
-			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['gsLastUpdate'].' BST'));
847
+			$data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['gsLastUpdate'].' BST'));
848 848
 			if (count($Source->getLocationInfoByLocationID($data['id'])) > 0) {
849
-				$Source->updateLocationByLocationID('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
849
+				$Source->updateLocationByLocationID('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
850 850
 			} else {
851
-				$Source->addLocation('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']);
851
+				$Source->addLocation('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']);
852 852
 			}
853 853
 			unset($data);
854 854
 		}
@@ -866,9 +866,9 @@  discard block
 block discarded – undo
866 866
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
867 867
 	    )
868 868
 	) {
869
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
869
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20');
870 870
 	    if ($buffer != '') {
871
-	        $all_data = json_decode($buffer,true);
871
+	        $all_data = json_decode($buffer, true);
872 872
 		if (isset($all_data['acList'])) {
873 873
 		    $reset = 0;
874 874
 		    foreach ($all_data['acList'] as $line) {
@@ -884,7 +884,7 @@  discard block
 block discarded – undo
884 884
 			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
885 885
 			$data['emergency'] = ''; // emergency
886 886
 			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
887
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
887
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
888 888
 			else $data['datetime'] = date('Y-m-d H:i:s');
889 889
 			//$data['datetime'] = date('Y-m-d H:i:s');
890 890
 			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
@@ -909,7 +909,7 @@  discard block
 block discarded – undo
909 909
 			$data['verticalrate'] = $line['vrt']; // verticale rate
910 910
 			$data['squawk'] = $line['squawk']; // squawk
911 911
 			$data['emergency'] = ''; // emergency
912
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
912
+			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000));
913 913
 			else $data['datetime'] = date('Y-m-d H:i:s');
914 914
 			$data['format_source'] = 'aircraftlistjson';
915 915
 			$data['id_source'] = $id_source;
@@ -930,7 +930,7 @@  discard block
 block discarded – undo
930 930
     	    )
931 931
     	) {
932 932
 	    $buffer = $Common->getData($value['host']);
933
-	    $all_data = json_decode($buffer,true);
933
+	    $all_data = json_decode($buffer, true);
934 934
 	    if (isset($all_data['planes'])) {
935 935
 		$reset = 0;
936 936
 		foreach ($all_data['planes'] as $key => $line) {
@@ -947,12 +947,12 @@  discard block
 block discarded – undo
947 947
 		    $data['emergency'] = ''; // emergency
948 948
 		    $data['registration'] = $line[2];
949 949
 		    $data['aircraft_icao'] = $line[0];
950
-		    $deparr = explode('-',$line[1]);
950
+		    $deparr = explode('-', $line[1]);
951 951
 		    if (count($deparr) == 2) {
952 952
 			$data['departure_airport_icao'] = $deparr[0];
953 953
 			$data['arrival_airport_icao'] = $deparr[1];
954 954
 		    }
955
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
955
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[9]);
956 956
 	    	    $data['format_source'] = 'planeupdatefaa';
957 957
     		    $data['id_source'] = $id_source;
958 958
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -970,7 +970,7 @@  discard block
 block discarded – undo
970 970
 	    )
971 971
 	) {
972 972
 	    $buffer = $Common->getData($value['host']);
973
-	    $all_data = json_decode($buffer,true);
973
+	    $all_data = json_decode($buffer, true);
974 974
 	    if (isset($all_data['states'])) {
975 975
 		$reset = 0;
976 976
 		foreach ($all_data['states'] as $key => $line) {
@@ -987,7 +987,7 @@  discard block
 block discarded – undo
987 987
 		    //$data['emergency'] = ''; // emergency
988 988
 		    //$data['registration'] = $line[2];
989 989
 		    //$data['aircraft_icao'] = $line[0];
990
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
990
+		    $data['datetime'] = date('Y-m-d H:i:s', $line[3]);
991 991
 		    $data['format_source'] = 'opensky';
992 992
 		    $data['id_source'] = $id_source;
993 993
 		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1006,7 +1006,7 @@  discard block
 block discarded – undo
1006 1006
 	) {
1007 1007
 	    //$buffer = $Common->getData($hosts[$id]);
1008 1008
 	    $buffer = $Common->getData($value['host']);
1009
-	    $all_data = json_decode($buffer,true);
1009
+	    $all_data = json_decode($buffer, true);
1010 1010
 	    if (!empty($all_data)) $reset = 0;
1011 1011
 	    foreach ($all_data as $key => $line) {
1012 1012
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
@@ -1044,11 +1044,11 @@  discard block
 block discarded – undo
1044 1044
 	    )
1045 1045
 	) {
1046 1046
 	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1047
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
1047
+	    $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150');
1048 1048
 	    //echo $buffer;
1049
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
1050
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1051
-	    $all_data = json_decode($buffer,true);
1049
+	    $buffer = str_replace(array("\n", "\r"), "", $buffer);
1050
+	    $buffer = preg_replace('/,"num":(.+)/', '}', $buffer);
1051
+	    $all_data = json_decode($buffer, true);
1052 1052
 	    if (json_last_error() != JSON_ERROR_NONE) {
1053 1053
 		die(json_last_error_msg());
1054 1054
 	    }
@@ -1071,7 +1071,7 @@  discard block
 block discarded – undo
1071 1071
 			//$data['departure_airport_iata'] = $line[11];
1072 1072
 			//$data['arrival_airport_iata'] = $line[12];
1073 1073
 	    		//$data['emergency'] = ''; // emergency
1074
-			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1074
+			$data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10]
1075 1075
 	    		$data['format_source'] = 'radarvirtueljson';
1076 1076
     			$data['id_source'] = $id_source;
1077 1077
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
@@ -1092,14 +1092,14 @@  discard block
 block discarded – undo
1092 1092
 	) {
1093 1093
 	    //$buffer = $Common->getData($hosts[$id]);
1094 1094
 	    $buffer = $Common->getData($value['host'].'?'.time());
1095
-	    $all_data = json_decode(utf8_encode($buffer),true);
1095
+	    $all_data = json_decode(utf8_encode($buffer), true);
1096 1096
 	    
1097 1097
 	    if (isset($all_data['pireps'])) {
1098 1098
 		$reset = 0;
1099 1099
 	        foreach ($all_data['pireps'] as $line) {
1100 1100
 		    $data = array();
1101 1101
 		    $data['id'] = $line['id'];
1102
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1102
+		    $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6);
1103 1103
 		    $data['ident'] = $line['callsign']; // ident
1104 1104
 		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1105 1105
 		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
@@ -1129,9 +1129,9 @@  discard block
 block discarded – undo
1129 1129
 			$SI->add($data);
1130 1130
 		    //    print_r($data);
1131 1131
     		    } elseif ($line['icon'] == 'ct') {
1132
-			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1133
-			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1134
-			$typec = substr($data['ident'],-3);
1132
+			$data['info'] = str_replace('^&sect;', '<br />', $data['info']);
1133
+			$data['info'] = str_replace('&amp;sect;', '', $data['info']);
1134
+			$typec = substr($data['ident'], -3);
1135 1135
 			$data['type'] = '';
1136 1136
 			if ($typec == 'APP') $data['type'] = 'Approach';
1137 1137
 			elseif ($typec == 'TWR') $data['type'] = 'Tower';
@@ -1142,7 +1142,7 @@  discard block
 block discarded – undo
1142 1142
 			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
1143 1143
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
1144 1144
 			else $data['type'] = 'Observer';
1145
-			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']);
1145
+			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']);
1146 1146
 		    }
1147 1147
 		    unset($data);
1148 1148
 		}
@@ -1159,14 +1159,14 @@  discard block
 block discarded – undo
1159 1159
 	    //$buffer = $Common->getData($hosts[$id]);
1160 1160
 	    if ($globalDebug) echo 'Get Data...'."\n";
1161 1161
 	    $buffer = $Common->getData($value['host']);
1162
-	    $all_data = json_decode($buffer,true);
1162
+	    $all_data = json_decode($buffer, true);
1163 1163
 	    if ($buffer != '' && is_array($all_data)) {
1164 1164
 		$reset = 0;
1165 1165
 		foreach ($all_data as $line) {
1166 1166
 	    	    $data = array();
1167 1167
 	    	    //$data['id'] = $line['id']; // id not usable
1168 1168
 	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1169
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1169
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex
1170 1170
 	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1171 1171
 	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1172 1172
 	    	    $data['ident'] = $line['flightnum']; // ident
@@ -1181,7 +1181,7 @@  discard block
 block discarded – undo
1181 1181
 	    	    //$data['datetime'] = $line['lastupdate'];
1182 1182
 	    	    //$data['last_update'] = $line['lastupdate'];
1183 1183
 	    	    if (isset($value['timezone'])) {
1184
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1184
+	    		$datetime = new DateTime($line['lastupdate'], new DateTimeZone($value['timezone']));
1185 1185
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1186 1186
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1187 1187
 	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
@@ -1194,14 +1194,14 @@  discard block
 block discarded – undo
1194 1194
 		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1195 1195
 		    if (isset($line['aircraftname'])) {
1196 1196
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1197
-			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1198
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1197
+			$line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']);
1198
+	    		$aircraft_data = explode('-', $line['aircraftname']);
1199 1199
 	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1200 1200
 	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1201 1201
 	    		else {
1202
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1203
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1204
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1202
+	    		    $aircraft_data = explode(' ', $line['aircraftname']);
1203
+	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-', '', $aircraft_data[1]);
1204
+	    		    else $data['aircraft_icao'] = str_replace('-', '', $line['aircraftname']);
1205 1205
 	    		}
1206 1206
 	    	    }
1207 1207
     		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
@@ -1226,14 +1226,14 @@  discard block
 block discarded – undo
1226 1226
 	    //$buffer = $Common->getData($hosts[$id]);
1227 1227
 	    if ($globalDebug) echo 'Get Data...'."\n";
1228 1228
 	    $buffer = $Common->getData($value['host']);
1229
-	    $all_data = json_decode($buffer,true);
1229
+	    $all_data = json_decode($buffer, true);
1230 1230
 	    if ($buffer != '' && is_array($all_data)) {
1231 1231
 		$reset = 0;
1232 1232
 		foreach ($all_data as $line) {
1233 1233
 	    	    $data = array();
1234 1234
 	    	    //$data['id'] = $line['id']; // id not usable
1235 1235
 	    	    $data['id'] = trim($line['flight_id']);
1236
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1236
+	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex
1237 1237
 	    	    $data['pilot_name'] = $line['pilot_name'];
1238 1238
 	    	    $data['pilot_id'] = $line['pilot_id'];
1239 1239
 	    	    $data['ident'] = trim($line['callsign']); // ident
@@ -1277,24 +1277,24 @@  discard block
 block discarded – undo
1277 1277
 	    //$buffer = $Common->getData($hosts[$id]);
1278 1278
 	    if ($globalDebug) echo 'Get Data...'."\n";
1279 1279
 	    $buffer = $Common->getData($value['host']);
1280
-	    $all_data = json_decode($buffer,true);
1280
+	    $all_data = json_decode($buffer, true);
1281 1281
 	    if ($buffer != '') {
1282 1282
 		$Source->deleteLocationBySource('blitzortung');
1283
-		$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1284
-		$buffer = explode('\n',$buffer);
1283
+		$buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer));
1284
+		$buffer = explode('\n', $buffer);
1285 1285
 		foreach ($buffer as $buffer_line) {
1286
-		    $line = json_decode($buffer_line,true);
1286
+		    $line = json_decode($buffer_line, true);
1287 1287
 		    if (isset($line['time'])) {
1288 1288
 			$data = array();
1289 1289
 			$data['altitude'] = $line['alt']; // altitude
1290 1290
 			$data['latitude'] = $line['lat']; // lat
1291 1291
 			$data['longitude'] = $line['lon']; // long
1292
-			$data['datetime'] = date('Y-m-d H:i:s',substr($line['time'],0,10));
1292
+			$data['datetime'] = date('Y-m-d H:i:s', substr($line['time'], 0, 10));
1293 1293
 			$data['id_source'] = $id_source;
1294 1294
 			$data['format_source'] = 'blitzortung';
1295 1295
 			$SI->add($data);
1296 1296
 			if ($globalDebug) echo '☈ Lightning added'."\n";
1297
-			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1297
+			$Source->addLocation('', $data['latitude'], $data['longitude'], 0, '', '', 'blitzortung', 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime']);
1298 1298
 			unset($data);
1299 1299
 		    }
1300 1300
 		}
@@ -1319,11 +1319,11 @@  discard block
 block discarded – undo
1319 1319
 		    //$value = $formats[$nb];
1320 1320
 		    $format = $globalSources[$nb]['format'];
1321 1321
 		    if ($format == 'sbs' || $format == 'aprs' || $format == 'famaprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1322
-			$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
1322
+			$buffer = socket_read($r, 6000, PHP_NORMAL_READ);
1323 1323
 		    } elseif ($format == 'vrstcp') {
1324 1324
 			$buffer = socket_read($r, 6000);
1325 1325
 		    } else {
1326
-			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1326
+			$az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port);
1327 1327
 		    }
1328 1328
 		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1329 1329
 		    //echo $buffer."\n";
@@ -1333,8 +1333,8 @@  discard block
 block discarded – undo
1333 1333
 		    //$SI::del();
1334 1334
 		    if ($buffer !== FALSE) {
1335 1335
 			if ($format == 'vrstcp') {
1336
-			    $buffer = explode('},{',$buffer);
1337
-			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1336
+			    $buffer = explode('},{', $buffer);
1337
+			} else $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer));
1338 1338
 		    }
1339 1339
 		    // SBS format is CSV format
1340 1340
 		    if ($buffer !== FALSE && $buffer !== '') {
@@ -1369,13 +1369,13 @@  discard block
 block discarded – undo
1369 1369
 			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1370 1370
 			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1371 1371
 			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1372
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1372
+			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']);
1373 1373
 			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1374 1374
 			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1375 1375
 			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1376 1376
 
1377 1377
 			    if (isset($ais_data['timestamp'])) {
1378
-				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1378
+				$data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']);
1379 1379
 			    } else {
1380 1380
 				$data['datetime'] = date('Y-m-d H:i:s');
1381 1381
 			    }
@@ -1386,10 +1386,10 @@  discard block
 block discarded – undo
1386 1386
                         } elseif ($format == 'flightgearsp') {
1387 1387
                     	    //echo $buffer."\n";
1388 1388
                     	    if (strlen($buffer) > 5) {
1389
-				$line = explode(',',$buffer);
1389
+				$line = explode(',', $buffer);
1390 1390
 				$data = array();
1391 1391
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
1392
-				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6);
1392
+				$data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6);
1393 1393
 				$data['ident'] = $line[6];
1394 1394
 				$data['aircraft_name'] = $line[7];
1395 1395
 				$data['longitude'] = $line[1];
@@ -1406,16 +1406,16 @@  discard block
 block discarded – undo
1406 1406
                         } elseif ($format == 'acars') {
1407 1407
                     	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1408 1408
 			    $ACARS->add(trim($buffer));
1409
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1409
+			    socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port);
1410 1410
 			    $ACARS->deleteLiveAcarsData();
1411 1411
 			} elseif ($format == 'flightgearmp') {
1412
-			    if (substr($buffer,0,1) != '#') {
1412
+			    if (substr($buffer, 0, 1) != '#') {
1413 1413
 				$data = array();
1414 1414
 				//echo $buffer."\n";
1415
-				$line = explode(' ',$buffer);
1415
+				$line = explode(' ', $buffer);
1416 1416
 				if (count($line) == 11) {
1417
-				    $userserver = explode('@',$line[0]);
1418
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1417
+				    $userserver = explode('@', $line[0]);
1418
+				    $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex
1419 1419
 				    $data['ident'] = $userserver[0];
1420 1420
 				    $data['registration'] = $userserver[0];
1421 1421
 				    $data['latitude'] = $line[4];
@@ -1423,8 +1423,8 @@  discard block
 block discarded – undo
1423 1423
 				    $data['altitude'] = $line[6];
1424 1424
 				    $data['datetime'] = date('Y-m-d H:i:s');
1425 1425
 				    $aircraft_type = $line[10];
1426
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1427
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1426
+				    $aircraft_type = preg_split(':/:', $aircraft_type);
1427
+				    $data['aircraft_name'] = substr(end($aircraft_type), 0, -4);
1428 1428
 				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1429 1429
 				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1430 1430
 				}
@@ -1433,8 +1433,8 @@  discard block
 block discarded – undo
1433 1433
 			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1434 1434
 			    die;
1435 1435
 			} elseif ($format == 'vrstcp') {
1436
-			    foreach($buffer as $all_data) {
1437
-				$line = json_decode('{'.$all_data.'}',true);
1436
+			    foreach ($buffer as $all_data) {
1437
+				$line = json_decode('{'.$all_data.'}', true);
1438 1438
 				$data = array();
1439 1439
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1440 1440
 				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -1460,16 +1460,16 @@  discard block
 block discarded – undo
1460 1460
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1461 1461
 				unset($data);
1462 1462
 			    }
1463
-			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1463
+			} elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') {
1464 1464
 			    $line = explode("\t", $buffer);
1465
-			    for($k = 0; $k < count($line); $k=$k+2) {
1465
+			    for ($k = 0; $k < count($line); $k = $k + 2) {
1466 1466
 				$key = $line[$k];
1467
-			        $lined[$key] = $line[$k+1];
1467
+			        $lined[$key] = $line[$k + 1];
1468 1468
 			    }
1469 1469
     			    if (count($lined) > 3) {
1470 1470
     				$data['hex'] = $lined['hexid'];
1471 1471
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1472
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1472
+    				$data['datetime'] = date('Y-m-d H:i:s'); ;
1473 1473
     				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1474 1474
     				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1475 1475
     				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
@@ -1488,23 +1488,23 @@  discard block
 block discarded – undo
1488 1488
     			    } else $error = true;
1489 1489
 			} elseif ($format == 'aprs' && $use_aprs) {
1490 1490
 			    if ($aprs_connect == 0) {
1491
-				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1491
+				$send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0);
1492 1492
 				$aprs_connect = 1;
1493 1493
 			    }
1494 1494
 			    
1495
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1495
+			    if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) {
1496 1496
 				$aprs_last_tx = time();
1497 1497
 				$data_aprs = "# Keep alive";
1498
-				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1498
+				$send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0);
1499 1499
 			    }
1500 1500
 			    
1501 1501
 			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1502 1502
 			    //echo 'APRS data : '.$buffer."\n";
1503
-			    $buffer = str_replace('APRS <- ','',$buffer);
1504
-			    $buffer = str_replace('APRS -> ','',$buffer);
1503
+			    $buffer = str_replace('APRS <- ', '', $buffer);
1504
+			    $buffer = str_replace('APRS -> ', '', $buffer);
1505 1505
 			    //echo $buffer."\n";
1506 1506
 			    date_default_timezone_set('UTC');
1507
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1507
+			    if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') {
1508 1508
 				$line = $APRS->parse($buffer);
1509 1509
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1510 1510
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
@@ -1519,7 +1519,7 @@  discard block
 block discarded – undo
1519 1519
 				    if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1520 1520
 				    if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1521 1521
 				    if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1522
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1522
+				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']);
1523 1523
 				    else $data['datetime'] = date('Y-m-d H:i:s');
1524 1524
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1525 1525
 				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
@@ -1601,29 +1601,29 @@  discard block
 block discarded – undo
1601 1601
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1602 1602
 					if (!isset($data['altitude'])) $data['altitude'] = 0;
1603 1603
 					$Source->deleteOldLocationByType('gs');
1604
-					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
1605
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1604
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'gs')) > 0) {
1605
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
1606 1606
 					} else {
1607
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1607
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']);
1608 1608
 					}
1609 1609
 				    } elseif (isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1610 1610
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1611 1611
 					if ($globalDebug) echo '# Weather Station added'."\n";
1612 1612
 					$Source->deleteOldLocationByType('wx');
1613 1613
 					$weather_data = json_encode($line);
1614
-					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
1615
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1614
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'wx')) > 0) {
1615
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
1616 1616
 					} else {
1617
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1617
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data);
1618 1618
 					}
1619 1619
 				    } elseif (isset($line['symbol']) && ($line['symbol'] == 'Lightning' || $line['symbol'] == 'Thunderstorm')) {
1620 1620
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1621 1621
 					if ($globalDebug) echo '☈ Lightning added'."\n";
1622 1622
 					$Source->deleteOldLocationByType('lightning');
1623
-					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
1624
-						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1623
+					if (count($Source->getLocationInfoByNameType($data['ident'], 'lightning')) > 0) {
1624
+						$Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
1625 1625
 					} else {
1626
-						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1626
+						$Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']);
1627 1627
 					}
1628 1628
 				    } elseif ($globalDebug) {
1629 1629
 				    	echo '/!\ Not added: '.$buffer."\n";
@@ -1632,7 +1632,7 @@  discard block
 block discarded – undo
1632 1632
 				    unset($data);
1633 1633
 				}
1634 1634
 				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1635
-					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
1635
+					$Source->updateLocationDescByName($line['ident'], $line['source'], $id, $line['comment']);
1636 1636
 				}
1637 1637
 				/*
1638 1638
 				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle')) {
@@ -1641,7 +1641,7 @@  discard block
 block discarded – undo
1641 1641
 				*/
1642 1642
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1643 1643
 				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1644
-				if (isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
1644
+				if (isset($globalSources[$nb]['last_weather_clean']) && time() - $globalSources[$nb]['last_weather_clean'] > 60*5) {
1645 1645
 					$Source->deleteOldLocationByType('lightning');
1646 1646
 					$Source->deleteOldLocationByType('wx');
1647 1647
 					$globalSources[$nb]['last_weather_clean'] = time();
@@ -1726,7 +1726,7 @@  discard block
 block discarded – undo
1726 1726
 				connect_all($sourceee);
1727 1727
 				$sourceee = array();
1728 1728
 				//connect_all($globalSources);
1729
-				$tt[$format]=0;
1729
+				$tt[$format] = 0;
1730 1730
 				break;
1731 1731
 			    }
1732 1732
 			}
@@ -1735,14 +1735,14 @@  discard block
 block discarded – undo
1735 1735
 	    } else {
1736 1736
 		$error = socket_strerror(socket_last_error());
1737 1737
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1738
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1738
+			if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n";
1739 1739
 			if (isset($globalDebug)) echo "Restarting...\n";
1740 1740
 			// Restart the script if possible
1741 1741
 			if (is_array($sockets)) {
1742 1742
 			    if ($globalDebug) echo "Shutdown all sockets...";
1743 1743
 			    
1744 1744
 			    foreach ($sockets as $sock) {
1745
-				@socket_shutdown($sock,2);
1745
+				@socket_shutdown($sock, 2);
1746 1746
 				@socket_close($sock);
1747 1747
 			    }
1748 1748
 			    
Please login to merge, or discard this patch.
Indentation   +963 added lines, -963 removed lines patch added patch discarded remove patch
@@ -16,8 +16,8 @@  discard block
 block discarded – undo
16 16
 require_once(dirname(__FILE__).'/../require/class.Common.php');
17 17
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
18 18
 if (isset($globalMarine) && $globalMarine) {
19
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
20
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
19
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
20
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
21 21
 }
22 22
 
23 23
 if (!isset($globalDebug)) $globalDebug = FALSE;
@@ -25,46 +25,46 @@  discard block
 block discarded – undo
25 25
 // Check if schema is at latest version
26 26
 $Connection = new Connection();
27 27
 if ($Connection->connectionExists() === false) {
28
-    echo "Can't connect to your database. Check DB is running, user/password and database logs.";
29
-    exit();
28
+	echo "Can't connect to your database. Check DB is running, user/password and database logs.";
29
+	exit();
30 30
 }
31 31
 if ($Connection->latest() === false) {
32
-    echo "You MUST update to latest schema. Run install/index.php";
33
-    exit();
32
+	echo "You MUST update to latest schema. Run install/index.php";
33
+	exit();
34 34
 }
35 35
 if (PHP_SAPI != 'cli') {
36
-    echo "This script MUST be called from console, not a web browser.";
36
+	echo "This script MUST be called from console, not a web browser.";
37 37
 //    exit();
38 38
 }
39 39
 
40 40
 // This is to be compatible with old version of settings.php
41 41
 if (!isset($globalSources)) {
42
-    if (isset($globalSBS1Hosts)) {
43
-        //$hosts = $globalSBS1Hosts;
44
-        foreach ($globalSBS1Hosts as $host) {
45
-	    $globalSources[] = array('host' => $host);
46
-    	}
47
-    } else {
48
-        if (!isset($globalSBS1Host)) {
49
-	    echo '$globalSources MUST be defined !';
50
-	    die;
42
+	if (isset($globalSBS1Hosts)) {
43
+		//$hosts = $globalSBS1Hosts;
44
+		foreach ($globalSBS1Hosts as $host) {
45
+		$globalSources[] = array('host' => $host);
46
+		}
47
+	} else {
48
+		if (!isset($globalSBS1Host)) {
49
+		echo '$globalSources MUST be defined !';
50
+		die;
51 51
 	}
52 52
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
53 53
 	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
54
-    }
54
+	}
55 55
 }
56 56
 
57 57
 $options = getopt('s::',array('source::','server','nodaemon','idsource::','aprsserverssid::','aprsserverpass::','aprsserverhost::','aprsserverport::','format::','noaprsserver','enable-aircraft','disable-aircraft','enable-tracker','disable-tracker','enable-marine','disable-marine'));
58 58
 //if (isset($options['s'])) $hosts = array($options['s']);
59 59
 //elseif (isset($options['source'])) $hosts = array($options['source']);
60 60
 if (isset($options['s'])) {
61
-    $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
63
-    else $globalSources[] = array('host' => $options['s']);
61
+	$globalSources = array();
62
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
63
+	else $globalSources[] = array('host' => $options['s']);
64 64
 } elseif (isset($options['source'])) {
65
-    $globalSources = array();
66
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
67
-    else $globalSources[] = array('host' => $options['source']);
65
+	$globalSources = array();
66
+	if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
67
+	else $globalSources[] = array('host' => $options['source']);
68 68
 }
69 69
 if (isset($options['aprsserverhost'])) {
70 70
 	$globalServerAPRS = TRUE;
@@ -103,8 +103,8 @@  discard block
 block discarded – undo
103 103
 if (isset($options['idsource'])) $id_source = $options['idsource'];
104 104
 else $id_source = 1;
105 105
 if (isset($globalServer) && $globalServer) {
106
-    if ($globalDebug) echo "Using Server Mode\n";
107
-    $SI=new SpotterServer();
106
+	if ($globalDebug) echo "Using Server Mode\n";
107
+	$SI=new SpotterServer();
108 108
 /*
109 109
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
110 110
     $SI = new adsb2aprs();
@@ -114,14 +114,14 @@  discard block
 block discarded – undo
114 114
 
115 115
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
116 116
 if (isset($globalMarine) && $globalMarine) {
117
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
118
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
117
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
118
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
119 119
 }
120 120
 
121 121
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
122 122
 if (isset($globalMarine) && $globalMarine) {
123
-    $AIS = new AIS();
124
-    $MI = new MarineImport($Connection->db);
123
+	$AIS = new AIS();
124
+	$MI = new MarineImport($Connection->db);
125 125
 }
126 126
 //$APRS=new APRS($Connection->db);
127 127
 $SBS=new SBS();
@@ -134,12 +134,12 @@  discard block
 block discarded – undo
134 134
 //$servertz = system('date +%Z');
135 135
 // signal handler - playing nice with sockets and dump1090
136 136
 if (function_exists('pcntl_fork')) {
137
-    pcntl_signal(SIGINT,  function() {
138
-        global $sockets;
139
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
140
-        die("Bye!\n");
141
-    });
142
-    pcntl_signal_dispatch();
137
+	pcntl_signal(SIGINT,  function() {
138
+		global $sockets;
139
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
140
+		die("Bye!\n");
141
+	});
142
+	pcntl_signal_dispatch();
143 143
 }
144 144
 
145 145
 // let's try and connect
@@ -149,36 +149,36 @@  discard block
 block discarded – undo
149 149
 $reset = 0;
150 150
 
151 151
 function connect_all($hosts) {
152
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
153
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
154
-    $reset++;
155
-    if ($globalDebug) echo 'Connect to all...'."\n";
156
-    foreach ($hosts as $id => $value) {
152
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
153
+	global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
154
+	$reset++;
155
+	if ($globalDebug) echo 'Connect to all...'."\n";
156
+	foreach ($hosts as $id => $value) {
157 157
 	$host = $value['host'];
158 158
 	$globalSources[$id]['last_exec'] = 0;
159 159
 	// Here we check type of source(s)
160 160
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
161
-            if (preg_match('/deltadb.txt$/i',$host)) {
162
-        	//$formats[$id] = 'deltadbtxt';
163
-        	$globalSources[$id]['format'] = 'deltadbtxt';
164
-        	//$last_exec['deltadbtxt'] = 0;
165
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
166
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
167
-        	//$formats[$id] = 'vatsimtxt';
168
-        	$globalSources[$id]['format'] = 'vatsimtxt';
169
-        	//$last_exec['vatsimtxt'] = 0;
170
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
171
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
172
-        	//$formats[$id] = 'aircraftlistjson';
173
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
174
-        	//$last_exec['aircraftlistjson'] = 0;
175
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
176
-    	    } else if (preg_match('/opensky/i',$host)) {
177
-        	//$formats[$id] = 'aircraftlistjson';
178
-        	$globalSources[$id]['format'] = 'opensky';
179
-        	//$last_exec['aircraftlistjson'] = 0;
180
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
181
-    	    /*
161
+			if (preg_match('/deltadb.txt$/i',$host)) {
162
+			//$formats[$id] = 'deltadbtxt';
163
+			$globalSources[$id]['format'] = 'deltadbtxt';
164
+			//$last_exec['deltadbtxt'] = 0;
165
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
166
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
167
+			//$formats[$id] = 'vatsimtxt';
168
+			$globalSources[$id]['format'] = 'vatsimtxt';
169
+			//$last_exec['vatsimtxt'] = 0;
170
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
171
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
172
+			//$formats[$id] = 'aircraftlistjson';
173
+			$globalSources[$id]['format'] = 'aircraftlistjson';
174
+			//$last_exec['aircraftlistjson'] = 0;
175
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
176
+			} else if (preg_match('/opensky/i',$host)) {
177
+			//$formats[$id] = 'aircraftlistjson';
178
+			$globalSources[$id]['format'] = 'opensky';
179
+			//$last_exec['aircraftlistjson'] = 0;
180
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
181
+			/*
182 182
     	    // Disabled for now, site change source format
183 183
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
184 184
         	//$formats[$id] = 'radarvirtueljson';
@@ -190,121 +190,121 @@  discard block
 block discarded – undo
190 190
         	    exit(0);
191 191
         	}
192 192
     	    */
193
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
194
-        	//$formats[$id] = 'planeupdatefaa';
195
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
196
-        	//$last_exec['planeupdatefaa'] = 0;
197
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
198
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
199
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
200
-        	    exit(0);
201
-        	}
202
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
203
-        	//$formats[$id] = 'phpvmacars';
204
-        	$globalSources[$id]['format'] = 'phpvmacars';
205
-        	//$last_exec['phpvmacars'] = 0;
206
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
207
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
208
-        	//$formats[$id] = 'phpvmacars';
209
-        	$globalSources[$id]['format'] = 'vam';
210
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
211
-            } else if (preg_match('/whazzup/i',$host)) {
212
-        	//$formats[$id] = 'whazzup';
213
-        	$globalSources[$id]['format'] = 'whazzup';
214
-        	//$last_exec['whazzup'] = 0;
215
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
216
-            } else if (preg_match('/blitzortung/i',$host)) {
217
-        	$globalSources[$id]['format'] = 'blitzortung';
218
-        	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
219
-            } else if (preg_match('/airwhere/i',$host)) {
220
-        	$globalSources[$id]['format'] = 'airwhere';
221
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
222
-            } else if (preg_match('/recentpireps/i',$host)) {
223
-        	//$formats[$id] = 'pirepsjson';
224
-        	$globalSources[$id]['format'] = 'pirepsjson';
225
-        	//$last_exec['pirepsjson'] = 0;
226
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
227
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
228
-        	//$formats[$id] = 'fr24json';
229
-        	$globalSources[$id]['format'] = 'fr24json';
230
-        	//$last_exec['fr24json'] = 0;
231
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
232
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
233
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
234
-        	    exit(0);
235
-        	}
236
-            } else if (preg_match(':myshiptracking.com/:i',$host)) {
237
-        	//$formats[$id] = 'fr24json';
238
-        	$globalSources[$id]['format'] = 'myshiptracking';
239
-        	//$last_exec['fr24json'] = 0;
240
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
241
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
242
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
243
-        	    exit(0);
244
-        	}
245
-            //} else if (preg_match('/10001/',$host)) {
246
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
247
-        	//$formats[$id] = 'tsv';
248
-        	$globalSources[$id]['format'] = 'tsv';
249
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
250
-            }
251
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
252
-    		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
253
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
254
-    		    if ($idf !== false) {
255
-    			$httpfeeds[$id] = $idf;
256
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
257
-    		    }
258
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
259
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
260
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
261
-	    $hostport = explode(':',$host);
262
-	    if (isset($hostport[1])) {
193
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
194
+			//$formats[$id] = 'planeupdatefaa';
195
+			$globalSources[$id]['format'] = 'planeupdatefaa';
196
+			//$last_exec['planeupdatefaa'] = 0;
197
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
198
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
199
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
200
+				exit(0);
201
+			}
202
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
203
+			//$formats[$id] = 'phpvmacars';
204
+			$globalSources[$id]['format'] = 'phpvmacars';
205
+			//$last_exec['phpvmacars'] = 0;
206
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
207
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
208
+			//$formats[$id] = 'phpvmacars';
209
+			$globalSources[$id]['format'] = 'vam';
210
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
211
+			} else if (preg_match('/whazzup/i',$host)) {
212
+			//$formats[$id] = 'whazzup';
213
+			$globalSources[$id]['format'] = 'whazzup';
214
+			//$last_exec['whazzup'] = 0;
215
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
216
+			} else if (preg_match('/blitzortung/i',$host)) {
217
+			$globalSources[$id]['format'] = 'blitzortung';
218
+			if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
219
+			} else if (preg_match('/airwhere/i',$host)) {
220
+			$globalSources[$id]['format'] = 'airwhere';
221
+			if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
222
+			} else if (preg_match('/recentpireps/i',$host)) {
223
+			//$formats[$id] = 'pirepsjson';
224
+			$globalSources[$id]['format'] = 'pirepsjson';
225
+			//$last_exec['pirepsjson'] = 0;
226
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
227
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
228
+			//$formats[$id] = 'fr24json';
229
+			$globalSources[$id]['format'] = 'fr24json';
230
+			//$last_exec['fr24json'] = 0;
231
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
232
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
233
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
234
+				exit(0);
235
+			}
236
+			} else if (preg_match(':myshiptracking.com/:i',$host)) {
237
+			//$formats[$id] = 'fr24json';
238
+			$globalSources[$id]['format'] = 'myshiptracking';
239
+			//$last_exec['fr24json'] = 0;
240
+			if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
241
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
242
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
243
+				exit(0);
244
+			}
245
+			//} else if (preg_match('/10001/',$host)) {
246
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
247
+			//$formats[$id] = 'tsv';
248
+			$globalSources[$id]['format'] = 'tsv';
249
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
250
+			}
251
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
252
+			if ($globalSources[$id]['format'] == 'aisnmeahttp') {
253
+				$idf = fopen($globalSources[$id]['host'],'r',false,$context);
254
+				if ($idf !== false) {
255
+				$httpfeeds[$id] = $idf;
256
+				if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
257
+				}
258
+				elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
259
+			} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
260
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
261
+		$hostport = explode(':',$host);
262
+		if (isset($hostport[1])) {
263 263
 		$port = $hostport[1];
264 264
 		$hostn = $hostport[0];
265
-	    } else {
265
+		} else {
266 266
 		$port = $globalSources[$id]['port'];
267 267
 		$hostn = $globalSources[$id]['host'];
268
-	    }
269
-	    $Common = new Common();
270
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
271
-        	$s = $Common->create_socket($hostn,$port, $errno, $errstr);
272
-    	    } else {
273
-        	$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
274
-	    }
275
-	    if ($s) {
276
-    	        $sockets[$id] = $s;
277
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
278
-		    if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
268
+		}
269
+		$Common = new Common();
270
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
271
+			$s = $Common->create_socket($hostn,$port, $errno, $errstr);
272
+			} else {
273
+			$s = $Common->create_socket_udp($hostn,$port, $errno, $errstr);
274
+		}
275
+		if ($s) {
276
+				$sockets[$id] = $s;
277
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
278
+			if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') {
279 279
 			//$formats[$id] = 'aprs';
280 280
 			$globalSources[$id]['format'] = 'aprs';
281 281
 			//$aprs_connect = 0;
282 282
 			//$use_aprs = true;
283
-		    } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
283
+			} elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') {
284 284
 			$globalSources[$id]['format'] = 'vrstcp';
285
-    		    } elseif ($port == '10001') {
286
-        		//$formats[$id] = 'tsv';
287
-        		$globalSources[$id]['format'] = 'tsv';
288
-		    } elseif ($port == '30002') {
289
-        		//$formats[$id] = 'raw';
290
-        		$globalSources[$id]['format'] = 'raw';
291
-		    } elseif ($port == '5001') {
292
-        		//$formats[$id] = 'raw';
293
-        		$globalSources[$id]['format'] = 'flightgearmp';
294
-		    } elseif ($port == '30005') {
285
+				} elseif ($port == '10001') {
286
+				//$formats[$id] = 'tsv';
287
+				$globalSources[$id]['format'] = 'tsv';
288
+			} elseif ($port == '30002') {
289
+				//$formats[$id] = 'raw';
290
+				$globalSources[$id]['format'] = 'raw';
291
+			} elseif ($port == '5001') {
292
+				//$formats[$id] = 'raw';
293
+				$globalSources[$id]['format'] = 'flightgearmp';
294
+			} elseif ($port == '30005') {
295 295
 			// Not yet supported
296
-        		//$formats[$id] = 'beast';
297
-        		$globalSources[$id]['format'] = 'beast';
298
-		    //} else $formats[$id] = 'sbs';
299
-		    } else $globalSources[$id]['format'] = 'sbs';
300
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
296
+				//$formats[$id] = 'beast';
297
+				$globalSources[$id]['format'] = 'beast';
298
+			//} else $formats[$id] = 'sbs';
299
+			} else $globalSources[$id]['format'] = 'sbs';
300
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
301 301
 		}
302 302
 		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
303
-            } else {
303
+			} else {
304 304
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
305
-    	    }
306
-        }
307
-    }
305
+			}
306
+		}
307
+	}
308 308
 }
309 309
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
310 310
 
@@ -327,9 +327,9 @@  discard block
 block discarded – undo
327 327
 //connect_all($globalSources);
328 328
 
329 329
 if (isset($globalProxy) && $globalProxy) {
330
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
330
+	$context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
331 331
 } else {
332
-    $context = stream_context_create(array('http' => array('timeout' => $timeout)));
332
+	$context = stream_context_create(array('http' => array('timeout' => $timeout)));
333 333
 }
334 334
 
335 335
 // APRS Configuration
@@ -338,21 +338,21 @@  discard block
 block discarded – undo
338 338
 	die;
339 339
 }
340 340
 foreach ($globalSources as $key => $source) {
341
-    if (!isset($source['format'])) {
342
-        $globalSources[$key]['format'] = 'auto';
343
-    }
344
-    if (isset($source['callback']) && $source['callback'] === TRUE) {
345
-        unset($globalSources[$key]);
346
-    }
341
+	if (!isset($source['format'])) {
342
+		$globalSources[$key]['format'] = 'auto';
343
+	}
344
+	if (isset($source['callback']) && $source['callback'] === TRUE) {
345
+		unset($globalSources[$key]);
346
+	}
347 347
 }
348 348
 connect_all($globalSources);
349 349
 foreach ($globalSources as $key => $source) {
350
-    if (isset($source['format']) && $source['format'] == 'aprs') {
350
+	if (isset($source['format']) && $source['format'] == 'aprs') {
351 351
 	$aprs_connect = 0;
352 352
 	$use_aprs = true;
353 353
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
354 354
 	break;
355
-    }
355
+	}
356 356
 }
357 357
 
358 358
 if ($use_aprs) {
@@ -393,129 +393,129 @@  discard block
 block discarded – undo
393 393
 
394 394
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
395 395
 while ($i > 0) {
396
-    if (!$globalDaemon) $i = $endtime-time();
397
-    // Delete old ATC
398
-    if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
396
+	if (!$globalDaemon) $i = $endtime-time();
397
+	// Delete old ATC
398
+	if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
399 399
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
400
-        $ATC->deleteOldATC();
401
-    }
400
+		$ATC->deleteOldATC();
401
+	}
402 402
     
403
-    if (count($last_exec) == count($globalSources)) {
403
+	if (count($last_exec) == count($globalSources)) {
404 404
 	$max = $globalMinFetch;
405 405
 	foreach ($last_exec as $last) {
406
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
406
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
407 407
 	}
408 408
 	if ($max != $globalMinFetch) {
409
-	    if ($globalDebug) echo 'Sleeping...'."\n";
410
-	    sleep($globalMinFetch-$max+2);
409
+		if ($globalDebug) echo 'Sleeping...'."\n";
410
+		sleep($globalMinFetch-$max+2);
411
+	}
411 412
 	}
412
-    }
413 413
 
414 414
     
415
-    //foreach ($formats as $id => $value) {
416
-    foreach ($globalSources as $id => $value) {
415
+	//foreach ($formats as $id => $value) {
416
+	foreach ($globalSources as $id => $value) {
417 417
 	date_default_timezone_set('UTC');
418 418
 	//if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n";
419 419
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
420 420
 	if ($value['format'] == 'deltadbtxt' && 
421
-	    (
421
+		(
422 422
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
423 423
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
424
-	    )
424
+		)
425 425
 	) {
426
-	    //$buffer = $Common->getData($hosts[$id]);
427
-	    $buffer = $Common->getData($value['host']);
428
-	    if ($buffer != '') $reset = 0;
429
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
430
-	    $buffer = explode('\n',$buffer);
431
-	    foreach ($buffer as $line) {
432
-    		if ($line != '' && count($line) > 7) {
433
-    		    $line = explode(',', $line);
434
-	            $data = array();
435
-	            $data['hex'] = $line[1]; // hex
436
-	            $data['ident'] = $line[2]; // ident
437
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
438
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
439
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
440
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
441
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
442
-	            $data['verticalrate'] = ''; // vertical rate
443
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
444
-	            $data['emergency'] = ''; // emergency
445
-		    $data['datetime'] = date('Y-m-d H:i:s');
446
-		    $data['format_source'] = 'deltadbtxt';
447
-    		    $data['id_source'] = $id_source;
448
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
449
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
450
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
451
-    		    $SI->add($data);
452
-		    unset($data);
453
-    		}
454
-    	    }
455
-    	    $last_exec[$id]['last'] = time();
426
+		//$buffer = $Common->getData($hosts[$id]);
427
+		$buffer = $Common->getData($value['host']);
428
+		if ($buffer != '') $reset = 0;
429
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
430
+		$buffer = explode('\n',$buffer);
431
+		foreach ($buffer as $line) {
432
+			if ($line != '' && count($line) > 7) {
433
+				$line = explode(',', $line);
434
+				$data = array();
435
+				$data['hex'] = $line[1]; // hex
436
+				$data['ident'] = $line[2]; // ident
437
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
438
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
439
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
440
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
441
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
442
+				$data['verticalrate'] = ''; // vertical rate
443
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
444
+				$data['emergency'] = ''; // emergency
445
+			$data['datetime'] = date('Y-m-d H:i:s');
446
+			$data['format_source'] = 'deltadbtxt';
447
+				$data['id_source'] = $id_source;
448
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
449
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
450
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
451
+				$SI->add($data);
452
+			unset($data);
453
+			}
454
+			}
455
+			$last_exec[$id]['last'] = time();
456 456
 	} elseif ($value['format'] == 'aisnmeatxt' && 
457
-	    (
457
+		(
458 458
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
459 459
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
460
-	    )
460
+		)
461 461
 	) {
462
-	    date_default_timezone_set('CET');
463
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
464
-	    date_default_timezone_set('UTC');
465
-	    if ($buffer != '') $reset = 0;
466
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
467
-	    $buffer = explode('\n',$buffer);
468
-	    foreach ($buffer as $line) {
462
+		date_default_timezone_set('CET');
463
+		$buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
464
+		date_default_timezone_set('UTC');
465
+		if ($buffer != '') $reset = 0;
466
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
467
+		$buffer = explode('\n',$buffer);
468
+		foreach ($buffer as $line) {
469 469
 		if ($line != '') {
470
-		    //echo "'".$line."'\n";
471
-		    $add = false;
472
-		    $ais_data = $AIS->parse_line(trim($line));
473
-		    $data = array();
474
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
475
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
476
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
477
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
478
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
479
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
480
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
481
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
482
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
483
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
484
-		    if (isset($ais_data['timestamp'])) {
470
+			//echo "'".$line."'\n";
471
+			$add = false;
472
+			$ais_data = $AIS->parse_line(trim($line));
473
+			$data = array();
474
+			if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
475
+			if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
476
+			if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
477
+			if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
478
+			if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
479
+			if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
480
+			if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
481
+			if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
482
+			if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
483
+			if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
484
+			if (isset($ais_data['timestamp'])) {
485 485
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
486 486
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
487
-			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
488
-			    $add = true;
487
+				$last_exec[$id]['timestamp'] = $ais_data['timestamp'];
488
+				$add = true;
489 489
 			}
490
-		    } else {
490
+			} else {
491 491
 			$data['datetime'] = date('Y-m-d H:i:s');
492 492
 			$add = true;
493
-		    }
494
-		    $data['format_source'] = 'aisnmeatxt';
495
-    		    $data['id_source'] = $id_source;
496
-		    //print_r($data);
497
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
498
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
499
-		    unset($data);
493
+			}
494
+			$data['format_source'] = 'aisnmeatxt';
495
+				$data['id_source'] = $id_source;
496
+			//print_r($data);
497
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
498
+			if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
499
+			unset($data);
500 500
 		}
501
-    	    }
502
-    	    $last_exec[$id]['last'] = time();
501
+			}
502
+			$last_exec[$id]['last'] = time();
503 503
 	} elseif ($value['format'] == 'aisnmeahttp') {
504
-	    $arr = $httpfeeds;
505
-	    $w = $e = null;
504
+		$arr = $httpfeeds;
505
+		$w = $e = null;
506 506
 	    
507
-	    if (isset($arr[$id])) {
507
+		if (isset($arr[$id])) {
508 508
 		$nn = stream_select($arr,$w,$e,$timeout);
509 509
 		if ($nn > 0) {
510
-		    foreach ($httpfeeds as $feed) {
510
+			foreach ($httpfeeds as $feed) {
511 511
 			$buffer = stream_get_line($feed,2000,"\n");
512 512
 			if ($buffer === FALSE) {
513
-			    connect_all($globalSources);
513
+				connect_all($globalSources);
514 514
 			}
515 515
 			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
516 516
 			$buffer = explode('\n',$buffer);
517 517
 			foreach ($buffer as $line) {
518
-			    if ($line != '') {
518
+				if ($line != '') {
519 519
 				$ais_data = $AIS->parse_line(trim($line));
520 520
 				$data = array();
521 521
 				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
@@ -533,115 +533,115 @@  discard block
 block discarded – undo
533 533
 				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
534 534
 				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
535 535
 				if (isset($ais_data['timestamp'])) {
536
-				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
536
+					$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
537 537
 				} else {
538
-				    $data['datetime'] = date('Y-m-d H:i:s');
538
+					$data['datetime'] = date('Y-m-d H:i:s');
539 539
 				}
540 540
 				$data['format_source'] = 'aisnmeahttp';
541 541
 				$data['id_source'] = $id_source;
542 542
 				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
543 543
 				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
544 544
 				unset($data);
545
-			    }
545
+				}
546
+			}
546 547
 			}
547
-		    }
548 548
 		} else {
549
-		    $format = $value['format'];
550
-		    if (isset($tt[$format])) $tt[$format]++;
551
-		    else $tt[$format] = 0;
552
-		    if ($tt[$format] > 30) {
549
+			$format = $value['format'];
550
+			if (isset($tt[$format])) $tt[$format]++;
551
+			else $tt[$format] = 0;
552
+			if ($tt[$format] > 30) {
553 553
 			if ($globalDebug) echo 'Reconnect...'."\n";
554 554
 			sleep(2);
555 555
 			//$sourceeen[] = $value;
556 556
 			//connect_all($sourceeen);
557 557
 			//$sourceeen = array();
558 558
 			connect_all($globalSources);
559
-		    }
559
+			}
560
+		}
560 561
 		}
561
-	    }
562 562
 	} elseif ($value['format'] == 'myshiptracking' && 
563
-	    (
563
+		(
564 564
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
565 565
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
566
-	    )
566
+		)
567 567
 	) {
568
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
569
-	    if ($buffer != '') {
568
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
569
+		if ($buffer != '') {
570 570
 		//echo $buffer;
571 571
 		$all_data = json_decode($buffer,true);
572 572
 		//print_r($all_data);
573 573
 		if (isset($all_data[0]['DATA'])) {
574
-		    foreach ($all_data[0]['DATA'] as $line) {
574
+			foreach ($all_data[0]['DATA'] as $line) {
575 575
 			if ($line != '') {
576
-			    $data = array();
577
-			    $data['ident'] = $line['NAME'];
578
-			    $data['mmsi'] = $line['MMSI'];
579
-			    if (strlen($data['mmsi']) > 9) {
576
+				$data = array();
577
+				$data['ident'] = $line['NAME'];
578
+				$data['mmsi'] = $line['MMSI'];
579
+				if (strlen($data['mmsi']) > 9) {
580 580
 				$data['mmsi'] = substr($data['mmsi'],-9);
581
-			    }
582
-			    $data['speed'] = $line['SOG'];
583
-			    $data['heading'] = $line['COG'];
584
-			    $data['latitude'] = $line['LAT'];
585
-			    $data['longitude'] = $line['LNG'];
586
-			    //    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
587
-			    $data['imo'] = $line['IMO'];
588
-			    //$data['arrival_code'] = $ais_data['destination'];
589
-			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
590
-			    $data['format_source'] = 'myshiptracking';
591
-			    $data['id_source'] = $id_source;
592
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
593
-			    $MI->add($data);
594
-			    unset($data);
581
+				}
582
+				$data['speed'] = $line['SOG'];
583
+				$data['heading'] = $line['COG'];
584
+				$data['latitude'] = $line['LAT'];
585
+				$data['longitude'] = $line['LNG'];
586
+				//    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
587
+				$data['imo'] = $line['IMO'];
588
+				//$data['arrival_code'] = $ais_data['destination'];
589
+				$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
590
+				$data['format_source'] = 'myshiptracking';
591
+				$data['id_source'] = $id_source;
592
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
593
+				$MI->add($data);
594
+				unset($data);
595 595
 			}
596
-		    }
596
+			}
597
+		}
597 598
 		}
598
-	    }
599
-	    $last_exec[$id]['last'] = time();
599
+		$last_exec[$id]['last'] = time();
600 600
 	} elseif ($value['format'] == 'boatbeaconapp' && 
601
-	    (
601
+		(
602 602
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
603 603
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
604
-	    )
604
+		)
605 605
 	) {
606
-	    $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
607
-	    if ($buffer != '') {
606
+		$buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host']));
607
+		if ($buffer != '') {
608 608
 		$all_data = json_decode($buffer,true);
609 609
 		if (isset($all_data[0]['mmsi'])) {
610
-		    foreach ($all_data as $line) {
610
+			foreach ($all_data as $line) {
611 611
 			if ($line != '') {
612
-			    $data = array();
613
-			    $data['ident'] = $line['shipname'];
614
-			    $data['callsign'] = $line['callsign'];
615
-			    $data['mmsi'] = $line['mmsi'];
616
-			    $data['speed'] = $line['sog'];
617
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
618
-			    $data['latitude'] = $line['latitude'];
619
-			    $data['longitude'] = $line['longitude'];
620
-			    $data['type_id'] = $line['shiptype'];
621
-			    $data['arrival_code'] = $line['destination'];
622
-			    $data['datetime'] = $line['time'];
623
-			    $data['format_source'] = 'boatbeaconapp';
624
-			    $data['id_source'] = $id_source;
625
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
626
-			    $MI->add($data);
627
-			    unset($data);
612
+				$data = array();
613
+				$data['ident'] = $line['shipname'];
614
+				$data['callsign'] = $line['callsign'];
615
+				$data['mmsi'] = $line['mmsi'];
616
+				$data['speed'] = $line['sog'];
617
+				if ($line['heading'] != '511') $data['heading'] = $line['heading'];
618
+				$data['latitude'] = $line['latitude'];
619
+				$data['longitude'] = $line['longitude'];
620
+				$data['type_id'] = $line['shiptype'];
621
+				$data['arrival_code'] = $line['destination'];
622
+				$data['datetime'] = $line['time'];
623
+				$data['format_source'] = 'boatbeaconapp';
624
+				$data['id_source'] = $id_source;
625
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
626
+				$MI->add($data);
627
+				unset($data);
628
+			}
628 629
 			}
629
-		    }
630 630
 		}
631 631
 		
632
-	    }
633
-    	    $last_exec[$id]['last'] = time();
632
+		}
633
+			$last_exec[$id]['last'] = time();
634 634
 	} elseif ($value['format'] == 'boatnerd' && 
635
-	    (
635
+		(
636 636
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
637 637
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
638
-	    )
638
+		)
639 639
 	) {
640
-	    $buffer = $Common->getData($value['host']);
641
-	    if ($buffer != '') {
640
+		$buffer = $Common->getData($value['host']);
641
+		if ($buffer != '') {
642 642
 		$all_data = json_decode($buffer,true);
643 643
 		if (isset($all_data['features'][0]['id'])) {
644
-		    foreach ($all_data['features'] as $line) {
644
+			foreach ($all_data['features'] as $line) {
645 645
 			$data = array();
646 646
 			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
647 647
 			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
@@ -660,78 +660,78 @@  discard block
 block discarded – undo
660 660
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
661 661
 			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
662 662
 			unset($data);
663
-		    }
663
+			}
664 664
 		}
665 665
 		
666
-	    }
667
-    	    $last_exec[$id]['last'] = time();
666
+		}
667
+			$last_exec[$id]['last'] = time();
668 668
 	} elseif ($value['format'] == 'shipplotter' && 
669
-	    (
669
+		(
670 670
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
671 671
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3))
672
-	    )
672
+		)
673 673
 	) {
674
-	    echo 'download...';
675
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
676
-	    echo 'done !'."\n";
677
-	    if ($buffer != '') $reset = 0;
678
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
679
-	    $buffer = explode('\n',$buffer);
680
-	    foreach ($buffer as $line) {
674
+		echo 'download...';
675
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
676
+		echo 'done !'."\n";
677
+		if ($buffer != '') $reset = 0;
678
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
679
+		$buffer = explode('\n',$buffer);
680
+		foreach ($buffer as $line) {
681 681
 		if ($line != '') {
682
-		    $data = array();
683
-		    $data['mmsi'] = (int)substr($line,0,9);
684
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
685
-		    //$data['status'] = substr($line,21,2);
686
-		    //$data['type'] = substr($line,24,3);
687
-		    $data['latitude'] = substr($line,29,9);
688
-		    $data['longitude'] = substr($line,41,9);
689
-		    $data['speed'] = round(substr($line,51,5));
690
-		    //$data['course'] = substr($line,57,5);
691
-		    $data['heading'] = round(substr($line,63,3));
692
-		    //$data['draft'] = substr($line,67,4);
693
-		    //$data['length'] = substr($line,72,3);
694
-		    //$data['beam'] = substr($line,76,2);
695
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
696
-		    //$data['callsign'] = trim(substr($line,100,7);
697
-		    //$data['dest'] = substr($line,108,20);
698
-		    //$data['etaDate'] = substr($line,129,5);
699
-		    //$data['etaTime'] = substr($line,135,5);
700
-		    $data['format_source'] = 'shipplotter';
701
-    		    $data['id_source'] = $id_source;
702
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
703
-		    //print_r($data);
704
-		    echo 'Add...'."\n";
705
-		    $MI->add($data);
706
-		    unset($data);
682
+			$data = array();
683
+			$data['mmsi'] = (int)substr($line,0,9);
684
+			$data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
685
+			//$data['status'] = substr($line,21,2);
686
+			//$data['type'] = substr($line,24,3);
687
+			$data['latitude'] = substr($line,29,9);
688
+			$data['longitude'] = substr($line,41,9);
689
+			$data['speed'] = round(substr($line,51,5));
690
+			//$data['course'] = substr($line,57,5);
691
+			$data['heading'] = round(substr($line,63,3));
692
+			//$data['draft'] = substr($line,67,4);
693
+			//$data['length'] = substr($line,72,3);
694
+			//$data['beam'] = substr($line,76,2);
695
+			$data['ident'] = trim(utf8_encode(substr($line,79,20)));
696
+			//$data['callsign'] = trim(substr($line,100,7);
697
+			//$data['dest'] = substr($line,108,20);
698
+			//$data['etaDate'] = substr($line,129,5);
699
+			//$data['etaTime'] = substr($line,135,5);
700
+			$data['format_source'] = 'shipplotter';
701
+				$data['id_source'] = $id_source;
702
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
703
+			//print_r($data);
704
+			echo 'Add...'."\n";
705
+			$MI->add($data);
706
+			unset($data);
707 707
 		}
708
-    	    }
709
-    	    $last_exec[$id]['last'] = time();
708
+			}
709
+			$last_exec[$id]['last'] = time();
710 710
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
711 711
 	} elseif (
712
-	    (
712
+		(
713 713
 		$value['format'] == 'whazzup' && 
714 714
 		(
715
-		    (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
716
-		    (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
715
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
716
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
717 717
 		)
718
-	    ) || (
718
+		) || (
719 719
 		$value['format'] == 'vatsimtxt' && 
720 720
 		(
721
-		    (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
722
-		    (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
721
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
722
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
723
+		)
723 724
 		)
724
-	    )
725 725
 	) {
726
-	    //$buffer = $Common->getData($hosts[$id]);
727
-	    $buffer = $Common->getData($value['host']);
728
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
729
-	    $buffer = explode('\n',$buffer);
730
-	    $reset = 0;
731
-	    foreach ($buffer as $line) {
732
-    		if ($line != '') {
733
-    		    $line = explode(':', $line);
734
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
726
+		//$buffer = $Common->getData($hosts[$id]);
727
+		$buffer = $Common->getData($value['host']);
728
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
729
+		$buffer = explode('\n',$buffer);
730
+		$reset = 0;
731
+		foreach ($buffer as $line) {
732
+			if ($line != '') {
733
+				$line = explode(':', $line);
734
+				if (count($line) > 30 && $line[0] != 'callsign') {
735 735
 			$data = array();
736 736
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
737 737
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -744,37 +744,37 @@  discard block
 block discarded – undo
744 744
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
745 745
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
746 746
 			$data['latitude'] = $line[5]; // lat
747
-	        	$data['longitude'] = $line[6]; // long
748
-	        	$data['verticalrate'] = ''; // vertical rate
749
-	        	$data['squawk'] = ''; // squawk
750
-	        	$data['emergency'] = ''; // emergency
751
-	        	$data['waypoints'] = $line[30];
747
+				$data['longitude'] = $line[6]; // long
748
+				$data['verticalrate'] = ''; // vertical rate
749
+				$data['squawk'] = ''; // squawk
750
+				$data['emergency'] = ''; // emergency
751
+				$data['waypoints'] = $line[30];
752 752
 			$data['datetime'] = date('Y-m-d H:i:s');
753 753
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
754 754
 			//if (isset($line[37])) $data['last_update'] = $line[37];
755
-		        $data['departure_airport_icao'] = $line[11];
756
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
757
-		        $data['arrival_airport_icao'] = $line[13];
755
+				$data['departure_airport_icao'] = $line[11];
756
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
757
+				$data['arrival_airport_icao'] = $line[13];
758 758
 			$data['frequency'] = $line[4];
759 759
 			$data['type'] = $line[18];
760 760
 			$data['range'] = $line[19];
761 761
 			if (isset($line[35])) $data['info'] = $line[35];
762
-    			$data['id_source'] = $id_source;
763
-	    		//$data['arrival_airport_time'] = ;
764
-	    		if ($line[9] != '') {
765
-	    		    $aircraft_data = explode('/',$line[9]);
766
-	    		    if (isset($aircraft_data[1])) {
767
-	    			$data['aircraft_icao'] = $aircraft_data[1];
768
-	    		    }
769
-        		}
770
-	    		/*
762
+				$data['id_source'] = $id_source;
763
+				//$data['arrival_airport_time'] = ;
764
+				if ($line[9] != '') {
765
+					$aircraft_data = explode('/',$line[9]);
766
+					if (isset($aircraft_data[1])) {
767
+					$data['aircraft_icao'] = $aircraft_data[1];
768
+					}
769
+				}
770
+				/*
771 771
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
772 772
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
773 773
 	    		*/
774
-	    		$data['format_source'] = $value['format'];
774
+				$data['format_source'] = $value['format'];
775 775
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
776 776
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
777
-    			if ($line[3] == 'PILOT') $SI->add($data);
777
+				if ($line[3] == 'PILOT') $SI->add($data);
778 778
 			elseif ($line[3] == 'ATC') {
779 779
 				//print_r($data);
780 780
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -795,21 +795,21 @@  discard block
 block discarded – undo
795 795
 					else echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
796 796
 				}
797 797
 			}
798
-    			unset($data);
799
-    		    }
800
-    		}
801
-    	    }
802
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
803
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
804
-    	    $last_exec[$id]['last'] = time();
805
-    	} elseif ($value['format'] == 'airwhere' && 
806
-    	    (
807
-    		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
808
-    		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
809
-    	    )
810
-    	) {
811
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
812
-	    if ($buffer != '') {
798
+				unset($data);
799
+				}
800
+			}
801
+			}
802
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
803
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
804
+			$last_exec[$id]['last'] = time();
805
+		} elseif ($value['format'] == 'airwhere' && 
806
+			(
807
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
808
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
809
+			)
810
+		) {
811
+		$buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20');
812
+		if ($buffer != '') {
813 813
 		$all_data = simplexml_load_string($buffer);
814 814
 		foreach($all_data->children() as $childdata) {
815 815
 			$data = array();
@@ -831,10 +831,10 @@  discard block
 block discarded – undo
831 831
 			$SI->add($data);
832 832
 			unset($data);
833 833
 		}
834
-	    }
835
-	    $Source->deleteOldLocationByType('gs');
836
-	    $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
837
-	    if ($buffer != '') {
834
+		}
835
+		$Source->deleteOldLocationByType('gs');
836
+		$buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20');
837
+		if ($buffer != '') {
838 838
 		$all_data = simplexml_load_string($buffer);
839 839
 		foreach($all_data->children() as $childdata) {
840 840
 			$data = array();
@@ -852,8 +852,8 @@  discard block
 block discarded – undo
852 852
 			}
853 853
 			unset($data);
854 854
 		}
855
-	    }
856
-	    $last_exec[$id]['last'] = time();
855
+		}
856
+		$last_exec[$id]['last'] = time();
857 857
 	/*
858 858
 	} if ($value['format'] == 'aircraftlistjson') {
859 859
 	    print_r($globalSources);
@@ -861,17 +861,17 @@  discard block
 block discarded – undo
861 861
 	    echo $globalMinFetch;
862 862
 	*/
863 863
 	} elseif ($value['format'] == 'aircraftlistjson' && 
864
-	    (
864
+		(
865 865
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
866 866
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
867
-	    )
867
+		)
868 868
 	) {
869
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
870
-	    if ($buffer != '') {
871
-	        $all_data = json_decode($buffer,true);
869
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
870
+		if ($buffer != '') {
871
+			$all_data = json_decode($buffer,true);
872 872
 		if (isset($all_data['acList'])) {
873
-		    $reset = 0;
874
-		    foreach ($all_data['acList'] as $line) {
873
+			$reset = 0;
874
+			foreach ($all_data['acList'] as $line) {
875 875
 			$data = array();
876 876
 			$data['hex'] = $line['Icao']; // hex
877 877
 			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
@@ -894,10 +894,10 @@  discard block
 block discarded – undo
894 894
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
895 895
 			if (isset($data['latitude'])) $SI->add($data);
896 896
 			unset($data);
897
-		    }
897
+			}
898 898
 		} elseif (is_array($all_data)) {
899
-		    $reset = 0;
900
-		    foreach ($all_data as $line) {
899
+			$reset = 0;
900
+			foreach ($all_data as $line) {
901 901
 			$data = array();
902 902
 			$data['hex'] = $line['hex']; // hex
903 903
 			$data['ident'] = $line['flight']; // ident
@@ -917,218 +917,218 @@  discard block
 block discarded – undo
917 917
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
918 918
 			$SI->add($data);
919 919
 			unset($data);
920
-		    }
920
+			}
921 921
 		}
922
-	    } elseif ($globalDebug) echo 'No data'."\n";
923
-    	    //$last_exec['aircraftlistjson'] = time();
924
-    	    $last_exec[$id]['last'] = time();
925
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
926
-    	} elseif ($value['format'] == 'planeupdatefaa' && 
927
-    	    (
928
-    		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
929
-    		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
930
-    	    )
931
-    	) {
932
-	    $buffer = $Common->getData($value['host']);
933
-	    $all_data = json_decode($buffer,true);
934
-	    if (isset($all_data['planes'])) {
922
+		} elseif ($globalDebug) echo 'No data'."\n";
923
+			//$last_exec['aircraftlistjson'] = time();
924
+			$last_exec[$id]['last'] = time();
925
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
926
+		} elseif ($value['format'] == 'planeupdatefaa' && 
927
+			(
928
+			(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
929
+			(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
930
+			)
931
+		) {
932
+		$buffer = $Common->getData($value['host']);
933
+		$all_data = json_decode($buffer,true);
934
+		if (isset($all_data['planes'])) {
935 935
 		$reset = 0;
936 936
 		foreach ($all_data['planes'] as $key => $line) {
937
-		    $data = array();
938
-		    $data['hex'] = $key; // hex
939
-		    $data['ident'] = $line[3]; // ident
940
-		    $data['altitude'] = $line[6]; // altitude
941
-		    $data['speed'] = $line[8]; // speed
942
-		    $data['heading'] = $line[7]; // heading
943
-		    $data['latitude'] = $line[4]; // lat
944
-		    $data['longitude'] = $line[5]; // long
945
-		    //$data['verticalrate'] = $line[]; // verticale rate
946
-		    $data['squawk'] = $line[10]; // squawk
947
-		    $data['emergency'] = ''; // emergency
948
-		    $data['registration'] = $line[2];
949
-		    $data['aircraft_icao'] = $line[0];
950
-		    $deparr = explode('-',$line[1]);
951
-		    if (count($deparr) == 2) {
937
+			$data = array();
938
+			$data['hex'] = $key; // hex
939
+			$data['ident'] = $line[3]; // ident
940
+			$data['altitude'] = $line[6]; // altitude
941
+			$data['speed'] = $line[8]; // speed
942
+			$data['heading'] = $line[7]; // heading
943
+			$data['latitude'] = $line[4]; // lat
944
+			$data['longitude'] = $line[5]; // long
945
+			//$data['verticalrate'] = $line[]; // verticale rate
946
+			$data['squawk'] = $line[10]; // squawk
947
+			$data['emergency'] = ''; // emergency
948
+			$data['registration'] = $line[2];
949
+			$data['aircraft_icao'] = $line[0];
950
+			$deparr = explode('-',$line[1]);
951
+			if (count($deparr) == 2) {
952 952
 			$data['departure_airport_icao'] = $deparr[0];
953 953
 			$data['arrival_airport_icao'] = $deparr[1];
954
-		    }
955
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
956
-	    	    $data['format_source'] = 'planeupdatefaa';
957
-    		    $data['id_source'] = $id_source;
958
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
959
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
960
-		    $SI->add($data);
961
-		    unset($data);
954
+			}
955
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
956
+				$data['format_source'] = 'planeupdatefaa';
957
+				$data['id_source'] = $id_source;
958
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
959
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
960
+			$SI->add($data);
961
+			unset($data);
962
+		}
962 963
 		}
963
-	    }
964
-	    //$last_exec['planeupdatefaa'] = time();
965
-	    $last_exec[$id]['last'] = time();
964
+		//$last_exec['planeupdatefaa'] = time();
965
+		$last_exec[$id]['last'] = time();
966 966
 	} elseif ($value['format'] == 'opensky' && 
967
-	    (
967
+		(
968 968
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
969 969
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
970
-	    )
970
+		)
971 971
 	) {
972
-	    $buffer = $Common->getData($value['host']);
973
-	    $all_data = json_decode($buffer,true);
974
-	    if (isset($all_data['states'])) {
972
+		$buffer = $Common->getData($value['host']);
973
+		$all_data = json_decode($buffer,true);
974
+		if (isset($all_data['states'])) {
975 975
 		$reset = 0;
976 976
 		foreach ($all_data['states'] as $key => $line) {
977
-		    $data = array();
978
-		    $data['hex'] = $line[0]; // hex
979
-		    $data['ident'] = trim($line[1]); // ident
980
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
981
-		    $data['speed'] = round($line[9]*1.94384); // speed
982
-		    $data['heading'] = round($line[10]); // heading
983
-		    $data['latitude'] = $line[6]; // lat
984
-		    $data['longitude'] = $line[5]; // long
985
-		    $data['verticalrate'] = $line[11]; // verticale rate
986
-		    //$data['squawk'] = $line[10]; // squawk
987
-		    //$data['emergency'] = ''; // emergency
988
-		    //$data['registration'] = $line[2];
989
-		    //$data['aircraft_icao'] = $line[0];
990
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
991
-		    $data['format_source'] = 'opensky';
992
-		    $data['id_source'] = $id_source;
993
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
994
-		    $SI->add($data);
995
-		    unset($data);
977
+			$data = array();
978
+			$data['hex'] = $line[0]; // hex
979
+			$data['ident'] = trim($line[1]); // ident
980
+			$data['altitude'] = round($line[7]*3.28084); // altitude
981
+			$data['speed'] = round($line[9]*1.94384); // speed
982
+			$data['heading'] = round($line[10]); // heading
983
+			$data['latitude'] = $line[6]; // lat
984
+			$data['longitude'] = $line[5]; // long
985
+			$data['verticalrate'] = $line[11]; // verticale rate
986
+			//$data['squawk'] = $line[10]; // squawk
987
+			//$data['emergency'] = ''; // emergency
988
+			//$data['registration'] = $line[2];
989
+			//$data['aircraft_icao'] = $line[0];
990
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
991
+			$data['format_source'] = 'opensky';
992
+			$data['id_source'] = $id_source;
993
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
994
+			$SI->add($data);
995
+			unset($data);
996 996
 		}
997
-	    }
998
-	    //$last_exec['planeupdatefaa'] = time();
999
-	    $last_exec[$id]['last'] = time();
997
+		}
998
+		//$last_exec['planeupdatefaa'] = time();
999
+		$last_exec[$id]['last'] = time();
1000 1000
 	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
1001 1001
 	} elseif ($value['format'] == 'fr24json' && 
1002
-	    (
1002
+		(
1003 1003
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1004 1004
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1005
-	    )
1005
+		)
1006 1006
 	) {
1007
-	    //$buffer = $Common->getData($hosts[$id]);
1008
-	    $buffer = $Common->getData($value['host']);
1009
-	    $all_data = json_decode($buffer,true);
1010
-	    if (!empty($all_data)) $reset = 0;
1011
-	    foreach ($all_data as $key => $line) {
1007
+		//$buffer = $Common->getData($hosts[$id]);
1008
+		$buffer = $Common->getData($value['host']);
1009
+		$all_data = json_decode($buffer,true);
1010
+		if (!empty($all_data)) $reset = 0;
1011
+		foreach ($all_data as $key => $line) {
1012 1012
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
1013
-		    $data = array();
1014
-		    $data['hex'] = $line[0];
1015
-		    $data['ident'] = $line[16]; //$line[13]
1016
-	    	    $data['altitude'] = $line[4]; // altitude
1017
-	    	    $data['speed'] = $line[5]; // speed
1018
-	    	    $data['heading'] = $line[3]; // heading
1019
-	    	    $data['latitude'] = $line[1]; // lat
1020
-	    	    $data['longitude'] = $line[2]; // long
1021
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
1022
-	    	    $data['squawk'] = $line[6]; // squawk
1023
-	    	    $data['aircraft_icao'] = $line[8];
1024
-	    	    $data['registration'] = $line[9];
1025
-		    $data['departure_airport_iata'] = $line[11];
1026
-		    $data['arrival_airport_iata'] = $line[12];
1027
-	    	    $data['emergency'] = ''; // emergency
1028
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1029
-	    	    $data['format_source'] = 'fr24json';
1030
-    		    $data['id_source'] = $id_source;
1031
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1032
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1033
-		    $SI->add($data);
1034
-		    unset($data);
1013
+			$data = array();
1014
+			$data['hex'] = $line[0];
1015
+			$data['ident'] = $line[16]; //$line[13]
1016
+				$data['altitude'] = $line[4]; // altitude
1017
+				$data['speed'] = $line[5]; // speed
1018
+				$data['heading'] = $line[3]; // heading
1019
+				$data['latitude'] = $line[1]; // lat
1020
+				$data['longitude'] = $line[2]; // long
1021
+				$data['verticalrate'] = $line[15]; // verticale rate
1022
+				$data['squawk'] = $line[6]; // squawk
1023
+				$data['aircraft_icao'] = $line[8];
1024
+				$data['registration'] = $line[9];
1025
+			$data['departure_airport_iata'] = $line[11];
1026
+			$data['arrival_airport_iata'] = $line[12];
1027
+				$data['emergency'] = ''; // emergency
1028
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1029
+				$data['format_source'] = 'fr24json';
1030
+				$data['id_source'] = $id_source;
1031
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1032
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1033
+			$SI->add($data);
1034
+			unset($data);
1035 1035
 		}
1036
-	    }
1037
-	    //$last_exec['fr24json'] = time();
1038
-	    $last_exec[$id]['last'] = time();
1036
+		}
1037
+		//$last_exec['fr24json'] = time();
1038
+		$last_exec[$id]['last'] = time();
1039 1039
 	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
1040 1040
 	} elseif ($value['format'] == 'radarvirtueljson' && 
1041
-	    (
1041
+		(
1042 1042
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1043 1043
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1044
-	    )
1044
+		)
1045 1045
 	) {
1046
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1047
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
1048
-	    //echo $buffer;
1049
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
1050
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1051
-	    $all_data = json_decode($buffer,true);
1052
-	    if (json_last_error() != JSON_ERROR_NONE) {
1046
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
1047
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
1048
+		//echo $buffer;
1049
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
1050
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
1051
+		$all_data = json_decode($buffer,true);
1052
+		if (json_last_error() != JSON_ERROR_NONE) {
1053 1053
 		die(json_last_error_msg());
1054
-	    }
1055
-	    if (isset($all_data['mrkrs'])) {
1054
+		}
1055
+		if (isset($all_data['mrkrs'])) {
1056 1056
 		$reset = 0;
1057 1057
 		foreach ($all_data['mrkrs'] as $key => $line) {
1058
-		    if (isset($line['inf'])) {
1058
+			if (isset($line['inf'])) {
1059 1059
 			$data = array();
1060 1060
 			$data['hex'] = $line['inf']['ia'];
1061 1061
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1062
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1063
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1064
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1065
-	    		$data['latitude'] = $line['pt'][0]; // lat
1066
-	    		$data['longitude'] = $line['pt'][1]; // long
1067
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1068
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1069
-	    		//$data['aircraft_icao'] = $line[8];
1070
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1062
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1063
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1064
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1065
+				$data['latitude'] = $line['pt'][0]; // lat
1066
+				$data['longitude'] = $line['pt'][1]; // long
1067
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1068
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1069
+				//$data['aircraft_icao'] = $line[8];
1070
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1071 1071
 			//$data['departure_airport_iata'] = $line[11];
1072 1072
 			//$data['arrival_airport_iata'] = $line[12];
1073
-	    		//$data['emergency'] = ''; // emergency
1073
+				//$data['emergency'] = ''; // emergency
1074 1074
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1075
-	    		$data['format_source'] = 'radarvirtueljson';
1076
-    			$data['id_source'] = $id_source;
1075
+				$data['format_source'] = 'radarvirtueljson';
1076
+				$data['id_source'] = $id_source;
1077 1077
 			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1078 1078
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1079 1079
 			$SI->add($data);
1080 1080
 			unset($data);
1081
-		    }
1081
+			}
1082
+		}
1082 1083
 		}
1083
-	    }
1084
-	    //$last_exec['radarvirtueljson'] = time();
1085
-	    $last_exec[$id]['last'] = time();
1084
+		//$last_exec['radarvirtueljson'] = time();
1085
+		$last_exec[$id]['last'] = time();
1086 1086
 	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
1087 1087
 	} elseif ($value['format'] == 'pirepsjson' && 
1088
-	    (
1088
+		(
1089 1089
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1090 1090
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1091
-	    )
1091
+		)
1092 1092
 	) {
1093
-	    //$buffer = $Common->getData($hosts[$id]);
1094
-	    $buffer = $Common->getData($value['host'].'?'.time());
1095
-	    $all_data = json_decode(utf8_encode($buffer),true);
1093
+		//$buffer = $Common->getData($hosts[$id]);
1094
+		$buffer = $Common->getData($value['host'].'?'.time());
1095
+		$all_data = json_decode(utf8_encode($buffer),true);
1096 1096
 	    
1097
-	    if (isset($all_data['pireps'])) {
1097
+		if (isset($all_data['pireps'])) {
1098 1098
 		$reset = 0;
1099
-	        foreach ($all_data['pireps'] as $line) {
1100
-		    $data = array();
1101
-		    $data['id'] = $line['id'];
1102
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1103
-		    $data['ident'] = $line['callsign']; // ident
1104
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1105
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1106
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1107
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1108
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1109
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1110
-		    $data['latitude'] = $line['lat']; // lat
1111
-		    $data['longitude'] = $line['lon']; // long
1112
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
1113
-		    //$data['squawk'] = $line['squawk']; // squawk
1114
-		    //$data['emergency'] = ''; // emergency
1115
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1116
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1117
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1118
-		    //$data['arrival_airport_time'] = $line['arrtime'];
1119
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1120
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1121
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
1122
-		    else $data['info'] = '';
1123
-		    $data['format_source'] = 'pireps';
1124
-    		    $data['id_source'] = $id_source;
1125
-		    $data['datetime'] = date('Y-m-d H:i:s');
1126
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1127
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1128
-		    if ($line['icon'] == 'plane') {
1099
+			foreach ($all_data['pireps'] as $line) {
1100
+			$data = array();
1101
+			$data['id'] = $line['id'];
1102
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1103
+			$data['ident'] = $line['callsign']; // ident
1104
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1105
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1106
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1107
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1108
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1109
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1110
+			$data['latitude'] = $line['lat']; // lat
1111
+			$data['longitude'] = $line['lon']; // long
1112
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
1113
+			//$data['squawk'] = $line['squawk']; // squawk
1114
+			//$data['emergency'] = ''; // emergency
1115
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1116
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1117
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1118
+			//$data['arrival_airport_time'] = $line['arrtime'];
1119
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1120
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1121
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
1122
+			else $data['info'] = '';
1123
+			$data['format_source'] = 'pireps';
1124
+				$data['id_source'] = $id_source;
1125
+			$data['datetime'] = date('Y-m-d H:i:s');
1126
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1127
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1128
+			if ($line['icon'] == 'plane') {
1129 1129
 			$SI->add($data);
1130
-		    //    print_r($data);
1131
-    		    } elseif ($line['icon'] == 'ct') {
1130
+			//    print_r($data);
1131
+				} elseif ($line['icon'] == 'ct') {
1132 1132
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
1133 1133
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1134 1134
 			$typec = substr($data['ident'],-3);
@@ -1143,148 +1143,148 @@  discard block
 block discarded – undo
1143 1143
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
1144 1144
 			else $data['type'] = 'Observer';
1145 1145
 			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']);
1146
-		    }
1147
-		    unset($data);
1146
+			}
1147
+			unset($data);
1148
+		}
1148 1149
 		}
1149
-	    }
1150
-	    //$last_exec['pirepsjson'] = time();
1151
-	    $last_exec[$id]['last'] = time();
1150
+		//$last_exec['pirepsjson'] = time();
1151
+		$last_exec[$id]['last'] = time();
1152 1152
 	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
1153 1153
 	} elseif ($value['format'] == 'phpvmacars' && 
1154
-	    (
1154
+		(
1155 1155
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1156 1156
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1157
-	    )
1157
+		)
1158 1158
 	) {
1159
-	    //$buffer = $Common->getData($hosts[$id]);
1160
-	    if ($globalDebug) echo 'Get Data...'."\n";
1161
-	    $buffer = $Common->getData($value['host']);
1162
-	    $all_data = json_decode($buffer,true);
1163
-	    if ($buffer != '' && is_array($all_data)) {
1159
+		//$buffer = $Common->getData($hosts[$id]);
1160
+		if ($globalDebug) echo 'Get Data...'."\n";
1161
+		$buffer = $Common->getData($value['host']);
1162
+		$all_data = json_decode($buffer,true);
1163
+		if ($buffer != '' && is_array($all_data)) {
1164 1164
 		$reset = 0;
1165 1165
 		foreach ($all_data as $line) {
1166
-	    	    $data = array();
1167
-	    	    //$data['id'] = $line['id']; // id not usable
1168
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1169
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1170
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1171
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1172
-	    	    $data['ident'] = $line['flightnum']; // ident
1173
-	    	    $data['altitude'] = $line['alt']; // altitude
1174
-	    	    $data['speed'] = $line['gs']; // speed
1175
-	    	    $data['heading'] = $line['heading']; // heading
1176
-	    	    $data['latitude'] = $line['lat']; // lat
1177
-	    	    $data['longitude'] = $line['lng']; // long
1178
-	    	    $data['verticalrate'] = ''; // verticale rate
1179
-	    	    $data['squawk'] = ''; // squawk
1180
-	    	    $data['emergency'] = ''; // emergency
1181
-	    	    //$data['datetime'] = $line['lastupdate'];
1182
-	    	    //$data['last_update'] = $line['lastupdate'];
1183
-	    	    if (isset($value['timezone'])) {
1184
-	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1185
-	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1186
-	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1187
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1188
-	    	    $data['departure_airport_icao'] = $line['depicao'];
1189
-	    	    $data['departure_airport_time'] = $line['deptime'];
1190
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
1191
-    		    $data['arrival_airport_time'] = $line['arrtime'];
1192
-    		    $data['registration'] = $line['aircraft'];
1193
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1194
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1195
-		    if (isset($line['aircraftname'])) {
1166
+				$data = array();
1167
+				//$data['id'] = $line['id']; // id not usable
1168
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1169
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1170
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1171
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1172
+				$data['ident'] = $line['flightnum']; // ident
1173
+				$data['altitude'] = $line['alt']; // altitude
1174
+				$data['speed'] = $line['gs']; // speed
1175
+				$data['heading'] = $line['heading']; // heading
1176
+				$data['latitude'] = $line['lat']; // lat
1177
+				$data['longitude'] = $line['lng']; // long
1178
+				$data['verticalrate'] = ''; // verticale rate
1179
+				$data['squawk'] = ''; // squawk
1180
+				$data['emergency'] = ''; // emergency
1181
+				//$data['datetime'] = $line['lastupdate'];
1182
+				//$data['last_update'] = $line['lastupdate'];
1183
+				if (isset($value['timezone'])) {
1184
+				$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1185
+				$datetime->setTimeZone(new DateTimeZone('UTC'));
1186
+				$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1187
+				} else $data['datetime'] = date('Y-m-d H:i:s');
1188
+				$data['departure_airport_icao'] = $line['depicao'];
1189
+				$data['departure_airport_time'] = $line['deptime'];
1190
+				$data['arrival_airport_icao'] = $line['arricao'];
1191
+				$data['arrival_airport_time'] = $line['arrtime'];
1192
+				$data['registration'] = $line['aircraft'];
1193
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1194
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1195
+			if (isset($line['aircraftname'])) {
1196 1196
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1197 1197
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1198
-	    		$aircraft_data = explode('-',$line['aircraftname']);
1199
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1200
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1201
-	    		else {
1202
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1203
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1204
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1205
-	    		}
1206
-	    	    }
1207
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1208
-    		    $data['id_source'] = $id_source;
1209
-	    	    $data['format_source'] = 'phpvmacars';
1210
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1211
-		    $SI->add($data);
1212
-		    unset($data);
1198
+				$aircraft_data = explode('-',$line['aircraftname']);
1199
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1200
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1201
+				else {
1202
+					$aircraft_data = explode(' ',$line['aircraftname']);
1203
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1204
+					else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1205
+				}
1206
+				}
1207
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
1208
+				$data['id_source'] = $id_source;
1209
+				$data['format_source'] = 'phpvmacars';
1210
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1211
+			$SI->add($data);
1212
+			unset($data);
1213 1213
 		}
1214 1214
 		if ($globalDebug) echo 'No more data...'."\n";
1215 1215
 		unset($buffer);
1216 1216
 		unset($all_data);
1217
-	    }
1218
-	    //$last_exec['phpvmacars'] = time();
1219
-	    $last_exec[$id]['last'] = time();
1217
+		}
1218
+		//$last_exec['phpvmacars'] = time();
1219
+		$last_exec[$id]['last'] = time();
1220 1220
 	} elseif ($value['format'] == 'vam' && 
1221
-	    (
1221
+		(
1222 1222
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) ||
1223 1223
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1224
-	    )
1224
+		)
1225 1225
 	) {
1226
-	    //$buffer = $Common->getData($hosts[$id]);
1227
-	    if ($globalDebug) echo 'Get Data...'."\n";
1228
-	    $buffer = $Common->getData($value['host']);
1229
-	    $all_data = json_decode($buffer,true);
1230
-	    if ($buffer != '' && is_array($all_data)) {
1226
+		//$buffer = $Common->getData($hosts[$id]);
1227
+		if ($globalDebug) echo 'Get Data...'."\n";
1228
+		$buffer = $Common->getData($value['host']);
1229
+		$all_data = json_decode($buffer,true);
1230
+		if ($buffer != '' && is_array($all_data)) {
1231 1231
 		$reset = 0;
1232 1232
 		foreach ($all_data as $line) {
1233
-	    	    $data = array();
1234
-	    	    //$data['id'] = $line['id']; // id not usable
1235
-	    	    $data['id'] = trim($line['flight_id']);
1236
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1237
-	    	    $data['pilot_name'] = $line['pilot_name'];
1238
-	    	    $data['pilot_id'] = $line['pilot_id'];
1239
-	    	    $data['ident'] = trim($line['callsign']); // ident
1240
-	    	    $data['altitude'] = $line['altitude']; // altitude
1241
-	    	    $data['speed'] = $line['gs']; // speed
1242
-	    	    $data['heading'] = $line['heading']; // heading
1243
-	    	    $data['latitude'] = $line['latitude']; // lat
1244
-	    	    $data['longitude'] = $line['longitude']; // long
1245
-	    	    $data['verticalrate'] = ''; // verticale rate
1246
-	    	    $data['squawk'] = ''; // squawk
1247
-	    	    $data['emergency'] = ''; // emergency
1248
-	    	    //$data['datetime'] = $line['lastupdate'];
1249
-	    	    $data['last_update'] = $line['last_update'];
1250
-		    $data['datetime'] = date('Y-m-d H:i:s');
1251
-	    	    $data['departure_airport_icao'] = $line['departure'];
1252
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
1253
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
1254
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
1255
-    		    //$data['registration'] = $line['aircraft'];
1256
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1257
-	    	    $data['aircraft_icao'] = $line['plane_type'];
1258
-    		    $data['id_source'] = $id_source;
1259
-	    	    $data['format_source'] = 'vam';
1260
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1261
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1262
-		    $SI->add($data);
1263
-		    unset($data);
1233
+				$data = array();
1234
+				//$data['id'] = $line['id']; // id not usable
1235
+				$data['id'] = trim($line['flight_id']);
1236
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
1237
+				$data['pilot_name'] = $line['pilot_name'];
1238
+				$data['pilot_id'] = $line['pilot_id'];
1239
+				$data['ident'] = trim($line['callsign']); // ident
1240
+				$data['altitude'] = $line['altitude']; // altitude
1241
+				$data['speed'] = $line['gs']; // speed
1242
+				$data['heading'] = $line['heading']; // heading
1243
+				$data['latitude'] = $line['latitude']; // lat
1244
+				$data['longitude'] = $line['longitude']; // long
1245
+				$data['verticalrate'] = ''; // verticale rate
1246
+				$data['squawk'] = ''; // squawk
1247
+				$data['emergency'] = ''; // emergency
1248
+				//$data['datetime'] = $line['lastupdate'];
1249
+				$data['last_update'] = $line['last_update'];
1250
+			$data['datetime'] = date('Y-m-d H:i:s');
1251
+				$data['departure_airport_icao'] = $line['departure'];
1252
+				//$data['departure_airport_time'] = $line['departure_time'];
1253
+				$data['arrival_airport_icao'] = $line['arrival'];
1254
+				//$data['arrival_airport_time'] = $line['arrival_time'];
1255
+				//$data['registration'] = $line['aircraft'];
1256
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1257
+				$data['aircraft_icao'] = $line['plane_type'];
1258
+				$data['id_source'] = $id_source;
1259
+				$data['format_source'] = 'vam';
1260
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1261
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1262
+			$SI->add($data);
1263
+			unset($data);
1264 1264
 		}
1265 1265
 		if ($globalDebug) echo 'No more data...'."\n";
1266 1266
 		unset($buffer);
1267 1267
 		unset($all_data);
1268
-	    }
1269
-	    //$last_exec['phpvmacars'] = time();
1270
-	    $last_exec[$id]['last'] = time();
1268
+		}
1269
+		//$last_exec['phpvmacars'] = time();
1270
+		$last_exec[$id]['last'] = time();
1271 1271
 	} elseif ($value['format'] == 'blitzortung' && 
1272
-	    (
1272
+		(
1273 1273
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
1274 1274
 		(!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch))
1275
-	    )
1275
+		)
1276 1276
 	) {
1277
-	    //$buffer = $Common->getData($hosts[$id]);
1278
-	    if ($globalDebug) echo 'Get Data...'."\n";
1279
-	    $buffer = $Common->getData($value['host']);
1280
-	    $all_data = json_decode($buffer,true);
1281
-	    if ($buffer != '') {
1277
+		//$buffer = $Common->getData($hosts[$id]);
1278
+		if ($globalDebug) echo 'Get Data...'."\n";
1279
+		$buffer = $Common->getData($value['host']);
1280
+		$all_data = json_decode($buffer,true);
1281
+		if ($buffer != '') {
1282 1282
 		$Source->deleteLocationBySource('blitzortung');
1283 1283
 		$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
1284 1284
 		$buffer = explode('\n',$buffer);
1285 1285
 		foreach ($buffer as $buffer_line) {
1286
-		    $line = json_decode($buffer_line,true);
1287
-		    if (isset($line['time'])) {
1286
+			$line = json_decode($buffer_line,true);
1287
+			if (isset($line['time'])) {
1288 1288
 			$data = array();
1289 1289
 			$data['altitude'] = $line['alt']; // altitude
1290 1290
 			$data['latitude'] = $line['lat']; // lat
@@ -1296,96 +1296,96 @@  discard block
 block discarded – undo
1296 1296
 			if ($globalDebug) echo '☈ Lightning added'."\n";
1297 1297
 			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1298 1298
 			unset($data);
1299
-		    }
1299
+			}
1300 1300
 		}
1301 1301
 		if ($globalDebug) echo 'No more data...'."\n";
1302 1302
 		unset($buffer);
1303
-	    }
1304
-	    $last_exec[$id]['last'] = time();
1303
+		}
1304
+		$last_exec[$id]['last'] = time();
1305 1305
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1306 1306
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'famaprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais' || $value['format'] == 'vrstcp') {
1307
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1308
-    	    //$last_exec[$id]['last'] = time();
1307
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1308
+			//$last_exec[$id]['last'] = time();
1309 1309
 
1310
-	    //$read = array( $sockets[$id] );
1311
-	    $read = $sockets;
1312
-	    $write = NULL;
1313
-	    $e = NULL;
1314
-	    $n = socket_select($read, $write, $e, $timeout);
1315
-	    if ($e != NULL) var_dump($e);
1316
-	    if ($n > 0) {
1310
+		//$read = array( $sockets[$id] );
1311
+		$read = $sockets;
1312
+		$write = NULL;
1313
+		$e = NULL;
1314
+		$n = socket_select($read, $write, $e, $timeout);
1315
+		if ($e != NULL) var_dump($e);
1316
+		if ($n > 0) {
1317 1317
 		$reset = 0;
1318 1318
 		foreach ($read as $nb => $r) {
1319
-		    //$value = $formats[$nb];
1320
-		    $format = $globalSources[$nb]['format'];
1321
-		    if ($format == 'sbs' || $format == 'aprs' || $format == 'famaprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1319
+			//$value = $formats[$nb];
1320
+			$format = $globalSources[$nb]['format'];
1321
+			if ($format == 'sbs' || $format == 'aprs' || $format == 'famaprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
1322 1322
 			$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
1323
-		    } elseif ($format == 'vrstcp') {
1323
+			} elseif ($format == 'vrstcp') {
1324 1324
 			$buffer = socket_read($r, 6000);
1325
-		    } else {
1325
+			} else {
1326 1326
 			$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
1327
-		    }
1328
-		    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1329
-		    //echo $buffer."\n";
1330
-		    // lets play nice and handle signals such as ctrl-c/kill properly
1331
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1332
-		    $error = false;
1333
-		    //$SI::del();
1334
-		    if ($buffer !== FALSE) {
1327
+			}
1328
+			//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
1329
+			//echo $buffer."\n";
1330
+			// lets play nice and handle signals such as ctrl-c/kill properly
1331
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1332
+			$error = false;
1333
+			//$SI::del();
1334
+			if ($buffer !== FALSE) {
1335 1335
 			if ($format == 'vrstcp') {
1336
-			    $buffer = explode('},{',$buffer);
1336
+				$buffer = explode('},{',$buffer);
1337 1337
 			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1338
-		    }
1339
-		    // SBS format is CSV format
1340
-		    if ($buffer !== FALSE && $buffer !== '') {
1338
+			}
1339
+			// SBS format is CSV format
1340
+			if ($buffer !== FALSE && $buffer !== '') {
1341 1341
 			$tt[$format] = 0;
1342 1342
 			if ($format == 'acarssbs3') {
1343
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1344
-			    $ACARS->add(trim($buffer));
1345
-			    $ACARS->deleteLiveAcarsData();
1343
+				if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1344
+				$ACARS->add(trim($buffer));
1345
+				$ACARS->deleteLiveAcarsData();
1346 1346
 			} elseif ($format == 'raw') {
1347
-			    // AVR format
1348
-			    $data = $SBS->parse($buffer);
1349
-			    if (is_array($data)) {
1347
+				// AVR format
1348
+				$data = $SBS->parse($buffer);
1349
+				if (is_array($data)) {
1350 1350
 				$data['datetime'] = date('Y-m-d H:i:s');
1351 1351
 				$data['format_source'] = 'raw';
1352 1352
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1353 1353
 				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1354 1354
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1355 1355
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1356
-			    }
1356
+				}
1357 1357
 			} elseif ($format == 'ais') {
1358
-			    $ais_data = $AIS->parse_line(trim($buffer));
1359
-			    $data = array();
1360
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1361
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1362
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1363
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1364
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1365
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1366
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1367
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1368
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1369
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1370
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1371
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1372
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1373
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1374
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1375
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1358
+				$ais_data = $AIS->parse_line(trim($buffer));
1359
+				$data = array();
1360
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1361
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1362
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1363
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1364
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1365
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1366
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1367
+				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1368
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1369
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1370
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1371
+				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1372
+				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1373
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1374
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1375
+				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1376 1376
 
1377
-			    if (isset($ais_data['timestamp'])) {
1377
+				if (isset($ais_data['timestamp'])) {
1378 1378
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1379
-			    } else {
1379
+				} else {
1380 1380
 				$data['datetime'] = date('Y-m-d H:i:s');
1381
-			    }
1382
-			    $data['format_source'] = 'aisnmea';
1383
-    			    $data['id_source'] = $id_source;
1384
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1385
-			    unset($data);
1386
-                        } elseif ($format == 'flightgearsp') {
1387
-                    	    //echo $buffer."\n";
1388
-                    	    if (strlen($buffer) > 5) {
1381
+				}
1382
+				$data['format_source'] = 'aisnmea';
1383
+					$data['id_source'] = $id_source;
1384
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1385
+				unset($data);
1386
+						} elseif ($format == 'flightgearsp') {
1387
+							//echo $buffer."\n";
1388
+							if (strlen($buffer) > 5) {
1389 1389
 				$line = explode(',',$buffer);
1390 1390
 				$data = array();
1391 1391
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1402,38 +1402,38 @@  discard block
 block discarded – undo
1402 1402
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1403 1403
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1404 1404
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1405
-			    }
1406
-                        } elseif ($format == 'acars') {
1407
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1408
-			    $ACARS->add(trim($buffer));
1409
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1410
-			    $ACARS->deleteLiveAcarsData();
1405
+				}
1406
+						} elseif ($format == 'acars') {
1407
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1408
+				$ACARS->add(trim($buffer));
1409
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1410
+				$ACARS->deleteLiveAcarsData();
1411 1411
 			} elseif ($format == 'flightgearmp') {
1412
-			    if (substr($buffer,0,1) != '#') {
1412
+				if (substr($buffer,0,1) != '#') {
1413 1413
 				$data = array();
1414 1414
 				//echo $buffer."\n";
1415 1415
 				$line = explode(' ',$buffer);
1416 1416
 				if (count($line) == 11) {
1417
-				    $userserver = explode('@',$line[0]);
1418
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1419
-				    $data['ident'] = $userserver[0];
1420
-				    $data['registration'] = $userserver[0];
1421
-				    $data['latitude'] = $line[4];
1422
-				    $data['longitude'] = $line[5];
1423
-				    $data['altitude'] = $line[6];
1424
-				    $data['datetime'] = date('Y-m-d H:i:s');
1425
-				    $aircraft_type = $line[10];
1426
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1427
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1428
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1429
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1417
+					$userserver = explode('@',$line[0]);
1418
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1419
+					$data['ident'] = $userserver[0];
1420
+					$data['registration'] = $userserver[0];
1421
+					$data['latitude'] = $line[4];
1422
+					$data['longitude'] = $line[5];
1423
+					$data['altitude'] = $line[6];
1424
+					$data['datetime'] = date('Y-m-d H:i:s');
1425
+					$aircraft_type = $line[10];
1426
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1427
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1428
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1429
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1430
+				}
1430 1431
 				}
1431
-			    }
1432 1432
 			} elseif ($format == 'beast') {
1433
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1434
-			    die;
1433
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1434
+				die;
1435 1435
 			} elseif ($format == 'vrstcp') {
1436
-			    foreach($buffer as $all_data) {
1436
+				foreach($buffer as $all_data) {
1437 1437
 				$line = json_decode('{'.$all_data.'}',true);
1438 1438
 				$data = array();
1439 1439
 				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
@@ -1453,153 +1453,153 @@  discard block
 block discarded – undo
1453 1453
 				*/
1454 1454
 				$data['datetime'] = date('Y-m-d H:i:s');
1455 1455
 				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1456
-		    		$data['format_source'] = 'vrstcp';
1456
+					$data['format_source'] = 'vrstcp';
1457 1457
 				$data['id_source'] = $id_source;
1458 1458
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1459 1459
 				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1460 1460
 				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1461 1461
 				unset($data);
1462
-			    }
1462
+				}
1463 1463
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1464
-			    $line = explode("\t", $buffer);
1465
-			    for($k = 0; $k < count($line); $k=$k+2) {
1464
+				$line = explode("\t", $buffer);
1465
+				for($k = 0; $k < count($line); $k=$k+2) {
1466 1466
 				$key = $line[$k];
1467
-			        $lined[$key] = $line[$k+1];
1468
-			    }
1469
-    			    if (count($lined) > 3) {
1470
-    				$data['hex'] = $lined['hexid'];
1471
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1472
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1473
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1474
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1475
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1476
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1477
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1478
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1479
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1480
-    				$data['id_source'] = $id_source;
1481
-    				$data['format_source'] = 'tsv';
1482
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1483
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1467
+					$lined[$key] = $line[$k+1];
1468
+				}
1469
+					if (count($lined) > 3) {
1470
+					$data['hex'] = $lined['hexid'];
1471
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1472
+					$data['datetime'] = date('Y-m-d H:i:s');;
1473
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1474
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1475
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1476
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1477
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1478
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1479
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1480
+					$data['id_source'] = $id_source;
1481
+					$data['format_source'] = 'tsv';
1482
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1483
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1484 1484
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1485
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1486
-    				unset($lined);
1487
-    				unset($data);
1488
-    			    } else $error = true;
1485
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1486
+					unset($lined);
1487
+					unset($data);
1488
+					} else $error = true;
1489 1489
 			} elseif ($format == 'aprs' && $use_aprs) {
1490
-			    if ($aprs_connect == 0) {
1490
+				if ($aprs_connect == 0) {
1491 1491
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1492 1492
 				$aprs_connect = 1;
1493
-			    }
1493
+				}
1494 1494
 			    
1495
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1495
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1496 1496
 				$aprs_last_tx = time();
1497 1497
 				$data_aprs = "# Keep alive";
1498 1498
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1499
-			    }
1499
+				}
1500 1500
 			    
1501
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1502
-			    //echo 'APRS data : '.$buffer."\n";
1503
-			    $buffer = str_replace('APRS <- ','',$buffer);
1504
-			    $buffer = str_replace('APRS -> ','',$buffer);
1505
-			    //echo $buffer."\n";
1506
-			    date_default_timezone_set('UTC');
1507
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1501
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1502
+				//echo 'APRS data : '.$buffer."\n";
1503
+				$buffer = str_replace('APRS <- ','',$buffer);
1504
+				$buffer = str_replace('APRS -> ','',$buffer);
1505
+				//echo $buffer."\n";
1506
+				date_default_timezone_set('UTC');
1507
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1508 1508
 				$line = $APRS->parse($buffer);
1509 1509
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1510 1510
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) {
1511
-				    $aprs_last_tx = time();
1512
-				    $data = array();
1513
-				    //print_r($line);
1514
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1515
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1516
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1517
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1518
-				    if (isset($line['arrival_code'])) $data['arrical_code'] = $line['arrival_code'];
1519
-				    if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1520
-				    if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1521
-				    if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1522
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1523
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1524
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1525
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1526
-				    $data['latitude'] = $line['latitude'];
1527
-				    $data['longitude'] = $line['longitude'];
1528
-				    //$data['verticalrate'] = $line[16];
1529
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1530
-				    //else $data['speed'] = 0;
1531
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1532
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1533
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1534
-				    //if (isset($line['heading'])) $data['heading'] = $line['heading'];
1511
+					$aprs_last_tx = time();
1512
+					$data = array();
1513
+					//print_r($line);
1514
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1515
+					if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1516
+					if (isset($line['imo'])) $data['imo'] = $line['imo'];
1517
+					if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1518
+					if (isset($line['arrival_code'])) $data['arrical_code'] = $line['arrival_code'];
1519
+					if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1520
+					if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1521
+					if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1522
+					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1523
+					else $data['datetime'] = date('Y-m-d H:i:s');
1524
+					//$data['datetime'] = date('Y-m-d H:i:s');
1525
+					if (isset($line['ident'])) $data['ident'] = $line['ident'];
1526
+					$data['latitude'] = $line['latitude'];
1527
+					$data['longitude'] = $line['longitude'];
1528
+					//$data['verticalrate'] = $line[16];
1529
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1530
+					//else $data['speed'] = 0;
1531
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1532
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1533
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1534
+					//if (isset($line['heading'])) $data['heading'] = $line['heading'];
1535 1535
 				    
1536
-				    if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
1537
-				    //else echo 'No heading...'."\n";
1538
-				    //else $data['heading'] = 0;
1539
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1540
-				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1541
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1542
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1543
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1544
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1545
-    				    $data['id_source'] = $id_source;
1546
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1547
-				    else $data['format_source'] = 'aprs';
1548
-				    $data['source_name'] = $line['source'];
1549
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1550
-				    else $data['source_type'] = 'flarm';
1551
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1552
-				    $currentdate = date('Y-m-d H:i:s');
1553
-				    $aprsdate = strtotime($data['datetime']);
1554
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
1555
-				    // Accept data if time <= system time + 20s
1556
-				    //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'])))) {
1557
-				    if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1536
+					if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
1537
+					//else echo 'No heading...'."\n";
1538
+					//else $data['heading'] = 0;
1539
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1540
+					//if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1541
+					if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1542
+					elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1543
+					if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1544
+					elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1545
+						$data['id_source'] = $id_source;
1546
+						if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1547
+					else $data['format_source'] = 'aprs';
1548
+					$data['source_name'] = $line['source'];
1549
+					if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1550
+					else $data['source_type'] = 'flarm';
1551
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1552
+					$currentdate = date('Y-m-d H:i:s');
1553
+					$aprsdate = strtotime($data['datetime']);
1554
+					if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
1555
+					// Accept data if time <= system time + 20s
1556
+					//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'])))) {
1557
+					if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1558 1558
 					$send = $SI->add($data);
1559
-				    } elseif ($data['source_type'] == 'ais') {
1559
+					} elseif ($data['source_type'] == 'ais') {
1560 1560
 					$data['type'] = '';
1561 1561
 					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
1562
-				    } elseif (isset($line['stealth'])) {
1562
+					} elseif (isset($line['stealth'])) {
1563 1563
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1564 1564
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1565
-				    } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1566
-					    //$line['symbol'] == 'Balloon' ||
1567
-					    $line['symbol'] == 'Glider' || 
1568
-					    $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1569
-					    if ($line['symbol'] == 'Ballon') $data['aircraft_icao'] = 'BALL';
1570
-					    if ($line['symbol'] == 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
1571
-					    $send = $SI->add($data);
1572
-				    } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1573
-					    $line['symbol'] == 'Yacht (Sail)' || 
1574
-					    $line['symbol'] == 'Ship (Power Boat)')) {
1575
-					    $send = $MI->add($data);
1576
-				    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1577
-					    $line['symbol'] == 'Car' || 
1578
-					    $line['symbol'] == 'Ambulance' || 
1579
-					    $line['symbol'] == 'Van' || 
1580
-					    $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || 
1581
-					    $line['symbol'] == 'Motorcycle' || 
1582
-					    $line['symbol'] == 'Tractor' || 
1583
-					    $line['symbol'] == 'Police' || 
1584
-					    $line['symbol'] == 'Bike' || 
1585
-					    $line['symbol'] == 'Jogger' || 
1586
-					    $line['symbol'] == 'Horse' || 
1587
-					    $line['symbol'] == 'Bus' || 
1588
-					    $line['symbol'] == 'Jeep' || 
1589
-					    $line['symbol'] == 'Recreational Vehicle' || 
1590
-					    $line['symbol'] == 'Yacht (Sail)' || 
1591
-					    $line['symbol'] == 'Ship (Power Boat)' || 
1592
-					    $line['symbol'] == 'Firetruck' || 
1593
-					    $line['symbol'] == 'Balloon' || $line['symbol'] == 'Glider' || 
1594
-					    $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter' || 
1595
-					    $line['symbol'] == 'SUV' ||
1596
-					    $line['symbol'] == 'Snowmobile' ||
1597
-					    $line['symbol'] == 'Mobile Satellite Station')) {
1598
-				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1565
+					} elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1566
+						//$line['symbol'] == 'Balloon' ||
1567
+						$line['symbol'] == 'Glider' || 
1568
+						$line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1569
+						if ($line['symbol'] == 'Ballon') $data['aircraft_icao'] = 'BALL';
1570
+						if ($line['symbol'] == 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
1571
+						$send = $SI->add($data);
1572
+					} elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1573
+						$line['symbol'] == 'Yacht (Sail)' || 
1574
+						$line['symbol'] == 'Ship (Power Boat)')) {
1575
+						$send = $MI->add($data);
1576
+					} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1577
+						$line['symbol'] == 'Car' || 
1578
+						$line['symbol'] == 'Ambulance' || 
1579
+						$line['symbol'] == 'Van' || 
1580
+						$line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || 
1581
+						$line['symbol'] == 'Motorcycle' || 
1582
+						$line['symbol'] == 'Tractor' || 
1583
+						$line['symbol'] == 'Police' || 
1584
+						$line['symbol'] == 'Bike' || 
1585
+						$line['symbol'] == 'Jogger' || 
1586
+						$line['symbol'] == 'Horse' || 
1587
+						$line['symbol'] == 'Bus' || 
1588
+						$line['symbol'] == 'Jeep' || 
1589
+						$line['symbol'] == 'Recreational Vehicle' || 
1590
+						$line['symbol'] == 'Yacht (Sail)' || 
1591
+						$line['symbol'] == 'Ship (Power Boat)' || 
1592
+						$line['symbol'] == 'Firetruck' || 
1593
+						$line['symbol'] == 'Balloon' || $line['symbol'] == 'Glider' || 
1594
+						$line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter' || 
1595
+						$line['symbol'] == 'SUV' ||
1596
+						$line['symbol'] == 'Snowmobile' ||
1597
+						$line['symbol'] == 'Mobile Satellite Station')) {
1598
+					//} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1599 1599
 				//    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1600 1600
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1601 1601
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1602
-				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1602
+					} elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1603 1603
 					if (!isset($data['altitude'])) $data['altitude'] = 0;
1604 1604
 					$Source->deleteOldLocationByType('gs');
1605 1605
 					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
@@ -1607,7 +1607,7 @@  discard block
 block discarded – undo
1607 1607
 					} else {
1608 1608
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
1609 1609
 					}
1610
-				    } elseif (isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1610
+					} elseif (isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1611 1611
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1612 1612
 					if ($globalDebug) echo '# Weather Station added'."\n";
1613 1613
 					$Source->deleteOldLocationByType('wx');
@@ -1617,7 +1617,7 @@  discard block
 block discarded – undo
1617 1617
 					} else {
1618 1618
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data);
1619 1619
 					}
1620
-				    } elseif (isset($line['symbol']) && ($line['symbol'] == 'Lightning' || $line['symbol'] == 'Thunderstorm')) {
1620
+					} elseif (isset($line['symbol']) && ($line['symbol'] == 'Lightning' || $line['symbol'] == 'Thunderstorm')) {
1621 1621
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1622 1622
 					if ($globalDebug) echo '☈ Lightning added'."\n";
1623 1623
 					$Source->deleteOldLocationByType('lightning');
@@ -1626,11 +1626,11 @@  discard block
 block discarded – undo
1626 1626
 					} else {
1627 1627
 						$Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
1628 1628
 					}
1629
-				    } elseif ($globalDebug) {
1630
-				    	echo '/!\ Not added: '.$buffer."\n";
1631
-				    	print_r($line);
1632
-				    }
1633
-				    unset($data);
1629
+					} elseif ($globalDebug) {
1630
+						echo '/!\ Not added: '.$buffer."\n";
1631
+						print_r($line);
1632
+					}
1633
+					unset($data);
1634 1634
 				}
1635 1635
 				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1636 1636
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
@@ -1649,12 +1649,12 @@  discard block
 block discarded – undo
1649 1649
 				} elseif (!isset($globalSources[$nb]['last_weather_clean'])) {
1650 1650
 					$globalSources[$nb]['last_weather_clean'] = time();
1651 1651
 				}
1652
-			    }
1652
+				}
1653 1653
 			} else {
1654
-			    $line = explode(',', $buffer);
1655
-    			    if (count($line) > 20) {
1656
-    			    	$data['hex'] = $line[4];
1657
-    				/*
1654
+				$line = explode(',', $buffer);
1655
+					if (count($line) > 20) {
1656
+						$data['hex'] = $line[4];
1657
+					/*
1658 1658
     				$data['datetime'] = $line[6].' '.$line[7];
1659 1659
     					date_default_timezone_set($globalTimezone);
1660 1660
     					$datetime = new DateTime($data['datetime']);
@@ -1662,30 +1662,30 @@  discard block
 block discarded – undo
1662 1662
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1663 1663
     					date_default_timezone_set('UTC');
1664 1664
     				*/
1665
-    				// Force datetime to current UTC datetime
1666
-    				date_default_timezone_set('UTC');
1667
-    				$data['datetime'] = date('Y-m-d H:i:s');
1668
-    				$data['ident'] = trim($line[10]);
1669
-    				$data['latitude'] = $line[14];
1670
-    				$data['longitude'] = $line[15];
1671
-    				$data['verticalrate'] = $line[16];
1672
-    				$data['emergency'] = $line[20];
1673
-    				$data['speed'] = $line[12];
1674
-    				$data['squawk'] = $line[17];
1675
-    				$data['altitude'] = $line[11];
1676
-    				$data['heading'] = $line[13];
1677
-    				$data['ground'] = $line[21];
1678
-    				$data['emergency'] = $line[19];
1679
-    				$data['format_source'] = 'sbs';
1665
+					// Force datetime to current UTC datetime
1666
+					date_default_timezone_set('UTC');
1667
+					$data['datetime'] = date('Y-m-d H:i:s');
1668
+					$data['ident'] = trim($line[10]);
1669
+					$data['latitude'] = $line[14];
1670
+					$data['longitude'] = $line[15];
1671
+					$data['verticalrate'] = $line[16];
1672
+					$data['emergency'] = $line[20];
1673
+					$data['speed'] = $line[12];
1674
+					$data['squawk'] = $line[17];
1675
+					$data['altitude'] = $line[11];
1676
+					$data['heading'] = $line[13];
1677
+					$data['ground'] = $line[21];
1678
+					$data['emergency'] = $line[19];
1679
+					$data['format_source'] = 'sbs';
1680 1680
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1681
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1681
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1682 1682
 				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1683
-    				$data['id_source'] = $id_source;
1684
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1685
-    				else $error = true;
1686
-    				unset($data);
1687
-    			    } else $error = true;
1688
-			    if ($error) {
1683
+					$data['id_source'] = $id_source;
1684
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1685
+					else $error = true;
1686
+					unset($data);
1687
+					} else $error = true;
1688
+				if ($error) {
1689 1689
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1690 1690
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1691 1691
 				} else {
@@ -1701,13 +1701,13 @@  discard block
 block discarded – undo
1701 1701
 					connect_all($sourceer);
1702 1702
 					$sourceer = array();
1703 1703
 				}
1704
-			    }
1704
+				}
1705 1705
 			}
1706 1706
 			// Sleep for xxx microseconds
1707 1707
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1708
-		    } else {
1708
+			} else {
1709 1709
 			if ($format == 'flightgearmp') {
1710
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1710
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1711 1711
 				//@socket_close($r);
1712 1712
 				sleep($globalMinFetch);
1713 1713
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1716,9 +1716,9 @@  discard block
 block discarded – undo
1716 1716
 				break;
1717 1717
 				
1718 1718
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1719
-			    if (isset($tt[$format])) $tt[$format]++;
1720
-			    else $tt[$format] = 0;
1721
-			    if ($tt[$format] > 30) {
1719
+				if (isset($tt[$format])) $tt[$format]++;
1720
+				else $tt[$format] = 0;
1721
+				if ($tt[$format] > 30) {
1722 1722
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1723 1723
 				//@socket_close($r);
1724 1724
 				sleep(2);
@@ -1729,23 +1729,23 @@  discard block
 block discarded – undo
1729 1729
 				//connect_all($globalSources);
1730 1730
 				$tt[$format]=0;
1731 1731
 				break;
1732
-			    }
1732
+				}
1733
+			}
1733 1734
 			}
1734
-		    }
1735 1735
 		}
1736
-	    } else {
1736
+		} else {
1737 1737
 		$error = socket_strerror(socket_last_error());
1738 1738
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1739 1739
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1740 1740
 			if (isset($globalDebug)) echo "Restarting...\n";
1741 1741
 			// Restart the script if possible
1742 1742
 			if (is_array($sockets)) {
1743
-			    if ($globalDebug) echo "Shutdown all sockets...";
1743
+				if ($globalDebug) echo "Shutdown all sockets...";
1744 1744
 			    
1745
-			    foreach ($sockets as $sock) {
1745
+				foreach ($sockets as $sock) {
1746 1746
 				@socket_shutdown($sock,2);
1747 1747
 				@socket_close($sock);
1748
-			    }
1748
+				}
1749 1749
 			    
1750 1750
 			}
1751 1751
 			if ($globalDebug) echo "Waiting...";
@@ -1760,15 +1760,15 @@  discard block
 block discarded – undo
1760 1760
 			if ($globalDebug) echo "Restart all connections...";
1761 1761
 			connect_all($globalSources);
1762 1762
 		}
1763
-	    }
1763
+		}
1764 1764
 	}
1765 1765
 	if ($globalDaemon === false) {
1766
-	    if ($globalDebug) echo 'Check all...'."\n";
1767
-	    if (isset($SI)) $SI->checkAll();
1768
-	    if (isset($TI)) $TI->checkAll();
1769
-	    if (isset($MI)) $MI->checkAll();
1766
+		if ($globalDebug) echo 'Check all...'."\n";
1767
+		if (isset($SI)) $SI->checkAll();
1768
+		if (isset($TI)) $TI->checkAll();
1769
+		if (isset($MI)) $MI->checkAll();
1770
+	}
1770 1771
 	}
1771
-    }
1772 1772
 }
1773 1773
 
1774 1774
 ?>
Please login to merge, or discard this patch.
Braces   +1049 added lines, -358 removed lines patch added patch discarded remove patch
@@ -14,13 +14,17 @@  discard block
 block discarded – undo
14 14
 require_once(dirname(__FILE__).'/../require/class.Source.php');
15 15
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
16 16
 require_once(dirname(__FILE__).'/../require/class.Common.php');
17
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
17
+if (isset($globalTracker) && $globalTracker) {
18
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
19
+}
18 20
 if (isset($globalMarine) && $globalMarine) {
19 21
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
20 22
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
21 23
 }
22 24
 
23
-if (!isset($globalDebug)) $globalDebug = FALSE;
25
+if (!isset($globalDebug)) {
26
+	$globalDebug = FALSE;
27
+}
24 28
 
25 29
 // Check if schema is at latest version
26 30
 $Connection = new Connection();
@@ -59,66 +63,107 @@  discard block
 block discarded – undo
59 63
 //elseif (isset($options['source'])) $hosts = array($options['source']);
60 64
 if (isset($options['s'])) {
61 65
     $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
63
-    else $globalSources[] = array('host' => $options['s']);
64
-} elseif (isset($options['source'])) {
66
+    if (isset($options['format'])) {
67
+    	$globalSources[] = array('host' => $options['s'],'format' => $options['format']);
68
+    } else {
69
+    	$globalSources[] = array('host' => $options['s']);
70
+    }
71
+    } elseif (isset($options['source'])) {
65 72
     $globalSources = array();
66
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
67
-    else $globalSources[] = array('host' => $options['source']);
68
-}
73
+    if (isset($options['format'])) {
74
+    	$globalSources[] = array('host' => $options['source'],'format' => $options['format']);
75
+    } else {
76
+    	$globalSources[] = array('host' => $options['source']);
77
+    }
78
+    }
69 79
 if (isset($options['aprsserverhost'])) {
70 80
 	$globalServerAPRS = TRUE;
71 81
 	$globalServerAPRShost = $options['aprsserverhost'];
72 82
 }
73
-if (isset($options['aprsserverport'])) $globalServerAPRSport = $options['aprsserverport'];
74
-if (isset($options['aprsserverssid'])) $globalServerAPRSssid = $options['aprsserverssid'];
75
-if (isset($options['aprsserverpass'])) $globalServerAPRSpass = $options['aprsserverpass'];
76
-if (isset($options['noaprsserver'])) $globalServerAPRS = FALSE; 
83
+if (isset($options['aprsserverport'])) {
84
+	$globalServerAPRSport = $options['aprsserverport'];
85
+}
86
+if (isset($options['aprsserverssid'])) {
87
+	$globalServerAPRSssid = $options['aprsserverssid'];
88
+}
89
+if (isset($options['aprsserverpass'])) {
90
+	$globalServerAPRSpass = $options['aprsserverpass'];
91
+}
92
+if (isset($options['noaprsserver'])) {
93
+	$globalServerAPRS = FALSE;
94
+}
77 95
 if (isset($options['enable-aircraft'])) {
78
-	if ($globalDebug) echo 'Enable Aircraft mode'."\n";
96
+	if ($globalDebug) {
97
+		echo 'Enable Aircraft mode'."\n";
98
+	}
79 99
 	$globalAircraft = TRUE; 
80 100
 }
81 101
 if (isset($options['disable-aircraft'])) {
82
-	if ($globalDebug) echo 'Disable Aircraft mode'."\n";
102
+	if ($globalDebug) {
103
+		echo 'Disable Aircraft mode'."\n";
104
+	}
83 105
 	$globalAircraft = FALSE;
84 106
 }
85 107
 if (isset($options['enable-tracker'])) {
86
-	if ($globalDebug) echo 'Enable Tracker mode'."\n";
108
+	if ($globalDebug) {
109
+		echo 'Enable Tracker mode'."\n";
110
+	}
87 111
 	$globalTracker = TRUE; 
88 112
 }
89 113
 if (isset($options['disable-tracker'])) {
90
-	if ($globalDebug) echo 'Disable Tracker mode'."\n";
114
+	if ($globalDebug) {
115
+		echo 'Disable Tracker mode'."\n";
116
+	}
91 117
 	$globalTracker = FALSE;
92 118
 }
93 119
 if (isset($options['enable-marine'])) {
94
-	if ($globalDebug) echo 'Enable Marine mode'."\n";
120
+	if ($globalDebug) {
121
+		echo 'Enable Marine mode'."\n";
122
+	}
95 123
 	$globalMarine = TRUE;
96 124
 }
97 125
 if (isset($options['disable-marine'])) {
98
-	if ($globalDebug) echo 'Disable Marine mode'."\n";
126
+	if ($globalDebug) {
127
+		echo 'Disable Marine mode'."\n";
128
+	}
99 129
 	$globalMarine = FALSE;
100 130
 }
101
-if (isset($options['nodaemon'])) $globalDaemon = FALSE;
102
-if (isset($options['server'])) $globalServer = TRUE;
103
-if (isset($options['idsource'])) $id_source = $options['idsource'];
104
-else $id_source = 1;
131
+if (isset($options['nodaemon'])) {
132
+	$globalDaemon = FALSE;
133
+}
134
+if (isset($options['server'])) {
135
+	$globalServer = TRUE;
136
+}
137
+if (isset($options['idsource'])) {
138
+	$id_source = $options['idsource'];
139
+} else {
140
+	$id_source = 1;
141
+}
105 142
 if (isset($globalServer) && $globalServer) {
106
-    if ($globalDebug) echo "Using Server Mode\n";
143
+    if ($globalDebug) {
144
+    	echo "Using Server Mode\n";
145
+    }
107 146
     $SI=new SpotterServer();
108 147
 /*
109 148
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
110 149
     $SI = new adsb2aprs();
111 150
     $SI->connect();
112 151
 */
113
-} else $SI=new SpotterImport($Connection->db);
152
+} else {
153
+	$SI=new SpotterImport($Connection->db);
154
+}
114 155
 
115
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
156
+if (isset($globalTracker) && $globalTracker) {
157
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
158
+}
116 159
 if (isset($globalMarine) && $globalMarine) {
117 160
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
118 161
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
119 162
 }
120 163
 
121
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
164
+if (isset($globalTracker) && $globalTracker) {
165
+	$TI = new TrackerImport($Connection->db);
166
+}
122 167
 if (isset($globalMarine) && $globalMarine) {
123 168
     $AIS = new AIS();
124 169
     $MI = new MarineImport($Connection->db);
@@ -143,7 +188,9 @@  discard block
 block discarded – undo
143 188
 }
144 189
 
145 190
 // let's try and connect
146
-if ($globalDebug) echo "Connecting...\n";
191
+if ($globalDebug) {
192
+	echo "Connecting...\n";
193
+}
147 194
 $use_aprs = false;
148 195
 $aprs_full = false;
149 196
 $reset = 0;
@@ -152,7 +199,9 @@  discard block
 block discarded – undo
152 199
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
153 200
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
154 201
     $reset++;
155
-    if ($globalDebug) echo 'Connect to all...'."\n";
202
+    if ($globalDebug) {
203
+    	echo 'Connect to all...'."\n";
204
+    }
156 205
     foreach ($hosts as $id => $value) {
157 206
 	$host = $value['host'];
158 207
 	$globalSources[$id]['last_exec'] = 0;
@@ -162,22 +211,30 @@  discard block
 block discarded – undo
162 211
         	//$formats[$id] = 'deltadbtxt';
163 212
         	$globalSources[$id]['format'] = 'deltadbtxt';
164 213
         	//$last_exec['deltadbtxt'] = 0;
165
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
214
+        	if ($globalDebug) {
215
+        		echo "Connect to deltadb source (".$host.")...\n";
216
+        	}
166 217
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
167 218
         	//$formats[$id] = 'vatsimtxt';
168 219
         	$globalSources[$id]['format'] = 'vatsimtxt';
169 220
         	//$last_exec['vatsimtxt'] = 0;
170
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
221
+        	if ($globalDebug) {
222
+        		echo "Connect to vatsim source (".$host.")...\n";
223
+        	}
171 224
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
172 225
         	//$formats[$id] = 'aircraftlistjson';
173 226
         	$globalSources[$id]['format'] = 'aircraftlistjson';
174 227
         	//$last_exec['aircraftlistjson'] = 0;
175
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
228
+        	if ($globalDebug) {
229
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
230
+        	}
176 231
     	    } else if (preg_match('/opensky/i',$host)) {
177 232
         	//$formats[$id] = 'aircraftlistjson';
178 233
         	$globalSources[$id]['format'] = 'opensky';
179 234
         	//$last_exec['aircraftlistjson'] = 0;
180
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
235
+        	if ($globalDebug) {
236
+        		echo "Connect to opensky source (".$host.")...\n";
237
+        	}
181 238
     	    /*
182 239
     	    // Disabled for now, site change source format
183 240
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
@@ -194,7 +251,9 @@  discard block
 block discarded – undo
194 251
         	//$formats[$id] = 'planeupdatefaa';
195 252
         	$globalSources[$id]['format'] = 'planeupdatefaa';
196 253
         	//$last_exec['planeupdatefaa'] = 0;
197
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
254
+        	if ($globalDebug) {
255
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
256
+        	}
198 257
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
199 258
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
200 259
         	    exit(0);
@@ -203,32 +262,46 @@  discard block
 block discarded – undo
203 262
         	//$formats[$id] = 'phpvmacars';
204 263
         	$globalSources[$id]['format'] = 'phpvmacars';
205 264
         	//$last_exec['phpvmacars'] = 0;
206
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
265
+        	if ($globalDebug) {
266
+        		echo "Connect to phpvmacars source (".$host.")...\n";
267
+        	}
207 268
             } else if (preg_match('/VAM-json.php$/i',$host)) {
208 269
         	//$formats[$id] = 'phpvmacars';
209 270
         	$globalSources[$id]['format'] = 'vam';
210
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
271
+        	if ($globalDebug) {
272
+        		echo "Connect to Vam source (".$host.")...\n";
273
+        	}
211 274
             } else if (preg_match('/whazzup/i',$host)) {
212 275
         	//$formats[$id] = 'whazzup';
213 276
         	$globalSources[$id]['format'] = 'whazzup';
214 277
         	//$last_exec['whazzup'] = 0;
215
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
278
+        	if ($globalDebug) {
279
+        		echo "Connect to whazzup source (".$host.")...\n";
280
+        	}
216 281
             } else if (preg_match('/blitzortung/i',$host)) {
217 282
         	$globalSources[$id]['format'] = 'blitzortung';
218
-        	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
283
+        	if ($globalDebug) {
284
+        		echo "Connect to blitzortung source (".$host.")...\n";
285
+        	}
219 286
             } else if (preg_match('/airwhere/i',$host)) {
220 287
         	$globalSources[$id]['format'] = 'airwhere';
221
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
288
+        	if ($globalDebug) {
289
+        		echo "Connect to airwhere source (".$host.")...\n";
290
+        	}
222 291
             } else if (preg_match('/recentpireps/i',$host)) {
223 292
         	//$formats[$id] = 'pirepsjson';
224 293
         	$globalSources[$id]['format'] = 'pirepsjson';
225 294
         	//$last_exec['pirepsjson'] = 0;
226
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
295
+        	if ($globalDebug) {
296
+        		echo "Connect to pirepsjson source (".$host.")...\n";
297
+        	}
227 298
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
228 299
         	//$formats[$id] = 'fr24json';
229 300
         	$globalSources[$id]['format'] = 'fr24json';
230 301
         	//$last_exec['fr24json'] = 0;
231
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
302
+        	if ($globalDebug) {
303
+        		echo "Connect to fr24 source (".$host.")...\n";
304
+        	}
232 305
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
233 306
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
234 307
         	    exit(0);
@@ -237,7 +310,9 @@  discard block
 block discarded – undo
237 310
         	//$formats[$id] = 'fr24json';
238 311
         	$globalSources[$id]['format'] = 'myshiptracking';
239 312
         	//$last_exec['fr24json'] = 0;
240
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
313
+        	if ($globalDebug) {
314
+        		echo "Connect to myshiptracking source (".$host.")...\n";
315
+        	}
241 316
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
242 317
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
243 318
         	    exit(0);
@@ -246,17 +321,24 @@  discard block
 block discarded – undo
246 321
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
247 322
         	//$formats[$id] = 'tsv';
248 323
         	$globalSources[$id]['format'] = 'tsv';
249
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
324
+        	if ($globalDebug) {
325
+        		echo "Connect to tsv source (".$host.")...\n";
326
+        	}
250 327
             }
251 328
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
252 329
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
253 330
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
254 331
     		    if ($idf !== false) {
255 332
     			$httpfeeds[$id] = $idf;
256
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
333
+        		if ($globalDebug) {
334
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
335
+        		}
336
+    		    } elseif ($globalDebug) {
337
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
257 338
     		    }
258
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
259
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
339
+    		} elseif ($globalDebug) {
340
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
341
+    		}
260 342
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
261 343
 	    $hostport = explode(':',$host);
262 344
 	    if (isset($hostport[1])) {
@@ -296,17 +378,25 @@  discard block
 block discarded – undo
296 378
         		//$formats[$id] = 'beast';
297 379
         		$globalSources[$id]['format'] = 'beast';
298 380
 		    //} else $formats[$id] = 'sbs';
299
-		    } else $globalSources[$id]['format'] = 'sbs';
381
+		    } else {
382
+		    	$globalSources[$id]['format'] = 'sbs';
383
+		    }
300 384
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
301 385
 		}
302
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
386
+		if ($globalDebug) {
387
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
388
+		}
303 389
             } else {
304
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
390
+		if ($globalDebug) {
391
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
392
+		}
305 393
     	    }
306 394
         }
307 395
     }
308 396
 }
309
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
397
+if (!isset($globalMinFetch)) {
398
+	$globalMinFetch = 15;
399
+}
310 400
 
311 401
 // Initialize all
312 402
 $status = array();
@@ -315,13 +405,19 @@  discard block
 block discarded – undo
315 405
 $formats = array();
316 406
 $last_exec = array();
317 407
 $time = time();
318
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
319
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
320
-else $timeout = 20;
408
+if (isset($globalSourcesTimeout)) {
409
+	$timeout = $globalSourcesTimeOut;
410
+} else if (isset($globalSBS1TimeOut)) {
411
+	$timeout = $globalSBS1TimeOut;
412
+} else {
413
+	$timeout = 20;
414
+}
321 415
 $errno = '';
322 416
 $errstr='';
323 417
 
324
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
418
+if (!isset($globalDaemon)) {
419
+	$globalDaemon = TRUE;
420
+}
325 421
 /* Initiate connections to all the hosts simultaneously */
326 422
 //connect_all($hosts);
327 423
 //connect_all($globalSources);
@@ -350,7 +446,9 @@  discard block
 block discarded – undo
350 446
     if (isset($source['format']) && $source['format'] == 'aprs') {
351 447
 	$aprs_connect = 0;
352 448
 	$use_aprs = true;
353
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
449
+	if (isset($source['port']) && $source['port'] == '10152') {
450
+		$aprs_full = true;
451
+	}
354 452
 	break;
355 453
     }
356 454
 }
@@ -361,25 +459,48 @@  discard block
 block discarded – undo
361 459
 	$aprs_connect = 0;
362 460
 	$aprs_keep = 120;
363 461
 	$aprs_last_tx = time();
364
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
365
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
366
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
367
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
368
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
369
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
370
-	if ($aprs_full) $aprs_filter = '';
371
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
372
-	else $aprs_pass = '-1';
462
+	if (isset($globalAPRSversion)) {
463
+		$aprs_version = $globalAPRSversion;
464
+	} else {
465
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
466
+	}
467
+	if (isset($globalAPRSssid)) {
468
+		$aprs_ssid = $globalAPRSssid;
469
+	} else {
470
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
471
+	}
472
+	if (isset($globalAPRSfilter)) {
473
+		$aprs_filter = $globalAPRSfilter;
474
+	} else {
475
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
476
+	}
477
+	if ($aprs_full) {
478
+		$aprs_filter = '';
479
+	}
480
+	if (isset($globalAPRSpass)) {
481
+		$aprs_pass = $globalAPRSpass;
482
+	} else {
483
+		$aprs_pass = '-1';
484
+	}
373 485
 
374
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
375
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
376
-}
486
+	if ($aprs_filter != '') {
487
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
488
+	} else {
489
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
490
+	}
491
+	}
377 492
 
378 493
 // connected - lets do some work
379
-if ($globalDebug) echo "Connected!\n";
494
+if ($globalDebug) {
495
+	echo "Connected!\n";
496
+}
380 497
 sleep(1);
381
-if ($globalDebug) echo "SCAN MODE \n\n";
382
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
498
+if ($globalDebug) {
499
+	echo "SCAN MODE \n\n";
500
+}
501
+if (!isset($globalCronEnd)) {
502
+	$globalCronEnd = 60;
503
+}
383 504
 $endtime = time()+$globalCronEnd;
384 505
 $i = 1;
385 506
 $tt = array();
@@ -393,20 +514,28 @@  discard block
 block discarded – undo
393 514
 
394 515
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
395 516
 while ($i > 0) {
396
-    if (!$globalDaemon) $i = $endtime-time();
517
+    if (!$globalDaemon) {
518
+    	$i = $endtime-time();
519
+    }
397 520
     // Delete old ATC
398 521
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
399
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
522
+	if ($globalDebug) {
523
+		echo 'Delete old ATC...'."\n";
524
+	}
400 525
         $ATC->deleteOldATC();
401 526
     }
402 527
     
403 528
     if (count($last_exec) == count($globalSources)) {
404 529
 	$max = $globalMinFetch;
405 530
 	foreach ($last_exec as $last) {
406
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
531
+	    if ((time() - $last['last']) < $max) {
532
+	    	$max = time() - $last['last'];
533
+	    }
407 534
 	}
408 535
 	if ($max != $globalMinFetch) {
409
-	    if ($globalDebug) echo 'Sleeping...'."\n";
536
+	    if ($globalDebug) {
537
+	    	echo 'Sleeping...'."\n";
538
+	    }
410 539
 	    sleep($globalMinFetch-$max+2);
411 540
 	}
412 541
     }
@@ -416,7 +545,9 @@  discard block
 block discarded – undo
416 545
     foreach ($globalSources as $id => $value) {
417 546
 	date_default_timezone_set('UTC');
418 547
 	//if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n";
419
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
548
+	if (!isset($last_exec[$id]['last'])) {
549
+		$last_exec[$id]['last'] = 0;
550
+	}
420 551
 	if ($value['format'] == 'deltadbtxt' && 
421 552
 	    (
422 553
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
@@ -425,7 +556,9 @@  discard block
 block discarded – undo
425 556
 	) {
426 557
 	    //$buffer = $Common->getData($hosts[$id]);
427 558
 	    $buffer = $Common->getData($value['host']);
428
-	    if ($buffer != '') $reset = 0;
559
+	    if ($buffer != '') {
560
+	    	$reset = 0;
561
+	    }
429 562
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
430 563
 	    $buffer = explode('\n',$buffer);
431 564
 	    foreach ($buffer as $line) {
@@ -434,20 +567,41 @@  discard block
 block discarded – undo
434 567
 	            $data = array();
435 568
 	            $data['hex'] = $line[1]; // hex
436 569
 	            $data['ident'] = $line[2]; // ident
437
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
438
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
439
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
440
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
441
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
570
+	            if (isset($line[3])) {
571
+	            	$data['altitude'] = $line[3];
572
+	            }
573
+	            // altitude
574
+	            if (isset($line[4])) {
575
+	            	$data['speed'] = $line[4];
576
+	            }
577
+	            // speed
578
+	            if (isset($line[5])) {
579
+	            	$data['heading'] = $line[5];
580
+	            }
581
+	            // heading
582
+	            if (isset($line[6])) {
583
+	            	$data['latitude'] = $line[6];
584
+	            }
585
+	            // lat
586
+	            if (isset($line[7])) {
587
+	            	$data['longitude'] = $line[7];
588
+	            }
589
+	            // long
442 590
 	            $data['verticalrate'] = ''; // vertical rate
443 591
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
444 592
 	            $data['emergency'] = ''; // emergency
445 593
 		    $data['datetime'] = date('Y-m-d H:i:s');
446 594
 		    $data['format_source'] = 'deltadbtxt';
447 595
     		    $data['id_source'] = $id_source;
448
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
449
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
450
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
596
+		    if (isset($value['name']) && $value['name'] != '') {
597
+		    	$data['source_name'] = $value['name'];
598
+		    }
599
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
600
+		    	$data['noarchive'] = true;
601
+		    }
602
+		    if (isset($value['sourcestats'])) {
603
+		    	$data['sourcestats'] = $value['sourcestats'];
604
+		    }
451 605
     		    $SI->add($data);
452 606
 		    unset($data);
453 607
     		}
@@ -462,7 +616,9 @@  discard block
 block discarded – undo
462 616
 	    date_default_timezone_set('CET');
463 617
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
464 618
 	    date_default_timezone_set('UTC');
465
-	    if ($buffer != '') $reset = 0;
619
+	    if ($buffer != '') {
620
+	    	$reset = 0;
621
+	    }
466 622
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
467 623
 	    $buffer = explode('\n',$buffer);
468 624
 	    foreach ($buffer as $line) {
@@ -471,16 +627,36 @@  discard block
 block discarded – undo
471 627
 		    $add = false;
472 628
 		    $ais_data = $AIS->parse_line(trim($line));
473 629
 		    $data = array();
474
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
475
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
476
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
477
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
478
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
479
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
480
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
481
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
482
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
483
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
630
+		    if (isset($ais_data['ident'])) {
631
+		    	$data['ident'] = $ais_data['ident'];
632
+		    }
633
+		    if (isset($ais_data['mmsi'])) {
634
+		    	$data['mmsi'] = $ais_data['mmsi'];
635
+		    }
636
+		    if (isset($ais_data['speed'])) {
637
+		    	$data['speed'] = $ais_data['speed'];
638
+		    }
639
+		    if (isset($ais_data['heading'])) {
640
+		    	$data['heading'] = $ais_data['heading'];
641
+		    }
642
+		    if (isset($ais_data['latitude'])) {
643
+		    	$data['latitude'] = $ais_data['latitude'];
644
+		    }
645
+		    if (isset($ais_data['longitude'])) {
646
+		    	$data['longitude'] = $ais_data['longitude'];
647
+		    }
648
+		    if (isset($ais_data['status'])) {
649
+		    	$data['status'] = $ais_data['status'];
650
+		    }
651
+		    if (isset($ais_data['type'])) {
652
+		    	$data['type'] = $ais_data['type'];
653
+		    }
654
+		    if (isset($ais_data['imo'])) {
655
+		    	$data['imo'] = $ais_data['imo'];
656
+		    }
657
+		    if (isset($ais_data['callsign'])) {
658
+		    	$data['callsign'] = $ais_data['callsign'];
659
+		    }
484 660
 		    if (isset($ais_data['timestamp'])) {
485 661
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
486 662
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -494,8 +670,12 @@  discard block
 block discarded – undo
494 670
 		    $data['format_source'] = 'aisnmeatxt';
495 671
     		    $data['id_source'] = $id_source;
496 672
 		    //print_r($data);
497
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
498
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
673
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
674
+		    	$data['noarchive'] = true;
675
+		    }
676
+		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
677
+		    	$MI->add($data);
678
+		    }
499 679
 		    unset($data);
500 680
 		}
501 681
     	    }
@@ -518,20 +698,48 @@  discard block
 block discarded – undo
518 698
 			    if ($line != '') {
519 699
 				$ais_data = $AIS->parse_line(trim($line));
520 700
 				$data = array();
521
-				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
522
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
523
-				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
524
-				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
525
-				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
526
-				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
527
-				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
528
-				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
529
-				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
530
-				if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
531
-				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
532
-				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
533
-				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
534
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
701
+				if (isset($ais_data['ident'])) {
702
+					$data['ident'] = $ais_data['ident'];
703
+				}
704
+				if (isset($ais_data['mmsi'])) {
705
+					$data['mmsi'] = $ais_data['mmsi'];
706
+				}
707
+				if (isset($ais_data['speed'])) {
708
+					$data['speed'] = $ais_data['speed'];
709
+				}
710
+				if (isset($ais_data['heading'])) {
711
+					$data['heading'] = $ais_data['heading'];
712
+				}
713
+				if (isset($ais_data['latitude'])) {
714
+					$data['latitude'] = $ais_data['latitude'];
715
+				}
716
+				if (isset($ais_data['longitude'])) {
717
+					$data['longitude'] = $ais_data['longitude'];
718
+				}
719
+				if (isset($ais_data['status'])) {
720
+					$data['status'] = $ais_data['status'];
721
+				}
722
+				if (isset($ais_data['statusid'])) {
723
+					$data['status_id'] = $ais_data['statusid'];
724
+				}
725
+				if (isset($ais_data['type'])) {
726
+					$data['type'] = $ais_data['type'];
727
+				}
728
+				if (isset($ais_data['typeid'])) {
729
+					$data['type_id'] = $ais_data['typeid'];
730
+				}
731
+				if (isset($ais_data['imo'])) {
732
+					$data['imo'] = $ais_data['imo'];
733
+				}
734
+				if (isset($ais_data['callsign'])) {
735
+					$data['callsign'] = $ais_data['callsign'];
736
+				}
737
+				if (isset($ais_data['destination'])) {
738
+					$data['arrival_code'] = $ais_data['destination'];
739
+				}
740
+				if (isset($ais_data['eta_ts'])) {
741
+					$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
742
+				}
535 743
 				if (isset($ais_data['timestamp'])) {
536 744
 				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
537 745
 				} else {
@@ -539,18 +747,27 @@  discard block
 block discarded – undo
539 747
 				}
540 748
 				$data['format_source'] = 'aisnmeahttp';
541 749
 				$data['id_source'] = $id_source;
542
-				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
543
-				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
750
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
751
+					$data['noarchive'] = true;
752
+				}
753
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
754
+					$MI->add($data);
755
+				}
544 756
 				unset($data);
545 757
 			    }
546 758
 			}
547 759
 		    }
548 760
 		} else {
549 761
 		    $format = $value['format'];
550
-		    if (isset($tt[$format])) $tt[$format]++;
551
-		    else $tt[$format] = 0;
762
+		    if (isset($tt[$format])) {
763
+		    	$tt[$format]++;
764
+		    } else {
765
+		    	$tt[$format] = 0;
766
+		    }
552 767
 		    if ($tt[$format] > 30) {
553
-			if ($globalDebug) echo 'Reconnect...'."\n";
768
+			if ($globalDebug) {
769
+				echo 'Reconnect...'."\n";
770
+			}
554 771
 			sleep(2);
555 772
 			//$sourceeen[] = $value;
556 773
 			//connect_all($sourceeen);
@@ -589,7 +806,9 @@  discard block
 block discarded – undo
589 806
 			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
590 807
 			    $data['format_source'] = 'myshiptracking';
591 808
 			    $data['id_source'] = $id_source;
592
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
809
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
810
+			    	$data['noarchive'] = true;
811
+			    }
593 812
 			    $MI->add($data);
594 813
 			    unset($data);
595 814
 			}
@@ -614,7 +833,9 @@  discard block
 block discarded – undo
614 833
 			    $data['callsign'] = $line['callsign'];
615 834
 			    $data['mmsi'] = $line['mmsi'];
616 835
 			    $data['speed'] = $line['sog'];
617
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
836
+			    if ($line['heading'] != '511') {
837
+			    	$data['heading'] = $line['heading'];
838
+			    }
618 839
 			    $data['latitude'] = $line['latitude'];
619 840
 			    $data['longitude'] = $line['longitude'];
620 841
 			    $data['type_id'] = $line['shiptype'];
@@ -622,7 +843,9 @@  discard block
 block discarded – undo
622 843
 			    $data['datetime'] = $line['time'];
623 844
 			    $data['format_source'] = 'boatbeaconapp';
624 845
 			    $data['id_source'] = $id_source;
625
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
846
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
847
+			    	$data['noarchive'] = true;
848
+			    }
626 849
 			    $MI->add($data);
627 850
 			    unset($data);
628 851
 			}
@@ -643,22 +866,44 @@  discard block
 block discarded – undo
643 866
 		if (isset($all_data['features'][0]['id'])) {
644 867
 		    foreach ($all_data['features'] as $line) {
645 868
 			$data = array();
646
-			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
647
-			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
648
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = $line['properties']['mmsi'];
649
-			if (isset($line['properties']['imo'])) $data['mmsi'] = $line['properties']['imo'];
650
-			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
651
-			if (isset($line['properties']['heading'])) $data['heading'] = $line['properties']['heading'];
869
+			if (isset($line['properties']['name'])) {
870
+				$data['ident'] = $line['properties']['name'];
871
+			}
872
+			if (isset($line['properties']['callsign'])) {
873
+				$data['callsign'] = $line['properties']['callsign'];
874
+			}
875
+			if (isset($line['properties']['mmsi'])) {
876
+				$data['mmsi'] = $line['properties']['mmsi'];
877
+			}
878
+			if (isset($line['properties']['imo'])) {
879
+				$data['mmsi'] = $line['properties']['imo'];
880
+			}
881
+			if (isset($line['properties']['speed'])) {
882
+				$data['speed'] = $line['properties']['speed'];
883
+			}
884
+			if (isset($line['properties']['heading'])) {
885
+				$data['heading'] = $line['properties']['heading'];
886
+			}
652 887
 			$data['latitude'] = $line['geometry']['coordinates'][1];
653 888
 			$data['longitude'] = $line['geometry']['coordinates'][0];
654
-			if (isset($line['properties']['vesselType'])) $data['type'] = $line['properties']['vesselType'];
655
-			if (isset($line['properties']['destination'])) $data['arrival_code'] = $line['properties']['destination'];
656
-			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') $data['arrival_date'] = $line['properties']['eta'];
889
+			if (isset($line['properties']['vesselType'])) {
890
+				$data['type'] = $line['properties']['vesselType'];
891
+			}
892
+			if (isset($line['properties']['destination'])) {
893
+				$data['arrival_code'] = $line['properties']['destination'];
894
+			}
895
+			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') {
896
+				$data['arrival_date'] = $line['properties']['eta'];
897
+			}
657 898
 			$data['format_source'] = 'boatnerd';
658 899
 			$data['id_source'] = $id_source;
659 900
 			$data['datetime'] = date('Y-m-d H:i:s');
660
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
661
-			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
901
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
902
+				$data['noarchive'] = true;
903
+			}
904
+			if ($line['properties']['vesselType'] != 'Navigation Aid') {
905
+				$MI->add($data);
906
+			}
662 907
 			unset($data);
663 908
 		    }
664 909
 		}
@@ -674,7 +919,9 @@  discard block
 block discarded – undo
674 919
 	    echo 'download...';
675 920
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
676 921
 	    echo 'done !'."\n";
677
-	    if ($buffer != '') $reset = 0;
922
+	    if ($buffer != '') {
923
+	    	$reset = 0;
924
+	    }
678 925
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
679 926
 	    $buffer = explode('\n',$buffer);
680 927
 	    foreach ($buffer as $line) {
@@ -699,7 +946,9 @@  discard block
 block discarded – undo
699 946
 		    //$data['etaTime'] = substr($line,135,5);
700 947
 		    $data['format_source'] = 'shipplotter';
701 948
     		    $data['id_source'] = $id_source;
702
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
949
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
950
+		    	$data['noarchive'] = true;
951
+		    }
703 952
 		    //print_r($data);
704 953
 		    echo 'Add...'."\n";
705 954
 		    $MI->add($data);
@@ -733,16 +982,28 @@  discard block
 block discarded – undo
733 982
     		    $line = explode(':', $line);
734 983
     		    if (count($line) > 30 && $line[0] != 'callsign') {
735 984
 			$data = array();
736
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
737
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
985
+			if (isset($line[37]) && $line[37] != '') {
986
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
987
+			} else {
988
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
989
+			}
738 990
 			$data['pilot_id'] = $line[1];
739 991
 			$data['pilot_name'] = $line[2];
740 992
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
741 993
 			$data['ident'] = $line[0]; // ident
742
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
994
+			if ($line[7] != '' && $line[7] != 0) {
995
+				$data['altitude'] = $line[7];
996
+			}
997
+			// altitude
743 998
 			$data['speed'] = $line[8]; // speed
744
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
745
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
999
+			if (isset($line[45])) {
1000
+				$data['heading'] = $line[45];
1001
+			}
1002
+			// heading
1003
+			elseif (isset($line[38])) {
1004
+				$data['heading'] = $line[38];
1005
+			}
1006
+			// heading
746 1007
 			$data['latitude'] = $line[5]; // lat
747 1008
 	        	$data['longitude'] = $line[6]; // long
748 1009
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -758,7 +1019,9 @@  discard block
 block discarded – undo
758 1019
 			$data['frequency'] = $line[4];
759 1020
 			$data['type'] = $line[18];
760 1021
 			$data['range'] = $line[19];
761
-			if (isset($line[35])) $data['info'] = $line[35];
1022
+			if (isset($line[35])) {
1023
+				$data['info'] = $line[35];
1024
+			}
762 1025
     			$data['id_source'] = $id_source;
763 1026
 	    		//$data['arrival_airport_time'] = ;
764 1027
 	    		if ($line[9] != '') {
@@ -772,27 +1035,47 @@  discard block
 block discarded – undo
772 1035
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
773 1036
 	    		*/
774 1037
 	    		$data['format_source'] = $value['format'];
775
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
776
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
777
-    			if ($line[3] == 'PILOT') $SI->add($data);
778
-			elseif ($line[3] == 'ATC') {
1038
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1039
+				$data['noarchive'] = true;
1040
+			}
1041
+			if (isset($value['name']) && $value['name'] != '') {
1042
+				$data['source_name'] = $value['name'];
1043
+			}
1044
+    			if ($line[3] == 'PILOT') {
1045
+    				$SI->add($data);
1046
+    			} elseif ($line[3] == 'ATC') {
779 1047
 				//print_r($data);
780 1048
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
781 1049
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
782 1050
 				$typec = substr($data['ident'],-3);
783
-				if ($typec == 'APP') $data['type'] = 'Approach';
784
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
785
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
786
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
787
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
788
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
789
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
790
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
791
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
792
-				if (!isset($data['source_name'])) $data['source_name'] = '';
1051
+				if ($typec == 'APP') {
1052
+					$data['type'] = 'Approach';
1053
+				} elseif ($typec == 'TWR') {
1054
+					$data['type'] = 'Tower';
1055
+				} elseif ($typec == 'OBS') {
1056
+					$data['type'] = 'Observer';
1057
+				} elseif ($typec == 'GND') {
1058
+					$data['type'] = 'Ground';
1059
+				} elseif ($typec == 'DEL') {
1060
+					$data['type'] = 'Delivery';
1061
+				} elseif ($typec == 'DEP') {
1062
+					$data['type'] = 'Departure';
1063
+				} elseif ($typec == 'FSS') {
1064
+					$data['type'] = 'Flight Service Station';
1065
+				} elseif ($typec == 'CTR') {
1066
+					$data['type'] = 'Control Radar or Centre';
1067
+				} elseif ($data['type'] == '') {
1068
+					$data['type'] = 'Observer';
1069
+				}
1070
+				if (!isset($data['source_name'])) {
1071
+					$data['source_name'] = '';
1072
+				}
793 1073
 				if (isset($ATC)) {
794
-					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) echo $ATC->update($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
795
-					else echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
1074
+					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) {
1075
+						echo $ATC->update($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
1076
+					} else {
1077
+						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']);
1078
+					}
796 1079
 				}
797 1080
 			}
798 1081
     			unset($data);
@@ -819,14 +1102,20 @@  discard block
 block discarded – undo
819 1102
 			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
820 1103
 			$data['latitude'] = (float)$line['pktLatitude'];
821 1104
 			$data['longitude'] = (float)$line['pktLongitude'];
822
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
823
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
1105
+			if ((float)$line['pktTrack'] != 0) {
1106
+				$data['heading'] = (float)$line['pktTrack'];
1107
+			}
1108
+			if ((int)$line['pktSpeed'] != 0) {
1109
+				$data['speed'] = (int)$line['pktSpeed'];
1110
+			}
824 1111
 			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
825 1112
 			$data['altitude_relative'] = 'AMSL';
826 1113
 			$data['pilot_id'] = (int)$line['pktPilotID'];
827 1114
 			$data['aircraft_icao'] = 'PARAGLIDER';
828 1115
 			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
829
-			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
1116
+			if (isset($pilot_data[4])) {
1117
+				$data['pilot_name'] = $pilot_data[4];
1118
+			}
830 1119
 			$data['format_source'] = $value['format'];
831 1120
 			$SI->add($data);
832 1121
 			unset($data);
@@ -874,25 +1163,59 @@  discard block
 block discarded – undo
874 1163
 		    foreach ($all_data['acList'] as $line) {
875 1164
 			$data = array();
876 1165
 			$data['hex'] = $line['Icao']; // hex
877
-			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
878
-			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
879
-			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
880
-			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
881
-			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
882
-			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1166
+			if (isset($line['Call'])) {
1167
+				$data['ident'] = $line['Call'];
1168
+			}
1169
+			// ident
1170
+			if (isset($line['Alt'])) {
1171
+				$data['altitude'] = $line['Alt'];
1172
+			}
1173
+			// altitude
1174
+			if (isset($line['Spd'])) {
1175
+				$data['speed'] = $line['Spd'];
1176
+			}
1177
+			// speed
1178
+			if (isset($line['Trak'])) {
1179
+				$data['heading'] = $line['Trak'];
1180
+			}
1181
+			// heading
1182
+			if (isset($line['Lat'])) {
1183
+				$data['latitude'] = $line['Lat'];
1184
+			}
1185
+			// lat
1186
+			if (isset($line['Long'])) {
1187
+				$data['longitude'] = $line['Long'];
1188
+			}
1189
+			// long
883 1190
 			//$data['verticalrate'] = $line['']; // verticale rate
884
-			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1191
+			if (isset($line['Sqk'])) {
1192
+				$data['squawk'] = $line['Sqk'];
1193
+			}
1194
+			// squawk
885 1195
 			$data['emergency'] = ''; // emergency
886
-			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
887
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
888
-			else $data['datetime'] = date('Y-m-d H:i:s');
1196
+			if (isset($line['Reg'])) {
1197
+				$data['registration'] = $line['Reg'];
1198
+			}
1199
+			if (isset($line['PosTime'])) {
1200
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1201
+			} else {
1202
+				$data['datetime'] = date('Y-m-d H:i:s');
1203
+			}
889 1204
 			//$data['datetime'] = date('Y-m-d H:i:s');
890
-			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1205
+			if (isset($line['Type'])) {
1206
+				$data['aircraft_icao'] = $line['Type'];
1207
+			}
891 1208
 			$data['format_source'] = 'aircraftlistjson';
892 1209
 			$data['id_source'] = $id_source;
893
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
894
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
895
-			if (isset($data['latitude'])) $SI->add($data);
1210
+			if (isset($value['name']) && $value['name'] != '') {
1211
+				$data['source_name'] = $value['name'];
1212
+			}
1213
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1214
+				$data['noarchive'] = true;
1215
+			}
1216
+			if (isset($data['latitude'])) {
1217
+				$SI->add($data);
1218
+			}
896 1219
 			unset($data);
897 1220
 		    }
898 1221
 		} elseif (is_array($all_data)) {
@@ -909,17 +1232,26 @@  discard block
 block discarded – undo
909 1232
 			$data['verticalrate'] = $line['vrt']; // verticale rate
910 1233
 			$data['squawk'] = $line['squawk']; // squawk
911 1234
 			$data['emergency'] = ''; // emergency
912
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
913
-			else $data['datetime'] = date('Y-m-d H:i:s');
1235
+			if (isset($line['PosTime'])) {
1236
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1237
+			} else {
1238
+				$data['datetime'] = date('Y-m-d H:i:s');
1239
+			}
914 1240
 			$data['format_source'] = 'aircraftlistjson';
915 1241
 			$data['id_source'] = $id_source;
916
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
917
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1242
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1243
+				$data['noarchive'] = true;
1244
+			}
1245
+			if (isset($value['name']) && $value['name'] != '') {
1246
+				$data['source_name'] = $value['name'];
1247
+			}
918 1248
 			$SI->add($data);
919 1249
 			unset($data);
920 1250
 		    }
921 1251
 		}
922
-	    } elseif ($globalDebug) echo 'No data'."\n";
1252
+	    } elseif ($globalDebug) {
1253
+	    	echo 'No data'."\n";
1254
+	    }
923 1255
     	    //$last_exec['aircraftlistjson'] = time();
924 1256
     	    $last_exec[$id]['last'] = time();
925 1257
     	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
@@ -955,8 +1287,12 @@  discard block
 block discarded – undo
955 1287
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
956 1288
 	    	    $data['format_source'] = 'planeupdatefaa';
957 1289
     		    $data['id_source'] = $id_source;
958
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
959
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1290
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1291
+		    	$data['noarchive'] = true;
1292
+		    }
1293
+		    if (isset($value['name']) && $value['name'] != '') {
1294
+		    	$data['source_name'] = $value['name'];
1295
+		    }
960 1296
 		    $SI->add($data);
961 1297
 		    unset($data);
962 1298
 		}
@@ -990,7 +1326,9 @@  discard block
 block discarded – undo
990 1326
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
991 1327
 		    $data['format_source'] = 'opensky';
992 1328
 		    $data['id_source'] = $id_source;
993
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1329
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1330
+		    	$data['noarchive'] = true;
1331
+		    }
994 1332
 		    $SI->add($data);
995 1333
 		    unset($data);
996 1334
 		}
@@ -1007,7 +1345,9 @@  discard block
 block discarded – undo
1007 1345
 	    //$buffer = $Common->getData($hosts[$id]);
1008 1346
 	    $buffer = $Common->getData($value['host']);
1009 1347
 	    $all_data = json_decode($buffer,true);
1010
-	    if (!empty($all_data)) $reset = 0;
1348
+	    if (!empty($all_data)) {
1349
+	    	$reset = 0;
1350
+	    }
1011 1351
 	    foreach ($all_data as $key => $line) {
1012 1352
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
1013 1353
 		    $data = array();
@@ -1028,8 +1368,12 @@  discard block
 block discarded – undo
1028 1368
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1029 1369
 	    	    $data['format_source'] = 'fr24json';
1030 1370
     		    $data['id_source'] = $id_source;
1031
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1032
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1371
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1372
+		    	$data['noarchive'] = true;
1373
+		    }
1374
+		    if (isset($value['name']) && $value['name'] != '') {
1375
+		    	$data['source_name'] = $value['name'];
1376
+		    }
1033 1377
 		    $SI->add($data);
1034 1378
 		    unset($data);
1035 1379
 		}
@@ -1058,24 +1402,42 @@  discard block
 block discarded – undo
1058 1402
 		    if (isset($line['inf'])) {
1059 1403
 			$data = array();
1060 1404
 			$data['hex'] = $line['inf']['ia'];
1061
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1405
+			if (isset($line['inf']['cs'])) {
1406
+				$data['ident'] = $line['inf']['cs'];
1407
+			}
1408
+			//$line[13]
1062 1409
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1063
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1064
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1410
+	    		if (isset($line['inf']['gs'])) {
1411
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1412
+	    		}
1413
+	    		// speed
1414
+	    		if (isset($line['inf']['tr'])) {
1415
+	    			$data['heading'] = $line['inf']['tr'];
1416
+	    		}
1417
+	    		// heading
1065 1418
 	    		$data['latitude'] = $line['pt'][0]; // lat
1066 1419
 	    		$data['longitude'] = $line['pt'][1]; // long
1067 1420
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1068
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1421
+	    		if (isset($line['inf']['sq'])) {
1422
+	    			$data['squawk'] = $line['inf']['sq'];
1423
+	    		}
1424
+	    		// squawk
1069 1425
 	    		//$data['aircraft_icao'] = $line[8];
1070
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1426
+	    		if (isset($line['inf']['rc'])) {
1427
+	    			$data['registration'] = $line['inf']['rc'];
1428
+	    		}
1071 1429
 			//$data['departure_airport_iata'] = $line[11];
1072 1430
 			//$data['arrival_airport_iata'] = $line[12];
1073 1431
 	    		//$data['emergency'] = ''; // emergency
1074 1432
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1075 1433
 	    		$data['format_source'] = 'radarvirtueljson';
1076 1434
     			$data['id_source'] = $id_source;
1077
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1078
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1435
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1436
+				$data['noarchive'] = true;
1437
+			}
1438
+			if (isset($value['name']) && $value['name'] != '') {
1439
+				$data['source_name'] = $value['name'];
1440
+			}
1079 1441
 			$SI->add($data);
1080 1442
 			unset($data);
1081 1443
 		    }
@@ -1101,30 +1463,65 @@  discard block
 block discarded – undo
1101 1463
 		    $data['id'] = $line['id'];
1102 1464
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1103 1465
 		    $data['ident'] = $line['callsign']; // ident
1104
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1105
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1106
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1107
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1108
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1109
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1466
+		    if (isset($line['pilotid'])) {
1467
+		    	$data['pilot_id'] = $line['pilotid'];
1468
+		    }
1469
+		    // pilot id
1470
+		    if (isset($line['name'])) {
1471
+		    	$data['pilot_name'] = $line['name'];
1472
+		    }
1473
+		    // pilot name
1474
+		    if (isset($line['alt'])) {
1475
+		    	$data['altitude'] = $line['alt'];
1476
+		    }
1477
+		    // altitude
1478
+		    if (isset($line['gs'])) {
1479
+		    	$data['speed'] = $line['gs'];
1480
+		    }
1481
+		    // speed
1482
+		    if (isset($line['heading'])) {
1483
+		    	$data['heading'] = $line['heading'];
1484
+		    }
1485
+		    // heading
1486
+		    if (isset($line['route'])) {
1487
+		    	$data['waypoints'] = $line['route'];
1488
+		    }
1489
+		    // route
1110 1490
 		    $data['latitude'] = $line['lat']; // lat
1111 1491
 		    $data['longitude'] = $line['lon']; // long
1112 1492
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
1113 1493
 		    //$data['squawk'] = $line['squawk']; // squawk
1114 1494
 		    //$data['emergency'] = ''; // emergency
1115
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1116
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1117
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1495
+		    if (isset($line['depicao'])) {
1496
+		    	$data['departure_airport_icao'] = $line['depicao'];
1497
+		    }
1498
+		    if (isset($line['deptime'])) {
1499
+		    	$data['departure_airport_time'] = $line['deptime'];
1500
+		    }
1501
+		    if (isset($line['arricao'])) {
1502
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1503
+		    }
1118 1504
 		    //$data['arrival_airport_time'] = $line['arrtime'];
1119
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1120
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1121
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
1122
-		    else $data['info'] = '';
1505
+		    if (isset($line['aircraft'])) {
1506
+		    	$data['aircraft_icao'] = $line['aircraft'];
1507
+		    }
1508
+		    if (isset($line['transponder'])) {
1509
+		    	$data['squawk'] = $line['transponder'];
1510
+		    }
1511
+		    if (isset($line['atis'])) {
1512
+		    	$data['info'] = $line['atis'];
1513
+		    } else {
1514
+		    	$data['info'] = '';
1515
+		    }
1123 1516
 		    $data['format_source'] = 'pireps';
1124 1517
     		    $data['id_source'] = $id_source;
1125 1518
 		    $data['datetime'] = date('Y-m-d H:i:s');
1126
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1127
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1519
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1520
+		    	$data['noarchive'] = true;
1521
+		    }
1522
+		    if (isset($value['name']) && $value['name'] != '') {
1523
+		    	$data['source_name'] = $value['name'];
1524
+		    }
1128 1525
 		    if ($line['icon'] == 'plane') {
1129 1526
 			$SI->add($data);
1130 1527
 		    //    print_r($data);
@@ -1133,16 +1530,28 @@  discard block
 block discarded – undo
1133 1530
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1134 1531
 			$typec = substr($data['ident'],-3);
1135 1532
 			$data['type'] = '';
1136
-			if ($typec == 'APP') $data['type'] = 'Approach';
1137
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
1138
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
1139
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
1140
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
1141
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
1142
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
1143
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
1144
-			else $data['type'] = 'Observer';
1145
-			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']);
1533
+			if ($typec == 'APP') {
1534
+				$data['type'] = 'Approach';
1535
+			} elseif ($typec == 'TWR') {
1536
+				$data['type'] = 'Tower';
1537
+			} elseif ($typec == 'OBS') {
1538
+				$data['type'] = 'Observer';
1539
+			} elseif ($typec == 'GND') {
1540
+				$data['type'] = 'Ground';
1541
+			} elseif ($typec == 'DEL') {
1542
+				$data['type'] = 'Delivery';
1543
+			} elseif ($typec == 'DEP') {
1544
+				$data['type'] = 'Departure';
1545
+			} elseif ($typec == 'FSS') {
1546
+				$data['type'] = 'Flight Service Station';
1547
+			} elseif ($typec == 'CTR') {
1548
+				$data['type'] = 'Control Radar or Centre';
1549
+			} else {
1550
+				$data['type'] = 'Observer';
1551
+			}
1552
+			if (isset($ATC)) {
1553
+				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']);
1554
+			}
1146 1555
 		    }
1147 1556
 		    unset($data);
1148 1557
 		}
@@ -1157,7 +1566,9 @@  discard block
 block discarded – undo
1157 1566
 	    )
1158 1567
 	) {
1159 1568
 	    //$buffer = $Common->getData($hosts[$id]);
1160
-	    if ($globalDebug) echo 'Get Data...'."\n";
1569
+	    if ($globalDebug) {
1570
+	    	echo 'Get Data...'."\n";
1571
+	    }
1161 1572
 	    $buffer = $Common->getData($value['host']);
1162 1573
 	    $all_data = json_decode($buffer,true);
1163 1574
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1165,10 +1576,16 @@  discard block
 block discarded – undo
1165 1576
 		foreach ($all_data as $line) {
1166 1577
 	    	    $data = array();
1167 1578
 	    	    //$data['id'] = $line['id']; // id not usable
1168
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1579
+	    	    if (isset($line['pilotid'])) {
1580
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1581
+	    	    }
1169 1582
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1170
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1171
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1583
+	    	    if (isset($line['pilotname'])) {
1584
+	    	    	$data['pilot_name'] = $line['pilotname'];
1585
+	    	    }
1586
+	    	    if (isset($line['pilotid'])) {
1587
+	    	    	$data['pilot_id'] = $line['pilotid'];
1588
+	    	    }
1172 1589
 	    	    $data['ident'] = $line['flightnum']; // ident
1173 1590
 	    	    $data['altitude'] = $line['alt']; // altitude
1174 1591
 	    	    $data['speed'] = $line['gs']; // speed
@@ -1184,34 +1601,52 @@  discard block
 block discarded – undo
1184 1601
 	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1185 1602
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1186 1603
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1187
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1604
+	    	    } else {
1605
+	    	    	$data['datetime'] = date('Y-m-d H:i:s');
1606
+	    	    }
1188 1607
 	    	    $data['departure_airport_icao'] = $line['depicao'];
1189 1608
 	    	    $data['departure_airport_time'] = $line['deptime'];
1190 1609
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
1191 1610
     		    $data['arrival_airport_time'] = $line['arrtime'];
1192 1611
     		    $data['registration'] = $line['aircraft'];
1193
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1194
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1612
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1613
+		    	$data['noarchive'] = true;
1614
+		    }
1615
+		    if (isset($line['route'])) {
1616
+		    	$data['waypoints'] = $line['route'];
1617
+		    }
1618
+		    // route
1195 1619
 		    if (isset($line['aircraftname'])) {
1196 1620
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1197 1621
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1198 1622
 	    		$aircraft_data = explode('-',$line['aircraftname']);
1199
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1200
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1201
-	    		else {
1623
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) {
1624
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1625
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) {
1626
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1627
+	    		} else {
1202 1628
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1203
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1204
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1629
+	    		    if (isset($aircraft_data[1])) {
1630
+	    		    	$data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1631
+	    		    } else {
1632
+	    		    	$data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1633
+	    		    }
1205 1634
 	    		}
1206 1635
 	    	    }
1207
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1636
+    		    if (isset($line['route'])) {
1637
+    		    	$data['waypoints'] = $line['route'];
1638
+    		    }
1208 1639
     		    $data['id_source'] = $id_source;
1209 1640
 	    	    $data['format_source'] = 'phpvmacars';
1210
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1641
+		    if (isset($value['name']) && $value['name'] != '') {
1642
+		    	$data['source_name'] = $value['name'];
1643
+		    }
1211 1644
 		    $SI->add($data);
1212 1645
 		    unset($data);
1213 1646
 		}
1214
-		if ($globalDebug) echo 'No more data...'."\n";
1647
+		if ($globalDebug) {
1648
+			echo 'No more data...'."\n";
1649
+		}
1215 1650
 		unset($buffer);
1216 1651
 		unset($all_data);
1217 1652
 	    }
@@ -1224,7 +1659,9 @@  discard block
 block discarded – undo
1224 1659
 	    )
1225 1660
 	) {
1226 1661
 	    //$buffer = $Common->getData($hosts[$id]);
1227
-	    if ($globalDebug) echo 'Get Data...'."\n";
1662
+	    if ($globalDebug) {
1663
+	    	echo 'Get Data...'."\n";
1664
+	    }
1228 1665
 	    $buffer = $Common->getData($value['host']);
1229 1666
 	    $all_data = json_decode($buffer,true);
1230 1667
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1253,16 +1690,25 @@  discard block
 block discarded – undo
1253 1690
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
1254 1691
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
1255 1692
     		    //$data['registration'] = $line['aircraft'];
1256
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1693
+		    if (isset($line['route'])) {
1694
+		    	$data['waypoints'] = $line['route'];
1695
+		    }
1696
+		    // route
1257 1697
 	    	    $data['aircraft_icao'] = $line['plane_type'];
1258 1698
     		    $data['id_source'] = $id_source;
1259 1699
 	    	    $data['format_source'] = 'vam';
1260
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1261
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1700
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1701
+		    	$data['noarchive'] = true;
1702
+		    }
1703
+		    if (isset($value['name']) && $value['name'] != '') {
1704
+		    	$data['source_name'] = $value['name'];
1705
+		    }
1262 1706
 		    $SI->add($data);
1263 1707
 		    unset($data);
1264 1708
 		}
1265
-		if ($globalDebug) echo 'No more data...'."\n";
1709
+		if ($globalDebug) {
1710
+			echo 'No more data...'."\n";
1711
+		}
1266 1712
 		unset($buffer);
1267 1713
 		unset($all_data);
1268 1714
 	    }
@@ -1275,7 +1721,9 @@  discard block
 block discarded – undo
1275 1721
 	    )
1276 1722
 	) {
1277 1723
 	    //$buffer = $Common->getData($hosts[$id]);
1278
-	    if ($globalDebug) echo 'Get Data...'."\n";
1724
+	    if ($globalDebug) {
1725
+	    	echo 'Get Data...'."\n";
1726
+	    }
1279 1727
 	    $buffer = $Common->getData($value['host']);
1280 1728
 	    $all_data = json_decode($buffer,true);
1281 1729
 	    if ($buffer != '') {
@@ -1293,18 +1741,24 @@  discard block
 block discarded – undo
1293 1741
 			$data['id_source'] = $id_source;
1294 1742
 			$data['format_source'] = 'blitzortung';
1295 1743
 			$SI->add($data);
1296
-			if ($globalDebug) echo '☈ Lightning added'."\n";
1744
+			if ($globalDebug) {
1745
+				echo '☈ Lightning added'."\n";
1746
+			}
1297 1747
 			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1298 1748
 			unset($data);
1299 1749
 		    }
1300 1750
 		}
1301
-		if ($globalDebug) echo 'No more data...'."\n";
1751
+		if ($globalDebug) {
1752
+			echo 'No more data...'."\n";
1753
+		}
1302 1754
 		unset($buffer);
1303 1755
 	    }
1304 1756
 	    $last_exec[$id]['last'] = time();
1305 1757
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1306 1758
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'famaprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais' || $value['format'] == 'vrstcp') {
1307
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1759
+	    if (function_exists('pcntl_fork')) {
1760
+	    	pcntl_signal_dispatch();
1761
+	    }
1308 1762
     	    //$last_exec[$id]['last'] = time();
1309 1763
 
1310 1764
 	    //$read = array( $sockets[$id] );
@@ -1312,7 +1766,9 @@  discard block
 block discarded – undo
1312 1766
 	    $write = NULL;
1313 1767
 	    $e = NULL;
1314 1768
 	    $n = socket_select($read, $write, $e, $timeout);
1315
-	    if ($e != NULL) var_dump($e);
1769
+	    if ($e != NULL) {
1770
+	    	var_dump($e);
1771
+	    }
1316 1772
 	    if ($n > 0) {
1317 1773
 		$reset = 0;
1318 1774
 		foreach ($read as $nb => $r) {
@@ -1334,13 +1790,17 @@  discard block
 block discarded – undo
1334 1790
 		    if ($buffer !== FALSE) {
1335 1791
 			if ($format == 'vrstcp') {
1336 1792
 			    $buffer = explode('},{',$buffer);
1337
-			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1793
+			} else {
1794
+				$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1795
+			}
1338 1796
 		    }
1339 1797
 		    // SBS format is CSV format
1340 1798
 		    if ($buffer !== FALSE && $buffer !== '') {
1341 1799
 			$tt[$format] = 0;
1342 1800
 			if ($format == 'acarssbs3') {
1343
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1801
+			    if ($globalDebug) {
1802
+			    	echo 'ACARS : '.$buffer."\n";
1803
+			    }
1344 1804
 			    $ACARS->add(trim($buffer));
1345 1805
 			    $ACARS->deleteLiveAcarsData();
1346 1806
 			} elseif ($format == 'raw') {
@@ -1349,30 +1809,70 @@  discard block
 block discarded – undo
1349 1809
 			    if (is_array($data)) {
1350 1810
 				$data['datetime'] = date('Y-m-d H:i:s');
1351 1811
 				$data['format_source'] = 'raw';
1352
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1353
-				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1354
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1355
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1812
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1813
+					$data['source_name'] = $globalSources[$nb]['name'];
1814
+				}
1815
+				if (isset($globalSources[$nb]['sourcestats'])) {
1816
+					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1817
+				}
1818
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1819
+					$data['noarchive'] = true;
1820
+				}
1821
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1822
+					$SI->add($data);
1823
+				}
1356 1824
 			    }
1357 1825
 			} elseif ($format == 'ais') {
1358 1826
 			    $ais_data = $AIS->parse_line(trim($buffer));
1359 1827
 			    $data = array();
1360
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1361
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1362
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1363
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1364
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1365
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1366
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1367
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1368
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1369
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1370
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1371
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1372
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1373
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1374
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1375
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1828
+			    if (isset($ais_data['ident'])) {
1829
+			    	$data['ident'] = $ais_data['ident'];
1830
+			    }
1831
+			    if (isset($ais_data['mmsi'])) {
1832
+			    	$data['mmsi'] = $ais_data['mmsi'];
1833
+			    }
1834
+			    if (isset($ais_data['speed'])) {
1835
+			    	$data['speed'] = $ais_data['speed'];
1836
+			    }
1837
+			    if (isset($ais_data['heading'])) {
1838
+			    	$data['heading'] = $ais_data['heading'];
1839
+			    }
1840
+			    if (isset($ais_data['latitude'])) {
1841
+			    	$data['latitude'] = $ais_data['latitude'];
1842
+			    }
1843
+			    if (isset($ais_data['longitude'])) {
1844
+			    	$data['longitude'] = $ais_data['longitude'];
1845
+			    }
1846
+			    if (isset($ais_data['status'])) {
1847
+			    	$data['status'] = $ais_data['status'];
1848
+			    }
1849
+			    if (isset($ais_data['statusid'])) {
1850
+			    	$data['status_id'] = $ais_data['statusid'];
1851
+			    }
1852
+			    if (isset($ais_data['type'])) {
1853
+			    	$data['type'] = $ais_data['type'];
1854
+			    }
1855
+			    if (isset($ais_data['imo'])) {
1856
+			    	$data['imo'] = $ais_data['imo'];
1857
+			    }
1858
+			    if (isset($ais_data['callsign'])) {
1859
+			    	$data['callsign'] = $ais_data['callsign'];
1860
+			    }
1861
+			    if (isset($ais_data['destination'])) {
1862
+			    	$data['arrival_code'] = $ais_data['destination'];
1863
+			    }
1864
+			    if (isset($ais_data['eta_ts'])) {
1865
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1866
+			    }
1867
+			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1868
+			    	$data['noarchive'] = true;
1869
+			    }
1870
+			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1871
+			    	$data['source_name'] = $globalSources[$nb]['name'];
1872
+			    }
1873
+			    if (isset($globalSources[$nb]['sourcestats'])) {
1874
+			    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1875
+			    }
1376 1876
 
1377 1877
 			    if (isset($ais_data['timestamp'])) {
1378 1878
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1381,7 +1881,9 @@  discard block
 block discarded – undo
1381 1881
 			    }
1382 1882
 			    $data['format_source'] = 'aisnmea';
1383 1883
     			    $data['id_source'] = $id_source;
1384
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1884
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
1885
+			    	$MI->add($data);
1886
+			    }
1385 1887
 			    unset($data);
1386 1888
                         } elseif ($format == 'flightgearsp') {
1387 1889
                     	    //echo $buffer."\n";
@@ -1399,12 +1901,18 @@  discard block
 block discarded – undo
1399 1901
 				$data['speed'] = round($line[5]*1.94384);
1400 1902
 				$data['datetime'] = date('Y-m-d H:i:s');
1401 1903
 				$data['format_source'] = 'flightgearsp';
1402
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1403
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1904
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1905
+					$data['noarchive'] = true;
1906
+				}
1907
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1908
+					$SI->add($data);
1909
+				}
1404 1910
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1405 1911
 			    }
1406 1912
                         } elseif ($format == 'acars') {
1407
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1913
+                    	    if ($globalDebug) {
1914
+                    	    	echo 'ACARS : '.$buffer."\n";
1915
+                    	    }
1408 1916
 			    $ACARS->add(trim($buffer));
1409 1917
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1410 1918
 			    $ACARS->deleteLiveAcarsData();
@@ -1425,8 +1933,12 @@  discard block
 block discarded – undo
1425 1933
 				    $aircraft_type = $line[10];
1426 1934
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1427 1935
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1428
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1429
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1936
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1937
+				    	$data['noarchive'] = true;
1938
+				    }
1939
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1940
+				    	$SI->add($data);
1941
+				    }
1430 1942
 				}
1431 1943
 			    }
1432 1944
 			} elseif ($format == 'beast') {
@@ -1436,28 +1948,62 @@  discard block
 block discarded – undo
1436 1948
 			    foreach($buffer as $all_data) {
1437 1949
 				$line = json_decode('{'.$all_data.'}',true);
1438 1950
 				$data = array();
1439
-				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1440
-				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1441
-				if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1442
-				if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1443
-				if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1444
-				if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1445
-				if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1951
+				if (isset($line['Icao'])) {
1952
+					$data['hex'] = $line['Icao'];
1953
+				}
1954
+				// hex
1955
+				if (isset($line['Call'])) {
1956
+					$data['ident'] = $line['Call'];
1957
+				}
1958
+				// ident
1959
+				if (isset($line['Alt'])) {
1960
+					$data['altitude'] = $line['Alt'];
1961
+				}
1962
+				// altitude
1963
+				if (isset($line['Spd'])) {
1964
+					$data['speed'] = $line['Spd'];
1965
+				}
1966
+				// speed
1967
+				if (isset($line['Trak'])) {
1968
+					$data['heading'] = $line['Trak'];
1969
+				}
1970
+				// heading
1971
+				if (isset($line['Lat'])) {
1972
+					$data['latitude'] = $line['Lat'];
1973
+				}
1974
+				// lat
1975
+				if (isset($line['Long'])) {
1976
+					$data['longitude'] = $line['Long'];
1977
+				}
1978
+				// long
1446 1979
 				//$data['verticalrate'] = $line['']; // verticale rate
1447
-				if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1980
+				if (isset($line['Sqk'])) {
1981
+					$data['squawk'] = $line['Sqk'];
1982
+				}
1983
+				// squawk
1448 1984
 				$data['emergency'] = ''; // emergency
1449
-				if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
1985
+				if (isset($line['Reg'])) {
1986
+					$data['registration'] = $line['Reg'];
1987
+				}
1450 1988
 				/*
1451 1989
 				if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
1452 1990
 				else $data['datetime'] = date('Y-m-d H:i:s');
1453 1991
 				*/
1454 1992
 				$data['datetime'] = date('Y-m-d H:i:s');
1455
-				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1993
+				if (isset($line['Type'])) {
1994
+					$data['aircraft_icao'] = $line['Type'];
1995
+				}
1456 1996
 		    		$data['format_source'] = 'vrstcp';
1457 1997
 				$data['id_source'] = $id_source;
1458
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1459
-				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1460
-				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1998
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1999
+					$data['noarchive'] = true;
2000
+				}
2001
+				if (isset($value['name']) && $value['name'] != '') {
2002
+					$data['source_name'] = $value['name'];
2003
+				}
2004
+				if (isset($data['latitude']) && isset($data['hex'])) {
2005
+					$SI->add($data);
2006
+				}
1461 2007
 				unset($data);
1462 2008
 			    }
1463 2009
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
@@ -1470,22 +2016,46 @@  discard block
 block discarded – undo
1470 2016
     				$data['hex'] = $lined['hexid'];
1471 2017
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1472 2018
     				$data['datetime'] = date('Y-m-d H:i:s');;
1473
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1474
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1475
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1476
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1477
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1478
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1479
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
2019
+    				if (isset($lined['ident'])) {
2020
+    					$data['ident'] = $lined['ident'];
2021
+    				}
2022
+    				if (isset($lined['lat'])) {
2023
+    					$data['latitude'] = $lined['lat'];
2024
+    				}
2025
+    				if (isset($lined['lon'])) {
2026
+    					$data['longitude'] = $lined['lon'];
2027
+    				}
2028
+    				if (isset($lined['speed'])) {
2029
+    					$data['speed'] = $lined['speed'];
2030
+    				}
2031
+    				if (isset($lined['squawk'])) {
2032
+    					$data['squawk'] = $lined['squawk'];
2033
+    				}
2034
+    				if (isset($lined['alt'])) {
2035
+    					$data['altitude'] = $lined['alt'];
2036
+    				}
2037
+    				if (isset($lined['heading'])) {
2038
+    					$data['heading'] = $lined['heading'];
2039
+    				}
1480 2040
     				$data['id_source'] = $id_source;
1481 2041
     				$data['format_source'] = 'tsv';
1482
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1483
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1484
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1485
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2042
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2043
+    					$data['source_name'] = $globalSources[$nb]['name'];
2044
+    				}
2045
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2046
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2047
+    				}
2048
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2049
+					$data['noarchive'] = true;
2050
+				}
2051
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2052
+    					$SI->add($data);
2053
+    				}
1486 2054
     				unset($lined);
1487 2055
     				unset($data);
1488
-    			    } else $error = true;
2056
+    			    } else {
2057
+    			    	$error = true;
2058
+    			    }
1489 2059
 			} elseif ($format == 'aprs' && $use_aprs) {
1490 2060
 			    if ($aprs_connect == 0) {
1491 2061
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1511,63 +2081,121 @@  discard block
 block discarded – undo
1511 2081
 				    $aprs_last_tx = time();
1512 2082
 				    $data = array();
1513 2083
 				    //print_r($line);
1514
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1515
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1516
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1517
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1518
-				    if (isset($line['arrival_code'])) $data['arrical_code'] = $line['arrival_code'];
1519
-				    if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1520
-				    if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1521
-				    if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1522
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1523
-				    else $data['datetime'] = date('Y-m-d H:i:s');
2084
+				    if (isset($line['address'])) {
2085
+				    	$data['hex'] = $line['address'];
2086
+				    }
2087
+				    if (isset($line['mmsi'])) {
2088
+				    	$data['mmsi'] = $line['mmsi'];
2089
+				    }
2090
+				    if (isset($line['imo'])) {
2091
+				    	$data['imo'] = $line['imo'];
2092
+				    }
2093
+				    if (isset($line['squawk'])) {
2094
+				    	$data['squawk'] = $line['squawk'];
2095
+				    }
2096
+				    if (isset($line['arrival_code'])) {
2097
+				    	$data['arrical_code'] = $line['arrival_code'];
2098
+				    }
2099
+				    if (isset($line['arrival_date'])) {
2100
+				    	$data['arrical_date'] = $line['arrival_date'];
2101
+				    }
2102
+				    if (isset($line['type_id'])) {
2103
+				    	$data['type_id'] = $line['typeid'];
2104
+				    }
2105
+				    if (isset($line['status_id'])) {
2106
+				    	$data['status_id'] = $line['statusid'];
2107
+				    }
2108
+				    if (isset($line['timestamp'])) {
2109
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
2110
+				    } else {
2111
+				    	$data['datetime'] = date('Y-m-d H:i:s');
2112
+				    }
1524 2113
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1525
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
2114
+				    if (isset($line['ident'])) {
2115
+				    	$data['ident'] = $line['ident'];
2116
+				    }
1526 2117
 				    $data['latitude'] = $line['latitude'];
1527 2118
 				    $data['longitude'] = $line['longitude'];
1528 2119
 				    //$data['verticalrate'] = $line[16];
1529
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
2120
+				    if (isset($line['speed'])) {
2121
+				    	$data['speed'] = $line['speed'];
2122
+				    }
1530 2123
 				    //else $data['speed'] = 0;
1531
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1532
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1533
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
2124
+				    if (isset($line['altitude'])) {
2125
+				    	$data['altitude'] = $line['altitude'];
2126
+				    }
2127
+				    if (isset($line['comment'])) {
2128
+				    	$data['comment'] = $line['comment'];
2129
+				    }
2130
+				    if (isset($line['symbol'])) {
2131
+				    	$data['type'] = $line['symbol'];
2132
+				    }
1534 2133
 				    //if (isset($line['heading'])) $data['heading'] = $line['heading'];
1535 2134
 				    
1536
-				    if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
2135
+				    if (isset($line['heading']) && isset($line['format_source'])) {
2136
+				    	$data['heading'] = $line['heading'];
2137
+				    }
1537 2138
 				    //else echo 'No heading...'."\n";
1538 2139
 				    //else $data['heading'] = 0;
1539
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
2140
+				    if (isset($line['stealth'])) {
2141
+				    	$data['aircraft_type'] = $line['stealth'];
2142
+				    }
1540 2143
 				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1541
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1542
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1543
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1544
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
2144
+				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) {
2145
+				    	$data['noarchive'] = true;
2146
+				    } elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) {
2147
+				    	$data['noarchive'] = false;
2148
+				    }
2149
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2150
+				    	$data['noarchive'] = true;
2151
+				    } elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) {
2152
+				    	$data['noarchive'] = false;
2153
+				    }
1545 2154
     				    $data['id_source'] = $id_source;
1546
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1547
-				    else $data['format_source'] = 'aprs';
2155
+    				    if (isset($line['format_source'])) {
2156
+    				    	$data['format_source'] = $line['format_source'];
2157
+    				    } else {
2158
+				    	$data['format_source'] = 'aprs';
2159
+				    }
1548 2160
 				    $data['source_name'] = $line['source'];
1549
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1550
-				    else $data['source_type'] = 'flarm';
1551
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2161
+				    if (isset($line['source_type'])) {
2162
+				    	$data['source_type'] = $line['source_type'];
2163
+				    } else {
2164
+				    	$data['source_type'] = 'flarm';
2165
+				    }
2166
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
2167
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2168
+    				    }
1552 2169
 				    $currentdate = date('Y-m-d H:i:s');
1553 2170
 				    $aprsdate = strtotime($data['datetime']);
1554
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
2171
+				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') {
2172
+				    	$data['altitude_relative'] = 'AMSL';
2173
+				    }
1555 2174
 				    // Accept data if time <= system time + 20s
1556 2175
 				    //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'])))) {
1557 2176
 				    if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1558 2177
 					$send = $SI->add($data);
1559 2178
 				    } elseif ($data['source_type'] == 'ais') {
1560 2179
 					$data['type'] = '';
1561
-					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
2180
+					if (isset($globalMarine) && $globalMarine) {
2181
+						$send = $MI->add($data);
2182
+					}
1562 2183
 				    } elseif (isset($line['stealth'])) {
1563
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1564
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
2184
+					if ($line['stealth'] != 0) {
2185
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
2186
+					} else {
2187
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
2188
+					}
1565 2189
 				    } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1566 2190
 					    //$line['symbol'] == 'Balloon' ||
1567 2191
 					    $line['symbol'] == 'Glider' || 
1568 2192
 					    $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1569
-					    if ($line['symbol'] == 'Ballon') $data['aircraft_icao'] = 'BALL';
1570
-					    if ($line['symbol'] == 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
2193
+					    if ($line['symbol'] == 'Ballon') {
2194
+					    	$data['aircraft_icao'] = 'BALL';
2195
+					    }
2196
+					    if ($line['symbol'] == 'Glider') {
2197
+					    	$data['aircraft_icao'] = 'PARAGLIDER';
2198
+					    }
1571 2199
 					    $send = $SI->add($data);
1572 2200
 				    } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1573 2201
 					    $line['symbol'] == 'Yacht (Sail)' || 
@@ -1598,9 +2226,13 @@  discard block
 block discarded – undo
1598 2226
 				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1599 2227
 				//    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1600 2228
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1601
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
2229
+					if (isset($globalTracker) && $globalTracker) {
2230
+						$send = $TI->add($data);
2231
+					}
1602 2232
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1603
-					if (!isset($data['altitude'])) $data['altitude'] = 0;
2233
+					if (!isset($data['altitude'])) {
2234
+						$data['altitude'] = 0;
2235
+					}
1604 2236
 					$Source->deleteOldLocationByType('gs');
1605 2237
 					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
1606 2238
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
@@ -1609,7 +2241,9 @@  discard block
 block discarded – undo
1609 2241
 					}
1610 2242
 				    } elseif (isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1611 2243
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1612
-					if ($globalDebug) echo '# Weather Station added'."\n";
2244
+					if ($globalDebug) {
2245
+						echo '# Weather Station added'."\n";
2246
+					}
1613 2247
 					$Source->deleteOldLocationByType('wx');
1614 2248
 					$weather_data = json_encode($line);
1615 2249
 					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
@@ -1619,7 +2253,9 @@  discard block
 block discarded – undo
1619 2253
 					}
1620 2254
 				    } elseif (isset($line['symbol']) && ($line['symbol'] == 'Lightning' || $line['symbol'] == 'Thunderstorm')) {
1621 2255
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1622
-					if ($globalDebug) echo '☈ Lightning added'."\n";
2256
+					if ($globalDebug) {
2257
+						echo '☈ Lightning added'."\n";
2258
+					}
1623 2259
 					$Source->deleteOldLocationByType('lightning');
1624 2260
 					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
1625 2261
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
@@ -1631,8 +2267,7 @@  discard block
 block discarded – undo
1631 2267
 				    	print_r($line);
1632 2268
 				    }
1633 2269
 				    unset($data);
1634
-				}
1635
-				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
2270
+				} elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1636 2271
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
1637 2272
 				}
1638 2273
 				/*
@@ -1641,7 +2276,9 @@  discard block
 block discarded – undo
1641 2276
 				}
1642 2277
 				*/
1643 2278
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1644
-				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
2279
+				elseif ($line == true && $globalDebug) {
2280
+					echo '!! Failed : '.$buffer."!!\n";
2281
+				}
1645 2282
 				if (isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
1646 2283
 					$Source->deleteOldLocationByType('lightning');
1647 2284
 					$Source->deleteOldLocationByType('wx');
@@ -1677,26 +2314,45 @@  discard block
 block discarded – undo
1677 2314
     				$data['ground'] = $line[21];
1678 2315
     				$data['emergency'] = $line[19];
1679 2316
     				$data['format_source'] = 'sbs';
1680
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1681
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1682
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
2317
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2318
+					$data['source_name'] = $globalSources[$nb]['name'];
2319
+				}
2320
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2321
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2322
+    				}
2323
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2324
+					$data['noarchive'] = true;
2325
+				}
1683 2326
     				$data['id_source'] = $id_source;
1684
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1685
-    				else $error = true;
2327
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2328
+    					$send = $SI->add($data);
2329
+    				} else {
2330
+    					$error = true;
2331
+    				}
1686 2332
     				unset($data);
1687
-    			    } else $error = true;
2333
+    			    } else {
2334
+    			    	$error = true;
2335
+    			    }
1688 2336
 			    if ($error) {
1689 2337
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1690
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
2338
+					if ($globalDebug) {
2339
+						echo "Not a message. Ignoring... \n";
2340
+					}
1691 2341
 				} else {
1692
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
2342
+					if ($globalDebug) {
2343
+						echo "Wrong line format. Ignoring... \n";
2344
+					}
1693 2345
 					if ($globalDebug) {
1694 2346
 						echo $buffer;
1695 2347
 						//print_r($line);
1696 2348
 					}
1697 2349
 					//socket_close($r);
1698
-					if ($globalDebug) echo "Reconnect after an error...\n";
1699
-					if ($format == 'aprs') $aprs_connect = 0;
2350
+					if ($globalDebug) {
2351
+						echo "Reconnect after an error...\n";
2352
+					}
2353
+					if ($format == 'aprs') {
2354
+						$aprs_connect = 0;
2355
+					}
1700 2356
 					$sourceer[$nb] = $globalSources[$nb];
1701 2357
 					connect_all($sourceer);
1702 2358
 					$sourceer = array();
@@ -1704,10 +2360,14 @@  discard block
 block discarded – undo
1704 2360
 			    }
1705 2361
 			}
1706 2362
 			// Sleep for xxx microseconds
1707
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
2363
+			if (isset($globalSBSSleep)) {
2364
+				usleep($globalSBSSleep);
2365
+			}
1708 2366
 		    } else {
1709 2367
 			if ($format == 'flightgearmp') {
1710
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
2368
+			    	if ($globalDebug) {
2369
+			    		echo "Reconnect FlightGear MP...";
2370
+			    	}
1711 2371
 				//@socket_close($r);
1712 2372
 				sleep($globalMinFetch);
1713 2373
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1716,10 +2376,15 @@  discard block
 block discarded – undo
1716 2376
 				break;
1717 2377
 				
1718 2378
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1719
-			    if (isset($tt[$format])) $tt[$format]++;
1720
-			    else $tt[$format] = 0;
2379
+			    if (isset($tt[$format])) {
2380
+			    	$tt[$format]++;
2381
+			    } else {
2382
+			    	$tt[$format] = 0;
2383
+			    }
1721 2384
 			    if ($tt[$format] > 30) {
1722
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
2385
+				if ($globalDebug) {
2386
+					echo "ERROR : Reconnect ".$format."...";
2387
+				}
1723 2388
 				//@socket_close($r);
1724 2389
 				sleep(2);
1725 2390
 				$aprs_connect = 0;
@@ -1736,11 +2401,17 @@  discard block
 block discarded – undo
1736 2401
 	    } else {
1737 2402
 		$error = socket_strerror(socket_last_error());
1738 2403
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1739
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1740
-			if (isset($globalDebug)) echo "Restarting...\n";
2404
+			if ($globalDebug) {
2405
+				echo "ERROR : socket_select give this error ".$error . "\n";
2406
+			}
2407
+			if (isset($globalDebug)) {
2408
+				echo "Restarting...\n";
2409
+			}
1741 2410
 			// Restart the script if possible
1742 2411
 			if (is_array($sockets)) {
1743
-			    if ($globalDebug) echo "Shutdown all sockets...";
2412
+			    if ($globalDebug) {
2413
+			    	echo "Shutdown all sockets...";
2414
+			    }
1744 2415
 			    
1745 2416
 			    foreach ($sockets as $sock) {
1746 2417
 				@socket_shutdown($sock,2);
@@ -1748,25 +2419,45 @@  discard block
 block discarded – undo
1748 2419
 			    }
1749 2420
 			    
1750 2421
 			}
1751
-			if ($globalDebug) echo "Waiting...";
2422
+			if ($globalDebug) {
2423
+				echo "Waiting...";
2424
+			}
1752 2425
 			sleep(2);
1753 2426
 			$time = time();
1754 2427
 			//connect_all($hosts);
1755 2428
 			$aprs_connect = 0;
1756
-			if ($reset%5 == 0) sleep(20);
1757
-			if ($reset%10 == 0) sleep(100);
1758
-			if ($reset%20 == 0) sleep(200);
1759
-			if ($reset > 100) exit('Too many attempts...');
1760
-			if ($globalDebug) echo "Restart all connections...";
2429
+			if ($reset%5 == 0) {
2430
+				sleep(20);
2431
+			}
2432
+			if ($reset%10 == 0) {
2433
+				sleep(100);
2434
+			}
2435
+			if ($reset%20 == 0) {
2436
+				sleep(200);
2437
+			}
2438
+			if ($reset > 100) {
2439
+				exit('Too many attempts...');
2440
+			}
2441
+			if ($globalDebug) {
2442
+				echo "Restart all connections...";
2443
+			}
1761 2444
 			connect_all($globalSources);
1762 2445
 		}
1763 2446
 	    }
1764 2447
 	}
1765 2448
 	if ($globalDaemon === false) {
1766
-	    if ($globalDebug) echo 'Check all...'."\n";
1767
-	    if (isset($SI)) $SI->checkAll();
1768
-	    if (isset($TI)) $TI->checkAll();
1769
-	    if (isset($MI)) $MI->checkAll();
2449
+	    if ($globalDebug) {
2450
+	    	echo 'Check all...'."\n";
2451
+	    }
2452
+	    if (isset($SI)) {
2453
+	    	$SI->checkAll();
2454
+	    }
2455
+	    if (isset($TI)) {
2456
+	    	$TI->checkAll();
2457
+	    }
2458
+	    if (isset($MI)) {
2459
+	    	$MI->checkAll();
2460
+	    }
1770 2461
 	}
1771 2462
     }
1772 2463
 }
Please login to merge, or discard this patch.