Completed
Push — master ( 9aa308...c4688e )
by Yannick
07:45
created
scripts/daemon-spotter.php 1 patch
Braces   +651 added lines, -225 removed lines patch added patch discarded remove patch
@@ -13,13 +13,17 @@  discard block
 block discarded – undo
13 13
 require_once(dirname(__FILE__).'/../require/class.SBS.php');
14 14
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
15 15
 require_once(dirname(__FILE__).'/../require/class.Common.php');
16
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
16
+if (isset($globalTracker) && $globalTracker) {
17
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
18
+}
17 19
 if (isset($globalMarine) && $globalMarine) {
18 20
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
19 21
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
20 22
 }
21 23
 
22
-if (!isset($globalDebug)) $globalDebug = FALSE;
24
+if (!isset($globalDebug)) {
25
+	$globalDebug = FALSE;
26
+}
23 27
 
24 28
 // Check if schema is at latest version
25 29
 $Connection = new Connection();
@@ -59,14 +63,25 @@  discard block
 block discarded – undo
59 63
     $globalSources = array();
60 64
     $globalSources[] = array('host' => $options['source']);
61 65
 }
62
-if (isset($options['server'])) $globalServer = TRUE;
63
-if (isset($options['idsource'])) $id_source = $options['idsource'];
64
-else $id_source = 1;
66
+if (isset($options['server'])) {
67
+	$globalServer = TRUE;
68
+}
69
+if (isset($options['idsource'])) {
70
+	$id_source = $options['idsource'];
71
+} else {
72
+	$id_source = 1;
73
+}
65 74
 if (isset($globalServer) && $globalServer) {
66
-    if ($globalDebug) echo "Using Server Mode\n";
75
+    if ($globalDebug) {
76
+    	echo "Using Server Mode\n";
77
+    }
67 78
     $SI=new SpotterServer();
68
-} else $SI=new SpotterImport($Connection->db);
69
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
79
+} else {
80
+	$SI=new SpotterImport($Connection->db);
81
+}
82
+if (isset($globalTracker) && $globalTracker) {
83
+	$TI = new TrackerImport($Connection->db);
84
+}
70 85
 if (isset($globalMarine) && $globalMarine) {
71 86
     $AIS = new AIS();
72 87
     $MI = new MarineImport($Connection->db);
@@ -88,7 +103,9 @@  discard block
 block discarded – undo
88 103
 }
89 104
 
90 105
 // let's try and connect
91
-if ($globalDebug) echo "Connecting...\n";
106
+if ($globalDebug) {
107
+	echo "Connecting...\n";
108
+}
92 109
 $use_aprs = false;
93 110
 $aprs_full = false;
94 111
 $reset = 0;
@@ -97,7 +114,9 @@  discard block
 block discarded – undo
97 114
     $ip = gethostbyname($host);
98 115
     $s = socket_create(AF_INET, SOCK_STREAM, 0);
99 116
     $r = @socket_connect($s, $ip, $port);
100
-    if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
117
+    if (!socket_set_nonblock($s)) {
118
+    	echo "Unable to set nonblock on socket\n";
119
+    }
101 120
     if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
102 121
         return $s;
103 122
     }
@@ -125,7 +144,9 @@  discard block
 block discarded – undo
125 144
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
126 145
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
127 146
     $reset++;
128
-    if ($globalDebug) echo 'Connect to all...'."\n";
147
+    if ($globalDebug) {
148
+    	echo 'Connect to all...'."\n";
149
+    }
129 150
     foreach ($hosts as $id => $value) {
130 151
 	$host = $value['host'];
131 152
 	$globalSources[$id]['last_exec'] = 0;
@@ -135,27 +156,37 @@  discard block
 block discarded – undo
135 156
         	//$formats[$id] = 'deltadbtxt';
136 157
         	$globalSources[$id]['format'] = 'deltadbtxt';
137 158
         	//$last_exec['deltadbtxt'] = 0;
138
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
159
+        	if ($globalDebug) {
160
+        		echo "Connect to deltadb source (".$host.")...\n";
161
+        	}
139 162
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
140 163
         	//$formats[$id] = 'vatsimtxt';
141 164
         	$globalSources[$id]['format'] = 'vatsimtxt';
142 165
         	//$last_exec['vatsimtxt'] = 0;
143
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
166
+        	if ($globalDebug) {
167
+        		echo "Connect to vatsim source (".$host.")...\n";
168
+        	}
144 169
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
145 170
         	//$formats[$id] = 'aircraftlistjson';
146 171
         	$globalSources[$id]['format'] = 'aircraftlistjson';
147 172
         	//$last_exec['aircraftlistjson'] = 0;
148
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
173
+        	if ($globalDebug) {
174
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
175
+        	}
149 176
     	    } else if (preg_match('/opensky/i',$host)) {
150 177
         	//$formats[$id] = 'aircraftlistjson';
151 178
         	$globalSources[$id]['format'] = 'opensky';
152 179
         	//$last_exec['aircraftlistjson'] = 0;
153
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
180
+        	if ($globalDebug) {
181
+        		echo "Connect to opensky source (".$host.")...\n";
182
+        	}
154 183
     	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
155 184
         	//$formats[$id] = 'radarvirtueljson';
156 185
         	$globalSources[$id]['format'] = 'radarvirtueljson';
157 186
         	//$last_exec['radarvirtueljson'] = 0;
158
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
187
+        	if ($globalDebug) {
188
+        		echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
189
+        	}
159 190
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
160 191
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
161 192
         	    exit(0);
@@ -164,7 +195,9 @@  discard block
 block discarded – undo
164 195
         	//$formats[$id] = 'planeupdatefaa';
165 196
         	$globalSources[$id]['format'] = 'planeupdatefaa';
166 197
         	//$last_exec['planeupdatefaa'] = 0;
167
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
198
+        	if ($globalDebug) {
199
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
200
+        	}
168 201
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
169 202
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
170 203
         	    exit(0);
@@ -173,26 +206,36 @@  discard block
 block discarded – undo
173 206
         	//$formats[$id] = 'phpvmacars';
174 207
         	$globalSources[$id]['format'] = 'phpvmacars';
175 208
         	//$last_exec['phpvmacars'] = 0;
176
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
209
+        	if ($globalDebug) {
210
+        		echo "Connect to phpvmacars source (".$host.")...\n";
211
+        	}
177 212
             } else if (preg_match('/VAM-json.php$/i',$host)) {
178 213
         	//$formats[$id] = 'phpvmacars';
179 214
         	$globalSources[$id]['format'] = 'vam';
180
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
215
+        	if ($globalDebug) {
216
+        		echo "Connect to Vam source (".$host.")...\n";
217
+        	}
181 218
             } else if (preg_match('/whazzup/i',$host)) {
182 219
         	//$formats[$id] = 'whazzup';
183 220
         	$globalSources[$id]['format'] = 'whazzup';
184 221
         	//$last_exec['whazzup'] = 0;
185
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
222
+        	if ($globalDebug) {
223
+        		echo "Connect to whazzup source (".$host.")...\n";
224
+        	}
186 225
             } else if (preg_match('/recentpireps/i',$host)) {
187 226
         	//$formats[$id] = 'pirepsjson';
188 227
         	$globalSources[$id]['format'] = 'pirepsjson';
189 228
         	//$last_exec['pirepsjson'] = 0;
190
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
229
+        	if ($globalDebug) {
230
+        		echo "Connect to pirepsjson source (".$host.")...\n";
231
+        	}
191 232
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
192 233
         	//$formats[$id] = 'fr24json';
193 234
         	$globalSources[$id]['format'] = 'fr24json';
194 235
         	//$last_exec['fr24json'] = 0;
195
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
236
+        	if ($globalDebug) {
237
+        		echo "Connect to fr24 source (".$host.")...\n";
238
+        	}
196 239
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
197 240
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
198 241
         	    exit(0);
@@ -201,17 +244,24 @@  discard block
 block discarded – undo
201 244
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
202 245
         	//$formats[$id] = 'tsv';
203 246
         	$globalSources[$id]['format'] = 'tsv';
204
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
247
+        	if ($globalDebug) {
248
+        		echo "Connect to tsv source (".$host.")...\n";
249
+        	}
205 250
             }
