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