Completed
Push — master ( 128a26...3f35c5 )
by Yannick
58:51 queued 28:47
created
scripts/daemon-spotter.php 1 patch
Braces   +1093 added lines, -372 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,37 +262,53 @@  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('/\/api\/v1\/acars\/data$/i',$host)) {
208 269
         	//$formats[$id] = 'phpvmacars';
209 270
         	$globalSources[$id]['format'] = 'vaos';
210 271
         	//$last_exec['phpvmacars'] = 0;
211
-        	if ($globalDebug) echo "Connect to vaos source (".$host.")...\n";
272
+        	if ($globalDebug) {
273
+        		echo "Connect to vaos source (".$host.")...\n";
274
+        	}
212 275
             } else if (preg_match('/VAM-json.php$/i',$host)) {
213 276
         	//$formats[$id] = 'phpvmacars';
214 277
         	$globalSources[$id]['format'] = 'vam';
215
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
278
+        	if ($globalDebug) {
279
+        		echo "Connect to Vam source (".$host.")...\n";
280
+        	}
216 281
             } else if (preg_match('/whazzup/i',$host)) {
217 282
         	//$formats[$id] = 'whazzup';
218 283
         	$globalSources[$id]['format'] = 'whazzup';
219 284
         	//$last_exec['whazzup'] = 0;
220
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
285
+        	if ($globalDebug) {
286
+        		echo "Connect to whazzup source (".$host.")...\n";
287
+        	}
221 288
             } else if (preg_match('/blitzortung/i',$host)) {
222 289
         	$globalSources[$id]['format'] = 'blitzortung';
223
-        	if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n";
290
+        	if ($globalDebug) {
291
+        		echo "Connect to blitzortung source (".$host.")...\n";
292
+        	}
224 293
             } else if (preg_match('/airwhere/i',$host)) {
225 294
         	$globalSources[$id]['format'] = 'airwhere';
226
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
295
+        	if ($globalDebug) {
296
+        		echo "Connect to airwhere source (".$host.")...\n";
297
+        	}
227 298
             } else if (preg_match('/recentpireps/i',$host)) {
228 299
         	//$formats[$id] = 'pirepsjson';
229 300
         	$globalSources[$id]['format'] = 'pirepsjson';
230 301
         	//$last_exec['pirepsjson'] = 0;
231
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
302
+        	if ($globalDebug) {
303
+        		echo "Connect to pirepsjson source (".$host.")...\n";
304
+        	}
232 305
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
233 306
         	//$formats[$id] = 'fr24json';
234 307
         	$globalSources[$id]['format'] = 'fr24json';
235 308
         	//$last_exec['fr24json'] = 0;
236
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
309
+        	if ($globalDebug) {
310
+        		echo "Connect to fr24 source (".$host.")...\n";
311
+        	}
237 312
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
238 313
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
239 314
         	    exit(0);
@@ -242,7 +317,9 @@  discard block
 block discarded – undo
242 317
         	//$formats[$id] = 'fr24json';
243 318
         	$globalSources[$id]['format'] = 'myshiptracking';
244 319
         	//$last_exec['fr24json'] = 0;
245
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
320
+        	if ($globalDebug) {
321
+        		echo "Connect to myshiptracking source (".$host.")...\n";
322
+        	}
246 323
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
247 324
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
248 325
         	    exit(0);
@@ -251,16 +328,24 @@  discard block
 block discarded – undo
251 328
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
252 329
         	//$formats[$id] = 'tsv';
253 330
         	$globalSources[$id]['format'] = 'tsv';
254
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
331
+        	if ($globalDebug) {
332
+        		echo "Connect to tsv source (".$host.")...\n";
333
+        	}
255 334
             }
256 335
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
257 336
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
258 337
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
259 338
     		    if ($idf !== false) {
260 339
     			$httpfeeds[$id] = $idf;
261
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
262
-    		    } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
263
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
340
+        		if ($globalDebug) {
341
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
342
+        		}
343
+    		    } elseif ($globalDebug) {
344
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
345
+    		    }
346
+    		} elseif ($globalDebug) {
347
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
348
+    		}
264 349
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
265 350
 	    $hostport = explode(':',$host);
266 351
 	    if (isset($hostport[1])) {
@@ -300,17 +385,25 @@  discard block
 block discarded – undo
300 385
         		//$formats[$id] = 'beast';
301 386
         		$globalSources[$id]['format'] = 'beast';
302 387
 		    //} else $formats[$id] = 'sbs';
303
-		    } else $globalSources[$id]['format'] = 'sbs';
388
+		    } else {
389
+		    	$globalSources[$id]['format'] = 'sbs';
390
+		    }
304 391
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
305 392
 		}
306
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
393
+		if ($globalDebug) {
394
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
395
+		}
307 396
             } else {
308
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
397
+		if ($globalDebug) {
398
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
399
+		}
309 400
     	    }
310 401
         }
311 402
     }
312 403
 }
313
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
404
+if (!isset($globalMinFetch)) {
405
+	$globalMinFetch = 15;
406
+}
314 407
 
315 408
 // Initialize all
316 409
 $status = array();
@@ -319,13 +412,19 @@  discard block
 block discarded – undo
319 412
 $formats = array();
320 413
 $last_exec = array();
321 414
 $time = time();
322
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
323
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
324
-else $timeout = 20;
415
+if (isset($globalSourcesTimeout)) {
416
+	$timeout = $globalSourcesTimeOut;
417
+} else if (isset($globalSBS1TimeOut)) {
418
+	$timeout = $globalSBS1TimeOut;
419
+} else {
420
+	$timeout = 20;
421
+}
325 422
 $errno = '';
326 423
 $errstr='';
327 424
 
328
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
425
+if (!isset($globalDaemon)) {
426
+	$globalDaemon = TRUE;
427
+}
329 428
 /* Initiate connections to all the hosts simultaneously */
330 429
 //connect_all($hosts);
331 430
 //connect_all($globalSources);
@@ -354,7 +453,9 @@  discard block
 block discarded – undo
354 453
     if (isset($source['format']) && $source['format'] == 'aprs') {
355 454
 	$aprs_connect = 0;
356 455
 	$use_aprs = true;
357
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
456
+	if (isset($source['port']) && $source['port'] == '10152') {
457
+		$aprs_full = true;
458
+	}
358 459
 	break;
359 460
     }
360 461
 }
@@ -365,25 +466,46 @@  discard block
 block discarded – undo
365 466
 	$aprs_connect = 0;
366 467
 	$aprs_keep = 120;
367 468
 	$aprs_last_tx = time();
368
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
369
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
370
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
371
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
372
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
373
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
374
-	if ($aprs_full) $aprs_filter = '';
375
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
376
-	else $aprs_pass = '-1';
469
+	if (isset($globalAPRSversion)) {
470
+		$aprs_version = $globalAPRSversion;
471
+	} else {
472
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
473
+	}
474
+	if (isset($globalAPRSssid)) {
475
+		$aprs_ssid = $globalAPRSssid;
476
+	} else {
477
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
478
+	}
479
+	if (isset($globalAPRSfilter)) {
480
+		$aprs_filter = $globalAPRSfilter;
481
+	} else {
482
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
483
+	}
484
+	if ($aprs_full) {
485
+		$aprs_filter = '';
486
+	}
487
+	if (isset($globalAPRSpass)) {
488
+		$aprs_pass = $globalAPRSpass;
489
+	} else {
490
+		$aprs_pass = '-1';
491
+	}
377 492
 
378
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
379
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
380
-}
493
+	if ($aprs_filter != '') {
494
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
495
+	} else {
496
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
497
+	}
498
+	}
381 499
 
382 500
 // connected - lets do some work
383 501
 //if ($globalDebug) echo "Connected!\n";
384 502
 sleep(1);
385
-if ($globalDebug) echo "SCAN MODE \n\n";
386
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
503
+if ($globalDebug) {
504
+	echo "SCAN MODE \n\n";
505
+}
506
+if (!isset($globalCronEnd)) {
507
+	$globalCronEnd = 60;
508
+}
387 509
 $endtime = time()+$globalCronEnd;
388 510
 $i = 1;
389 511
 $tt = array();
@@ -397,20 +519,28 @@  discard block
 block discarded – undo
397 519
 
398 520
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
399 521
 while ($i > 0) {
400
-    if (!$globalDaemon) $i = $endtime-time();
522
+    if (!$globalDaemon) {
523
+    	$i = $endtime-time();
524
+    }
401 525
     // Delete old ATC
402 526
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
403
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
527
+	if ($globalDebug) {
528
+		echo 'Delete old ATC...'."\n";
529
+	}
404 530
         $ATC->deleteOldATC();
405 531
     }
406 532
     
407 533
     if (count($last_exec) == count($globalSources)) {
408 534
 	$max = $globalMinFetch;
409 535
 	foreach ($last_exec as $last) {
410
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
536
+	    if ((time() - $last['last']) < $max) {
537
+	    	$max = time() - $last['last'];
538
+	    }
411 539
 	}
412 540
 	if ($max != $globalMinFetch) {
413
-	    if ($globalDebug) echo 'Sleeping...'."\n";
541
+	    if ($globalDebug) {
542
+	    	echo 'Sleeping...'."\n";
543
+	    }
414 544
 	    sleep($globalMinFetch-$max+2);
415 545
 	}
416 546
     }
@@ -420,7 +550,9 @@  discard block
 block discarded – undo
