Completed
Push — master ( cf2135...b184e5 )
by Yannick
28:22
created
scripts/daemon-spotter.php 1 patch
Braces   +1047 added lines, -357 removed lines patch added patch discarded remove patch
@@ -14,13 +14,17 @@  discard block
 block discarded – undo
14 14
 require_once(dirname(__FILE__).'/../require/class.Source.php');
15 15
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
16 16
 require_once(dirname(__FILE__).'/../require/class.Common.php');
17
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
17
+if (isset($globalTracker) && $globalTracker) {
18
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
19
+}
18 20
 if (isset($globalMarine) && $globalMarine) {
19 21
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
20 22
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
21 23
 }
22 24
 
23
-if (!isset($globalDebug)) $globalDebug = FALSE;
25
+if (!isset($globalDebug)) {
26
+	$globalDebug = FALSE;
27
+}
24 28
 
25 29
 // Check if schema is at latest version
26 30
 $Connection = new Connection();
@@ -59,66 +63,107 @@  discard block
 block discarded – undo
59 63
 //elseif (isset($options['source'])) $hosts = array($options['source']);
60 64
 if (isset($options['s'])) {
61 65
     $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
63
-    else $globalSources[] = array('host' => $options['s']);
64
-} elseif (isset($options['source'])) {
66
+    if (isset($options['format'])) {
67
+    	$globalSources[] = array('host' => $options['s'],'format' => $options['format']);
68
+    } else {
69
+    	$globalSources[] = array('host' => $options['s']);
70
+    }
71
+    } elseif (isset($options['source'])) {
65 72
     $globalSources = array();
66
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
67
-    else $globalSources[] = array('host' => $options['source']);
68
-}
73
+    if (isset($options['format'])) {
74
+    	$globalSources[] = array('host' => $options['source'],'format' => $options['format']);
75
+    } else {
76
+    	$globalSources[] = array('host' => $options['source']);
77
+    }
78
+    }
69 79
 if (isset($options['aprsserverhost'])) {
70 80
 	$globalServerAPRS = TRUE;
71 81
 	$globalServerAPRShost = $options['aprsserverhost'];
72 82
 }
73
-if (isset($options['aprsserverport'])) $globalServerAPRSport = $options['aprsserverport'];
74
-if (isset($options['aprsserverssid'])) $globalServerAPRSssid = $options['aprsserverssid'];
75
-if (isset($options['aprsserverpass'])) $globalServerAPRSpass = $options['aprsserverpass'];
76
-if (isset($options['noaprsserver'])) $globalServerAPRS = FALSE; 
83
+if (isset($options['aprsserverport'])) {
84
+	$globalServerAPRSport = $options['aprsserverport'];
85
+}
86
+if (isset($options['aprsserverssid'])) {
87
+	$globalServerAPRSssid = $options['aprsserverssid'];
88
+}
89
+if (isset($options['aprsserverpass'])) {
90
+	$globalServerAPRSpass = $options['aprsserverpass'];
91
+}
92
+if (isset($options['noaprsserver'])) {
93
+	$globalServerAPRS = FALSE;
94
+}
77 95
 if (isset($options['enable-aircraft'])) {
78
-	if ($globalDebug) echo 'Enable Aircraft mode'."\n";
96
+	if ($globalDebug) {
97
+		echo 'Enable Aircraft mode'."\n";
98
+	}
79 99
 	$globalAircraft = TRUE; 
80 100
 }
81 101
 if (isset($options['disable-aircraft'])) {
82
-	if ($globalDebug) echo 'Disable Aircraft mode'."\n";
102
+	if ($globalDebug) {
103
+		echo 'Disable Aircraft mode'."\n";
104
+	}
83 105
 	$globalAircraft = FALSE;
84 106
 }
85 107
 if (isset($options['enable-tracker'])) {
86
-	if ($globalDebug) echo 'Enable Tracker mode'."\n";
108
+	if ($globalDebug) {
109
+		echo 'Enable Tracker mode'."\n";
110
+	}
87 111
 	$globalTracker = TRUE; 
88 112
 }
89 113
 if (isset($options['disable-tracker'])) {
90
-	if ($globalDebug) echo 'Disable Tracker mode'."\n";
114
+	if ($globalDebug) {
115
+		echo 'Disable Tracker mode'."\n";
116
+	}
91 117
 	$globalTracker = FALSE;
92 118
 }
93 119
 if (isset($options['enable-marine'])) {
94
-	if ($globalDebug) echo 'Enable Marine mode'."\n";
120
+	if ($globalDebug) {
121
+		echo 'Enable Marine mode'."\n";
122
+	}
95 123
 	$globalMarine = TRUE;
96 124
 }
97 125
 if (isset($options['disable-marine'])) {
98
-	if ($globalDebug) echo 'Disable Marine mode'."\n";
126
+	if ($globalDebug) {
127
+		echo 'Disable Marine mode'."\n";
128
+	}
99 129
 	$globalMarine = FALSE;
100 130
 }
101
-if (isset($options['nodaemon'])) $globalDaemon = FALSE;
102
-if (isset($options['server'])) $globalServer = TRUE;
103
-if (isset($options['idsource'])) $id_source = $options['idsource'];
104
-else $id_source = 1;
131
+if (isset($options['nodaemon'])) {
132
+	$globalDaemon = FALSE;
133
+}
134
+if (isset($options['server'])) {
135
+	$globalServer = TRUE;
136
+}
137
+if (isset($options['idsource'])) {
138
+	$id_source = $options['idsource'];
139
+} else {
140
+	$id_source = 1;
141
+}
105 142
 if (isset($globalServer) && $globalServer) {
106
-    if ($globalDebug) echo "Using Server Mode\n";
143
+    if ($globalDebug) {
144
+    	echo "Using Server Mode\n";
145
+    }
107 146
     $SI=new SpotterServer();
108 147
 /*
109 148
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
110 149
     $SI = new adsb2aprs();
111 150
     $SI->connect();
112 151
 */
113
-} else $SI=new SpotterImport($Connection->db);
152
+} else {
153
+	$SI=new SpotterImport($Connection->db);
154
+}
114 155
 
115
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
156
+if (isset($globalTracker) && $globalTracker) {
157
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
158
+}
116 159
 if (isset($globalMarine) && $globalMarine) {
117 160
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
118 161
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
119 162
 }
120 163
 
121
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
164
+if (isset($globalTracker) && $globalTracker) {
165
+	$TI = new TrackerImport($Connection->db);
166
+}
122 167
 if (isset($globalMarine) && $globalMarine) {
123 168
     $AIS = new AIS();
124 169
     $MI = new MarineImport($Connection->db);
@@ -143,7 +188,9 @@  discard block
 block discarded – undo
143 188
 }
144 189
 
145 190
 // let's try and connect
146
-if ($globalDebug) echo "Connecting...\n";
191
+if ($globalDebug) {
192
+	echo "Connecting...\n";
193
+}
147 194
 $use_aprs = false;
148 195
 $aprs_full = false;
149 196
 $reset = 0;
@@ -152,7 +199,9 @@  discard block
 block discarded – undo
152 199
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
153 200
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
154 201
     $reset++;