206 251
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
207 252
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
208 253
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
209 254
     		    if ($idf !== false) {
210 255
     			$httpfeeds[$id] = $idf;
211
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
256
+        		if ($globalDebug) {
257
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
258
+        		}
259
+    		    } elseif ($globalDebug) {
260
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
212 261
     		    }
213
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
214
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
262
+    		} elseif ($globalDebug) {
263
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
264
+    		}
215 265
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
216 266
 	    $hostport = explode(':',$host);
217 267
 	    if (isset($hostport[1])) {
@@ -248,17 +298,25 @@  discard block
 block discarded – undo
248 298
         		//$formats[$id] = 'beast';
249 299
         		$globalSources[$id]['format'] = 'beast';
250 300
 		    //} else $formats[$id] = 'sbs';
251
-		    } else $globalSources[$id]['format'] = 'sbs';
301
+		    } else {
302
+		    	$globalSources[$id]['format'] = 'sbs';
303
+		    }
252 304
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
253 305
 		}
254
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
306
+		if ($globalDebug) {
307
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
308
+		}
255 309
             } else {
256
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
310
+		if ($globalDebug) {
311
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
312
+		}
257 313
     	    }
258 314
         }
259 315
     }
260 316
 }
261
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
317
+if (!isset($globalMinFetch)) {
318
+	$globalMinFetch = 15;
319
+}
262 320
 
263 321
 // Initialize all
264 322
 $status = array();
@@ -267,13 +325,19 @@  discard block
 block discarded – undo
267 325
 $formats = array();
268 326
 $last_exec = array();
269 327
 $time = time();
270
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
271
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
272
-else $timeout = 20;
328
+if (isset($globalSourcesTimeout)) {
329
+	$timeout = $globalSourcesTimeOut;
330
+} else if (isset($globalSBS1TimeOut)) {
331
+	$timeout = $globalSBS1TimeOut;
332
+} else {
333
+	$timeout = 20;
334
+}
273 335
 $errno = '';
274 336
 $errstr='';
275 337
 
276
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
338
+if (!isset($globalDaemon)) {
339
+	$globalDaemon = TRUE;
340
+}
277 341
 /* Initiate connections to all the hosts simultaneously */
278 342
 //connect_all($hosts);
279 343
 //connect_all($globalSources);
@@ -299,7 +363,9 @@  discard block
 block discarded – undo
299 363
     if (isset($source['format']) && $source['format'] == 'aprs') {
300 364
 	$aprs_connect = 0;
301 365
 	$use_aprs = true;
302
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
366
+	if (isset($source['port']) && $source['port'] == '10152') {
367
+		$aprs_full = true;
368
+	}
303 369
 	break;
304 370
     }
305 371
 }
@@ -310,23 +376,43 @@  discard block
 block discarded – undo
310 376
 	$aprs_connect = 0;
311 377
 	$aprs_keep = 120;
312 378
 	$aprs_last_tx = time();
313
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
314
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
315
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
316
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
317
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
318
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
319
-	if ($aprs_full) $aprs_filter = '';
379
+	if (isset($globalAPRSversion)) {
380
+		$aprs_version = $globalAPRSversion;
381
+	} else {
382
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
383
+	}
384
+	if (isset($globalAPRSssid)) {
385
+		$aprs_ssid = $globalAPRSssid;
386
+	} else {
387
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
388
+	}
389
+	if (isset($globalAPRSfilter)) {
390
+		$aprs_filter = $globalAPRSfilter;
391
+	} else {
392
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
393
+	}
394
+	if ($aprs_full) {
395
+		$aprs_filter = '';
396
+	}
320 397
 
321
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version} filter {$aprs_filter}\n";
322
-	else $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version}\n";
323
-}
398
+	if ($aprs_filter != '') {
399
+		$aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version} filter {$aprs_filter}\n";
400
+	} else {
401
+		$aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version}\n";
402
+	}
403
+	}
324 404
 
325 405
 // connected - lets do some work
326
-if ($globalDebug) echo "Connected!\n";
406
+if ($globalDebug) {
407
+	echo "Connected!\n";
408
+}
327 409
 sleep(1);
328
-if ($globalDebug) echo "SCAN MODE \n\n";
329
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
410
+if ($globalDebug) {
411
+	echo "SCAN MODE \n\n";
412
+}
413
+if (!isset($globalCronEnd)) {
414
+	$globalCronEnd = 60;
415
+}
330 416
 $endtime = time()+$globalCronEnd;
331 417
 $i = 1;
332 418
 $tt = array();
@@ -340,10 +426,14 @@  discard block
 block discarded – undo
340 426
 
341 427
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
342 428
 while ($i > 0) {
343
-    if (!$globalDaemon) $i = $endtime-time();
429
+    if (!$globalDaemon) {
430
+    	$i = $endtime-time();
431
+    }
344 432
     // Delete old ATC
345 433
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
346
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
434
+	if ($globalDebug) {
435
+		echo 'Delete old ATC...'."\n";
436
+	}
347 437
         $ATC->deleteOldATC();
348 438
     }
349 439
     
@@ -351,10 +441,14 @@  discard block
 block discarded – undo
351 441
     if (count($last_exec) == count($globalSources)) {
352 442
 	$max = $globalMinFetch;
353 443
 	foreach ($last_exec as $last) {
354
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
444
+	    if ((time() - $last['last']) < $max) {
445
+	    	$max = time() - $last['last'];
446
+	    }
355 447
 	}
356 448
 	if ($max != $globalMinFetch) {
357
-	    if ($globalDebug) echo 'Sleeping...'."\n";
449
+	    if ($globalDebug) {
450
+	    	echo 'Sleeping...'."\n";
451
+	    }
358 452
 	    sleep($globalMinFetch-$max+2);
359 453
 	}
360 454
     }