420 550
     foreach ($globalSources as $id => $value) {
421 551
 	date_default_timezone_set('UTC');
422 552
 	//if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n";
423
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
553
+	if (!isset($last_exec[$id]['last'])) {
554
+		$last_exec[$id]['last'] = 0;
555
+	}
424 556
 	if ($value['format'] == 'deltadbtxt' && 
425 557
 	    (
426 558
 		(isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || 
@@ -429,7 +561,9 @@  discard block
 block discarded – undo
429 561
 	) {
430 562
 	    //$buffer = $Common->getData($hosts[$id]);
431 563
 	    $buffer = $Common->getData($value['host']);
432
-	    if ($buffer != '') $reset = 0;
564
+	    if ($buffer != '') {
565
+	    	$reset = 0;
566
+	    }
433 567
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
434 568
 	    $buffer = explode('\n',$buffer);
435 569
 	    foreach ($buffer as $line) {
@@ -438,20 +572,41 @@  discard block
 block discarded – undo
438 572
 	            $data = array();
439 573
 	            $data['hex'] = $line[1]; // hex
440 574
 	            $data['ident'] = $line[2]; // ident
441
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
442
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
443
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
444
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
445
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
575
+	            if (isset($line[3])) {
576
+	            	$data['altitude'] = $line[3];
577
+	            }
578
+	            // altitude
579
+	            if (isset($line[4])) {
580
+	            	$data['speed'] = $line[4];
581
+	            }
582
+	            // speed
583
+	            if (isset($line[5])) {
584
+	            	$data['heading'] = $line[5];
585
+	            }
586
+	            // heading
587
+	            if (isset($line[6])) {
588
+	            	$data['latitude'] = $line[6];
589
+	            }
590
+	            // lat
591
+	            if (isset($line[7])) {
592
+	            	$data['longitude'] = $line[7];
593
+	            }
594
+	            // long
446 595
 	            $data['verticalrate'] = ''; // vertical rate
447 596
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
448 597
 	            $data['emergency'] = ''; // emergency
449 598
 		    $data['datetime'] = date('Y-m-d H:i:s');
450 599
 		    $data['format_source'] = 'deltadbtxt';
451 600
     		    $data['id_source'] = $id_source;
452
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
453
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
454
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
601
+		    if (isset($value['name']) && $value['name'] != '') {
602
+		    	$data['source_name'] = $value['name'];
603
+		    }
604
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
605
+		    	$data['noarchive'] = true;
606
+		    }
607
+		    if (isset($value['sourcestats'])) {
608
+		    	$data['sourcestats'] = $value['sourcestats'];
609
+		    }
455 610
     		    $SI->add($data);
456 611
 		    unset($data);
457 612
     		}
@@ -466,7 +621,9 @@  discard block
 block discarded – undo
466 621
 	    date_default_timezone_set('CET');
467 622
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
468 623
 	    date_default_timezone_set('UTC');
469
-	    if ($buffer != '') $reset = 0;
624
+	    if ($buffer != '') {
625
+	    	$reset = 0;
626
+	    }
470 627
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
471 628
 	    $buffer = explode('\n',$buffer);
472 629
 	    foreach ($buffer as $line) {
@@ -475,18 +632,42 @@  discard block
 block discarded – undo
475 632
 		    $add = false;
476 633
 		    $ais_data = $AIS->parse_line(trim($line));
477 634
 		    $data = array();
478
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
479
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
480
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
481
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
482
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
483
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
484
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
485
-		    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
486
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
487
-		    if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
488
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
489
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
635
+		    if (isset($ais_data['ident'])) {
636
+		    	$data['ident'] = $ais_data['ident'];
637
+		    }
638
+		    if (isset($ais_data['mmsi'])) {
639
+		    	$data['mmsi'] = substr($ais_data['mmsi'],-9);
640
+		    }
641
+		    if (isset($ais_data['speed'])) {
642
+		    	$data['speed'] = $ais_data['speed'];
643
+		    }
644
+		    if (isset($ais_data['heading'])) {
645
+		    	$data['heading'] = $ais_data['heading'];
646
+		    }
647
+		    if (isset($ais_data['latitude'])) {
648
+		    	$data['latitude'] = $ais_data['latitude'];
649
+		    }
650
+		    if (isset($ais_data['longitude'])) {
651
+		    	$data['longitude'] = $ais_data['longitude'];
652
+		    }
653
+		    if (isset($ais_data['status'])) {
654
+		    	$data['status'] = $ais_data['status'];
655
+		    }
656
+		    if (isset($ais_data['statusid'])) {
657
+		    	$data['status_id'] = $ais_data['statusid'];
658
+		    }
659
+		    if (isset($ais_data['type'])) {
660
+		    	$data['type'] = $ais_data['type'];
661
+		    }
662
+		    if (isset($ais_data['typeid'])) {
663
+		    	$data['type_id'] = $ais_data['typeid'];
664
+		    }
665
+		    if (isset($ais_data['imo'])) {
666
+		    	$data['imo'] = $ais_data['imo'];
667
+		    }
668
+		    if (isset($ais_data['callsign'])) {
669
+		    	$data['callsign'] = $ais_data['callsign'];
670
+		    }
490 671
 		    if (isset($ais_data['timestamp'])) {
491 672
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
492 673
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -500,8 +681,12 @@  discard block
 block discarded – undo
500 681
 		    $data['format_source'] = 'aisnmeatxt';
501 682
     		    $data['id_source'] = $id_source;
502 683
 		    //print_r($data);
503
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
504
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
684
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
685
+		    	$data['noarchive'] = true;
686
+		    }
687
+		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
688
+		    	$MI->add($data);
689
+		    }
505 690
 		    unset($data);
506 691
 		}
507 692
     	    }
@@ -524,20 +709,48 @@  discard block
 block discarded – undo
524 709
 			    if ($line != '') {
525 710
 				$ais_data = $AIS->parse_line(trim($line));
526 711
 				$data = array();
527
-				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
528
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
529
-				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
530
-				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
531
-				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
532
-				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
533
-				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
534
-				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
535
-				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
536
-				if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
537
-				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
538
-				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
539
-				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
540
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
712
+				if (isset($ais_data['ident'])) {
713
+					$data['ident'] = $ais_data['ident'];
714
+				}
715
+				if (isset($ais_data['mmsi'])) {
716
+					$data['mmsi'] = substr($ais_data['mmsi'],-9);
717
+				}
718
+				if (isset($ais_data['speed'])) {
719
+					$data['speed'] = $ais_data['speed'];
720
+				}
721
+				if (isset($ais_data['heading'])) {
722
+					$data['heading'] = $ais_data['heading'];
723
+				}
724
+				if (isset($ais_data['latitude'])) {
725
+					$data['latitude'] = $ais_data['latitude'];
726
+				}
727
+				if (isset($ais_data['longitude'])) {
728
+					$data['longitude'] = $ais_data['longitude'];
729
+				}
730
+				if (isset($ais_data['status'])) {
731
+					$data['status'] = $ais_data['status'];
732
+				}
733
+				if (isset($ais_data['statusid'])) {
734
+					$data['status_id'] = $ais_data['statusid'];
735
+				}
736
+				if (isset($ais_data['type'])) {
737
+					$data['type'] = $ais_data['type'];
738
+				}
739
+				if (isset($ais_data['typeid'])) {
740
+					$data['type_id'] = $ais_data['typeid'];
741
+				}
742
+				if (isset($ais_data['imo'])) {
743
+					$data['imo'] = $ais_data['imo'];
744
+				}
745
+				if (isset($ais_data['callsign'])) {
746
+					$data['callsign'] = $ais_data['callsign'];
747
+				}
748
+				if (isset($ais_data['destination'])) {
749
+					$data['arrival_code'] = $ais_data['destination'];
750
+				}
751
+				if (isset($ais_data['eta_ts'])) {
752
+					$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
753
+				}
541 754
 				if (isset($ais_data['timestamp'])) {
542 755
 				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
543 756
 				} else {
@@ -545,18 +758,27 @@  discard block
 block discarded – undo
545 758
 				}
546 759
 				$data['format_source'] = 'aisnmeahttp';
547 760
 				$data['id_source'] = $id_source;
548
-				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
549
-				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
761
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
762
+					$data['noarchive'] = true;
763
+				}
764
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
765
+					$MI->add($data);
766
+				}
550 767
 				unset($data);
551 768
 			    }
552 769
 			}
553 770
 		    }
554 771
 		} else {
555 772
 		    $format = $value['format'];
556
-		    if (isset($tt[$format])) $tt[$format]++;
557
-		    else $tt[$format] = 0;
773
+		    if (isset($tt[$format])) {
774
+		    	$tt[$format]++;
775
+		    } else {
776
+		    	$tt[$format] = 0;
777
+		    }
558 778
 		    if ($tt[$format] > 30) {
559
-			if ($globalDebug) echo 'Reconnect...'."\n";
779
+			if ($globalDebug) {
780
+				echo 'Reconnect...'."\n";
781
+			}
560 782
 			sleep(2);
561 783
 			//$sourceeen[] = $value;
562 784
 			//connect_all($sourceeen);
@@ -592,12 +814,18 @@  discard block
 block discarded – undo
592 814
 			    //    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
593 815
 			    //$data['type_id'] = $line['TYPE'];
594 816
 			    $data['imo'] = $line['IMO'];
595
-			    if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST'];
596
-			    if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
817
+			    if ($line['DEST'] != '') {
818
+			    	$data['arrival_code'] = $line['DEST'];
819
+			    }
820
+			    if ($line['ARV'] != '') {
821
+			    	$data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV']));
822
+			    }
597 823
 			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
598 824
 			    $data['format_source'] = 'myshiptracking';
599 825
 			    $data['id_source'] = $id_source;
600
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
826
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
827
+			    	$data['noarchive'] = true;
828
+			    }
601 829
 			    $MI->add($data);
602 830
 			    unset($data);
603 831
 			}
@@ -622,7 +850,9 @@  discard block
 block discarded – undo
622 850
 			    $data['callsign'] = $line['callsign'];
623 851
 			    $data['mmsi'] = substr($line['mmsi'],-9);
624 852
 			    $data['speed'] = $line['sog'];
625
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
853
+			    if ($line['heading'] != '511') {
854
+			    	$data['heading'] = $line['heading'];
855
+			    }
626 856
 			    $data['latitude'] = $line['latitude'];
627 857
 			    $data['longitude'] = $line['longitude'];
628 858
 			    $data['type_id'] = $line['shiptype'];
@@ -630,7 +860,9 @@  discard block
 block discarded – undo
