Completed
Push — master ( 72f2a4...101685 )
by Yannick
28:38
created
scripts/daemon-spotter.php 1 patch
Braces   +1135 added lines, -383 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,27 +211,37 @@  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('/aircraft.json$/i',$host)) {
177 232
         	//$formats[$id] = 'aircraftjson';
178 233
         	$globalSources[$id]['format'] = 'aircraftjson';
179 234
         	//$last_exec['aircraftlistjson'] = 0;
180
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
235
+        	if ($globalDebug) {
236
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
237
+        	}
181 238
     	    } else if (preg_match('/opensky/i',$host)) {
182 239
         	//$formats[$id] = 'aircraftlistjson';
183 240
         	$globalSources[$id]['format'] = 'opensky';
184 241
         	//$last_exec['aircraftlistjson'] = 0;
185
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
242
+        	if ($globalDebug) {
243
+        		echo "Connect to opensky source (".$host.")...\n";
244
+        	}
186 245
     	    /*
187 246
     	    // Disabled for now, site change source format
188 247
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
@@ -199,7 +258,9 @@  discard block
 block discarded – undo
199 258
         	//$formats[$id] = 'planeupdatefaa';
200 259
         	$globalSources[$id]['format'] = 'planeupdatefaa';
201 260
         	//$last_exec['planeupdatefaa'] = 0;
202
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
261
+        	if ($globalDebug) {
262
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
263
+        	}
203 264
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
204 265
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
205 266
         	    exit(0);
@@ -208,37 +269,53 @@  discard block
 block discarded – undo
208 269
         	//$formats[$id] = 'phpvmacars';
209 270
         	$globalSources[$id]['format'] = 'phpvmacars';
210 271
         	//$last_exec['phpvmacars'] = 0;
211
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
272
+        	if ($globalDebug) {
273
+        		echo "Connect to phpvmacars source (".$host.")...\n";
274
+        	}
212 275
             } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) {
213 276
         	//$formats[$id] = 'phpvmacars';
214 277
         	$globalSources[$id]['format'] = 'vaos';
215 278
         	//$last_exec['phpvmacars'] = 0;
216
-        	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
279
+        	if ($globalDebug) {
280
+        		echo "Connect to vaos source (".$host.")...\n";
281
+        	}
217 282
             } else if (preg_match('/VAM-json.php$/i',$host)) {
218 283
         	//$formats[$id] = 'phpvmacars';
219 284
         	$globalSources[$id]['format'] = 'vam';
220
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
285
+        	if ($globalDebug) {
286
+        		echo "Connect to Vam source (".$host.")...\n";
287
+        	}
221 288
             } else if (preg_match('/whazzup/i',$host)) {
222 289
         	//$formats[$id] = 'whazzup';
223 290
         	$globalSources[$id]['format'] = 'whazzup';
224 291
         	//$last_exec['whazzup'] = 0;
225
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
292
+        	if ($globalDebug) {
293
+        		echo "Connect to whazzup source (".$host.")...\n";
294
+        	}
226 295
             } else if (preg_match('/blitzortung/i',$host)) {
227 296
         	$globalSources[$id]['format'] = 'blitzortung';
228
-        	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
297
+        	if ($globalDebug) {
298
+        		echo "Connect to blitzortung source (".$host.")...\n";
299
+        	}
229 300
             } else if (preg_match('/airwhere/i',$host)) {
230 301
         	$globalSources[$id]['format'] = 'airwhere';
231
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
302
+        	if ($globalDebug) {
303
+        		echo "Connect to airwhere source (".$host.")...\n";
304
+        	}
232 305
             } else if (preg_match('/recentpireps/i',$host)) {
233 306
         	//$formats[$id] = 'pirepsjson';
234 307
         	$globalSources[$id]['format'] = 'pirepsjson';
235 308
         	//$last_exec['pirepsjson'] = 0;
236
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
309
+        	if ($globalDebug) {
310
+        		echo "Connect to pirepsjson source (".$host.")...\n";
311
+        	}
237 312
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
238 313
         	//$formats[$id] = 'fr24json';
239 314
         	$globalSources[$id]['format'] = 'fr24json';
240 315
         	//$last_exec['fr24json'] = 0;
241
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
316
+        	if ($globalDebug) {
317
+        		echo "Connect to fr24 source (".$host.")...\n";
318
+        	}
242 319
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
243 320
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
244 321
         	    exit(0);
@@ -247,7 +324,9 @@  discard block
 block discarded – undo
247 324
         	//$formats[$id] = 'fr24json';
248 325
         	$globalSources[$id]['format'] = 'myshiptracking';
249 326
         	//$last_exec['fr24json'] = 0;
250
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
327
+        	if ($globalDebug) {
328
+        		echo "Connect to myshiptracking source (".$host.")...\n";
329
+        	}
251 330
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
252 331
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
253 332
         	    exit(0);
@@ -256,16 +335,24 @@  discard block
 block discarded – undo
256 335
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
257 336
         	//$formats[$id] = 'tsv';
258 337
         	$globalSources[$id]['format'] = 'tsv';
259
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
338
+        	if ($globalDebug) {
339
+        		echo "Connect to tsv source (".$host.")...\n";
340
+        	}
260 341
             }
261 342
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
262 343
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
263 344
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
264 345
     		    if ($idf !== false) {
265 346
     			$httpfeeds[$id] = $idf;
266
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
267
-    		    } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
268
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
347
+        		if ($globalDebug) {
348
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
349
+        		}
350
+    		    } elseif ($globalDebug) {
351
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
352
+    		    }
353
+    		} elseif ($globalDebug) {
354
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
355
+    		}
269 356
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
270 357
 	    $hostport = explode(':',$host);
271 358
 	    if (isset($hostport[1])) {
@@ -305,17 +392,25 @@  discard block
 block discarded – undo
305 392
         		//$formats[$id] = 'beast';
306 393
         		$globalSources[$id]['format'] = 'beast';
307 394
 		    //} else $formats[$id] = 'sbs';
308
-		    } else $globalSources[$id]['format'] = 'sbs';
395
+		    } else {
396
+		    	$globalSources[$id]['format'] = 'sbs';
397
+		    }
309 398
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
310 399
 		}
311
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
400
+		if ($globalDebug) {
401
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
402
+		}
312 403
             } else {
313
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
404
+		if ($globalDebug) {
405
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
406
+		}
314 407
     	    }
315 408
         }
316 409
     }
317 410
 }
318
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
411
+if (!isset($globalMinFetch)) {
412
+	$globalMinFetch = 15;
413
+}
319 414
 
320 415
 // Initialize all
321 416
 $status = array();
@@ -324,13 +419,19 @@  discard block
 block discarded – undo
324 419
 $formats = array();
325 420
 $last_exec = array();
326 421
 $time = time();
327
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
328
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
329
-else $timeout = 20;
422
+if (isset($globalSourcesTimeout)) {
423
+	$timeout = $globalSourcesTimeOut;
424
+} else if (isset($globalSBS1TimeOut)) {
425
+	$timeout = $globalSBS1TimeOut;
426
+} else {
427
+	$timeout = 20;
428
+}
330 429
 $errno = '';
331 430
 $errstr='';
332 431
 
333
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
432
+if (!isset($globalDaemon)) {
433
+	$globalDaemon = TRUE;
434
+}
334 435
 /* Initiate connections to all the hosts simultaneously */
335 436
 //connect_all($hosts);
336 437
 //connect_all($globalSources);
@@ -359,7 +460,9 @@  discard block
 block discarded – undo
359 460
     if (isset($source['format']) && $source['format'] == 'aprs') {
360 461
 	$aprs_connect = 0;
361 462
 	$use_aprs = true;
362
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
463
+	if (isset($source['port']) && $source['port'] == '10152') {
464
+		$aprs_full = true;
465
+	}
363 466
 	break;
364 467
     }
365 468
 }
@@ -370,25 +473,46 @@  discard block
 block discarded – undo
370 473
 	$aprs_connect = 0;
371 474
 	$aprs_keep = 120;
372 475
 	$aprs_last_tx = time();
373
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
374
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
375
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
376
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
377
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
378
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
379
-	if ($aprs_full) $aprs_filter = '';
380
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
381
-	else $aprs_pass = '-1';
476
+	if (isset($globalAPRSversion)) {
477
+		$aprs_version = $globalAPRSversion;
478
+	} else {
479
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
480
+	}
481
+	if (isset($globalAPRSssid)) {
482
+		$aprs_ssid = $globalAPRSssid;
483
+	} else {
484
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
485
+	}
486
+	if (isset($globalAPRSfilter)) {
487
+		$aprs_filter = $globalAPRSfilter;
488
+	} else {
489
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
490
+	}
491
+	if ($aprs_full) {
492
+		$aprs_filter = '';
493
+	}
494
+	if (isset($globalAPRSpass)) {
495
+		$aprs_pass = $globalAPRSpass;
496
+	} else {
497
+		$aprs_pass = '-1';
498
+	}
382 499
 
383
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
384
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
385
-}
500
+	if ($aprs_filter != '') {
501
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
502
+	} else {
503
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
504
+	}
505
+	}
386 506
 
387 507
 // connected - lets do some work
388 508
 //if ($globalDebug) echo "Connected!\n";
389 509
 sleep(1);
390
-if ($globalDebug) echo "SCAN MODE \n\n";
391
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
510
+if ($globalDebug) {
511
+	echo "SCAN MODE \n\n";
512
+}
513
+if (!isset($globalCronEnd)) {
514
+	$globalCronEnd = 60;
515
+}
392 516
 $endtime = time()+$globalCronEnd;
393 517
 $i = 1;
394 518
 $tt = array();
@@ -402,22 +526,32 @@  discard block
 block discarded – undo
402 526
 
403 527
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
404 528
 while ($i > 0) {
405
-    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
529
+    if (function_exists('pcntl_fork')) {
530
+    	pcntl_signal_dispatch();
531
+    }
406 532
 
407
-    if (!$globalDaemon) $i = $endtime-time();
533
+    if (!$globalDaemon) {
534
+    	$i = $endtime-time();
535
+    }
408 536
     // Delete old ATC
409 537
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
410
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
538
+	if ($globalDebug) {
539
+		echo 'Delete old ATC...'."\n";
540
+	}
411 541
         $ATC->deleteOldATC();
412 542
     }
413 543
     
414 544
     if (count($last_exec) == count($globalSources)) {
415 545
 	$max = $globalMinFetch;
416 546
 	foreach ($last_exec as $last) {
417
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
547
+	    if ((time() - $last['last']) < $max) {
548
+	    	$max = time() - $last['last'];
549
+	    }
418 550
 	}
419 551
 	if ($max < $globalMinFetch) {
420
-	    if ($globalDebug) echo 'Sleeping...'."\n";
552
+	    if ($globalDebug) {
553
+	    	echo 'Sleeping...'."\n";
554
+	    }
421 555
 	    sleep($globalMinFetch-$max+2);
422 556
 	}
423 557
     }