@@ -363,11 +457,15 @@  discard block
 block discarded – undo
363 457
     //foreach ($formats as $id => $value) {
364 458
     foreach ($globalSources as $id => $value) {
365 459
 	date_default_timezone_set('UTC');
366
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
460
+	if (!isset($last_exec[$id]['last'])) {
461
+		$last_exec[$id]['last'] = 0;
462
+	}
367 463
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
368 464
 	    //$buffer = $Common->getData($hosts[$id]);
369 465
 	    $buffer = $Common->getData($value['host']);
370
-	    if ($buffer != '') $reset = 0;
466
+	    if ($buffer != '') {
467
+	    	$reset = 0;
468
+	    }
371 469
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
372 470
 	    $buffer = explode('\n',$buffer);
373 471
 	    foreach ($buffer as $line) {
@@ -376,19 +474,38 @@  discard block
 block discarded – undo
376 474
 	            $data = array();
377 475
 	            $data['hex'] = $line[1]; // hex
378 476
 	            $data['ident'] = $line[2]; // ident
379
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
380
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
381
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
382
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
383
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
477
+	            if (isset($line[3])) {
478
+	            	$data['altitude'] = $line[3];
479
+	            }
480
+	            // altitude
481
+	            if (isset($line[4])) {
482
+	            	$data['speed'] = $line[4];
483
+	            }
484
+	            // speed
485
+	            if (isset($line[5])) {
486
+	            	$data['heading'] = $line[5];
487
+	            }
488
+	            // heading
489
+	            if (isset($line[6])) {
490
+	            	$data['latitude'] = $line[6];
491
+	            }
492
+	            // lat
493
+	            if (isset($line[7])) {
494
+	            	$data['longitude'] = $line[7];
495
+	            }
496
+	            // long
384 497
 	            $data['verticalrate'] = ''; // vertical rate
385 498
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
386 499
 	            $data['emergency'] = ''; // emergency
387 500
 		    $data['datetime'] = date('Y-m-d H:i:s');
388 501
 		    $data['format_source'] = 'deltadbtxt';
389 502
     		    $data['id_source'] = $id_source;
390
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
391
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
503
+		    if (isset($value['name']) && $value['name'] != '') {
504
+		    	$data['source_name'] = $value['name'];
505
+		    }
506
+		    if (isset($value['sourcestats'])) {
507
+		    	$data['sourcestats'] = $value['sourcestats'];
508
+		    }
392 509
     		    $SI->add($data);
393 510
 		    unset($data);
394 511
     		}
@@ -398,7 +515,9 @@  discard block
 block discarded – undo
398 515
 	    date_default_timezone_set('CET');
399 516
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
400 517
 	    date_default_timezone_set('UTC');
401
-	    if ($buffer != '') $reset = 0;
518
+	    if ($buffer != '') {
519
+	    	$reset = 0;
520
+	    }
402 521
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
403 522
 	    $buffer = explode('\n',$buffer);
404 523
 	    foreach ($buffer as $line) {
@@ -407,13 +526,27 @@  discard block
 block discarded – undo
407 526
 		    $add = false;
408 527
 		    $ais_data = $AIS->parse_line(trim($line));
409 528
 		    $data = array();
410
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
411
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
412
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
413
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
414
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
415
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
416
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
529
+		    if (isset($ais_data['ident'])) {
530
+		    	$data['ident'] = $ais_data['ident'];
531
+		    }
532
+		    if (isset($ais_data['mmsi'])) {
533
+		    	$data['mmsi'] = $ais_data['mmsi'];
534
+		    }
535
+		    if (isset($ais_data['speed'])) {
536
+		    	$data['speed'] = $ais_data['speed'];
537
+		    }
538
+		    if (isset($ais_data['heading'])) {
539
+		    	$data['heading'] = $ais_data['heading'];
540
+		    }
541
+		    if (isset($ais_data['latitude'])) {
542
+		    	$data['latitude'] = $ais_data['latitude'];
543
+		    }
544
+		    if (isset($ais_data['longitude'])) {
545
+		    	$data['longitude'] = $ais_data['longitude'];
546
+		    }
547
+		    if (isset($ais_data['status'])) {
548
+		    	$data['status'] = $ais_data['status'];
549
+		    }
417 550
 		    if (isset($ais_data['timestamp'])) {
418 551
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
419 552
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -428,7 +561,9 @@  discard block
 block discarded – undo
428 561
     		    $data['id_source'] = $id_source;
429 562
 		    print_r($data);
430 563
 		    echo 'Add...'."\n";
431
-		    if ($add) $MI->add($data);
564
+		    if ($add) {
565
+		    	$MI->add($data);
566
+		    }
432 567
 		    unset($data);
433 568
 		}
434 569
     	    }
@@ -448,13 +583,27 @@  discard block
 block discarded – undo
448 583
 			if ($line != '') {
449 584
 			    $ais_data = $AIS->parse_line(trim($line));
450 585
 			    $data = array();
451
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
452
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
453
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
454
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
455
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
456
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
457
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
586
+			    if (isset($ais_data['ident'])) {
587
+			    	$data['ident'] = $ais_data['ident'];
588
+			    }
589
+			    if (isset($ais_data['mmsi'])) {
590
+			    	$data['mmsi'] = $ais_data['mmsi'];
591
+			    }
592
+			    if (isset($ais_data['speed'])) {
593
+			    	$data['speed'] = $ais_data['speed'];
594
+			    }
595
+			    if (isset($ais_data['heading'])) {
596
+			    	$data['heading'] = $ais_data['heading'];
597
+			    }
598
+			    if (isset($ais_data['latitude'])) {
599
+			    	$data['latitude'] = $ais_data['latitude'];
600
+			    }
601
+			    if (isset($ais_data['longitude'])) {
602
+			    	$data['longitude'] = $ais_data['longitude'];
603
+			    }
604
+			    if (isset($ais_data['status'])) {
605
+			    	$data['status'] = $ais_data['status'];
606
+			    }
458 607
 			    if (isset($ais_data['timestamp'])) {
459 608
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
460 609
 			    } else {
@@ -473,7 +622,9 @@  discard block
 block discarded – undo
473 622
 	    echo 'download...';
474 623
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
475 624
 	    echo 'done !'."\n";
476
-	    if ($buffer != '') $reset = 0;
625
+	    if ($buffer != '') {
626
+	    	$reset = 0;
627
+	    }
477 628
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
478 629
 	    $buffer = explode('\n',$buffer);
479 630
 	    foreach ($buffer as $line) {
@@ -517,16 +668,28 @@  discard block
 block discarded – undo
517 668
     		    $line = explode(':', $line);
518 669
     		    if (count($line) > 30 && $line[0] != 'callsign') {
519 670
 			$data = array();
520
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
521
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
671
+			if (isset($line[37]) && $line[37] != '') {
672
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
673
+			} else {
674
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
675
+			}
522 676
 			$data['pilot_id'] = $line[1];
523 677
 			$data['pilot_name'] = $line[2];
524 678
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
525 679
 			$data['ident'] = $line[0]; // ident
526
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
680
+			if ($line[7] != '' && $line[7] != 0) {
681
+				$data['altitude'] = $line[7];
682
+			}
683
+			// altitude
527 684
 			$data['speed'] = $line[8]; // speed
528
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
529
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
685
+			if (isset($line[45])) {
686
+				$data['heading'] = $line[45];
687
+			}
688
+			// heading
689
+			elseif (isset($line[38])) {
690
+				$data['heading'] = $line[38];
691
+			}
692
+			// heading
530 693
 			$data['latitude'] = $line[5]; // lat
531 694
 	        	$data['longitude'] = $line[6]; // long
532 695
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -542,7 +705,9 @@  discard block
 block discarded – undo
542 705
 			$data['frequency'] = $line[4];
543 706
 			$data['type'] = $line[18];
544 707
 			$data['range'] = $line[19];
545
-			if (isset($line[35])) $data['info'] = $line[35];
708
+			if (isset($line[35])) {
709
+				$data['info'] = $line[35];
710
+			}
546 711
     			$data['id_source'] = $id_source;
547 712
 	    		//$data['arrival_airport_time'] = ;
548 713
 	    		if ($line[9] != '') {
@@ -556,24 +721,41 @@  discard block
 block discarded – undo
556 721
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
557 722
 	    		*/
558 723
 	    		$data['format_source'] = $value['format'];
559
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
560
-    			if ($line[3] == 'PILOT') $SI->add($data);
561
-			elseif ($line[3] == 'ATC') {
724
+			if (isset($value['name']) && $value['name'] != '') {
725
+				$data['source_name'] = $value['name'];
726
+			}
727
+    			if ($line[3] == 'PILOT') {
728
+    				$SI->add($data);
729
+    			} elseif ($line[3] == 'ATC') {
562 730
 				//print_r($data);
563 731
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
564 732
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
565 733
 				$typec = substr($data['ident'],-3);
566
-				if ($typec == 'APP') $data['type'] = 'Approach';
567
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
568
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
569
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
570
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
571
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
572
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
573
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
574
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
575
-				if (!isset($data['source_name'])) $data['source_name'] = '';
576
-				if (isset($ATC)) 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']);
734
+				if ($typec == 'APP') {
735
+					$data['type'] = 'Approach';
736
+				} elseif ($typec == 'TWR') {
737
+					$data['type'] = 'Tower';
738
+				} elseif ($typec == 'OBS') {
739
+					$data['type'] = 'Observer';
740
+				} elseif ($typec == 'GND') {
741
+					$data['type'] = 'Ground';
742
+				} elseif ($typec == 'DEL') {
743
+					$data['type'] = 'Delivery';
744
+				} elseif ($typec == 'DEP') {
745
+					$data['type'] = 'Departure';
746
+				} elseif ($typec == 'FSS') {
747
+					$data['type'] = 'Flight Service Station';
748
+				} elseif ($typec == 'CTR') {
749
+					$data['type'] = 'Control Radar or Centre';
750
+				} elseif ($data['type'] == '') {
751
+					$data['type'] = 'Observer';
752
+				}
753
+				if (!isset($data['source_name'])) {
754
+					$data['source_name'] = '';
755
+				}
756
+				if (isset($ATC)) {
757
+					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']);
758
+				}
577 759
 			}
578 760
     			unset($data);
579 761
     		    }
@@ -592,26 +774,55 @@  discard block
 block discarded – undo
592 774
 		foreach ($all_data['acList'] as $line) {
593 775
 		    $data = array();
594 776
 		    $data['hex'] = $line['Icao']; // hex
595
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
596
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
597
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
598
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
599
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
600
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
777
+		    if (isset($line['Call'])) {
778
+		    	$data['ident'] = $line['Call'];
779
+		    }
780
+		    // ident
781
+		    if (isset($line['Alt'])) {
782
+		    	$data['altitude'] = $line['Alt'];
783
+		    }
784
+		    // altitude
785
+		    if (isset($line['Spd'])) {
786
+		    	$data['speed'] = $line['Spd'];
787
+		    }
788
+		    // speed
789
+		    if (isset($line['Trak'])) {
790
+		    	$data['heading'] = $line['Trak'];
791
+		    }
792
+		    // heading
793
+		    if (isset($line['Lat'])) {
794
+		    	$data['latitude'] = $line['Lat'];
795
+		    }
796
+		    // lat
797
+		    if (isset($line['Long'])) {
798
+		    	$data['longitude'] = $line['Long'];
799
+		    }
800
+		    // long
601 801
 		    //$data['verticalrate'] = $line['']; // verticale rate
602
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
802
+		    if (isset($line['Sqk'])) {
803
+		    	$data['squawk'] = $line['Sqk'];
804
+		    }
805
+		    // squawk
603 806
 		    $data['emergency'] = ''; // emergency
604
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
807
+		    if (isset($line['Reg'])) {
808
+		    	$data['registration'] = $line['Reg'];
809
+		    }
605 810
 		    /*
606 811
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
607 812
 		    else $data['datetime'] = date('Y-m-d H:i:s');
608 813
 		    */
609 814
 		    $data['datetime'] = date('Y-m-d H:i:s');
610
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
815
+		    if (isset($line['Type'])) {
816
+		    	$data['aircraft_icao'] = $line['Type'];
817
+		    }
611 818
 	    	    $data['format_source'] = 'aircraftlistjson';
612 819
 		    $data['id_source'] = $id_source;
613
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
614
-		    if (isset($data['datetime'])) $SI->add($data);
820
+		    if (isset($value['name']) && $value['name'] != '') {
821
+		    	$data['source_name'] = $value['name'];
822
+		    }
823
+		    if (isset($data['datetime'])) {
824
+		    	$SI->add($data);
825
+		    }
615 826
 		    unset($data);
616 827
 		}
617 828
 	    } else {
@@ -631,7 +842,9 @@  discard block
 block discarded – undo
631 842
 		    $data['datetime'] = date('Y-m-d H:i:s');
632 843
 	    	    $data['format_source'] = 'aircraftlistjson';
633 844
     		    $data['id_source'] = $id_source;
634
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
845
+		    if (isset($value['name']) && $value['name'] != '') {
846
+		    	$data['source_name'] = $value['name'];
847
+		    }
635 848
 		    $SI->add($data);
636 849
 		    unset($data);
637 850
 		}
@@ -667,7 +880,9 @@  discard block
 block discarded – undo
667 880
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
668 881
 	    	    $data['format_source'] = 'planeupdatefaa';
669 882
     		    $data['id_source'] = $id_source;
670
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
883
+		    if (isset($value['name']) && $value['name'] != '') {
884
+		    	$data['source_name'] = $value['name'];
885
+		    }
671 886
 		    $SI->add($data);
672 887
 		    unset($data);
673 888
 		}
@@ -707,7 +922,9 @@  discard block
 block discarded – undo
707 922
 	    //$buffer = $Common->getData($hosts[$id]);
708 923
 	    $buffer = $Common->getData($value['host']);
709 924
 	    $all_data = json_decode($buffer,true);
710
-	    if (!empty($all_data)) $reset = 0;
925
+	    if (!empty($all_data)) {
926
+	    	$reset = 0;
927
+	    }
711 928
 	    foreach ($all_data as $key => $line) {
712 929
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
713 930
 		    $data = array();
@@ -728,7 +945,9 @@  discard block
 block discarded – undo
728 945
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
729 946
 	    	    $data['format_source'] = 'fr24json';
730 947
     		    $data['id_source'] = $id_source;
731
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
948
+		    if (isset($value['name']) && $value['name'] != '') {
949
+		    	$data['source_name'] = $value['name'];
950
+		    }
732 951
 		    $SI->add($data);
733 952
 		    unset($data);
734 953
 		}
@@ -752,23 +971,39 @@  discard block
 block discarded – undo
752 971
 		    if (isset($line['inf'])) {
753 972
 			$data = array();
754 973
 			$data['hex'] = $line['inf']['ia'];
755
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
974
+			if (isset($line['inf']['cs'])) {
975
+				$data['ident'] = $line['inf']['cs'];
976
+			}
977
+			//$line[13]
756 978
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
757
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
758
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
979
+	    		if (isset($line['inf']['gs'])) {
980
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
981
+	    		}
982
+	    		// speed
983
+	    		if (isset($line['inf']['tr'])) {
984
+	    			$data['heading'] = $line['inf']['tr'];
985
+	    		}
986
+	    		// heading
759 987
 	    		$data['latitude'] = $line['pt'][0]; // lat
760 988
 	    		$data['longitude'] = $line['pt'][1]; // long
761 989
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
762
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
990
+	    		if (isset($line['inf']['sq'])) {
991
+	    			$data['squawk'] = $line['inf']['sq'];
992
+	    		}
993
+	    		// squawk
763 994
 	    		//$data['aircraft_icao'] = $line[8];
764
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
995
+	    		if (isset($line['inf']['rc'])) {
996
+	    			$data['registration'] = $line['inf']['rc'];
997
+	    		}
765 998
 			//$data['departure_airport_iata'] = $line[11];
766 999
 			//$data['arrival_airport_iata'] = $line[12];
767 1000
 	    		//$data['emergency'] = ''; // emergency
768 1001
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
769 1002
 	    		$data['format_source'] = 'radarvirtueljson';
770 1003
     			$data['id_source'] = $id_source;
771
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1004
+			if (isset($value['name']) && $value['name'] != '') {
1005
+				$data['source_name'] = $value['name'];
1006
+			}
772 1007
 			$SI->add($data);
773 1008
 			unset($data);
774 1009
 		    }
@@ -789,29 +1024,62 @@  discard block
 block discarded – undo
789 1024
 		    $data['id'] = $line['id'];
790 1025
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
791 1026
 		    $data['ident'] = $line['callsign']; // ident
792
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
793
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
794
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
795
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
796
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
797
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1027
+		    if (isset($line['pilotid'])) {
1028
+		    	$data['pilot_id'] = $line['pilotid'];
1029
+		    }
1030
+		    // pilot id
1031
+		    if (isset($line['name'])) {
1032
+		    	$data['pilot_name'] = $line['name'];
1033
+		    }
1034
+		    // pilot name
1035
+		    if (isset($line['alt'])) {
1036
+		    	$data['altitude'] = $line['alt'];
1037
+		    }
1038
+		    // altitude
1039
+		    if (isset($line['gs'])) {
1040
+		    	$data['speed'] = $line['gs'];
1041
+		    }
1042
+		    // speed
1043
+		    if (isset($line['heading'])) {
1044
+		    	$data['heading'] = $line['heading'];
1045
+		    }
1046
+		    // heading
1047
+		    if (isset($line['route'])) {
1048
+		    	$data['waypoints'] = $line['route'];
1049
+		    }
1050
+		    // route
798 1051
 		    $data['latitude'] = $line['lat']; // lat
799 1052
 		    $data['longitude'] = $line['lon']; // long
800 1053
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
801 1054
 		    //$data['squawk'] = $line['squawk']; // squawk
802 1055
 		    //$data['emergency'] = ''; // emergency
803
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
804
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
805
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1056
+		    if (isset($line['depicao'])) {
1057
+		    	$data['departure_airport_icao'] = $line['depicao'];
1058
+		    }
1059
+		    if (isset($line['deptime'])) {
1060
+		    	$data['departure_airport_time'] = $line['deptime'];
1061
+		    }
1062
+		    if (isset($line['arricao'])) {
1063
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1064
+		    }
806 1065
 		    //$data['arrival_airport_time'] = $line['arrtime'];
807
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
808
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
809
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
810
-		    else $data['info'] = '';
1066
+		    if (isset($line['aircraft'])) {
1067
+		    	$data['aircraft_icao'] = $line['aircraft'];
1068
+		    }
1069
+		    if (isset($line['transponder'])) {
1070
+		    	$data['squawk'] = $line['transponder'];
1071
+		    }
1072
+		    if (isset($line['atis'])) {
1073
+		    	$data['info'] = $line['atis'];
1074
+		    } else {
1075
+		    	$data['info'] = '';
1076
+		    }
811 1077
 		    $data['format_source'] = 'pireps';
812 1078
     		    $data['id_source'] = $id_source;
813 1079
 		    $data['datetime'] = date('Y-m-d H:i:s');
814
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1080
+		    if (isset($value['name']) && $value['name'] != '') {
1081
+		    	$data['source_name'] = $value['name'];
1082
+		    }
815 1083
 		    if ($line['icon'] == 'plane') {
816 1084
 			$SI->add($data);
817 1085
 		    //    print_r($data);
@@ -820,16 +1088,28 @@  discard block
 block discarded – undo
820 1088
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
821 1089
 			$typec = substr($data['ident'],-3);
822 1090
 			$data['type'] = '';
823
-			if ($typec == 'APP') $data['type'] = 'Approach';
824
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
825
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
826
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
827
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
828
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
829
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
830
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
831
-			else $data['type'] = 'Observer';
832
-			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']);
1091
+			if ($typec == 'APP') {
1092
+				$data['type'] = 'Approach';
1093
+			} elseif ($typec == 'TWR') {
1094
+				$data['type'] = 'Tower';
1095
+			} elseif ($typec == 'OBS') {
1096
+				$data['type'] = 'Observer';
1097
+			} elseif ($typec == 'GND') {
1098
+				$data['type'] = 'Ground';
1099
+			} elseif ($typec == 'DEL') {
1100
+				$data['type'] = 'Delivery';
1101
+			} elseif ($typec == 'DEP') {
1102
+				$data['type'] = 'Departure';
1103
+			} elseif ($typec == 'FSS') {
1104
+				$data['type'] = 'Flight Service Station';
1105
+			} elseif ($typec == 'CTR') {
1106
+				$data['type'] = 'Control Radar or Centre';
1107
+			} else {
1108
+				$data['type'] = 'Observer';
1109
+			}
1110
+			if (isset($ATC)) {
1111
+				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']);
1112
+			}
833 1113
 		    }
834 1114
 		    unset($data);
835 1115
 		}
@@ -839,7 +1119,9 @@  discard block
 block discarded – undo
839 1119
     	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
840 1120
     	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
841 1121
 	    //$buffer = $Common->getData($hosts[$id]);
842
-	    if ($globalDebug) echo 'Get Data...'."\n";
1122
+	    if ($globalDebug) {
1123
+	    	echo 'Get Data...'."\n";
1124
+	    }
843 1125
 	    $buffer = $Common->getData($value['host']);
844 1126
 	    $all_data = json_decode($buffer,true);
845 1127
 	    if ($buffer != '' && is_array($all_data)) {
@@ -847,10 +1129,16 @@  discard block
 block discarded – undo
847 1129
 		foreach ($all_data as $line) {
848 1130
 	    	    $data = array();
849 1131
 	    	    //$data['id'] = $line['id']; // id not usable
850
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1132
+	    	    if (isset($line['pilotid'])) {
1133
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1134
+	    	    }
851 1135
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
852
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
853
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1136
+	    	    if (isset($line['pilotname'])) {
1137
+	    	    	$data['pilot_name'] = $line['pilotname'];
1138
+	    	    }
1139
+	    	    if (isset($line['pilotid'])) {
1140
+	    	    	$data['pilot_id'] = $line['pilotid'];
1141
+	    	    }
854 1142
 	    	    $data['ident'] = $line['flightnum']; // ident
855 1143
 	    	    $data['altitude'] = $line['alt']; // altitude
856 1144
 	    	    $data['speed'] = $line['gs']; // speed
@@ -868,27 +1156,41 @@  discard block
 block discarded – undo
868 1156
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
869 1157
     		    $data['arrival_airport_time'] = $line['arrtime'];
870 1158
     		    $data['registration'] = $line['aircraft'];
871
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1159
+		    if (isset($line['route'])) {
1160
+		    	$data['waypoints'] = $line['route'];
1161
+		    }
1162
+		    // route
872 1163
 		    if (isset($line['aircraftname'])) {
873 1164
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
874 1165
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
875 1166
 	    		$aircraft_data = explode('-',$line['aircraftname']);
876
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
877
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
878
-	    		else {
1167
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) {
1168
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1169
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) {
1170
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1171
+	    		} else {
879 1172
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
880
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
881
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
1173
+	    		    if (isset($aircraft_data[1])) {
1174
+	    		    	$data['aircraft_icao'] = $aircraft_data[1];
1175
+	    		    } else {
1176
+	    		    	$data['aircraft_icao'] = $line['aircraftname'];
1177
+	    		    }
882 1178
 	    		}
883 1179
 	    	    }
884
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1180
+    		    if (isset($line['route'])) {
1181
+    		    	$data['waypoints'] = $line['route'];
1182
+    		    }
885 1183
     		    $data['id_source'] = $id_source;
886 1184
 	    	    $data['format_source'] = 'phpvmacars';
887
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1185
+		    if (isset($value['name']) && $value['name'] != '') {
1186
+		    	$data['source_name'] = $value['name'];
1187
+		    }
888 1188
 		    $SI->add($data);
889 1189
 		    unset($data);
890 1190
 		}
891
-		if ($globalDebug) echo 'No more data...'."\n";
1191
+		if ($globalDebug) {
1192
+			echo 'No more data...'."\n";
1193
+		}
892 1194
 		unset($buffer);
893 1195
 		unset($all_data);
894 1196
 	    }
@@ -896,7 +1198,9 @@  discard block
 block discarded – undo
896 1198
     	    $last_exec[$id]['last'] = time();
897 1199
     	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
898 1200
 	    //$buffer = $Common->getData($hosts[$id]);
899
-	    if ($globalDebug) echo 'Get Data...'."\n";
1201
+	    if ($globalDebug) {
1202
+	    	echo 'Get Data...'."\n";
1203
+	    }
900 1204
 	    $buffer = $Common->getData($value['host']);
901 1205
 	    $all_data = json_decode($buffer,true);
902 1206
 	    if ($buffer != '' && is_array($all_data)) {
@@ -925,15 +1229,22 @@  discard block
 block discarded – undo
925 1229
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
926 1230
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
927 1231
     		    //$data['registration'] = $line['aircraft'];
928
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1232
+		    if (isset($line['route'])) {
1233
+		    	$data['waypoints'] = $line['route'];
1234
+		    }
1235
+		    // route
929 1236
 	    	    $data['aircraft_icao'] = $line['plane_type'];
930 1237
     		    $data['id_source'] = $id_source;
931 1238
 	    	    $data['format_source'] = 'vam';
932
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1239
+		    if (isset($value['name']) && $value['name'] != '') {
1240
+		    	$data['source_name'] = $value['name'];
1241
+		    }
933 1242
 		    $SI->add($data);
934 1243
 		    unset($data);
935 1244
 		}
936
-		if ($globalDebug) echo 'No more data...'."\n";
1245
+		if ($globalDebug) {
1246
+			echo 'No more data...'."\n";
1247
+		}
937 1248
 		unset($buffer);
938 1249
 		unset($all_data);
939 1250
 	    }
@@ -941,7 +1252,9 @@  discard block
 block discarded – undo
941 1252
     	    $last_exec[$id]['last'] = time();
942 1253
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
943 1254
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais') {
944
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1255
+	    if (function_exists('pcntl_fork')) {
1256
+	    	pcntl_signal_dispatch();
1257
+	    }
945 1258
     	    //$last_exec[$id]['last'] = time();
946 1259
 
947 1260
 	    //$read = array( $sockets[$id] );
@@ -949,7 +1262,9 @@  discard block
 block discarded – undo
949 1262
 	    $write = NULL;
950 1263
 	    $e = NULL;
951 1264
 	    $n = socket_select($read, $write, $e, $timeout);
952
-	    if ($e != NULL) var_dump($e);
1265
+	    if ($e != NULL) {
1266
+	    	var_dump($e);
1267
+	    }
953 1268
 	    if ($n > 0) {
954 1269
 		$reset = 0;
955 1270
 		foreach ($read as $nb => $r) {
@@ -971,7 +1286,9 @@  discard block
 block discarded – undo
971 1286
 		    if ($buffer != '') {
972 1287
 			$tt[$format] = 0;
973 1288
 			if ($format == 'acarssbs3') {
974
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1289
+                    	    if ($globalDebug) {
1290
+                    	    	echo 'ACARS : '.$buffer."\n";
1291
+                    	    }
975 1292
 			    $ACARS->add(trim($buffer));
976 1293
 			    $ACARS->deleteLiveAcarsData();
977 1294
 			} elseif ($format == 'raw') {
@@ -980,19 +1297,37 @@  discard block
 block discarded – undo
980 1297
 			    if (is_array($data)) {
981 1298
 				$data['datetime'] = date('Y-m-d H:i:s');
982 1299
 				$data['format_source'] = 'raw';
983
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
984
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
985
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1300
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1301
+					$data['source_name'] = $globalSources[$nb]['name'];
1302
+				}
1303
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1304
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1305
+    				}
1306
+                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1307
+                                	$SI->add($data);
1308
+                                }
986 1309
                             }
987 1310
                         } elseif ($format == 'ais') {
988 1311
 			    $ais_data = $AIS->parse_line(trim($buffer));
989 1312
 			    $data = array();
990
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
991
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
992
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
993
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
994
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
995
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1313
+			    if (isset($ais_data['ident'])) {
1314
+			    	$data['ident'] = $ais_data['ident'];
1315
+			    }
1316
+			    if (isset($ais_data['mmsi'])) {
1317
+			    	$data['mmsi'] = $ais_data['mmsi'];
1318
+			    }
1319
+			    if (isset($ais_data['speed'])) {
1320
+			    	$data['speed'] = $ais_data['speed'];
1321
+			    }
1322
+			    if (isset($ais_data['heading'])) {
1323
+			    	$data['heading'] = $ais_data['heading'];
1324
+			    }
1325
+			    if (isset($ais_data['latitude'])) {
1326
+			    	$data['latitude'] = $ais_data['latitude'];
1327
+			    }
1328
+			    if (isset($ais_data['longitude'])) {
1329
+			    	$data['longitude'] = $ais_data['longitude'];
1330
+			    }
996 1331
 			    if (isset($ais_data['timestamp'])) {
997 1332
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
998 1333
 			    } else {
@@ -1018,11 +1353,15 @@  discard block
 block discarded – undo
1018 1353
 				$data['speed'] = round($line[5]*1.94384);
1019 1354
 				$data['datetime'] = date('Y-m-d H:i:s');
1020 1355
 				$data['format_source'] = 'flightgearsp';
1021
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1356
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1357
+					$SI->add($data);
1358
+				}
1022 1359
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1023 1360
 			    }
1024 1361
                         } elseif ($format == 'acars') {
1025
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1362
+                    	    if ($globalDebug) {
1363
+                    	    	echo 'ACARS : '.$buffer."\n";
1364
+                    	    }
1026 1365
 			    $ACARS->add(trim($buffer));
1027 1366
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1028 1367
 			    $ACARS->deleteLiveAcarsData();
@@ -1043,7 +1382,9 @@  discard block
 block discarded – undo
1043 1382
 				    $aircraft_type = $line[10];
1044 1383
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1045 1384
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1046
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1385
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1386
+				    	$SI->add($data);
1387
+				    }
1047 1388
 				}