630 860
 			    $data['datetime'] = $line['time'];
631 861
 			    $data['format_source'] = 'boatbeaconapp';
632 862
 			    $data['id_source'] = $id_source;
633
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
863
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
864
+			    	$data['noarchive'] = true;
865
+			    }
634 866
 			    $MI->add($data);
635 867
 			    unset($data);
636 868
 			}
@@ -652,22 +884,44 @@  discard block
 block discarded – undo
652 884
 		    foreach ($all_data['features'] as $line) {
653 885
 			print_r($line);
654 886
 			$data = array();
655
-			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
656
-			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
657
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'],-9);
658
-			if (isset($line['properties']['imo'])) $data['imo'] = $line['properties']['imo'];
659
-			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
660
-			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) $data['heading'] = $line['properties']['heading'];
887
+			if (isset($line['properties']['name'])) {
888
+				$data['ident'] = $line['properties']['name'];
889
+			}
890
+			if (isset($line['properties']['callsign'])) {
891
+				$data['callsign'] = $line['properties']['callsign'];
892
+			}
893
+			if (isset($line['properties']['mmsi'])) {
894
+				$data['mmsi'] = substr($line['properties']['mmsi'],-9);
895
+			}
896
+			if (isset($line['properties']['imo'])) {
897
+				$data['imo'] = $line['properties']['imo'];
898
+			}
899
+			if (isset($line['properties']['speed'])) {
900
+				$data['speed'] = $line['properties']['speed'];
901
+			}
902
+			if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) {
903
+				$data['heading'] = $line['properties']['heading'];
904
+			}
661 905
 			$data['latitude'] = $line['geometry']['coordinates'][1];
662 906
 			$data['longitude'] = $line['geometry']['coordinates'][0];
663
-			if (isset($line['properties']['vesselType'])) $data['type'] = $line['properties']['vesselType'];
664
-			if (isset($line['properties']['destination'])) $data['arrival_code'] = $line['properties']['destination'];
665
-			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') $data['arrival_date'] = $line['properties']['eta'];
907
+			if (isset($line['properties']['vesselType'])) {
908
+				$data['type'] = $line['properties']['vesselType'];
909
+			}
910
+			if (isset($line['properties']['destination'])) {
911
+				$data['arrival_code'] = $line['properties']['destination'];
912
+			}
913
+			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') {
914
+				$data['arrival_date'] = $line['properties']['eta'];
915
+			}
666 916
 			$data['format_source'] = 'boatnerd';
667 917
 			$data['id_source'] = $id_source;
668 918
 			$data['datetime'] = date('Y-m-d H:i:s');
669
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
670
-			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
919
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
920
+				$data['noarchive'] = true;
921
+			}
922
+			if ($line['properties']['vesselType'] != 'Navigation Aid') {
923
+				$MI->add($data);
924
+			}
671 925
 			unset($data);
672 926
 		    }
673 927
 		}
@@ -684,7 +938,9 @@  discard block
 block discarded – undo
684 938
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
685 939
 	    echo 'done !'."\n";
686 940
 	    // FIXME: Need more work
687
-	    if ($buffer != '') $reset = 0;
941
+	    if ($buffer != '') {
942
+	    	$reset = 0;
943
+	    }
688 944
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
689 945
 	    $buffer = explode('\n',$buffer);
690 946
 	    foreach ($buffer as $line) {
@@ -710,7 +966,9 @@  discard block
 block discarded – undo
710 966
 		    //$data['etaTime'] = substr($line,135,5);
711 967
 		    $data['format_source'] = 'shipplotter';
712 968
     		    $data['id_source'] = $id_source;
713
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
969
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
970
+		    	$data['noarchive'] = true;
971
+		    }
714 972
 		    //print_r($data);
715 973
 		    echo 'Add...'."\n";
716 974
 		    $MI->add($data);
@@ -744,16 +1002,28 @@  discard block
 block discarded – undo
744 1002
     		    $line = explode(':', $line);
745 1003
     		    if (count($line) > 30 && $line[0] != 'callsign') {
746 1004
 			$data = array();
747
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
748
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
1005
+			if (isset($line[37]) && $line[37] != '') {
1006
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
1007
+			} else {
1008
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
1009
+			}
749 1010
 			$data['pilot_id'] = $line[1];
750 1011
 			$data['pilot_name'] = $line[2];
751 1012
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
752 1013
 			$data['ident'] = $line[0]; // ident
753
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
1014
+			if ($line[7] != '' && $line[7] != 0) {
1015
+				$data['altitude'] = $line[7];
1016
+			}
1017
+			// altitude
754 1018
 			$data['speed'] = $line[8]; // speed
755
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
756
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
1019
+			if (isset($line[45])) {
1020
+				$data['heading'] = $line[45];
1021
+			}
1022
+			// heading
1023
+			elseif (isset($line[38])) {
1024
+				$data['heading'] = $line[38];
1025
+			}
1026
+			// heading
757 1027
 			$data['latitude'] = $line[5]; // lat
758 1028
 	        	$data['longitude'] = $line[6]; // long
759 1029
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -769,7 +1039,9 @@  discard block
 block discarded – undo
769 1039
 			$data['frequency'] = $line[4];
770 1040
 			$data['type'] = $line[18];
771 1041
 			$data['range'] = $line[19];
772
-			if (isset($line[35])) $data['info'] = $line[35];
1042
+			if (isset($line[35])) {
1043
+				$data['info'] = $line[35];
1044
+			}
773 1045
     			$data['id_source'] = $id_source;
774 1046
 	    		//$data['arrival_airport_time'] = ;
775 1047
 	    		if ($line[9] != '') {
@@ -783,27 +1055,47 @@  discard block
 block discarded – undo
783 1055
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
784 1056
 	    		*/
785 1057
 	    		$data['format_source'] = $value['format'];
786
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
787
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
788
-    			if ($line[3] == 'PILOT') $SI->add($data);
789
-			elseif ($line[3] == 'ATC') {
1058
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1059
+				$data['noarchive'] = true;
1060
+			}
1061
+			if (isset($value['name']) && $value['name'] != '') {
1062
+				$data['source_name'] = $value['name'];
1063
+			}
1064
+    			if ($line[3] == 'PILOT') {
1065
+    				$SI->add($data);
1066
+    			} elseif ($line[3] == 'ATC') {
790 1067
 				//print_r($data);
791 1068
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
792 1069
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
793 1070
 				$typec = substr($data['ident'],-3);
794
-				if ($typec == 'APP') $data['type'] = 'Approach';
795
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
796
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
797
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
798
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
799
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
800
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
801
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
802
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
803
-				if (!isset($data['source_name'])) $data['source_name'] = '';
1071
+				if ($typec == 'APP') {
1072
+					$data['type'] = 'Approach';
1073
+				} elseif ($typec == 'TWR') {
1074
+					$data['type'] = 'Tower';
1075
+				} elseif ($typec == 'OBS') {
1076
+					$data['type'] = 'Observer';
1077
+				} elseif ($typec == 'GND') {
1078
+					$data['type'] = 'Ground';
1079
+				} elseif ($typec == 'DEL') {
1080
+					$data['type'] = 'Delivery';
1081
+				} elseif ($typec == 'DEP') {
1082
+					$data['type'] = 'Departure';
1083
+				} elseif ($typec == 'FSS') {
1084
+					$data['type'] = 'Flight Service Station';
1085
+				} elseif ($typec == 'CTR') {
1086
+					$data['type'] = 'Control Radar or Centre';
1087
+				} elseif ($data['type'] == '') {
1088
+					$data['type'] = 'Observer';
1089
+				}
1090
+				if (!isset($data['source_name'])) {
1091
+					$data['source_name'] = '';
1092
+				}
804 1093
 				if (isset($ATC)) {
805
-					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']);
806
-					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']);
1094
+					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) {
1095
+						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']);
1096
+					} else {
1097
+						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']);
1098
+					}
807 1099
 				}
808 1100
 			}
809 1101
     			unset($data);
@@ -830,14 +1122,20 @@  discard block
 block discarded – undo
830 1122
 			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
831 1123
 			$data['latitude'] = (float)$line['pktLatitude'];
832 1124
 			$data['longitude'] = (float)$line['pktLongitude'];
833
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
834
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
1125
+			if ((float)$line['pktTrack'] != 0) {
1126
+				$data['heading'] = (float)$line['pktTrack'];
1127
+			}
1128
+			if ((int)$line['pktSpeed'] != 0) {
1129
+				$data['speed'] = (int)$line['pktSpeed'];
1130
+			}
835 1131
 			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
836 1132
 			$data['altitude_relative'] = 'AMSL';
837 1133
 			$data['pilot_id'] = (int)$line['pktPilotID'];
838 1134
 			$data['aircraft_icao'] = 'PARAGLIDER';
839 1135
 			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
840
-			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
1136
+			if (isset($pilot_data[4])) {
1137
+				$data['pilot_name'] = $pilot_data[4];
1138
+			}
841 1139
 			$data['format_source'] = $value['format'];
842 1140
 			$SI->add($data);
843 1141
 			unset($data);
@@ -885,25 +1183,59 @@  discard block
 block discarded – undo
885 1183
 		    foreach ($all_data['acList'] as $line) {
886 1184
 			$data = array();
887 1185
 			$data['hex'] = $line['Icao']; // hex
888
-			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
889
-			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
890
-			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
891
-			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
892
-			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
893
-			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1186
+			if (isset($line['Call'])) {
1187
+				$data['ident'] = $line['Call'];
1188
+			}
1189
+			// ident
1190
+			if (isset($line['Alt'])) {
1191
+				$data['altitude'] = $line['Alt'];
1192
+			}
1193
+			// altitude
1194
+			if (isset($line['Spd'])) {
1195
+				$data['speed'] = $line['Spd'];
1196
+			}
1197
+			// speed
1198
+			if (isset($line['Trak'])) {
1199
+				$data['heading'] = $line['Trak'];
1200
+			}
1201
+			// heading
1202
+			if (isset($line['Lat'])) {
1203
+				$data['latitude'] = $line['Lat'];
1204
+			}
1205
+			// lat
1206
+			if (isset($line['Long'])) {
1207
+				$data['longitude'] = $line['Long'];
1208
+			}
1209
+			// long
894 1210
 			//$data['verticalrate'] = $line['']; // verticale rate
895
-			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1211
+			if (isset($line['Sqk'])) {
1212
+				$data['squawk'] = $line['Sqk'];
1213
+			}
1214
+			// squawk
896 1215
 			$data['emergency'] = ''; // emergency
897
-			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
898
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
899
-			else $data['datetime'] = date('Y-m-d H:i:s');
1216
+			if (isset($line['Reg'])) {
1217
+				$data['registration'] = $line['Reg'];
1218
+			}
1219
+			if (isset($line['PosTime'])) {
1220
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1221
+			} else {
1222
+				$data['datetime'] = date('Y-m-d H:i:s');
1223
+			}
900 1224
 			//$data['datetime'] = date('Y-m-d H:i:s');
901
-			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1225
+			if (isset($line['Type'])) {
1226
+				$data['aircraft_icao'] = $line['Type'];
1227
+			}
902 1228
 			$data['format_source'] = 'aircraftlistjson';
903 1229
 			$data['id_source'] = $id_source;
904
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
905
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
906
-			if (isset($data['latitude'])) $SI->add($data);
1230
+			if (isset($value['name']) && $value['name'] != '') {
1231
+				$data['source_name'] = $value['name'];
1232
+			}
1233
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1234
+				$data['noarchive'] = true;
1235
+			}
1236
+			if (isset($data['latitude'])) {
1237
+				$SI->add($data);
1238
+			}
907 1239
 			unset($data);
908 1240
 		    }