@@ -427,7 +561,9 @@  discard block
 block discarded – undo
427 561
     foreach ($globalSources as $id => $value) {
428 562
 	date_default_timezone_set('UTC');
429 563
 	//if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n";
430
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
564
+	if (!isset($last_exec[$id]['last'])) {
565
+		$last_exec[$id]['last'] = 0;
566
+	}
431 567
 	if ($value['format'] === 'deltadbtxt' && 
432 568
 	    (
433 569
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
@@ -436,7 +572,9 @@  discard block
 block discarded – undo
436 572
 	) {
437 573
 	    //$buffer = $Common->getData($hosts[$id]);
438 574
 	    $buffer = $Common->getData($value['host']);
439
-	    if ($buffer != '') $reset = 0;
575
+	    if ($buffer != '') {
576
+	    	$reset = 0;
577
+	    }
440 578
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
441 579
 	    $buffer = explode('\n',$buffer);
442 580
 	    foreach ($buffer as $line) {
@@ -445,20 +583,41 @@  discard block
 block discarded – undo
445 583
 	            $data = array();
446 584
 	            $data['hex'] = $line[1]; // hex
447 585
 	            $data['ident'] = $line[2]; // ident
448
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
449
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
450
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
451
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
452
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
586
+	            if (isset($line[3])) {
587
+	            	$data['altitude'] = $line[3];
588
+	            }
589
+	            // altitude
590
+	            if (isset($line[4])) {
591
+	            	$data['speed'] = $line[4];
592
+	            }
593
+	            // speed
594
+	            if (isset($line[5])) {
595
+	            	$data['heading'] = $line[5];
596
+	            }
597
+	            // heading
598
+	            if (isset($line[6])) {
599
+	            	$data['latitude'] = $line[6];
600
+	            }
601
+	            // lat
602
+	            if (isset($line[7])) {
603
+	            	$data['longitude'] = $line[7];
604
+	            }
605
+	            // long
453 606
 	            $data['verticalrate'] = ''; // vertical rate
454 607
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
455 608
 	            $data['emergency'] = ''; // emergency
456 609
 		    $data['datetime'] = date('Y-m-d H:i:s');
457 610
 		    $data['format_source'] = 'deltadbtxt';
458 611
     		    $data['id_source'] = $id_source;
459
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
460
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
461
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
612
+		    if (isset($value['name']) && $value['name'] != '') {
613
+		    	$data['source_name'] = $value['name'];
614
+		    }
615
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
616
+		    	$data['noarchive'] = true;
617
+		    }
618
+		    if (isset($value['sourcestats'])) {
619
+		    	$data['sourcestats'] = $value['sourcestats'];
620
+		    }
462 621
     		    $SI->add($data);
463 622
 		    unset($data);
464 623
     		}
@@ -473,7 +632,9 @@  discard block
 block discarded – undo
473 632
 	    date_default_timezone_set('CET');
474 633
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
475 634
 	    date_default_timezone_set('UTC');
476
-	    if ($buffer != '') $reset = 0;
635
+	    if ($buffer != '') {
636
+	    	$reset = 0;
637
+	    }
477 638
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
478 639
 	    $buffer = explode('\n',$buffer);
479 640
 	    foreach ($buffer as $line) {
@@ -482,18 +643,42 @@  discard block
 block discarded – undo
482 643
 		    $add = false;
483 644
 		    $ais_data = $AIS->parse_line(trim($line));
484 645
 		    $data = array();
485
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
486
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
487
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
488
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
489
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
490
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
491
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
492
-		    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
493
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
494
-		    if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
495
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
496
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
646
+		    if (isset($ais_data['ident'])) {
647
+		    	$data['ident'] = $ais_data['ident'];
648
+		    }
649
+		    if (isset($ais_data['mmsi'])) {
650
+		    	$data['mmsi'] = substr($ais_data['mmsi'],-9);
651
+		    }
652
+		    if (isset($ais_data['speed'])) {
653
+		    	$data['speed'] = $ais_data['speed'];
654
+		    }
655
+		    if (isset($ais_data['heading'])) {
656
+		    	$data['heading'] = $ais_data['heading'];
657
+		    }
658
+		    if (isset($ais_data['latitude'])) {
659
+		    	$data['latitude'] = $ais_data['latitude'];
660
+		    }
661
+		    if (isset($ais_data['longitude'])) {
662
+		    	$data['longitude'] = $ais_data['longitude'];
663
+		    }
664
+		    if (isset($ais_data['status'])) {
665
+		    	$data['status'] = $ais_data['status'];
666
+		    }
667
+		    if (isset($ais_data['statusid'])) {
668
+		    	$data['status_id'] = $ais_data['statusid'];
669
+		    }
670
+		    if (isset($ais_data['type'])) {
671
+		    	$data['type'] = $ais_data['type'];
672
+		    }
673
+		    if (isset($ais_data['typeid'])) {
674
+		    	$data['type_id'] = $ais_data['typeid'];
675
+		    }
676
+		    if (isset($ais_data['imo'])) {
677
+		    	$data['imo'] = $ais_data['imo'];
678
+		    }
679
+		    if (isset($ais_data['callsign'])) {
680
+		    	$data['callsign'] = $ais_data['callsign'];
681
+		    }
497 682
 		    if (isset($ais_data['timestamp'])) {
498 683
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
499 684
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -507,8 +692,12 @@  discard block
 block discarded – undo
507 692
 		    $data['format_source'] = 'aisnmeatxt';
508 693
     		    $data['id_source'] = $id_source;
509 694
 		    //print_r($data);
510
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
511
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
695
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
696
+		    	$data['noarchive'] = true;
697
+		    }
698
+		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') {
699
+		    	$MI->add($data);
700
+		    }
512 701
 		    unset($data);
513 702
 		}
514 703
     	    }
@@ -531,20 +720,48 @@  discard block
 block discarded – undo
531 720
 			    if ($line != '') {
532 721
 				$ais_data = $AIS->parse_line(trim($line));
533 722
 				$data = array();
534
-				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
535
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
536
-				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
537
-				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
538
-				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
539
-				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
540
-				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
541
-				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
542
-				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
543
-				if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
544
-				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
545
-				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
546
-				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
547
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
723
+				if (isset($ais_data['ident'])) {
724
+					$data['ident'] = $ais_data['ident'];
725
+				}
726
+				if (isset($ais_data['mmsi'])) {
727
+					$data['mmsi'] = substr($ais_data['mmsi'],-9);
728
+				}
729
+				if (isset($ais_data['speed'])) {
730
+					$data['speed'] = $ais_data['speed'];
731
+				}
732
+				if (isset($ais_data['heading'])) {
733
+					$data['heading'] = $ais_data['heading'];
734
+				}
735
+				if (isset($ais_data['latitude'])) {
736
+					$data['latitude'] = $ais_data['latitude'];
737
+				}
738
+				if (isset($ais_data['longitude'])) {
739
+					$data['longitude'] = $ais_data['longitude'];
740
+				}
741
+				if (isset($ais_data['status'])) {
742
+					$data['status'] = $ais_data['status'];
743
+				}
744
+				if (isset($ais_data['statusid'])) {
745
+					$data['status_id'] = $ais_data['statusid'];
746
+				}
747
+				if (isset($ais_data['type'])) {
748
+					$data['type'] = $ais_data['type'];
749
+				}
750
+				if (isset($ais_data['typeid'])) {
751
+					$data['type_id'] = $ais_data['typeid'];
752
+				}
753
+				if (isset($ais_data['imo'])) {
754
+					$data['imo'] = $ais_data['imo'];
755
+				}
756
+				if (isset($ais_data['callsign'])) {
757
+					$data['callsign'] = $ais_data['callsign'];
758
+				}
759
+				if (isset($ais_data['destination'])) {
760
+					$data['arrival_code'] = $ais_data['destination'];
761
+				}
762
+				if (isset($ais_data['eta_ts'])) {
763
+					$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
764
+				}
548 765
 				if (isset($ais_data['timestamp'])) {
549 766
 				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
550 767
 				} else {
@@ -552,18 +769,27 @@  discard block
 block discarded – undo
552 769
 				}
553 770
 				$data['format_source'] = 'aisnmeahttp';
554 771
 				$data['id_source'] = $id_source;
555
-				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
556
-				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
772
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
773
+					$data['noarchive'] = true;
774
+				}
775
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') {
776
+					$MI->add($data);
777
+				}
557 778
 				unset($data);
558 779
 			    }
559 780
 			}
560 781
 		    }
561 782
 		} else {
562 783
 		    $format = $value['format'];
563
-		    if (isset($tt[$format])) $tt[$format]++;
564
-		    else $tt[$format] = 0;
784
+		    if (isset($tt[$format])) {
785
+		    	$tt[$format]++;
786
+		    } else {
787
+		    	$tt[$format] = 0;
788
+		    }
565 789
 		    if ($tt[$format] > 30) {
566
-			if ($globalDebug) echo 'Reconnect...'."\n";
790
+			if ($globalDebug) {
791
+				echo 'Reconnect...'."\n";
792
+			}
567 793
 			sleep(2);
568 794
 			//$sourceeen[] = $value;
569 795
 			//connect_all($sourceeen);
@@ -599,12 +825,18 @@  discard block
 block discarded – undo
599 825
 			    //    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
600 826
 			    //$data['type_id'] = $line['TYPE'];
601 827
 			    $data['imo'] = $line['IMO'];
602
-			    if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
603
-			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
828
+			    if ($line['DEST'] != '') {
829
+			    	$data['arrival_code'] = $line['DEST'];
830
+			    }
831
+			    if ($line['ARV'] != '') {
832
+			    	$data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
833
+			    }
604 834
 			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
605 835
 			    $data['format_source'] = 'myshiptracking';
606 836
 			    $data['id_source'] = $id_source;
607
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
837
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
838
+			    	$data['noarchive'] = true;
839
+			    }
608 840
 			    $MI->add($data);
609 841
 			    unset($data);
610 842
 			}
@@ -629,7 +861,9 @@  discard block
 block discarded – undo
629 861
 			    $data['callsign'] = $line['callsign'];
630 862
 			    $data['mmsi'] = substr($line['mmsi'],-9);
631 863
 			    $data['speed'] = $line['sog'];
632
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
864
+			    if ($line['heading'] != '511') {
865
+			    	$data['heading'] = $line['heading'];
866
+			    }
633 867
 			    $data['latitude'] = $line['latitude'];