155
-    if ($globalDebug) echo 'Connect to all...'."\n";
202
+    if ($globalDebug) {
203
+    	echo 'Connect to all...'."\n";
204
+    }
156 205
     foreach ($hosts as $id => $value) {
157 206
 	$host = $value['host'];
158 207
 	$globalSources[$id]['last_exec'] = 0;
@@ -162,22 +211,30 @@  discard block
 block discarded – undo
162 211
         	//$formats[$id] = 'deltadbtxt';
163 212
         	$globalSources[$id]['format'] = 'deltadbtxt';
164 213
         	//$last_exec['deltadbtxt'] = 0;
165
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
214
+        	if ($globalDebug) {
215
+        		echo "Connect to deltadb source (".$host.")...\n";
216
+        	}
166 217
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
167 218
         	//$formats[$id] = 'vatsimtxt';
168 219
         	$globalSources[$id]['format'] = 'vatsimtxt';
169 220
         	//$last_exec['vatsimtxt'] = 0;
170
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
221
+        	if ($globalDebug) {
222
+        		echo "Connect to vatsim source (".$host.")...\n";
223
+        	}
171 224
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
172 225
         	//$formats[$id] = 'aircraftlistjson';
173 226
         	$globalSources[$id]['format'] = 'aircraftlistjson';
174 227
         	//$last_exec['aircraftlistjson'] = 0;
175
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
228
+        	if ($globalDebug) {
229
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
230
+        	}
176 231
     	    } else if (preg_match('/opensky/i',$host)) {
177 232
         	//$formats[$id] = 'aircraftlistjson';
178 233
         	$globalSources[$id]['format'] = 'opensky';
179 234
         	//$last_exec['aircraftlistjson'] = 0;
180
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
235
+        	if ($globalDebug) {
236
+        		echo "Connect to opensky source (".$host.")...\n";
237
+        	}
181 238
     	    /*
182 239
     	    // Disabled for now, site change source format
183 240
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
@@ -194,7 +251,9 @@  discard block
 block discarded – undo
194 251
         	//$formats[$id] = 'planeupdatefaa';
195 252
         	$globalSources[$id]['format'] = 'planeupdatefaa';
196 253
         	//$last_exec['planeupdatefaa'] = 0;
197
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
254
+        	if ($globalDebug) {
255
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
256
+        	}
198 257
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
199 258
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
200 259
         	    exit(0);
@@ -203,32 +262,46 @@  discard block
 block discarded – undo
203 262
         	//$formats[$id] = 'phpvmacars';
204 263
         	$globalSources[$id]['format'] = 'phpvmacars';
205 264
         	//$last_exec['phpvmacars'] = 0;
206
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
265
+        	if ($globalDebug) {
266
+        		echo "Connect to phpvmacars source (".$host.")...\n";
267
+        	}
207 268
             } else if (preg_match('/VAM-json.php$/i',$host)) {
208 269
         	//$formats[$id] = 'phpvmacars';
209 270
         	$globalSources[$id]['format'] = 'vam';
210
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
271
+        	if ($globalDebug) {
272
+        		echo "Connect to Vam source (".$host.")...\n";
273
+        	}
211 274
             } else if (preg_match('/whazzup/i',$host)) {
212 275
         	//$formats[$id] = 'whazzup';
213 276
         	$globalSources[$id]['format'] = 'whazzup';
214 277
         	//$last_exec['whazzup'] = 0;
215
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
278
+        	if ($globalDebug) {
279
+        		echo "Connect to whazzup source (".$host.")...\n";
280
+        	}
216 281
             } else if (preg_match('/blitzortung/i',$host)) {
217 282
         	$globalSources[$id]['format'] = 'blitzortung';
218
-        	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
283
+        	if ($globalDebug) {
284
+        		echo "Connect to blitzortung source (".$host.")...\n";
285
+        	}
219 286
             } else if (preg_match('/airwhere/i',$host)) {
220 287
         	$globalSources[$id]['format'] = 'airwhere';
221
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
288
+        	if ($globalDebug) {
289
+        		echo "Connect to airwhere source (".$host.")...\n";
290
+        	}
222 291
             } else if (preg_match('/recentpireps/i',$host)) {
223 292
         	//$formats[$id] = 'pirepsjson';
224 293
         	$globalSources[$id]['format'] = 'pirepsjson';
225 294
         	//$last_exec['pirepsjson'] = 0;
226
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
295
+        	if ($globalDebug) {
296
+        		echo "Connect to pirepsjson source (".$host.")...\n";
297
+        	}
227 298
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
228 299
         	//$formats[$id] = 'fr24json';
229 300
         	$globalSources[$id]['format'] = 'fr24json';
230 301
         	//$last_exec['fr24json'] = 0;
231
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
302
+        	if ($globalDebug) {
303
+        		echo "Connect to fr24 source (".$host.")...\n";
304
+        	}
232 305
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
233 306
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
234 307
         	    exit(0);
@@ -237,7 +310,9 @@  discard block
 block discarded – undo
237 310
         	//$formats[$id] = 'fr24json';
238 311
         	$globalSources[$id]['format'] = 'myshiptracking';
239 312
         	//$last_exec['fr24json'] = 0;
240
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
313
+        	if ($globalDebug) {
314
+        		echo "Connect to myshiptracking source (".$host.")...\n";
315
+        	}
241 316
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
242 317
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
243 318
         	    exit(0);
@@ -246,16 +321,24 @@  discard block
 block discarded – undo
246 321
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
247 322
         	//$formats[$id] = 'tsv';
248 323
         	$globalSources[$id]['format'] = 'tsv';
249
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
324
+        	if ($globalDebug) {
325
+        		echo "Connect to tsv source (".$host.")...\n";
326
+        	}
250 327
             }
251 328
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
252 329
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
253 330
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
254 331
     		    if ($idf !== false) {
255 332
     			$httpfeeds[$id] = $idf;
256
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
257
-    		    } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
258
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
333
+        		if ($globalDebug) {
334
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
335
+        		}
336
+    		    } elseif ($globalDebug) {
337
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
338
+    		    }
339
+    		} elseif ($globalDebug) {
340
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
341
+    		}
259 342
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
260 343
 	    $hostport = explode(':',$host);
261 344
 	    if (isset($hostport[1])) {
@@ -295,17 +378,25 @@  discard block
 block discarded – undo
295 378
         		//$formats[$id] = 'beast';
296 379
         		$globalSources[$id]['format'] = 'beast';
297 380
 		    //} else $formats[$id] = 'sbs';
298
-		    } else $globalSources[$id]['format'] = 'sbs';
381
+		    } else {
382
+		    	$globalSources[$id]['format'] = 'sbs';
383
+		    }
299 384
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
300 385
 		}
301
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
386
+		if ($globalDebug) {
387
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
388
+		}
302 389
             } else {
303
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
390
+		if ($globalDebug) {
391
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
392
+		}
304 393
     	    }
305 394
         }
306 395
     }
307 396
 }
308
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
397
+if (!isset($globalMinFetch)) {
398
+	$globalMinFetch = 15;
399
+}
309 400
 
310 401
 // Initialize all
311 402
 $status = array();
@@ -314,13 +405,19 @@  discard block
 block discarded – undo
314 405
 $formats = array();
315 406
 $last_exec = array();
316 407
 $time = time();
317
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
318
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
319
-else $timeout = 20;
408
+if (isset($globalSourcesTimeout)) {
409
+	$timeout = $globalSourcesTimeOut;
410
+} else if (isset($globalSBS1TimeOut)) {
411
+	$timeout = $globalSBS1TimeOut;
412
+} else {
413
+	$timeout = 20;
414
+}
320 415
 $errno = '';
321 416
 $errstr='';
322 417
 
323
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
418
+if (!isset($globalDaemon)) {
419
+	$globalDaemon = TRUE;
420
+}
324 421
 /* Initiate connections to all the hosts simultaneously */
325 422
 //connect_all($hosts);
326 423
 //connect_all($globalSources);
@@ -349,7 +446,9 @@  discard block
 block discarded – undo
349 446
     if (isset($source['format']) && $source['format'] == 'aprs') {
350 447
 	$aprs_connect = 0;
351 448
 	$use_aprs = true;
352
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
449
+	if (isset($source['port']) && $source['port'] == '10152') {
450
+		$aprs_full = true;
451
+	}
353 452
 	break;
354 453
     }
355 454
 }
@@ -360,25 +459,46 @@  discard block
 block discarded – undo
360 459
 	$aprs_connect = 0;
361 460
 	$aprs_keep = 120;
362 461
 	$aprs_last_tx = time();
363
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
364
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
365
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
366
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
367
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
368
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
369
-	if ($aprs_full) $aprs_filter = '';
370
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
371
-	else $aprs_pass = '-1';
462
+	if (isset($globalAPRSversion)) {
463
+		$aprs_version = $globalAPRSversion;
464
+	} else {
465
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
466
+	}
467
+	if (isset($globalAPRSssid)) {
468
+		$aprs_ssid = $globalAPRSssid;
469
+	} else {
470
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
471
+	}
472
+	if (isset($globalAPRSfilter)) {
473
+		$aprs_filter = $globalAPRSfilter;
474
+	} else {
475
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
476
+	}
477
+	if ($aprs_full) {
478
+		$aprs_filter = '';
479
+	}
480
+	if (isset($globalAPRSpass)) {
481
+		$aprs_pass = $globalAPRSpass;
482
+	} else {
483
+		$aprs_pass = '-1';
484
+	}
372 485
 
373
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
374
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
375
-}
486
+	if ($aprs_filter != '') {
487
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
488
+	} else {
489
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
490
+	}
491
+	}
376 492
 
377 493
 // connected - lets do some work
378 494
 //if ($globalDebug) echo "Connected!\n";
379 495
 sleep(1);
380
-if ($globalDebug) echo "SCAN MODE \n\n";
381
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
496
+if ($globalDebug) {
497
+	echo "SCAN MODE \n\n";
498
+}
499
+if (!isset($globalCronEnd)) {
500
+	$globalCronEnd = 60;
501
+}
382 502
 $endtime = time()+$globalCronEnd;
383 503
 $i = 1;
384 504
 $tt = array();
@@ -392,20 +512,28 @@  discard block
 block discarded – undo
392 512
 
393 513
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
394 514
 while ($i > 0) {
395
-    if (!$globalDaemon) $i = $endtime-time();
515
+    if (!$globalDaemon) {
516
+    	$i = $endtime-time();
517
+    }
396 518
     // Delete old ATC
397 519
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
398
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
520
+	if ($globalDebug) {
521
+		echo 'Delete old ATC...'."\n";
522
+	}
399 523
         $ATC->deleteOldATC();
400 524
     }
401 525
     
402 526
     if (count($last_exec) == count($globalSources)) {
403 527
 	$max = $globalMinFetch;
404 528
 	foreach ($last_exec as $last) {
405
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
529
+	    if ((time() - $last['last']) < $max) {
530
+	    	$max = time() - $last['last'];
531
+	    }
406 532
 	}
407 533
 	if ($max != $globalMinFetch) {
408
-	    if ($globalDebug) echo 'Sleeping...'."\n";
534
+	    if ($globalDebug) {
535
+	    	echo 'Sleeping...'."\n";
536
+	    }
409 537
 	    sleep($globalMinFetch-$max+2);
410 538
 	}
411 539
     }
@@ -415,7 +543,9 @@  discard block
 block discarded – undo