909 1241
 		} elseif (is_array($all_data)) {
@@ -920,17 +1252,26 @@  discard block
 block discarded – undo
920 1252
 			$data['verticalrate'] = $line['vrt']; // verticale rate
921 1253
 			$data['squawk'] = $line['squawk']; // squawk
922 1254
 			$data['emergency'] = ''; // emergency
923
-			if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
924
-			else $data['datetime'] = date('Y-m-d H:i:s');
1255
+			if (isset($line['PosTime'])) {
1256
+				$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1257
+			} else {
1258
+				$data['datetime'] = date('Y-m-d H:i:s');
1259
+			}
925 1260
 			$data['format_source'] = 'aircraftlistjson';
926 1261
 			$data['id_source'] = $id_source;
927
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
928
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1262
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1263
+				$data['noarchive'] = true;
1264
+			}
1265
+			if (isset($value['name']) && $value['name'] != '') {
1266
+				$data['source_name'] = $value['name'];
1267
+			}
929 1268
 			$SI->add($data);
930 1269
 			unset($data);
931 1270
 		    }
932 1271
 		}
933
-	    } elseif ($globalDebug) echo 'No data'."\n";
1272
+	    } elseif ($globalDebug) {
1273
+	    	echo 'No data'."\n";
1274
+	    }
934 1275
     	    //$last_exec['aircraftlistjson'] = time();
935 1276
     	    $last_exec[$id]['last'] = time();
936 1277
     	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
@@ -966,8 +1307,12 @@  discard block
 block discarded – undo
966 1307
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
967 1308
 	    	    $data['format_source'] = 'planeupdatefaa';
968 1309
     		    $data['id_source'] = $id_source;
969
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
970
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1310
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1311
+		    	$data['noarchive'] = true;
1312
+		    }
1313
+		    if (isset($value['name']) && $value['name'] != '') {
1314
+		    	$data['source_name'] = $value['name'];
1315
+		    }
971 1316
 		    $SI->add($data);
972 1317
 		    unset($data);
973 1318
 		}
@@ -1001,7 +1346,9 @@  discard block
 block discarded – undo
1001 1346
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
1002 1347
 		    $data['format_source'] = 'opensky';
1003 1348
 		    $data['id_source'] = $id_source;
1004
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1349
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1350
+		    	$data['noarchive'] = true;
1351
+		    }
1005 1352
 		    $SI->add($data);
1006 1353
 		    unset($data);
1007 1354
 		}
@@ -1018,7 +1365,9 @@  discard block
 block discarded – undo
1018 1365
 	    //$buffer = $Common->getData($hosts[$id]);
1019 1366
 	    $buffer = $Common->getData($value['host']);
1020 1367
 	    $all_data = json_decode($buffer,true);
1021
-	    if (!empty($all_data)) $reset = 0;
1368
+	    if (!empty($all_data)) {
1369
+	    	$reset = 0;
1370
+	    }
1022 1371
 	    foreach ($all_data as $key => $line) {
1023 1372
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
1024 1373
 		    $data = array();
@@ -1039,8 +1388,12 @@  discard block
 block discarded – undo
1039 1388
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
1040 1389
 	    	    $data['format_source'] = 'fr24json';
1041 1390
     		    $data['id_source'] = $id_source;
1042
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1043
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1391
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1392
+		    	$data['noarchive'] = true;
1393
+		    }
1394
+		    if (isset($value['name']) && $value['name'] != '') {
1395
+		    	$data['source_name'] = $value['name'];
1396
+		    }
1044 1397
 		    $SI->add($data);
1045 1398
 		    unset($data);
1046 1399
 		}
@@ -1069,24 +1422,42 @@  discard block
 block discarded – undo
1069 1422
 		    if (isset($line['inf'])) {
1070 1423
 			$data = array();
1071 1424
 			$data['hex'] = $line['inf']['ia'];
1072
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1425
+			if (isset($line['inf']['cs'])) {
1426
+				$data['ident'] = $line['inf']['cs'];
1427
+			}
1428
+			//$line[13]
1073 1429
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
1074
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
1075
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1430
+	    		if (isset($line['inf']['gs'])) {
1431
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1432
+	    		}
1433
+	    		// speed
1434
+	    		if (isset($line['inf']['tr'])) {
1435
+	    			$data['heading'] = $line['inf']['tr'];
1436
+	    		}
1437
+	    		// heading
1076 1438
 	    		$data['latitude'] = $line['pt'][0]; // lat
1077 1439
 	    		$data['longitude'] = $line['pt'][1]; // long
1078 1440
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
1079
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1441
+	    		if (isset($line['inf']['sq'])) {
1442
+	    			$data['squawk'] = $line['inf']['sq'];
1443
+	    		}
1444
+	    		// squawk
1080 1445
 	    		//$data['aircraft_icao'] = $line[8];
1081
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1446
+	    		if (isset($line['inf']['rc'])) {
1447
+	    			$data['registration'] = $line['inf']['rc'];
1448
+	    		}
1082 1449
 			//$data['departure_airport_iata'] = $line[11];
1083 1450
 			//$data['arrival_airport_iata'] = $line[12];
1084 1451
 	    		//$data['emergency'] = ''; // emergency
1085 1452
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
1086 1453
 	    		$data['format_source'] = 'radarvirtueljson';
1087 1454
     			$data['id_source'] = $id_source;
1088
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1089
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1455
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1456
+				$data['noarchive'] = true;
1457
+			}
1458
+			if (isset($value['name']) && $value['name'] != '') {
1459
+				$data['source_name'] = $value['name'];
1460
+			}
1090 1461
 			$SI->add($data);
1091 1462
 			unset($data);
1092 1463
 		    }
@@ -1112,30 +1483,65 @@  discard block
 block discarded – undo
1112 1483
 		    $data['id'] = $line['id'];
1113 1484
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
1114 1485
 		    $data['ident'] = $line['callsign']; // ident
1115
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
1116
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
1117
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
1118
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
1119
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
1120
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1486
+		    if (isset($line['pilotid'])) {
1487
+		    	$data['pilot_id'] = $line['pilotid'];
1488
+		    }
1489
+		    // pilot id
1490
+		    if (isset($line['name'])) {
1491
+		    	$data['pilot_name'] = $line['name'];
1492
+		    }
1493
+		    // pilot name
1494
+		    if (isset($line['alt'])) {
1495
+		    	$data['altitude'] = $line['alt'];
1496
+		    }
1497
+		    // altitude
1498
+		    if (isset($line['gs'])) {
1499
+		    	$data['speed'] = $line['gs'];
1500
+		    }
1501
+		    // speed
1502
+		    if (isset($line['heading'])) {
1503
+		    	$data['heading'] = $line['heading'];
1504
+		    }
1505
+		    // heading
1506
+		    if (isset($line['route'])) {
1507
+		    	$data['waypoints'] = $line['route'];
1508
+		    }
1509
+		    // route
1121 1510
 		    $data['latitude'] = $line['lat']; // lat
1122 1511
 		    $data['longitude'] = $line['lon']; // long
1123 1512
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
1124 1513
 		    //$data['squawk'] = $line['squawk']; // squawk
1125 1514
 		    //$data['emergency'] = ''; // emergency
1126
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
1127
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
1128
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1515
+		    if (isset($line['depicao'])) {
1516
+		    	$data['departure_airport_icao'] = $line['depicao'];
1517
+		    }
1518
+		    if (isset($line['deptime'])) {
1519
+		    	$data['departure_airport_time'] = $line['deptime'];
1520
+		    }
1521
+		    if (isset($line['arricao'])) {
1522
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1523
+		    }
1129 1524
 		    //$data['arrival_airport_time'] = $line['arrtime'];
1130
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
1131
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
1132
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
1133
-		    else $data['info'] = '';
1525
+		    if (isset($line['aircraft'])) {
1526
+		    	$data['aircraft_icao'] = $line['aircraft'];
1527
+		    }
1528
+		    if (isset($line['transponder'])) {
1529
+		    	$data['squawk'] = $line['transponder'];
1530
+		    }
1531
+		    if (isset($line['atis'])) {
1532
+		    	$data['info'] = $line['atis'];
1533
+		    } else {
1534
+		    	$data['info'] = '';
1535
+		    }
1134 1536
 		    $data['format_source'] = 'pireps';