634 868
 			    $data['longitude'] = $line['longitude'];
635 869
 			    $data['type_id'] = $line['shiptype'];
@@ -637,7 +871,9 @@  discard block
 block discarded – undo
637 871
 			    $data['datetime'] = $line['time'];
638 872
 			    $data['format_source'] = 'boatbeaconapp';
639 873
 			    $data['id_source'] = $id_source;
640
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
874
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
875
+			    	$data['noarchive'] = true;
876
+			    }
641 877
 			    $MI->add($data);
642 878
 			    unset($data);
643 879
 			}
@@ -659,22 +895,44 @@  discard block
 block discarded – undo
659 895
 		    foreach ($all_data['features'] as $line) {
660 896
 			print_r($line);
661 897
 			$data = array();
662
-			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
663
-			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
664
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'],-9);
665
-			if (isset($line['properties']['imo'])) $data['imo'] = $line['properties']['imo'];
666
-			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
667
-			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) $data['heading'] = $line['properties']['heading'];
898
+			if (isset($line['properties']['name'])) {
899
+				$data['ident'] = $line['properties']['name'];
900
+			}
901
+			if (isset($line['properties']['callsign'])) {
902
+				$data['callsign'] = $line['properties']['callsign'];
903
+			}
904
+			if (isset($line['properties']['mmsi'])) {
905
+				$data['mmsi'] = substr($line['properties']['mmsi'],-9);
906
+			}
907
+			if (isset($line['properties']['imo'])) {
908
+				$data['imo'] = $line['properties']['imo'];
909
+			}
910
+			if (isset($line['properties']['speed'])) {
911
+				$data['speed'] = $line['properties']['speed'];
912
+			}
913
+			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) {
914
+				$data['heading'] = $line['properties']['heading'];
915
+			}
668 916
 			$data['latitude'] = $line['geometry']['coordinates'][1];
669 917
 			$data['longitude'] = $line['geometry']['coordinates'][0];
670
-			if (isset($line['properties']['vesselType'])) $data['type'] = $line['properties']['vesselType'];
671
-			if (isset($line['properties']['destination'])) $data['arrival_code'] = $line['properties']['destination'];
672
-			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') $data['arrival_date'] = $line['properties']['eta'];
918
+			if (isset($line['properties']['vesselType'])) {
919
+				$data['type'] = $line['properties']['vesselType'];
920
+			}
921
+			if (isset($line['properties']['destination'])) {
922
+				$data['arrival_code'] = $line['properties']['destination'];
923
+			}
924
+			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') {
925
+				$data['arrival_date'] = $line['properties']['eta'];
926
+			}
673 927
 			$data['format_source'] = 'boatnerd';
674 928
 			$data['id_source'] = $id_source;
675 929
 			$data['datetime'] = date('Y-m-d H:i:s');
676
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
677
-			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
930
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
931
+				$data['noarchive'] = true;
932
+			}
933
+			if ($line['properties']['vesselType'] != 'Navigation Aid') {
934
+				$MI->add($data);
935
+			}
678 936
 			unset($data);
679 937
 		    }
680 938
 		}
@@ -691,7 +949,9 @@  discard block
 block discarded – undo
691 949
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
692 950
 	    echo 'done !'."\n";
693 951
 	    // FIXME: Need more work
694
-	    if ($buffer != '') $reset = 0;
952
+	    if ($buffer != '') {
953
+	    	$reset = 0;
954
+	    }
695 955
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
696 956
 	    $buffer = explode('\n',$buffer);
697 957
 	    foreach ($buffer as $line) {
@@ -717,7 +977,9 @@  discard block
 block discarded – undo
717 977
 		    //$data['etaTime'] = substr($line,135,5);
718 978
 		    $data['format_source'] = 'shipplotter';
719 979
     		    $data['id_source'] = $id_source;
720
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
980
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
981
+		    	$data['noarchive'] = true;
982
+		    }
721 983
 		    //print_r($data);
722 984
 		    echo 'Add...'."\n";
723 985
 		    $MI->add($data);
@@ -751,16 +1013,28 @@  discard block
 block discarded – undo
751 1013
     		    $line = explode(':', $line);
752 1014
     		    if (count($line) > 30 && $line[0] != 'callsign') {
753 1015
 			$data = array();
754
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
755
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
1016
+			if (isset($line[37]) && $line[37] != '') {
1017
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
1018
+			} else {
1019
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
1020
+			}
756 1021
 			$data['pilot_id'] = $line[1];
757 1022
 			$data['pilot_name'] = $line[2];
758 1023
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
759 1024
 			$data['ident'] = $line[0]; // ident
760
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
1025
+			if ($line[7] != '' && $line[7] != 0) {
1026
+				$data['altitude'] = $line[7];
1027
+			}
1028
+			// altitude
761 1029
 			$data['speed'] = $line[8]; // speed
762
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
763
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
1030
+			if (isset($line[45])) {
1031
+				$data['heading'] = $line[45];
1032
+			}
1033
+			// heading
1034
+			elseif (isset($line[38])) {
1035
+				$data['heading'] = $line[38];
1036
+			}
1037
+			// heading
764 1038
 			$data['latitude'] = $line[5]; // lat
765 1039
 	        	$data['longitude'] = $line[6]; // long
766 1040
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -776,7 +1050,9 @@  discard block
 block discarded – undo
776 1050
 			$data['frequency'] = $line[4];
777 1051
 			$data['type'] = $line[18];
778 1052
 			$data['range'] = $line[19];
779
-			if (isset($line[35])) $data['info'] = $line[35];
1053
+			if (isset($line[35])) {
1054
+				$data['info'] = $line[35];
1055
+			}
780 1056
     			$data['id_source'] = $id_source;
781 1057
 	    		//$data['arrival_airport_time'] = ;
782 1058
 	    		if ($line[9] != '') {
@@ -790,27 +1066,47 @@  discard block
 block discarded – undo
790 1066
 	    		elseif ($value === 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
791 1067
 	    		*/
792 1068
 	    		$data['format_source'] = $value['format'];
793
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
794
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
795
-    			if ($line[3] === 'PILOT') $SI->add($data);
796
-			elseif ($line[3] === 'ATC') {
1069
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1070
+				$data['noarchive'] = true;
1071
+			}
1072
+			if (isset($value['name']) && $value['name'] != '') {
1073
+				$data['source_name'] = $value['name'];
1074
+			}
1075
+    			if ($line[3] === 'PILOT') {
1076
+    				$SI->add($data);
1077
+    			} elseif ($line[3] === 'ATC') {
797 1078
 				//print_r($data);
798 1079
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
799 1080
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
800 1081
 				$typec = substr($data['ident'],-3);
801
-				if ($typec === 'APP') $data['type'] = 'Approach';
802
-				elseif ($typec === 'TWR') $data['type'] = 'Tower';
803
-				elseif ($typec === 'OBS') $data['type'] = 'Observer';
804
-				elseif ($typec === 'GND') $data['type'] = 'Ground';
805
-				elseif ($typec === 'DEL') $data['type'] = 'Delivery';
806
-				elseif ($typec === 'DEP') $data['type'] = 'Departure';
807
-				elseif ($typec === 'FSS') $data['type'] = 'Flight Service Station';
808
-				elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
809
-				elseif ($data['type'] === '') $data['type'] = 'Observer';
810
-				if (!isset($data['source_name'])) $data['source_name'] = '';
1082
+				if ($typec === 'APP') {
1083
+					$data['type'] = 'Approach';
1084
+				} elseif ($typec === 'TWR') {
1085
+					$data['type'] = 'Tower';
1086
+				} elseif ($typec === 'OBS') {
1087
+					$data['type'] = 'Observer';
1088
+				} elseif ($typec === 'GND') {
1089
+					$data['type'] = 'Ground';
1090
+				} elseif ($typec === 'DEL') {
1091
+					$data['type'] = 'Delivery';
1092
+				} elseif ($typec === 'DEP') {
1093
+					$data['type'] = 'Departure';
1094
+				} elseif ($typec === 'FSS') {
1095
+					$data['type'] = 'Flight Service Station';
1096
+				} elseif ($typec === 'CTR') {
1097
+					$data['type'] = 'Control Radar or Centre';
1098
+				} elseif ($data['type'] === '') {
1099
+					$data['type'] = 'Observer';
1100
+				}
1101
+				if (!isset($data['source_name'])) {
1102
+					$data['source_name'] = '';
1103
+				}
811 1104
 				if (isset($ATC)) {
812
-					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']);
813
-					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']);
1105
+					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) {
1106
+						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']);
1107
+					} else {
1108
+						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']);
1109
+					}
814 1110
 				}
815 1111
 			}
816 1112
     			unset($data);
@@ -837,14 +1133,20 @@  discard block
 block discarded – undo
837 1133
 			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
838 1134
 			$data['latitude'] = (float)$line['pktLatitude'];
839 1135
 			$data['longitude'] = (float)$line['pktLongitude'];
840
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
841
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
1136
+			if ((float)$line['pktTrack'] != 0) {
1137
+				$data['heading'] = (float)$line['pktTrack'];
1138
+			}
1139
+			if ((int)$line['pktSpeed'] != 0) {
1140
+				$data['speed'] = (int)$line['pktSpeed'];
1141
+			}
842 1142
 			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
843 1143
 			$data['altitude_relative'] = 'AMSL';
844 1144
 			$data['pilot_id'] = (int)$line['pktPilotID'];
845 1145
 			$data['aircraft_icao'] = 'PARAGLIDER';
846 1146
 			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
847
-			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
1147
+			if (isset($pilot_data[4])) {
1148
+				$data['pilot_name'] = $pilot_data[4];
1149
+			}
848 1150
 			$data['format_source'] = $value['format'];
849 1151
 			$SI->add($data);
850 1152
 			unset($data);
@@ -892,25 +1194,59 @@  discard block
 block discarded – undo
892 1194
 		    foreach ($all_data['acList'] as $line) {
893 1195
 			$data = array();
894 1196
 			$data['hex'] = $line['Icao']; // hex
895
-			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
896
-			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
897
-			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
898
-			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
899
-			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
900
-			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1197
+			if (isset($line['Call'])) {
1198
+				$data['ident'] = $line['Call'];
1199
+			}
1200
+			// ident
1201
+			if (isset($line['Alt'])) {
1202
+				$data['altitude'] = $line['Alt'];
1203
+			}
1204
+			// altitude
1205
+			if (isset($line['Spd'])) {
1206
+				$data['speed'] = $line['Spd'];
1207
+			}
1208
+			// speed
1209
+			if (isset($line['Trak'])) {
1210
+				$data['heading'] = $line['Trak'];
1211
+			}
1212
+			// heading
1213
+			if (isset($line['Lat'])) {
1214
+				$data['latitude'] = $line['Lat'];
1215
+			}
1216
+			// lat
1217
+			if (isset($line['Long'])) {
1218
+				$data['longitude'] = $line['Long'];
1219
+			}
1220
+			// long
901 1221
 			//$data['verticalrate'] = $line['']; // verticale rate
902
-			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1222
+			if (isset($line['Sqk'])) {
1223
+				$data['squawk'] = $line['Sqk'];
1224
+			}
1225
+			// squawk
903 1226
 			$data['emergency'] = ''; // emergency
904
-			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
905
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
906
-			else $data['datetime'] = date('Y-m-d H:i:s');
1227
+			if (isset($line['Reg'])) {
1228
+				$data['registration'] = $line['Reg'];
1229
+			}
1230
+			if (isset($line['PosTime'])) {
1231
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1232
+			} else {
1233
+				$data['datetime'] = date('Y-m-d H:i:s');
1234
+			}
907 1235
 			//$data['datetime'] = date('Y-m-d H:i:s');
908
-			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1236
+			if (isset($line['Type'])) {
1237
+				$data['aircraft_icao'] = $line['Type'];
1238
+			}
909 1239
 			$data['format_source'] = 'aircraftlistjson';
910 1240
 			$data['id_source'] = $id_source;
911
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
912
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
913
-			if (isset($data['latitude'])) $SI->add($data);
1241
+			if (isset($value['name']) && $value['name'] != '') {
1242
+				$data['source_name'] = $value['name'];
1243
+			}
1244
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1245
+				$data['noarchive'] = true;
1246
+			}
1247
+			if (isset($data['latitude'])) {
1248
+				$SI->add($data);
1249
+			}
914 1250
 			unset($data);
915 1251
 		    }
916 1252
 		} elseif (is_array($all_data)) {
@@ -927,17 +1263,26 @@  discard block
 block discarded – undo
927 1263
 			$data['verticalrate'] = $line['vrt']; // verticale rate
928 1264
 			$data['squawk'] = $line['squawk']; // squawk
929 1265
 			$data['emergency'] = ''; // emergency
930
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
931
-			else $data['datetime'] = date('Y-m-d H:i:s');
1266
+			if (isset($line['PosTime'])) {
1267
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1268
+			} else {
1269
+				$data['datetime'] = date('Y-m-d H:i:s');
1270
+			}
932 1271
 			$data['format_source'] = 'aircraftlistjson';
933 1272
 			$data['id_source'] = $id_source;
934
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
935
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1273
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1274
+				$data['noarchive'] = true;
1275
+			}
1276
+			if (isset($value['name']) && $value['name'] != '') {
1277
+				$data['source_name'] = $value['name'];
1278
+			}
936 1279
 			$SI->add($data);