415 543
     foreach ($globalSources as $id => $value) {
416 544
 	date_default_timezone_set('UTC');
417 545
 	//if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n";
418
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
546
+	if (!isset($last_exec[$id]['last'])) {
547
+		$last_exec[$id]['last'] = 0;
548
+	}
419 549
 	if ($value['format'] == 'deltadbtxt' && 
420 550
 	    (
421 551
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
@@ -424,7 +554,9 @@  discard block
 block discarded – undo
424 554
 	) {
425 555
 	    //$buffer = $Common->getData($hosts[$id]);
426 556
 	    $buffer = $Common->getData($value['host']);
427
-	    if ($buffer != '') $reset = 0;
557
+	    if ($buffer != '') {
558
+	    	$reset = 0;
559
+	    }
428 560
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
429 561
 	    $buffer = explode('\n',$buffer);
430 562
 	    foreach ($buffer as $line) {
@@ -433,20 +565,41 @@  discard block
 block discarded – undo
433 565
 	            $data = array();
434 566
 	            $data['hex'] = $line[1]; // hex
435 567
 	            $data['ident'] = $line[2]; // ident
436
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
437
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
438
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
439
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
440
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
568
+	            if (isset($line[3])) {
569
+	            	$data['altitude'] = $line[3];
570
+	            }
571
+	            // altitude
572
+	            if (isset($line[4])) {
573
+	            	$data['speed'] = $line[4];
574
+	            }
575
+	            // speed
576
+	            if (isset($line[5])) {
577
+	            	$data['heading'] = $line[5];
578
+	            }
579
+	            // heading
580
+	            if (isset($line[6])) {
581
+	            	$data['latitude'] = $line[6];
582
+	            }
583
+	            // lat
584
+	            if (isset($line[7])) {
585
+	            	$data['longitude'] = $line[7];
586
+	            }
587
+	            // long
441 588
 	            $data['verticalrate'] = ''; // vertical rate
442 589
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
443 590
 	            $data['emergency'] = ''; // emergency
444 591
 		    $data['datetime'] = date('Y-m-d H:i:s');
445 592
 		    $data['format_source'] = 'deltadbtxt';
446 593
     		    $data['id_source'] = $id_source;
447
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
448
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
449
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
594
+		    if (isset($value['name']) && $value['name'] != '') {
595
+		    	$data['source_name'] = $value['name'];
596
+		    }
597
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
598
+		    	$data['noarchive'] = true;
599
+		    }
600
+		    if (isset($value['sourcestats'])) {
601
+		    	$data['sourcestats'] = $value['sourcestats'];
602
+		    }
450 603
     		    $SI->add($data);
451 604
 		    unset($data);
452 605
     		}
@@ -461,7 +614,9 @@  discard block
 block discarded – undo
461 614
 	    date_default_timezone_set('CET');
462 615
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
463 616
 	    date_default_timezone_set('UTC');
464
-	    if ($buffer != '') $reset = 0;
617
+	    if ($buffer != '') {
618
+	    	$reset = 0;
619
+	    }
465 620
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
466 621
 	    $buffer = explode('\n',$buffer);
467 622
 	    foreach ($buffer as $line) {
@@ -470,16 +625,36 @@  discard block
 block discarded – undo
470 625
 		    $add = false;
471 626
 		    $ais_data = $AIS->parse_line(trim($line));
472 627
 		    $data = array();
473
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
474
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
475
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
476
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
477
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
478
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
479
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
480
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
481
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
482
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
628
+		    if (isset($ais_data['ident'])) {
629
+		    	$data['ident'] = $ais_data['ident'];
630
+		    }
631
+		    if (isset($ais_data['mmsi'])) {
632
+		    	$data['mmsi'] = $ais_data['mmsi'];
633
+		    }
634
+		    if (isset($ais_data['speed'])) {
635
+		    	$data['speed'] = $ais_data['speed'];
636
+		    }
637
+		    if (isset($ais_data['heading'])) {
638
+		    	$data['heading'] = $ais_data['heading'];
639
+		    }
640
+		    if (isset($ais_data['latitude'])) {
641
+		    	$data['latitude'] = $ais_data['latitude'];
642
+		    }
643
+		    if (isset($ais_data['longitude'])) {
644
+		    	$data['longitude'] = $ais_data['longitude'];
645
+		    }
646
+		    if (isset($ais_data['status'])) {
647
+		    	$data['status'] = $ais_data['status'];
648
+		    }
649
+		    if (isset($ais_data['type'])) {
650
+		    	$data['type'] = $ais_data['type'];
651
+		    }
652
+		    if (isset($ais_data['imo'])) {
653
+		    	$data['imo'] = $ais_data['imo'];
654
+		    }
655
+		    if (isset($ais_data['callsign'])) {
656
+		    	$data['callsign'] = $ais_data['callsign'];
657
+		    }
483 658
 		    if (isset($ais_data['timestamp'])) {
484 659
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
485 660
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -493,8 +668,12 @@  discard block
 block discarded – undo
493 668
 		    $data['format_source'] = 'aisnmeatxt';
494 669
     		    $data['id_source'] = $id_source;
495 670
 		    //print_r($data);
496
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
497
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
671
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
672
+		    	$data['noarchive'] = true;
673
+		    }
674
+		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
675
+		    	$MI->add($data);
676
+		    }
498 677
 		    unset($data);
499 678
 		}
500 679
     	    }
@@ -517,20 +696,48 @@  discard block
 block discarded – undo
517 696
 			    if ($line != '') {
518 697
 				$ais_data = $AIS->parse_line(trim($line));
519 698
 				$data = array();
520
-				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
521
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
522
-				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
523
-				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
524
-				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
525
-				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
526
-				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
527
-				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
528
-				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
529
-				if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
530
-				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
531
-				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
532
-				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
533
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
699
+				if (isset($ais_data['ident'])) {
700
+					$data['ident'] = $ais_data['ident'];
701
+				}
702
+				if (isset($ais_data['mmsi'])) {
703
+					$data['mmsi'] = $ais_data['mmsi'];
704
+				}
705
+				if (isset($ais_data['speed'])) {
706
+					$data['speed'] = $ais_data['speed'];
707
+				}
708
+				if (isset($ais_data['heading'])) {
709
+					$data['heading'] = $ais_data['heading'];
710
+				}
711
+				if (isset($ais_data['latitude'])) {
712
+					$data['latitude'] = $ais_data['latitude'];
713
+				}
714
+				if (isset($ais_data['longitude'])) {
715
+					$data['longitude'] = $ais_data['longitude'];
716
+				}
717
+				if (isset($ais_data['status'])) {
718
+					$data['status'] = $ais_data['status'];
719
+				}
720
+				if (isset($ais_data['statusid'])) {
721
+					$data['status_id'] = $ais_data['statusid'];
722
+				}
723
+				if (isset($ais_data['type'])) {
724
+					$data['type'] = $ais_data['type'];
725
+				}
726
+				if (isset($ais_data['typeid'])) {
727
+					$data['type_id'] = $ais_data['typeid'];
728
+				}
729
+				if (isset($ais_data['imo'])) {
730
+					$data['imo'] = $ais_data['imo'];
731
+				}
732
+				if (isset($ais_data['callsign'])) {
733
+					$data['callsign'] = $ais_data['callsign'];
734
+				}
735
+				if (isset($ais_data['destination'])) {
736
+					$data['arrival_code'] = $ais_data['destination'];
737
+				}
738
+				if (isset($ais_data['eta_ts'])) {
739
+					$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
740
+				}
534 741
 				if (isset($ais_data['timestamp'])) {
535 742
 				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
536 743
 				} else {
@@ -538,18 +745,27 @@  discard block
 block discarded – undo
538 745
 				}
539 746
 				$data['format_source'] = 'aisnmeahttp';
540 747
 				$data['id_source'] = $id_source;
541
-				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
542
-				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
748
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
749
+					$data['noarchive'] = true;
750
+				}
751
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
752
+					$MI->add($data);
753
+				}
543 754
 				unset($data);
544 755
 			    }
545 756
 			}
546 757
 		    }
547 758
 		} else {
548 759
 		    $format = $value['format'];
549
-		    if (isset($tt[$format])) $tt[$format]++;
550
-		    else $tt[$format] = 0;
760
+		    if (isset($tt[$format])) {
761
+		    	$tt[$format]++;
762
+		    } else {
763
+		    	$tt[$format] = 0;
764
+		    }
551 765
 		    if ($tt[$format] > 30) {
552
-			if ($globalDebug) echo 'Reconnect...'."\n";
766
+			if ($globalDebug) {
767
+				echo 'Reconnect...'."\n";
768
+			}
553 769
 			sleep(2);
554 770
 			//$sourceeen[] = $value;
555 771
 			//connect_all($sourceeen);
@@ -588,7 +804,9 @@  discard block
 block discarded – undo
588 804
 			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
589 805
 			    $data['format_source'] = 'myshiptracking';
590 806
 			    $data['id_source'] = $id_source;
591
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
807
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
808
+			    	$data['noarchive'] = true;
809
+			    }
592 810
 			    $MI->add($data);
593 811
 			    unset($data);
594 812
 			}
@@ -613,7 +831,9 @@  discard block
 block discarded – undo
613 831
 			    $data['callsign'] = $line['callsign'];
614 832
 			    $data['mmsi'] = $line['mmsi'];
615 833
 			    $data['speed'] = $line['sog'];
616
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
834
+			    if ($line['heading'] != '511') {
835
+			    	$data['heading'] = $line['heading'];
836
+			    }
617 837
 			    $data['latitude'] = $line['latitude'];
618 838
 			    $data['longitude'] = $line['longitude'];
619 839
 			    $data['type_id'] = $line['shiptype'];
@@ -621,7 +841,9 @@  discard block
 block discarded – undo
621 841
 			    $data['datetime'] = $line['time'];
622 842
 			    $data['format_source'] = 'boatbeaconapp';
623 843
 			    $data['id_source'] = $id_source;
624
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
844
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
845
+			    	$data['noarchive'] = true;
846
+			    }
625 847
 			    $MI->add($data);
626 848
 			    unset($data);
627 849
 			}
@@ -642,22 +864,44 @@  discard block
 block discarded – undo
642 864
 		if (isset($all_data['features'][0]['id'])) {
643 865
 		    foreach ($all_data['features'] as $line) {
644 866
 			$data = array();
645
-			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
646
-			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
647
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = $line['properties']['mmsi'];
648
-			if (isset($line['properties']['imo'])) $data['mmsi'] = $line['properties']['imo'];
649
-			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
650
-			if (isset($line['properties']['heading'])) $data['heading'] = $line['properties']['heading'];
867
+			if (isset($line['properties']['name'])) {
868
+				$data['ident'] = $line['properties']['name'];
869
+			}
870
+			if (isset($line['properties']['callsign'])) {
871
+				$data['callsign'] = $line['properties']['callsign'];
872
+			}
873
+			if (isset($line['properties']['mmsi'])) {
874
+				$data['mmsi'] = $line['properties']['mmsi'];
875
+			}
876
+			if (isset($line['properties']['imo'])) {
877
+				$data['mmsi'] = $line['properties']['imo'];
878
+			}
879
+			if (isset($line['properties']['speed'])) {
880
+				$data['speed'] = $line['properties']['speed'];
881
+			}
882
+			if (isset($line['properties']['heading'])) {
883
+				$data['heading'] = $line['properties']['heading'];
884
+			}
651 885
 			$data['latitude'] = $line['geometry']['coordinates'][1];
652 886
 			$data['longitude'] = $line['geometry']['coordinates'][0];
653
-			if (isset($line['properties']['vesselType'])) $data['type'] = $line['properties']['vesselType'];
654
-			if (isset($line['properties']['destination'])) $data['arrival_code'] = $line['properties']['destination'];
655
-			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') $data['arrival_date'] = $line['properties']['eta'];
887
+			if (isset($line['properties']['vesselType'])) {
888
+				$data['type'] = $line['properties']['vesselType'];
889
+			}
890
+			if (isset($line['properties']['destination'])) {
891
+				$data['arrival_code'] = $line['properties']['destination'];
892
+			}
893
+			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') {
894
+				$data['arrival_date'] = $line['properties']['eta'];
895
+			}
656 896
 			$data['format_source'] = 'boatnerd';
657 897
 			$data['id_source'] = $id_source;
658 898
 			$data['datetime'] = date('Y-m-d H:i:s');
659
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
660
-			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
899
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
900
+				$data['noarchive'] = true;
901
+			}
902
+			if ($line['properties']['vesselType'] != 'Navigation Aid') {
903
+				$MI->add($data);
904
+			}
661 905
 			unset($data);
662 906
 		    }
663 907
 		}
@@ -673,7 +917,9 @@  discard block
 block discarded – undo
673 917
 	    echo 'download...';
674 918
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
675 919
 	    echo 'done !'."\n";