1135 1537
     		    $data['id_source'] = $id_source;
1136 1538
 		    $data['datetime'] = date('Y-m-d H:i:s');
1137
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1138
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1539
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1540
+		    	$data['noarchive'] = true;
1541
+		    }
1542
+		    if (isset($value['name']) && $value['name'] != '') {
1543
+		    	$data['source_name'] = $value['name'];
1544
+		    }
1139 1545
 		    if ($line['icon'] == 'plane') {
1140 1546
 			$SI->add($data);
1141 1547
 		    //    print_r($data);
@@ -1144,16 +1550,28 @@  discard block
 block discarded – undo
1144 1550
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1145 1551
 			$typec = substr($data['ident'],-3);
1146 1552
 			$data['type'] = '';
1147
-			if ($typec == 'APP') $data['type'] = 'Approach';
1148
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
1149
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
1150
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
1151
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
1152
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
1153
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
1154
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
1155
-			else $data['type'] = 'Observer';
1156
-			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']);
1553
+			if ($typec == 'APP') {
1554
+				$data['type'] = 'Approach';
1555
+			} elseif ($typec == 'TWR') {
1556
+				$data['type'] = 'Tower';
1557
+			} elseif ($typec == 'OBS') {
1558
+				$data['type'] = 'Observer';
1559
+			} elseif ($typec == 'GND') {
1560
+				$data['type'] = 'Ground';
1561
+			} elseif ($typec == 'DEL') {
1562
+				$data['type'] = 'Delivery';
1563
+			} elseif ($typec == 'DEP') {
1564
+				$data['type'] = 'Departure';
1565
+			} elseif ($typec == 'FSS') {
1566
+				$data['type'] = 'Flight Service Station';
1567
+			} elseif ($typec == 'CTR') {
1568
+				$data['type'] = 'Control Radar or Centre';
1569
+			} else {
1570
+				$data['type'] = 'Observer';
1571
+			}
1572
+			if (isset($ATC)) {
1573
+				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']);
1574
+			}
1157 1575
 		    }
1158 1576
 		    unset($data);
1159 1577
 		}
@@ -1168,7 +1586,9 @@  discard block
 block discarded – undo
1168 1586
 	    )
1169 1587
 	) {
1170 1588
 	    //$buffer = $Common->getData($hosts[$id]);
1171
-	    if ($globalDebug) echo 'Get Data...'."\n";
1589
+	    if ($globalDebug) {
1590
+	    	echo 'Get Data...'."\n";
1591
+	    }
1172 1592
 	    $buffer = $Common->getData($value['host']);
1173 1593
 	    $all_data = json_decode($buffer,true);
1174 1594
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1176,10 +1596,16 @@  discard block
 block discarded – undo
1176 1596
 		foreach ($all_data as $line) {
1177 1597
 	    	    $data = array();
1178 1598
 	    	    //$data['id'] = $line['id']; // id not usable
1179
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1599
+	    	    if (isset($line['pilotid'])) {
1600
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1601
+	    	    }
1180 1602
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1181
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1182
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1603
+	    	    if (isset($line['pilotname'])) {
1604
+	    	    	$data['pilot_name'] = $line['pilotname'];
1605
+	    	    }
1606
+	    	    if (isset($line['pilotid'])) {
1607
+	    	    	$data['pilot_id'] = $line['pilotid'];
1608
+	    	    }
1183 1609
 	    	    $data['ident'] = $line['flightnum']; // ident
1184 1610
 	    	    $data['altitude'] = $line['alt']; // altitude
1185 1611
 	    	    $data['speed'] = $line['gs']; // speed
@@ -1195,7 +1621,9 @@  discard block
 block discarded – undo
1195 1621
 	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1196 1622
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1197 1623
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1198
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1624
+	    	    } else {
1625
+	    	    	$data['datetime'] = date('Y-m-d H:i:s');
1626
+	    	    }
1199 1627
 	    	    $data['departure_airport_icao'] = $line['depicao'];
1200 1628
 	    	    $data['departure_airport_time'] = $line['deptime'];
1201 1629
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
@@ -1203,29 +1631,47 @@  discard block
 block discarded – undo
1203 1631
     		    if (isset($line['registration'])) {
1204 1632
     			$data['registration'] = $line['registration'];
1205 1633
     			//if (isset($line['aircraft'])) $data['id'] = $line['aircraft'];
1206
-    		    } else $data['registration'] = $line['aircraft'];
1207
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1208
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1634
+    		    } else {
1635
+    		    	$data['registration'] = $line['aircraft'];
1636
+    		    }
1637
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1638
+		    	$data['noarchive'] = true;
1639
+		    }
1640
+		    if (isset($line['route'])) {
1641
+		    	$data['waypoints'] = $line['route'];
1642
+		    }
1643
+		    // route
1209 1644
 		    if (isset($line['aircraftname'])) {
1210 1645
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1211 1646
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1212 1647
 	    		$aircraft_data = explode('-',$line['aircraftname']);
1213
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1214
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1215
-	    		else {
1648
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) {
1649
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1650
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) {
1651
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1652
+	    		} else {
1216 1653
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1217
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1218
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1654
+	    		    if (isset($aircraft_data[1])) {
1655
+	    		    	$data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1656
+	    		    } else {
1657
+	    		    	$data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1658
+	    		    }
1219 1659
 	    		}
1220 1660
 	    	    }
1221
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1661
+    		    if (isset($line['route'])) {
1662
+    		    	$data['waypoints'] = $line['route'];
1663
+    		    }
1222 1664
     		    $data['id_source'] = $id_source;
1223 1665
 	    	    $data['format_source'] = 'phpvmacars';
1224
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1666
+		    if (isset($value['name']) && $value['name'] != '') {
1667
+		    	$data['source_name'] = $value['name'];
1668
+		    }
1225 1669
 		    $SI->add($data);
1226 1670
 		    unset($data);
1227 1671
 		}
1228
-		if ($globalDebug) echo 'No more data...'."\n";
1672
+		if ($globalDebug) {
1673
+			echo 'No more data...'."\n";
1674
+		}
1229 1675
 		unset($buffer);
1230 1676
 		unset($all_data);
1231 1677
 	    }
@@ -1238,7 +1684,9 @@  discard block
 block discarded – undo
1238 1684
 	    )
1239 1685
 	) {
1240 1686
 	    //$buffer = $Common->getData($hosts[$id]);
1241
-	    if ($globalDebug) echo 'Get Data...'."\n";
1687
+	    if ($globalDebug) {
1688
+	    	echo 'Get Data...'."\n";
1689
+	    }
1242 1690
 	    $buffer = $Common->getData($value['host']);
1243 1691
 	    $all_data = json_decode($buffer,true);
1244 1692
 	    if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) {
@@ -1249,10 +1697,16 @@  discard block
 block discarded – undo
1249 1697
 	    	    //$data['id'] = $line['id']; // id not usable
1250 1698
 	    	    $data['id'] = $line['id'];
1251 1699
 	    	    //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1252
-	    	    if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username'];
1253
-	    	    if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id'];
1700
+	    	    if (isset($line['user']['username'])) {
1701
+	    	    	$data['pilot_name'] = $line['user']['username'];
1702
+	    	    }
1703
+	    	    if (isset($line['user_id'])) {
1704
+	    	    	$data['pilot_id'] = $line['user_id'];
1705
+	    	    }
1254 1706
 	    	    $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident
1255
-	    	    if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1707
+	    	    if (is_numeric($data['ident'])) {
1708
+	    	    	$data['ident'] = $line['bid']['airline']['icao'].$data['ident'];
1709
+	    	    }
1256 1710
 	    	    $data['altitude'] = $line['altitude']; // altitude
1257 1711
 	    	    $data['speed'] = $line['groundspeed']; // speed
1258 1712
 	    	    $data['heading'] = $line['heading']; // heading
@@ -1265,7 +1719,9 @@  discard block
 block discarded – undo
1265 1719
 	    		$datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone']));
1266 1720
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1267 1721
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1268
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1722
+	    	    } else {
1723
+	    	    	$data['datetime'] = date('Y-m-d H:i:s');
1724
+	    	    }
1269 1725
 	    	    
1270 1726
 	    	    $data['departure_airport_icao'] = $line['bid']['depapt']['icao'];
1271 1727
 	    	    $data['departure_airport_time'] = $line['bid']['deptime'];
@@ -1273,17 +1729,26 @@  discard block
 block discarded – undo
1273 1729
 		    $data['arrival_airport_time'] = $line['bid']['arrtime'];
1274 1730
 		    $data['registration'] = $line['bid']['aircraft']['registration'];
1275 1731
 
1276
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1277
-		    if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route
1732
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1733
+		    	$data['noarchive'] = true;
1734
+		    }
1735
+		    if (isset($line['bid']['route']) && $line['bid']['route'] != '') {
1736
+		    	$data['waypoints'] = $line['bid']['route'];
1737
+		    }
1738
+		    // route
1278 1739
 	    	    $data['aircraft_icao'] = $line['bid']['aircraft']['icao'];
1279 1740
 
1280 1741
     		    $data['id_source'] = $id_source;
1281 1742
 	    	    $data['format_source'] = 'vaos';
1282
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1743
+		    if (isset($value['name']) && $value['name'] != '') {
1744
+		    	$data['source_name'] = $value['name'];
1745
+		    }
1283 1746
 		    $SI->add($data);
1284 1747
 		    unset($data);
1285 1748
 		}
1286
-		if ($globalDebug) echo 'No more data...'."\n";
1749
+		if ($globalDebug) {
1750
+			echo 'No more data...'."\n";
1751
+		}
1287 1752
 		unset($buffer);
1288 1753
 		unset($all_data);
1289 1754
 	    }
@@ -1296,7 +1761,9 @@  discard block
 block discarded – undo
1296 1761
 	    )