937 1280
 			unset($data);
938 1281
 		    }
939 1282
 		}
940
-	    } elseif ($globalDebug) echo 'No data'."\n";
1283
+	    } elseif ($globalDebug) {
1284
+	    	echo 'No data'."\n";
1285
+	    }
941 1286
     	    //$last_exec['aircraftlistjson'] = time();
942 1287
     	    $last_exec[$id]['last'] = time();
943 1288
     	//} elseif ($value === 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
@@ -973,8 +1318,12 @@  discard block
 block discarded – undo
973 1318
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
974 1319
 	    	    $data['format_source'] = 'planeupdatefaa';
975 1320
     		    $data['id_source'] = $id_source;
976
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
977
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1321
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1322
+		    	$data['noarchive'] = true;
1323
+		    }
1324
+		    if (isset($value['name']) && $value['name'] != '') {
1325
+		    	$data['source_name'] = $value['name'];
1326
+		    }
978 1327
 		    $SI->add($data);
979 1328
 		    unset($data);
980 1329
 		}
@@ -1008,7 +1357,9 @@  discard block
 block discarded – undo
1008 1357
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1009 1358
 		    $data['format_source'] = 'opensky';
1010 1359
 		    $data['id_source'] = $id_source;
1011
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1360
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1361
+		    	$data['noarchive'] = true;
1362
+		    }
1012 1363
 		    $SI->add($data);
1013 1364
 		    unset($data);
1014 1365
 		}
@@ -1027,22 +1378,51 @@  discard block
 block discarded – undo
1027 1378
 		$reset = 0;
1028 1379
 		foreach ($all_data['aircraft'] as $key => $line) {
1029 1380
 		    $data = array();
1030
-		    if (isset($line['hex'])) $data['hex'] = $line['hex']; // hex
1031
-		    if (isset($line['flight'])) $data['ident'] = trim($line['flight']); // ident
1032
-		    if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; // altitude
1033
-		    if (isset($line['speed'])) $data['speed'] = $line['speed']; // speed
1034
-		    if (isset($line['track'])) $data['heading'] = $line['track']; // heading
1035
-		    if (isset($line['lat'])) $data['latitude'] = $line['lat']; // lat
1036
-		    if (isset($line['lon'])) $data['longitude'] = $line['lon']; // long
1037
-		    if (isset($line['vert_rate'])) $data['verticalrate'] = $line['vert_rate']; // verticale rate
1038
-		    if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; // squawk
1381
+		    if (isset($line['hex'])) {
1382
+		    	$data['hex'] = $line['hex'];
1383
+		    }
1384
+		    // hex
1385
+		    if (isset($line['flight'])) {
1386
+		    	$data['ident'] = trim($line['flight']);
1387
+		    }
1388
+		    // ident
1389
+		    if (isset($line['altitude'])) {
1390
+		    	$data['altitude'] = $line['altitude'];
1391
+		    }
1392
+		    // altitude
1393
+		    if (isset($line['speed'])) {
1394
+		    	$data['speed'] = $line['speed'];
1395
+		    }
1396
+		    // speed
1397
+		    if (isset($line['track'])) {
1398
+		    	$data['heading'] = $line['track'];
1399
+		    }
1400
+		    // heading
1401
+		    if (isset($line['lat'])) {
1402
+		    	$data['latitude'] = $line['lat'];
1403
+		    }
1404
+		    // lat
1405
+		    if (isset($line['lon'])) {
1406
+		    	$data['longitude'] = $line['lon'];
1407
+		    }
1408
+		    // long
1409
+		    if (isset($line['vert_rate'])) {
1410
+		    	$data['verticalrate'] = $line['vert_rate'];
1411
+		    }
1412
+		    // verticale rate
1413
+		    if (isset($line['squawk'])) {
1414
+		    	$data['squawk'] = $line['squawk'];
1415
+		    }
1416
+		    // squawk
1039 1417
 		    //$data['emergency'] = ''; // emergency
1040 1418
 		    //$data['registration'] = $line[2];
1041 1419
 		    //$data['aircraft_icao'] = $line[0];
1042 1420
 		    $data['datetime'] = date('Y-m-d H:i:s');
1043 1421
 		    $data['format_source'] = 'aircraftjson';
1044 1422
 		    $data['id_source'] = $id_source;
1045
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1423
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1424
+		    	$data['noarchive'] = true;
1425
+		    }
1046 1426
 		    $SI->add($data);
1047 1427
 		    unset($data);
1048 1428
 		}
@@ -1059,7 +1439,9 @@  discard block
 block discarded – undo
1059 1439
 	    //$buffer = $Common->getData($hosts[$id]);
1060 1440
 	    $buffer = $Common->getData($value['host']);
1061 1441
 	    $all_data = json_decode($buffer,true);
1062
-	    if (!empty($all_data)) $reset = 0;
1442
+	    if (!empty($all_data)) {
1443
+	    	$reset = 0;
1444
+	    }
1063 1445
 	    foreach ($all_data as $key => $line) {
1064 1446
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
1065 1447
 		    $data = array();
@@ -1080,8 +1462,12 @@  discard block
 block discarded – undo
1080 1462
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1081 1463
 	    	    $data['format_source'] = 'fr24json';
1082 1464
     		    $data['id_source'] = $id_source;
1083
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1084
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1465
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1466
+		    	$data['noarchive'] = true;
1467
+		    }
1468
+		    if (isset($value['name']) && $value['name'] != '') {
1469
+		    	$data['source_name'] = $value['name'];
1470
+		    }
1085 1471
 		    $SI->add($data);
1086 1472
 		    unset($data);
1087 1473
 		}
@@ -1110,24 +1496,42 @@  discard block
 block discarded – undo
1110 1496
 		    if (isset($line['inf'])) {
1111 1497
 			$data = array();
1112 1498
 			$data['hex'] = $line['inf']['ia'];
1113
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1499
+			if (isset($line['inf']['cs'])) {
1500
+				$data['ident'] = $line['inf']['cs'];
1501
+			}
1502
+			//$line[13]
1114 1503
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1115
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1116
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1504
+	    		if (isset($line['inf']['gs'])) {
1505
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1506
+	    		}
1507
+	    		// speed
1508
+	    		if (isset($line['inf']['tr'])) {
1509
+	    			$data['heading'] = $line['inf']['tr'];
1510
+	    		}
1511
+	    		// heading
1117 1512
 	    		$data['latitude'] = $line['pt'][0]; // lat
1118 1513
 	    		$data['longitude'] = $line['pt'][1]; // long
1119 1514
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1120
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1515
+	    		if (isset($line['inf']['sq'])) {
1516
+	    			$data['squawk'] = $line['inf']['sq'];
1517
+	    		}
1518
+	    		// squawk
1121 1519
 	    		//$data['aircraft_icao'] = $line[8];
1122
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1520
+	    		if (isset($line['inf']['rc'])) {
1521
+	    			$data['registration'] = $line['inf']['rc'];
1522
+	    		}
1123 1523
 			//$data['departure_airport_iata'] = $line[11];
1124 1524
 			//$data['arrival_airport_iata'] = $line[12];
1125 1525
 	    		//$data['emergency'] = ''; // emergency
1126 1526
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1127 1527
 	    		$data['format_source'] = 'radarvirtueljson';
1128 1528
     			$data['id_source'] = $id_source;
1129
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1130
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1529
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1530
+				$data['noarchive'] = true;
1531
+			}
1532
+			if (isset($value['name']) && $value['name'] != '') {
1533
+				$data['source_name'] = $value['name'];
1534
+			}
1131 1535
 			$SI->add($data);
1132 1536
 			unset($data);
1133 1537
 		    }
@@ -1153,30 +1557,65 @@  discard block
 block discarded – undo
1153 1557
 		    $data['id'] = $line['id'];
1154 1558
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1155 1559
 		    $data['ident'] = $line['callsign']; // ident