676
-	    if ($buffer != '') $reset = 0;
920
+	    if ($buffer != '') {
921
+	    	$reset = 0;
922
+	    }
677 923
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
678 924
 	    $buffer = explode('\n',$buffer);
679 925
 	    foreach ($buffer as $line) {
@@ -698,7 +944,9 @@  discard block
 block discarded – undo
698 944
 		    //$data['etaTime'] = substr($line,135,5);
699 945
 		    $data['format_source'] = 'shipplotter';
700 946
     		    $data['id_source'] = $id_source;
701
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
947
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
948
+		    	$data['noarchive'] = true;
949
+		    }
702 950
 		    //print_r($data);
703 951
 		    echo 'Add...'."\n";
704 952
 		    $MI->add($data);
@@ -732,16 +980,28 @@  discard block
 block discarded – undo
732 980
     		    $line = explode(':', $line);
733 981
     		    if (count($line) > 30 && $line[0] != 'callsign') {
734 982
 			$data = array();
735
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
736
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
983
+			if (isset($line[37]) && $line[37] != '') {
984
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
985
+			} else {
986
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
987
+			}
737 988
 			$data['pilot_id'] = $line[1];
738 989
 			$data['pilot_name'] = $line[2];
739 990
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
740 991
 			$data['ident'] = $line[0]; // ident
741
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
992
+			if ($line[7] != '' && $line[7] != 0) {
993
+				$data['altitude'] = $line[7];
994
+			}
995
+			// altitude
742 996
 			$data['speed'] = $line[8]; // speed
743
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
744
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
997
+			if (isset($line[45])) {
998
+				$data['heading'] = $line[45];
999
+			}
1000
+			// heading
1001
+			elseif (isset($line[38])) {
1002
+				$data['heading'] = $line[38];
1003
+			}
1004
+			// heading
745 1005
 			$data['latitude'] = $line[5]; // lat
746 1006
 	        	$data['longitude'] = $line[6]; // long
747 1007
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -757,7 +1017,9 @@  discard block
 block discarded – undo
757 1017
 			$data['frequency'] = $line[4];
758 1018
 			$data['type'] = $line[18];
759 1019
 			$data['range'] = $line[19];
760
-			if (isset($line[35])) $data['info'] = $line[35];
1020
+			if (isset($line[35])) {
1021
+				$data['info'] = $line[35];
1022
+			}
761 1023
     			$data['id_source'] = $id_source;
762 1024
 	    		//$data['arrival_airport_time'] = ;
763 1025
 	    		if ($line[9] != '') {
@@ -771,27 +1033,47 @@  discard block
 block discarded – undo
771 1033
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
772 1034
 	    		*/
773 1035
 	    		$data['format_source'] = $value['format'];
774
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
775
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
776
-    			if ($line[3] == 'PILOT') $SI->add($data);
777
-			elseif ($line[3] == 'ATC') {
1036
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1037
+				$data['noarchive'] = true;
1038
+			}
1039
+			if (isset($value['name']) && $value['name'] != '') {
1040
+				$data['source_name'] = $value['name'];
1041
+			}
1042
+    			if ($line[3] == 'PILOT') {
1043
+    				$SI->add($data);
1044
+    			} elseif ($line[3] == 'ATC') {
778 1045
 				//print_r($data);
779 1046
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
780 1047
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
781 1048
 				$typec = substr($data['ident'],-3);
782
-				if ($typec == 'APP') $data['type'] = 'Approach';
783
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
784
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
785
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
786
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
787
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
788
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
789
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
790
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
791
-				if (!isset($data['source_name'])) $data['source_name'] = '';
1049
+				if ($typec == 'APP') {
1050
+					$data['type'] = 'Approach';
1051
+				} elseif ($typec == 'TWR') {
1052
+					$data['type'] = 'Tower';
1053
+				} elseif ($typec == 'OBS') {
1054
+					$data['type'] = 'Observer';
1055
+				} elseif ($typec == 'GND') {
1056
+					$data['type'] = 'Ground';
1057
+				} elseif ($typec == 'DEL') {
1058
+					$data['type'] = 'Delivery';
1059
+				} elseif ($typec == 'DEP') {
1060
+					$data['type'] = 'Departure';
1061
+				} elseif ($typec == 'FSS') {
1062
+					$data['type'] = 'Flight Service Station';
1063
+				} elseif ($typec == 'CTR') {
1064
+					$data['type'] = 'Control Radar or Centre';
1065
+				} elseif ($data['type'] == '') {
1066
+					$data['type'] = 'Observer';
1067
+				}
1068
+				if (!isset($data['source_name'])) {
1069
+					$data['source_name'] = '';
1070
+				}
792 1071
 				if (isset($ATC)) {
793
-					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']);
794
-					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']);
1072
+					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) {
1073
+						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']);
1074
+					} else {
1075
+						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']);
1076
+					}
795 1077
 				}
796 1078
 			}
797 1079
     			unset($data);
@@ -818,14 +1100,20 @@  discard block
 block discarded – undo
818 1100
 			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
819 1101
 			$data['latitude'] = (float)$line['pktLatitude'];
820 1102
 			$data['longitude'] = (float)$line['pktLongitude'];
821
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
822
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
1103
+			if ((float)$line['pktTrack'] != 0) {
1104
+				$data['heading'] = (float)$line['pktTrack'];
1105
+			}
1106
+			if ((int)$line['pktSpeed'] != 0) {
1107
+				$data['speed'] = (int)$line['pktSpeed'];
1108
+			}
823 1109
 			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
824 1110
 			$data['altitude_relative'] = 'AMSL';
825 1111
 			$data['pilot_id'] = (int)$line['pktPilotID'];
826 1112
 			$data['aircraft_icao'] = 'PARAGLIDER';
827 1113
 			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
828
-			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
1114
+			if (isset($pilot_data[4])) {
1115
+				$data['pilot_name'] = $pilot_data[4];
1116
+			}
829 1117
 			$data['format_source'] = $value['format'];
830 1118
 			$SI->add($data);
831 1119
 			unset($data);
@@ -873,25 +1161,59 @@  discard block
 block discarded – undo
873 1161
 		    foreach ($all_data['acList'] as $line) {
874 1162
 			$data = array();
875 1163
 			$data['hex'] = $line['Icao']; // hex
876
-			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
877
-			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
878
-			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
879
-			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
880
-			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
881
-			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1164
+			if (isset($line['Call'])) {
1165
+				$data['ident'] = $line['Call'];
1166
+			}
1167
+			// ident
1168
+			if (isset($line['Alt'])) {
1169
+				$data['altitude'] = $line['Alt'];
1170
+			}
1171
+			// altitude
1172
+			if (isset($line['Spd'])) {
1173
+				$data['speed'] = $line['Spd'];
1174
+			}
1175
+			// speed
1176
+			if (isset($line['Trak'])) {
1177
+				$data['heading'] = $line['Trak'];
1178
+			}
1179
+			// heading
1180
+			if (isset($line['Lat'])) {
1181
+				$data['latitude'] = $line['Lat'];
1182
+			}
1183
+			// lat
1184
+			if (isset($line['Long'])) {
1185
+				$data['longitude'] = $line['Long'];
1186
+			}
1187
+			// long
882 1188
 			//$data['verticalrate'] = $line['']; // verticale rate
883
-			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1189
+			if (isset($line['Sqk'])) {
1190
+				$data['squawk'] = $line['Sqk'];
1191
+			}
1192
+			// squawk
884 1193
 			$data['emergency'] = ''; // emergency
885
-			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
886
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
887
-			else $data['datetime'] = date('Y-m-d H:i:s');
1194
+			if (isset($line['Reg'])) {
1195
+				$data['registration'] = $line['Reg'];
1196
+			}
1197
+			if (isset($line['PosTime'])) {
1198
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1199
+			} else {
1200
+				$data['datetime'] = date('Y-m-d H:i:s');
1201
+			}
888 1202
 			//$data['datetime'] = date('Y-m-d H:i:s');
889
-			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1203
+			if (isset($line['Type'])) {
1204
+				$data['aircraft_icao'] = $line['Type'];
1205
+			}
890 1206
 			$data['format_source'] = 'aircraftlistjson';
891 1207
 			$data['id_source'] = $id_source;
892
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
893
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
894
-			if (isset($data['latitude'])) $SI->add($data);
1208
+			if (isset($value['name']) && $value['name'] != '') {
1209
+				$data['source_name'] = $value['name'];
1210
+			}
1211
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1212
+				$data['noarchive'] = true;
1213
+			}
1214
+			if (isset($data['latitude'])) {
1215
+				$SI->add($data);
1216
+			}
895 1217
 			unset($data);
896 1218
 		    }
897 1219
 		} elseif (is_array($all_data)) {
@@ -908,17 +1230,26 @@  discard block
 block discarded – undo
908 1230
 			$data['verticalrate'] = $line['vrt']; // verticale rate
909 1231
 			$data['squawk'] = $line['squawk']; // squawk
910 1232
 			$data['emergency'] = ''; // emergency
911
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
912
-			else $data['datetime'] = date('Y-m-d H:i:s');
1233
+			if (isset($line['PosTime'])) {
1234
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1235
+			} else {
1236
+				$data['datetime'] = date('Y-m-d H:i:s');
1237
+			}
913 1238
 			$data['format_source'] = 'aircraftlistjson';
914 1239
 			$data['id_source'] = $id_source;
915
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
916
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1240
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1241
+				$data['noarchive'] = true;
1242
+			}
1243
+			if (isset($value['name']) && $value['name'] != '') {
1244
+				$data['source_name'] = $value['name'];
1245
+			}
917 1246
 			$SI->add($data);
918 1247
 			unset($data);
919 1248
 		    }
920 1249
 		}
921
-	    } elseif ($globalDebug) echo 'No data'."\n";
1250
+	    } elseif ($globalDebug) {
1251
+	    	echo 'No data'."\n";
1252
+	    }
922 1253
     	    //$last_exec['aircraftlistjson'] = time();
923 1254
     	    $last_exec[$id]['last'] = time();
924 1255
     	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
@@ -954,8 +1285,12 @@  discard block
 block discarded – undo
954 1285
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
955 1286
 	    	    $data['format_source'] = 'planeupdatefaa';
956 1287
     		    $data['id_source'] = $id_source;
957
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
958
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1288
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1289
+		    	$data['noarchive'] = true;
1290
+		    }
1291
+		    if (isset($value['name']) && $value['name'] != '') {
1292
+		    	$data['source_name'] = $value['name'];
1293
+		    }
959 1294
 		    $SI->add($data);