1048 1389
 			    }
1049 1390
 			} elseif ($format == 'beast') {
@@ -1059,21 +1400,43 @@  discard block
 block discarded – undo
1059 1400
     				$data['hex'] = $lined['hexid'];
1060 1401
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1061 1402
     				$data['datetime'] = date('Y-m-d H:i:s');;
1062
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1063
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1064
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1065
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1066
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1067
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1068
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1403
+    				if (isset($lined['ident'])) {
1404
+    					$data['ident'] = $lined['ident'];
1405
+    				}
1406
+    				if (isset($lined['lat'])) {
1407
+    					$data['latitude'] = $lined['lat'];
1408
+    				}
1409
+    				if (isset($lined['lon'])) {
1410
+    					$data['longitude'] = $lined['lon'];
1411
+    				}
1412
+    				if (isset($lined['speed'])) {
1413
+    					$data['speed'] = $lined['speed'];
1414
+    				}
1415
+    				if (isset($lined['squawk'])) {
1416
+    					$data['squawk'] = $lined['squawk'];
1417
+    				}
1418
+    				if (isset($lined['alt'])) {
1419
+    					$data['altitude'] = $lined['alt'];
1420
+    				}
1421
+    				if (isset($lined['heading'])) {
1422
+    					$data['heading'] = $lined['heading'];
1423
+    				}
1069 1424
     				$data['id_source'] = $id_source;
1070 1425
     				$data['format_source'] = 'tsv';
1071
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1072
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1073
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1426
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1427
+    					$data['source_name'] = $globalSources[$nb]['name'];
1428
+    				}
1429
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1430
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1431
+    				}
1432
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1433
+    					$SI->add($data);
1434
+    				}
1074 1435
     				unset($lined);