1297 1762
 	) {
1298 1763
 	    //$buffer = $Common->getData($hosts[$id]);
1299
-	    if ($globalDebug) echo 'Get Data...'."\n";
1764
+	    if ($globalDebug) {
1765
+	    	echo 'Get Data...'."\n";
1766
+	    }
1300 1767
 	    $buffer = $Common->getData($value['host']);
1301 1768
 	    $all_data = json_decode($buffer,true);
1302 1769
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1325,16 +1792,25 @@  discard block
 block discarded – undo
1325 1792
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
1326 1793
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
1327 1794
     		    //$data['registration'] = $line['aircraft'];
1328
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1795
+		    if (isset($line['route'])) {
1796
+		    	$data['waypoints'] = $line['route'];
1797
+		    }
1798
+		    // route
1329 1799
 	    	    $data['aircraft_icao'] = $line['plane_type'];
1330 1800
     		    $data['id_source'] = $id_source;
1331 1801
 	    	    $data['format_source'] = 'vam';
1332
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1333
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1802
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1803
+		    	$data['noarchive'] = true;
1804
+		    }
1805
+		    if (isset($value['name']) && $value['name'] != '') {
1806
+		    	$data['source_name'] = $value['name'];
1807
+		    }
1334 1808
 		    $SI->add($data);
1335 1809
 		    unset($data);
1336 1810
 		}
1337
-		if ($globalDebug) echo 'No more data...'."\n";
1811
+		if ($globalDebug) {
1812
+			echo 'No more data...'."\n";
1813
+		}
1338 1814
 		unset($buffer);
1339 1815
 		unset($all_data);
1340 1816
 	    }
@@ -1347,7 +1823,9 @@  discard block
 block discarded – undo
1347 1823
 	    )
1348 1824
 	) {
1349 1825
 	    //$buffer = $Common->getData($hosts[$id]);
1350
-	    if ($globalDebug) echo 'Get Data...'."\n";
1826
+	    if ($globalDebug) {
1827
+	    	echo 'Get Data...'."\n";
1828
+	    }
1351 1829
 	    $buffer = $Common->getData($value['host']);
1352 1830
 	    $all_data = json_decode($buffer,true);
1353 1831
 	    if ($buffer != '') {
@@ -1365,18 +1843,24 @@  discard block
 block discarded – undo
1365 1843
 			$data['id_source'] = $id_source;
1366 1844
 			$data['format_source'] = 'blitzortung';
1367 1845
 			$SI->add($data);
1368
-			if ($globalDebug) echo '☈ Lightning added'."\n";
1846
+			if ($globalDebug) {
1847
+				echo '☈ Lightning added'."\n";
1848
+			}
1369 1849
 			$Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']);
1370 1850
 			unset($data);
1371 1851
 		    }
1372 1852
 		}
1373
-		if ($globalDebug) echo 'No more data...'."\n";
1853
+		if ($globalDebug) {
1854
+			echo 'No more data...'."\n";
1855
+		}
1374 1856
 		unset($buffer);
1375 1857
 	    }
1376 1858
 	    $last_exec[$id]['last'] = time();
1377 1859
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1378 1860
 	} 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') {
1379
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1861
+	    if (function_exists('pcntl_fork')) {
1862
+	    	pcntl_signal_dispatch();
1863
+	    }
1380 1864
     	    //$last_exec[$id]['last'] = time();
1381 1865
 
1382 1866
 	    //$read = array( $sockets[$id] );
@@ -1384,7 +1868,9 @@  discard block
 block discarded – undo
1384 1868
 	    $write = NULL;
1385 1869
 	    $e = NULL;
1386 1870
 	    $n = socket_select($read, $write, $e, $timeout);
1387
-	    if ($e != NULL) var_dump($e);
1871
+	    if ($e != NULL) {
1872
+	    	var_dump($e);
1873
+	    }
1388 1874
 	    if ($n > 0) {
1389 1875
 		$reset = 0;
1390 1876
 		foreach ($read as $nb => $r) {
@@ -1406,13 +1892,17 @@  discard block
 block discarded – undo
1406 1892
 		    if ($buffer !== FALSE) {
1407 1893
 			if ($format == 'vrstcp') {
1408 1894
 			    $buffer = explode('},{',$buffer);
1409
-			} else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1895
+			} else {
1896
+				$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1897
+			}
1410 1898
 		    }
1411 1899
 		    // SBS format is CSV format
1412 1900
 		    if ($buffer !== FALSE && $buffer !== '') {
1413 1901
 			$tt[$format] = 0;
1414 1902
 			if ($format == 'acarssbs3') {
1415
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1903
+			    if ($globalDebug) {
1904
+			    	echo 'ACARS : '.$buffer."\n";
1905
+			    }
1416 1906
 			    $ACARS->add(trim($buffer));
1417 1907
 			    $ACARS->deleteLiveAcarsData();
1418 1908
 			} elseif ($format == 'raw') {
@@ -1421,30 +1911,70 @@  discard block
 block discarded – undo
1421 1911
 			    if (is_array($data)) {
1422 1912
 				$data['datetime'] = date('Y-m-d H:i:s');
1423 1913
 				$data['format_source'] = 'raw';
1424
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1425
-				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1426
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1427
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1914
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1915
+					$data['source_name'] = $globalSources[$nb]['name'];
1916
+				}
1917
+				if (isset($globalSources[$nb]['sourcestats'])) {
1918
+					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1919
+				}
1920
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1921
+					$data['noarchive'] = true;
1922
+				}
1923
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1924
+					$SI->add($data);
1925
+				}
1428 1926
 			    }
1429 1927
 			} elseif ($format == 'ais') {
1430 1928
 			    $ais_data = $AIS->parse_line(trim($buffer));
1431 1929
 			    $data = array();
1432
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1433
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9);
1434
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1435
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1436
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1437
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1438
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1439
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1440
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1441
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1442
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1443
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1444
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1445
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1446
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1447
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1930
+			    if (isset($ais_data['ident'])) {
1931
+			    	$data['ident'] = $ais_data['ident'];
1932
+			    }
1933
+			    if (isset($ais_data['mmsi'])) {
1934
+			    	$data['mmsi'] = substr($ais_data['mmsi'],-9);
1935
+			    }
1936
+			    if (isset($ais_data['speed'])) {
1937
+			    	$data['speed'] = $ais_data['speed'];
1938
+			    }
1939
+			    if (isset($ais_data['heading'])) {
1940
+			    	$data['heading'] = $ais_data['heading'];
1941
+			    }
1942
+			    if (isset($ais_data['latitude'])) {
1943
+			    	$data['latitude'] = $ais_data['latitude'];
1944
+			    }
1945
+			    if (isset($ais_data['longitude'])) {
1946
+			    	$data['longitude'] = $ais_data['longitude'];
1947
+			    }
1948
+			    if (isset($ais_data['status'])) {
1949
+			    	$data['status'] = $ais_data['status'];
1950
+			    }
1951
+			    if (isset($ais_data['statusid'])) {
1952
+			    	$data['status_id'] = $ais_data['statusid'];
1953
+			    }
1954
+			    if (isset($ais_data['type'])) {
1955
+			    	$data['type'] = $ais_data['type'];
1956
+			    }
1957
+			    if (isset($ais_data['imo'])) {
1958
+			    	$data['imo'] = $ais_data['imo'];
1959
+			    }
1960
+			    if (isset($ais_data['callsign'])) {
1961
+			    	$data['callsign'] = $ais_data['callsign'];
1962
+			    }
1963
+			    if (isset($ais_data['destination'])) {
1964
+			    	$data['arrival_code'] = $ais_data['destination'];
1965
+			    }
1966
+			    if (isset($ais_data['eta_ts'])) {
1967
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1968
+			    }
1969
+			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1970
+			    	$data['noarchive'] = true;
1971
+			    }
1972
+			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1973
+			    	$data['source_name'] = $globalSources[$nb]['name'];
1974
+			    }
1975
+			    if (isset($globalSources[$nb]['sourcestats'])) {
1976
+			    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1977
+			    }
1448 1978
 
1449 1979
 			    if (isset($ais_data['timestamp'])) {
1450 1980
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1453,7 +1983,9 @@  discard block
 block discarded – undo
1453 1983
 			    }
1454 1984
 			    $data['format_source'] = 'aisnmea';
1455 1985
     			    $data['id_source'] = $id_source;
1456
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1986
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
1987
+			    	$MI->add($data);
1988
+			    }
1457 1989
 			    unset($data);
1458 1990
                         } elseif ($format == 'flightgearsp') {
1459 1991
                     	    //echo $buffer."\n";
@@ -1471,12 +2003,18 @@  discard block
 block discarded – undo
1471 2003
 				$data['speed'] = round($line[5]*1.94384);
1472 2004
 				$data['datetime'] = date('Y-m-d H:i:s');
1473 2005
 				$data['format_source'] = 'flightgearsp';
1474
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1475
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2006
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2007
+					$data['noarchive'] = true;
2008
+				}
2009
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2010
+					$SI->add($data);
2011
+				}
1476 2012
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1477 2013
 			    }
1478 2014
                         } elseif ($format == 'acars') {
1479
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
2015
+                    	    if ($globalDebug) {
2016
+                    	    	echo 'ACARS : '.$buffer."\n";
2017
+                    	    }
1480 2018
 			    $ACARS->add(trim($buffer));
1481 2019
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1482 2020
 			    $ACARS->deleteLiveAcarsData();
@@ -1497,8 +2035,12 @@  discard block
 block discarded – undo
1497 2035
 				    $aircraft_type = $line[10];
1498 2036
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1499 2037
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1500
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1501
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2038
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2039
+				    	$data['noarchive'] = true;
2040
+				    }
2041
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2042
+				    	$SI->add($data);
2043
+				    }
1502 2044
 				}
1503 2045
 			    }