960 1295
 		    unset($data);
961 1296
 		}
@@ -989,7 +1324,9 @@  discard block
 block discarded – undo
989 1324
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
990 1325
 		    $data['format_source'] = 'opensky';
991 1326
 		    $data['id_source'] = $id_source;
992
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1327
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1328
+		    	$data['noarchive'] = true;
1329
+		    }
993 1330
 		    $SI->add($data);
994 1331
 		    unset($data);
995 1332
 		}
@@ -1006,7 +1343,9 @@  discard block
 block discarded – undo
1006 1343
 	    //$buffer = $Common->getData($hosts[$id]);
1007 1344
 	    $buffer = $Common->getData($value['host']);
1008 1345
 	    $all_data = json_decode($buffer,true);
1009
-	    if (!empty($all_data)) $reset = 0;
1346
+	    if (!empty($all_data)) {
1347
+	    	$reset = 0;
1348
+	    }
1010 1349
 	    foreach ($all_data as $key => $line) {
1011 1350
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
1012 1351
 		    $data = array();
@@ -1027,8 +1366,12 @@  discard block
 block discarded – undo
1027 1366
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1028 1367
 	    	    $data['format_source'] = 'fr24json';
1029 1368
     		    $data['id_source'] = $id_source;
1030
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1031
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1369
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1370
+		    	$data['noarchive'] = true;
1371
+		    }
1372
+		    if (isset($value['name']) && $value['name'] != '') {
1373
+		    	$data['source_name'] = $value['name'];
1374
+		    }
1032 1375
 		    $SI->add($data);
1033 1376
 		    unset($data);
1034 1377
 		}
@@ -1057,24 +1400,42 @@  discard block
 block discarded – undo
1057 1400
 		    if (isset($line['inf'])) {
1058 1401
 			$data = array();
1059 1402
 			$data['hex'] = $line['inf']['ia'];
1060
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1403
+			if (isset($line['inf']['cs'])) {
1404
+				$data['ident'] = $line['inf']['cs'];
1405
+			}
1406
+			//$line[13]
1061 1407
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1062
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1063
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1408
+	    		if (isset($line['inf']['gs'])) {
1409
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1410
+	    		}
1411
+	    		// speed
1412
+	    		if (isset($line['inf']['tr'])) {
1413
+	    			$data['heading'] = $line['inf']['tr'];
1414
+	    		}
1415
+	    		// heading
1064 1416
 	    		$data['latitude'] = $line['pt'][0]; // lat
1065 1417
 	    		$data['longitude'] = $line['pt'][1]; // long
1066 1418
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1067
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1419
+	    		if (isset($line['inf']['sq'])) {
1420
+	    			$data['squawk'] = $line['inf']['sq'];
1421
+	    		}
1422
+	    		// squawk
1068 1423
 	    		//$data['aircraft_icao'] = $line[8];
1069
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1424
+	    		if (isset($line['inf']['rc'])) {
1425
+	    			$data['registration'] = $line['inf']['rc'];
1426
+	    		}
1070 1427
 			//$data['departure_airport_iata'] = $line[11];
1071 1428
 			//$data['arrival_airport_iata'] = $line[12];
1072 1429
 	    		//$data['emergency'] = ''; // emergency
1073 1430
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1074 1431
 	    		$data['format_source'] = 'radarvirtueljson';
1075 1432
     			$data['id_source'] = $id_source;
1076
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1077
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1433
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1434
+				$data['noarchive'] = true;
1435
+			}
1436
+			if (isset($value['name']) && $value['name'] != '') {
1437
+				$data['source_name'] = $value['name'];
1438
+			}
1078 1439
 			$SI->add($data);
1079 1440
 			unset($data);
1080 1441
 		    }
@@ -1100,30 +1461,65 @@  discard block
 block discarded – undo
1100 1461
 		    $data['id'] = $line['id'];
1101 1462
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1102 1463
 		    $data['ident'] = $line['callsign']; // ident
1103
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1104
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1105
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1106
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1107
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1108
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1464
+		    if (isset($line['pilotid'])) {
1465
+		    	$data['pilot_id'] = $line['pilotid'];
1466
+		    }
1467
+		    // pilot id
1468
+		    if (isset($line['name'])) {
1469
+		    	$data['pilot_name'] = $line['name'];
1470
+		    }
1471
+		    // pilot name
1472
+		    if (isset($line['alt'])) {
1473
+		    	$data['altitude'] = $line['alt'];
1474
+		    }
1475
+		    // altitude
1476
+		    if (isset($line['gs'])) {
1477
+		    	$data['speed'] = $line['gs'];
1478
+		    }
1479
+		    // speed
1480
+		    if (isset($line['heading'])) {
1481
+		    	$data['heading'] = $line['heading'];
1482
+		    }
1483
+		    // heading
1484
+		    if (isset($line['route'])) {
1485
+		    	$data['waypoints'] = $line['route'];
1486
+		    }
1487
+		    // route
1109 1488
 		    $data['latitude'] = $line['lat']; // lat
1110 1489
 		    $data['longitude'] = $line['lon']; // long
1111 1490
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
1112 1491
 		    //$data['squawk'] = $line['squawk']; // squawk
1113 1492
 		    //$data['emergency'] = ''; // emergency
1114
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1115
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1116
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1493
+		    if (isset($line['depicao'])) {
1494
+		    	$data['departure_airport_icao'] = $line['depicao'];
1495
+		    }
1496
+		    if (isset($line['deptime'])) {
1497
+		    	$data['departure_airport_time'] = $line['deptime'];
1498
+		    }
1499
+		    if (isset($line['arricao'])) {
1500
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1501
+		    }
1117 1502
 		    //$data['arrival_airport_time'] = $line['arrtime'];
1118
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1119
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1120
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
1121
-		    else $data['info'] = '';
1503
+		    if (isset($line['aircraft'])) {
1504
+		    	$data['aircraft_icao'] = $line['aircraft'];
1505
+		    }
1506
+		    if (isset($line['transponder'])) {
1507
+		    	$data['squawk'] = $line['transponder'];
1508
+		    }
1509
+		    if (isset($line['atis'])) {
1510
+		    	$data['info'] = $line['atis'];
1511
+		    } else {
1512
+		    	$data['info'] = '';
1513
+		    }
1122 1514
 		    $data['format_source'] = 'pireps';
1123 1515
     		    $data['id_source'] = $id_source;
1124 1516
 		    $data['datetime'] = date('Y-m-d H:i:s');
1125
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1126
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1517
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1518
+		    	$data['noarchive'] = true;
1519
+		    }
1520
+		    if (isset($value['name']) && $value['name'] != '') {
1521
+		    	$data['source_name'] = $value['name'];
1522
+		    }
1127 1523
 		    if ($line['icon'] == 'plane') {
1128 1524
 			$SI->add($data);
1129 1525
 		    //    print_r($data);
@@ -1132,16 +1528,28 @@  discard block
 block discarded – undo
1132 1528
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1133 1529
 			$typec = substr($data['ident'],-3);
1134 1530
 			$data['type'] = '';
1135
-			if ($typec == 'APP') $data['type'] = 'Approach';
1136
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
1137
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
1138
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
1139
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
1140
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
1141
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
1142
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
1143
-			else $data['type'] = 'Observer';
1144
-			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']);
1531
+			if ($typec == 'APP') {
1532
+				$data['type'] = 'Approach';
1533
+			} elseif ($typec == 'TWR') {
1534
+				$data['type'] = 'Tower';
1535
+			} elseif ($typec == 'OBS') {
1536
+				$data['type'] = 'Observer';
1537
+			} elseif ($typec == 'GND') {
1538
+				$data['type'] = 'Ground';
1539
+			} elseif ($typec == 'DEL') {
1540
+				$data['type'] = 'Delivery';
1541
+			} elseif ($typec == 'DEP') {
1542
+				$data['type'] = 'Departure';
1543
+			} elseif ($typec == 'FSS') {
1544
+				$data['type'] = 'Flight Service Station';
1545
+			} elseif ($typec == 'CTR') {
1546
+				$data['type'] = 'Control Radar or Centre';
1547
+			} else {
1548
+				$data['type'] = 'Observer';
1549
+			}
1550
+			if (isset($ATC)) {
1551
+				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']);
1552
+			}
1145 1553
 		    }
1146 1554
 		    unset($data);
1147 1555
 		}
@@ -1156,7 +1564,9 @@  discard block
 block discarded – undo
1156 1564
 	    )
1157 1565
 	) {
1158 1566
 	    //$buffer = $Common->getData($hosts[$id]);
1159
-	    if ($globalDebug) echo 'Get Data...'."\n";
1567
+	    if ($globalDebug) {
1568
+	    	echo 'Get Data...'."\n";
1569
+	    }
1160 1570
 	    $buffer = $Common->getData($value['host']);
1161 1571
 	    $all_data = json_decode($buffer,true);
1162 1572
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1164,10 +1574,16 @@  discard block
 block discarded – undo
1164 1574
 		foreach ($all_data as $line) {
1165 1575
 	    	    $data = array();
1166 1576
 	    	    //$data['id'] = $line['id']; // id not usable
1167
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1577
+	    	    if (isset($line['pilotid'])) {
1578
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1579
+	    	    }
1168 1580
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1169
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1170
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1581
+	    	    if (isset($line['pilotname'])) {
1582
+	    	    	$data['pilot_name'] = $line['pilotname'];
1583
+	    	    }
1584
+	    	    if (isset($line['pilotid'])) {
1585
+	    	    	$data['pilot_id'] = $line['pilotid'];
1586
+	    	    }
1171 1587
 	    	    $data['ident'] = $line['flightnum']; // ident
1172 1588
 	    	    $data['altitude'] = $line['alt']; // altitude
1173 1589
 	    	    $data['speed'] = $line['gs']; // speed
@@ -1183,34 +1599,52 @@  discard block
 block discarded – undo
1183 1599
 	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1184 1600
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1185 1601
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1186
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1602
+	    	    } else {
1603
+	    	    	$data['datetime'] = date('Y-m-d H:i:s');
1604
+	    	    }
1187 1605
 	    	    $data['departure_airport_icao'] = $line['depicao'];
1188 1606
 	    	    $data['departure_airport_time'] = $line['deptime'];
1189 1607
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
1190 1608
     		    $data['arrival_airport_time'] = $line['arrtime'];
1191 1609
     		    $data['registration'] = $line['aircraft'];
1192
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1193
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1610
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1611
+		    	$data['noarchive'] = true;
1612
+		    }
1613
+		    if (isset($line['route'])) {
1614
+		    	$data['waypoints'] = $line['route'];
1615
+		    }
1616
+		    // route
1194 1617
 		    if (isset($line['aircraftname'])) {
1195 1618
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1196 1619
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1197 1620
 	    		$aircraft_data = explode('-',$line['aircraftname']);
1198
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1199
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1200
-	    		else {
1621
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) {
1622
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1623
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) {
1624
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1625
+	    		} else {
1201 1626
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1202
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1203
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1627
+	    		    if (isset($aircraft_data[1])) {
1628
+	    		    	$data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1629
+	    		    } else {
1630
+	    		    	$data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1631
+	    		    }
1204 1632
 	    		}
1205 1633
 	    	    }