1075 1436
     				unset($data);
1076
-    			    } else $error = true;
1437
+    			    } else {
1438
+    			    	$error = true;
1439
+    			    }
1077 1440
 			} elseif ($format == 'aprs' && $use_aprs) {
1078 1441
 			    if ($aprs_connect == 0) {
1079 1442
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1098,47 +1461,72 @@  discard block
 block discarded – undo
1098 1461
 				    $aprs_last_tx = time();
1099 1462
 				    $data = array();
1100 1463
 				    //print_r($line);
1101
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1102
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1103
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1464
+				    if (isset($line['address'])) {
1465
+				    	$data['hex'] = $line['address'];
1466
+				    }
1467
+				    if (isset($line['timestamp'])) {
1468
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1469
+				    } else {
1470
+				    	$data['datetime'] = date('Y-m-d H:i:s');
1471
+				    }
1104 1472
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1105 1473
 				    $data['ident'] = $line['ident'];
1106 1474
 				    $data['latitude'] = $line['latitude'];
1107 1475
 				    $data['longitude'] = $line['longitude'];
1108 1476
 				    //$data['verticalrate'] = $line[16];
1109
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1110
-				    else $data['speed'] = 0;
1111
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1112
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1113
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1114
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1477
+				    if (isset($line['speed'])) {
1478
+				    	$data['speed'] = $line['speed'];
1479
+				    } else {
1480
+				    	$data['speed'] = 0;
1481
+				    }
1482
+				    if (isset($line['altitude'])) {
1483
+				    	$data['altitude'] = $line['altitude'];
1484
+				    }
1485
+				    if (isset($line['comment'])) {
1486
+				    	$data['comment'] = $line['comment'];
1487
+				    }
1488
+				    if (isset($line['symbol'])) {
1489
+				    	$data['type'] = $line['symbol'];
1490
+				    }
1491
+				    if (isset($line['heading'])) {
1492
+				    	$data['heading'] = $line['heading'];
1493
+				    }
1115 1494
 				    //else $data['heading'] = 0;
1116
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1117
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1495
+				    if (isset($line['stealth'])) {
1496
+				    	$data['aircraft_type'] = $line['stealth'];
1497
+				    }
1498
+				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) {
1499
+				    	$data['noarchive'] = true;
1500
+				    }
1118 1501
     				    $data['id_source'] = $id_source;
1119 1502
 				    $data['format_source'] = 'aprs';
1120 1503
 				    $data['source_name'] = $line['source'];
1121 1504
 				    $data['source_type'] = 'flarm';
1122
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1505
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
1506
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1507
+    				    }
1123 1508
 				    $currentdate = date('Y-m-d H:i:s');
