Completed
Push — master ( 0ab128...e37ce2 )
by Yannick
07:35
created
scripts/daemon-spotter.php 1 patch
Braces   +988 added lines, -341 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();
@@ -55,35 +59,62 @@  discard block
 block discarded – undo
55 59
 //elseif (isset($options['source'])) $hosts = array($options['source']);
56 60
 if (isset($options['s'])) {
57 61
     $globalSources = array();
58
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
59
-    else $globalSources[] = array('host' => $options['s']);
60
-} elseif (isset($options['source'])) {
62
+    if (isset($options['format'])) {
63
+    	$globalSources[] = array('host' => $options['s'],'format' => $options['format']);
64
+    } else {
65
+    	$globalSources[] = array('host' => $options['s']);
66
+    }
67
+    } elseif (isset($options['source'])) {
61 68
     $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
63
-    else $globalSources[] = array('host' => $options['source']);
64
-}
69
+    if (isset($options['format'])) {
70
+    	$globalSources[] = array('host' => $options['source'],'format' => $options['format']);
71
+    } else {
72
+    	$globalSources[] = array('host' => $options['source']);
73
+    }
74
+    }
65 75
 if (isset($options['aprsserverhost'])) {
66 76
 	$globalServerAPRS = TRUE;
67 77
 	$globalServerAPRShost = $options['aprsserverhost'];
68 78
 }
69
-if (isset($options['aprsserverport'])) $globalServerAPRSport = $options['aprsserverport'];
70
-if (isset($options['aprsserverssid'])) $globalServerAPRSssid = $options['aprsserverssid'];
71
-if (isset($options['aprsserverpass'])) $globalServerAPRSpass = $options['aprsserverpass'];
72
-if (isset($options['noaprsserver'])) $globalServerAPRS = FALSE; 
73
-if (isset($options['nodaemon'])) $globalDaemon = FALSE;
74
-if (isset($options['server'])) $globalServer = TRUE;
75
-if (isset($options['idsource'])) $id_source = $options['idsource'];
76
-else $id_source = 1;
79
+if (isset($options['aprsserverport'])) {
80
+	$globalServerAPRSport = $options['aprsserverport'];
81
+}
82
+if (isset($options['aprsserverssid'])) {
83
+	$globalServerAPRSssid = $options['aprsserverssid'];
84
+}
85
+if (isset($options['aprsserverpass'])) {
86
+	$globalServerAPRSpass = $options['aprsserverpass'];
87
+}
88
+if (isset($options['noaprsserver'])) {
89
+	$globalServerAPRS = FALSE;
90
+}
91
+if (isset($options['nodaemon'])) {
92
+	$globalDaemon = FALSE;
93
+}
94
+if (isset($options['server'])) {
95
+	$globalServer = TRUE;
96
+}
97
+if (isset($options['idsource'])) {
98
+	$id_source = $options['idsource'];
99
+} else {
100
+	$id_source = 1;
101
+}
77 102
 if (isset($globalServer) && $globalServer) {
78
-    if ($globalDebug) echo "Using Server Mode\n";
103
+    if ($globalDebug) {
104
+    	echo "Using Server Mode\n";
105
+    }
79 106
     $SI=new SpotterServer();
80 107
 /*
81 108
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
82 109
     $SI = new adsb2aprs();
83 110
     $SI->connect();
84 111
 */
85
-} else $SI=new SpotterImport($Connection->db);
86
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
112
+} else {
113
+	$SI=new SpotterImport($Connection->db);
114
+}
115
+if (isset($globalTracker) && $globalTracker) {
116
+	$TI = new TrackerImport($Connection->db);
117
+}
87 118
 if (isset($globalMarine) && $globalMarine) {
88 119
     $AIS = new AIS();
89 120
     $MI = new MarineImport($Connection->db);
@@ -106,7 +137,9 @@  discard block
 block discarded – undo
106 137
 }
107 138
 
108 139
 // let's try and connect
109
-if ($globalDebug) echo "Connecting...\n";
140
+if ($globalDebug) {
141
+	echo "Connecting...\n";
142
+}
110 143
 $use_aprs = false;
111 144
 $aprs_full = false;
112 145
 $reset = 0;
@@ -115,7 +148,9 @@  discard block
 block discarded – undo
115 148
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
116 149
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
117 150
     $reset++;
118
-    if ($globalDebug) echo 'Connect to all...'."\n";
151
+    if ($globalDebug) {
152
+    	echo 'Connect to all...'."\n";
153
+    }
119 154
     foreach ($hosts as $id => $value) {
120 155
 	$host = $value['host'];
121 156
 	$globalSources[$id]['last_exec'] = 0;
@@ -125,22 +160,30 @@  discard block
 block discarded – undo
125 160
         	//$formats[$id] = 'deltadbtxt';
126 161
         	$globalSources[$id]['format'] = 'deltadbtxt';
127 162
         	//$last_exec['deltadbtxt'] = 0;
128
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
163
+        	if ($globalDebug) {
164
+        		echo "Connect to deltadb source (".$host.")...\n";
165
+        	}
129 166
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
130 167
         	//$formats[$id] = 'vatsimtxt';
131 168
         	$globalSources[$id]['format'] = 'vatsimtxt';
132 169
         	//$last_exec['vatsimtxt'] = 0;
133
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
170
+        	if ($globalDebug) {
171
+        		echo "Connect to vatsim source (".$host.")...\n";
172
+        	}
134 173
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
135 174
         	//$formats[$id] = 'aircraftlistjson';
136 175
         	$globalSources[$id]['format'] = 'aircraftlistjson';
137 176
         	//$last_exec['aircraftlistjson'] = 0;
138
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
177
+        	if ($globalDebug) {
178
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
179
+        	}
139 180
     	    } else if (preg_match('/opensky/i',$host)) {
140 181
         	//$formats[$id] = 'aircraftlistjson';
141 182
         	$globalSources[$id]['format'] = 'opensky';
142 183
         	//$last_exec['aircraftlistjson'] = 0;
143
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
184
+        	if ($globalDebug) {
185
+        		echo "Connect to opensky source (".$host.")...\n";
186
+        	}
144 187
     	    /*
145 188
     	    // Disabled for now, site change source format
146 189
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
@@ -157,7 +200,9 @@  discard block
 block discarded – undo
157 200
         	//$formats[$id] = 'planeupdatefaa';
158 201
         	$globalSources[$id]['format'] = 'planeupdatefaa';
159 202
         	//$last_exec['planeupdatefaa'] = 0;
160
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
203
+        	if ($globalDebug) {
204
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
205
+        	}
161 206
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
162 207
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
163 208
         	    exit(0);
@@ -166,29 +211,41 @@  discard block
 block discarded – undo
166 211
         	//$formats[$id] = 'phpvmacars';
167 212
         	$globalSources[$id]['format'] = 'phpvmacars';
168 213
         	//$last_exec['phpvmacars'] = 0;
169
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
214
+        	if ($globalDebug) {
215
+        		echo "Connect to phpvmacars source (".$host.")...\n";
216
+        	}
170 217
             } else if (preg_match('/VAM-json.php$/i',$host)) {
171 218
         	//$formats[$id] = 'phpvmacars';
172 219
         	$globalSources[$id]['format'] = 'vam';
173
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
220
+        	if ($globalDebug) {
221
+        		echo "Connect to Vam source (".$host.")...\n";
222
+        	}
174 223
             } else if (preg_match('/whazzup/i',$host)) {
175 224
         	//$formats[$id] = 'whazzup';
176 225
         	$globalSources[$id]['format'] = 'whazzup';
177 226
         	//$last_exec['whazzup'] = 0;
178
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
227
+        	if ($globalDebug) {
228
+        		echo "Connect to whazzup source (".$host.")...\n";
229
+        	}
179 230
             } else if (preg_match('/airwhere/i',$host)) {
180 231
         	$globalSources[$id]['format'] = 'airwhere';
181
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
232
+        	if ($globalDebug) {
233
+        		echo "Connect to airwhere source (".$host.")...\n";
234
+        	}
182 235
             } else if (preg_match('/recentpireps/i',$host)) {
183 236
         	//$formats[$id] = 'pirepsjson';
184 237
         	$globalSources[$id]['format'] = 'pirepsjson';
185 238
         	//$last_exec['pirepsjson'] = 0;
186
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
239
+        	if ($globalDebug) {
240
+        		echo "Connect to pirepsjson source (".$host.")...\n";
241
+        	}
187 242
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
188 243
         	//$formats[$id] = 'fr24json';
189 244
         	$globalSources[$id]['format'] = 'fr24json';
190 245
         	//$last_exec['fr24json'] = 0;
191
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
246
+        	if ($globalDebug) {
247
+        		echo "Connect to fr24 source (".$host.")...\n";
248
+        	}
192 249
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
193 250
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
194 251
         	    exit(0);
@@ -197,7 +254,9 @@  discard block
 block discarded – undo
197 254
         	//$formats[$id] = 'fr24json';
198 255
         	$globalSources[$id]['format'] = 'myshiptracking';
199 256
         	//$last_exec['fr24json'] = 0;
200
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
257
+        	if ($globalDebug) {
258
+        		echo "Connect to myshiptracking source (".$host.")...\n";
259
+        	}
201 260
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
202 261
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
203 262
         	    exit(0);
@@ -206,17 +265,24 @@  discard block
 block discarded – undo
206 265
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
207 266
         	//$formats[$id] = 'tsv';
208 267
         	$globalSources[$id]['format'] = 'tsv';
209
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
268
+        	if ($globalDebug) {
269
+        		echo "Connect to tsv source (".$host.")...\n";
270
+        	}
210 271
             }
211 272
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
212 273
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
213 274
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
214 275
     		    if ($idf !== false) {
215 276
     			$httpfeeds[$id] = $idf;
216
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
277
+        		if ($globalDebug) {
278
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
279
+        		}
280
+    		    } elseif ($globalDebug) {
281
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
217 282
     		    }
218
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
219
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
283
+    		} elseif ($globalDebug) {
284
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
285
+    		}
220 286
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
221 287
 	    $hostport = explode(':',$host);
222 288
 	    if (isset($hostport[1])) {
@@ -256,17 +322,25 @@  discard block
 block discarded – undo
256 322
         		//$formats[$id] = 'beast';
257 323
         		$globalSources[$id]['format'] = 'beast';
258 324
 		    //} else $formats[$id] = 'sbs';
259
-		    } else $globalSources[$id]['format'] = 'sbs';
325
+		    } else {
326
+		    	$globalSources[$id]['format'] = 'sbs';
327
+		    }
260 328
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
261 329
 		}
262
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
330
+		if ($globalDebug) {
331
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
332
+		}
263 333
             } else {
264
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
334
+		if ($globalDebug) {
335
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
336
+		}
265 337
     	    }
266 338
         }
267 339
     }
268 340
 }
269
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
341
+if (!isset($globalMinFetch)) {
342
+	$globalMinFetch = 15;
343
+}
270 344
 
271 345
 // Initialize all
272 346
 $status = array();
@@ -275,13 +349,19 @@  discard block
 block discarded – undo
275 349
 $formats = array();
276 350
 $last_exec = array();
277 351
 $time = time();
278
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
279
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
280
-else $timeout = 20;
352
+if (isset($globalSourcesTimeout)) {
353
+	$timeout = $globalSourcesTimeOut;
354
+} else if (isset($globalSBS1TimeOut)) {
355
+	$timeout = $globalSBS1TimeOut;
356
+} else {
357
+	$timeout = 20;
358
+}
281 359
 $errno = '';
282 360
 $errstr='';
283 361
 
284
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
362
+if (!isset($globalDaemon)) {
363
+	$globalDaemon = TRUE;
364
+}
285 365
 /* Initiate connections to all the hosts simultaneously */
286 366
 //connect_all($hosts);
287 367
 //connect_all($globalSources);
@@ -307,7 +387,9 @@  discard block
 block discarded – undo
307 387
     if (isset($source['format']) && $source['format'] == 'aprs') {
308 388
 	$aprs_connect = 0;
309 389
 	$use_aprs = true;
310
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
390
+	if (isset($source['port']) && $source['port'] == '10152') {
391
+		$aprs_full = true;
392
+	}
311 393
 	break;
312 394
     }
313 395
 }
@@ -318,25 +400,48 @@  discard block
 block discarded – undo
318 400
 	$aprs_connect = 0;
319 401
 	$aprs_keep = 120;
320 402
 	$aprs_last_tx = time();
321
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
322
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
323
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
324
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
325
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
326
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
327
-	if ($aprs_full) $aprs_filter = '';
328
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
329
-	else $aprs_pass = '-1';
403
+	if (isset($globalAPRSversion)) {
404
+		$aprs_version = $globalAPRSversion;
405
+	} else {
406
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
407
+	}
408
+	if (isset($globalAPRSssid)) {
409
+		$aprs_ssid = $globalAPRSssid;
410
+	} else {
411
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
412
+	}
413
+	if (isset($globalAPRSfilter)) {
414
+		$aprs_filter = $globalAPRSfilter;
415
+	} else {
416
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
417
+	}
418
+	if ($aprs_full) {
419
+		$aprs_filter = '';
420
+	}
421
+	if (isset($globalAPRSpass)) {
422
+		$aprs_pass = $globalAPRSpass;
423
+	} else {
424
+		$aprs_pass = '-1';
425
+	}
330 426
 
331
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
332
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
333
-}
427
+	if ($aprs_filter != '') {
428
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
429
+	} else {
430
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
431
+	}
432
+	}
334 433
 
335 434
 // connected - lets do some work
336
-if ($globalDebug) echo "Connected!\n";
435
+if ($globalDebug) {
436
+	echo "Connected!\n";
437
+}
337 438
 sleep(1);
338
-if ($globalDebug) echo "SCAN MODE \n\n";
339
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
439
+if ($globalDebug) {
440
+	echo "SCAN MODE \n\n";
441
+}
442
+if (!isset($globalCronEnd)) {
443
+	$globalCronEnd = 60;
444
+}
340 445
 $endtime = time()+$globalCronEnd;
341 446
 $i = 1;
342 447
 $tt = array();
@@ -350,20 +455,28 @@  discard block
 block discarded – undo
350 455
 
351 456
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
352 457
 while ($i > 0) {
353
-    if (!$globalDaemon) $i = $endtime-time();
458
+    if (!$globalDaemon) {
459
+    	$i = $endtime-time();
460
+    }
354 461
     // Delete old ATC
355 462
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
356
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
463
+	if ($globalDebug) {
464
+		echo 'Delete old ATC...'."\n";
465
+	}
357 466
         $ATC->deleteOldATC();
358 467
     }
359 468
     
360 469
     if (count($last_exec) == count($globalSources)) {
361 470
 	$max = $globalMinFetch;
362 471
 	foreach ($last_exec as $last) {
363
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
472
+	    if ((time() - $last['last']) < $max) {
473
+	    	$max = time() - $last['last'];
474
+	    }
364 475
 	}
365 476
 	if ($max != $globalMinFetch) {
366
-	    if ($globalDebug) echo 'Sleeping...'."\n";
477
+	    if ($globalDebug) {
478
+	    	echo 'Sleeping...'."\n";
479
+	    }
367 480
 	    sleep($globalMinFetch-$max+2);
368 481
 	}
369 482
     }
@@ -372,11 +485,15 @@  discard block
 block discarded – undo
372 485
     //foreach ($formats as $id => $value) {
373 486
     foreach ($globalSources as $id => $value) {
374 487
 	date_default_timezone_set('UTC');
375
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
488
+	if (!isset($last_exec[$id]['last'])) {
489
+		$last_exec[$id]['last'] = 0;
490
+	}
376 491
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
377 492
 	    //$buffer = $Common->getData($hosts[$id]);
378 493
 	    $buffer = $Common->getData($value['host']);
379
-	    if ($buffer != '') $reset = 0;
494
+	    if ($buffer != '') {
495
+	    	$reset = 0;
496
+	    }
380 497
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
381 498
 	    $buffer = explode('\n',$buffer);
382 499
 	    foreach ($buffer as $line) {
@@ -385,20 +502,41 @@  discard block
 block discarded – undo
385 502
 	            $data = array();
386 503
 	            $data['hex'] = $line[1]; // hex
387 504
 	            $data['ident'] = $line[2]; // ident
388
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
389
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
390
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
391
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
392
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
505
+	            if (isset($line[3])) {
506
+	            	$data['altitude'] = $line[3];
507
+	            }
508
+	            // altitude
509
+	            if (isset($line[4])) {
510
+	            	$data['speed'] = $line[4];
511
+	            }
512
+	            // speed
513
+	            if (isset($line[5])) {
514
+	            	$data['heading'] = $line[5];
515
+	            }
516
+	            // heading
517
+	            if (isset($line[6])) {
518
+	            	$data['latitude'] = $line[6];
519
+	            }
520
+	            // lat
521
+	            if (isset($line[7])) {
522
+	            	$data['longitude'] = $line[7];
523
+	            }
524
+	            // long
393 525
 	            $data['verticalrate'] = ''; // vertical rate
394 526
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
395 527
 	            $data['emergency'] = ''; // emergency
396 528
 		    $data['datetime'] = date('Y-m-d H:i:s');
397 529
 		    $data['format_source'] = 'deltadbtxt';
398 530
     		    $data['id_source'] = $id_source;
399
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
400
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
401
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
531
+		    if (isset($value['name']) && $value['name'] != '') {
532
+		    	$data['source_name'] = $value['name'];
533
+		    }
534
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
535
+		    	$data['noarchive'] = true;
536
+		    }
537
+		    if (isset($value['sourcestats'])) {
538
+		    	$data['sourcestats'] = $value['sourcestats'];
539
+		    }
402 540
     		    $SI->add($data);
403 541
 		    unset($data);
404 542
     		}