1156
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1157
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1158
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1159
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1160
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1161
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1560
+		    if (isset($line['pilotid'])) {
1561
+		    	$data['pilot_id'] = $line['pilotid'];
1562
+		    }
1563
+		    // pilot id
1564
+		    if (isset($line['name'])) {
1565
+		    	$data['pilot_name'] = $line['name'];
1566
+		    }
1567
+		    // pilot name
1568
+		    if (isset($line['alt'])) {
1569
+		    	$data['altitude'] = $line['alt'];
1570
+		    }
1571
+		    // altitude
1572
+		    if (isset($line['gs'])) {
1573
+		    	$data['speed'] = $line['gs'];
1574
+		    }
1575
+		    // speed
1576
+		    if (isset($line['heading'])) {
1577
+		    	$data['heading'] = $line['heading'];
1578
+		    }
1579
+		    // heading
1580
+		    if (isset($line['route'])) {
1581
+		    	$data['waypoints'] = $line['route'];
1582
+		    }
1583
+		    // route
1162 1584
 		    $data['latitude'] = $line['lat']; // lat
1163 1585
 		    $data['longitude'] = $line['lon']; // long
1164 1586
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
1165 1587
 		    //$data['squawk'] = $line['squawk']; // squawk
1166 1588
 		    //$data['emergency'] = ''; // emergency
1167
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1168
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1169
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1589
+		    if (isset($line['depicao'])) {
1590
+		    	$data['departure_airport_icao'] = $line['depicao'];
1591
+		    }
1592
+		    if (isset($line['deptime'])) {
1593
+		    	$data['departure_airport_time'] = $line['deptime'];
1594
+		    }
1595
+		    if (isset($line['arricao'])) {
1596
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1597
+		    }
1170 1598
 		    //$data['arrival_airport_time'] = $line['arrtime'];
1171
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1172
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1173
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
1174
-		    else $data['info'] = '';
1599
+		    if (isset($line['aircraft'])) {
1600
+		    	$data['aircraft_icao'] = $line['aircraft'];
1601
+		    }
1602
+		    if (isset($line['transponder'])) {
1603
+		    	$data['squawk'] = $line['transponder'];
1604
+		    }
1605
+		    if (isset($line['atis'])) {
1606
+		    	$data['info'] = $line['atis'];
1607
+		    } else {
1608
+		    	$data['info'] = '';
1609
+		    }
1175 1610
 		    $data['format_source'] = 'pireps';
1176 1611
     		    $data['id_source'] = $id_source;
1177 1612
 		    $data['datetime'] = date('Y-m-d H:i:s');
1178
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1179
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1613
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1614
+		    	$data['noarchive'] = true;
1615
+		    }
1616
+		    if (isset($value['name']) && $value['name'] != '') {
1617
+		    	$data['source_name'] = $value['name'];
1618
+		    }
1180 1619
 		    if ($line['icon'] === 'plane') {
1181 1620
 			$SI->add($data);
1182 1621
 		    //    print_r($data);
@@ -1185,16 +1624,28 @@  discard block
 block discarded – undo
1185 1624
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1186 1625
 			$typec = substr($data['ident'],-3);
1187 1626
 			$data['type'] = '';
1188
-			if ($typec === 'APP') $data['type'] = 'Approach';
1189
-			elseif ($typec === 'TWR') $data['type'] = 'Tower';
1190
-			elseif ($typec === 'OBS') $data['type'] = 'Observer';
1191
-			elseif ($typec === 'GND') $data['type'] = 'Ground';
1192
-			elseif ($typec === 'DEL') $data['type'] = 'Delivery';
1193
-			elseif ($typec === 'DEP') $data['type'] = 'Departure';
1194
-			elseif ($typec === 'FSS') $data['type'] = 'Flight Service Station';
1195
-			elseif ($typec === 'CTR') $data['type'] = 'Control Radar or Centre';
1196
-			else $data['type'] = 'Observer';
1197
-			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']);
1627
+			if ($typec === 'APP') {
1628
+				$data['type'] = 'Approach';
1629
+			} elseif ($typec === 'TWR') {
1630
+				$data['type'] = 'Tower';
1631
+			} elseif ($typec === 'OBS') {
1632
+				$data['type'] = 'Observer';
1633
+			} elseif ($typec === 'GND') {
1634
+				$data['type'] = 'Ground';
1635
+			} elseif ($typec === 'DEL') {
1636
+				$data['type'] = 'Delivery';
1637
+			} elseif ($typec === 'DEP') {
1638
+				$data['type'] = 'Departure';
1639
+			} elseif ($typec === 'FSS') {
1640
+				$data['type'] = 'Flight Service Station';
1641
+			} elseif ($typec === 'CTR') {
1642
+				$data['type'] = 'Control Radar or Centre';
1643
+			} else {
1644
+				$data['type'] = 'Observer';
1645
+			}
1646
+			if (isset($ATC)) {
1647
+				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']);
1648
+			}
1198 1649
 		    }
1199 1650
 		    unset($data);
1200 1651
 		}
@@ -1209,7 +1660,9 @@  discard block
 block discarded – undo
1209 1660
 	    )
1210 1661
 	) {
1211 1662
 	    //$buffer = $Common->getData($hosts[$id]);
1212
-	    if ($globalDebug) echo 'Get Data...'."\n";
1663
+	    if ($globalDebug) {
1664
+	    	echo 'Get Data...'."\n";
1665
+	    }
1213 1666
 	    $buffer = $Common->getData($value['host']);
1214 1667
 	    $all_data = json_decode($buffer,true);
1215 1668
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1217,10 +1670,16 @@  discard block
 block discarded – undo
1217 1670
 		foreach ($all_data as $line) {
1218 1671
 	    	    $data = array();
1219 1672
 	    	    //$data['id'] = $line['id']; // id not usable
1220
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1673
+	    	    if (isset($line['pilotid'])) {
1674
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1675
+	    	    }
1221 1676
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1222
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1223
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1677
+	    	    if (isset($line['pilotname'])) {
1678
+	    	    	$data['pilot_name'] = $line['pilotname'];
1679
+	    	    }
1680
+	    	    if (isset($line['pilotid'])) {
1681
+	    	    	$data['pilot_id'] = $line['pilotid'];
1682
+	    	    }
1224 1683
 	    	    $data['ident'] = $line['flightnum']; // ident
1225 1684
 	    	    $data['altitude'] = $line['alt']; // altitude
1226 1685
 	    	    $data['speed'] = $line['gs']; // speed
@@ -1236,7 +1695,9 @@  discard block
 block discarded – undo
1236 1695
 	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1237 1696
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1238 1697
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1239
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1698
+	    	    } else {
1699
+	    	    	$data['datetime'] = date('Y-m-d H:i:s');
1700
+	    	    }
1240 1701
 	    	    $data['departure_airport_icao'] = $line['depicao'];
1241 1702
 	    	    $data['departure_airport_time'] = $line['deptime'];
1242 1703
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
@@ -1244,29 +1705,47 @@  discard block
 block discarded – undo
1244 1705
     		    if (isset($line['registration'])) {
1245 1706
     			$data['registration'] = $line['registration'];
1246 1707
     			//if (isset($line['aircraft'])) $data['id'] = $line['aircraft'];
1247
-    		    } else $data['registration'] = $line['aircraft'];
1248
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1249
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1708
+    		    } else {
1709
+    		    	$data['registration'] = $line['aircraft'];
1710
+    		    }
1711
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1712
+		    	$data['noarchive'] = true;
1713
+		    }
1714
+		    if (isset($line['route'])) {
1715
+		    	$data['waypoints'] = $line['route'];
1716
+		    }
1717
+		    // route
1250 1718
 		    if (isset($line['aircraftname'])) {
1251 1719
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1252 1720
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1253 1721
 	    		$aircraft_data = explode('-',$line['aircraftname']);
1254
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1255
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1256
-	    		else {
1722
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) {
1723
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1724
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) {
1725
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1726
+	    		} else {
1257 1727
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1258
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1259
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1728
+	    		    if (isset($aircraft_data[1])) {
1729
+	    		    	$data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1730
+	    		    } else {
1731
+	    		    	$data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1732
+	    		    }
1260 1733
 	    		}
1261 1734
 	    	    }
1262
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1735
+    		    if (isset($line['route'])) {
1736
+    		    	$data['waypoints'] = $line['route'];
1737
+    		    }
1263 1738
     		    $data['id_source'] = $id_source;
1264 1739
 	    	    $data['format_source'] = 'phpvmacars';
1265
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1740
+		    if (isset($value['name']) && $value['name'] != '') {
1741
+		    	$data['source_name'] = $value['name'];
1742
+		    }
1266 1743
 		    $SI->add($data);
1267 1744
 		    unset($data);
1268 1745
 		}
1269
-		if ($globalDebug) echo 'No more data...'."\n";
1746
+		if ($globalDebug) {
1747
+			echo 'No more data...'."\n";
1748
+		}
1270 1749
 		unset($buffer);
1271 1750
 		unset($all_data);
1272 1751
 	    }
@@ -1279,7 +1758,9 @@  discard block
 block discarded – undo
1279 1758
 	    )
1280 1759
 	) {
1281 1760
 	    //$buffer = $Common->getData($hosts[$id]);
1282
-	    if ($globalDebug) echo 'Get Data...'."\n";
1761
+	    if ($globalDebug) {
1762
+	    	echo 'Get Data...'."\n";
1763
+	    }
1283 1764
 	    $buffer = $Common->getData($value['host']);
1284 1765
 	    $all_data = json_decode($buffer,true);
1285 1766
 	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
@@ -1290,10 +1771,16 @@  discard block
 block discarded – undo
1290 1771
 	    	    //$data['id'] = $line['id']; // id not usable
1291 1772
 	    	    $data['id'] = $line['id'];
1292 1773
 	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1293
-	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1294
-	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1774
+	    	    if (isset($line['user']['username'])) {
1775
+	    	    	$data['pilot_name'] = $line['user']['username'];
1776
+	    	    }
1777
+	    	    if (isset($line['user_id'])) {
1778
+	    	    	$data['pilot_id'] = $line['user_id'];
1779
+	    	    }
1295 1780
 	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1296
-	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1781
+	    	    if (is_numeric($data['ident'])) {
1782
+	    	    	$data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1783
+	    	    }
1297 1784
 	    	    $data['altitude'] = $line['altitude']; // altitude
1298 1785
 	    	    $data['speed'] = $line['groundspeed']; // speed
1299 1786
 	    	    $data['heading'] = $line['heading']; // heading
@@ -1306,7 +1793,9 @@  discard block
 block discarded – undo
1306 1793
 	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1307 1794
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1308 1795
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1309
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1796
+	    	    } else {
1797
+	    	    	$data['datetime'] = date('Y-m-d H:i:s');
1798
+	    	    }
1310 1799
 	    	    