1504 2046
 			} elseif ($format == 'beast') {
@@ -1508,28 +2050,62 @@  discard block
 block discarded – undo
1508 2050
 			    foreach($buffer as $all_data) {
1509 2051
 				$line = json_decode('{'.$all_data.'}',true);
1510 2052
 				$data = array();
1511
-				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1512
-				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1513
-				if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1514
-				if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1515
-				if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1516
-				if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1517
-				if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
2053
+				if (isset($line['Icao'])) {
2054
+					$data['hex'] = $line['Icao'];
2055
+				}
2056
+				// hex
2057
+				if (isset($line['Call'])) {
2058
+					$data['ident'] = $line['Call'];
2059
+				}
2060
+				// ident
2061
+				if (isset($line['Alt'])) {
2062
+					$data['altitude'] = $line['Alt'];
2063
+				}
2064
+				// altitude
2065
+				if (isset($line['Spd'])) {
2066
+					$data['speed'] = $line['Spd'];
2067
+				}
2068
+				// speed
2069
+				if (isset($line['Trak'])) {
2070
+					$data['heading'] = $line['Trak'];
2071
+				}
2072
+				// heading
2073
+				if (isset($line['Lat'])) {
2074
+					$data['latitude'] = $line['Lat'];
2075
+				}
2076
+				// lat
2077
+				if (isset($line['Long'])) {
2078
+					$data['longitude'] = $line['Long'];
2079
+				}
2080
+				// long
1518 2081
 				//$data['verticalrate'] = $line['']; // verticale rate
1519
-				if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
2082
+				if (isset($line['Sqk'])) {
2083
+					$data['squawk'] = $line['Sqk'];
2084
+				}
2085
+				// squawk
1520 2086
 				$data['emergency'] = ''; // emergency
1521
-				if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
2087
+				if (isset($line['Reg'])) {
2088
+					$data['registration'] = $line['Reg'];
2089
+				}
1522 2090
 				/*
1523 2091
 				if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
1524 2092
 				else $data['datetime'] = date('Y-m-d H:i:s');
1525 2093
 				*/
1526 2094
 				$data['datetime'] = date('Y-m-d H:i:s');
1527
-				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
2095
+				if (isset($line['Type'])) {
2096
+					$data['aircraft_icao'] = $line['Type'];
2097
+				}
1528 2098
 		    		$data['format_source'] = 'vrstcp';
1529 2099
 				$data['id_source'] = $id_source;
1530
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1531
-				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1532
-				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
2100
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2101
+					$data['noarchive'] = true;
2102
+				}
2103
+				if (isset($value['name']) && $value['name'] != '') {
2104
+					$data['source_name'] = $value['name'];
2105
+				}
2106
+				if (isset($data['latitude']) && isset($data['hex'])) {
2107
+					$SI->add($data);
2108
+				}
1533 2109
 				unset($data);
1534 2110
 			    }
1535 2111
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
@@ -1542,22 +2118,46 @@  discard block
 block discarded – undo
1542 2118
     				$data['hex'] = $lined['hexid'];
1543 2119
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1544 2120
     				$data['datetime'] = date('Y-m-d H:i:s');;
1545
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1546
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1547
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1548
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1549
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1550
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1551
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
2121
+    				if (isset($lined['ident'])) {
2122
+    					$data['ident'] = $lined['ident'];
2123
+    				}
2124
+    				if (isset($lined['lat'])) {
2125
+    					$data['latitude'] = $lined['lat'];
2126
+    				}
2127
+    				if (isset($lined['lon'])) {
2128
+    					$data['longitude'] = $lined['lon'];
2129
+    				}
2130
+    				if (isset($lined['speed'])) {
2131
+    					$data['speed'] = $lined['speed'];
2132
+    				}
2133
+    				if (isset($lined['squawk'])) {
2134
+    					$data['squawk'] = $lined['squawk'];
2135
+    				}
2136
+    				if (isset($lined['alt'])) {
2137
+    					$data['altitude'] = $lined['alt'];
2138
+    				}
2139
+    				if (isset($lined['heading'])) {
2140
+    					$data['heading'] = $lined['heading'];
2141
+    				}
1552 2142
     				$data['id_source'] = $id_source;
1553 2143
     				$data['format_source'] = 'tsv';
1554
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1555
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1556
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1557
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
2144
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2145
+    					$data['source_name'] = $globalSources[$nb]['name'];
2146
+    				}
2147
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2148
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2149
+    				}
2150
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2151
+					$data['noarchive'] = true;
2152
+				}
2153
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2154
+    					$SI->add($data);
2155
+    				}
1558 2156
     				unset($lined);
1559 2157
     				unset($data);
1560
-    			    } else $error = true;
2158
+    			    } else {
2159
+    			    	$error = true;
2160
+    			    }
1561 2161
 			} elseif ($format == 'aprs' && $use_aprs) {
1562 2162
 			    if ($aprs_connect == 0) {
1563 2163
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1583,63 +2183,121 @@  discard block
 block discarded – undo
1583 2183
 				    $aprs_last_tx = time();
1584 2184
 				    $data = array();
1585 2185
 				    //print_r($line);
1586
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1587
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1588
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1589
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1590
-				    if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code'];
1591
-				    if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date'];
1592
-				    if (isset($line['typeid'])) $data['type_id'] = $line['typeid'];
1593
-				    if (isset($line['statusid'])) $data['status_id'] = $line['statusid'];
1594
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1595
-				    else $data['datetime'] = date('Y-m-d H:i:s');
2186
+				    if (isset($line['address'])) {
2187
+				    	$data['hex'] = $line['address'];
2188
+				    }
2189
+				    if (isset($line['mmsi'])) {
2190
+				    	$data['mmsi'] = $line['mmsi'];
2191
+				    }
2192
+				    if (isset($line['imo'])) {
2193
+				    	$data['imo'] = $line['imo'];
2194
+				    }
2195
+				    if (isset($line['squawk'])) {
2196
+				    	$data['squawk'] = $line['squawk'];
2197
+				    }
2198
+				    if (isset($line['arrival_code'])) {
2199
+				    	$data['arrival_code'] = $line['arrival_code'];
2200
+				    }
2201
+				    if (isset($line['arrival_date'])) {
2202
+				    	$data['arrival_date'] = $line['arrival_date'];
2203
+				    }
2204
+				    if (isset($line['typeid'])) {
2205
+				    	$data['type_id'] = $line['typeid'];
2206
+				    }
2207
+				    if (isset($line['statusid'])) {
2208
+				    	$data['status_id'] = $line['statusid'];
2209
+				    }
2210
+				    if (isset($line['timestamp'])) {
2211
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
2212
+				    } else {
2213
+				    	$data['datetime'] = date('Y-m-d H:i:s');
2214
+				    }
1596 2215
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1597
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
2216
+				    if (isset($line['ident'])) {
2217
+				    	$data['ident'] = $line['ident'];
2218
+				    }
1598 2219
 				    $data['latitude'] = $line['latitude'];
1599 2220
 				    $data['longitude'] = $line['longitude'];
1600 2221
 				    //$data['verticalrate'] = $line[16];
1601
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
2222
+				    if (isset($line['speed'])) {
2223
+				    	$data['speed'] = $line['speed'];
2224
+				    }
1602 2225
 				    //else $data['speed'] = 0;
1603
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1604
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1605
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
2226
+				    if (isset($line['altitude'])) {
2227
+				    	$data['altitude'] = $line['altitude'];
2228
+				    }
2229
+				    if (isset($line['comment'])) {
2230
+				    	$data['comment'] = $line['comment'];
2231
+				    }
2232
+				    if (isset($line['symbol'])) {
2233
+				    	$data['type'] = $line['symbol'];
2234
+				    }
1606 2235
 				    //if (isset($line['heading'])) $data['heading'] = $line['heading'];
1607 2236
 				    
1608
-				    if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading'];
2237
+				    if (isset($line['heading']) && isset($line['format_source'])) {
2238
+				    	$data['heading'] = $line['heading'];
2239
+				    }
1609 2240
 				    //else echo 'No heading...'."\n";
1610 2241
 				    //else $data['heading'] = 0;
1611
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
2242
+				    if (isset($line['stealth'])) {
2243
+				    	$data['aircraft_type'] = $line['stealth'];
2244
+				    }
1612 2245
 				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1613
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1614
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1615
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1616
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
2246
+				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) {
2247
+				    	$data['noarchive'] = true;
2248
+				    } elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) {
2249
+				    	$data['noarchive'] = false;
2250
+				    }
2251
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2252
+				    	$data['noarchive'] = true;
2253
+				    } elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) {
2254
+				    	$data['noarchive'] = false;
2255
+				    }
1617 2256
     				    $data['id_source'] = $id_source;
1618
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1619
-				    else $data['format_source'] = 'aprs';
2257
+    				    if (isset($line['format_source'])) {
2258
+    				    	$data['format_source'] = $line['format_source'];
2259
+    				    } else {
2260
+				    	$data['format_source'] = 'aprs';
2261
+				    }
1620 2262
 				    $data['source_name'] = $line['source'];
1621
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1622
-				    else $data['source_type'] = 'flarm';
1623
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2263
+				    if (isset($line['source_type'])) {
2264
+				    	$data['source_type'] = $line['source_type'];
2265
+				    } else {
2266
+				    	$data['source_type'] = 'flarm';
2267
+				    }
2268
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
2269
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2270
+    				    }
1624 2271
 				    $currentdate = date('Y-m-d H:i:s');
1625 2272
 				    $aprsdate = strtotime($data['datetime']);
1626
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
2273
+				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') {
2274
+				    	$data['altitude_relative'] = 'AMSL';
2275
+				    }
1627 2276
 				    // Accept data if time <= system time + 20s
1628 2277
 				    //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'])))) {
1629 2278
 				    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'])))) {
1630 2279
 					$send = $SI->add($data);
1631 2280
 				    } elseif ($data['source_type'] == 'ais') {
1632 2281
 					$data['type'] = '';
1633
-					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
2282
+					if (isset($globalMarine) && $globalMarine) {
2283
+						$send = $MI->add($data);
2284
+					}
1634 2285
 				    } elseif (isset($line['stealth'])) {
1635
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1636
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
2286
+					if ($line['stealth'] != 0) {
2287
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
2288
+					} else {
2289
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
2290
+					}
1637 2291
 				    } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1638 2292
 					    //$line['symbol'] == 'Balloon' ||