@@ -408,7 +546,9 @@  discard block
 block discarded – undo
408 546
 	    date_default_timezone_set('CET');
409 547
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
410 548
 	    date_default_timezone_set('UTC');
411
-	    if ($buffer != '') $reset = 0;
549
+	    if ($buffer != '') {
550
+	    	$reset = 0;
551
+	    }
412 552
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
413 553
 	    $buffer = explode('\n',$buffer);
414 554
 	    foreach ($buffer as $line) {
@@ -417,16 +557,36 @@  discard block
 block discarded – undo
417 557
 		    $add = false;
418 558
 		    $ais_data = $AIS->parse_line(trim($line));
419 559
 		    $data = array();
420
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
421
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
422
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
423
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
424
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
425
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
426
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
427
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
428
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
429
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
560
+		    if (isset($ais_data['ident'])) {
561
+		    	$data['ident'] = $ais_data['ident'];
562
+		    }
563
+		    if (isset($ais_data['mmsi'])) {
564
+		    	$data['mmsi'] = $ais_data['mmsi'];
565
+		    }
566
+		    if (isset($ais_data['speed'])) {
567
+		    	$data['speed'] = $ais_data['speed'];
568
+		    }
569
+		    if (isset($ais_data['heading'])) {
570
+		    	$data['heading'] = $ais_data['heading'];
571
+		    }
572
+		    if (isset($ais_data['latitude'])) {
573
+		    	$data['latitude'] = $ais_data['latitude'];
574
+		    }
575
+		    if (isset($ais_data['longitude'])) {
576
+		    	$data['longitude'] = $ais_data['longitude'];
577
+		    }
578
+		    if (isset($ais_data['status'])) {
579
+		    	$data['status'] = $ais_data['status'];
580
+		    }
581
+		    if (isset($ais_data['type'])) {
582
+		    	$data['type'] = $ais_data['type'];
583
+		    }
584
+		    if (isset($ais_data['imo'])) {
585
+		    	$data['imo'] = $ais_data['imo'];
586
+		    }
587
+		    if (isset($ais_data['callsign'])) {
588
+		    	$data['callsign'] = $ais_data['callsign'];
589
+		    }
430 590
 		    if (isset($ais_data['timestamp'])) {
431 591
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
432 592
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -440,8 +600,12 @@  discard block
 block discarded – undo
440 600
 		    $data['format_source'] = 'aisnmeatxt';
441 601
     		    $data['id_source'] = $id_source;
442 602
 		    //print_r($data);
443
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
444
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
603
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
604
+		    	$data['noarchive'] = true;
605
+		    }
606
+		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
607
+		    	$MI->add($data);
608
+		    }
445 609
 		    unset($data);
446 610
 		}
447 611
     	    }
@@ -461,20 +625,48 @@  discard block
 block discarded – undo
461 625
 			    if ($line != '') {
462 626
 				$ais_data = $AIS->parse_line(trim($line));
463 627
 				$data = array();
464
-				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
465
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
466
-				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
467
-				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
468
-				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
469
-				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
470
-				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
471
-				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
472
-				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
473
-				if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
474
-				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
475
-				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
476
-				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
477
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
628
+				if (isset($ais_data['ident'])) {
629
+					$data['ident'] = $ais_data['ident'];
630
+				}
631
+				if (isset($ais_data['mmsi'])) {
632
+					$data['mmsi'] = $ais_data['mmsi'];
633
+				}
634
+				if (isset($ais_data['speed'])) {
635
+					$data['speed'] = $ais_data['speed'];
636
+				}
637
+				if (isset($ais_data['heading'])) {
638
+					$data['heading'] = $ais_data['heading'];
639
+				}
640
+				if (isset($ais_data['latitude'])) {
641
+					$data['latitude'] = $ais_data['latitude'];
642
+				}
643
+				if (isset($ais_data['longitude'])) {
644
+					$data['longitude'] = $ais_data['longitude'];
645
+				}
646
+				if (isset($ais_data['status'])) {
647
+					$data['status'] = $ais_data['status'];
648
+				}
649
+				if (isset($ais_data['statusid'])) {
650
+					$data['status_id'] = $ais_data['statusid'];
651
+				}
652
+				if (isset($ais_data['type'])) {
653
+					$data['type'] = $ais_data['type'];
654
+				}
655
+				if (isset($ais_data['typeid'])) {
656
+					$data['type_id'] = $ais_data['typeid'];
657
+				}
658
+				if (isset($ais_data['imo'])) {
659
+					$data['imo'] = $ais_data['imo'];
660
+				}
661
+				if (isset($ais_data['callsign'])) {
662
+					$data['callsign'] = $ais_data['callsign'];
663
+				}
664
+				if (isset($ais_data['destination'])) {
665
+					$data['arrival_code'] = $ais_data['destination'];
666
+				}
667
+				if (isset($ais_data['eta_ts'])) {
668
+					$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
669
+				}
478 670
 				if (isset($ais_data['timestamp'])) {
479 671
 				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
480 672
 				} else {
@@ -482,18 +674,27 @@  discard block
 block discarded – undo
482 674
 				}
483 675
 				$data['format_source'] = 'aisnmeahttp';
484 676
 				$data['id_source'] = $id_source;
485
-				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
486
-				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
677
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
678
+					$data['noarchive'] = true;
679
+				}
680
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
681
+					$MI->add($data);
682
+				}
487 683
 				unset($data);
488 684
 			    }
489 685
 			}
490 686
 		    }
491 687
 		} else {
492 688
 		    $format = $value['format'];
493
-		    if (isset($tt[$format])) $tt[$format]++;
494
-		    else $tt[$format] = 0;
689
+		    if (isset($tt[$format])) {
690
+		    	$tt[$format]++;
691
+		    } else {
692
+		    	$tt[$format] = 0;
693
+		    }
495 694
 		    if ($tt[$format] > 30) {
496
-			if ($globalDebug) echo 'Reconnect...'."\n";
695
+			if ($globalDebug) {
696
+				echo 'Reconnect...'."\n";
697
+			}
497 698
 			sleep(2);
498 699
 			$sourceeen[] = $value;
499 700
 			connect_all($sourceeen);
@@ -523,7 +724,9 @@  discard block
 block discarded – undo
523 724
 			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
524 725
 			    $data['format_source'] = 'myshiptracking';
525 726
 			    $data['id_source'] = $id_source;
526
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
727
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
728
+			    	$data['noarchive'] = true;
729
+			    }
527 730
 			    $MI->add($data);
528 731
 			    unset($data);
529 732
 			}
@@ -543,7 +746,9 @@  discard block
 block discarded – undo
543 746
 			    $data['callsign'] = $line['callsign'];
544 747
 			    $data['mmsi'] = $line['mmsi'];
545 748
 			    $data['speed'] = $line['sog'];
546
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
749
+			    if ($line['heading'] != '511') {
750
+			    	$data['heading'] = $line['heading'];
751
+			    }
547 752
 			    $data['latitude'] = $line['latitude'];
548 753
 			    $data['longitude'] = $line['longitude'];
549 754
 			    $data['type_id'] = $line['shiptype'];
@@ -551,7 +756,9 @@  discard block
 block discarded – undo
551 756
 			    $data['datetime'] = $line['time'];
552 757
 			    $data['format_source'] = 'boatbeaconapp';
553 758
 			    $data['id_source'] = $id_source;
554
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
759
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
760
+			    	$data['noarchive'] = true;
761
+			    }
555 762
 			    $MI->add($data);
556 763
 			    unset($data);
557 764
 			}
@@ -567,22 +774,44 @@  discard block
 block discarded – undo
567 774
 		if (isset($all_data['features'][0]['id'])) {
568 775
 		    foreach ($all_data['features'] as $line) {
569 776
 			$data = array();
570
-			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
571
-			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
572
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = $line['properties']['mmsi'];
573
-			if (isset($line['properties']['imo'])) $data['mmsi'] = $line['properties']['imo'];
574
-			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
575
-			if (isset($line['properties']['heading'])) $data['heading'] = $line['properties']['heading'];
777
+			if (isset($line['properties']['name'])) {
778
+				$data['ident'] = $line['properties']['name'];
779
+			}
780
+			if (isset($line['properties']['callsign'])) {
781
+				$data['callsign'] = $line['properties']['callsign'];
782
+			}
783
+			if (isset($line['properties']['mmsi'])) {
784
+				$data['mmsi'] = $line['properties']['mmsi'];
785
+			}
786
+			if (isset($line['properties']['imo'])) {
787
+				$data['mmsi'] = $line['properties']['imo'];
788
+			}
789
+			if (isset($line['properties']['speed'])) {
790
+				$data['speed'] = $line['properties']['speed'];
791
+			}
792
+			if (isset($line['properties']['heading'])) {
793
+				$data['heading'] = $line['properties']['heading'];
794
+			}
576 795
 			$data['latitude'] = $line['geometry']['coordinates'][1];
577 796
 			$data['longitude'] = $line['geometry']['coordinates'][0];
578
-			if (isset($line['properties']['vesselType'])) $data['type'] = $line['properties']['vesselType'];
579
-			if (isset($line['properties']['destination'])) $data['arrival_code'] = $line['properties']['destination'];
580
-			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') $data['arrival_date'] = $line['properties']['eta'];
797
+			if (isset($line['properties']['vesselType'])) {
798
+				$data['type'] = $line['properties']['vesselType'];
799
+			}
800
+			if (isset($line['properties']['destination'])) {
801
+				$data['arrival_code'] = $line['properties']['destination'];
802
+			}
803
+			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') {
804
+				$data['arrival_date'] = $line['properties']['eta'];
805
+			}
581 806
 			$data['format_source'] = 'boatnerd';
582 807
 			$data['id_source'] = $id_source;
583 808
 			$data['datetime'] = date('Y-m-d H:i:s');
584
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
585
-			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
809
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
810
+				$data['noarchive'] = true;
811
+			}
812
+			if ($line['properties']['vesselType'] != 'Navigation Aid') {
813
+				$MI->add($data);
814
+			}
586 815
 			unset($data);
587 816
 		    }
588 817
 		}
@@ -593,7 +822,9 @@  discard block
 block discarded – undo
593 822
 	    echo 'download...';
594 823
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
595 824
 	    echo 'done !'."\n";
596
-	    if ($buffer != '') $reset = 0;
825
+	    if ($buffer != '') {
826
+	    	$reset = 0;
827
+	    }
597 828
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
598 829
 	    $buffer = explode('\n',$buffer);
599 830
 	    foreach ($buffer as $line) {
@@ -618,7 +849,9 @@  discard block
 block discarded – undo
618 849
 		    //$data['etaTime'] = substr($line,135,5);
619 850
 		    $data['format_source'] = 'shipplotter';
620 851
     		    $data['id_source'] = $id_source;
621
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
852
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
853
+		    	$data['noarchive'] = true;
854
+		    }
622 855
 		    //print_r($data);
623 856
 		    echo 'Add...'."\n";
624 857
 		    $MI->add($data);
@@ -638,16 +871,28 @@  discard block
 block discarded – undo
638 871
     		    $line = explode(':', $line);
639 872
     		    if (count($line) > 30 && $line[0] != 'callsign') {
640 873
 			$data = array();
641
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
642
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
874
+			if (isset($line[37]) && $line[37] != '') {
875
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
876
+			} else {
877
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
878
+			}
643 879
 			$data['pilot_id'] = $line[1];
644 880
 			$data['pilot_name'] = $line[2];
645 881
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
646 882
 			$data['ident'] = $line[0]; // ident
647
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
883
+			if ($line[7] != '' && $line[7] != 0) {
884
+				$data['altitude'] = $line[7];
885
+			}
886
+			// altitude
648 887
 			$data['speed'] = $line[8]; // speed
649
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
650
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
888
+			if (isset($line[45])) {
889
+				$data['heading'] = $line[45];
890
+			}
891
+			// heading
892
+			elseif (isset($line[38])) {
893
+				$data['heading'] = $line[38];
894
+			}
895
+			// heading
651 896
 			$data['latitude'] = $line[5]; // lat
652 897
 	        	$data['longitude'] = $line[6]; // long
653 898
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -663,7 +908,9 @@  discard block
 block discarded – undo
663 908
 			$data['frequency'] = $line[4];
664 909
 			$data['type'] = $line[18];
665 910
 			$data['range'] = $line[19];
666
-			if (isset($line[35])) $data['info'] = $line[35];
911
+			if (isset($line[35])) {
912
+				$data['info'] = $line[35];
913
+			}
667 914
     			$data['id_source'] = $id_source;
668 915
 	    		//$data['arrival_airport_time'] = ;
669 916
 	    		if ($line[9] != '') {
@@ -677,27 +924,47 @@  discard block
 block discarded – undo
677 924
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
678 925
 	    		*/
679 926
 	    		$data['format_source'] = $value['format'];
680
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
681
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
682
-    			if ($line[3] == 'PILOT') $SI->add($data);
683
-			elseif ($line[3] == 'ATC') {
927
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
928
+				$data['noarchive'] = true;
929
+			}
930
+			if (isset($value['name']) && $value['name'] != '') {
931
+				$data['source_name'] = $value['name'];
932
+			}
933
+    			if ($line[3] == 'PILOT') {
934
+    				$SI->add($data);
935
+    			} elseif ($line[3] == 'ATC') {
684 936
 				//print_r($data);
685 937
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
686 938
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
687 939
 				$typec = substr($data['ident'],-3);
688
-				if ($typec == 'APP') $data['type'] = 'Approach';
689
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
690
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
691
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
692
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
693
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
694
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
695
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
696
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
697
-				if (!isset($data['source_name'])) $data['source_name'] = '';
940
+				if ($typec == 'APP') {
941
+					$data['type'] = 'Approach';
942
+				} elseif ($typec == 'TWR') {
943
+					$data['type'] = 'Tower';
944
+				} elseif ($typec == 'OBS') {
945
+					$data['type'] = 'Observer';
946
+				} elseif ($typec == 'GND') {
947
+					$data['type'] = 'Ground';
948
+				} elseif ($typec == 'DEL') {
949
+					$data['type'] = 'Delivery';
950
+				} elseif ($typec == 'DEP') {
951
+					$data['type'] = 'Departure';
952
+				} elseif ($typec == 'FSS') {
953
+					$data['type'] = 'Flight Service Station';
954
+				} elseif ($typec == 'CTR') {
955
+					$data['type'] = 'Control Radar or Centre';
956
+				} elseif ($data['type'] == '') {
957
+					$data['type'] = 'Observer';
958
+				}
959
+				if (!isset($data['source_name'])) {
960
+					$data['source_name'] = '';
961
+				}
698 962
 				if (isset($ATC)) {
699
-					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']);
700
-					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']);
963
+					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) {
964
+						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']);
965
+					} else {
966
+						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']);
967
+					}
701 968
 				}
702 969
 			}
703 970
     			unset($data);
@@ -719,13 +986,19 @@  discard block
 block discarded – undo
719 986
 			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
720 987
 			$data['latitude'] = (float)$line['pktLatitude'];
721 988
 			$data['longitude'] = (float)$line['pktLongitude'];
722
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
723
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
989
+			if ((float)$line['pktTrack'] != 0) {
990
+				$data['heading'] = (float)$line['pktTrack'];
991
+			}
992
+			if ((int)$line['pktSpeed'] != 0) {
993
+				$data['speed'] = (int)$line['pktSpeed'];
994
+			}
724 995
 			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
725 996
 			$data['pilot_id'] = (int)$line['pktPilotID'];
726 997
 			$data['aircraft_icao'] = 'PARAGLIDER';
727 998
 			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
728
-			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
999
+			if (isset($pilot_data[4])) {
1000
+				$data['pilot_name'] = $pilot_data[4];
1001
+			}
729 1002
 			$data['format_source'] = $value['format'];
730 1003
 			$SI->add($data);
731 1004
 			unset($data);
@@ -761,27 +1034,61 @@  discard block
 block discarded – undo
761 1034
 		foreach ($all_data['acList'] as $line) {
762 1035
 		    $data = array();
763 1036
 		    $data['hex'] = $line['Icao']; // hex
764
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
765
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
766
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
767
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
768
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
769
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1037
+		    if (isset($line['Call'])) {
1038
+		    	$data['ident'] = $line['Call'];
1039
+		    }
1040
+		    // ident
1041
+		    if (isset($line['Alt'])) {
1042
+		    	$data['altitude'] = $line['Alt'];
1043
+		    }
1044
+		    // altitude
1045
+		    if (isset($line['Spd'])) {
1046
+		    	$data['speed'] = $line['Spd'];
1047
+		    }
1048
+		    // speed
1049
+		    if (isset($line['Trak'])) {
1050
+		    	$data['heading'] = $line['Trak'];
1051
+		    }
1052
+		    // heading
1053
+		    if (isset($line['Lat'])) {
1054
+		    	$data['latitude'] = $line['Lat'];
1055
+		    }
1056
+		    // lat
1057
+		    if (isset($line['Long'])) {
1058
+		    	$data['longitude'] = $line['Long'];
1059
+		    }
1060
+		    // long
770 1061
 		    //$data['verticalrate'] = $line['']; // verticale rate
771
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1062
+		    if (isset($line['Sqk'])) {
1063
+		    	$data['squawk'] = $line['Sqk'];
1064
+		    }
1065
+		    // squawk
772 1066
 		    $data['emergency'] = ''; // emergency
773
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
1067
+		    if (isset($line['Reg'])) {
1068
+		    	$data['registration'] = $line['Reg'];
1069
+		    }
774 1070
 		    
775
-		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
776
-		    else $data['datetime'] = date('Y-m-d H:i:s');
1071
+		    if (isset($line['PosTime'])) {
1072
+		    	$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1073
+		    } else {
1074
+		    	$data['datetime'] = date('Y-m-d H:i:s');
1075
+		    }
777 1076
 		    
778 1077
 		    //$data['datetime'] = date('Y-m-d H:i:s');
779
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1078
+		    if (isset($line['Type'])) {
1079
+		    	$data['aircraft_icao'] = $line['Type'];
1080
+		    }
780 1081
 	    	    $data['format_source'] = 'aircraftlistjson';
781 1082
 		    $data['id_source'] = $id_source;
782
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
783
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
784
-		    if (isset($data['latitude'])) $SI->add($data);
1083
+		    if (isset($value['name']) && $value['name'] != '') {
1084
+		    	$data['source_name'] = $value['name'];
1085
+		    }
1086
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1087
+		    	$data['noarchive'] = true;
1088
+		    }
1089
+		    if (isset($data['latitude'])) {
1090
+		    	$SI->add($data);
1091
+		    }
785 1092
 		    unset($data);
786 1093
 		}