1311 1800
 	    	    $data['departure_airport_icao'] = $line['bid']['depapt']['icao'];
1312 1801
 	    	    $data['departure_airport_time'] = $line['bid']['deptime'];
@@ -1314,17 +1803,26 @@  discard block
 block discarded – undo
1314 1803
 		    $data['arrival_airport_time'] = $line['bid']['arrtime'];
1315 1804
 		    $data['registration'] = $line['bid']['aircraft']['registration'];
1316 1805
 
1317
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1318
-		    if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route
1806
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1807
+		    	$data['noarchive'] = true;
1808
+		    }
1809
+		    if (isset($line['bid']['route']) && $line['bid']['route'] != '') {
1810
+		    	$data['waypoints'] = $line['bid']['route'];
1811
+		    }
1812
+		    // route
1319 1813
 	    	    $data['aircraft_icao'] = $line['bid']['aircraft']['icao'];
1320 1814
 
1321 1815
     		    $data['id_source'] = $id_source;
1322 1816
 	    	    $data['format_source'] = 'vaos';
1323
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1817
+		    if (isset($value['name']) && $value['name'] != '') {
1818
+		    	$data['source_name'] = $value['name'];
1819
+		    }
1324 1820
 		    $SI->add($data);
1325 1821
 		    unset($data);
1326 1822
 		}
1327
-		if ($globalDebug) echo 'No more data...'."\n";
1823
+		if ($globalDebug) {
1824
+			echo 'No more data...'."\n";
1825
+		}
1328 1826
 		unset($buffer);
1329 1827
 		unset($all_data);
1330 1828
 	    }
@@ -1337,7 +1835,9 @@  discard block
 block discarded – undo
1337 1835
 	    )
1338 1836
 	) {
1339 1837
 	    //$buffer = $Common->getData($hosts[$id]);
1340
-	    if ($globalDebug) echo 'Get Data...'."\n";
1838
+	    if ($globalDebug) {
1839
+	    	echo 'Get Data...'."\n";
1840
+	    }
1341 1841
 	    $buffer = $Common->getData($value['host']);
1342 1842
 	    $all_data = json_decode($buffer,true);
1343 1843
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1366,16 +1866,25 @@  discard block
 block discarded – undo
1366 1866
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
1367 1867
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
1368 1868
     		    //$data['registration'] = $line['aircraft'];
1369
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1869
+		    if (isset($line['route'])) {
1870
+		    	$data['waypoints'] = $line['route'];
1871
+		    }
1872
+		    // route
1370 1873
 	    	    $data['aircraft_icao'] = $line['plane_type'];
1371 1874
     		    $data['id_source'] = $id_source;
1372 1875
 	    	    $data['format_source'] = 'vam';
1373
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1374
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1876
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1877
+		    	$data['noarchive'] = true;
1878
+		    }
1879
+		    if (isset($value['name']) && $value['name'] != '') {
1880
+		    	$data['source_name'] = $value['name'];
1881
+		    }
1375 1882
 		    $SI->add($data);
1376 1883
 		    unset($data);
1377 1884
 		}
1378
-		if ($globalDebug) echo 'No more data...'."\n";
1885
+		if ($globalDebug) {
1886
+			echo 'No more data...'."\n";
1887
+		}
1379 1888
 		unset($buffer);
1380 1889
 		unset($all_data);
1381 1890
 	    }
@@ -1388,7 +1897,9 @@  discard block
 block discarded – undo
1388 1897
 	    )
1389 1898
 	) {
1390 1899
 	    //$buffer = $Common->getData($hosts[$id]);
1391
-	    if ($globalDebug) echo 'Get Data...'."\n";
1900
+	    if ($globalDebug) {
1901
+	    	echo 'Get Data...'."\n";
1902
+	    }
1392 1903
 	    $buffer = $Common->getData($value['host']);
1393 1904
 	    $all_data = json_decode($buffer,true);
1394 1905
 	    if ($buffer != '') {
@@ -1406,12 +1917,16 @@  discard block
 block discarded – undo
1406 1917
 			$data['id_source'] = $id_source;
1407 1918
 			$data['format_source'] = 'blitzortung';
1408 1919
 			$SI->add($data);
1409
-			if ($globalDebug) echo '☈ Lightning added'."\n";
1920
+			if ($globalDebug) {
1921
+				echo '☈ Lightning added'."\n";
1922
+			}
1410 1923
 			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1411 1924
 			unset($data);
1412 1925
 		    }
1413 1926
 		}
1414
-		if ($globalDebug) echo 'No more data...'."\n";
1927
+		if ($globalDebug) {
1928
+			echo 'No more data...'."\n";
1929
+		}
1415 1930
 		unset($buffer);
1416 1931
 	    }
1417 1932
 	    $last_exec[$id]['last'] = time();
@@ -1423,7 +1938,9 @@  discard block
 block discarded – undo
1423 1938
 	    $write = NULL;
1424 1939
 	    $e = NULL;
1425 1940
 	    $n = socket_select($read, $write, $e, $timeout);
1426
-	    if ($e != NULL) var_dump($e);
1941
+	    if ($e != NULL) {
1942
+	    	var_dump($e);
1943
+	    }
1427 1944
 	    if ($n > 0) {
1428 1945
 		$reset = 0;
1429 1946
 		foreach ($read as $nb => $r) {
@@ -1445,13 +1962,17 @@  discard block
 block discarded – undo
1445 1962
 		    if ($buffer !== FALSE) {
1446 1963
 			if ($format === 'vrstcp') {
1447 1964
 			    $buffer = explode('},{',$buffer);
1448
-			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1965
+			} else {
1966
+				$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1967
+			}
1449 1968
 		    }
1450 1969
 		    // SBS format is CSV format
1451 1970
 		    if ($buffer !== FALSE && $buffer !== '') {
1452 1971
 			$tt[$format] = 0;
1453 1972
 			if ($format === 'acarssbs3') {
1454
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1973
+			    if ($globalDebug) {
1974
+			    	echo 'ACARS : '.$buffer."\n";
1975
+			    }
1455 1976
 			    $ACARS->add(trim($buffer));
1456 1977
 			    $ACARS->deleteLiveAcarsData();
1457 1978
 			} elseif ($format === 'raw') {
@@ -1460,30 +1981,70 @@  discard block
 block discarded – undo
1460 1981
 			    if (is_array($data)) {
1461 1982
 				$data['datetime'] = date('Y-m-d H:i:s');
1462 1983
 				$data['format_source'] = 'raw';
1463
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1464
-				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1465
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1466
-				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1984
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1985
+					$data['source_name'] = $globalSources[$nb]['name'];
1986
+				}
1987
+				if (isset($globalSources[$nb]['sourcestats'])) {
1988
+					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1989
+				}
1990
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1991
+					$data['noarchive'] = true;
1992
+				}
1993
+				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1994
+					$SI->add($data);
1995
+				}
1467 1996
 			    }
1468 1997
 			} elseif ($format === 'ais') {
1469 1998
 			    $ais_data = $AIS->parse_line(trim($buffer));
1470 1999
 			    $data = array();
1471
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1472
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1473
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1474
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1475
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1476
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1477
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1478
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1479
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1480
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1481
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1482
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1483
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1484
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1485
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1486
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2000
+			    if (isset($ais_data['ident'])) {
2001
+			    	$data['ident'] = $ais_data['ident'];
2002
+			    }
2003
+			    if (isset($ais_data['mmsi'])) {
2004
+			    	$data['mmsi'] = substr($ais_data['mmsi'],-9);
2005
+			    }
2006
+			    if (isset($ais_data['speed'])) {
2007
+			    	$data['speed'] = $ais_data['speed'];
2008
+			    }
2009
+			    if (isset($ais_data['heading'])) {
2010
+			    	$data['heading'] = $ais_data['heading'];
2011
+			    }
2012
+			    if (isset($ais_data['latitude'])) {
2013
+			    	$data['latitude'] = $ais_data['latitude'];
2014
+			    }
2015
+			    if (isset($ais_data['longitude'])) {
2016
+			    	$data['longitude'] = $ais_data['longitude'];
2017
+			    }
2018
+			    if (isset($ais_data['status'])) {
2019
+			    	$data['status'] = $ais_data['status'];
2020
+			    }
2021
+			    if (isset($ais_data['statusid'])) {
2022
+			    	$data['status_id'] = $ais_data['statusid'];
2023
+			    }
2024
+			    if (isset($ais_data['type'])) {
2025
+			    	$data['type'] = $ais_data['type'];
2026
+			    }
2027
+			    if (isset($ais_data['imo'])) {
2028
+			    	$data['imo'] = $ais_data['imo'];
2029
+			    }
2030
+			    if (isset($ais_data['callsign'])) {
2031
+			    	$data['callsign'] = $ais_data['callsign'];
2032
+			    }
2033
+			    if (isset($ais_data['destination'])) {
2034
+			    	$data['arrival_code'] = $ais_data['destination'];
2035
+			    }
2036
+			    if (isset($ais_data['eta_ts'])) {
2037
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
2038
+			    }
2039
+			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2040
+			    	$data['noarchive'] = true;
2041
+			    }
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
+			    }
1487 2048
 
1488 2049
 			    if (isset($ais_data['timestamp'])) {
1489 2050
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1492,7 +2053,9 @@  discard block
 block discarded – undo
1492 2053
 			    }
1493 2054
 			    $data['format_source'] = 'aisnmea';
1494 2055
     			    $data['id_source'] = $id_source;
1495
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') $MI->add($data);
2056
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] === 'Ship') {
2057
+			    	$MI->add($data);
2058
+			    }
1496 2059
 			    unset($data);
1497 2060
                         } elseif ($format === 'flightgearsp') {
1498 2061
                     	    //echo $buffer."\n";
@@ -1510,12 +2073,18 @@  discard block
 block discarded – undo
1510 2073
 				$data['speed'] = round($line[5]*1.94384);
1511 2074
 				$data['datetime'] = date('Y-m-d H:i:s');
1512 2075
 				$data['format_source'] = 'flightgearsp';
1513
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1514
-				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2076
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2077
+					$data['noarchive'] = true;
2078
+				}
2079
+				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2080
+					$SI->add($data);
2081
+				}
1515 2082
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1516 2083
 			    }