1206
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1634
+    		    if (isset($line['route'])) {
1635
+    		    	$data['waypoints'] = $line['route'];
1636
+    		    }
1207 1637
     		    $data['id_source'] = $id_source;
1208 1638
 	    	    $data['format_source'] = 'phpvmacars';
1209
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1639
+		    if (isset($value['name']) && $value['name'] != '') {
1640
+		    	$data['source_name'] = $value['name'];
1641
+		    }
1210 1642
 		    $SI->add($data);
1211 1643
 		    unset($data);
1212 1644
 		}
1213
-		if ($globalDebug) echo 'No more data...'."\n";
1645
+		if ($globalDebug) {
1646
+			echo 'No more data...'."\n";
1647
+		}
1214 1648
 		unset($buffer);
1215 1649
 		unset($all_data);
1216 1650
 	    }
@@ -1223,7 +1657,9 @@  discard block
 block discarded – undo
1223 1657
 	    )
1224 1658
 	) {
1225 1659
 	    //$buffer = $Common->getData($hosts[$id]);
1226
-	    if ($globalDebug) echo 'Get Data...'."\n";
1660
+	    if ($globalDebug) {
1661
+	    	echo 'Get Data...'."\n";
1662
+	    }
1227 1663
 	    $buffer = $Common->getData($value['host']);
1228 1664
 	    $all_data = json_decode($buffer,true);
1229 1665
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1252,16 +1688,25 @@  discard block
 block discarded – undo
1252 1688
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
1253 1689
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
1254 1690
     		    //$data['registration'] = $line['aircraft'];
1255
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1691
+		    if (isset($line['route'])) {
1692
+		    	$data['waypoints'] = $line['route'];
1693
+		    }
1694
+		    // route
1256 1695
 	    	    $data['aircraft_icao'] = $line['plane_type'];
1257 1696
     		    $data['id_source'] = $id_source;
1258 1697
 	    	    $data['format_source'] = 'vam';
1259
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1260
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1698
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1699
+		    	$data['noarchive'] = true;
1700
+		    }
1701
+		    if (isset($value['name']) && $value['name'] != '') {
1702
+		    	$data['source_name'] = $value['name'];
1703
+		    }
1261 1704
 		    $SI->add($data);
1262 1705
 		    unset($data);
1263 1706
 		}
1264
-		if ($globalDebug) echo 'No more data...'."\n";
1707
+		if ($globalDebug) {
1708
+			echo 'No more data...'."\n";
1709
+		}
1265 1710
 		unset($buffer);
1266 1711
 		unset($all_data);
1267 1712
 	    }
@@ -1274,7 +1719,9 @@  discard block
 block discarded – undo
1274 1719
 	    )
1275 1720
 	) {
1276 1721
 	    //$buffer = $Common->getData($hosts[$id]);
1277
-	    if ($globalDebug) echo 'Get Data...'."\n";
1722
+	    if ($globalDebug) {
1723
+	    	echo 'Get Data...'."\n";
1724
+	    }
1278 1725
 	    $buffer = $Common->getData($value['host']);
1279 1726
 	    $all_data = json_decode($buffer,true);
1280 1727
 	    if ($buffer != '') {
@@ -1292,18 +1739,24 @@  discard block
 block discarded – undo
1292 1739
 			$data['id_source'] = $id_source;
1293 1740
 			$data['format_source'] = 'blitzortung';
1294 1741
 			$SI->add($data);
1295
-			if ($globalDebug) echo '☈ Lightning added'."\n";
1742
+			if ($globalDebug) {
1743
+				echo '☈ Lightning added'."\n";
1744
+			}
1296 1745
 			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1297 1746
 			unset($data);
1298 1747
 		    }
1299 1748
 		}
1300
-		if ($globalDebug) echo 'No more data...'."\n";
1749
+		if ($globalDebug) {
1750
+			echo 'No more data...'."\n";
1751
+		}
1301 1752
 		unset($buffer);
1302 1753
 	    }
1303 1754
 	    $last_exec[$id]['last'] = time();
1304 1755
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1305 1756
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'famaprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais' || $value['format'] == 'vrstcp') {
1306
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1757
+	    if (function_exists('pcntl_fork')) {
1758
+	    	pcntl_signal_dispatch();
1759
+	    }
1307 1760
     	    //$last_exec[$id]['last'] = time();
1308 1761
 
1309 1762
 	    //$read = array( $sockets[$id] );
@@ -1311,7 +1764,9 @@  discard block
 block discarded – undo
1311 1764
 	    $write = NULL;
1312 1765
 	    $e = NULL;
1313 1766
 	    $n = socket_select($read, $write, $e, $timeout);
1314
-	    if ($e != NULL) var_dump($e);
1767
+	    if ($e != NULL) {
1768
+	    	var_dump($e);
1769
+	    }
1315 1770
 	    if ($n > 0) {
1316 1771
 		$reset = 0;
1317 1772
 		foreach ($read as $nb => $r) {
@@ -1333,13 +1788,17 @@  discard block
 block discarded – undo
1333 1788
 		    if ($buffer !== FALSE) {
1334 1789
 			if ($format == 'vrstcp') {
1335 1790
 			    $buffer = explode('},{',$buffer);
1336
-			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1791
+			} else {
1792
+				$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1793
+			}
1337 1794
 		    }
1338 1795
 		    // SBS format is CSV format
1339 1796
 		    if ($buffer !== FALSE && $buffer !== '') {
1340 1797
 			$tt[$format] = 0;
1341 1798
 			if ($format == 'acarssbs3') {
1342
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1799
+			    if ($globalDebug) {
1800
+			    	echo 'ACARS : '.$buffer."\n";
1801
+			    }
1343 1802
 			    $ACARS->add(trim($buffer));
1344 1803
 			    $ACARS->deleteLiveAcarsData();
1345 1804
 			} elseif ($format == 'raw') {
@@ -1348,30 +1807,70 @@  discard block
 block discarded – undo
1348 1807
 			    if (is_array($data)) {
1349 1808
 				$data['datetime'] = date('Y-m-d H:i:s');
1350 1809
 				$data['format_source'] = 'raw';
1351
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1352
-				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1353
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1354
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1810
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1811
+					$data['source_name'] = $globalSources[$nb]['name'];
1812
+				}
1813
+				if (isset($globalSources[$nb]['sourcestats'])) {
1814
+					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1815
+				}
1816
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1817
+					$data['noarchive'] = true;
1818
+				}
1819
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1820
+					$SI->add($data);
1821
+				}
1355 1822
 			    }
1356 1823
 			} elseif ($format == 'ais') {
1357 1824
 			    $ais_data = $AIS->parse_line(trim($buffer));
1358 1825
 			    $data = array();
1359
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1360
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1361
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1362
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1363
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1364
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1365
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1366
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1367
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1368
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1369
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1370
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1371
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1372
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1373
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1374
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1826
+			    if (isset($ais_data['ident'])) {
1827
+			    	$data['ident'] = $ais_data['ident'];
1828
+			    }
1829
+			    if (isset($ais_data['mmsi'])) {
1830
+			    	$data['mmsi'] = $ais_data['mmsi'];
1831
+			    }
1832
+			    if (isset($ais_data['speed'])) {
1833
+			    	$data['speed'] = $ais_data['speed'];
1834
+			    }
1835
+			    if (isset($ais_data['heading'])) {
1836
+			    	$data['heading'] = $ais_data['heading'];
1837
+			    }
1838
+			    if (isset($ais_data['latitude'])) {
1839
+			    	$data['latitude'] = $ais_data['latitude'];
1840
+			    }
1841
+			    if (isset($ais_data['longitude'])) {
1842
+			    	$data['longitude'] = $ais_data['longitude'];
1843
+			    }
1844
+			    if (isset($ais_data['status'])) {
1845
+			    	$data['status'] = $ais_data['status'];
1846
+			    }
1847
+			    if (isset($ais_data['statusid'])) {
1848
+			    	$data['status_id'] = $ais_data['statusid'];
1849
+			    }
1850
+			    if (isset($ais_data['type'])) {
1851
+			    	$data['type'] = $ais_data['type'];
1852
+			    }
1853
+			    if (isset($ais_data['imo'])) {
1854
+			    	$data['imo'] = $ais_data['imo'];
1855
+			    }
1856
+			    if (isset($ais_data['callsign'])) {
1857
+			    	$data['callsign'] = $ais_data['callsign'];
1858
+			    }
1859
+			    if (isset($ais_data['destination'])) {
1860
+			    	$data['arrival_code'] = $ais_data['destination'];
1861
+			    }
1862
+			    if (isset($ais_data['eta_ts'])) {
1863
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1864
+			    }
1865
+			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1866
+			    	$data['noarchive'] = true;
1867
+			    }
1868
+			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1869
+			    	$data['source_name'] = $globalSources[$nb]['name'];
1870
+			    }
1871
+			    if (isset($globalSources[$nb]['sourcestats'])) {
1872
+			    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1873
+			    }
1375 1874
 
1376 1875
 			    if (isset($ais_data['timestamp'])) {
1377 1876
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1380,7 +1879,9 @@  discard block
 block discarded – undo
1380 1879
 			    }
1381 1880
 			    $data['format_source'] = 'aisnmea';
1382 1881
     			    $data['id_source'] = $id_source;
1383
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1882
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
1883
+			    	$MI->add($data);
1884
+			    }
1384 1885
 			    unset($data);
1385 1886
                         } elseif ($format == 'flightgearsp') {
1386 1887
                     	    //echo $buffer."\n";
@@ -1398,12 +1899,18 @@  discard block
 block discarded – undo
1398 1899
 				$data['speed'] = round($line[5]*1.94384);
1399 1900
 				$data['datetime'] = date('Y-m-d H:i:s');
1400 1901
 				$data['format_source'] = 'flightgearsp';
1401
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1402
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1902
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1903
+					$data['noarchive'] = true;
1904
+				}
1905
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1906
+					$SI->add($data);
1907
+				}
1403 1908
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1404 1909
 			    }