787 1094
 	    } elseif (is_array($all_data)) {
@@ -798,12 +1105,19 @@  discard block
 block discarded – undo
798 1105
 		    $data['verticalrate'] = $line['vrt']; // verticale rate
799 1106
 		    $data['squawk'] = $line['squawk']; // squawk
800 1107
 		    $data['emergency'] = ''; // emergency
801
-		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
802
-		    else $data['datetime'] = date('Y-m-d H:i:s');
1108
+		    if (isset($line['PosTime'])) {
1109
+		    	$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1110
+		    } else {
1111
+		    	$data['datetime'] = date('Y-m-d H:i:s');
1112
+		    }
803 1113
 	    	    $data['format_source'] = 'aircraftlistjson';
804 1114
     		    $data['id_source'] = $id_source;
805
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
806
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1115
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1116
+		    	$data['noarchive'] = true;
1117
+		    }
1118
+		    if (isset($value['name']) && $value['name'] != '') {
1119
+		    	$data['source_name'] = $value['name'];
1120
+		    }
807 1121
 		    $SI->add($data);
808 1122
 		    unset($data);
809 1123
 		}
@@ -839,8 +1153,12 @@  discard block
 block discarded – undo
839 1153
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
840 1154
 	    	    $data['format_source'] = 'planeupdatefaa';
841 1155
     		    $data['id_source'] = $id_source;
842
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
843
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1156
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1157
+		    	$data['noarchive'] = true;
1158
+		    }
1159
+		    if (isset($value['name']) && $value['name'] != '') {
1160
+		    	$data['source_name'] = $value['name'];
1161
+		    }
844 1162
 		    $SI->add($data);
845 1163
 		    unset($data);
846 1164
 		}
@@ -869,7 +1187,9 @@  discard block
 block discarded – undo
869 1187
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
870 1188
 	    	    $data['format_source'] = 'opensky';
871 1189
     		    $data['id_source'] = $id_source;
872
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1190
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1191
+		    	$data['noarchive'] = true;
1192
+		    }
873 1193
 		    $SI->add($data);
874 1194
 		    unset($data);
875 1195
 		}
@@ -881,7 +1201,9 @@  discard block
 block discarded – undo
881 1201
 	    //$buffer = $Common->getData($hosts[$id]);
882 1202
 	    $buffer = $Common->getData($value['host']);
883 1203
 	    $all_data = json_decode($buffer,true);
884
-	    if (!empty($all_data)) $reset = 0;
1204
+	    if (!empty($all_data)) {
1205
+	    	$reset = 0;
1206
+	    }
885 1207
 	    foreach ($all_data as $key => $line) {
886 1208
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
887 1209
 		    $data = array();
@@ -902,8 +1224,12 @@  discard block
 block discarded – undo
902 1224
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
903 1225
 	    	    $data['format_source'] = 'fr24json';
904 1226
     		    $data['id_source'] = $id_source;
905
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
906
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1227
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1228
+		    	$data['noarchive'] = true;
1229
+		    }
1230
+		    if (isset($value['name']) && $value['name'] != '') {
1231
+		    	$data['source_name'] = $value['name'];
1232
+		    }
907 1233
 		    $SI->add($data);
908 1234
 		    unset($data);
909 1235
 		}
@@ -927,24 +1253,42 @@  discard block
 block discarded – undo
927 1253
 		    if (isset($line['inf'])) {
928 1254
 			$data = array();
929 1255
 			$data['hex'] = $line['inf']['ia'];
930
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1256
+			if (isset($line['inf']['cs'])) {
1257
+				$data['ident'] = $line['inf']['cs'];
1258
+			}
1259
+			//$line[13]
931 1260
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
932
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
933
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1261
+	    		if (isset($line['inf']['gs'])) {
1262
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1263
+	    		}
1264
+	    		// speed
1265
+	    		if (isset($line['inf']['tr'])) {
1266
+	    			$data['heading'] = $line['inf']['tr'];
1267
+	    		}
1268
+	    		// heading
934 1269
 	    		$data['latitude'] = $line['pt'][0]; // lat
935 1270
 	    		$data['longitude'] = $line['pt'][1]; // long
936 1271
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
937
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1272
+	    		if (isset($line['inf']['sq'])) {
1273
+	    			$data['squawk'] = $line['inf']['sq'];
1274
+	    		}
1275
+	    		// squawk
938 1276
 	    		//$data['aircraft_icao'] = $line[8];
939
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1277
+	    		if (isset($line['inf']['rc'])) {
1278
+	    			$data['registration'] = $line['inf']['rc'];
1279
+	    		}
940 1280
 			//$data['departure_airport_iata'] = $line[11];
941 1281
 			//$data['arrival_airport_iata'] = $line[12];
942 1282
 	    		//$data['emergency'] = ''; // emergency
943 1283
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
944 1284
 	    		$data['format_source'] = 'radarvirtueljson';
945 1285
     			$data['id_source'] = $id_source;
946
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
947
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1286
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1287
+				$data['noarchive'] = true;
1288
+			}
1289
+			if (isset($value['name']) && $value['name'] != '') {
1290
+				$data['source_name'] = $value['name'];
1291
+			}
948 1292
 			$SI->add($data);
949 1293
 			unset($data);
950 1294
 		    }
@@ -965,30 +1309,65 @@  discard block
 block discarded – undo
965 1309
 		    $data['id'] = $line['id'];
966 1310
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
967 1311
 		    $data['ident'] = $line['callsign']; // ident
968
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
969
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
970
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
971
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
972
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
973
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1312
+		    if (isset($line['pilotid'])) {
1313
+		    	$data['pilot_id'] = $line['pilotid'];
1314
+		    }
1315
+		    // pilot id
1316
+		    if (isset($line['name'])) {
1317
+		    	$data['pilot_name'] = $line['name'];
1318
+		    }
1319
+		    // pilot name
1320
+		    if (isset($line['alt'])) {
1321
+		    	$data['altitude'] = $line['alt'];
1322
+		    }
1323
+		    // altitude
1324
+		    if (isset($line['gs'])) {
1325
+		    	$data['speed'] = $line['gs'];
1326
+		    }
1327
+		    // speed
1328
+		    if (isset($line['heading'])) {
1329
+		    	$data['heading'] = $line['heading'];
1330
+		    }
1331
+		    // heading
1332
+		    if (isset($line['route'])) {
1333
+		    	$data['waypoints'] = $line['route'];
1334
+		    }
1335
+		    // route
974 1336
 		    $data['latitude'] = $line['lat']; // lat
975 1337
 		    $data['longitude'] = $line['lon']; // long
976 1338
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
977 1339
 		    //$data['squawk'] = $line['squawk']; // squawk
978 1340
 		    //$data['emergency'] = ''; // emergency
979
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
980
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
981
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1341
+		    if (isset($line['depicao'])) {
1342
+		    	$data['departure_airport_icao'] = $line['depicao'];
1343
+		    }
1344
+		    if (isset($line['deptime'])) {
1345
+		    	$data['departure_airport_time'] = $line['deptime'];
1346
+		    }
1347
+		    if (isset($line['arricao'])) {
1348
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1349
+		    }
982 1350
 		    //$data['arrival_airport_time'] = $line['arrtime'];
983
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
984
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
985
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
986
-		    else $data['info'] = '';
1351
+		    if (isset($line['aircraft'])) {
1352
+		    	$data['aircraft_icao'] = $line['aircraft'];
1353
+		    }
1354
+		    if (isset($line['transponder'])) {
1355
+		    	$data['squawk'] = $line['transponder'];
1356
+		    }
1357
+		    if (isset($line['atis'])) {
1358
+		    	$data['info'] = $line['atis'];
1359
+		    } else {
1360
+		    	$data['info'] = '';
1361
+		    }
987 1362
 		    $data['format_source'] = 'pireps';
988 1363
     		    $data['id_source'] = $id_source;
989 1364
 		    $data['datetime'] = date('Y-m-d H:i:s');
990
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
991
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1365
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1366
+		    	$data['noarchive'] = true;
1367
+		    }
1368
+		    if (isset($value['name']) && $value['name'] != '') {
1369
+		    	$data['source_name'] = $value['name'];
1370
+		    }
992 1371
 		    if ($line['icon'] == 'plane') {
993 1372
 			$SI->add($data);
994 1373
 		    //    print_r($data);
@@ -997,16 +1376,28 @@  discard block
 block discarded – undo
997 1376
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
998 1377
 			$typec = substr($data['ident'],-3);
999 1378
 			$data['type'] = '';
1000
-			if ($typec == 'APP') $data['type'] = 'Approach';
1001
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
1002
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
1003
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
1004
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
1005
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
1006
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
1007
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
1008
-			else $data['type'] = 'Observer';
1009
-			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']);
1379
+			if ($typec == 'APP') {
1380
+				$data['type'] = 'Approach';
1381
+			} elseif ($typec == 'TWR') {
1382
+				$data['type'] = 'Tower';
1383
+			} elseif ($typec == 'OBS') {
1384
+				$data['type'] = 'Observer';
1385
+			} elseif ($typec == 'GND') {
1386
+				$data['type'] = 'Ground';
1387
+			} elseif ($typec == 'DEL') {
1388
+				$data['type'] = 'Delivery';
1389
+			} elseif ($typec == 'DEP') {
1390
+				$data['type'] = 'Departure';
1391
+			} elseif ($typec == 'FSS') {
1392
+				$data['type'] = 'Flight Service Station';
1393
+			} elseif ($typec == 'CTR') {
1394
+				$data['type'] = 'Control Radar or Centre';
1395
+			} else {
1396
+				$data['type'] = 'Observer';
1397
+			}
1398
+			if (isset($ATC)) {
1399
+				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']);
1400
+			}
1010 1401
 		    }
1011 1402
 		    unset($data);
1012 1403
 		}
@@ -1016,7 +1407,9 @@  discard block
 block discarded – undo
1016 1407
     	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
1017 1408
     	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
1018 1409
 	    //$buffer = $Common->getData($hosts[$id]);
1019
-	    if ($globalDebug) echo 'Get Data...'."\n";
1410
+	    if ($globalDebug) {
1411
+	    	echo 'Get Data...'."\n";
1412
+	    }
1020 1413
 	    $buffer = $Common->getData($value['host']);
1021 1414
 	    $all_data = json_decode($buffer,true);
1022 1415
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1024,10 +1417,16 @@  discard block
 block discarded – undo
1024 1417
 		foreach ($all_data as $line) {
1025 1418
 	    	    $data = array();
1026 1419
 	    	    //$data['id'] = $line['id']; // id not usable
1027
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1420
+	    	    if (isset($line['pilotid'])) {
1421
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1422
+	    	    }
1028 1423
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1029
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1030
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1424
+	    	    if (isset($line['pilotname'])) {
1425
+	    	    	$data['pilot_name'] = $line['pilotname'];
1426
+	    	    }
1427
+	    	    if (isset($line['pilotid'])) {
1428
+	    	    	$data['pilot_id'] = $line['pilotid'];
1429
+	    	    }
1031 1430
 	    	    $data['ident'] = $line['flightnum']; // ident
1032 1431
 	    	    $data['altitude'] = $line['alt']; // altitude
1033 1432
 	    	    $data['speed'] = $line['gs']; // speed
@@ -1045,28 +1444,44 @@  discard block
 block discarded – undo
1045 1444
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
1046 1445
     		    $data['arrival_airport_time'] = $line['arrtime'];
1047 1446
     		    $data['registration'] = $line['aircraft'];
1048
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1049
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1447
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1448
+		    	$data['noarchive'] = true;
1449
+		    }
1450
+		    if (isset($line['route'])) {
1451
+		    	$data['waypoints'] = $line['route'];
1452
+		    }
1453
+		    // route
1050 1454
 		    if (isset($line['aircraftname'])) {
1051 1455
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1052 1456
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1053 1457
 	    		$aircraft_data = explode('-',$line['aircraftname']);
1054
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1055
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1056
-	    		else {
1458
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) {
1459
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1460
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) {
1461
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1462
+	    		} else {
1057 1463
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1058
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1059
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1464
+	    		    if (isset($aircraft_data[1])) {
1465
+	    		    	$data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1466
+	    		    } else {
1467
+	    		    	$data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1468
+	    		    }
1060 1469
 	    		}
1061 1470
 	    	    }
1062
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1471
+    		    if (isset($line['route'])) {
1472
+    		    	$data['waypoints'] = $line['route'];
1473
+    		    }
1063 1474
     		    $data['id_source'] = $id_source;
1064 1475
 	    	    $data['format_source'] = 'phpvmacars';
1065
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1476
+		    if (isset($value['name']) && $value['name'] != '') {
1477
+		    	$data['source_name'] = $value['name'];
1478
+		    }
1066 1479
 		    $SI->add($data);
1067 1480
 		    unset($data);
1068 1481
 		}
1069
-		if ($globalDebug) echo 'No more data...'."\n";
1482
+		if ($globalDebug) {
1483
+			echo 'No more data...'."\n";
1484
+		}
1070 1485
 		unset($buffer);
1071 1486
 		unset($all_data);
1072 1487
 	    }
@@ -1074,7 +1489,9 @@  discard block
 block discarded – undo
1074 1489
     	    $last_exec[$id]['last'] = time();
1075 1490
     	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
1076 1491
 	    //$buffer = $Common->getData($hosts[$id]);
1077
-	    if ($globalDebug) echo 'Get Data...'."\n";
1492
+	    if ($globalDebug) {
1493
+	    	echo 'Get Data...'."\n";
1494
+	    }
1078 1495
 	    $buffer = $Common->getData($value['host']);