1124 1509
 				    $aprsdate = strtotime($data['datetime']);
1125 1510
 				    // Accept data if time <= system time + 20s
1126 1511
 				    if (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'])))) {
1127 1512
 					$send = $SI->add($data);
1128 1513
 				    } elseif (isset($line['stealth'])) {
1129
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1130
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1514
+					if ($line['stealth'] != 0) {
1515
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1516
+					} else {
1517
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1518
+					}
1131 1519
 				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1132 1520
 				    } 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') {
1133 1521
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1134
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1522
+					if (isset($globalTracker) && $globalTracker) {
1523
+						$send = $TI->add($data);
1524
+					}
1135 1525
 				    }
1136 1526
 				    unset($data);
1137
-				} 
1138
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1527
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1139 1528
 					echo '!! Weather Station not yet supported'."\n";
1140
-				}
1141
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle')) {
1529
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle')) {
1142 1530
 					echo '!! Car & Trucks not yet supported'."\n";
1143 1531
 				}
1144 1532
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
@@ -1171,25 +1559,42 @@  discard block
 block discarded – undo
1171 1559
     				$data['ground'] = $line[21];
1172 1560
     				$data['emergency'] = $line[19];
1173 1561
     				$data['format_source'] = 'sbs';
1174
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1175
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1562
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1563
+					$data['source_name'] = $globalSources[$nb]['name'];
1564
+				}
1565
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1566
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1567
+    				}
1176 1568
     				$data['id_source'] = $id_source;