1517 2084
                         } elseif ($format === 'acars') {
1518
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
2085
+                    	    if ($globalDebug) {
2086
+                    	    	echo 'ACARS : '.$buffer."\n";
2087
+                    	    }
1519 2088
 			    $ACARS->add(trim($buffer));
1520 2089
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1521 2090
 			    $ACARS->deleteLiveAcarsData();
@@ -1536,8 +2105,12 @@  discard block
 block discarded – undo
1536 2105
 				    $aircraft_type = $line[10];
1537 2106
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1538 2107
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1539
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1540
-				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2108
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2109
+				    	$data['noarchive'] = true;
2110
+				    }
2111
+				    if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2112
+				    	$SI->add($data);
2113
+				    }
1541 2114
 				}
1542 2115
 			    }
1543 2116
 			} elseif ($format === 'beast') {
@@ -1547,28 +2120,62 @@  discard block
 block discarded – undo
1547 2120
 			    foreach($buffer as $all_data) {
1548 2121
 				$line = json_decode('{'.$all_data.'}',true);
1549 2122
 				$data = array();
1550
-				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1551
-				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1552
-				if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1553
-				if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1554
-				if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1555
-				if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1556
-				if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
2123
+				if (isset($line['Icao'])) {
2124
+					$data['hex'] = $line['Icao'];
2125
+				}
2126
+				// hex
2127
+				if (isset($line['Call'])) {
2128
+					$data['ident'] = $line['Call'];
2129
+				}
2130
+				// ident
2131
+				if (isset($line['Alt'])) {
2132
+					$data['altitude'] = $line['Alt'];
2133
+				}
2134
+				// altitude
2135
+				if (isset($line['Spd'])) {
2136
+					$data['speed'] = $line['Spd'];
2137
+				}
2138
+				// speed
2139
+				if (isset($line['Trak'])) {
2140
+					$data['heading'] = $line['Trak'];
2141
+				}
2142
+				// heading
2143
+				if (isset($line['Lat'])) {
2144
+					$data['latitude'] = $line['Lat'];
2145
+				}
2146
+				// lat
2147
+				if (isset($line['Long'])) {
2148
+					$data['longitude'] = $line['Long'];
2149
+				}
2150
+				// long
1557 2151
 				//$data['verticalrate'] = $line['']; // verticale rate
1558
-				if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
2152
+				if (isset($line['Sqk'])) {
2153
+					$data['squawk'] = $line['Sqk'];
2154
+				}
2155
+				// squawk
1559 2156
 				$data['emergency'] = ''; // emergency
1560
-				if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
2157
+				if (isset($line['Reg'])) {
2158
+					$data['registration'] = $line['Reg'];
2159
+				}
1561 2160
 				/*
1562 2161
 				if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
1563 2162
 				else $data['datetime'] = date('Y-m-d H:i:s');
1564 2163
 				*/
1565 2164
 				$data['datetime'] = date('Y-m-d H:i:s');
1566
-				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
2165
+				if (isset($line['Type'])) {
2166
+					$data['aircraft_icao'] = $line['Type'];
2167
+				}
1567 2168
 		    		$data['format_source'] = 'vrstcp';
1568 2169
 				$data['id_source'] = $id_source;
1569
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1570
-				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1571
-				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
2170
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2171
+					$data['noarchive'] = true;
2172
+				}
2173
+				if (isset($value['name']) && $value['name'] != '') {
2174
+					$data['source_name'] = $value['name'];
2175
+				}
2176
+				if (isset($data['latitude']) && isset($data['hex'])) {
2177
+					$SI->add($data);
2178
+				}
1572 2179
 				unset($data);
1573 2180
 			    }
1574 2181
 			} elseif ($format === 'tsv' || substr($buffer,0,4) === 'clock') {
@@ -1581,22 +2188,46 @@  discard block
 block discarded – undo
1581 2188
     				$data['hex'] = $lined['hexid'];
1582 2189
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1583 2190
     				$data['datetime'] = date('Y-m-d H:i:s');;
1584
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1585
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1586
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1587
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1588
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1589
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1590
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
2191
+    				if (isset($lined['ident'])) {
2192
+    					$data['ident'] = $lined['ident'];
2193
+    				}
2194
+    				if (isset($lined['lat'])) {
2195
+    					$data['latitude'] = $lined['lat'];
2196
+    				}
2197
+    				if (isset($lined['lon'])) {
2198
+    					$data['longitude'] = $lined['lon'];
2199
+    				}
2200
+    				if (isset($lined['speed'])) {
2201
+    					$data['speed'] = $lined['speed'];
2202
+    				}
2203
+    				if (isset($lined['squawk'])) {
2204
+    					$data['squawk'] = $lined['squawk'];
2205
+    				}
2206
+    				if (isset($lined['alt'])) {
2207
+    					$data['altitude'] = $lined['alt'];
2208
+    				}
2209
+    				if (isset($lined['heading'])) {
2210
+    					$data['heading'] = $lined['heading'];
2211
+    				}
1591 2212
     				$data['id_source'] = $id_source;
1592 2213
     				$data['format_source'] = 'tsv';
1593
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1594
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1595
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1596
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2214
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2215
+    					$data['source_name'] = $globalSources[$nb]['name'];
2216
+    				}
2217
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2218
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2219
+    				}
2220
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2221
+					$data['noarchive'] = true;
2222
+				}
2223
+    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2224
+    					$SI->add($data);
2225
+    				}
1597 2226
     				unset($lined);
1598 2227
     				unset($data);
1599
-    			    } else $error = true;
2228
+    			    } else {
2229
+    			    	$error = true;
2230
+    			    }
1600 2231
 			} elseif ($format === 'aprs' && $use_aprs) {
1601 2232
 			    if ($aprs_connect === 0) {
1602 2233
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1622,63 +2253,121 @@  discard block
 block discarded – undo
1622 2253
 				    $aprs_last_tx = time();
1623 2254
 				    $data = array();
1624 2255
 				    //print_r($line);
1625
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1626
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1627
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1628
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1629
-				    if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code'];
1630
-				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1631
-				    if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1632
-				    if (isset($line['statusid'])) $data['status_id'] = $line['statusid'];
1633
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1634
-				    else $data['datetime'] = date('Y-m-d H:i:s');
2256
+				    if (isset($line['address'])) {
2257
+				    	$data['hex'] = $line['address'];
2258
+				    }
2259
+				    if (isset($line['mmsi'])) {
2260
+				    	$data['mmsi'] = $line['mmsi'];
2261
+				    }
2262
+				    if (isset($line['imo'])) {
2263
+				    	$data['imo'] = $line['imo'];
2264
+				    }
2265
+				    if (isset($line['squawk'])) {
2266
+				    	$data['squawk'] = $line['squawk'];
2267
+				    }
2268
+				    if (isset($line['arrival_code'])) {
2269
+				    	$data['arrival_code'] = $line['arrival_code'];
2270
+				    }
2271
+				    if (isset($line['arrival_date'])) {
2272
+				    	$data['arrival_date'] = $line['arrival_date'];
2273
+				    }
2274
+				    if (isset($line['typeid'])) {
2275
+				    	$data['type_id'] = $line['typeid'];
2276
+				    }
2277
+				    if (isset($line['statusid'])) {
2278
+				    	$data['status_id'] = $line['statusid'];
2279
+				    }
2280
+				    if (isset($line['timestamp'])) {
2281
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
2282
+				    } else {
2283
+				    	$data['datetime'] = date('Y-m-d H:i:s');
2284
+				    }
1635 2285
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1636
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
2286
+				    if (isset($line['ident'])) {
2287
+				    	$data['ident'] = $line['ident'];
2288
+				    }
1637 2289
 				    $data['latitude'] = $line['latitude'];
1638 2290
 				    $data['longitude'] = $line['longitude'];
1639 2291
 				    //$data['verticalrate'] = $line[16];
1640
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
2292
+				    if (isset($line['speed'])) {
2293
+				    	$data['speed'] = $line['speed'];
2294
+				    }
1641 2295
 				    //else $data['speed'] = 0;
1642
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1643
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1644
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
2296
+				    if (isset($line['altitude'])) {
2297
+				    	$data['altitude'] = $line['altitude'];
2298
+				    }
2299
+				    if (isset($line['comment'])) {
2300
+				    	$data['comment'] = $line['comment'];
2301
+				    }
2302
+				    if (isset($line['symbol'])) {
2303
+				    	$data['type'] = $line['symbol'];
2304
+				    }
1645 2305
 				    //if (isset($line['heading'])) $data['heading'] = $line['heading'];
1646 2306
 				    
1647
-				    if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
2307
+				    if (isset($line['heading']) && isset($line['format_source'])) {
2308
+				    	$data['heading'] = $line['heading'];
2309
+				    }
1648 2310
 				    //else echo 'No heading...'."\n";
1649 2311
 				    //else $data['heading'] = 0;
1650
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
2312
+				    if (isset($line['stealth'])) {
2313
+				    	$data['aircraft_type'] = $line['stealth'];
2314
+				    }
1651 2315
 				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1652
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1653
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1654
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1655
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
2316
+				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) {
2317
+				    	$data['noarchive'] = true;
2318
+				    } elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) {
2319
+				    	$data['noarchive'] = false;
2320
+				    }
2321
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2322
+				    	$data['noarchive'] = true;
2323
+				    } elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) {
2324
+				    	$data['noarchive'] = false;
2325
+				    }
1656 2326
     				    $data['id_source'] = $id_source;
1657
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1658
-				    else $data['format_source'] = 'aprs';
2327
+    				    if (isset($line['format_source'])) {
2328
+    				    	$data['format_source'] = $line['format_source'];
2329
+    				    } else {
2330
+				    	$data['format_source'] = 'aprs';
2331
+				    }
1659 2332
 				    $data['source_name'] = $line['source'];
1660
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1661
-				    else $data['source_type'] = 'flarm';
1662
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2333
+				    if (isset($line['source_type'])) {
2334
+				    	$data['source_type'] = $line['source_type'];
2335
+				    } else {
2336
+				    	$data['source_type'] = 'flarm';
2337
+				    }
2338
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
2339
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2340
+    				    }
1663 2341
 				    $currentdate = date('Y-m-d H:i:s');
1664 2342
 				    $aprsdate = strtotime($data['datetime']);
1665
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
2343
+				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') {
2344
+				    	$data['altitude_relative'] = 'AMSL';
2345
+				    }
1666 2346
 				    // Accept data if time <= system time + 20s
1667 2347
 				    //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'])))) {