1079 1496
 	    $all_data = json_decode($buffer,true);
1080 1497
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1103,16 +1520,25 @@  discard block
 block discarded – undo
1103 1520
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
1104 1521
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
1105 1522
     		    //$data['registration'] = $line['aircraft'];
1106
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1523
+		    if (isset($line['route'])) {
1524
+		    	$data['waypoints'] = $line['route'];
1525
+		    }
1526
+		    // route
1107 1527
 	    	    $data['aircraft_icao'] = $line['plane_type'];
1108 1528
     		    $data['id_source'] = $id_source;
1109 1529
 	    	    $data['format_source'] = 'vam';
1110
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1111
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1530
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1531
+		    	$data['noarchive'] = true;
1532
+		    }
1533
+		    if (isset($value['name']) && $value['name'] != '') {
1534
+		    	$data['source_name'] = $value['name'];
1535
+		    }
1112 1536
 		    $SI->add($data);
1113 1537
 		    unset($data);
1114 1538
 		}
1115
-		if ($globalDebug) echo 'No more data...'."\n";
1539
+		if ($globalDebug) {
1540
+			echo 'No more data...'."\n";
1541
+		}
1116 1542
 		unset($buffer);
1117 1543
 		unset($all_data);
1118 1544
 	    }
@@ -1120,7 +1546,9 @@  discard block
 block discarded – undo
1120 1546
     	    $last_exec[$id]['last'] = time();
1121 1547
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1122 1548
 	} 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') {
1123
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1549
+	    if (function_exists('pcntl_fork')) {
1550
+	    	pcntl_signal_dispatch();
1551
+	    }
1124 1552
     	    //$last_exec[$id]['last'] = time();
1125 1553
 
1126 1554
 	    //$read = array( $sockets[$id] );
@@ -1128,7 +1556,9 @@  discard block
 block discarded – undo
1128 1556
 	    $write = NULL;
1129 1557
 	    $e = NULL;
1130 1558
 	    $n = socket_select($read, $write, $e, $timeout);
1131
-	    if ($e != NULL) var_dump($e);
1559
+	    if ($e != NULL) {
1560
+	    	var_dump($e);
1561
+	    }
1132 1562
 	    if ($n > 0) {
1133 1563
 		$reset = 0;
1134 1564
 		foreach ($read as $nb => $r) {
@@ -1149,12 +1579,16 @@  discard block
 block discarded – undo
1149 1579
 		    //$SI::del();
1150 1580
 		    if ($format == 'vrstcp') {
1151 1581
 			$buffer = explode('},{',$buffer);
1152
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1582
+		    } else {
1583
+		    	$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1584
+		    }
1153 1585
 		    // SBS format is CSV format
1154 1586
 		    if ($buffer !== FALSE && $buffer != '') {
1155 1587
 			$tt[$format] = 0;
1156 1588
 			if ($format == 'acarssbs3') {
1157
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1589
+			    if ($globalDebug) {
1590
+			    	echo 'ACARS : '.$buffer."\n";
1591
+			    }
1158 1592
 			    $ACARS->add(trim($buffer));
1159 1593
 			    $ACARS->deleteLiveAcarsData();
1160 1594
 			} elseif ($format == 'raw') {
@@ -1163,30 +1597,70 @@  discard block
 block discarded – undo
1163 1597
 			    if (is_array($data)) {
1164 1598
 				$data['datetime'] = date('Y-m-d H:i:s');
1165 1599
 				$data['format_source'] = 'raw';
1166
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1167
-				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1168
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1169
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1600
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1601
+					$data['source_name'] = $globalSources[$nb]['name'];
1602
+				}
1603
+				if (isset($globalSources[$nb]['sourcestats'])) {
1604
+					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1605
+				}
1606
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1607
+					$data['noarchive'] = true;
1608
+				}
1609
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1610
+					$SI->add($data);
1611
+				}
1170 1612
 			    }
1171 1613
 			} elseif ($format == 'ais') {
1172 1614
 			    $ais_data = $AIS->parse_line(trim($buffer));
1173 1615
 			    $data = array();
1174
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1175
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1176
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1177
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1178
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1179
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1180
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1181
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1182
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1183
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1184
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1185
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1186
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1187
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1188
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1189
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1616
+			    if (isset($ais_data['ident'])) {
1617
+			    	$data['ident'] = $ais_data['ident'];
1618
+			    }
1619
+			    if (isset($ais_data['mmsi'])) {
1620
+			    	$data['mmsi'] = $ais_data['mmsi'];
1621
+			    }
1622
+			    if (isset($ais_data['speed'])) {
1623
+			    	$data['speed'] = $ais_data['speed'];
1624
+			    }
1625
+			    if (isset($ais_data['heading'])) {
1626
+			    	$data['heading'] = $ais_data['heading'];
1627
+			    }
1628
+			    if (isset($ais_data['latitude'])) {
1629
+			    	$data['latitude'] = $ais_data['latitude'];
1630
+			    }
1631
+			    if (isset($ais_data['longitude'])) {
1632
+			    	$data['longitude'] = $ais_data['longitude'];
1633
+			    }
1634
+			    if (isset($ais_data['status'])) {
1635
+			    	$data['status'] = $ais_data['status'];
1636
+			    }
1637
+			    if (isset($ais_data['statusid'])) {
1638
+			    	$data['status_id'] = $ais_data['statusid'];
1639
+			    }
1640
+			    if (isset($ais_data['type'])) {
1641
+			    	$data['type'] = $ais_data['type'];
1642
+			    }
1643
+			    if (isset($ais_data['imo'])) {
1644
+			    	$data['imo'] = $ais_data['imo'];
1645
+			    }
1646
+			    if (isset($ais_data['callsign'])) {
1647
+			    	$data['callsign'] = $ais_data['callsign'];
1648
+			    }
1649
+			    if (isset($ais_data['destination'])) {
1650
+			    	$data['arrival_code'] = $ais_data['destination'];
1651
+			    }
1652
+			    if (isset($ais_data['eta_ts'])) {
1653
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1654
+			    }
1655
+			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1656
+			    	$data['noarchive'] = true;
1657
+			    }
1658
+			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1659
+			    	$data['source_name'] = $globalSources[$nb]['name'];
1660
+			    }
1661
+			    if (isset($globalSources[$nb]['sourcestats'])) {
1662
+			    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1663
+			    }
1190 1664
 
1191 1665
 			    if (isset($ais_data['timestamp'])) {
1192 1666
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1195,7 +1669,9 @@  discard block
 block discarded – undo
1195 1669
 			    }
1196 1670
 			    $data['format_source'] = 'aisnmea';
1197 1671
     			    $data['id_source'] = $id_source;
1198
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1672
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
1673
+			    	$MI->add($data);
1674
+			    }
1199 1675
 			    unset($data);
1200 1676
                         } elseif ($format == 'flightgearsp') {
1201 1677
                     	    //echo $buffer."\n";
@@ -1213,12 +1689,18 @@  discard block
 block discarded – undo
1213 1689
 				$data['speed'] = round($line[5]*1.94384);
1214 1690
 				$data['datetime'] = date('Y-m-d H:i:s');
1215 1691
 				$data['format_source'] = 'flightgearsp';
1216
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1217
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1692
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1693
+					$data['noarchive'] = true;
1694
+				}
1695
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1696
+					$SI->add($data);
1697
+				}
1218 1698
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1219 1699
 			    }
1220 1700
                         } elseif ($format == 'acars') {
1221
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1701
+                    	    if ($globalDebug) {
1702
+                    	    	echo 'ACARS : '.$buffer."\n";
1703
+                    	    }
1222 1704
 			    $ACARS->add(trim($buffer));
1223 1705
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1224 1706
 			    $ACARS->deleteLiveAcarsData();
@@ -1239,8 +1721,12 @@  discard block
 block discarded – undo
1239 1721
 				    $aircraft_type = $line[10];
1240 1722
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1241 1723
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1242
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1243
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1724
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1725
+				    	$data['noarchive'] = true;
1726
+				    }
1727
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1728
+				    	$SI->add($data);
1729
+				    }
1244 1730
 				}
1245 1731
 			    }
1246 1732
 			} elseif ($format == 'beast') {
@@ -1250,28 +1736,62 @@  discard block
 block discarded – undo
1250 1736
 			    foreach($buffer as $all_data) {
1251 1737
 				$line = json_decode('{'.$all_data.'}',true);
1252 1738
 				$data = array();
1253
-				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1254
-				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1255
-				if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1256
-				if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1257
-				if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1258
-				if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1259
-				if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1739
+				if (isset($line['Icao'])) {
1740
+					$data['hex'] = $line['Icao'];
1741
+				}
1742
+				// hex
1743
+				if (isset($line['Call'])) {
1744
+					$data['ident'] = $line['Call'];
1745
+				}
1746
+				// ident
1747
+				if (isset($line['Alt'])) {
1748
+					$data['altitude'] = $line['Alt'];
1749
+				}
1750
+				// altitude
1751
+				if (isset($line['Spd'])) {
1752
+					$data['speed'] = $line['Spd'];
1753
+				}
1754
+				// speed
1755
+				if (isset($line['Trak'])) {
1756
+					$data['heading'] = $line['Trak'];
1757
+				}
1758
+				// heading
1759
+				if (isset($line['Lat'])) {
1760
+					$data['latitude'] = $line['Lat'];
1761
+				}
1762
+				// lat
1763
+				if (isset($line['Long'])) {
1764
+					$data['longitude'] = $line['Long'];
1765
+				}
1766
+				// long
1260 1767
 				//$data['verticalrate'] = $line['']; // verticale rate
1261
-				if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1768
+				if (isset($line['Sqk'])) {
1769
+					$data['squawk'] = $line['Sqk'];
1770
+				}
1771
+				// squawk
1262 1772
 				$data['emergency'] = ''; // emergency
1263
-				if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
1773
+				if (isset($line['Reg'])) {
1774
+					$data['registration'] = $line['Reg'];
1775
+				}
1264 1776
 				/*
1265 1777
 				if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
1266 1778
 				else $data['datetime'] = date('Y-m-d H:i:s');
1267 1779
 				*/
1268 1780
 				$data['datetime'] = date('Y-m-d H:i:s');
1269
-				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1781
+				if (isset($line['Type'])) {
1782
+					$data['aircraft_icao'] = $line['Type'];
1783
+				}
1270 1784
 		    		$data['format_source'] = 'vrstcp';
1271 1785
 				$data['id_source'] = $id_source;
1272
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1273
-				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1274
-				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1786
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1787
+					$data['noarchive'] = true;
1788
+				}
1789
+				if (isset($value['name']) && $value['name'] != '') {
1790
+					$data['source_name'] = $value['name'];
1791
+				}
1792
+				if (isset($data['latitude']) && isset($data['hex'])) {
1793
+					$SI->add($data);
1794
+				}
1275 1795
 				unset($data);
1276 1796
 			    }
1277 1797
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
@@ -1284,22 +1804,46 @@  discard block
 block discarded – undo
1284 1804
     				$data['hex'] = $lined['hexid'];
1285 1805
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1286 1806
     				$data['datetime'] = date('Y-m-d H:i:s');;
1287
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1288
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1289
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1290
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1291
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1292
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1293
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1807
+    				if (isset($lined['ident'])) {
1808
+    					$data['ident'] = $lined['ident'];
1809
+    				}
1810
+    				if (isset($lined['lat'])) {
1811
+    					$data['latitude'] = $lined['lat'];
1812
+    				}
1813
+    				if (isset($lined['lon'])) {
1814
+    					$data['longitude'] = $lined['lon'];
1815
+    				}
1816
+    				if (isset($lined['speed'])) {
1817
+    					$data['speed'] = $lined['speed'];
1818
+    				}
1819
+    				if (isset($lined['squawk'])) {
1820
+    					$data['squawk'] = $lined['squawk'];
1821
+    				}
1822
+    				if (isset($lined['alt'])) {
1823
+    					$data['altitude'] = $lined['alt'];
1824
+    				}
1825
+    				if (isset($lined['heading'])) {
1826
+    					$data['heading'] = $lined['heading'];
1827
+    				}
1294 1828
     				$data['id_source'] = $id_source;
1295 1829
     				$data['format_source'] = 'tsv';
1296
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1297
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1298
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1299
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1830
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1831
+    					$data['source_name'] = $globalSources[$nb]['name'];
1832
+    				}
1833
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1834
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1835
+    				}
1836
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1837
+					$data['noarchive'] = true;
1838
+				}
1839
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1840
+    					$SI->add($data);
1841
+    				}
1300 1842
     				unset($lined);
1301 1843
     				unset($data);
1302
-    			    } else $error = true;
1844
+    			    } else {
1845
+    			    	$error = true;
1846
+    			    }
1303 1847
 			} elseif ($format == 'aprs' && $use_aprs) {
1304 1848
 			    if ($aprs_connect == 0) {
1305 1849
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1324,41 +1868,89 @@  discard block
 block discarded – undo
1324 1868
 				    $aprs_last_tx = time();
1325 1869
 				    $data = array();
1326 1870
 				    //print_r($line);
1327
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1328
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1329
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1330
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1331
-				    if (isset($line['arrival_code'])) $data['arrical_code'] = $line['arrival_code'];
1332
-				    if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1333
-				    if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1334
-				    if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1335
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1336
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1871
+				    if (isset($line['address'])) {
1872
+				    	$data['hex'] = $line['address'];
1873
+				    }
1874
+				    if (isset($line['mmsi'])) {
1875
+				    	$data['mmsi'] = $line['mmsi'];
1876
+				    }
1877
+				    if (isset($line['imo'])) {
1878
+				    	$data['imo'] = $line['imo'];
1879
+				    }
1880
+				    if (isset($line['squawk'])) {
1881
+				    	$data['squawk'] = $line['squawk'];
1882
+				    }
1883
+				    if (isset($line['arrival_code'])) {
1884
+				    	$data['arrical_code'] = $line['arrival_code'];
1885
+				    }
1886
+				    if (isset($line['arrival_date'])) {
1887
+				    	$data['arrical_date'] = $line['arrival_date'];
1888
+				    }
1889
+				    if (isset($line['type_id'])) {
1890
+				    	$data['type_id'] = $line['typeid'];
1891
+				    }
1892
+				    if (isset($line['status_id'])) {
1893
+				    	$data['status_id'] = $line['statusid'];
1894
+				    }
1895
+				    if (isset($line['timestamp'])) {
1896
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1897
+				    } else {
1898
+				    	$data['datetime'] = date('Y-m-d H:i:s');
1899
+				    }
1337 1900
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1338
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1901
+				    if (isset($line['ident'])) {
1902
+				    	$data['ident'] = $line['ident'];
1903
+				    }
1339 1904
 				    $data['latitude'] = $line['latitude'];
1340 1905
 				    $data['longitude'] = $line['longitude'];
1341 1906
 				    //$data['verticalrate'] = $line[16];
1342
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1343
-				    else $data['speed'] = 0;
1344
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1345
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1346
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1347
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1907
+				    if (isset($line['speed'])) {
1908
+				    	$data['speed'] = $line['speed'];
1909
+				    } else {
1910
+				    	$data['speed'] = 0;
1911
+				    }
1912
+				    if (isset($line['altitude'])) {
1913
+				    	$data['altitude'] = $line['altitude'];
1914
+				    }
1915
+				    if (isset($line['comment'])) {
1916
+				    	$data['comment'] = $line['comment'];
1917
+				    }
1918
+				    if (isset($line['symbol'])) {
1919
+				    	$data['type'] = $line['symbol'];
1920
+				    }
1921
+				    if (isset($line['heading'])) {
1922
+				    	$data['heading'] = $line['heading'];
1923
+				    }
1348 1924
 				    //else $data['heading'] = 0;
1349
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1925
+				    if (isset($line['stealth'])) {
1926
+				    	$data['aircraft_type'] = $line['stealth'];
1927
+				    }
1350 1928
 				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1351
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1352
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1353
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1354
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1929
+				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) {
1930
+				    	$data['noarchive'] = true;
1931
+				    } elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) {
1932
+				    	$data['noarchive'] = false;
1933
+				    }
1934
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1935
+				    	$data['noarchive'] = true;
1936
+				    } elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) {
1937
+				    	$data['noarchive'] = false;
1938
+				    }
1355 1939
     				    $data['id_source'] = $id_source;
1356
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1357
-				    else $data['format_source'] = 'aprs';
1940
+    				    if (isset($line['format_source'])) {
1941
+    				    	$data['format_source'] = $line['format_source'];
1942
+    				    } else {
1943
+				    	$data['format_source'] = 'aprs';
1944
+				    }
1358 1945
 				    $data['source_name'] = $line['source'];