1177
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1178
-    				else $error = true;
1569
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1570
+    					$send = $SI->add($data);
1571
+    				} else {
1572
+    					$error = true;
1573
+    				}
1179 1574
     				unset($data);
1180
-    			    } else $error = true;
1575
+    			    } else {
1576
+    			    	$error = true;
1577
+    			    }
1181 1578
 			    if ($error) {
1182 1579
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1183
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
1580
+					if ($globalDebug) {
1581
+						echo "Not a message. Ignoring... \n";
1582
+					}
1184 1583
 				} else {
1185
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
1584
+					if ($globalDebug) {
1585
+						echo "Wrong line format. Ignoring... \n";
1586
+					}
1186 1587
 					if ($globalDebug) {
1187 1588
 						echo $buffer;
1188 1589
 						print_r($line);
1189 1590
 					}
1190 1591
 					//socket_close($r);
1191
-					if ($globalDebug) echo "Reconnect after an error...\n";
1192
-					if ($format == 'aprs') $aprs_connect = 0;
1592
+					if ($globalDebug) {
1593
+						echo "Reconnect after an error...\n";
1594
+					}
1595
+					if ($format == 'aprs') {
1596
+						$aprs_connect = 0;
1597
+					}
1193 1598
 					$sourceer[$nb] = $globalSources[$nb];
1194 1599
 					connect_all($sourceer);
1195 1600
 					$sourceer = array();
@@ -1197,10 +1602,14 @@  discard block
 block discarded – undo
1197 1602
 			    }