1668 2348
 				    if (($data['source_type'] === 'modes') || isset($line['stealth']) && (!isset($data['hex']) || $data['hex'] != 'FFFFFF') && ($line['stealth'] === 0 || $line['stealth'] === '') && (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1669 2349
 					$send = $SI->add($data);
1670 2350
 				    } elseif ($data['source_type'] === 'ais') {
1671 2351
 					$data['type'] = '';
1672
-					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
2352
+					if (isset($globalMarine) && $globalMarine) {
2353
+						$send = $MI->add($data);
2354
+					}
1673 2355
 				    } elseif (isset($line['stealth'])) {
1674
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1675
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
2356
+					if ($line['stealth'] != 0) {
2357
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
2358
+					} else {
2359
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
2360
+					}
1676 2361
 				    } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1677 2362
 					    //$line['symbol'] === 'Balloon' ||
1678 2363
 					    $line['symbol'] === 'Glider' || 
1679 2364
 					    $line['symbol'] === 'Aircraft (small)' || $line['symbol'] === 'Helicopter')) {
1680
-					    if ($line['symbol'] === 'Ballon') $data['aircraft_icao'] = 'BALL';
1681
-					    if ($line['symbol'] === 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
2365
+					    if ($line['symbol'] === 'Ballon') {
2366
+					    	$data['aircraft_icao'] = 'BALL';
2367
+					    }
2368
+					    if ($line['symbol'] === 'Glider') {
2369
+					    	$data['aircraft_icao'] = 'PARAGLIDER';
2370
+					    }
1682 2371
 					    $send = $SI->add($data);
1683 2372
 				    } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1684 2373
 					    $line['symbol'] === 'Yacht (Sail)' || 
@@ -1709,9 +2398,13 @@  discard block
 block discarded – undo
1709 2398
 				    //} 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') {
1710 2399
 				//    } 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') {
1711 2400
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1712
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
2401
+					if (isset($globalTracker) && $globalTracker) {
2402
+						$send = $TI->add($data);
2403
+					}
1713 2404
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1714
-					if (!isset($data['altitude'])) $data['altitude'] = 0;
2405
+					if (!isset($data['altitude'])) {
2406
+						$data['altitude'] = 0;
2407
+					}
1715 2408
 					$Source->deleteOldLocationByType('gs');
1716 2409
 					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
1717 2410
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
@@ -1720,7 +2413,9 @@  discard block
 block discarded – undo
1720 2413
 					}
1721 2414
 				    } elseif (isset($line['symbol']) && $line['symbol'] === 'Weather Station') {
1722 2415
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1723
-					if ($globalDebug) echo '# Weather Station added'."\n";
2416
+					if ($globalDebug) {
2417
+						echo '# Weather Station added'."\n";
2418
+					}
1724 2419
 					$Source->deleteOldLocationByType('wx');
1725 2420
 					$weather_data = json_encode($line);
1726 2421
 					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
@@ -1730,7 +2425,9 @@  discard block
 block discarded – undo
1730 2425
 					}
1731 2426
 				    } elseif (isset($line['symbol']) && ($line['symbol'] === 'Lightning' || $line['symbol'] === 'Thunderstorm')) {
1732 2427
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1733
-					if ($globalDebug) echo '☈ Lightning added'."\n";
2428
+					if ($globalDebug) {
2429
+						echo '☈ Lightning added'."\n";
2430
+					}
1734 2431
 					$Source->deleteOldLocationByType('lightning');
1735 2432
 					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
1736 2433
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
@@ -1742,8 +2439,7 @@  discard block
 block discarded – undo
1742 2439
 				    	print_r($line);
1743 2440
 				    }
1744 2441
 				    unset($data);
1745
-				}
1746
-				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
2442
+				} elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1747 2443
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
1748 2444
 				}
1749 2445
 				/*
@@ -1752,7 +2448,9 @@  discard block
 block discarded – undo
1752 2448
 				}
1753 2449
 				*/
1754 2450
 				//elseif ($line === false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1755
-				elseif ($line === true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
2451
+				elseif ($line === true && $globalDebug) {
2452
+					echo '!! Failed : '.$buffer."!!\n";
2453
+				}
1756 2454
 				if (isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
1757 2455
 					$Source->deleteOldLocationByType('lightning');
1758 2456
 					$Source->deleteOldLocationByType('wx');
@@ -1788,26 +2486,45 @@  discard block
 block discarded – undo
1788 2486
     				$data['ground'] = $line[21];
1789 2487
     				$data['emergency'] = $line[19];
1790 2488
     				$data['format_source'] = 'sbs';
1791
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1792
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1793
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
2489
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2490
+					$data['source_name'] = $globalSources[$nb]['name'];
2491
+				}
2492
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2493
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2494
+    				}
2495
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2496
+					$data['noarchive'] = true;
2497
+				}
1794 2498
     				$data['id_source'] = $id_source;
1795
-    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1796
-    				else $error = true;
2499
+    				if (($data['latitude'] === '' && $data['longitude'] === '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2500
+    					$send = $SI->add($data);
2501
+    				} else {
2502
+    					$error = true;
2503
+    				}
1797 2504
     				unset($data);
1798
-    			    } else $error = true;
2505
+    			    } else {
2506
+    			    	$error = true;
2507
+    			    }
1799 2508
 			    if ($error) {
1800 2509
 				if (count($line) > 1 && ($line[0] === 'STA' || $line[0] === 'AIR' || $line[0] === 'SEL' || $line[0] === 'ID' || $line[0] === 'CLK')) { 
1801
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
2510
+					if ($globalDebug) {
2511
+						echo "Not a message. Ignoring... \n";
2512
+					}
1802 2513
 				} else {
1803
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
2514
+					if ($globalDebug) {
2515
+						echo "Wrong line format. Ignoring... \n";
2516
+					}
1804 2517
 					if ($globalDebug) {
1805 2518
 						echo $buffer;
1806 2519
 						//print_r($line);
1807 2520
 					}
1808 2521
 					//socket_close($r);
1809
-					if ($globalDebug) echo "Reconnect after an error...\n";
1810
-					if ($format === 'aprs') $aprs_connect = 0;
2522
+					if ($globalDebug) {
2523
+						echo "Reconnect after an error...\n";
2524
+					}
2525
+					if ($format === 'aprs') {
2526
+						$aprs_connect = 0;
2527
+					}
1811 2528
 					$sourceer[$nb] = $globalSources[$nb];
1812 2529
 					connect_all($sourceer);
1813 2530
 					$sourceer = array();
@@ -1815,10 +2532,14 @@  discard block
 block discarded – undo
1815 2532
 			    }
1816 2533
 			}
1817 2534
 			// Sleep for xxx microseconds
1818
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
2535
+			if (isset($globalSBSSleep)) {
2536
+				usleep($globalSBSSleep);
2537
+			}
1819 2538
 		    } else {
1820 2539
 			if ($format === 'flightgearmp') {
1821
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
2540
+			    	if ($globalDebug) {
2541
+			    		echo "Reconnect FlightGear MP...";
2542
+			    	}
1822 2543
 				//@socket_close($r);
1823 2544
 				sleep($globalMinFetch);
1824 2545
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1827,10 +2548,15 @@  discard block
 block discarded – undo
1827 2548
 				break;
1828 2549
 				
1829 2550
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1830
-			    if (isset($tt[$format])) $tt[$format]++;
1831
-			    else $tt[$format] = 0;
2551
+			    if (isset($tt[$format])) {
2552
+			    	$tt[$format]++;
2553
+			    } else {
2554
+			    	$tt[$format] = 0;
2555
+			    }
1832 2556
 			    if ($tt[$format] > 30 || $buffer === FALSE) {
1833
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
2557
+				if ($globalDebug) {
2558
+					echo "ERROR : Reconnect ".$format."...";
2559
+				}
1834 2560
 				//@socket_close($r);
1835 2561
 				sleep(2);
1836 2562
 				$aprs_connect = 0;
@@ -1848,11 +2574,17 @@  discard block
 block discarded – undo
1848 2574
 	    } else {
1849 2575
 		$error = socket_strerror(socket_last_error());
1850 2576
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1851
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1852
-			if (isset($globalDebug)) echo "Restarting...\n";
2577
+			if ($globalDebug) {
2578
+				echo "ERROR : socket_select give this error ".$error . "\n";
2579
+			}
2580
+			if (isset($globalDebug)) {
2581
+				echo "Restarting...\n";
2582
+			}
1853 2583
 			// Restart the script if possible
1854 2584
 			if (is_array($sockets)) {
1855
-			    if ($globalDebug) echo "Shutdown all sockets...";
2585
+			    if ($globalDebug) {
2586
+			    	echo "Shutdown all sockets...";
2587
+			    }
1856 2588
 			    
1857 2589
 			    foreach ($sockets as $sock) {
1858 2590
 				@socket_shutdown($sock,2);
@@ -1860,25 +2592,45 @@  discard block
 block discarded – undo
1860 2592
 			    }
1861 2593
 			    
1862 2594
 			}
1863
-			if ($globalDebug) echo "Waiting...";
2595
+			if ($globalDebug) {
2596
+				echo "Waiting...";
2597
+			}
1864 2598
 			sleep(2);
1865 2599
 			$time = time();
1866 2600
 			//connect_all($hosts);
1867 2601
 			$aprs_connect = 0;
1868
-			if ($reset%5 === 0) sleep(20);
1869
-			if ($reset%10 === 0) sleep(100);
1870
-			if ($reset%20 === 0) sleep(200);
1871
-			if ($reset > 100) exit('Too many attempts...');
1872
-			if ($globalDebug) echo "Restart all connections...";
2602
+			if ($reset%5 === 0) {
2603
+				sleep(20);
2604
+			}
2605
+			if ($reset%10 === 0) {
2606
+				sleep(100);
2607
+			}
2608
+			if ($reset%20 === 0) {
2609
+				sleep(200);
2610
+			}
2611
+			if ($reset > 100) {
2612
+				exit('Too many attempts...');
2613
+			}
2614
+			if ($globalDebug) {
2615
+				echo "Restart all connections...";
2616
+			}
1873 2617
 			connect_all($globalSources);
1874 2618
 		}
1875 2619
 	    }
1876 2620
 	}
1877 2621
 	if ($globalDaemon === false) {
1878
-	    if ($globalDebug) echo 'Check all...'."\n";
1879
-	    if (isset($SI)) $SI->checkAll();
1880
-	    if (isset($TI)) $TI->checkAll();
1881
-	    if (isset($MI)) $MI->checkAll();
2622
+	    if ($globalDebug) {
2623
+	    	echo 'Check all...'."\n";
2624
+	    }
2625
+	    if (isset($SI)) {
2626
+	    	$SI->checkAll();
2627
+	    }
2628
+	    if (isset($TI)) {
2629
+	    	$TI->checkAll();
2630
+	    }
2631
+	    if (isset($MI)) {
2632
+	    	$MI->checkAll();
2633
+	    }
1882 2634
 	}
1883 2635
     }
1884 2636
 }
Please login to merge, or discard this patch.