1405 1910
                         } elseif ($format == 'acars') {
1406
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1911
+                    	    if ($globalDebug) {
1912
+                    	    	echo 'ACARS : '.$buffer."\n";
1913
+                    	    }
1407 1914
 			    $ACARS->add(trim($buffer));
1408 1915
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1409 1916
 			    $ACARS->deleteLiveAcarsData();
@@ -1424,8 +1931,12 @@  discard block
 block discarded – undo
1424 1931
 				    $aircraft_type = $line[10];
1425 1932
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1426 1933
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1427
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1428
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1934
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1935
+				    	$data['noarchive'] = true;
1936
+				    }
1937
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1938
+				    	$SI->add($data);
1939
+				    }
1429 1940
 				}
1430 1941
 			    }
1431 1942
 			} elseif ($format == 'beast') {
@@ -1435,28 +1946,62 @@  discard block
 block discarded – undo
1435 1946
 			    foreach($buffer as $all_data) {
1436 1947
 				$line = json_decode('{'.$all_data.'}',true);
1437 1948
 				$data = array();
1438
-				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1439
-				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1440
-				if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1441
-				if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1442
-				if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1443
-				if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1444
-				if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1949
+				if (isset($line['Icao'])) {
1950
+					$data['hex'] = $line['Icao'];
1951
+				}
1952
+				// hex
1953
+				if (isset($line['Call'])) {
1954
+					$data['ident'] = $line['Call'];
1955
+				}
1956
+				// ident
1957
+				if (isset($line['Alt'])) {
1958
+					$data['altitude'] = $line['Alt'];
1959
+				}
1960
+				// altitude
1961
+				if (isset($line['Spd'])) {
1962
+					$data['speed'] = $line['Spd'];
1963
+				}
1964
+				// speed
1965
+				if (isset($line['Trak'])) {
1966
+					$data['heading'] = $line['Trak'];
1967
+				}
1968
+				// heading
1969
+				if (isset($line['Lat'])) {
1970
+					$data['latitude'] = $line['Lat'];
1971
+				}
1972
+				// lat
1973
+				if (isset($line['Long'])) {
1974
+					$data['longitude'] = $line['Long'];
1975
+				}
1976
+				// long
1445 1977
 				//$data['verticalrate'] = $line['']; // verticale rate
1446
-				if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1978
+				if (isset($line['Sqk'])) {
1979
+					$data['squawk'] = $line['Sqk'];
1980
+				}
1981
+				// squawk
1447 1982
 				$data['emergency'] = ''; // emergency
1448
-				if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
1983
+				if (isset($line['Reg'])) {
1984
+					$data['registration'] = $line['Reg'];
1985
+				}
1449 1986
 				/*
1450 1987
 				if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
1451 1988
 				else $data['datetime'] = date('Y-m-d H:i:s');
1452 1989
 				*/
1453 1990
 				$data['datetime'] = date('Y-m-d H:i:s');
1454
-				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1991
+				if (isset($line['Type'])) {
1992
+					$data['aircraft_icao'] = $line['Type'];
1993
+				}
1455 1994
 		    		$data['format_source'] = 'vrstcp';
1456 1995
 				$data['id_source'] = $id_source;
1457
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1458
-				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1459
-				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1996
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1997
+					$data['noarchive'] = true;
1998
+				}
1999
+				if (isset($value['name']) && $value['name'] != '') {
2000
+					$data['source_name'] = $value['name'];
2001
+				}
2002
+				if (isset($data['latitude']) && isset($data['hex'])) {
2003
+					$SI->add($data);
2004
+				}
1460 2005
 				unset($data);
1461 2006
 			    }
1462 2007
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
@@ -1469,22 +2014,46 @@  discard block
 block discarded – undo
1469 2014
     				$data['hex'] = $lined['hexid'];
1470 2015
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1471 2016
     				$data['datetime'] = date('Y-m-d H:i:s');;
1472
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1473
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1474
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1475
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1476
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1477
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1478
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
2017
+    				if (isset($lined['ident'])) {
2018
+    					$data['ident'] = $lined['ident'];
2019
+    				}
2020
+    				if (isset($lined['lat'])) {
2021
+    					$data['latitude'] = $lined['lat'];
2022
+    				}
2023
+    				if (isset($lined['lon'])) {
2024
+    					$data['longitude'] = $lined['lon'];
2025
+    				}
2026
+    				if (isset($lined['speed'])) {
2027
+    					$data['speed'] = $lined['speed'];
2028
+    				}
2029
+    				if (isset($lined['squawk'])) {
2030
+    					$data['squawk'] = $lined['squawk'];
2031
+    				}
2032
+    				if (isset($lined['alt'])) {
2033
+    					$data['altitude'] = $lined['alt'];
2034
+    				}
2035
+    				if (isset($lined['heading'])) {
2036
+    					$data['heading'] = $lined['heading'];
2037
+    				}
1479 2038
     				$data['id_source'] = $id_source;
1480 2039
     				$data['format_source'] = 'tsv';
1481
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1482
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1483
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1484
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2040
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2041
+    					$data['source_name'] = $globalSources[$nb]['name'];
2042
+    				}
2043
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2044
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2045
+    				}
2046
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2047
+					$data['noarchive'] = true;
2048
+				}
2049
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2050
+    					$SI->add($data);
2051
+    				}
1485 2052
     				unset($lined);
1486 2053
     				unset($data);
1487
-    			    } else $error = true;
2054
+    			    } else {
2055
+    			    	$error = true;
2056
+    			    }
1488 2057
 			} elseif ($format == 'aprs' && $use_aprs) {
1489 2058
 			    if ($aprs_connect == 0) {
1490 2059
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1510,63 +2079,121 @@  discard block
 block discarded – undo
1510 2079
 				    $aprs_last_tx = time();
1511 2080
 				    $data = array();
1512 2081
 				    //print_r($line);
1513
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1514
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1515
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1516
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1517
-				    if (isset($line['arrival_code'])) $data['arrical_code'] = $line['arrival_code'];
1518
-				    if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1519
-				    if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1520
-				    if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1521
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1522
-				    else $data['datetime'] = date('Y-m-d H:i:s');
2082
+				    if (isset($line['address'])) {
2083
+				    	$data['hex'] = $line['address'];
2084
+				    }
2085
+				    if (isset($line['mmsi'])) {
2086
+				    	$data['mmsi'] = $line['mmsi'];
2087
+				    }
2088
+				    if (isset($line['imo'])) {
2089
+				    	$data['imo'] = $line['imo'];
2090
+				    }
2091
+				    if (isset($line['squawk'])) {
2092
+				    	$data['squawk'] = $line['squawk'];
2093
+				    }
2094
+				    if (isset($line['arrival_code'])) {
2095
+				    	$data['arrical_code'] = $line['arrival_code'];
2096
+				    }
2097
+				    if (isset($line['arrival_date'])) {
2098
+				    	$data['arrical_date'] = $line['arrival_date'];
2099
+				    }
2100
+				    if (isset($line['type_id'])) {
2101
+				    	$data['type_id'] = $line['typeid'];
2102
+				    }
2103
+				    if (isset($line['status_id'])) {
2104
+				    	$data['status_id'] = $line['statusid'];
2105
+				    }
2106
+				    if (isset($line['timestamp'])) {
2107
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
2108
+				    } else {
2109
+				    	$data['datetime'] = date('Y-m-d H:i:s');
2110
+				    }
1523 2111
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1524
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
2112
+				    if (isset($line['ident'])) {
2113
+				    	$data['ident'] = $line['ident'];
2114
+				    }
1525 2115
 				    $data['latitude'] = $line['latitude'];
1526 2116
 				    $data['longitude'] = $line['longitude'];
1527 2117
 				    //$data['verticalrate'] = $line[16];
1528
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
2118
+				    if (isset($line['speed'])) {
2119
+				    	$data['speed'] = $line['speed'];
2120
+				    }
1529 2121
 				    //else $data['speed'] = 0;
1530
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1531
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1532
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
2122
+				    if (isset($line['altitude'])) {
2123
+				    	$data['altitude'] = $line['altitude'];
2124
+				    }
2125
+				    if (isset($line['comment'])) {
2126
+				    	$data['comment'] = $line['comment'];
2127
+				    }
2128
+				    if (isset($line['symbol'])) {
2129
+				    	$data['type'] = $line['symbol'];
2130
+				    }
1533 2131
 				    //if (isset($line['heading'])) $data['heading'] = $line['heading'];
1534 2132
 				    
1535
-				    if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
2133
+				    if (isset($line['heading']) && isset($line['format_source'])) {
2134
+				    	$data['heading'] = $line['heading'];
2135
+				    }
1536 2136
 				    //else echo 'No heading...'."\n";
1537 2137
 				    //else $data['heading'] = 0;
1538
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
2138
+				    if (isset($line['stealth'])) {
2139
+				    	$data['aircraft_type'] = $line['stealth'];
2140
+				    }
1539 2141
 				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1540
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1541
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1542
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1543
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
2142
+				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) {
2143
+				    	$data['noarchive'] = true;
2144
+				    } elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) {
2145
+				    	$data['noarchive'] = false;
2146
+				    }
2147
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2148
+				    	$data['noarchive'] = true;
2149
+				    } elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) {
2150
+				    	$data['noarchive'] = false;
2151
+				    }
1544 2152
     				    $data['id_source'] = $id_source;
1545
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1546
-				    else $data['format_source'] = 'aprs';
2153
+    				    if (isset($line['format_source'])) {
2154
+    				    	$data['format_source'] = $line['format_source'];
2155
+    				    } else {
2156
+				    	$data['format_source'] = 'aprs';
2157
+				    }
1547 2158
 				    $data['source_name'] = $line['source'];
1548
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1549
-				    else $data['source_type'] = 'flarm';
1550
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2159
+				    if (isset($line['source_type'])) {
2160
+				    	$data['source_type'] = $line['source_type'];
2161
+				    } else {
2162
+				    	$data['source_type'] = 'flarm';
2163
+				    }
2164
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
2165
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2166
+    				    }
1551 2167
 				    $currentdate = date('Y-m-d H:i:s');
1552 2168
 				    $aprsdate = strtotime($data['datetime']);
1553
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
2169
+				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') {
2170
+				    	$data['altitude_relative'] = 'AMSL';
2171
+				    }
1554 2172
 				    // Accept data if time <= system time + 20s