1198 1603
 			}
1199 1604
 			// Sleep for xxx microseconds
1200
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1605
+			if (isset($globalSBSSleep)) {
1606
+				usleep($globalSBSSleep);
1607
+			}
1201 1608
 		    } else {
1202 1609
 			if ($format == 'flightgearmp') {
1203
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1610
+			    	if ($globalDebug) {
1611
+			    		echo "Reconnect FlightGear MP...";
1612
+			    	}
1204 1613
 				//@socket_close($r);
1205 1614
 				sleep($globalMinFetch);
1206 1615
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1209,10 +1618,15 @@  discard block
 block discarded – undo
1209 1618
 				break;
1210 1619
 				
1211 1620
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1212
-			    if (isset($tt[$format])) $tt[$format]++;
1213
-			    else $tt[$format] = 0;
1621
+			    if (isset($tt[$format])) {
1622
+			    	$tt[$format]++;
1623
+			    } else {
1624
+			    	$tt[$format] = 0;
1625
+			    }
1214 1626
 			    if ($tt[$format] > 30) {
1215
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1627
+				if ($globalDebug) {
1628
+					echo "ERROR : Reconnect ".$format."...";
1629
+				}
1216 1630
 				//@socket_close($r);
1217 1631
 				sleep(2);
1218 1632
 				$aprs_connect = 0;
@@ -1229,11 +1643,17 @@  discard block
 block discarded – undo
1229 1643
 	    } else {
1230 1644
 		$error = socket_strerror(socket_last_error());
1231 1645
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1232
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1233
-			if (isset($globalDebug)) echo "Restarting...\n";
1646
+			if ($globalDebug) {
1647
+				echo "ERROR : socket_select give this error ".$error . "\n";
1648
+			}
1649
+			if (isset($globalDebug)) {
1650
+				echo "Restarting...\n";
1651
+			}
1234 1652
 			// Restart the script if possible
1235 1653
 			if (is_array($sockets)) {
1236
-			    if ($globalDebug) echo "Shutdown all sockets...";
1654
+			    if ($globalDebug) {
1655
+			    	echo "Shutdown all sockets...";
1656
+			    }
1237 1657
 			    
1238 1658
 			    foreach ($sockets as $sock) {
1239 1659
 				@socket_shutdown($sock,2);
@@ -1241,18 +1661,24 @@  discard block
 block discarded – undo
1241 1661
 			    }
1242 1662
 			    
1243 1663
 			}
1244
-			if ($globalDebug) echo "Restart all connections...";
1664
+			if ($globalDebug) {
1665
+				echo "Restart all connections...";
1666
+			}
1245 1667
 			sleep(2);
1246 1668
 			$time = time();
1247 1669
 			//connect_all($hosts);
1248 1670
 			$aprs_connect = 0;
1249
-			if ($reset > 40) exit('Too many attempts...');
1671
+			if ($reset > 40) {
1672
+				exit('Too many attempts...');
1673
+			}
1250 1674
 			connect_all($globalSources);
1251 1675
 		}
1252 1676
 	    }
1253 1677
 	}
1254 1678
 	if ($globalDaemon === false) {
1255
-	    if ($globalDebug) echo 'Check all...'."\n";
1679
+	    if ($globalDebug) {
1680
+	    	echo 'Check all...'."\n";
1681
+	    }
1256 1682
 	    $SI->checkAll();
1257 1683
 	}
1258 1684
     }
Please login to merge, or discard this patch.