1359
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1360
-				    else $data['source_type'] = 'flarm';
1361
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1946
+				    if (isset($line['source_type'])) {
1947
+				    	$data['source_type'] = $line['source_type'];
1948
+				    } else {
1949
+				    	$data['source_type'] = 'flarm';
1950
+				    }
1951
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
1952
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1953
+    				    }
1362 1954
 				    $currentdate = date('Y-m-d H:i:s');
1363 1955
 				    $aprsdate = strtotime($data['datetime']);
1364 1956
 				    // Accept data if time <= system time + 20s
@@ -1366,14 +1958,21 @@  discard block
 block discarded – undo
1366 1958
 				    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'])))) {
1367 1959
 					$send = $SI->add($data);
1368 1960
 				    } elseif ($data['source_type'] == 'ais') {
1369
-					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
1961
+					if (isset($globalMarine) && $globalMarine) {
1962
+						$send = $MI->add($data);
1963
+					}
1370 1964
 				    } elseif (isset($line['stealth'])) {
1371
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1372
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1965
+					if ($line['stealth'] != 0) {
1966
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1967
+					} else {
1968
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1969
+					}
1373 1970
 				    //} 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')) {
1374 1971
 				    } 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') {
1375 1972
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1376
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1973
+					if (isset($globalTracker) && $globalTracker) {
1974
+						$send = $TI->add($data);
1975
+					}
1377 1976
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident'])) {
1378 1977
 					$Source->deleteOldLocationByType('gs');
1379 1978
 					if (count($Source->getLocationInfoByName($data['ident'])) > 0) {
@@ -1386,12 +1985,9 @@  discard block
 block discarded – undo
1386 1985
 				    	print_r($data);
1387 1986
 				    }
1388 1987
 				    unset($data);
1389
-				} 
1390
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1988
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1391 1989
 					echo '!! Weather Station not yet supported'."\n";
1392
-				}
1393
-				 
1394
-				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1990
+				} elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1395 1991
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
1396 1992
 				}
1397 1993
 				/*
@@ -1399,8 +1995,11 @@  discard block
 block discarded – undo
1399 1995
 					echo '!! Car & Trucks not yet supported'."\n";
1400 1996
 				}
1401 1997
 				*/
1402
-				elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1403
-				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1998
+				elseif ($line == false && $globalDebug) {
1999
+					echo 'Ignored ('.$buffer.")\n";
2000
+				} elseif ($line == true && $globalDebug) {
2001
+					echo '!! Failed : '.$buffer."!!\n";
2002
+				}
1404 2003
 			    }
1405 2004
 			} else {
1406 2005
 			    $line = explode(',', $buffer);
@@ -1429,26 +2028,45 @@  discard block
 block discarded – undo
1429 2028
     				$data['ground'] = $line[21];
1430 2029
     				$data['emergency'] = $line[19];
1431 2030
     				$data['format_source'] = 'sbs';
1432
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1433
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1434
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
2031
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2032
+					$data['source_name'] = $globalSources[$nb]['name'];
2033
+				}
2034
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2035
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2036
+    				}
2037
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2038
+					$data['noarchive'] = true;
2039
+				}
1435 2040
     				$data['id_source'] = $id_source;
1436
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1437
-    				else $error = true;
2041
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2042
+    					$send = $SI->add($data);
2043
+    				} else {
2044
+    					$error = true;
2045
+    				}
1438 2046
     				unset($data);
1439
-    			    } else $error = true;
2047
+    			    } else {
2048
+    			    	$error = true;
2049
+    			    }
1440 2050
 			    if ($error) {
1441 2051
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1442
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
2052
+					if ($globalDebug) {
2053
+						echo "Not a message. Ignoring... \n";
2054
+					}
1443 2055
 				} else {
1444
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
2056
+					if ($globalDebug) {
2057
+						echo "Wrong line format. Ignoring... \n";
2058
+					}
1445 2059
 					if ($globalDebug) {
1446 2060
 						echo $buffer;
1447 2061
 						//print_r($line);
1448 2062
 					}
1449 2063
 					//socket_close($r);
1450
-					if ($globalDebug) echo "Reconnect after an error...\n";
1451
-					if ($format == 'aprs') $aprs_connect = 0;
2064
+					if ($globalDebug) {
2065
+						echo "Reconnect after an error...\n";
2066
+					}
2067
+					if ($format == 'aprs') {
2068
+						$aprs_connect = 0;
2069
+					}
1452 2070
 					$sourceer[$nb] = $globalSources[$nb];
1453 2071
 					connect_all($sourceer);
1454 2072
 					$sourceer = array();
@@ -1456,10 +2074,14 @@  discard block
 block discarded – undo
1456 2074
 			    }
1457 2075
 			}
1458 2076
 			// Sleep for xxx microseconds
1459
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
2077
+			if (isset($globalSBSSleep)) {
2078
+				usleep($globalSBSSleep);
2079
+			}
1460 2080
 		    } else {
1461 2081
 			if ($format == 'flightgearmp') {
1462
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
2082
+			    	if ($globalDebug) {
2083
+			    		echo "Reconnect FlightGear MP...";
2084
+			    	}
1463 2085
 				//@socket_close($r);
1464 2086
 				sleep($globalMinFetch);
1465 2087
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1468,10 +2090,15 @@  discard block
 block discarded – undo
1468 2090
 				break;
1469 2091
 				
1470 2092
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1471
-			    if (isset($tt[$format])) $tt[$format]++;
1472
-			    else $tt[$format] = 0;
2093
+			    if (isset($tt[$format])) {
2094
+			    	$tt[$format]++;
2095
+			    } else {
2096
+			    	$tt[$format] = 0;
2097
+			    }
1473 2098
 			    if ($tt[$format] > 30) {
1474
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
2099
+				if ($globalDebug) {
2100
+					echo "ERROR : Reconnect ".$format."...";
2101
+				}
1475 2102
 				//@socket_close($r);
1476 2103
 				sleep(2);
1477 2104
 				$aprs_connect = 0;
@@ -1488,11 +2115,17 @@  discard block
 block discarded – undo
1488 2115
 	    } else {
1489 2116
 		$error = socket_strerror(socket_last_error());
1490 2117
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1491
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1492
-			if (isset($globalDebug)) echo "Restarting...\n";
2118
+			if ($globalDebug) {
2119
+				echo "ERROR : socket_select give this error ".$error . "\n";
2120
+			}
2121
+			if (isset($globalDebug)) {
2122
+				echo "Restarting...\n";
2123
+			}
1493 2124
 			// Restart the script if possible
1494 2125
 			if (is_array($sockets)) {
1495
-			    if ($globalDebug) echo "Shutdown all sockets...";
2126
+			    if ($globalDebug) {
2127
+			    	echo "Shutdown all sockets...";
2128
+			    }
1496 2129
 			    
1497 2130
 			    foreach ($sockets as $sock) {
1498 2131
 				@socket_shutdown($sock,2);
@@ -1500,22 +2133,36 @@  discard block
 block discarded – undo
1500 2133
 			    }
1501 2134
 			    
1502 2135
 			}
1503
-			if ($globalDebug) echo "Waiting...";
2136
+			if ($globalDebug) {
2137
+				echo "Waiting...";
2138
+			}
1504 2139
 			sleep(2);
1505 2140
 			$time = time();
1506 2141
 			//connect_all($hosts);
1507 2142
 			$aprs_connect = 0;
1508
-			if ($reset%5 == 0) sleep(20);
1509
-			if ($reset%10 == 0) sleep(100);
1510
-			if ($reset%20 == 0) sleep(200);
1511
-			if ($reset > 100) exit('Too many attempts...');
1512
-			if ($globalDebug) echo "Restart all connections...";
2143
+			if ($reset%5 == 0) {
2144
+				sleep(20);
2145
+			}
2146
+			if ($reset%10 == 0) {
2147
+				sleep(100);
2148
+			}
2149
+			if ($reset%20 == 0) {
2150
+				sleep(200);
2151
+			}
2152
+			if ($reset > 100) {
2153
+				exit('Too many attempts...');
2154
+			}
2155
+			if ($globalDebug) {
2156
+				echo "Restart all connections...";
2157
+			}
1513 2158
 			connect_all($globalSources);
1514 2159
 		}
1515 2160
 	    }
1516 2161
 	}
1517 2162
 	if ($globalDaemon === false) {
1518
-	    if ($globalDebug) echo 'Check all...'."\n";
2163
+	    if ($globalDebug) {
2164
+	    	echo 'Check all...'."\n";
2165
+	    }
1519 2166
 	    $SI->checkAll();
1520 2167
 	}
1521 2168
     }
Please login to merge, or discard this patch.
require/class.Accident.php 1 patch
Braces   +81 added lines, -29 removed lines patch added patch discarded remove patch
@@ -113,8 +113,11 @@  discard block
 block discarded – undo
113 113
 				$data = array();
114 114
 				if ($row['registration'] != '') {
115 115
 					$image_array = $Image->getSpotterImage($row['registration']);
116
-					if (count($image_array) > 0) $data = array_merge($data,array('image' => $image_array[0]['image'],'image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website']));
117
-					else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
116
+					if (count($image_array) > 0) {
117
+						$data = array_merge($data,array('image' => $image_array[0]['image'],'image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website']));
118
+					} else {
119
+						$data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
120
+					}
118 121
 					$aircraft_type = $Spotter->getAllAircraftTypeByRegistration($row['registration']);
119 122
 					$aircraft_info = $Spotter->getAllAircraftInfo($aircraft_type);
120 123
 					if (!empty($aircraft_info)) {
@@ -130,17 +133,30 @@  discard block
 block discarded – undo
130 133
 						$data['aircraft_base'] = $owner_data['base'];
131 134
 						$data['aircraft_date_first_reg'] = $owner_data['date_first_reg'];
132 135
 					}
133
-				} else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
134
-				if ($row['registration'] == '') $row['registration'] = 'NA';
135
-				if ($row['ident'] == '') $row['ident'] = 'NA';
136
+				} else {
137
+					$data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
138
+				}
139
+				if ($row['registration'] == '') {
140
+					$row['registration'] = 'NA';
141
+				}
142
+				if ($row['ident'] == '') {
143
+					$row['ident'] = 'NA';
144
+				}
136 145
 				$identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,3));
137 146
 				if (isset($identicao[0])) {
138 147
 					if (substr($row['ident'],0,2) == 'AF') {
139
-						if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident'];
140
-						else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
141
-					} else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
148
+						if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) {
149
+							$icao = $row['ident'];
150
+						} else {
151
+							$icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
152
+						}
153
+					} else {
154
+						$icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
155
+					}
142 156
 					$data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name']));
143
-				} else $icao = $row['ident'];
157
+				} else {
158
+					$icao = $row['ident'];
159
+				}
144 160
 				$icao = $Translation->checkTranslation($icao,false);
145 161
 				//$data = array_merge($data,array('registration' => $row['registration'], 'date' => $row['date'], 'ident' => $icao,'url' => $row['url']));
146 162
 				if ($row['airline_name'] != '' && !isset($data['airline_name'])) {
@@ -155,10 +171,14 @@  discard block
 block discarded – undo
155 171
 					//else echo 'No data...'."\n";
156 172
 				}
157 173
 				$data = array_merge($row,$data);
158
-				if ($data['ident'] == null) $data['ident'] = $icao;
174
+				if ($data['ident'] == null) {
175
+					$data['ident'] = $icao;
176
+				}
159 177
 				if ($data['title'] == null) {
160 178
 					$data['message'] = $row['type'].' of '.$row['registration'].' at '.$row['place'].','.$row['country'];
161
-				} else $data['message'] = strtolower($data['title']);
179
+				} else {
180
+					$data['message'] = strtolower($data['title']);
181
+				}
162 182
 				$ids = $Spotter->getAllIDByRegistration($data['registration']);
163 183
 				$date = $data['date'];
164 184
 				if (isset($ids[$date])) {
@@ -177,8 +197,9 @@  discard block
 block discarded – undo
177 197
 		if (isset($result)) {
178 198
 			$result[0]['query_number_rows'] = $i;
179 199
 			return $result;
200
+		} else {
201
+			return array();
180 202
 		}
181
-		else return array();
182 203
 	}
183 204
 	
184 205
 	/*
@@ -222,7 +243,9 @@  discard block
 block discarded – undo
222 243
 	*/
223 244
 	public function import($file) {
224 245
 		global $globalTransaction, $globalDebug;
225
-		if ($globalDebug) echo 'Import '.$file."\n";
246
+		if ($globalDebug) {
247
+			echo 'Import '.$file."\n";
248
+		}
226 249
 		$result = array();
227 250
 		if (file_exists($file)) {
228 251
 			if (($handle = fopen($file,'r')) !== FALSE) {
@@ -233,8 +256,11 @@  discard block
 block discarded – undo
233 256
 				}
234 257
 				fclose($handle);
235 258
 			}
236
-			if (!empty($result)) $this->add($result,true);
237
-			elseif ($globalDebug) echo 'Nothing to import';
259
+			if (!empty($result)) {
260
+				$this->add($result,true);
261
+			} elseif ($globalDebug) {
262
+				echo 'Nothing to import';
263
+			}
238 264
 		}
239 265
 	}
240 266
 
@@ -270,14 +296,23 @@  discard block
 block discarded – undo
270 296
 					}
271 297
 				}
272 298
 				fclose($handle);
273
-			} elseif ($globalDebug) echo "Can't open ".dirname(__FILE__).'/../install/tmp/cr-all.md5';
274
-		} elseif ($globalDebug) echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.';
299
+			} elseif ($globalDebug) {
300
+				echo "Can't open ".dirname(__FILE__).'/../install/tmp/cr-all.md5';
301
+			}
302
+		} elseif ($globalDebug) {
303
+			echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.';
304
+		}
275 305
 		$result = $Common->arr_diff($all_md5_new,$all_md5);
276
-		if (empty($result) && $globalDebug) echo 'Nothing to update';
306
+		if (empty($result) && $globalDebug) {
307
+			echo 'Nothing to update';
308
+		}
277 309
 		foreach ($result as $file => $md5) {
278 310
 			$Common->download('http://data.flightairmap.fr/data/cr/'.$file,dirname(__FILE__).'/../install/tmp/'.$file);
279
-			if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) $this->import(dirname(__FILE__).'/../install/tmp/'.$file);
280
-			elseif ($globalDebug) echo 'Download '.$file.' failed';
311
+			if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) {
312
+				$this->import(dirname(__FILE__).'/../install/tmp/'.$file);
313
+			} elseif ($globalDebug) {
314
+				echo 'Download '.$file.' failed';
315
+			}
281 316
 		}
282 317
 	}
283 318
 
@@ -294,13 +329,17 @@  discard block
 block discarded – undo
294 329
 		$Image = new Image();
295 330
 		$Spotter = new Spotter();
296 331
 
297
-		if (empty($crash)) return false;
332
+		if (empty($crash)) {
333
+			return false;
334
+		}
298 335
 		if (!$new) {
299 336
 			$query_delete = 'DELETE FROM accidents WHERE source = :source';
300 337
 			$sthd = $Connection->db->prepare($query_delete);
301 338
 			$sthd->execute(array(':source' => $crash[0]['source']));
302 339
 		}
303
-		if ($globalTransaction) $Connection->db->beginTransaction();
340
+		if ($globalTransaction) {
341
+			$Connection->db->beginTransaction();
342
+		}
304 343
 		$initial_array = array('ident' => null,'type' => 'accident','url' => null,'registration' => null, 'date' => null, 'place' => null,'country' => null, 'latitude' => null, 'longitude' => null, 'fatalities' => null, 'title' => '','source' => '','aircraft_manufacturer' => null,'aircraft_name' => null,'operator' => null);
305 344
 		$query_check = 'SELECT COUNT(*) as nb FROM accidents WHERE registration = :registration AND date = :date AND type = :type AND source = :source';
306 345
 		$sth_check = $Connection->db->prepare($query_check);
@@ -315,7 +354,9 @@  discard block
 block discarded – undo
315 354
 					return $value === "" ? NULL : $value;
316 355
 				}, $cr);