1555 2173
 				    //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'])))) {
1556 2174
 				    if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1557 2175
 					$send = $SI->add($data);
1558 2176
 				    } elseif ($data['source_type'] == 'ais') {
1559 2177
 					$data['type'] = '';
1560
-					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
2178
+					if (isset($globalMarine) && $globalMarine) {
2179
+						$send = $MI->add($data);
2180
+					}
1561 2181
 				    } elseif (isset($line['stealth'])) {
1562
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1563
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
2182
+					if ($line['stealth'] != 0) {
2183
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
2184
+					} else {
2185
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
2186
+					}
1564 2187
 				    } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1565 2188
 					    //$line['symbol'] == 'Balloon' ||
1566 2189
 					    $line['symbol'] == 'Glider' || 
1567 2190
 					    $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1568
-					    if ($line['symbol'] == 'Ballon') $data['aircraft_icao'] = 'BALL';
1569
-					    if ($line['symbol'] == 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
2191
+					    if ($line['symbol'] == 'Ballon') {
2192
+					    	$data['aircraft_icao'] = 'BALL';
2193
+					    }
2194
+					    if ($line['symbol'] == 'Glider') {
2195
+					    	$data['aircraft_icao'] = 'PARAGLIDER';
2196
+					    }
1570 2197
 					    $send = $SI->add($data);
1571 2198
 				    } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1572 2199
 					    $line['symbol'] == 'Yacht (Sail)' || 
@@ -1597,9 +2224,13 @@  discard block
 block discarded – undo
1597 2224
 				    //} 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') {
1598 2225
 				//    } 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') {
1599 2226
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1600
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
2227
+					if (isset($globalTracker) && $globalTracker) {
2228
+						$send = $TI->add($data);
2229
+					}
1601 2230
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1602
-					if (!isset($data['altitude'])) $data['altitude'] = 0;
2231
+					if (!isset($data['altitude'])) {
2232
+						$data['altitude'] = 0;
2233
+					}
1603 2234
 					$Source->deleteOldLocationByType('gs');
1604 2235
 					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
1605 2236
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
@@ -1608,7 +2239,9 @@  discard block
 block discarded – undo
1608 2239
 					}
1609 2240
 				    } elseif (isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1610 2241
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1611
-					if ($globalDebug) echo '# Weather Station added'."\n";
2242
+					if ($globalDebug) {
2243
+						echo '# Weather Station added'."\n";
2244
+					}
1612 2245
 					$Source->deleteOldLocationByType('wx');
1613 2246
 					$weather_data = json_encode($line);
1614 2247
 					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
@@ -1618,7 +2251,9 @@  discard block
 block discarded – undo
1618 2251
 					}
1619 2252
 				    } elseif (isset($line['symbol']) && ($line['symbol'] == 'Lightning' || $line['symbol'] == 'Thunderstorm')) {
1620 2253
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1621
-					if ($globalDebug) echo '☈ Lightning added'."\n";
2254
+					if ($globalDebug) {
2255
+						echo '☈ Lightning added'."\n";
2256
+					}
1622 2257
 					$Source->deleteOldLocationByType('lightning');
1623 2258
 					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
1624 2259
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
@@ -1630,8 +2265,7 @@  discard block
 block discarded – undo
1630 2265
 				    	print_r($line);
1631 2266
 				    }
1632 2267
 				    unset($data);
1633
-				}
1634
-				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
2268
+				} elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1635 2269
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
1636 2270
 				}
1637 2271
 				/*
@@ -1640,7 +2274,9 @@  discard block
 block discarded – undo
1640 2274
 				}
1641 2275
 				*/
1642 2276
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1643
-				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
2277
+				elseif ($line == true && $globalDebug) {
2278
+					echo '!! Failed : '.$buffer."!!\n";
2279
+				}
1644 2280
 				if (isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
1645 2281
 					$Source->deleteOldLocationByType('lightning');
1646 2282
 					$Source->deleteOldLocationByType('wx');
@@ -1676,26 +2312,45 @@  discard block
 block discarded – undo
1676 2312
     				$data['ground'] = $line[21];
1677 2313
     				$data['emergency'] = $line[19];
1678 2314
     				$data['format_source'] = 'sbs';
1679
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1680
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1681
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
2315
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2316
+					$data['source_name'] = $globalSources[$nb]['name'];
2317
+				}
2318
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2319
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2320
+    				}
2321
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2322
+					$data['noarchive'] = true;
2323
+				}
1682 2324
     				$data['id_source'] = $id_source;
1683
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1684
-    				else $error = true;
2325
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2326
+    					$send = $SI->add($data);
2327
+    				} else {
2328
+    					$error = true;
2329
+    				}
1685 2330
     				unset($data);
1686
-    			    } else $error = true;
2331
+    			    } else {
2332
+    			    	$error = true;
2333
+    			    }
1687 2334
 			    if ($error) {
1688 2335
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1689
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
2336
+					if ($globalDebug) {
2337
+						echo "Not a message. Ignoring... \n";
2338
+					}
1690 2339
 				} else {
1691
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
2340
+					if ($globalDebug) {
2341
+						echo "Wrong line format. Ignoring... \n";
2342
+					}
1692 2343
 					if ($globalDebug) {
1693 2344
 						echo $buffer;
1694 2345
 						//print_r($line);
1695 2346
 					}
1696 2347
 					//socket_close($r);
1697
-					if ($globalDebug) echo "Reconnect after an error...\n";
1698
-					if ($format == 'aprs') $aprs_connect = 0;
2348
+					if ($globalDebug) {
2349
+						echo "Reconnect after an error...\n";
2350
+					}
2351
+					if ($format == 'aprs') {
2352
+						$aprs_connect = 0;
2353
+					}
1699 2354
 					$sourceer[$nb] = $globalSources[$nb];
1700 2355
 					connect_all($sourceer);
1701 2356
 					$sourceer = array();
@@ -1703,10 +2358,14 @@  discard block
 block discarded – undo
1703 2358
 			    }
1704 2359
 			}
1705 2360
 			// Sleep for xxx microseconds
1706
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
2361
+			if (isset($globalSBSSleep)) {
2362
+				usleep($globalSBSSleep);
2363
+			}
1707 2364
 		    } else {
1708 2365
 			if ($format == 'flightgearmp') {
1709
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
2366
+			    	if ($globalDebug) {
2367
+			    		echo "Reconnect FlightGear MP...";
2368
+			    	}
1710 2369
 				//@socket_close($r);
1711 2370
 				sleep($globalMinFetch);
1712 2371
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1715,10 +2374,15 @@  discard block
 block discarded – undo
1715 2374
 				break;
1716 2375
 				
1717 2376
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1718
-			    if (isset($tt[$format])) $tt[$format]++;
1719
-			    else $tt[$format] = 0;
2377
+			    if (isset($tt[$format])) {
2378
+			    	$tt[$format]++;
2379
+			    } else {
2380
+			    	$tt[$format] = 0;
2381
+			    }
1720 2382
 			    if ($tt[$format] > 30 || $buffer === FALSE) {
1721
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
2383
+				if ($globalDebug) {
2384
+					echo "ERROR : Reconnect ".$format."...";
2385
+				}
1722 2386
 				//@socket_close($r);
1723 2387
 				sleep(2);
1724 2388
 				$aprs_connect = 0;
@@ -1736,11 +2400,17 @@  discard block
 block discarded – undo
1736 2400
 	    } else {
1737 2401
 		$error = socket_strerror(socket_last_error());
1738 2402
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1739
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1740
-			if (isset($globalDebug)) echo "Restarting...\n";
2403
+			if ($globalDebug) {
2404
+				echo "ERROR : socket_select give this error ".$error . "\n";
2405
+			}
2406
+			if (isset($globalDebug)) {
2407
+				echo "Restarting...\n";
2408
+			}
1741 2409
 			// Restart the script if possible
1742 2410
 			if (is_array($sockets)) {
1743
-			    if ($globalDebug) echo "Shutdown all sockets...";
2411
+			    if ($globalDebug) {
2412
+			    	echo "Shutdown all sockets...";
2413
+			    }
1744 2414
 			    
1745 2415
 			    foreach ($sockets as $sock) {
1746 2416
 				@socket_shutdown($sock,2);
@@ -1748,25 +2418,45 @@  discard block
 block discarded – undo
1748 2418
 			    }
1749 2419
 			    
1750 2420
 			}
1751
-			if ($globalDebug) echo "Waiting...";
2421
+			if ($globalDebug) {
2422
+				echo "Waiting...";
2423
+			}
1752 2424
 			sleep(2);
1753 2425
 			$time = time();
1754 2426
 			//connect_all($hosts);
1755 2427
 			$aprs_connect = 0;
1756
-			if ($reset%5 == 0) sleep(20);
1757
-			if ($reset%10 == 0) sleep(100);
1758
-			if ($reset%20 == 0) sleep(200);
1759
-			if ($reset > 100) exit('Too many attempts...');
1760
-			if ($globalDebug) echo "Restart all connections...";
2428
+			if ($reset%5 == 0) {
2429
+				sleep(20);
2430
+			}
2431
+			if ($reset%10 == 0) {
2432
+				sleep(100);
2433
+			}
2434
+			if ($reset%20 == 0) {
2435
+				sleep(200);
2436
+			}
2437
+			if ($reset > 100) {
2438
+				exit('Too many attempts...');
2439
+			}
2440
+			if ($globalDebug) {
2441
+				echo "Restart all connections...";
2442
+			}
1761 2443
 			connect_all($globalSources);
1762 2444
 		}
1763 2445
 	    }
1764 2446
 	}
1765 2447
 	if ($globalDaemon === false) {
1766
-	    if ($globalDebug) echo 'Check all...'."\n";
1767
-	    if (isset($SI)) $SI->checkAll();
1768
-	    if (isset($TI)) $TI->checkAll();
1769
-	    if (isset($MI)) $MI->checkAll();
2448
+	    if ($globalDebug) {
2449
+	    	echo 'Check all...'."\n";
2450
+	    }
2451
+	    if (isset($SI)) {
2452
+	    	$SI->checkAll();
2453
+	    }
2454
+	    if (isset($TI)) {
2455
+	    	$TI->checkAll();
2456
+	    }
2457
+	    if (isset($MI)) {
2458
+	    	$MI->checkAll();
2459
+	    }
1770 2460
 	}
1771 2461
     }
1772 2462
 }
Please login to merge, or discard this patch.