1639 2293
 					    $line['symbol'] == 'Glider' || 
1640 2294
 					    $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1641
-					    if ($line['symbol'] == 'Ballon') $data['aircraft_icao'] = 'BALL';
1642
-					    if ($line['symbol'] == 'Glider') $data['aircraft_icao'] = 'PARAGLIDER';
2295
+					    if ($line['symbol'] == 'Ballon') {
2296
+					    	$data['aircraft_icao'] = 'BALL';
2297
+					    }
2298
+					    if ($line['symbol'] == 'Glider') {
2299
+					    	$data['aircraft_icao'] = 'PARAGLIDER';
2300
+					    }
1643 2301
 					    $send = $SI->add($data);
1644 2302
 				    } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1645 2303
 					    $line['symbol'] == 'Yacht (Sail)' || 
@@ -1670,9 +2328,13 @@  discard block
 block discarded – undo
1670 2328
 				    //} 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') {
1671 2329
 				//    } 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') {
1672 2330
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1673
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
2331
+					if (isset($globalTracker) && $globalTracker) {
2332
+						$send = $TI->add($data);
2333
+					}
1674 2334
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1675
-					if (!isset($data['altitude'])) $data['altitude'] = 0;
2335
+					if (!isset($data['altitude'])) {
2336
+						$data['altitude'] = 0;
2337
+					}
1676 2338
 					$Source->deleteOldLocationByType('gs');
1677 2339
 					if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) {
1678 2340
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
@@ -1681,7 +2343,9 @@  discard block
 block discarded – undo
1681 2343
 					}
1682 2344
 				    } elseif (isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1683 2345
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1684
-					if ($globalDebug) echo '# Weather Station added'."\n";
2346
+					if ($globalDebug) {
2347
+						echo '# Weather Station added'."\n";
2348
+					}
1685 2349
 					$Source->deleteOldLocationByType('wx');
1686 2350
 					$weather_data = json_encode($line);
1687 2351
 					if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) {
@@ -1691,7 +2355,9 @@  discard block
 block discarded – undo
1691 2355
 					}
1692 2356
 				    } elseif (isset($line['symbol']) && ($line['symbol'] == 'Lightning' || $line['symbol'] == 'Thunderstorm')) {
1693 2357
 					//if ($globalDebug) echo '!! Weather Station not yet supported'."\n";
1694
-					if ($globalDebug) echo '☈ Lightning added'."\n";
2358
+					if ($globalDebug) {
2359
+						echo '☈ Lightning added'."\n";
2360
+					}
1695 2361
 					$Source->deleteOldLocationByType('lightning');
1696 2362
 					if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) {
1697 2363
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']);
@@ -1703,8 +2369,7 @@  discard block
 block discarded – undo
1703 2369
 				    	print_r($line);
1704 2370
 				    }
1705 2371
 				    unset($data);
1706
-				}
1707
-				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
2372
+				} elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1708 2373
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
1709 2374
 				}
1710 2375
 				/*
@@ -1713,7 +2378,9 @@  discard block
 block discarded – undo
1713 2378
 				}
1714 2379
 				*/
1715 2380
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1716
-				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
2381
+				elseif ($line == true && $globalDebug) {
2382
+					echo '!! Failed : '.$buffer."!!\n";
2383
+				}
1717 2384
 				if (isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) {
1718 2385
 					$Source->deleteOldLocationByType('lightning');
1719 2386
 					$Source->deleteOldLocationByType('wx');
@@ -1749,26 +2416,45 @@  discard block
 block discarded – undo
1749 2416
     				$data['ground'] = $line[21];
1750 2417
     				$data['emergency'] = $line[19];
1751 2418
     				$data['format_source'] = 'sbs';
1752
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1753
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1754
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
2419
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2420
+					$data['source_name'] = $globalSources[$nb]['name'];
2421
+				}
2422
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2423
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2424
+    				}
2425
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2426
+					$data['noarchive'] = true;
2427
+				}
1755 2428
     				$data['id_source'] = $id_source;
1756
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1757
-    				else $error = true;
2429
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2430
+    					$send = $SI->add($data);
2431
+    				} else {
2432
+    					$error = true;
2433
+    				}
1758 2434
     				unset($data);
1759
-    			    } else $error = true;
2435
+    			    } else {
2436
+    			    	$error = true;
2437
+    			    }
1760 2438
 			    if ($error) {
1761 2439
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1762
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
2440
+					if ($globalDebug) {
2441
+						echo "Not a message. Ignoring... \n";
2442
+					}
1763 2443
 				} else {
1764
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
2444
+					if ($globalDebug) {
2445
+						echo "Wrong line format. Ignoring... \n";
2446
+					}
1765 2447
 					if ($globalDebug) {
1766 2448
 						echo $buffer;
1767 2449
 						//print_r($line);
1768 2450
 					}
1769 2451
 					//socket_close($r);
1770
-					if ($globalDebug) echo "Reconnect after an error...\n";
1771
-					if ($format == 'aprs') $aprs_connect = 0;
2452
+					if ($globalDebug) {
2453
+						echo "Reconnect after an error...\n";
2454
+					}
2455
+					if ($format == 'aprs') {
2456
+						$aprs_connect = 0;
2457
+					}
1772 2458
 					$sourceer[$nb] = $globalSources[$nb];
1773 2459
 					connect_all($sourceer);
1774 2460
 					$sourceer = array();
@@ -1776,10 +2462,14 @@  discard block
 block discarded – undo
1776 2462
 			    }
1777 2463
 			}
1778 2464
 			// Sleep for xxx microseconds
1779
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
2465
+			if (isset($globalSBSSleep)) {
2466
+				usleep($globalSBSSleep);
2467
+			}
1780 2468
 		    } else {
1781 2469
 			if ($format == 'flightgearmp') {
1782
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
2470
+			    	if ($globalDebug) {
2471
+			    		echo "Reconnect FlightGear MP...";
2472
+			    	}
1783 2473
 				//@socket_close($r);
1784 2474
 				sleep($globalMinFetch);
1785 2475
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1788,10 +2478,15 @@  discard block
 block discarded – undo
1788 2478
 				break;
1789 2479
 				
1790 2480
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1791
-			    if (isset($tt[$format])) $tt[$format]++;
1792
-			    else $tt[$format] = 0;
2481
+			    if (isset($tt[$format])) {
2482
+			    	$tt[$format]++;
2483
+			    } else {
2484
+			    	$tt[$format] = 0;
2485
+			    }
1793 2486
 			    if ($tt[$format] > 30 || $buffer === FALSE) {
1794
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
2487
+				if ($globalDebug) {
2488
+					echo "ERROR : Reconnect ".$format."...";
2489
+				}
1795 2490
 				//@socket_close($r);
1796 2491
 				sleep(2);
1797 2492
 				$aprs_connect = 0;
@@ -1809,11 +2504,17 @@  discard block
 block discarded – undo
1809 2504
 	    } else {
1810 2505
 		$error = socket_strerror(socket_last_error());
1811 2506
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1812
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1813
-			if (isset($globalDebug)) echo "Restarting...\n";
2507
+			if ($globalDebug) {
2508
+				echo "ERROR : socket_select give this error ".$error . "\n";
2509
+			}
2510
+			if (isset($globalDebug)) {
2511
+				echo "Restarting...\n";
2512
+			}
1814 2513
 			// Restart the script if possible
1815 2514
 			if (is_array($sockets)) {
1816
-			    if ($globalDebug) echo "Shutdown all sockets...";
2515
+			    if ($globalDebug) {
2516
+			    	echo "Shutdown all sockets...";
2517
+			    }
1817 2518
 			    
1818 2519
 			    foreach ($sockets as $sock) {
1819 2520
 				@socket_shutdown($sock,2);
@@ -1821,25 +2522,45 @@  discard block
 block discarded – undo
1821 2522
 			    }
1822 2523
 			    
1823 2524
 			}
1824
-			if ($globalDebug) echo "Waiting...";
2525
+			if ($globalDebug) {
2526
+				echo "Waiting...";
2527
+			}
1825 2528
 			sleep(2);
1826 2529
 			$time = time();
1827 2530
 			//connect_all($hosts);
1828 2531
 			$aprs_connect = 0;
1829
-			if ($reset%5 == 0) sleep(20);
1830
-			if ($reset%10 == 0) sleep(100);
1831
-			if ($reset%20 == 0) sleep(200);
1832
-			if ($reset > 100) exit('Too many attempts...');
1833
-			if ($globalDebug) echo "Restart all connections...";
2532
+			if ($reset%5 == 0) {
2533
+				sleep(20);
2534
+			}
2535
+			if ($reset%10 == 0) {
2536
+				sleep(100);
2537
+			}
2538
+			if ($reset%20 == 0) {
2539
+				sleep(200);
2540
+			}
2541
+			if ($reset > 100) {
2542
+				exit('Too many attempts...');
2543
+			}
2544
+			if ($globalDebug) {
2545
+				echo "Restart all connections...";
2546
+			}
1834 2547
 			connect_all($globalSources);
1835 2548
 		}
1836 2549
 	    }
1837 2550
 	}
1838 2551
 	if ($globalDaemon === false) {
1839
-	    if ($globalDebug) echo 'Check all...'."\n";
1840
-	    if (isset($SI)) $SI->checkAll();
1841
-	    if (isset($TI)) $TI->checkAll();
1842
-	    if (isset($MI)) $MI->checkAll();
2552
+	    if ($globalDebug) {
2553
+	    	echo 'Check all...'."\n";
2554
+	    }
2555
+	    if (isset($SI)) {
2556
+	    	$SI->checkAll();
2557
+	    }
2558
+	    if (isset($TI)) {
2559
+	    	$TI->checkAll();
2560
+	    }
2561
+	    if (isset($MI)) {
2562
+	    	$MI->checkAll();
2563
+	    }
1843 2564
 	}
1844 2565
     }
1845 2566
 }
Please login to merge, or discard this patch.