317 356
 				if ($cr['date'] != '' && $cr['registration'] != null && $cr['registration'] != '' && $cr['registration'] != '?' && $cr['registration'] != '-' && strtolower($cr['registration']) != 'unknown' && $cr['date'] < time() && !preg_match('/\s/',$cr['registration'])) {
318
-					if (strpos($cr['registration'],'-') === FALSE) $cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']);
357
+					if (strpos($cr['registration'],'-') === FALSE) {
358
+						$cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']);
359
+					}
319 360
 					$query_check_values = array(':registration' => $cr['registration'],':date' => date('Y-m-d',$cr['date']),':type' => $cr['type'],':source' => $cr['source']);
320 361
 					$sth_check->execute($query_check_values);
321 362
 					$result_check = $sth_check->fetch(PDO::FETCH_ASSOC);
@@ -324,9 +365,13 @@  discard block
 block discarded – undo
324 365
 						$sth->execute($query_values);
325 366
 						if ($cr['date'] > time()-(30*86400)) {
326 367
 							if (empty($Image->getSpotterImage($cr['registration']))) {
327
-								if ($globalDebug) echo "\t".'Get image for '.$cr['registration'].'...';
368
+								if ($globalDebug) {
369
+									echo "\t".'Get image for '.$cr['registration'].'...';
370
+								}
328 371
 								$Image->addSpotterImage($cr['registration']);
329
-								if ($globalDebug) echo "\t".'Done'."\n";
372
+								if ($globalDebug) {
373
+									echo "\t".'Done'."\n";
374
+								}
330 375
 							}
331 376
 							// elseif ($globalDebug) echo 'Image already in DB'."\n";
332 377
 						}
@@ -338,9 +383,13 @@  discard block
 block discarded – undo
338 383
 					$Connection->db->beginTransaction();
339 384
 				}
340 385
 			}
341
-			if ($globalTransaction) $Connection->db->commit();
386
+			if ($globalTransaction) {
387
+				$Connection->db->commit();
388
+			}
342 389
 		} catch(PDOException $e) {
343
-			if ($globalTransaction) $Connection->db->rollBack();
390
+			if ($globalTransaction) {
391
+				$Connection->db->rollBack();
392
+			}
344 393
 			echo $e->getMessage();
345 394
 		}
346 395
 		$sth_check->closeCursor();
@@ -379,8 +428,11 @@  discard block
 block discarded – undo
379 428
 			return "error : ".$e->getMessage();
380 429
 		}
381 430
 		$row = $sth->fetch(PDO::FETCH_ASSOC);
382
-		if ($row['nb'] > 0) return false;
383
-		else return true;
431
+		if ($row['nb'] > 0) {
432
+			return false;
433
+		} else {
434
+			return true;
435
+		}
384 436
 	}
385 437
 
386 438
 	public static function insert_last_accidents_update() {
Please login to merge, or discard this patch.
require/class.SpotterImport.php 1 patch
Braces   +396 added lines, -141 removed lines patch added patch discarded remove patch
@@ -63,7 +63,9 @@  discard block
 block discarded – undo
63 63
 	$dbc = $this->db;
64 64
 	$this->all_flights[$id]['schedule_check'] = true;
65 65
 	if ($globalSchedulesFetch) {
66
-	if ($globalDebug) echo 'Getting schedule info...'."\n";
66
+	if ($globalDebug) {
67
+		echo 'Getting schedule info...'."\n";
68
+	}
67 69
 	$Spotter = new Spotter($dbc);
68 70
 	$Schedule = new Schedule($dbc);
69 71
 	$Translation = new Translation($dbc);
@@ -74,7 +76,9 @@  discard block
 block discarded – undo
74 76
 	    if ($Schedule->checkSchedule($operator) == 0) {
75 77
 		$schedule = $Schedule->fetchSchedule($operator);
76 78
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
77
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
79
+		    if ($globalDebug) {
80
+		    	echo "-> Schedule info for ".$operator." (".$ident.")\n";
81
+		    }
78 82
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
79 83
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
80 84
 		    // Should also check if route schedule = route from DB
@@ -83,7 +87,9 @@  discard block
 block discarded – undo
83 87
 			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
84 88
 			    if (trim($airport_icao) != '') {
85 89
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
86
-				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
90
+				if ($globalDebug) {
91
+					echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
92
+				}
87 93
 			    }
88 94
 			}
89 95
 		    }
@@ -92,17 +98,25 @@  discard block
 block discarded – undo
92 98
 			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
93 99
 			    if (trim($airport_icao) != '') {
94 100
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
95
-				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
101
+				if ($globalDebug) {
102
+					echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
103
+				}
96 104
 			    }
97 105
 			}
98 106
 		    }
99 107
 		    $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
100 108
 		}
101
-	    } else $scheduleexist = true;
102
-	} else $scheduleexist = true;
109
+	    } else {
110
+	    	$scheduleexist = true;
111
+	    }
112
+	} else {
113
+		$scheduleexist = true;
114
+	}
103 115
 	// close connection, at least one way will work ?
104 116
        if ($scheduleexist) {
105
-		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
117
+		if ($globalDebug) {
118
+			echo "-> get arrival/departure airport info for ".$ident."\n";
119
+		}
106 120
     		$sch = $Schedule->getSchedule($operator);
107 121
 		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time']));
108 122
        }
@@ -124,14 +138,18 @@  discard block
 block discarded – undo
124 138
 
125 139
     public function checkAll() {
126 140
 	global $globalDebug, $globalNoImport;
127
-	if ($globalDebug) echo "Update last seen flights data...\n";
141
+	if ($globalDebug) {
142
+		echo "Update last seen flights data...\n";
143
+	}
128 144
 	if (!isset($globalNoImport) || $globalNoImport === FALSE) {
129 145
 	    foreach ($this->all_flights as $key => $flight) {
130 146
 		if (isset($this->all_flights[$key]['id'])) {
131 147
 		    //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
132 148
     		    $Spotter = new Spotter($this->db);
133 149
         	    $real_arrival = $this->arrival($key);
134
-        	    if (isset($this->all_flights[$key]['altitude'])) $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
150
+        	    if (isset($this->all_flights[$key]['altitude'])) {
151
+        	    	$Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
152
+        	    }
135 153
         	}
136 154
 	    }
137 155
 	}
@@ -139,24 +157,32 @@  discard block
 block discarded – undo
139 157
 
140 158
     public function arrival($key) {
141 159
 	global $globalClosestMinDist, $globalDebug;
142
-	if ($globalDebug) echo 'Update arrival...'."\n";
160
+	if ($globalDebug) {
161
+		echo 'Update arrival...'."\n";
162
+	}
143 163
 	$Spotter = new Spotter($this->db);
144 164
         $airport_icao = '';
145 165
         $airport_time = '';
146
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
166
+        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') {
167
+        	$globalClosestMinDist = 50;
168
+        }
147 169
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
148 170
 	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
149 171
     	    if (isset($closestAirports[0])) {
150 172
         	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
151 173
         	    $airport_icao = $closestAirports[0]['icao'];
152 174
         	    $airport_time = $this->all_flights[$key]['datetime'];
153
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
175
+        	    if ($globalDebug) {
176
+        	    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
177
+        	    }
154 178
         	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
155 179
         	    foreach ($closestAirports as $airport) {
156 180
         		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
157 181
         		    $airport_icao = $airport['icao'];
158 182
         		    $airport_time = $this->all_flights[$key]['datetime'];
159
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
183
+        		    if ($globalDebug) {
184
+        		    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
185
+        		    }
160 186
         		    break;
161 187
         		}
162 188
         	    }
@@ -164,14 +190,20 @@  discard block
 block discarded – undo
164 190
         		$airport_icao = $closestAirports[0]['icao'];
165 191
         		$airport_time = $this->all_flights[$key]['datetime'];
166 192
         	} else {
167
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
193
+        		if ($globalDebug) {
194
+        			echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
195
+        		}
168 196
         	}
169 197
     	    } else {
170
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
198
+    		    if ($globalDebug) {
199
+    		    	echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
200
+    		    }
171 201
     	    }
172 202
 
173 203
         } else {
174
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
204
+        	if ($globalDebug) {
205
+        		echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
206
+        	}
175 207
         }
176 208
         return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
177 209
     }
@@ -181,7 +213,9 @@  discard block
 block discarded – undo
181 213
     public function del() {
182 214
 	global $globalDebug, $globalNoImport, $globalNoDB;
183 215
 	// Delete old infos
184
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
216
+	if ($globalDebug) {
217
+		echo 'Delete old values and update latest data...'."\n";
218
+	}
185 219
 	foreach ($this->all_flights as $key => $flight) {
186 220
 	    if (isset($flight['lastupdate'])) {
187 221
 		if ($flight['lastupdate'] < (time()-5900)) {
@@ -195,13 +229,17 @@  discard block
 block discarded – undo
195 229
 	global $globalDebug, $globalNoImport, $globalNoDB;
196 230
 	// Delete old infos
197 231
 	if (isset($this->all_flights[$key]['id'])) {
198
-		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
232
+		if ($globalDebug) {
233
+			echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
234
+		}
199 235
 		if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
200 236
 			$real_arrival = $this->arrival($key);
201 237
 			$Spotter = new Spotter($this->db);
202 238
 			if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
203 239
 				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
204
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
240
+				if ($globalDebug && $result != 'success') {
241
+					echo '!!! ERROR : '.$result."\n";
242
+				}
205 243
 			}
206 244
 		}
207 245
 	}
@@ -211,9 +249,13 @@  discard block
 block discarded – undo
211 249
     public function add($line) {
212 250
 	global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights, $globalServerAPRS, $APRSSpotter, $globalNoImport, $globalNoDB, $globalVA, $globalAircraftMaxUpdate, $globalAircraftMinUpdate;
213 251
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
214
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
215
-	if (!isset($globalAircraftMaxUpdate) || $globalAircraftMaxUpdate == '') $globalAircraftMaxUpdate = 2300;
216
-/*
252
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
253
+		$globalCoordMinChange = '0.02';
254
+	}
255
+	if (!isset($globalAircraftMaxUpdate) || $globalAircraftMaxUpdate == '') {
256
+		$globalAircraftMaxUpdate = 2300;
257
+	}
258
+	/*
217 259
 	$Spotter = new Spotter();
218 260
 	$dbc = $Spotter->db;
219 261
 	$SpotterLive = new SpotterLive($dbc);
@@ -235,19 +277,28 @@  discard block
 block discarded – undo
235 277
 	// SBS format is CSV format
236 278
 	if(is_array($line) && (isset($line['hex']) || isset($line['id']))) {
237 279
 	    //print_r($line);
238
-	    if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']);
280
+	    if (isset($line['hex'])) {
281
+	    	$line['hex'] = strtoupper($line['hex']);
282
+	    }
239 283
   	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
240 284
 
241 285
 		// Increment message number
242 286
 		if (isset($line['sourcestats']) && $line['sourcestats'] === TRUE) {
243 287
 		    $current_date = date('Y-m-d');
244
-		    if (isset($line['source_name'])) $source = $line['source_name'];
245
-		    else $source = '';
246
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
288
+		    if (isset($line['source_name'])) {
289
+		    	$source = $line['source_name'];
290
+		    } else {
291
+		    	$source = '';
292
+		    }
293
+		    if ($source == '' || $line['format_source'] == 'aprs') {
294
+		    	$source = $line['format_source'];
295
+		    }
247 296
 		    if (!isset($this->stats[$current_date][$source]['msg'])) {
248 297
 		    	$this->stats[$current_date][$source]['msg']['date'] = time();
249 298
 		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
250
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
299
+		    } else {
300
+		    	$this->stats[$current_date][$source]['msg']['nb'] += 1;
301
+		    }
251 302
 		}
252 303
 		
253 304
 		/*
@@ -263,22 +314,35 @@  discard block
 block discarded – undo
263 314
 		//$this->db = $dbc;
264 315
 
265 316
 		//$hex = trim($line['hex']);
266
-	        if (!isset($line['id'])) $id = trim($line['hex']);
267
-	        else $id = trim($line['id']);
317
+	        if (!isset($line['id'])) {
318
+	        	$id = trim($line['hex']);
319
+	        } else {
320
+	        	$id = trim($line['id']);
321
+	        }
268 322
 		
269 323
 		if (!isset($this->all_flights[$id])) {
270 324
 		    $this->all_flights[$id] = array();
271 325
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
272 326
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '','altitude_previous' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
273
-		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
327
+		    if (isset($globalDaemon) && $globalDaemon === FALSE) {
328
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
329
+		    }
274 330
 		    if (!isset($line['id'])) {
275
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
276
-//			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
331
+			if (!isset($globalDaemon)) {
332
+				$globalDaemon = TRUE;
333
+			}
334
+			//			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
277 335
 //			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
278
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
336
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
337
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
338
+			}
279 339
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
280
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
281
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
340
+		     } else {
341
+		     	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
342
+		     }
343
+		    if ($globalAllFlights !== FALSE) {
344
+		    	$dataFound = true;
345
+		    }
282 346
 		}
283 347
 		if (isset($line['source_type']) && $line['source_type'] != '') {
284 348
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
@@ -300,12 +364,20 @@  discard block
 block discarded – undo
300 364
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
301 365
 			    }
302 366
 			    $Spotter->db = null;
303
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
304
-			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
367
+			    if ($globalDebugTimeElapsed) {
368
+			    	echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
369
+			    }
370
+			    if ($aircraft_icao != '') {
371
+			    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
372
+			    }
305 373
 			}
306 374
 		    }
307
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
308
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
375
+		    if ($globalAllFlights !== FALSE) {
376
+		    	$dataFound = true;
377
+		    }
378
+		    if ($globalDebug) {
379
+		    	echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
380
+		    }
309 381
 		}
310 382
 	        if (isset($line['id']) && !isset($line['hex'])) {
311 383
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
@@ -313,7 +385,9 @@  discard block
 block discarded – undo
313 385
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
314 386
 			$icao = $line['aircraft_icao'];
315 387
 			$Spotter = new Spotter($this->db);
316
-			if (isset($Spotter->aircraft_correct_icaotype[$icao])) $icao = $Spotter->aircraft_correct_icaotype[$icao];
388
+			if (isset($Spotter->aircraft_correct_icaotype[$icao])) {
389
+				$icao = $Spotter->aircraft_correct_icaotype[$icao];
390
+			}
317 391
 			$Spotter->db = null;
318 392
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $icao));
319 393
 		}
@@ -323,15 +397,24 @@  discard block
 block discarded – undo
323 397
 				$Spotter = new Spotter($this->db);
324 398
 				$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
325 399
 				$Spotter->db = null;
326
-				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
400
+				if ($aircraft_icao != '') {
401
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
402
+				}
327 403
 			}
328 404
 		}
329 405
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) {
330
-			if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
331
-			elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
332
-			elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
333
-			elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
334
-			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
406
+			if ($line['aircraft_type'] == 'PARA_GLIDER') {
407
+				$aircraft_icao = 'GLID';
408
+			} elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') {
409
+				$aircraft_icao = 'UHEL';
410
+			} elseif ($line['aircraft_type'] == 'TOW_PLANE') {
411
+				$aircraft_icao = 'TOWPLANE';
412
+			} elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') {
413
+				$aircraft_icao = 'POWAIRC';
414
+			}
415
+			if (isset($aircraft_icao)) {
416
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
417
+			}
335 418
 		}
336 419
 		if (!isset($this->all_flights[$id]['aircraft_icao'])) {
337 420
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
@@ -341,8 +424,11 @@  discard block
 block discarded – undo
341 424
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
342 425
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
343 426
 		    } else {
344
-				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
345
-				elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
427
+				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
428
+					echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
429
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
430
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
431
+				}
346 432
 				/*
347 433
 				echo strtotime($line['datetime']).' > '.strtotime($this->all_flights[$id]['datetime']);
348 434
 				print_r($this->all_flights[$id]);
@@ -351,17 +437,23 @@  discard block
 block discarded – undo
351 437
 				return '';
352 438
 		    }
353 439
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) {
354
-			if ($globalDebug) echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n";
440
+			if ($globalDebug) {
441
+				echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n";
442
+			}
355 443
 			return '';
356 444
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) > time()+20*60) {
357
-			if ($globalDebug) echo "!!! Date is in the future ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n
445
+			if ($globalDebug) {
446
+				echo "!!! Date is in the future ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n
358 447
 			";
448
+			}
359 449
 			return '';
360 450
 		} elseif (!isset($line['datetime'])) {
361 451
 			date_default_timezone_set('UTC');
362 452
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
363 453
 		} else {
364
-			if ($globalDebug) echo "!!! Unknow date error ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!";
454
+			if ($globalDebug) {
455
+				echo "!!! Unknow date error ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!";
456
+			}
365 457
 			return '';
366 458
 		}
367 459
 
@@ -382,30 +474,48 @@  discard block
 block discarded – undo
382 474
 
383 475
 		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
384 476
 			if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
385
-				if ($globalDebug) echo '---!!!! New ident, reset aircraft data...'."\n";
477
+				if ($globalDebug) {
478
+					echo '---!!!! New ident, reset aircraft data...'."\n";
479
+				}
386 480
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
387 481
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
388
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
389
-				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
390
-				elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
482
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
483
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
484
+				} elseif (isset($line['id'])) {
485
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
486
+				} elseif (isset($this->all_flights[$id]['ident'])) {
487
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
488
+				}
391 489
 			} else {
392 490
 			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
393 491
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
394 492
 				$timeelapsed = microtime(true);
395 493
             			$Spotter = new Spotter($this->db);
396 494
             			$fromsource = NULL;
397
-            			if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
398
-            			elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
399
-				elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
400
-				elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
401
-				elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
495
+            			if (isset($globalAirlinesSource) && $globalAirlinesSource != '') {
496
+            				$fromsource = $globalAirlinesSource;
497
+            			} elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') {
498
+            				$fromsource = 'vatsim';
499
+            			} elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') {
500
+					$fromsource = 'ivao';
501
+				} elseif (isset($globalVATSIM) && $globalVATSIM) {
502
+					$fromsource = 'vatsim';
503
+				} elseif (isset($globalIVAO) && $globalIVAO) {
504
+					$fromsource = 'ivao';
505
+				}
402 506
             			$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
403
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
507
+				if ($globalDebug && $result != 'success') {
508
+					echo '!!! ERROR : '.$result."\n";
509
+				}
404 510
 				$Spotter->db = null;
405
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
511
+				if ($globalDebugTimeElapsed) {
512
+					echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
513
+				}
406 514
 			    }
407 515
 			}
408
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
516
+		    } else {
517
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
518
+		    }
409 519
 		    
410 520
 /*
411 521
 		    if (!isset($line['id'])) {
@@ -415,7 +525,9 @@  discard block
 block discarded – undo
415 525
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
416 526
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
417 527
   */
418
-		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
528
+		    if (!isset($this->all_flights[$id]['id'])) {
529
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
530
+		    }
419 531
 
420 532
 		    //$putinarchive = true;
421 533
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
@@ -433,7 +545,9 @@  discard block
 block discarded – undo
433 545
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
434 546
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
435 547
 		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
436
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
548
+				if ($globalDebugTimeElapsed) {
549
+					echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
550
+				}
437 551
                         }
438 552
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
439 553
 			$timeelapsed = microtime(true);
@@ -447,7 +561,9 @@  discard block
 block discarded – undo
447 561
 				$Translation->db = null;
448 562
 			    }
449 563
 			    $Spotter->db = null;
450
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
564
+			    if ($globalDebugTimeElapsed) {
565
+			    	echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
566
+			    }
451 567
                     	}
452 568
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
453 569
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
@@ -456,9 +572,13 @@  discard block
 block discarded – undo
456 572
 		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
457 573
 		    	    }
458 574
 			}
459
-			if (!isset($globalFork)) $globalFork = TRUE;
575
+			if (!isset($globalFork)) {
576
+				$globalFork = TRUE;
577
+			}
460 578
 			if (!$globalVA && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
461
-				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
579
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) {
580
+					$this->get_Schedule($id,trim($line['ident']));
581
+				}
462 582
 			}
463 583
 		    }
464 584
 		}
@@ -474,8 +594,12 @@  discard block
 block discarded – undo
474 594
 		    // use datetime
475 595
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
476 596
 			$speed = $speed*3.6;
477
-			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
478
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
597
+			if ($speed < 1000) {
598
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
599
+			}
600
+  			if ($globalDebug) {
601
+  				echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
602
+  			}
479 603
 		    }
480 604
 		}
481 605
 
@@ -483,11 +607,16 @@  discard block
 block discarded – undo
483 607
 
484 608
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude']) && !is_int($line['latitude']) && !is_int($line['longitude'])) {
485 609
 	    	    if (ctype_digit(strval($line['latitude'])) || ctype_digit(strval($line['longitude']))) {
486
-	    	    	if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
610
+	    	    	if ($globalDebug) {
611
+	    	    		echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
612
+	    	    	}
487 613
 	    	    	return false;
488 614
 	    	    }
489
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
490
-	    	    else unset($timediff);
615
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) {
616
+	    	    	$timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
617
+	    	    } else {
618
+	    	    	unset($timediff);
619
+	    	    }
491 620
 	    	    if ($this->tmd > 5
492 621
 	    	        || (isset($line['format_source']) 
493 622
 	    	    	    && $line['format_source'] == 'airwhere' 
@@ -519,16 +648,25 @@  discard block
 block discarded – undo
519 648
 				$this->all_flights[$id]['putinarchive'] = true;
520 649
 				$this->tmd = 0;
521 650
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
522
-				    if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
651
+				    if ($globalDebug) {
652
+				    	echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
653
+				    }
523 654
 				    $timeelapsed = microtime(true);
524 655
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
525 656
 					$Spotter = new Spotter($this->db);
526 657
 					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
527
-					if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
528
-					else $this->all_flights[$id]['over_country'] = '';
658
+					if (!empty($all_country)) {
659
+						$this->all_flights[$id]['over_country'] = $all_country['iso2'];
660
+					} else {
661
+						$this->all_flights[$id]['over_country'] = '';
662
+					}
529 663
 					$Spotter->db = null;
530
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
531
-					if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
664
+					if ($globalDebugTimeElapsed) {
665
+						echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
666
+					}
667
+					if ($globalDebug) {
668
+						echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
669
+					}
532 670
 				    }
533 671
 				}
534 672
 			    }
@@ -536,7 +674,9 @@  discard block
 block discarded – undo
536 674
 
537 675
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
538 676
 			    //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
539
-				if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
677
+				if (!isset($this->all_flights[$id]['archive_latitude'])) {
678
+					$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
679
+				}
540 680
 				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs' || $this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > 0.0001) {
541 681
 				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
542 682
 				    $dataFound = true;
@@ -558,9 +698,13 @@  discard block
 block discarded – undo
558 698
 			    */
559 699
 			}
560 700
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
561
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
701
+			    if ($line['longitude'] > 180) {
702
+			    	$line['longitude'] = $line['longitude'] - 360;
703
+			    }
562 704
 			    //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
563
-				if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
705
+				if (!isset($this->all_flights[$id]['archive_longitude'])) {
706
+					$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
707
+				}
564 708
 				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs' || $this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > 0.0001) {
565 709
 				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
566 710
 				    $dataFound = true;
@@ -591,7 +735,9 @@  discard block
 block discarded – undo
591 735
 		    }
592 736
 		}
593 737
 		if (isset($line['last_update']) && $line['last_update'] != '') {
594
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
738
+		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) {
739
+		    	$dataFound = true;
740
+		    }
595 741
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
596 742
 		}
597 743
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
@@ -613,53 +759,79 @@  discard block
 block discarded – undo
613 759
 			// Here we force archive of flight because after ground it's a new one (or should be)
614 760
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
615 761
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
616
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
617
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
618
-			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
762
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
763
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
764
+			} elseif (isset($line['id'])) {
765
+		        	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
766
+		        } elseif (isset($this->all_flights[$id]['ident'])) {
767
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
768
+			}
769
+		    }
770
+		    if ($line['ground'] != 1) {
771
+		    	$line['ground'] = 0;
619 772
 		    }
620
-		    if ($line['ground'] != 1) $line['ground'] = 0;
621 773
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
622 774
 		    //$dataFound = true;
623 775
 		}
624 776
 		if (isset($line['squawk']) && $line['squawk'] != '') {
625 777
 		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
626
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
778
+			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) {
779
+			    	$this->all_flights[$id]['putinarchive'] = true;
780
+			    }
627 781
 			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
628 782
 			    $highlight = '';
629
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
630
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
631
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
783
+			    if ($this->all_flights[$id]['squawk'] == '7500') {
784
+			    	$highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
785
+			    }
786
+			    if ($this->all_flights[$id]['squawk'] == '7600') {
787
+			    	$highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
788
+			    }
789
+			    if ($this->all_flights[$id]['squawk'] == '7700') {
790
+			    	$highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
791
+			    }
632 792
 			    if ($highlight != '') {
633 793
 				$timeelapsed = microtime(true);
634 794
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
635 795
 				    $Spotter = new Spotter($this->db);
636 796
 				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
637 797
 				    $Spotter->db = null;
638
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
798
+				    if ($globalDebugTimeElapsed) {
799
+				    	echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
800
+				    }
639 801
 				}
640 802
 				//$putinarchive = true;
641 803
 				//$highlight = '';
642 804
 			    }
643 805
 			    
644
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
806
+		    } else {
807
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
808
+		    }
645 809
 		    //$dataFound = true;
646 810
 		}
647 811
 
648 812
 		if (isset($line['altitude']) && $line['altitude'] != '') {
649 813
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
650
-			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
814
+			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) {
815
+				$this->all_flights[$id]['putinarchive'] = true;
816
+			}
651 817
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
652 818
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
653 819
 			//$dataFound = true;
654 820
 		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
655 821
 		    if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
656 822
 			if (isset($this->all_flights[$id]['over_country']) && $this->all_flights[$id]['over_country'] != '' && isset($this->all_flights[$id]['altitude_previous']) && $this->all_flights[$id]['altitude_previous'] != '' && $this->all_flights[$id]['altitude_previous'] < $this->all_flights[$id]['altitude_real'] && isset($this->all_flights[$id]['lastupdate']) && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
657
-				if ($globalDebug) echo '--- Reset because of altitude'."\n";
823
+				if ($globalDebug) {
824
+					echo '--- Reset because of altitude'."\n";
825
+				}
658 826
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
659 827
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
660
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
661
-				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
662
-				elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
828
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
829
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
830
+				} elseif (isset($line['id'])) {
831
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
832
+				} elseif (isset($this->all_flights[$id]['ident'])) {
833
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
834
+				}
663 835
 			}
664 836
 		    }
665 837
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
@@ -670,22 +842,32 @@  discard block
 block discarded – undo
670 842
 		}
671 843
 		
672 844
 		if (isset($line['heading']) && $line['heading'] != '') {
673
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
845
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) {
846
+		    	$this->all_flights[$id]['putinarchive'] = true;
847
+		    }
674 848
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
675 849
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
676 850
 		    //$dataFound = true;
677 851
   		} elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) {
678 852
   		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
679 853
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
680
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
681
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['id']." : ".$heading."\n";
854
+		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) {
855
+		    	$this->all_flights[$id]['putinarchive'] = true;
856
+		    }
857
+  		    if ($globalDebug) {
858
+  		    	echo "ø Calculated Heading for ".$this->all_flights[$id]['id']." : ".$heading."\n";
859
+  		    }
682 860
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
683 861
   		    // If not enough messages and ACARS set heading to 0
684 862
   		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
685 863
   		}
686
-		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
687
-		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
688
-		elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalMinupdate) $dataFound = false;
864
+		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) {
865
+			$dataFound = false;
866
+		} elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) {
867
+			$dataFound = false;
868
+		} elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalMinupdate) {
869
+			$dataFound = false;
870
+		}
689 871
 
690 872
 //		print_r($this->all_flights[$id]);
691 873
 		//gets the callsign from the last hour
@@ -702,23 +884,38 @@  discard block
 block discarded – undo
702 884
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
703 885
 			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
704 886
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
705
-				    if ($globalDebug) echo "Check if aircraft is already in DB...";
887
+				    if ($globalDebug) {
888
+				    	echo "Check if aircraft is already in DB...";
889
+				    }
706 890
 				    $timeelapsed = microtime(true);
707 891
 				    $SpotterLive = new SpotterLive($this->db);
708 892
 				    if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
709 893
 					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
710
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
894
+					if ($globalDebugTimeElapsed) {
895
+						echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
896
+					}
711 897
 				    } elseif (isset($line['id'])) {
712 898
 					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
713
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
899
+					if ($globalDebugTimeElapsed) {
900
+						echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
901
+					}
714 902
 				    } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
715 903
 					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
716
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
717
-				    } else $recent_ident = '';
904
+					if ($globalDebugTimeElapsed) {
905
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
906
+					}
907
+				    } else {
908
+				    	$recent_ident = '';
909
+				    }
718 910
 				    $SpotterLive->db=null;
719
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
720
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
721
-				} else $recent_ident = '';
911
+				    if ($globalDebug && $recent_ident == '') {
912
+				    	echo " Not in DB.\n";
913
+				    } elseif ($globalDebug && $recent_ident != '') {
914
+				    	echo " Already in DB.\n";
915
+				    }
916
+				} else {
917
+					$recent_ident = '';
918
+				}
722 919
 			    } else {
723 920
 				$recent_ident = '';
724 921
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
@@ -726,7 +923,9 @@  discard block
 block discarded – undo
726 923
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
727 924
 			    if($recent_ident == "")
728 925
 			    {
729
-				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
926
+				if ($globalDebug) {
927
+					echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
928
+				}
730 929
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
731 930
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
732 931
 				//adds the spotter data for the archive
@@ -770,31 +969,49 @@  discard block
 block discarded – undo
770 969
 				
771 970
 				if (!$ignoreImport) {
772 971
 				    $highlight = '';
773
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
774
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
775
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
776
-				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
972
+				    if ($this->all_flights[$id]['squawk'] == '7500') {
973
+				    	$highlight = 'Squawk 7500 : Hijack';
974
+				    }
975
+				    if ($this->all_flights[$id]['squawk'] == '7600') {
976
+				    	$highlight = 'Squawk 7600 : Lost Comm (radio failure)';
977
+				    }
978
+				    if ($this->all_flights[$id]['squawk'] == '7700') {
979
+				    	$highlight = 'Squawk 7700 : Emergency';
980
+				    }
981
+				    if (!isset($this->all_flights[$id]['id'])) {
982
+				    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
983
+				    }
777 984
 				    $timeelapsed = microtime(true);
778 985
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
779 986
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
780 987
 					    $Spotter = new Spotter($this->db);
781 988
 					    $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']);
782 989
 					    $Spotter->db = null;
783
-					    if ($globalDebug && isset($result)) echo $result."\n";
990
+					    if ($globalDebug && isset($result)) {
991
+					    	echo $result."\n";
992
+					    }
784 993
 					}
785 994
 				    }
786
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
995
+				    if ($globalDebugTimeElapsed) {
996
+				    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
997
+				    }
787 998
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
788 999
 
789 1000
 				    // Add source stat in DB
790 1001
 				    $Stats = new Stats($this->db);
791 1002
 				    if (!empty($this->stats)) {
792
-					if ($globalDebug) echo 'Add source stats : ';
1003
+					if ($globalDebug) {
1004
+						echo 'Add source stats : ';
1005
+					}
793 1006
 				        foreach($this->stats as $date => $data) {
794 1007
 					    foreach($data as $source => $sourced) {
795 1008
 					        //print_r($sourced);
796
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
797
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
1009
+				    	        if (isset($sourced['polar'])) {
1010
+				    	        	echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
1011
+				    	        }
1012
+				    	        if (isset($sourced['hist'])) {
1013
+				    	        	echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
1014
+				    	        }
798 1015
 				    		if (isset($sourced['msg'])) {
799 1016
 				    		    if (time() - $sourced['msg']['date'] > 10) {
800 1017
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
@@ -807,13 +1024,17 @@  discard block
 block discarded – undo
807 1024
 			    			unset($this->stats[$date]);
808 1025
 			    		    }
809 1026
 				    	}
810
-				    	if ($globalDebug) echo 'Done'."\n";
1027
+				    	if ($globalDebug) {
1028
+				    		echo 'Done'."\n";
1029
+				    	}
811 1030
 
812 1031
 				    }
813 1032
 				    $Stats->db = null;
814 1033
 				    }
815 1034
 				    $this->del();
816
-				} elseif ($globalDebug) echo 'Ignore data'."\n";
1035
+				} elseif ($globalDebug) {
1036
+					echo 'Ignore data'."\n";
1037
+				}
817 1038
 				//$ignoreImport = false;
818 1039
 				$this->all_flights[$id]['addedSpotter'] = 1;
819 1040
 				//print_r($this->all_flights[$id]);
@@ -830,7 +1051,9 @@  discard block
 block discarded – undo
830 1051
 			*/
831 1052
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
832 1053
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
833
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
1054
+				    if ($globalDebug) {
1055
+				    	echo "---- Deleting Live Spotter data older than 9 hours...";
1056
+				    }
834 1057
 				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
835 1058
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
836 1059
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
@@ -839,7 +1062,9 @@  discard block
 block discarded – undo
839 1062
 					    $SpotterLive->db=null;
840 1063
 					}
841 1064
 				    }
842
-				    if ($globalDebug) echo " Done\n";
1065
+				    if ($globalDebug) {
1066
+				    	echo " Done\n";
1067
+				    }
843 1068
 				    $this->last_delete = time();
844 1069
 				}
845 1070
 			    } else {
@@ -866,11 +1091,17 @@  discard block
 block discarded – undo
866 1091
 		    //echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n";
867 1092
 		    if ($globalDebug) {
868 1093
 			if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
869
-				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";
870
-				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
1094
+				if (isset($this->all_flights[$id]['source_name'])) {
1095
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";
1096
+				} else {
1097
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
1098
+				}
871 1099
 			} else {
872
-				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";
873
-				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";
1100
+				if (isset($this->all_flights[$id]['source_name'])) {
1101
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";
1102
+				} else {
1103
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";
1104
+				}
874 1105
 			}
875 1106
 		    }
876 1107
 		    $ignoreImport = false;
@@ -916,22 +1147,30 @@  discard block
 block discarded – undo
916 1147
 
917 1148
 		    if (!$ignoreImport) {
918 1149
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
919
-				if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
1150
+				if (!isset($this->all_flights[$id]['id'])) {
1151
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
1152
+				}
920 1153
 				$timeelapsed = microtime(true);
921 1154
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
922 1155
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
923
-					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1156
+					if ($globalDebug) {
1157
+						echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1158
+					}
924 1159
 					$SpotterLive = new SpotterLive($this->db);
925 1160
 					$result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
926 1161
 					$SpotterLive->db = null;
927
-					if ($globalDebug) echo $result."\n";
1162
+					if ($globalDebug) {
1163
+						echo $result."\n";
1164
+					}
928 1165
 				    }
929 1166
 				}
930 1167
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) {
931 1168
 					$APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
932 1169
 				}
933 1170
 				$this->all_flights[$id]['putinarchive'] = false;
934
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1171
+				if ($globalDebugTimeElapsed) {
1172
+					echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1173
+				}
935 1174
 
936 1175
 				// Put statistics in $this->stats variable
937 1176
 				//if ($line['format_source'] != 'aprs') {
@@ -939,7 +1178,9 @@  discard block
 block discarded – undo
939 1178
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
940 1179
 				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
941 1180
 					$source = $this->all_flights[$id]['source_name'];
942
-					if ($source == '') $source = $this->all_flights[$id]['format_source'];
1181
+					if ($source == '') {
1182
+						$source = $this->all_flights[$id]['format_source'];
1183
+					}
943 1184
 					if (!isset($this->source_location[$source])) {
944 1185
 						$Location = new Source();
945 1186
 						$coord = $Location->getLocationInfobySourceName($source);
@@ -960,7 +1201,9 @@  discard block
 block discarded – undo
960 1201
 					$stats_heading = round($stats_heading/22.5);
961 1202
 					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
962 1203
 					$current_date = date('Y-m-d');
963
-					if ($stats_heading == 16) $stats_heading = 0;
1204
+					if ($stats_heading == 16) {
1205
+						$stats_heading = 0;
1206
+					}
964 1207
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
965 1208
 						for ($i=0;$i<=15;$i++) {
966 1209
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
@@ -978,7 +1221,9 @@  discard block
 block discarded – undo
978 1221
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
979 1222
 						    end($this->stats[$current_date][$source]['hist']);
980 1223
 						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
981
-						} else $mini = 0;
1224
+						} else {
1225
+							$mini = 0;
1226
+						}
982 1227
 						for ($i=$mini;$i<=$distance;$i+=10) {
983 1228
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
984 1229
 						}
@@ -990,19 +1235,27 @@  discard block
 block discarded – undo
990 1235
 				}
991 1236
 
992 1237
 				$this->all_flights[$id]['lastupdate'] = time();
993
-				if ($this->all_flights[$id]['putinarchive']) $send = true;
1238
+				if ($this->all_flights[$id]['putinarchive']) {
1239
+					$send = true;
1240
+				}
994 1241
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
995
-			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1242
+			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
1243
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1244
+			}
996 1245
 			//$this->del();
997 1246
 			
998 1247
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
999 1248
 			    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
1000
-				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1249
+				if ($globalDebug) {
1250
+					echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1251
+				}
1001 1252
 				$SpotterLive = new SpotterLive($this->db);
1002 1253
 				$SpotterLive->deleteLiveSpotterDataNotUpdated();
1003 1254
 				$SpotterLive->db = null;
1004 1255
 				//SpotterLive->deleteLiveSpotterData();
1005
-				if ($globalDebug) echo " Done\n";
1256
+				if ($globalDebug) {
1257
+					echo " Done\n";
1258
+				}
1006 1259
 				$this->last_delete_hourly = time();
1007 1260
 			    } else {
1008 1261
 				$this->del();
@@ -1014,7 +1267,9 @@  discard block
 block discarded – undo
1014 1267
 		    //$ignoreImport = false;
1015 1268
 		}
1016 1269
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
1017
-		if ($send) return $this->all_flights[$id];
1270
+		if ($send) {
1271
+			return $this->all_flights[$id];
1272
+		}
1018 1273
 	    }
1019 1274
 	}
1020 1275
     }
Please login to merge, or discard this patch.
require/class.SpotterLive.php 1 patch
Braces   +86 added lines, -29 removed lines patch added patch discarded remove patch
@@ -29,7 +29,9 @@  discard block
 block discarded – undo
29 29
 		if (isset($filter[0]['source'])) {
30 30
 			$filters = array_merge($filters,$filter);
31 31
 		}
32
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
32
+		if (is_array($globalFilter)) {
33
+			$filter = array_merge($filter,$globalFilter);
34
+		}
33 35
 		$filter_query_join = '';
34 36
 		$filter_query_where = '';
35 37
 		foreach($filters as $flt) {
@@ -118,8 +120,11 @@  discard block
 block discarded – undo
118 120
 		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
119 121
 			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
120 122
 		}
121
-		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
122
-		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
123
+		if ($filter_query_where == '' && $where) {
124
+			$filter_query_where = ' WHERE';
125
+		} elseif ($filter_query_where != '' && $and) {
126
+			$filter_query_where .= ' AND';
127
+		}
123 128
 		if ($filter_query_where != '') {
124 129
 			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
125 130
 		}
@@ -160,9 +165,13 @@  discard block
 block discarded – undo
160 165
 				$orderby_query = ' '.$search_orderby_array[$sort]['sql'];
161 166
 			}
162 167
 		}
163
-		if ($orderby_query == '') $orderby_query = ' ORDER BY date DESC';
168
+		if ($orderby_query == '') {
169
+			$orderby_query = ' ORDER BY date DESC';
170
+		}
164 171
 
165
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
172
+		if (!isset($globalLiveInterval)) {
173
+			$globalLiveInterval = '200';
174
+		}
166 175
 		if ($globalDBdriver == 'mysql') {
167 176
 			//$query  = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate";
168 177
 			$query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query.$orderby_query;
@@ -185,7 +194,9 @@  discard block
 block discarded – undo
185 194
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
186 195
 		date_default_timezone_set('UTC');
187 196
 		$filter_query = $this->getFilter($filter,true,true);
188
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
197
+		if (!isset($globalLiveInterval)) {
198
+			$globalLiveInterval = '200';
199
+		}
189 200
 		if ($globalDBdriver == 'mysql') {
190 201
 			if (isset($globalArchive) && $globalArchive === TRUE) {
191 202
 				$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source 
@@ -228,7 +239,9 @@  discard block
 block discarded – undo
228 239
 
229 240
 		$filter_query = $this->getFilter($filter,true,true);
230 241
 
231
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
242
+		if (!isset($globalLiveInterval)) {
243
+			$globalLiveInterval = '200';
244
+		}
232 245
 		if ($globalDBdriver == 'mysql') {
233 246
 			if (isset($globalArchive) && $globalArchive === TRUE) {
234 247
 				$query  = 'SELECT spotter_archive.ident, spotter_archive.flightaware_id, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, spotter_archive.date, spotter_archive.format_source 
@@ -274,7 +287,9 @@  discard block
 block discarded – undo
274 287
 		global $globalDBdriver, $globalLiveInterval;
275 288
 		$filter_query = $this->getFilter($filter,true,true);
276 289
 
277
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
290
+		if (!isset($globalLiveInterval)) {
291
+			$globalLiveInterval = '200';
292
+		}
278 293
 		if ($globalDBdriver == 'mysql') {
279 294
 			//$query  = 'SELECT COUNT(*) as nb FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query;
280 295
 			$query = 'SELECT COUNT(DISTINCT spotter_live.flightaware_id) as nb FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
@@ -304,7 +319,9 @@  discard block
 block discarded – undo
304 319
 	{
305 320
 		global $globalDBdriver, $globalLiveInterval;
306 321
 		$Spotter = new Spotter($this->db);
307
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
322
+		if (!isset($globalLiveInterval)) {
323
+			$globalLiveInterval = '200';
324
+		}
308 325
 		$filter_query = $this->getFilter($filter);
309 326
 
310 327
 		if (is_array($coord)) {
@@ -312,7 +329,9 @@  discard block
 block discarded – undo
312 329
 			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
313 330
 			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
314 331
 			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
315
-		} else return array();
332
+		} else {
333
+			return array();
334
+		}
316 335
 		if ($globalDBdriver == 'mysql') {
317 336
 			$query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND spotter_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND spotter_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.' GROUP BY spotter_live.flightaware_id'.$filter_query;
318 337
 		} else {
@@ -333,7 +352,9 @@  discard block
 block discarded – undo
333 352
 	{
334 353
 		global $globalDBdriver, $globalLiveInterval, $globalArchive;
335 354
 		$Spotter = new Spotter($this->db);
336
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
355
+		if (!isset($globalLiveInterval)) {
356
+			$globalLiveInterval = '200';
357
+		}
337 358
 		$filter_query = $this->getFilter($filter,true,true);
338 359
 
339 360
 		if (is_array($coord)) {
@@ -341,7 +362,9 @@  discard block
 block discarded – undo
341 362
 			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
342 363
 			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
343 364
 			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
344
-		} else return array();
365
+		} else {
366
+			return array();
367
+		}
345 368
 		if ($globalDBdriver == 'mysql') {
346 369
 			if (isset($globalArchive) && $globalArchive === TRUE) {
347 370
 				$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source 
@@ -571,11 +594,15 @@  discard block
 block discarded – undo
571 594
 		//$query  = self::$global_query.' WHERE spotter_live.flightaware_id = :id ORDER BY date';
572 595
 		if ($globalDBdriver == 'mysql') {
573 596
 			$query = 'SELECT spotter_live.* FROM spotter_live WHERE spotter_live.flightaware_id = :id';
574
-			if ($liveinterval) $query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
597
+			if ($liveinterval) {
598
+				$query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
599
+			}
575 600
 			$query .= ' ORDER BY date';
576 601
 		} else {
577 602
 			$query = 'SELECT spotter_live.* FROM spotter_live WHERE spotter_live.flightaware_id = :id';
578
-			if ($liveinterval) $query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
603
+			if ($liveinterval) {
604
+				$query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
605
+			}
579 606
 			$query .= ' ORDER BY date';
580 607
 		}
581 608
 
@@ -670,7 +697,9 @@  discard block
 block discarded – undo
670 697
 				$i++;
671 698
 				$j++;
672 699
 				if ($j == 30) {
673
-					if ($globalDebug) echo ".";
700
+					if ($globalDebug) {
701
+						echo ".";
702
+					}
674 703
 				    	try {
675 704
 						
676 705
 						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
@@ -977,7 +1006,9 @@  discard block
 block discarded – undo
977 1006
 			{
978 1007
 				return false;
979 1008
 			}
980
-		} else return '';
1009
+		} else {
1010
+			return '';
1011
+		}
981 1012
 
982 1013
 		if ($longitude != '')
983 1014
 		{
@@ -985,7 +1016,9 @@  discard block
 block discarded – undo
985 1016
 			{
986 1017
 				return false;
987 1018
 			}
988
-		} else return '';
1019
+		} else {
1020
+			return '';
1021
+		}
989 1022
 
990 1023
 		if ($waypoints != '')
991 1024
 		{
@@ -1001,14 +1034,18 @@  discard block
 block discarded – undo
1001 1034
 			{
1002 1035
 				return false;
1003 1036
 			}
1004
-		} else $altitude = 0;
1037
+		} else {
1038
+			$altitude = 0;
1039
+		}
1005 1040
 		if ($altitude_real != '')
1006 1041
 		{
1007 1042
 			if (!is_numeric($altitude_real))
1008 1043
 			{
1009 1044
 				return false;
1010 1045
 			}
1011
-		} else $altitude_real = 0;
1046
+		} else {
1047
+			$altitude_real = 0;
1048
+		}
1012 1049
 
1013 1050
 		if ($heading != '')
1014 1051
 		{
@@ -1016,7 +1053,9 @@  discard block
 block discarded – undo
1016 1053
 			{
1017 1054
 				return false;
1018 1055
 			}
1019
-		} else $heading = 0;
1056
+		} else {
1057
+			$heading = 0;
1058
+		}
1020 1059
 
1021 1060
 		if ($groundspeed != '')
1022 1061
 		{
@@ -1024,9 +1063,13 @@  discard block
 block discarded – undo
1024 1063
 			{
1025 1064
 				return false;
1026 1065
 			}
1027
-		} else $groundspeed = 0;
1066
+		} else {
1067
+			$groundspeed = 0;
1068
+		}
1028 1069
 		date_default_timezone_set('UTC');
1029
-		if ($date == '') $date = date("Y-m-d H:i:s", time());
1070
+		if ($date == '') {
1071
+			$date = date("Y-m-d H:i:s", time());
1072
+		}
1030 1073
 
1031 1074
         
1032 1075
 		$flightaware_id = filter_var($flightaware_id,FILTER_SANITIZE_STRING);
@@ -1071,14 +1114,24 @@  discard block
 block discarded – undo
1071 1114
 		$arrival_airport_country = '';
1072 1115
 		
1073 1116
             	
1074
-            	if ($squawk == '' || $Common->isInteger($squawk) === false ) $squawk = NULL;
1075
-            	if ($verticalrate == '' || $Common->isInteger($verticalrate) === false ) $verticalrate = NULL;
1076
-            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
1077
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
1117
+            	if ($squawk == '' || $Common->isInteger($squawk) === false ) {
1118
+            		$squawk = NULL;
1119
+            	}
1120
+            	if ($verticalrate == '' || $Common->isInteger($verticalrate) === false ) {
1121
+            		$verticalrate = NULL;
1122
+            	}
1123
+            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) {
1124
+            		$groundspeed = 0;
1125
+            	}
1126
+            	if ($heading == '' || $Common->isInteger($heading) === false ) {
1127
+            		$heading = 0;
1128
+            	}
1078 1129
 		
1079 1130
 		$query = '';
1080 1131
 		if ($globalArchive) {
1081
-			if ($globalDebug) echo '-- Delete previous data -- ';
1132
+			if ($globalDebug) {
1133
+				echo '-- Delete previous data -- ';
1134
+			}
1082 1135
 			$query .= 'DELETE FROM spotter_live WHERE flightaware_id = :flightaware_id;';
1083 1136
 		}
1084 1137
 
@@ -1095,10 +1148,14 @@  discard block
 block discarded – undo
1095 1148
 			return "error : ".$e->getMessage();
1096 1149
 		}
1097 1150
 		if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) {
1098
-		    if ($globalDebug) echo '(Add to SBS archive : ';
1151
+		    if ($globalDebug) {
1152
+		    	echo '(Add to SBS archive : ';
1153
+		    }
1099 1154
 		    $SpotterArchive = new SpotterArchive($this->db);
1100 1155
 		    $result =  $SpotterArchive->addSpotterArchiveData($flightaware_id, $ident, $registration, $airline_name, $airline_icao, $airline_country, $airline_type, $aircraft_icao, $aircraft_shadow, $aircraft_name, $aircraft_manufacturer, $departure_airport_icao, $departure_airport_name, $departure_airport_city, $departure_airport_country, $departure_airport_time,$arrival_airport_icao, $arrival_airport_name, $arrival_airport_city, $arrival_airport_country, $arrival_airport_time, $route_stop, $date,$latitude, $longitude, $waypoints, $altitude, $altitude_real,$heading, $groundspeed, $squawk, $ModeS, $pilot_id, $pilot_name,$verticalrate,$format_source,$source_name, $over_country);
1101
-		    if ($globalDebug) echo $result.')';
1156
+		    if ($globalDebug) {
1157
+		    	echo $result.')';
1158
+		    }
1102 1159
 		} elseif ($globalDebug && $putinarchive !== true) {
1103 1160
 			echo '(Not adding to archive)';
1104 1161
 		} elseif ($globalDebug && $noarchive === true) {
Please login to merge, or discard this patch.