Completed
Push — master ( bd938e...e4cf93 )
by Yannick
08:57
created
scripts/daemon-spotter.php 1 patch
Braces   +908 added lines, -312 removed lines patch added patch discarded remove patch
@@ -13,13 +13,17 @@  discard block
 block discarded – undo
13 13
 require_once(dirname(__FILE__).'/../require/class.SBS.php');
14 14
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
15 15
 require_once(dirname(__FILE__).'/../require/class.Common.php');
16
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
16
+if (isset($globalTracker) && $globalTracker) {
17
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
18
+}
17 19
 if (isset($globalMarine) && $globalMarine) {
18 20
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
19 21
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
20 22
 }
21 23
 
22
-if (!isset($globalDebug)) $globalDebug = FALSE;
24
+if (!isset($globalDebug)) {
25
+	$globalDebug = FALSE;
26
+}
23 27
 
24 28
 // Check if schema is at latest version
25 29
 $Connection = new Connection();
@@ -54,35 +58,62 @@  discard block
 block discarded – undo
54 58
 //elseif (isset($options['source'])) $hosts = array($options['source']);
55 59
 if (isset($options['s'])) {
56 60
     $globalSources = array();
57
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
58
-    else $globalSources[] = array('host' => $options['s']);
59
-} elseif (isset($options['source'])) {
61
+    if (isset($options['format'])) {
62
+    	$globalSources[] = array('host' => $options['s'],'format' => $options['format']);
63
+    } else {
64
+    	$globalSources[] = array('host' => $options['s']);
65
+    }
66
+    } elseif (isset($options['source'])) {
60 67
     $globalSources = array();
61
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
62
-    else $globalSources[] = array('host' => $options['source']);
63
-}
68
+    if (isset($options['format'])) {
69
+    	$globalSources[] = array('host' => $options['source'],'format' => $options['format']);
70
+    } else {
71
+    	$globalSources[] = array('host' => $options['source']);
72
+    }
73
+    }
64 74
 if (isset($options['aprsserverhost'])) {
65 75
 	$globalServerAPRS = TRUE;
66 76
 	$globalServerAPRShost = $options['aprsserverhost'];
67 77
 }
68
-if (isset($options['aprsserverport'])) $globalServerAPRSport = $options['aprsserverport'];
69
-if (isset($options['aprsserverssid'])) $globalServerAPRSssid = $options['aprsserverssid'];
70
-if (isset($options['aprsserverpass'])) $globalServerAPRSpass = $options['aprsserverpass'];
71
-if (isset($options['noaprsserver'])) $globalServerAPRS = FALSE; 
72
-if (isset($options['nodaemon'])) $globalDaemon = FALSE;
73
-if (isset($options['server'])) $globalServer = TRUE;
74
-if (isset($options['idsource'])) $id_source = $options['idsource'];
75
-else $id_source = 1;
78
+if (isset($options['aprsserverport'])) {
79
+	$globalServerAPRSport = $options['aprsserverport'];
80
+}
81
+if (isset($options['aprsserverssid'])) {
82
+	$globalServerAPRSssid = $options['aprsserverssid'];
83
+}
84
+if (isset($options['aprsserverpass'])) {
85
+	$globalServerAPRSpass = $options['aprsserverpass'];
86
+}
87
+if (isset($options['noaprsserver'])) {
88
+	$globalServerAPRS = FALSE;
89
+}
90
+if (isset($options['nodaemon'])) {
91
+	$globalDaemon = FALSE;
92
+}
93
+if (isset($options['server'])) {
94
+	$globalServer = TRUE;
95
+}
96
+if (isset($options['idsource'])) {
97
+	$id_source = $options['idsource'];
98
+} else {
99
+	$id_source = 1;
100
+}
76 101
 if (isset($globalServer) && $globalServer) {
77
-    if ($globalDebug) echo "Using Server Mode\n";
102
+    if ($globalDebug) {
103
+    	echo "Using Server Mode\n";
104
+    }
78 105
     $SI=new SpotterServer();
79 106
 /*
80 107
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
81 108
     $SI = new adsb2aprs();
82 109
     $SI->connect();
83 110
 */
84
-} else $SI=new SpotterImport($Connection->db);
85
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
111
+} else {
112
+	$SI=new SpotterImport($Connection->db);
113
+}
114
+if (isset($globalTracker) && $globalTracker) {
115
+	$TI = new TrackerImport($Connection->db);
116
+}
86 117
 if (isset($globalMarine) && $globalMarine) {
87 118
     $AIS = new AIS();
88 119
     $MI = new MarineImport($Connection->db);
@@ -104,7 +135,9 @@  discard block
 block discarded – undo
104 135
 }
105 136
 
106 137
 // let's try and connect
107
-if ($globalDebug) echo "Connecting...\n";
138
+if ($globalDebug) {
139
+	echo "Connecting...\n";
140
+}
108 141
 $use_aprs = false;
109 142
 $aprs_full = false;
110 143
 $reset = 0;
@@ -113,7 +146,9 @@  discard block
 block discarded – undo
113 146
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
114 147
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
115 148
     $reset++;
116
-    if ($globalDebug) echo 'Connect to all...'."\n";
149
+    if ($globalDebug) {
150
+    	echo 'Connect to all...'."\n";
151
+    }
117 152
     foreach ($hosts as $id => $value) {
118 153
 	$host = $value['host'];
119 154
 	$globalSources[$id]['last_exec'] = 0;
@@ -123,27 +158,37 @@  discard block
 block discarded – undo
123 158
         	//$formats[$id] = 'deltadbtxt';
124 159
         	$globalSources[$id]['format'] = 'deltadbtxt';
125 160
         	//$last_exec['deltadbtxt'] = 0;
126
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
161
+        	if ($globalDebug) {
162
+        		echo "Connect to deltadb source (".$host.")...\n";
163
+        	}
127 164
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
128 165
         	//$formats[$id] = 'vatsimtxt';
129 166
         	$globalSources[$id]['format'] = 'vatsimtxt';
130 167
         	//$last_exec['vatsimtxt'] = 0;
131
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
168
+        	if ($globalDebug) {
169
+        		echo "Connect to vatsim source (".$host.")...\n";
170
+        	}
132 171
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
133 172
         	//$formats[$id] = 'aircraftlistjson';
134 173
         	$globalSources[$id]['format'] = 'aircraftlistjson';
135 174
         	//$last_exec['aircraftlistjson'] = 0;
136
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
175
+        	if ($globalDebug) {
176
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
177
+        	}
137 178
     	    } else if (preg_match('/opensky/i',$host)) {
138 179
         	//$formats[$id] = 'aircraftlistjson';
139 180
         	$globalSources[$id]['format'] = 'opensky';
140 181
         	//$last_exec['aircraftlistjson'] = 0;
141
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
182
+        	if ($globalDebug) {
183
+        		echo "Connect to opensky source (".$host.")...\n";
184
+        	}
142 185
     	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
143 186
         	//$formats[$id] = 'radarvirtueljson';
144 187
         	$globalSources[$id]['format'] = 'radarvirtueljson';
145 188
         	//$last_exec['radarvirtueljson'] = 0;
146
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
189
+        	if ($globalDebug) {
190
+        		echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
191
+        	}
147 192
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
148 193
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
149 194
         	    exit(0);
@@ -152,7 +197,9 @@  discard block
 block discarded – undo
152 197
         	//$formats[$id] = 'planeupdatefaa';
153 198
         	$globalSources[$id]['format'] = 'planeupdatefaa';
154 199
         	//$last_exec['planeupdatefaa'] = 0;
155
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
200
+        	if ($globalDebug) {
201
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
202
+        	}
156 203
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
157 204
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
158 205
         	    exit(0);
@@ -161,26 +208,36 @@  discard block
 block discarded – undo
161 208
         	//$formats[$id] = 'phpvmacars';
162 209
         	$globalSources[$id]['format'] = 'phpvmacars';
163 210
         	//$last_exec['phpvmacars'] = 0;
164
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
211
+        	if ($globalDebug) {
212
+        		echo "Connect to phpvmacars source (".$host.")...\n";
213
+        	}
165 214
             } else if (preg_match('/VAM-json.php$/i',$host)) {
166 215
         	//$formats[$id] = 'phpvmacars';
167 216
         	$globalSources[$id]['format'] = 'vam';
168
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
217
+        	if ($globalDebug) {
218
+        		echo "Connect to Vam source (".$host.")...\n";
219
+        	}
169 220
             } else if (preg_match('/whazzup/i',$host)) {
170 221
         	//$formats[$id] = 'whazzup';
171 222
         	$globalSources[$id]['format'] = 'whazzup';
172 223
         	//$last_exec['whazzup'] = 0;
173
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
224
+        	if ($globalDebug) {
225
+        		echo "Connect to whazzup source (".$host.")...\n";
226
+        	}
174 227
             } else if (preg_match('/recentpireps/i',$host)) {
175 228
         	//$formats[$id] = 'pirepsjson';
176 229
         	$globalSources[$id]['format'] = 'pirepsjson';
177 230
         	//$last_exec['pirepsjson'] = 0;
178
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
231
+        	if ($globalDebug) {
232
+        		echo "Connect to pirepsjson source (".$host.")...\n";
233
+        	}
179 234
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
180 235
         	//$formats[$id] = 'fr24json';
181 236
         	$globalSources[$id]['format'] = 'fr24json';
182 237
         	//$last_exec['fr24json'] = 0;
183
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
238
+        	if ($globalDebug) {
239
+        		echo "Connect to fr24 source (".$host.")...\n";
240
+        	}
184 241
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
185 242
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
186 243
         	    exit(0);
@@ -189,7 +246,9 @@  discard block
 block discarded – undo
189 246
         	//$formats[$id] = 'fr24json';
190 247
         	$globalSources[$id]['format'] = 'myshiptracking';
191 248
         	//$last_exec['fr24json'] = 0;
192
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
249
+        	if ($globalDebug) {
250
+        		echo "Connect to myshiptracking source (".$host.")...\n";
251
+        	}
193 252
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
194 253
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
195 254
         	    exit(0);
@@ -198,17 +257,24 @@  discard block
 block discarded – undo
198 257
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
199 258
         	//$formats[$id] = 'tsv';
200 259
         	$globalSources[$id]['format'] = 'tsv';
201
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
260
+        	if ($globalDebug) {
261
+        		echo "Connect to tsv source (".$host.")...\n";
262
+        	}
202 263
             }
203 264
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
204 265
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
205 266
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
206 267
     		    if ($idf !== false) {
207 268
     			$httpfeeds[$id] = $idf;
208
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
269
+        		if ($globalDebug) {
270
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
271
+        		}
272
+    		    } elseif ($globalDebug) {
273
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
209 274
     		    }
210
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
211
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
275
+    		} elseif ($globalDebug) {
276
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
277
+    		}
212 278
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
213 279
 	    $hostport = explode(':',$host);
214 280
 	    if (isset($hostport[1])) {
@@ -248,17 +314,25 @@  discard block
 block discarded – undo
248 314
         		//$formats[$id] = 'beast';
249 315
         		$globalSources[$id]['format'] = 'beast';
250 316
 		    //} else $formats[$id] = 'sbs';
251
-		    } else $globalSources[$id]['format'] = 'sbs';
317
+		    } else {
318
+		    	$globalSources[$id]['format'] = 'sbs';
319
+		    }
252 320
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
253 321
 		}
254
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
322
+		if ($globalDebug) {
323
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
324
+		}
255 325
             } else {
256
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
326
+		if ($globalDebug) {
327
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
328
+		}
257 329
     	    }
258 330
         }
259 331
     }
260 332
 }
261
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
333
+if (!isset($globalMinFetch)) {
334
+	$globalMinFetch = 15;
335
+}
262 336
 
263 337
 // Initialize all
264 338
 $status = array();
@@ -267,13 +341,19 @@  discard block
 block discarded – undo
267 341
 $formats = array();
268 342
 $last_exec = array();
269 343
 $time = time();
270
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
271
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
272
-else $timeout = 20;
344
+if (isset($globalSourcesTimeout)) {
345
+	$timeout = $globalSourcesTimeOut;
346
+} else if (isset($globalSBS1TimeOut)) {
347
+	$timeout = $globalSBS1TimeOut;
348
+} else {
349
+	$timeout = 20;
350
+}
273 351
 $errno = '';
274 352
 $errstr='';
275 353
 
276
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
354
+if (!isset($globalDaemon)) {
355
+	$globalDaemon = TRUE;
356
+}
277 357
 /* Initiate connections to all the hosts simultaneously */
278 358
 //connect_all($hosts);
279 359
 //connect_all($globalSources);
@@ -299,7 +379,9 @@  discard block
 block discarded – undo
299 379
     if (isset($source['format']) && $source['format'] == 'aprs') {
300 380
 	$aprs_connect = 0;
301 381
 	$use_aprs = true;
302
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
382
+	if (isset($source['port']) && $source['port'] == '10152') {
383
+		$aprs_full = true;
384
+	}
303 385
 	break;
304 386
     }
305 387
 }
@@ -310,25 +392,48 @@  discard block
 block discarded – undo
310 392
 	$aprs_connect = 0;
311 393
 	$aprs_keep = 120;
312 394
 	$aprs_last_tx = time();
313
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
314
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
315
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
316
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
317
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
318
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
319
-	if ($aprs_full) $aprs_filter = '';
320
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
321
-	else $aprs_pass = '-1';
395
+	if (isset($globalAPRSversion)) {
396
+		$aprs_version = $globalAPRSversion;
397
+	} else {
398
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
399
+	}
400
+	if (isset($globalAPRSssid)) {
401
+		$aprs_ssid = $globalAPRSssid;
402
+	} else {
403
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
404
+	}
405
+	if (isset($globalAPRSfilter)) {
406
+		$aprs_filter = $globalAPRSfilter;
407
+	} else {
408
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
409
+	}
410
+	if ($aprs_full) {
411
+		$aprs_filter = '';
412
+	}
413
+	if (isset($globalAPRSpass)) {
414
+		$aprs_pass = $globalAPRSpass;
415
+	} else {
416
+		$aprs_pass = '-1';
417
+	}
322 418
 
323
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
324
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
325
-}
419
+	if ($aprs_filter != '') {
420
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
421
+	} else {
422
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
423
+	}
424
+	}
326 425
 
327 426
 // connected - lets do some work
328
-if ($globalDebug) echo "Connected!\n";
427
+if ($globalDebug) {
428
+	echo "Connected!\n";
429
+}
329 430
 sleep(1);
330
-if ($globalDebug) echo "SCAN MODE \n\n";
331
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
431
+if ($globalDebug) {
432
+	echo "SCAN MODE \n\n";
433
+}
434
+if (!isset($globalCronEnd)) {
435
+	$globalCronEnd = 60;
436
+}
332 437
 $endtime = time()+$globalCronEnd;
333 438
 $i = 1;
334 439
 $tt = array();
@@ -342,10 +447,14 @@  discard block
 block discarded – undo
342 447
 
343 448
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
344 449
 while ($i > 0) {
345
-    if (!$globalDaemon) $i = $endtime-time();
450
+    if (!$globalDaemon) {
451
+    	$i = $endtime-time();
452
+    }
346 453
     // Delete old ATC
347 454
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
348
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
455
+	if ($globalDebug) {
456
+		echo 'Delete old ATC...'."\n";
457
+	}
349 458
         $ATC->deleteOldATC();
350 459
     }
351 460
     
@@ -353,10 +462,14 @@  discard block
 block discarded – undo
353 462
     if (count($last_exec) == count($globalSources)) {
354 463
 	$max = $globalMinFetch;
355 464
 	foreach ($last_exec as $last) {
356
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
465
+	    if ((time() - $last['last']) < $max) {
466
+	    	$max = time() - $last['last'];
467
+	    }
357 468
 	}
358 469
 	if ($max != $globalMinFetch) {
359
-	    if ($globalDebug) echo 'Sleeping...'."\n";
470
+	    if ($globalDebug) {
471
+	    	echo 'Sleeping...'."\n";
472
+	    }
360 473
 	    sleep($globalMinFetch-$max+2);
361 474
 	}
362 475
     }
@@ -365,11 +478,15 @@  discard block
 block discarded – undo
365 478
     //foreach ($formats as $id => $value) {
366 479
     foreach ($globalSources as $id => $value) {
367 480
 	date_default_timezone_set('UTC');
368
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
481
+	if (!isset($last_exec[$id]['last'])) {
482
+		$last_exec[$id]['last'] = 0;
483
+	}
369 484
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
370 485
 	    //$buffer = $Common->getData($hosts[$id]);
371 486
 	    $buffer = $Common->getData($value['host']);
372
-	    if ($buffer != '') $reset = 0;
487
+	    if ($buffer != '') {
488
+	    	$reset = 0;
489
+	    }
373 490
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
374 491
 	    $buffer = explode('\n',$buffer);
375 492
 	    foreach ($buffer as $line) {
@@ -378,20 +495,41 @@  discard block
 block discarded – undo
378 495
 	            $data = array();
379 496
 	            $data['hex'] = $line[1]; // hex
380 497
 	            $data['ident'] = $line[2]; // ident
381
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
382
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
383
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
384
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
385
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
498
+	            if (isset($line[3])) {
499
+	            	$data['altitude'] = $line[3];
500
+	            }
501
+	            // altitude
502
+	            if (isset($line[4])) {
503
+	            	$data['speed'] = $line[4];
504
+	            }
505
+	            // speed
506
+	            if (isset($line[5])) {
507
+	            	$data['heading'] = $line[5];
508
+	            }
509
+	            // heading
510
+	            if (isset($line[6])) {
511
+	            	$data['latitude'] = $line[6];
512
+	            }
513
+	            // lat
514
+	            if (isset($line[7])) {
515
+	            	$data['longitude'] = $line[7];
516
+	            }
517
+	            // long
386 518
 	            $data['verticalrate'] = ''; // vertical rate
387 519
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
388 520
 	            $data['emergency'] = ''; // emergency
389 521
 		    $data['datetime'] = date('Y-m-d H:i:s');
390 522
 		    $data['format_source'] = 'deltadbtxt';
391 523
     		    $data['id_source'] = $id_source;
392
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
393
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
394
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
524
+		    if (isset($value['name']) && $value['name'] != '') {
525
+		    	$data['source_name'] = $value['name'];
526
+		    }
527
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
528
+		    	$data['noarchive'] = true;
529
+		    }
530
+		    if (isset($value['sourcestats'])) {
531
+		    	$data['sourcestats'] = $value['sourcestats'];
532
+		    }
395 533
     		    $SI->add($data);
396 534
 		    unset($data);
397 535
     		}
@@ -401,7 +539,9 @@  discard block
 block discarded – undo
401 539
 	    date_default_timezone_set('CET');
402 540
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
403 541
 	    date_default_timezone_set('UTC');
404
-	    if ($buffer != '') $reset = 0;
542
+	    if ($buffer != '') {
543
+	    	$reset = 0;
544
+	    }
405 545
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
406 546
 	    $buffer = explode('\n',$buffer);
407 547
 	    foreach ($buffer as $line) {
@@ -410,16 +550,36 @@  discard block
 block discarded – undo
410 550
 		    $add = false;
411 551
 		    $ais_data = $AIS->parse_line(trim($line));
412 552
 		    $data = array();
413
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
414
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
415
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
416
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
417
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
418
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
419
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
420
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
421
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
422
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
553
+		    if (isset($ais_data['ident'])) {
554
+		    	$data['ident'] = $ais_data['ident'];
555
+		    }
556
+		    if (isset($ais_data['mmsi'])) {
557
+		    	$data['mmsi'] = $ais_data['mmsi'];
558
+		    }
559
+		    if (isset($ais_data['speed'])) {
560
+		    	$data['speed'] = $ais_data['speed'];
561
+		    }
562
+		    if (isset($ais_data['heading'])) {
563
+		    	$data['heading'] = $ais_data['heading'];
564
+		    }
565
+		    if (isset($ais_data['latitude'])) {
566
+		    	$data['latitude'] = $ais_data['latitude'];
567
+		    }
568
+		    if (isset($ais_data['longitude'])) {
569
+		    	$data['longitude'] = $ais_data['longitude'];
570
+		    }
571
+		    if (isset($ais_data['status'])) {
572
+		    	$data['status'] = $ais_data['status'];
573
+		    }
574
+		    if (isset($ais_data['type'])) {
575
+		    	$data['type'] = $ais_data['type'];
576
+		    }
577
+		    if (isset($ais_data['imo'])) {
578
+		    	$data['imo'] = $ais_data['imo'];
579
+		    }
580
+		    if (isset($ais_data['callsign'])) {
581
+		    	$data['callsign'] = $ais_data['callsign'];
582
+		    }
423 583
 		    if (isset($ais_data['timestamp'])) {
424 584
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
425 585
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -434,8 +594,12 @@  discard block
 block discarded – undo
434 594
     		    $data['id_source'] = $id_source;
435 595
 		    //print_r($data);
436 596
 		    echo 'Add...'."\n";
437
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
438
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
597
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
598
+		    	$data['noarchive'] = true;
599
+		    }
600
+		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
601
+		    	$MI->add($data);
602
+		    }
439 603
 		    unset($data);
440 604
 		}
441 605
     	    }
@@ -455,19 +619,45 @@  discard block
 block discarded – undo
455 619
 			    if ($line != '') {
456 620
 				$ais_data = $AIS->parse_line(trim($line));
457 621
 				$data = array();
458
-				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
459
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
460
-				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
461
-				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
462
-				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
463
-				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
464
-				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
465
-				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
466
-				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
467
-				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
468
-				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
469
-				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
470
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
622
+				if (isset($ais_data['ident'])) {
623
+					$data['ident'] = $ais_data['ident'];
624
+				}
625
+				if (isset($ais_data['mmsi'])) {
626
+					$data['mmsi'] = $ais_data['mmsi'];
627
+				}
628
+				if (isset($ais_data['speed'])) {
629
+					$data['speed'] = $ais_data['speed'];
630
+				}
631
+				if (isset($ais_data['heading'])) {
632
+					$data['heading'] = $ais_data['heading'];
633
+				}
634
+				if (isset($ais_data['latitude'])) {
635
+					$data['latitude'] = $ais_data['latitude'];
636
+				}
637
+				if (isset($ais_data['longitude'])) {
638
+					$data['longitude'] = $ais_data['longitude'];
639
+				}
640
+				if (isset($ais_data['status'])) {
641
+					$data['status'] = $ais_data['status'];
642
+				}
643
+				if (isset($ais_data['statusid'])) {
644
+					$data['status_id'] = $ais_data['statusid'];
645
+				}
646
+				if (isset($ais_data['type'])) {
647
+					$data['type'] = $ais_data['type'];
648
+				}
649
+				if (isset($ais_data['imo'])) {
650
+					$data['imo'] = $ais_data['imo'];
651
+				}
652
+				if (isset($ais_data['callsign'])) {
653
+					$data['callsign'] = $ais_data['callsign'];
654
+				}
655
+				if (isset($ais_data['destination'])) {
656
+					$data['arrival_code'] = $ais_data['destination'];
657
+				}
658
+				if (isset($ais_data['eta_ts'])) {
659
+					$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
660
+				}
471 661
 				if (isset($ais_data['timestamp'])) {
472 662
 				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
473 663
 				} else {
@@ -475,16 +665,23 @@  discard block
 block discarded – undo
475 665
 				}
476 666
 				$data['format_source'] = 'aisnmeahttp';
477 667
 				$data['id_source'] = $id_source;
478
-				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
479
-				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
668
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
669
+					$data['noarchive'] = true;
670
+				}
671
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
672
+					$MI->add($data);
673
+				}
480 674
 				unset($data);
481 675
 			    }
482 676
 			}
483 677
 		    }
484 678
 		} else {
485 679
 		    $format = $value['format'];
486
-		    if (isset($tt[$format])) $tt[$format]++;
487
-		    else $tt[$format] = 0;
680
+		    if (isset($tt[$format])) {
681
+		    	$tt[$format]++;
682
+		    } else {
683
+		    	$tt[$format] = 0;
684
+		    }
488 685
 		    if ($tt[$format] > 30) {
489 686
 			sleep(2);
490 687
 			$sourceeen[] = $value;
@@ -515,7 +712,9 @@  discard block
 block discarded – undo
515 712
 			$data['datetime'] = date('Y-m-d H:i:s',$line['T']);
516 713
 			$data['format_source'] = 'myshiptracking';
517 714
 			$data['id_source'] = $id_source;
518
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
715
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
716
+				$data['noarchive'] = true;
717
+			}
519 718
 			$MI->add($data);
520 719
 			unset($data);
521 720
 		    }
@@ -536,7 +735,9 @@  discard block
 block discarded – undo
536 735
 			    $data['callsign'] = $line['callsign'];
537 736
 			    $data['mmsi'] = $line['mmsi'];
538 737
 			    $data['speed'] = $line['sog'];
539
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
738
+			    if ($line['heading'] != '511') {
739
+			    	$data['heading'] = $line['heading'];
740
+			    }
540 741
 			    $data['latitude'] = $line['latitude'];
541 742
 			    $data['longitude'] = $line['longitude'];
542 743
 			    $data['type_id'] = $line['shiptype'];
@@ -544,7 +745,9 @@  discard block
 block discarded – undo
544 745
 			    $data['datetime'] = $line['time'];
545 746
 			    $data['format_source'] = 'boatbeaconapp';
546 747
 			    $data['id_source'] = $id_source;
547
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
748
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
749
+			    	$data['noarchive'] = true;
750
+			    }
548 751
 			    $MI->add($data);
549 752
 			    unset($data);
550 753
 			}
@@ -557,7 +760,9 @@  discard block
 block discarded – undo
557 760
 	    echo 'download...';
558 761
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
559 762
 	    echo 'done !'."\n";
560
-	    if ($buffer != '') $reset = 0;
763
+	    if ($buffer != '') {
764
+	    	$reset = 0;
765
+	    }
561 766
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
562 767
 	    $buffer = explode('\n',$buffer);
563 768
 	    foreach ($buffer as $line) {
@@ -582,7 +787,9 @@  discard block
 block discarded – undo
582 787
 		    //$data['etaTime'] = substr($line,135,5);
583 788
 		    $data['format_source'] = 'shipplotter';
584 789
     		    $data['id_source'] = $id_source;
585
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
790
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
791
+		    	$data['noarchive'] = true;
792
+		    }
586 793
 		    //print_r($data);
587 794
 		    echo 'Add...'."\n";
588 795
 		    $MI->add($data);
@@ -602,16 +809,28 @@  discard block
 block discarded – undo
602 809
     		    $line = explode(':', $line);
603 810
     		    if (count($line) > 30 && $line[0] != 'callsign') {
604 811
 			$data = array();
605
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
606
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
812
+			if (isset($line[37]) && $line[37] != '') {
813
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
814
+			} else {
815
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
816
+			}
607 817
 			$data['pilot_id'] = $line[1];
608 818
 			$data['pilot_name'] = $line[2];
609 819
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
610 820
 			$data['ident'] = $line[0]; // ident
611
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
821
+			if ($line[7] != '' && $line[7] != 0) {
822
+				$data['altitude'] = $line[7];
823
+			}
824
+			// altitude
612 825
 			$data['speed'] = $line[8]; // speed
613
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
614
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
826
+			if (isset($line[45])) {
827
+				$data['heading'] = $line[45];
828
+			}
829
+			// heading
830
+			elseif (isset($line[38])) {
831
+				$data['heading'] = $line[38];
832
+			}
833
+			// heading
615 834
 			$data['latitude'] = $line[5]; // lat
616 835
 	        	$data['longitude'] = $line[6]; // long
617 836
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -627,7 +846,9 @@  discard block
 block discarded – undo
627 846
 			$data['frequency'] = $line[4];
628 847
 			$data['type'] = $line[18];
629 848
 			$data['range'] = $line[19];
630
-			if (isset($line[35])) $data['info'] = $line[35];
849
+			if (isset($line[35])) {
850
+				$data['info'] = $line[35];
851
+			}
631 852
     			$data['id_source'] = $id_source;
632 853
 	    		//$data['arrival_airport_time'] = ;
633 854
 	    		if ($line[9] != '') {
@@ -641,25 +862,44 @@  discard block
 block discarded – undo
641 862
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
642 863
 	    		*/
643 864
 	    		$data['format_source'] = $value['format'];
644
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
645
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
646
-    			if ($line[3] == 'PILOT') $SI->add($data);
647
-			elseif ($line[3] == 'ATC') {
865
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
866
+				$data['noarchive'] = true;
867
+			}
868
+			if (isset($value['name']) && $value['name'] != '') {
869
+				$data['source_name'] = $value['name'];
870
+			}
871
+    			if ($line[3] == 'PILOT') {
872
+    				$SI->add($data);
873
+    			} elseif ($line[3] == 'ATC') {
648 874
 				//print_r($data);
649 875
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
650 876
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
651 877
 				$typec = substr($data['ident'],-3);
652
-				if ($typec == 'APP') $data['type'] = 'Approach';
653
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
654
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
655
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
656
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
657
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
658
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
659
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
660
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
661
-				if (!isset($data['source_name'])) $data['source_name'] = '';
662
-				if (isset($ATC)) echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
878
+				if ($typec == 'APP') {
879
+					$data['type'] = 'Approach';
880
+				} elseif ($typec == 'TWR') {
881
+					$data['type'] = 'Tower';
882
+				} elseif ($typec == 'OBS') {
883
+					$data['type'] = 'Observer';
884
+				} elseif ($typec == 'GND') {
885
+					$data['type'] = 'Ground';
886
+				} elseif ($typec == 'DEL') {
887
+					$data['type'] = 'Delivery';
888
+				} elseif ($typec == 'DEP') {
889
+					$data['type'] = 'Departure';
890
+				} elseif ($typec == 'FSS') {
891
+					$data['type'] = 'Flight Service Station';
892
+				} elseif ($typec == 'CTR') {
893
+					$data['type'] = 'Control Radar or Centre';
894
+				} elseif ($data['type'] == '') {
895
+					$data['type'] = 'Observer';
896
+				}
897
+				if (!isset($data['source_name'])) {
898
+					$data['source_name'] = '';
899
+				}
900
+				if (isset($ATC)) {
901
+					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']);
902
+				}
663 903
 			}
664 904
     			unset($data);
665 905
     		    }
@@ -678,27 +918,61 @@  discard block
 block discarded – undo
678 918
 		foreach ($all_data['acList'] as $line) {
679 919
 		    $data = array();
680 920
 		    $data['hex'] = $line['Icao']; // hex
681
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
682
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
683
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
684
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
685
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
686
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
921
+		    if (isset($line['Call'])) {
922
+		    	$data['ident'] = $line['Call'];
923
+		    }
924
+		    // ident
925
+		    if (isset($line['Alt'])) {
926
+		    	$data['altitude'] = $line['Alt'];
927
+		    }
928
+		    // altitude
929
+		    if (isset($line['Spd'])) {
930
+		    	$data['speed'] = $line['Spd'];
931
+		    }
932
+		    // speed
933
+		    if (isset($line['Trak'])) {
934
+		    	$data['heading'] = $line['Trak'];
935
+		    }
936
+		    // heading
937
+		    if (isset($line['Lat'])) {
938
+		    	$data['latitude'] = $line['Lat'];
939
+		    }
940
+		    // lat
941
+		    if (isset($line['Long'])) {
942
+		    	$data['longitude'] = $line['Long'];
943
+		    }
944
+		    // long
687 945
 		    //$data['verticalrate'] = $line['']; // verticale rate
688
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
946
+		    if (isset($line['Sqk'])) {
947
+		    	$data['squawk'] = $line['Sqk'];
948
+		    }
949
+		    // squawk
689 950
 		    $data['emergency'] = ''; // emergency
690
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
951
+		    if (isset($line['Reg'])) {
952
+		    	$data['registration'] = $line['Reg'];
953
+		    }
691 954
 		    
692
-		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
693
-		    else $data['datetime'] = date('Y-m-d H:i:s');
955
+		    if (isset($line['PosTime'])) {
956
+		    	$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
957
+		    } else {
958
+		    	$data['datetime'] = date('Y-m-d H:i:s');
959
+		    }
694 960
 		    
695 961
 		    //$data['datetime'] = date('Y-m-d H:i:s');
696
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
962
+		    if (isset($line['Type'])) {
963
+		    	$data['aircraft_icao'] = $line['Type'];
964
+		    }
697 965
 	    	    $data['format_source'] = 'aircraftlistjson';
698 966
 		    $data['id_source'] = $id_source;
699
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
700
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
701
-		    if (isset($data['latitude'])) $SI->add($data);
967
+		    if (isset($value['name']) && $value['name'] != '') {
968
+		    	$data['source_name'] = $value['name'];
969
+		    }
970
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
971
+		    	$data['noarchive'] = true;
972
+		    }
973
+		    if (isset($data['latitude'])) {
974
+		    	$SI->add($data);
975
+		    }
702 976
 		    unset($data);
703 977
 		}
704 978
 	    } elseif (is_array($all_data)) {
@@ -715,12 +989,19 @@  discard block
 block discarded – undo
715 989
 		    $data['verticalrate'] = $line['vrt']; // verticale rate
716 990
 		    $data['squawk'] = $line['squawk']; // squawk
717 991
 		    $data['emergency'] = ''; // emergency
718
-		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
719
-		    else $data['datetime'] = date('Y-m-d H:i:s');
992
+		    if (isset($line['PosTime'])) {
993
+		    	$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
994
+		    } else {
995
+		    	$data['datetime'] = date('Y-m-d H:i:s');
996
+		    }
720 997
 	    	    $data['format_source'] = 'aircraftlistjson';
721 998
     		    $data['id_source'] = $id_source;
722
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
723
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
999
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1000
+		    	$data['noarchive'] = true;
1001
+		    }
1002
+		    if (isset($value['name']) && $value['name'] != '') {
1003
+		    	$data['source_name'] = $value['name'];
1004
+		    }
724 1005
 		    $SI->add($data);
725 1006
 		    unset($data);
726 1007
 		}
@@ -756,8 +1037,12 @@  discard block
 block discarded – undo
756 1037
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
757 1038
 	    	    $data['format_source'] = 'planeupdatefaa';
758 1039
     		    $data['id_source'] = $id_source;
759
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
760
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1040
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1041
+		    	$data['noarchive'] = true;
1042
+		    }
1043
+		    if (isset($value['name']) && $value['name'] != '') {
1044
+		    	$data['source_name'] = $value['name'];
1045
+		    }
761 1046
 		    $SI->add($data);
762 1047
 		    unset($data);
763 1048
 		}
@@ -786,7 +1071,9 @@  discard block
 block discarded – undo
786 1071
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
787 1072
 	    	    $data['format_source'] = 'opensky';
788 1073
     		    $data['id_source'] = $id_source;
789
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1074
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1075
+		    	$data['noarchive'] = true;
1076
+		    }
790 1077
 		    $SI->add($data);
791 1078
 		    unset($data);
792 1079
 		}
@@ -798,7 +1085,9 @@  discard block
 block discarded – undo
798 1085
 	    //$buffer = $Common->getData($hosts[$id]);
799 1086
 	    $buffer = $Common->getData($value['host']);
800 1087
 	    $all_data = json_decode($buffer,true);
801
-	    if (!empty($all_data)) $reset = 0;
1088
+	    if (!empty($all_data)) {
1089
+	    	$reset = 0;
1090
+	    }
802 1091
 	    foreach ($all_data as $key => $line) {
803 1092
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
804 1093
 		    $data = array();
@@ -819,8 +1108,12 @@  discard block
 block discarded – undo
819 1108
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
820 1109
 	    	    $data['format_source'] = 'fr24json';
821 1110
     		    $data['id_source'] = $id_source;
822
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
823
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1111
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1112
+		    	$data['noarchive'] = true;
1113
+		    }
1114
+		    if (isset($value['name']) && $value['name'] != '') {
1115
+		    	$data['source_name'] = $value['name'];
1116
+		    }
824 1117
 		    $SI->add($data);
825 1118
 		    unset($data);
826 1119
 		}
@@ -844,24 +1137,42 @@  discard block
 block discarded – undo
844 1137
 		    if (isset($line['inf'])) {
845 1138
 			$data = array();
846 1139
 			$data['hex'] = $line['inf']['ia'];
847
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1140
+			if (isset($line['inf']['cs'])) {
1141
+				$data['ident'] = $line['inf']['cs'];
1142
+			}
1143
+			//$line[13]
848 1144
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
849
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
850
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1145
+	    		if (isset($line['inf']['gs'])) {
1146
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1147
+	    		}
1148
+	    		// speed
1149
+	    		if (isset($line['inf']['tr'])) {
1150
+	    			$data['heading'] = $line['inf']['tr'];
1151
+	    		}
1152
+	    		// heading
851 1153
 	    		$data['latitude'] = $line['pt'][0]; // lat
852 1154
 	    		$data['longitude'] = $line['pt'][1]; // long
853 1155
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
854
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1156
+	    		if (isset($line['inf']['sq'])) {
1157
+	    			$data['squawk'] = $line['inf']['sq'];
1158
+	    		}
1159
+	    		// squawk
855 1160
 	    		//$data['aircraft_icao'] = $line[8];
856
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1161
+	    		if (isset($line['inf']['rc'])) {
1162
+	    			$data['registration'] = $line['inf']['rc'];
1163
+	    		}
857 1164
 			//$data['departure_airport_iata'] = $line[11];
858 1165
 			//$data['arrival_airport_iata'] = $line[12];
859 1166
 	    		//$data['emergency'] = ''; // emergency
860 1167
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
861 1168
 	    		$data['format_source'] = 'radarvirtueljson';
862 1169
     			$data['id_source'] = $id_source;
863
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
864
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1170
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1171
+				$data['noarchive'] = true;
1172
+			}
1173
+			if (isset($value['name']) && $value['name'] != '') {
1174
+				$data['source_name'] = $value['name'];
1175
+			}
865 1176
 			$SI->add($data);
866 1177
 			unset($data);
867 1178
 		    }
@@ -882,30 +1193,65 @@  discard block
 block discarded – undo
882 1193
 		    $data['id'] = $line['id'];
883 1194
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
884 1195
 		    $data['ident'] = $line['callsign']; // ident
885
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
886
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
887
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
888
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
889
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
890
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1196
+		    if (isset($line['pilotid'])) {
1197
+		    	$data['pilot_id'] = $line['pilotid'];
1198
+		    }
1199
+		    // pilot id
1200
+		    if (isset($line['name'])) {
1201
+		    	$data['pilot_name'] = $line['name'];
1202
+		    }
1203
+		    // pilot name
1204
+		    if (isset($line['alt'])) {
1205
+		    	$data['altitude'] = $line['alt'];
1206
+		    }
1207
+		    // altitude
1208
+		    if (isset($line['gs'])) {
1209
+		    	$data['speed'] = $line['gs'];
1210
+		    }
1211
+		    // speed
1212
+		    if (isset($line['heading'])) {
1213
+		    	$data['heading'] = $line['heading'];
1214
+		    }
1215
+		    // heading
1216
+		    if (isset($line['route'])) {
1217
+		    	$data['waypoints'] = $line['route'];
1218
+		    }
1219
+		    // route
891 1220
 		    $data['latitude'] = $line['lat']; // lat
892 1221
 		    $data['longitude'] = $line['lon']; // long
893 1222
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
894 1223
 		    //$data['squawk'] = $line['squawk']; // squawk
895 1224
 		    //$data['emergency'] = ''; // emergency
896
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
897
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
898
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1225
+		    if (isset($line['depicao'])) {
1226
+		    	$data['departure_airport_icao'] = $line['depicao'];
1227
+		    }
1228
+		    if (isset($line['deptime'])) {
1229
+		    	$data['departure_airport_time'] = $line['deptime'];
1230
+		    }
1231
+		    if (isset($line['arricao'])) {
1232
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1233
+		    }
899 1234
 		    //$data['arrival_airport_time'] = $line['arrtime'];
900
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
901
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
902
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
903
-		    else $data['info'] = '';
1235
+		    if (isset($line['aircraft'])) {
1236
+		    	$data['aircraft_icao'] = $line['aircraft'];
1237
+		    }
1238
+		    if (isset($line['transponder'])) {
1239
+		    	$data['squawk'] = $line['transponder'];
1240
+		    }
1241
+		    if (isset($line['atis'])) {
1242
+		    	$data['info'] = $line['atis'];
1243
+		    } else {
1244
+		    	$data['info'] = '';
1245
+		    }
904 1246
 		    $data['format_source'] = 'pireps';
905 1247
     		    $data['id_source'] = $id_source;
906 1248
 		    $data['datetime'] = date('Y-m-d H:i:s');
907
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
908
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1249
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1250
+		    	$data['noarchive'] = true;
1251
+		    }
1252
+		    if (isset($value['name']) && $value['name'] != '') {
1253
+		    	$data['source_name'] = $value['name'];
1254
+		    }
909 1255
 		    if ($line['icon'] == 'plane') {
910 1256
 			$SI->add($data);
911 1257
 		    //    print_r($data);
@@ -914,16 +1260,28 @@  discard block
 block discarded – undo
914 1260
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
915 1261
 			$typec = substr($data['ident'],-3);
916 1262
 			$data['type'] = '';
917
-			if ($typec == 'APP') $data['type'] = 'Approach';
918
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
919
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
920
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
921
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
922
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
923
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
924
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
925
-			else $data['type'] = 'Observer';
926
-			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']);
1263
+			if ($typec == 'APP') {
1264
+				$data['type'] = 'Approach';
1265
+			} elseif ($typec == 'TWR') {
1266
+				$data['type'] = 'Tower';
1267
+			} elseif ($typec == 'OBS') {
1268
+				$data['type'] = 'Observer';
1269
+			} elseif ($typec == 'GND') {
1270
+				$data['type'] = 'Ground';
1271
+			} elseif ($typec == 'DEL') {
1272
+				$data['type'] = 'Delivery';
1273
+			} elseif ($typec == 'DEP') {
1274
+				$data['type'] = 'Departure';
1275
+			} elseif ($typec == 'FSS') {
1276
+				$data['type'] = 'Flight Service Station';
1277
+			} elseif ($typec == 'CTR') {
1278
+				$data['type'] = 'Control Radar or Centre';
1279
+			} else {
1280
+				$data['type'] = 'Observer';
1281
+			}
1282
+			if (isset($ATC)) {
1283
+				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']);
1284
+			}
927 1285
 		    }
928 1286
 		    unset($data);
929 1287
 		}
@@ -933,7 +1291,9 @@  discard block
 block discarded – undo
933 1291
     	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
934 1292
     	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
935 1293
 	    //$buffer = $Common->getData($hosts[$id]);
936
-	    if ($globalDebug) echo 'Get Data...'."\n";
1294
+	    if ($globalDebug) {
1295
+	    	echo 'Get Data...'."\n";
1296
+	    }
937 1297
 	    $buffer = $Common->getData($value['host']);
938 1298
 	    $all_data = json_decode($buffer,true);
939 1299
 	    if ($buffer != '' && is_array($all_data)) {
@@ -941,10 +1301,16 @@  discard block
 block discarded – undo
941 1301
 		foreach ($all_data as $line) {
942 1302
 	    	    $data = array();
943 1303
 	    	    //$data['id'] = $line['id']; // id not usable
944
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1304
+	    	    if (isset($line['pilotid'])) {
1305
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1306
+	    	    }
945 1307
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
946
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
947
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1308
+	    	    if (isset($line['pilotname'])) {
1309
+	    	    	$data['pilot_name'] = $line['pilotname'];
1310
+	    	    }
1311
+	    	    if (isset($line['pilotid'])) {
1312
+	    	    	$data['pilot_id'] = $line['pilotid'];
1313
+	    	    }
948 1314
 	    	    $data['ident'] = $line['flightnum']; // ident
949 1315
 	    	    $data['altitude'] = $line['alt']; // altitude
950 1316
 	    	    $data['speed'] = $line['gs']; // speed
@@ -962,28 +1328,44 @@  discard block
 block discarded – undo
962 1328
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
963 1329
     		    $data['arrival_airport_time'] = $line['arrtime'];
964 1330
     		    $data['registration'] = $line['aircraft'];
965
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
966
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1331
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1332
+		    	$data['noarchive'] = true;
1333
+		    }
1334
+		    if (isset($line['route'])) {
1335
+		    	$data['waypoints'] = $line['route'];
1336
+		    }
1337
+		    // route
967 1338
 		    if (isset($line['aircraftname'])) {
968 1339
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
969 1340
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
970 1341
 	    		$aircraft_data = explode('-',$line['aircraftname']);
971
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
972
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
973
-	    		else {
1342
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) {
1343
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1344
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) {
1345
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1346
+	    		} else {
974 1347
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
975
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
976
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1348
+	    		    if (isset($aircraft_data[1])) {
1349
+	    		    	$data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1350
+	    		    } else {
1351
+	    		    	$data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1352
+	    		    }
977 1353
 	    		}
978 1354
 	    	    }
979
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1355
+    		    if (isset($line['route'])) {
1356
+    		    	$data['waypoints'] = $line['route'];
1357
+    		    }
980 1358
     		    $data['id_source'] = $id_source;
981 1359
 	    	    $data['format_source'] = 'phpvmacars';
982
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1360
+		    if (isset($value['name']) && $value['name'] != '') {
1361
+		    	$data['source_name'] = $value['name'];
1362
+		    }
983 1363
 		    $SI->add($data);
984 1364
 		    unset($data);
985 1365
 		}
986
-		if ($globalDebug) echo 'No more data...'."\n";
1366
+		if ($globalDebug) {
1367
+			echo 'No more data...'."\n";
1368
+		}
987 1369
 		unset($buffer);
988 1370
 		unset($all_data);
989 1371
 	    }
@@ -991,7 +1373,9 @@  discard block
 block discarded – undo
991 1373
     	    $last_exec[$id]['last'] = time();
992 1374
     	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
993 1375
 	    //$buffer = $Common->getData($hosts[$id]);
994
-	    if ($globalDebug) echo 'Get Data...'."\n";
1376
+	    if ($globalDebug) {
1377
+	    	echo 'Get Data...'."\n";
1378
+	    }
995 1379
 	    $buffer = $Common->getData($value['host']);
996 1380
 	    $all_data = json_decode($buffer,true);
997 1381
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1020,16 +1404,25 @@  discard block
 block discarded – undo
1020 1404
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
1021 1405
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
1022 1406
     		    //$data['registration'] = $line['aircraft'];
1023
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1407
+		    if (isset($line['route'])) {
1408
+		    	$data['waypoints'] = $line['route'];
1409
+		    }
1410
+		    // route
1024 1411
 	    	    $data['aircraft_icao'] = $line['plane_type'];
1025 1412
     		    $data['id_source'] = $id_source;
1026 1413
 	    	    $data['format_source'] = 'vam';
1027
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1028
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1414
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1415
+		    	$data['noarchive'] = true;
1416
+		    }
1417
+		    if (isset($value['name']) && $value['name'] != '') {
1418
+		    	$data['source_name'] = $value['name'];
1419
+		    }
1029 1420
 		    $SI->add($data);
1030 1421
 		    unset($data);
1031 1422
 		}
1032
-		if ($globalDebug) echo 'No more data...'."\n";
1423
+		if ($globalDebug) {
1424
+			echo 'No more data...'."\n";
1425
+		}
1033 1426
 		unset($buffer);
1034 1427
 		unset($all_data);
1035 1428
 	    }
@@ -1037,7 +1430,9 @@  discard block
 block discarded – undo
1037 1430
     	    $last_exec[$id]['last'] = time();
1038 1431
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1039 1432
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais' || $value['format'] == 'vrstcp') {
1040
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1433
+	    if (function_exists('pcntl_fork')) {
1434
+	    	pcntl_signal_dispatch();
1435
+	    }
1041 1436
     	    //$last_exec[$id]['last'] = time();
1042 1437
 
1043 1438
 	    //$read = array( $sockets[$id] );
@@ -1045,7 +1440,9 @@  discard block
 block discarded – undo
1045 1440
 	    $write = NULL;
1046 1441
 	    $e = NULL;
1047 1442
 	    $n = socket_select($read, $write, $e, $timeout);
1048
-	    if ($e != NULL) var_dump($e);
1443
+	    if ($e != NULL) {
1444
+	    	var_dump($e);
1445
+	    }
1049 1446
 	    if ($n > 0) {
1050 1447
 		$reset = 0;
1051 1448
 		foreach ($read as $nb => $r) {
@@ -1066,12 +1463,16 @@  discard block
 block discarded – undo
1066 1463
 		    //$SI::del();
1067 1464
 		    if ($format == 'vrstcp') {
1068 1465
 			$buffer = explode('},{',$buffer);
1069
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1466
+		    } else {
1467
+		    	$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1468
+		    }
1070 1469
 		    // SBS format is CSV format
1071 1470
 		    if ($buffer !== FALSE && $buffer != '') {
1072 1471
 			$tt[$format] = 0;
1073 1472
 			if ($format == 'acarssbs3') {
1074
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1473
+			    if ($globalDebug) {
1474
+			    	echo 'ACARS : '.$buffer."\n";
1475
+			    }
1075 1476
 			    $ACARS->add(trim($buffer));
1076 1477
 			    $ACARS->deleteLiveAcarsData();
1077 1478
 			} elseif ($format == 'raw') {
@@ -1080,28 +1481,64 @@  discard block
 block discarded – undo
1080 1481
 			    if (is_array($data)) {
1081 1482
 				$data['datetime'] = date('Y-m-d H:i:s');
1082 1483
 				$data['format_source'] = 'raw';
1083
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1084
-				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1085
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1086
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1484
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1485
+					$data['source_name'] = $globalSources[$nb]['name'];
1486
+				}
1487
+				if (isset($globalSources[$nb]['sourcestats'])) {
1488
+					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1489
+				}
1490
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1491
+					$data['noarchive'] = true;
1492
+				}
1493
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1494
+					$SI->add($data);
1495
+				}
1087 1496
 			    }
1088 1497
 			} elseif ($format == 'ais') {
1089 1498
 			    $ais_data = $AIS->parse_line(trim($buffer));
1090 1499
 			    $data = array();
1091
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1092
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1093
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1094
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1095
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1096
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1097
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1098
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1099
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1100
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1101
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1102
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1103
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1104
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1500
+			    if (isset($ais_data['ident'])) {
1501
+			    	$data['ident'] = $ais_data['ident'];
1502
+			    }
1503
+			    if (isset($ais_data['mmsi'])) {
1504
+			    	$data['mmsi'] = $ais_data['mmsi'];
1505
+			    }
1506
+			    if (isset($ais_data['speed'])) {
1507
+			    	$data['speed'] = $ais_data['speed'];
1508
+			    }
1509
+			    if (isset($ais_data['heading'])) {
1510
+			    	$data['heading'] = $ais_data['heading'];
1511
+			    }
1512
+			    if (isset($ais_data['latitude'])) {
1513
+			    	$data['latitude'] = $ais_data['latitude'];
1514
+			    }
1515
+			    if (isset($ais_data['longitude'])) {
1516
+			    	$data['longitude'] = $ais_data['longitude'];
1517
+			    }
1518
+			    if (isset($ais_data['status'])) {
1519
+			    	$data['status'] = $ais_data['status'];
1520
+			    }
1521
+			    if (isset($ais_data['statusid'])) {
1522
+			    	$data['status_id'] = $ais_data['statusid'];
1523
+			    }
1524
+			    if (isset($ais_data['type'])) {
1525
+			    	$data['type'] = $ais_data['type'];
1526
+			    }
1527
+			    if (isset($ais_data['imo'])) {
1528
+			    	$data['imo'] = $ais_data['imo'];
1529
+			    }
1530
+			    if (isset($ais_data['callsign'])) {
1531
+			    	$data['callsign'] = $ais_data['callsign'];
1532
+			    }
1533
+			    if (isset($ais_data['destination'])) {
1534
+			    	$data['arrival_code'] = $ais_data['destination'];
1535
+			    }
1536
+			    if (isset($ais_data['eta_ts'])) {
1537
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1538
+			    }
1539
+			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1540
+			    	$data['noarchive'] = true;
1541
+			    }
1105 1542
 
1106 1543
 			    if (isset($ais_data['timestamp'])) {
1107 1544
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1110,7 +1547,9 @@  discard block
 block discarded – undo
1110 1547
 			    }
1111 1548
 			    $data['format_source'] = 'aisnmea';
1112 1549
     			    $data['id_source'] = $id_source;
1113
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1550
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
1551
+			    	$MI->add($data);
1552
+			    }
1114 1553
 			    unset($data);
1115 1554
                         } elseif ($format == 'flightgearsp') {
1116 1555
                     	    //echo $buffer."\n";
@@ -1128,12 +1567,18 @@  discard block
 block discarded – undo
1128 1567
 				$data['speed'] = round($line[5]*1.94384);
1129 1568
 				$data['datetime'] = date('Y-m-d H:i:s');
1130 1569
 				$data['format_source'] = 'flightgearsp';
1131
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1132
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1570
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1571
+					$data['noarchive'] = true;
1572
+				}
1573
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1574
+					$SI->add($data);
1575
+				}
1133 1576
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1134 1577
 			    }
1135 1578
                         } elseif ($format == 'acars') {
1136
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1579
+                    	    if ($globalDebug) {
1580
+                    	    	echo 'ACARS : '.$buffer."\n";
1581
+                    	    }
1137 1582
 			    $ACARS->add(trim($buffer));
1138 1583
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1139 1584
 			    $ACARS->deleteLiveAcarsData();
@@ -1154,8 +1599,12 @@  discard block
 block discarded – undo
1154 1599
 				    $aircraft_type = $line[10];
1155 1600
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1156 1601
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1157
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1158
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1602
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1603
+				    	$data['noarchive'] = true;
1604
+				    }
1605
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1606
+				    	$SI->add($data);
1607
+				    }
1159 1608
 				}
1160 1609
 			    }
1161 1610
 			} elseif ($format == 'beast') {
@@ -1165,28 +1614,62 @@  discard block
 block discarded – undo
1165 1614
 			    foreach($buffer as $all_data) {
1166 1615
 				$line = json_decode('{'.$all_data.'}',true);
1167 1616
 				$data = array();
1168
-				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1169
-				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1170
-				if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1171
-				if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1172
-				if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1173
-				if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1174
-				if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1617
+				if (isset($line['Icao'])) {
1618
+					$data['hex'] = $line['Icao'];
1619
+				}
1620
+				// hex
1621
+				if (isset($line['Call'])) {
1622
+					$data['ident'] = $line['Call'];
1623
+				}
1624
+				// ident
1625
+				if (isset($line['Alt'])) {
1626
+					$data['altitude'] = $line['Alt'];
1627
+				}
1628
+				// altitude
1629
+				if (isset($line['Spd'])) {
1630
+					$data['speed'] = $line['Spd'];
1631
+				}
1632
+				// speed
1633
+				if (isset($line['Trak'])) {
1634
+					$data['heading'] = $line['Trak'];
1635
+				}
1636
+				// heading
1637
+				if (isset($line['Lat'])) {
1638
+					$data['latitude'] = $line['Lat'];
1639
+				}
1640
+				// lat
1641
+				if (isset($line['Long'])) {
1642
+					$data['longitude'] = $line['Long'];
1643
+				}
1644
+				// long
1175 1645
 				//$data['verticalrate'] = $line['']; // verticale rate
1176
-				if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1646
+				if (isset($line['Sqk'])) {
1647
+					$data['squawk'] = $line['Sqk'];
1648
+				}
1649
+				// squawk
1177 1650
 				$data['emergency'] = ''; // emergency
1178
-				if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
1651
+				if (isset($line['Reg'])) {
1652
+					$data['registration'] = $line['Reg'];
1653
+				}
1179 1654
 				/*
1180 1655
 				if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
1181 1656
 				else $data['datetime'] = date('Y-m-d H:i:s');
1182 1657
 				*/
1183 1658
 				$data['datetime'] = date('Y-m-d H:i:s');
1184
-				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1659
+				if (isset($line['Type'])) {
1660
+					$data['aircraft_icao'] = $line['Type'];
1661
+				}
1185 1662
 		    		$data['format_source'] = 'vrstcp';
1186 1663
 				$data['id_source'] = $id_source;
1187
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1188
-				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1189
-				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1664
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1665
+					$data['noarchive'] = true;
1666
+				}
1667
+				if (isset($value['name']) && $value['name'] != '') {
1668
+					$data['source_name'] = $value['name'];
1669
+				}
1670
+				if (isset($data['latitude']) && isset($data['hex'])) {
1671
+					$SI->add($data);
1672
+				}
1190 1673
 				unset($data);
1191 1674
 			    }
1192 1675
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
@@ -1199,22 +1682,46 @@  discard block
 block discarded – undo
1199 1682
     				$data['hex'] = $lined['hexid'];
1200 1683
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1201 1684
     				$data['datetime'] = date('Y-m-d H:i:s');;
1202
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1203
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1204
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1205
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1206
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1207
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1208
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1685
+    				if (isset($lined['ident'])) {
1686
+    					$data['ident'] = $lined['ident'];
1687
+    				}
1688
+    				if (isset($lined['lat'])) {
1689
+    					$data['latitude'] = $lined['lat'];
1690
+    				}
1691
+    				if (isset($lined['lon'])) {
1692
+    					$data['longitude'] = $lined['lon'];
1693
+    				}
1694
+    				if (isset($lined['speed'])) {
1695
+    					$data['speed'] = $lined['speed'];
1696
+    				}
1697
+    				if (isset($lined['squawk'])) {
1698
+    					$data['squawk'] = $lined['squawk'];
1699
+    				}
1700
+    				if (isset($lined['alt'])) {
1701
+    					$data['altitude'] = $lined['alt'];
1702
+    				}
1703
+    				if (isset($lined['heading'])) {
1704
+    					$data['heading'] = $lined['heading'];
1705
+    				}
1209 1706
     				$data['id_source'] = $id_source;
1210 1707
     				$data['format_source'] = 'tsv';
1211
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1212
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1213
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1214
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1708
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1709
+    					$data['source_name'] = $globalSources[$nb]['name'];
1710
+    				}
1711
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1712
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1713
+    				}
1714
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1715
+					$data['noarchive'] = true;
1716
+				}
1717
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1718
+    					$SI->add($data);
1719
+    				}
1215 1720
     				unset($lined);
1216 1721
     				unset($data);
1217
-    			    } else $error = true;
1722
+    			    } else {
1723
+    			    	$error = true;
1724
+    			    }
1218 1725
 			} elseif ($format == 'aprs' && $use_aprs) {
1219 1726
 			    if ($aprs_connect == 0) {
1220 1727
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1239,34 +1746,72 @@  discard block
 block discarded – undo
1239 1746
 				    $aprs_last_tx = time();
1240 1747
 				    $data = array();
1241 1748
 				    //print_r($line);
1242
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1243
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1244
-				    if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1245
-				    if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1246
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1247
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1749
+				    if (isset($line['address'])) {
1750
+				    	$data['hex'] = $line['address'];
1751
+				    }
1752
+				    if (isset($line['mmsi'])) {
1753
+				    	$data['mmsi'] = $line['mmsi'];
1754
+				    }
1755
+				    if (isset($line['type_id'])) {
1756
+				    	$data['type_id'] = $line['typeid'];
1757
+				    }
1758
+				    if (isset($line['status_id'])) {
1759
+				    	$data['status_id'] = $line['statusid'];
1760
+				    }
1761
+				    if (isset($line['timestamp'])) {
1762
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1763
+				    } else {
1764
+				    	$data['datetime'] = date('Y-m-d H:i:s');
1765
+				    }
1248 1766
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1249
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1767
+				    if (isset($line['ident'])) {
1768
+				    	$data['ident'] = $line['ident'];
1769
+				    }
1250 1770
 				    $data['latitude'] = $line['latitude'];
1251 1771
 				    $data['longitude'] = $line['longitude'];
1252 1772
 				    //$data['verticalrate'] = $line[16];
1253
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1254
-				    else $data['speed'] = 0;
1255
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1256
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1257
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1258
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1773
+				    if (isset($line['speed'])) {
1774
+				    	$data['speed'] = $line['speed'];
1775
+				    } else {
1776
+				    	$data['speed'] = 0;
1777
+				    }
1778
+				    if (isset($line['altitude'])) {
1779
+				    	$data['altitude'] = $line['altitude'];
1780
+				    }
1781
+				    if (isset($line['comment'])) {
1782
+				    	$data['comment'] = $line['comment'];
1783
+				    }
1784
+				    if (isset($line['symbol'])) {
1785
+				    	$data['type'] = $line['symbol'];
1786
+				    }
1787
+				    if (isset($line['heading'])) {
1788
+				    	$data['heading'] = $line['heading'];
1789
+				    }
1259 1790
 				    //else $data['heading'] = 0;
1260
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1261
-				    if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1262
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1791
+				    if (isset($line['stealth'])) {
1792
+				    	$data['aircraft_type'] = $line['stealth'];
1793
+				    }
1794
+				    if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) {
1795
+				    	$data['noarchive'] = true;
1796
+				    }
1797
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1798
+				    	$data['noarchive'] = true;
1799
+				    }
1263 1800
     				    $data['id_source'] = $id_source;
1264
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1265
-				    else $data['format_source'] = 'aprs';
1801
+    				    if (isset($line['format_source'])) {
1802
+    				    	$data['format_source'] = $line['format_source'];
1803
+    				    } else {
1804
+				    	$data['format_source'] = 'aprs';
1805
+				    }
1266 1806
 				    $data['source_name'] = $line['source'];
1267
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1268
-				    else $data['source_type'] = 'flarm';
1269
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1807
+				    if (isset($line['source_type'])) {
1808
+				    	$data['source_type'] = $line['source_type'];
1809
+				    } else {
1810
+				    	$data['source_type'] = 'flarm';
1811
+				    }
1812
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
1813
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1814
+    				    }
1270 1815
 				    $currentdate = date('Y-m-d H:i:s');
1271 1816
 				    $aprsdate = strtotime($data['datetime']);
1272 1817
 				    // Accept data if time <= system time + 20s
@@ -1277,19 +1822,22 @@  discard block
 block discarded – undo
1277 1822
 					echo 'add...'."\n";
1278 1823
 					$send = $MI->add($data);
1279 1824
 				    } elseif (isset($line['stealth'])) {
1280
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1281
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1825
+					if ($line['stealth'] != 0) {
1826
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1827
+					} else {
1828
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1829
+					}
1282 1830
 				    //} 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')) {
1283 1831
 				    } 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') {
1284 1832
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1285
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1833
+					if (isset($globalTracker) && $globalTracker) {
1834
+						$send = $TI->add($data);
1835
+					}
1286 1836
 				    }
1287 1837
 				    unset($data);
1288
-				} 
1289
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1838
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1290 1839
 					echo '!! Weather Station not yet supported'."\n";
1291
-				}
1292
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle')) {
1840
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle')) {
1293 1841
 					echo '!! Car & Trucks not yet supported'."\n";
1294 1842
 				}
1295 1843
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
@@ -1322,26 +1870,45 @@  discard block
 block discarded – undo
1322 1870
     				$data['ground'] = $line[21];
1323 1871
     				$data['emergency'] = $line[19];
1324 1872
     				$data['format_source'] = 'sbs';
1325
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1326
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1327
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1873
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1874
+					$data['source_name'] = $globalSources[$nb]['name'];
1875
+				}
1876
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1877
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1878
+    				}
1879
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1880
+					$data['noarchive'] = true;
1881
+				}
1328 1882
     				$data['id_source'] = $id_source;
1329
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1330
-    				else $error = true;
1883
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1884
+    					$send = $SI->add($data);
1885
+    				} else {
1886
+    					$error = true;
1887
+    				}
1331 1888
     				unset($data);
1332
-    			    } else $error = true;
1889
+    			    } else {
1890
+    			    	$error = true;
1891
+    			    }
1333 1892
 			    if ($error) {
1334 1893
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1335
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
1894
+					if ($globalDebug) {
1895
+						echo "Not a message. Ignoring... \n";
1896
+					}
1336 1897
 				} else {
1337
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
1898
+					if ($globalDebug) {
1899
+						echo "Wrong line format. Ignoring... \n";
1900
+					}
1338 1901
 					if ($globalDebug) {
1339 1902
 						echo $buffer;
1340 1903
 						//print_r($line);
1341 1904
 					}
1342 1905
 					//socket_close($r);
1343
-					if ($globalDebug) echo "Reconnect after an error...\n";
1344
-					if ($format == 'aprs') $aprs_connect = 0;
1906
+					if ($globalDebug) {
1907
+						echo "Reconnect after an error...\n";
1908
+					}
1909
+					if ($format == 'aprs') {
1910
+						$aprs_connect = 0;
1911
+					}
1345 1912
 					$sourceer[$nb] = $globalSources[$nb];
1346 1913
 					connect_all($sourceer);
1347 1914
 					$sourceer = array();
@@ -1349,10 +1916,14 @@  discard block
 block discarded – undo
1349 1916
 			    }
1350 1917
 			}
1351 1918
 			// Sleep for xxx microseconds
1352
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1919
+			if (isset($globalSBSSleep)) {
1920
+				usleep($globalSBSSleep);
1921
+			}
1353 1922
 		    } else {
1354 1923
 			if ($format == 'flightgearmp') {
1355
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1924
+			    	if ($globalDebug) {
1925
+			    		echo "Reconnect FlightGear MP...";
1926
+			    	}
1356 1927
 				//@socket_close($r);
1357 1928
 				sleep($globalMinFetch);
1358 1929
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1361,10 +1932,15 @@  discard block
 block discarded – undo
1361 1932
 				break;
1362 1933
 				
1363 1934
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1364
-			    if (isset($tt[$format])) $tt[$format]++;
1365
-			    else $tt[$format] = 0;
1935
+			    if (isset($tt[$format])) {
1936
+			    	$tt[$format]++;
1937
+			    } else {
1938
+			    	$tt[$format] = 0;
1939
+			    }
1366 1940
 			    if ($tt[$format] > 30) {
1367
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1941
+				if ($globalDebug) {
1942
+					echo "ERROR : Reconnect ".$format."...";
1943
+				}
1368 1944
 				//@socket_close($r);
1369 1945
 				sleep(2);
1370 1946
 				$aprs_connect = 0;
@@ -1381,11 +1957,17 @@  discard block
 block discarded – undo
1381 1957
 	    } else {
1382 1958
 		$error = socket_strerror(socket_last_error());
1383 1959
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1384
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1385
-			if (isset($globalDebug)) echo "Restarting...\n";
1960
+			if ($globalDebug) {
1961
+				echo "ERROR : socket_select give this error ".$error . "\n";
1962
+			}
1963
+			if (isset($globalDebug)) {
1964
+				echo "Restarting...\n";
1965
+			}
1386 1966
 			// Restart the script if possible
1387 1967
 			if (is_array($sockets)) {
1388
-			    if ($globalDebug) echo "Shutdown all sockets...";
1968
+			    if ($globalDebug) {
1969
+			    	echo "Shutdown all sockets...";
1970
+			    }
1389 1971
 			    
1390 1972
 			    foreach ($sockets as $sock) {
1391 1973
 				@socket_shutdown($sock,2);
@@ -1393,22 +1975,36 @@  discard block
 block discarded – undo
1393 1975
 			    }
1394 1976
 			    
1395 1977
 			}
1396
-			if ($globalDebug) echo "Waiting...";
1978
+			if ($globalDebug) {
1979
+				echo "Waiting...";
1980
+			}
1397 1981
 			sleep(2);
1398 1982
 			$time = time();
1399 1983
 			//connect_all($hosts);
1400 1984
 			$aprs_connect = 0;
1401
-			if ($reset%5 == 0) sleep(20);
1402
-			if ($reset%10 == 0) sleep(100);
1403
-			if ($reset%20 == 0) sleep(200);
1404
-			if ($reset > 100) exit('Too many attempts...');
1405
-			if ($globalDebug) echo "Restart all connections...";
1985
+			if ($reset%5 == 0) {
1986
+				sleep(20);
1987
+			}
1988
+			if ($reset%10 == 0) {
1989
+				sleep(100);
1990
+			}
1991
+			if ($reset%20 == 0) {
1992
+				sleep(200);
1993
+			}
1994
+			if ($reset > 100) {
1995
+				exit('Too many attempts...');
1996
+			}
1997
+			if ($globalDebug) {
1998
+				echo "Restart all connections...";
1999
+			}
1406 2000
 			connect_all($globalSources);
1407 2001
 		}
1408 2002
 	    }
1409 2003
 	}
1410 2004
 	if ($globalDaemon === false) {
1411
-	    if ($globalDebug) echo 'Check all...'."\n";
2005
+	    if ($globalDebug) {
2006
+	    	echo 'Check all...'."\n";
2007
+	    }
1412 2008
 	    $SI->checkAll();
1413 2009
 	}
1414 2010
     }
Please login to merge, or discard this patch.
install/class.update_schema.php 1 patch
Braces   +363 added lines, -134 removed lines patch added patch discarded remove patch
@@ -258,7 +258,9 @@  discard block
 block discarded – undo
258 258
     		// Update table countries
259 259
     		if ($Connection->tableExists('airspace')) {
260 260
     		    $error .= update_db::update_countries();
261
-		    if ($error != '') return $error;
261
+		    if ($error != '') {
262
+		    	return $error;
263
+		    }
262 264
 		}
263 265
 		// Update schema_version to 7
264 266
 		$query = "UPDATE `config` SET `value` = '7' WHERE `name` = 'schema_version'";
@@ -314,7 +316,9 @@  discard block
 block discarded – undo
314 316
     		$error = '';
315 317
     		// Update table aircraft
316 318
 		$error .= create_db::import_file('../db/source_location.sql');
317
-		if ($error != '') return $error;
319
+		if ($error != '') {
320
+			return $error;
321
+		}
318 322
 		// Update schema_version to 6
319 323
 		$query = "UPDATE `config` SET `value` = '8' WHERE `name` = 'schema_version'";
320 324
         	try {
@@ -331,7 +335,9 @@  discard block
 block discarded – undo
331 335
     		$error = '';
332 336
     		// Update table aircraft
333 337
 		$error .= create_db::import_file('../db/notam.sql');
334
-		if ($error != '') return $error;
338
+		if ($error != '') {
339
+			return $error;
340
+		}
335 341
 		$query = "DELETE FROM config WHERE name = 'last_update_db';
336 342
                         INSERT INTO config (name,value) VALUES ('last_update_db',NOW());
337 343
                         DELETE FROM config WHERE name = 'last_update_notam_db';
@@ -365,7 +371,9 @@  discard block
 block discarded – undo
365 371
 		$error = '';
366 372
     		// Update table atc
367 373
 		$error .= create_db::import_file('../db/atc.sql');
368
-		if ($error != '') return $error;
374
+		if ($error != '') {
375
+			return $error;
376
+		}
369 377
 		
370 378
 		$query = "UPDATE `config` SET `value` = '10' WHERE `name` = 'schema_version'";
371 379
         	try {
@@ -389,13 +397,21 @@  discard block
 block discarded – undo
389 397
 		$error = '';
390 398
     		// Add tables
391 399
 		$error .= create_db::import_file('../db/aircraft_owner.sql');
392
-		if ($error != '') return $error;
400
+		if ($error != '') {
401
+			return $error;
402
+		}
393 403
 		$error .= create_db::import_file('../db/metar.sql');
394
-		if ($error != '') return $error;
404
+		if ($error != '') {
405
+			return $error;
406
+		}
395 407
 		$error .= create_db::import_file('../db/taf.sql');
396
-		if ($error != '') return $error;
408
+		if ($error != '') {
409
+			return $error;
410
+		}
397 411
 		$error .= create_db::import_file('../db/airport.sql');
398
-		if ($error != '') return $error;
412
+		if ($error != '') {
413
+			return $error;
414
+		}
399 415
 		
400 416
 		$query = "UPDATE `config` SET `value` = '11' WHERE `name` = 'schema_version'";
401 417
         	try {
@@ -469,19 +485,33 @@  discard block
 block discarded – undo
469 485
 		$error = '';
470 486
     		// Add tables
471 487
 		$error .= create_db::import_file('../db/stats.sql');
472
-		if ($error != '') return $error;
488
+		if ($error != '') {
489
+			return $error;
490
+		}
473 491
 		$error .= create_db::import_file('../db/stats_aircraft.sql');
474
-		if ($error != '') return $error;
492
+		if ($error != '') {
493
+			return $error;
494
+		}
475 495
 		$error .= create_db::import_file('../db/stats_airline.sql');
476
-		if ($error != '') return $error;
496
+		if ($error != '') {
497
+			return $error;
498
+		}
477 499
 		$error .= create_db::import_file('../db/stats_airport.sql');
478
-		if ($error != '') return $error;
500
+		if ($error != '') {
501
+			return $error;
502
+		}
479 503
 		$error .= create_db::import_file('../db/stats_owner.sql');
480
-		if ($error != '') return $error;
504
+		if ($error != '') {
505
+			return $error;
506
+		}
481 507
 		$error .= create_db::import_file('../db/stats_pilot.sql');
482
-		if ($error != '') return $error;
508
+		if ($error != '') {
509
+			return $error;
510
+		}
483 511
 		$error .= create_db::import_file('../db/spotter_archive_output.sql');
484
-		if ($error != '') return $error;
512
+		if ($error != '') {
513
+			return $error;
514
+		}
485 515
 		
486 516
 		$query = "UPDATE `config` SET `value` = '13' WHERE `name` = 'schema_version'";
487 517
         	try {
@@ -521,7 +551,9 @@  discard block
 block discarded – undo
521 551
     		// Add tables
522 552
     		if (!$Connection->tableExists('stats_flight')) {
523 553
 			$error .= create_db::import_file('../db/stats_flight.sql');
524
-			if ($error != '') return $error;
554
+			if ($error != '') {
555
+				return $error;
556
+			}
525 557
 		}
526 558
 		$query = "UPDATE `config` SET `value` = '15' WHERE `name` = 'schema_version'";
527 559
         	try {
@@ -545,7 +577,9 @@  discard block
 block discarded – undo
545 577
     		} catch(PDOException $e) {
546 578
 		    return "error (update stats) : ".$e->getMessage()."\n";
547 579
     		}
548
-		if ($error != '') return $error;
580
+		if ($error != '') {
581
+			return $error;
582
+		}
549 583
 		$query = "UPDATE `config` SET `value` = '16' WHERE `name` = 'schema_version'";
550 584
         	try {
551 585
             	    $sth = $Connection->db->prepare($query);
@@ -566,7 +600,9 @@  discard block
 block discarded – undo
566 600
     		if (!$Connection->tableExists('stats_callsign')) {
567 601
 			$error .= create_db::import_file('../db/stats_callsign.sql');
568 602
 		}
569
-		if ($error != '') return $error;
603
+		if ($error != '') {
604
+			return $error;
605
+		}
570 606
 		$query = "UPDATE `config` SET `value` = '17' WHERE `name` = 'schema_version'";
571 607
         	try {
572 608
             	    $sth = $Connection->db->prepare($query);
@@ -584,7 +620,9 @@  discard block
 block discarded – undo
584 620
     		if (!$Connection->tableExists('stats_country')) {
585 621
 			$error .= create_db::import_file('../db/stats_country.sql');
586 622
 		}
587
-		if ($error != '') return $error;
623
+		if ($error != '') {
624
+			return $error;
625
+		}
588 626
 		$query = "UPDATE `config` SET `value` = '18' WHERE `name` = 'schema_version'";
589 627
         	try {
590 628
             	    $sth = $Connection->db->prepare($query);
@@ -607,7 +645,9 @@  discard block
 block discarded – undo
607 645
 			    return "error (update stats) : ".$e->getMessage()."\n";
608 646
     			}
609 647
     		}
610
-		if ($error != '') return $error;
648
+		if ($error != '') {
649
+			return $error;
650
+		}
611 651
 		$query = "UPDATE `config` SET `value` = '19' WHERE `name` = 'schema_version'";
612 652
         	try {
613 653
             	    $sth = $Connection->db->prepare($query);
@@ -623,7 +663,9 @@  discard block
 block discarded – undo
623 663
 		$error = '';
624 664
     		// Update airport table
625 665
 		$error .= create_db::import_file('../db/airport.sql');
626
-		if ($error != '') return 'Import airport.sql : '.$error;
666
+		if ($error != '') {
667
+			return 'Import airport.sql : '.$error;
668
+		}
627 669
 		// Remove primary key on Spotter_Archive
628 670
 		$query = "alter table spotter_archive drop spotter_archive_id";
629 671
         	try {
@@ -699,7 +741,9 @@  discard block
 block discarded – undo
699 741
 				return "error (add source_name column) : ".$e->getMessage()."\n";
700 742
     			}
701 743
     		}
702
-		if ($error != '') return $error;
744
+		if ($error != '') {
745
+			return $error;
746
+		}
703 747
 		$query = "UPDATE `config` SET `value` = '20' WHERE `name` = 'schema_version'";
704 748
         	try {
705 749
             	    $sth = $Connection->db->prepare($query);
@@ -717,7 +761,9 @@  discard block
 block discarded – undo
717 761
     		// Update airline table
718 762
     		if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS) {
719 763
 			$error .= create_db::import_file('../db/airlines.sql');
720
-			if ($error != '') return 'Import airlines.sql : '.$error;
764
+			if ($error != '') {
765
+				return 'Import airlines.sql : '.$error;
766
+			}
721 767
 		}
722 768
 		if (!$Connection->checkColumnName('aircraft_modes','type_flight')) {
723 769
 			// Add column over_country
@@ -729,7 +775,9 @@  discard block
 block discarded – undo
729 775
 				return "error (add over_country) : ".$e->getMessage()."\n";
730 776
     			}
731 777
     		}
732
-		if ($error != '') return $error;
778
+		if ($error != '') {
779
+			return $error;
780
+		}
733 781
 		/*
734 782
     		if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS) {
735 783
 			// Force update ModeS (this will put type_flight data
@@ -759,7 +807,9 @@  discard block
 block discarded – undo
759 807
 			} catch(PDOException $e) {
760 808
 				return "error (rename type to stats_type on stats*) : ".$e->getMessage()."\n";
761 809
 			}
762
-			if ($error != '') return $error;
810
+			if ($error != '') {
811
+				return $error;
812
+			}
763 813
 		}
764 814
 		$query = "UPDATE `config` SET `value` = '22' WHERE `name` = 'schema_version'";
765 815
         	try {
@@ -782,7 +832,9 @@  discard block
 block discarded – undo
782 832
 			} else {
783 833
 				$error .= create_db::import_file('../db/pgsql/stats_source.sql');
784 834
 			}
785
-			if ($error != '') return $error;
835
+			if ($error != '') {
836
+				return $error;
837
+			}
786 838
 		}
787 839
 		$query = "UPDATE config SET value = '23' WHERE name = 'schema_version'";
788 840
         	try {
@@ -804,12 +856,16 @@  discard block
 block discarded – undo
804 856
 		if ($globalDBdriver == 'mysql') {
805 857
 			if (!$Connection->tableExists('tle')) {
806 858
 				$error .= create_db::import_file('../db/tle.sql');
807
-				if ($error != '') return $error;
859
+				if ($error != '') {
860
+					return $error;
861
+				}
808 862
 			}
809 863
 		} else {
810 864
 			if (!$Connection->tableExists('tle')) {
811 865
 				$error .= create_db::import_file('../db/pgsql/tle.sql');
812
-				if ($error != '') return $error;
866
+				if ($error != '') {
867
+					return $error;
868
+				}
813 869
 			}
814 870
 			$query = "create index flightaware_id_idx ON spotter_archive USING btree(flightaware_id)";
815 871
 			try {
@@ -849,7 +905,9 @@  discard block
 block discarded – undo
849 905
 		} else {
850 906
 			$error .= create_db::import_file('../db/pgsql/airlines.sql');
851 907
 		}
852
-		if ($error != '') return 'Import airlines.sql : '.$error;
908
+		if ($error != '') {
909
+			return 'Import airlines.sql : '.$error;
910
+		}
853 911
 		if (!$Connection->checkColumnName('airlines','forsource')) {
854 912
 			// Add forsource to airlines
855 913
 			$query = "ALTER TABLE airlines ADD forsource VARCHAR(255) NULL DEFAULT NULL";
@@ -1332,20 +1390,28 @@  discard block
 block discarded – undo
1332 1390
 		}
1333 1391
 		if ($globalDBdriver == 'mysql') {
1334 1392
 			$error .= create_db::import_file('../db/airlines.sql');
1335
-			if ($error != '') return $error;
1393
+			if ($error != '') {
1394
+				return $error;
1395
+			}
1336 1396
 		} else {
1337 1397
 			$error .= create_db::import_file('../db/pgsql/airlines.sql');
1338
-			if ($error != '') return $error;
1398
+			if ($error != '') {
1399
+				return $error;
1400
+			}
1339 1401
 		}
1340 1402
 		if ((isset($globalVATSIM) && $globalVATSIM) || (isset($globalIVAO) && $globalIVAO)) {
1341 1403
 			include_once(dirname(__FILE__).'/class.update_db.php');
1342 1404
 			if (isset($globalVATSIM) && $globalVATSIM) {
1343 1405
 				$error .= update_db::update_vatsim();
1344
-				if ($error != '') return $error;
1406
+				if ($error != '') {
1407
+					return $error;
1408
+				}
1345 1409
 			}
1346 1410
 			if (isset($globalIVAO) && $globalIVAO && file_exists('tmp/ivae_feb2013.zip')) {
1347 1411
 				$error .= update_db::update_IVAO();
1348
-				if ($error != '') return $error;
1412
+				if ($error != '') {
1413
+					return $error;
1414
+				}
1349 1415
 			}
1350 1416
 		}
1351 1417
 
@@ -1608,41 +1674,65 @@  discard block
 block discarded – undo
1608 1674
 		if ($globalDBdriver == 'mysql') {
1609 1675
 			if (!$Connection->tableExists('tracker_output')) {
1610 1676
 				$error .= create_db::import_file('../db/tracker_output.sql');
1611
-				if ($error != '') return $error;
1677
+				if ($error != '') {
1678
+					return $error;
1679
+				}
1612 1680
 			}
1613 1681
 			if (!$Connection->tableExists('tracker_live')) {
1614 1682
 				$error .= create_db::import_file('../db/tracker_live.sql');
1615
-				if ($error != '') return $error;
1683
+				if ($error != '') {
1684
+					return $error;
1685
+				}
1616 1686
 			}
1617 1687
 			if (!$Connection->tableExists('marine_output')) {
1618 1688
 				$error .= create_db::import_file('../db/marine_output.sql');
1619
-				if ($error != '') return $error;
1689
+				if ($error != '') {
1690
+					return $error;
1691
+				}
1620 1692
 			}
1621 1693
 			if (!$Connection->tableExists('marine_live')) {
1622 1694
 				$error .= create_db::import_file('../db/marine_live.sql');
1623
-				if ($error != '') return $error;
1695
+				if ($error != '') {
1696
+					return $error;
1697
+				}
1624 1698
 			}
1625 1699
 			if (!$Connection->tableExists('marine_identity')) {
1626 1700
 				$error .= create_db::import_file('../db/marine_identity.sql');
1627
-				if ($error != '') return $error;
1701
+				if ($error != '') {
1702
+					return $error;
1703
+				}
1628 1704
 			}
1629 1705
 			if (!$Connection->tableExists('marine_mid')) {
1630 1706
 				$error .= create_db::import_file('../db/marine_mid.sql');
1631
-				if ($error != '') return $error;
1707
+				if ($error != '') {
1708
+					return $error;
1709
+				}
1632 1710
 			}
1633 1711
 		} else {
1634 1712
 			$error .= create_db::import_file('../db/pgsql/tracker_output.sql');
1635
-			if ($error != '') return $error;
1713
+			if ($error != '') {
1714
+				return $error;
1715
+			}
1636 1716
 			$error .= create_db::import_file('../db/pgsql/tracker_live.sql');
1637
-			if ($error != '') return $error;
1717
+			if ($error != '') {
1718
+				return $error;
1719
+			}
1638 1720
 			$error .= create_db::import_file('../db/pgsql/marine_output.sql');
1639
-			if ($error != '') return $error;
1721
+			if ($error != '') {
1722
+				return $error;
1723
+			}
1640 1724
 			$error .= create_db::import_file('../db/pgsql/marine_live.sql');
1641
-			if ($error != '') return $error;
1725
+			if ($error != '') {
1726
+				return $error;
1727
+			}
1642 1728
 			$error .= create_db::import_file('../db/pgsql/marine_identity.sql');
1643
-			if ($error != '') return $error;
1729
+			if ($error != '') {
1730
+				return $error;
1731
+			}
1644 1732
 			$error .= create_db::import_file('../db/pgsql/marine_mid.sql');
1645
-			if ($error != '') return $error;
1733
+			if ($error != '') {
1734
+				return $error;
1735
+			}
1646 1736
 		}
1647 1737
 		$query = "UPDATE config SET value = '37' WHERE name = 'schema_version'";
1648 1738
 		try {
@@ -1661,35 +1751,55 @@  discard block
 block discarded – undo
1661 1751
 		if ($globalDBdriver == 'mysql') {
1662 1752
 			if (!$Connection->tableExists('marine_image')) {
1663 1753
 				$error .= create_db::import_file('../db/marine_image.sql');
1664
-				if ($error != '') return $error;
1754
+				if ($error != '') {
1755
+					return $error;
1756
+				}
1665 1757
 			}
1666 1758
 			if (!$Connection->tableExists('marine_archive')) {
1667 1759
 				$error .= create_db::import_file('../db/marine_archive.sql');
1668
-				if ($error != '') return $error;
1760
+				if ($error != '') {
1761
+					return $error;
1762
+				}
1669 1763
 			}
1670 1764
 			if (!$Connection->tableExists('marine_archive_output')) {
1671 1765
 				$error .= create_db::import_file('../db/marine_archive_output.sql');
1672
-				if ($error != '') return $error;
1766
+				if ($error != '') {
1767
+					return $error;
1768
+				}
1673 1769
 			}
1674 1770
 			if (!$Connection->tableExists('tracker_archive')) {
1675 1771
 				$error .= create_db::import_file('../db/tracker_archive.sql');
1676
-				if ($error != '') return $error;
1772
+				if ($error != '') {
1773
+					return $error;
1774
+				}
1677 1775
 			}
1678 1776
 			if (!$Connection->tableExists('marine_archive_output')) {
1679 1777
 				$error .= create_db::import_file('../db/tracker_archive_output.sql');
1680
-				if ($error != '') return $error;
1778
+				if ($error != '') {
1779
+					return $error;
1780
+				}
1681 1781
 			}
1682 1782
 		} else {
1683 1783
 			$error .= create_db::import_file('../db/pgsql/marine_image.sql');
1684
-			if ($error != '') return $error;
1784
+			if ($error != '') {
1785
+				return $error;
1786
+			}
1685 1787
 			$error .= create_db::import_file('../db/pgsql/marine_archive.sql');
1686
-			if ($error != '') return $error;
1788
+			if ($error != '') {
1789
+				return $error;
1790
+			}
1687 1791
 			$error .= create_db::import_file('../db/pgsql/marine_archive_output.sql');
1688
-			if ($error != '') return $error;
1792
+			if ($error != '') {
1793
+				return $error;
1794
+			}
1689 1795
 			$error .= create_db::import_file('../db/pgsql/tracker_archive.sql');
1690
-			if ($error != '') return $error;
1796
+			if ($error != '') {
1797
+				return $error;
1798
+			}
1691 1799
 			$error .= create_db::import_file('../db/pgsql/tracker_archive_output.sql');
1692
-			if ($error != '') return $error;
1800
+			if ($error != '') {
1801
+				return $error;
1802
+			}
1693 1803
 		}
1694 1804
 		if (!$Connection->indexExists('spotter_archive','flightaware_id_date_idx') && !$Connection->indexExists('spotter_archive','flightaware_id')) {
1695 1805
 			// Add index key
@@ -1880,8 +1990,11 @@  discard block
 block discarded – undo
1880 1990
     	    if ($Connection->tableExists('aircraft')) {
1881 1991
     		if (!$Connection->tableExists('config')) {
1882 1992
     		    $version = '1';
1883
-    		    if ($update) return self::update_from_1();
1884
-    		    else return $version;
1993
+    		    if ($update) {
1994
+    		    	return self::update_from_1();
1995
+    		    } else {
1996
+    		    	return $version;
1997
+    		    }
1885 1998
 		} else {
1886 1999
     		    $Connection = new Connection();
1887 2000
 		    $query = "SELECT value FROM config WHERE name = 'schema_version' LIMIT 1";
@@ -1895,158 +2008,274 @@  discard block
 block discarded – undo
1895 2008
     		    if ($update) {
1896 2009
     			if ($result['value'] == '2') {
1897 2010
     			    $error = self::update_from_2();
1898
-    			    if ($error != '') return $error;
1899
-    			    else return self::check_version(true);
2011
+    			    if ($error != '') {
2012
+    			    	return $error;
2013
+    			    } else {
2014
+    			    	return self::check_version(true);
2015
+    			    }
1900 2016
     			} elseif ($result['value'] == '3') {
1901 2017
     			    $error = self::update_from_3();
1902
-    			    if ($error != '') return $error;
1903
-    			    else return self::check_version(true);
2018
+    			    if ($error != '') {
2019
+    			    	return $error;
2020
+    			    } else {
2021
+    			    	return self::check_version(true);
2022
+    			    }
1904 2023
     			} elseif ($result['value'] == '4') {
1905 2024
     			    $error = self::update_from_4();
1906
-    			    if ($error != '') return $error;
1907
-    			    else return self::check_version(true);
2025
+    			    if ($error != '') {
2026
+    			    	return $error;
2027
+    			    } else {
2028
+    			    	return self::check_version(true);
2029
+    			    }
1908 2030
     			} elseif ($result['value'] == '5') {
1909 2031
     			    $error = self::update_from_5();
1910
-    			    if ($error != '') return $error;
1911
-    			    else return self::check_version(true);
2032
+    			    if ($error != '') {
2033
+    			    	return $error;
2034
+    			    } else {
2035
+    			    	return self::check_version(true);
2036
+    			    }
1912 2037
     			} elseif ($result['value'] == '6') {
1913 2038
     			    $error = self::update_from_6();
1914
-    			    if ($error != '') return $error;
1915
-    			    else return self::check_version(true);
2039
+    			    if ($error != '') {
2040
+    			    	return $error;
2041
+    			    } else {
2042
+    			    	return self::check_version(true);
2043
+    			    }
1916 2044
     			} elseif ($result['value'] == '7') {
1917 2045
     			    $error = self::update_from_7();
1918
-    			    if ($error != '') return $error;
1919
-    			    else return self::check_version(true);
2046
+    			    if ($error != '') {
2047
+    			    	return $error;
2048
+    			    } else {
2049
+    			    	return self::check_version(true);
2050
+    			    }
1920 2051
     			} elseif ($result['value'] == '8') {
1921 2052
     			    $error = self::update_from_8();
1922
-    			    if ($error != '') return $error;
1923
-    			    else return self::check_version(true);
2053
+    			    if ($error != '') {
2054
+    			    	return $error;
2055
+    			    } else {
2056
+    			    	return self::check_version(true);
2057
+    			    }
1924 2058
     			} elseif ($result['value'] == '9') {
1925 2059
     			    $error = self::update_from_9();
1926
-    			    if ($error != '') return $error;
1927
-    			    else return self::check_version(true);
2060
+    			    if ($error != '') {
2061
+    			    	return $error;
2062
+    			    } else {
2063
+    			    	return self::check_version(true);
2064
+    			    }
1928 2065
     			} elseif ($result['value'] == '10') {
1929 2066
     			    $error = self::update_from_10();
1930
-    			    if ($error != '') return $error;
1931
-    			    else return self::check_version(true);
2067
+    			    if ($error != '') {
2068
+    			    	return $error;
2069
+    			    } else {
2070
+    			    	return self::check_version(true);
2071
+    			    }
1932 2072
     			} elseif ($result['value'] == '11') {
1933 2073
     			    $error = self::update_from_11();
1934
-    			    if ($error != '') return $error;
1935
-    			    else return self::check_version(true);
2074
+    			    if ($error != '') {
2075
+    			    	return $error;
2076
+    			    } else {
2077
+    			    	return self::check_version(true);
2078
+    			    }
1936 2079
     			} elseif ($result['value'] == '12') {
1937 2080
     			    $error = self::update_from_12();
1938
-    			    if ($error != '') return $error;
1939
-    			    else return self::check_version(true);
2081
+    			    if ($error != '') {
2082
+    			    	return $error;
2083
+    			    } else {
2084
+    			    	return self::check_version(true);
2085
+    			    }
1940 2086
     			} elseif ($result['value'] == '13') {
1941 2087
     			    $error = self::update_from_13();
1942
-    			    if ($error != '') return $error;
1943
-    			    else return self::check_version(true);
2088
+    			    if ($error != '') {
2089
+    			    	return $error;
2090
+    			    } else {
2091
+    			    	return self::check_version(true);
2092
+    			    }
1944 2093
     			} elseif ($result['value'] == '14') {
1945 2094
     			    $error = self::update_from_14();
1946
-    			    if ($error != '') return $error;
1947
-    			    else return self::check_version(true);
2095
+    			    if ($error != '') {
2096
+    			    	return $error;
2097
+    			    } else {
2098
+    			    	return self::check_version(true);
2099
+    			    }
1948 2100
     			} elseif ($result['value'] == '15') {
1949 2101
     			    $error = self::update_from_15();
1950
-    			    if ($error != '') return $error;
1951
-    			    else return self::check_version(true);
2102
+    			    if ($error != '') {
2103
+    			    	return $error;
2104
+    			    } else {
2105
+    			    	return self::check_version(true);
2106
+    			    }
1952 2107
     			} elseif ($result['value'] == '16') {
1953 2108
     			    $error = self::update_from_16();
1954
-    			    if ($error != '') return $error;
1955
-    			    else return self::check_version(true);
2109
+    			    if ($error != '') {
2110
+    			    	return $error;
2111
+    			    } else {
2112
+    			    	return self::check_version(true);
2113
+    			    }
1956 2114
     			} elseif ($result['value'] == '17') {
1957 2115
     			    $error = self::update_from_17();
1958
-    			    if ($error != '') return $error;
1959
-    			    else return self::check_version(true);
2116
+    			    if ($error != '') {
2117
+    			    	return $error;
2118
+    			    } else {
2119
+    			    	return self::check_version(true);
2120
+    			    }
1960 2121
     			} elseif ($result['value'] == '18') {
1961 2122
     			    $error = self::update_from_18();
1962
-    			    if ($error != '') return $error;
1963
-    			    else return self::check_version(true);
2123
+    			    if ($error != '') {
2124
+    			    	return $error;
2125
+    			    } else {
2126
+    			    	return self::check_version(true);
2127
+    			    }
1964 2128
     			} elseif ($result['value'] == '19') {
1965 2129
     			    $error = self::update_from_19();
1966
-    			    if ($error != '') return $error;
1967
-    			    else return self::check_version(true);
2130
+    			    if ($error != '') {
2131
+    			    	return $error;
2132
+    			    } else {
2133
+    			    	return self::check_version(true);
2134
+    			    }
1968 2135
     			} elseif ($result['value'] == '20') {
1969 2136
     			    $error = self::update_from_20();
1970
-    			    if ($error != '') return $error;
1971
-    			    else return self::check_version(true);
2137
+    			    if ($error != '') {
2138
+    			    	return $error;
2139
+    			    } else {
2140
+    			    	return self::check_version(true);
2141
+    			    }
1972 2142
     			} elseif ($result['value'] == '21') {
1973 2143
     			    $error = self::update_from_21();
1974
-    			    if ($error != '') return $error;
1975
-    			    else return self::check_version(true);
2144
+    			    if ($error != '') {
2145
+    			    	return $error;
2146
+    			    } else {
2147
+    			    	return self::check_version(true);
2148
+    			    }
1976 2149
     			} elseif ($result['value'] == '22') {
1977 2150
     			    $error = self::update_from_22();
1978
-    			    if ($error != '') return $error;
1979
-    			    else return self::check_version(true);
2151
+    			    if ($error != '') {
2152
+    			    	return $error;
2153
+    			    } else {
2154
+    			    	return self::check_version(true);
2155
+    			    }
1980 2156
     			} elseif ($result['value'] == '23') {
1981 2157
     			    $error = self::update_from_23();
1982
-    			    if ($error != '') return $error;
1983
-    			    else return self::check_version(true);
2158
+    			    if ($error != '') {
2159
+    			    	return $error;
2160
+    			    } else {
2161
+    			    	return self::check_version(true);
2162
+    			    }
1984 2163
     			} elseif ($result['value'] == '24') {
1985 2164
     			    $error = self::update_from_24();
1986
-    			    if ($error != '') return $error;
1987
-    			    else return self::check_version(true);
2165
+    			    if ($error != '') {
2166
+    			    	return $error;
2167
+    			    } else {
2168
+    			    	return self::check_version(true);
2169
+    			    }
1988 2170
     			} elseif ($result['value'] == '25') {
1989 2171
     			    $error = self::update_from_25();
1990
-    			    if ($error != '') return $error;
1991
-    			    else return self::check_version(true);
2172
+    			    if ($error != '') {
2173
+    			    	return $error;
2174
+    			    } else {
2175
+    			    	return self::check_version(true);
2176
+    			    }
1992 2177
     			} elseif ($result['value'] == '26') {
1993 2178
     			    $error = self::update_from_26();
1994
-    			    if ($error != '') return $error;
1995
-    			    else return self::check_version(true);
2179
+    			    if ($error != '') {
2180
+    			    	return $error;
2181
+    			    } else {
2182
+    			    	return self::check_version(true);
2183
+    			    }
1996 2184
     			} elseif ($result['value'] == '27') {
1997 2185
     			    $error = self::update_from_27();
1998
-    			    if ($error != '') return $error;
1999
-    			    else return self::check_version(true);
2186
+    			    if ($error != '') {
2187
+    			    	return $error;
2188
+    			    } else {
2189
+    			    	return self::check_version(true);
2190
+    			    }
2000 2191
     			} elseif ($result['value'] == '28') {
2001 2192
     			    $error = self::update_from_28();
2002
-    			    if ($error != '') return $error;
2003
-    			    else return self::check_version(true);
2193
+    			    if ($error != '') {
2194
+    			    	return $error;
2195
+    			    } else {
2196
+    			    	return self::check_version(true);
2197
+    			    }
2004 2198
     			} elseif ($result['value'] == '29') {
2005 2199
     			    $error = self::update_from_29();
2006
-    			    if ($error != '') return $error;
2007
-    			    else return self::check_version(true);
2200
+    			    if ($error != '') {
2201
+    			    	return $error;
2202
+    			    } else {
2203
+    			    	return self::check_version(true);
2204
+    			    }
2008 2205
     			} elseif ($result['value'] == '30') {
2009 2206
     			    $error = self::update_from_30();
2010
-    			    if ($error != '') return $error;
2011
-    			    else return self::check_version(true);
2207
+    			    if ($error != '') {
2208
+    			    	return $error;
2209
+    			    } else {
2210
+    			    	return self::check_version(true);
2211
+    			    }
2012 2212
     			} elseif ($result['value'] == '31') {
2013 2213
     			    $error = self::update_from_31();
2014
-    			    if ($error != '') return $error;
2015
-    			    else return self::check_version(true);
2214
+    			    if ($error != '') {
2215
+    			    	return $error;
2216
+    			    } else {
2217
+    			    	return self::check_version(true);
2218
+    			    }
2016 2219
     			} elseif ($result['value'] == '32') {
2017 2220
     			    $error = self::update_from_32();
2018
-    			    if ($error != '') return $error;
2019
-    			    else return self::check_version(true);
2221
+    			    if ($error != '') {
2222
+    			    	return $error;
2223
+    			    } else {
2224
+    			    	return self::check_version(true);
2225
+    			    }
2020 2226
     			} elseif ($result['value'] == '33') {
2021 2227
     			    $error = self::update_from_33();
2022
-    			    if ($error != '') return $error;
2023
-    			    else return self::check_version(true);
2228
+    			    if ($error != '') {
2229
+    			    	return $error;
2230
+    			    } else {
2231
+    			    	return self::check_version(true);
2232
+    			    }
2024 2233
     			} elseif ($result['value'] == '34') {
2025 2234
     			    $error = self::update_from_34();
2026
-    			    if ($error != '') return $error;
2027
-    			    else return self::check_version(true);
2235
+    			    if ($error != '') {
2236
+    			    	return $error;
2237
+    			    } else {
2238
+    			    	return self::check_version(true);
2239
+    			    }
2028 2240
     			} elseif ($result['value'] == '35') {
2029 2241
     			    $error = self::update_from_35();
2030
-    			    if ($error != '') return $error;
2031
-    			    else return self::check_version(true);
2242
+    			    if ($error != '') {
2243
+    			    	return $error;
2244
+    			    } else {
2245
+    			    	return self::check_version(true);
2246
+    			    }
2032 2247
     			} elseif ($result['value'] == '36') {
2033 2248
     			    $error = self::update_from_36();
2034
-    			    if ($error != '') return $error;
2035
-    			    else return self::check_version(true);
2249
+    			    if ($error != '') {
2250
+    			    	return $error;
2251
+    			    } else {
2252
+    			    	return self::check_version(true);
2253
+    			    }
2036 2254
     			} elseif ($result['value'] == '37') {
2037 2255
     			    $error = self::update_from_37();
2038
-    			    if ($error != '') return $error;
2039
-    			    else return self::check_version(true);
2256
+    			    if ($error != '') {
2257
+    			    	return $error;
2258
+    			    } else {
2259
+    			    	return self::check_version(true);
2260
+    			    }
2040 2261
     			} elseif ($result['value'] == '38') {
2041 2262
     			    $error = self::update_from_38();
2042
-    			    if ($error != '') return $error;
2043
-    			    else return self::check_version(true);
2044
-    			} else return '';
2263
+    			    if ($error != '') {
2264
+    			    	return $error;
2265
+    			    } else {
2266
+    			    	return self::check_version(true);
2267
+    			    }
2268
+    			} else {
2269
+    				return '';
2270
+    			}
2271
+    		    } else {
2272
+    		    	return $result['value'];
2045 2273
     		    }
2046
-    		    else return $result['value'];
2047 2274
 		}
2048 2275
 		
2049
-	    } else return $version;
2276
+	    } else {
2277
+	    	return $version;
2278
+	    }
2050 2279
     	}
2051 2280
     	
2052 2281
 }
Please login to merge, or discard this patch.
require/class.AIS.php 1 patch
Braces   +331 added lines, -143 removed lines patch added patch discarded remove patch
@@ -35,7 +35,9 @@  discard block
 block discarded – undo
35 35
 			$temp += 1;
36 36
 			$flat = (float)($temp / (60.0 * 10000.0));
37 37
 			$flat *= -1.0;
38
-		} else $flat = (float)($temp / (60.0 * 10000.0));
38
+		} else {
39
+			$flat = (float)($temp / (60.0 * 10000.0));
40
+		}
39 41
 		return $flat; // float
40 42
 	}
41 43
 
@@ -47,7 +49,9 @@  discard block
 block discarded – undo
47 49
 			$temp += 1;
48 50
 			$flon = (float)($temp / (60.0 * 10000.0));
49 51
 			$flon *= -1.0;
50
-		} else $flon = (float)($temp / (60.0 * 10000.0));
52
+		} else {
53
+			$flon = (float)($temp / (60.0 * 10000.0));
54
+		}
51 55
 		return $flon;
52 56
 	}
53 57
 
@@ -70,10 +74,8 @@  discard block
 block discarded – undo
70 74
     */
71 75
 	private function asciidec_2_8bit($ascii) {
72 76
 		//only process in the following range: 48-87, 96-119
73
-		if ($ascii < 48) { }
74
-		else {
75
-			if($ascii>119) { }
76
-			else {
77
+		if ($ascii < 48) { } else {
78
+			if($ascii>119) { } else {
77 79
 				if ($ascii>87 && $ascii<96) ;
78 80
 				else {
79 81
 					$ascii=$ascii+40;
@@ -175,7 +177,9 @@  discard block
 block discarded – undo
175 177
 			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,57,28)));
176 178
 			$ro->lat = $this->make_latf(bindec(substr($_aisdata,85,27)));
177 179
 			$ro->heading = bindec(substr($_aisdata,124,9));
178
-			if ($ro->heading == 511) $ro->heading = '';
180
+			if ($ro->heading == 511) {
181
+				$ro->heading = '';
182
+			}
179 183
 			$ro->cls = 2; // class B
180 184
 		} else if ($ro->id == 19) {
181 185
 			$ro->cog = bindec(substr($_aisdata,112,12))/10;
@@ -185,7 +189,9 @@  discard block
 block discarded – undo
185 189
 			$ro->name = $this->binchar($_aisdata,143,120);
186 190
 			$ro->cls = 2; // class B
187 191
 			$ro->heading = bindec(substr($_aisdata,124,9));
188
-			if ($ro->heading == 511) $ro->heading = '';
192
+			if ($ro->heading == 511) {
193
+				$ro->heading = '';
194
+			}
189 195
 			$ro->typeid = bindec(substr($_aisdata,263,8));
190 196
 			$ro->type = $this->getShipType($ro->typeid);
191 197
 			//$ro->to_bow = bindec(substr($_aisdata,271,9));
@@ -216,9 +222,13 @@  discard block
 block discarded – undo
216 222
 			$ro->cls = 2; // class B
217 223
 		} else if ($ro->id == 27) {
218 224
 			$ro->cog = bindec(substr($_aisdata,85,9));
219
-			if ($ro->cog == 511) $ro->cog = 0.0;
225
+			if ($ro->cog == 511) {
226
+				$ro->cog = 0.0;
227
+			}
220 228
 			$ro->sog = bindec(substr($_aisdata,79,6));
221
-			if ($ro->sog == 63) $ro->sog = 0.0;
229
+			if ($ro->sog == 63) {
230
+				$ro->sog = 0.0;
231
+			}
222 232
 			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,44,18))*10);
223 233
 			$ro->lat = $this->make_latf(bindec(substr($_aisdata,62,17))*10);
224 234
 			$ro->cls = 1; // class A
@@ -267,88 +277,171 @@  discard block
 block discarded – undo
267 277
 	}
268 278
 	
269 279
 	public function getShipType($code) {
270
-		if ($code == 0) return 'Not available (default)';
271
-		elseif ($code >= 1 && $code <= 19) return 'Reserved for future use';
272
-		elseif ($code == 20) return 'Wing in ground (WIG), all ships of this type';
273
-		elseif ($code == 21) return 'Wing in ground (WIG), Hazardous category A';
274
-		elseif ($code == 22) return 'Wing in ground (WIG), Hazardous category B';
275
-		elseif ($code == 23) return 'Wing in ground (WIG), Hazardous category C';
276
-		elseif ($code == 24) return 'Wing in ground (WIG), Hazardous category D';
277
-		elseif ($code == 25) return 'Wing in ground (WIG), Reserved for future use';
278
-		elseif ($code == 26) return 'Wing in ground (WIG), Reserved for future use';
279
-		elseif ($code == 27) return 'Wing in ground (WIG), Reserved for future use';
280
-		elseif ($code == 28) return 'Wing in ground (WIG), Reserved for future use';
281
-		elseif ($code == 29) return 'Wing in ground (WIG), Reserved for future use';
282
-		elseif ($code == 30) return 'Fishing';
283
-		elseif ($code == 31) return 'Towing';
284
-		elseif ($code == 32) return 'Towing: length exceeds 200m or breadth exceeds 25m';
285
-		elseif ($code == 33) return 'Dredging or underwater ops';
286
-		elseif ($code == 34) return 'Diving ops';
287
-		elseif ($code == 35) return 'Military ops';
288
-		elseif ($code == 36) return 'Sailing';
289
-		elseif ($code == 37) return 'Pleasure Craft';
290
-		elseif ($code == 38) return 'Reserved';
291
-		elseif ($code == 39) return 'Reserved';
292
-		elseif ($code == 40) return 'High speed craft (HSC), all ships of this type';
293
-		elseif ($code == 41) return 'High speed craft (HSC), Hazardous category A';
294
-		elseif ($code == 42) return 'High speed craft (HSC), Hazardous category B';
295
-		elseif ($code == 43) return 'High speed craft (HSC), Hazardous category C';
296
-		elseif ($code == 44) return 'High speed craft (HSC), Hazardous category D';
297
-		elseif ($code == 45) return 'High speed craft (HSC), Reserved for future use';
298
-		elseif ($code == 46) return 'High speed craft (HSC), Reserved for future use';
299
-		elseif ($code == 47) return 'High speed craft (HSC), Reserved for future use';
300
-		elseif ($code == 48) return 'High speed craft (HSC), Reserved for future use';
301
-		elseif ($code == 49) return 'High speed craft (HSC), No additional information';
302
-		elseif ($code == 50) return 'Pilot Vessel';
303
-		elseif ($code == 51) return 'Search and Rescue vessel';
304
-		elseif ($code == 52) return 'Tug';
305
-		elseif ($code == 53) return 'Port Tender';
306
-		elseif ($code == 54) return 'Anti-pollution equipment';
307
-		elseif ($code == 55) return 'Law Enforcement';
308
-		elseif ($code == 56) return 'Spare - Local Vessel';
309
-		elseif ($code == 57) return 'Spare - Local Vessel';
310
-		elseif ($code == 58) return 'Medical Transport';
311
-		elseif ($code == 59) return 'Noncombatant ship according to RR Resolution No. 18';
312
-		elseif ($code == 60) return 'Passenger, all ships of this type';
313
-		elseif ($code == 61) return 'Passenger, Hazardous category A';
314
-		elseif ($code == 62) return 'Passenger, Hazardous category B';
315
-		elseif ($code == 63) return 'Passenger, Hazardous category C';
316
-		elseif ($code == 64) return 'Passenger, Hazardous category D';
317
-		elseif ($code == 65) return 'Passenger, Reserved for future use';
318
-		elseif ($code == 66) return 'Passenger, Reserved for future use';
319
-		elseif ($code == 67) return 'Passenger, Reserved for future use';
320
-		elseif ($code == 68) return 'Passenger, Reserved for future use';
321
-		elseif ($code == 69) return 'Passenger, No additional information';
322
-		elseif ($code == 70) return 'Cargo, all ships of this type';
323
-		elseif ($code == 71) return 'Cargo, Hazardous category A';
324
-		elseif ($code == 72) return 'Cargo, Hazardous category B';
325
-		elseif ($code == 73) return 'Cargo, Hazardous category C';
326
-		elseif ($code == 74) return 'Cargo, Hazardous category D';
327
-		elseif ($code == 75) return 'Cargo, Reserved for future use';
328
-		elseif ($code == 76) return 'Cargo, Reserved for future use';
329
-		elseif ($code == 77) return 'Cargo, Reserved for future use';
330
-		elseif ($code == 78) return 'Cargo, Reserved for future use';
331
-		elseif ($code == 79) return 'Cargo, No additional information';
332
-		elseif ($code == 80) return 'Tanker, all ships of this type';
333
-		elseif ($code == 81) return 'Tanker, Hazardous category A';
334
-		elseif ($code == 82) return 'Tanker, Hazardous category B';
335
-		elseif ($code == 83) return 'Tanker, Hazardous category C';
336
-		elseif ($code == 84) return 'Tanker, Hazardous category D';
337
-		elseif ($code == 85) return 'Tanker, Reserved for future use';
338
-		elseif ($code == 86) return 'Tanker, Reserved for future use';
339
-		elseif ($code == 87) return 'Tanker, Reserved for future use';
340
-		elseif ($code == 88) return 'Tanker, Reserved for future use';
341
-		elseif ($code == 89) return 'Tanker, No additional information';
342
-		elseif ($code == 90) return 'Other Type, all ships of this type';
343
-		elseif ($code == 91) return 'Other Type, Hazardous category A';
344
-		elseif ($code == 92) return 'Other Type, Hazardous category B';
345
-		elseif ($code == 93) return 'Other Type, Hazardous category C';
346
-		elseif ($code == 94) return 'Other Type, Hazardous category D';
347
-		elseif ($code == 95) return 'Other Type, Reserved for future use';
348
-		elseif ($code == 96) return 'Other Type, Reserved for future use';
349
-		elseif ($code == 97) return 'Other Type, Reserved for future use';
350
-		elseif ($code == 98) return 'Other Type, Reserved for future use';
351
-		elseif ($code == 99) return 'Other Type, no additional information';
280
+		if ($code == 0) {
281
+			return 'Not available (default)';
282
+		} elseif ($code >= 1 && $code <= 19) {
283
+			return 'Reserved for future use';
284
+		} elseif ($code == 20) {
285
+			return 'Wing in ground (WIG), all ships of this type';
286
+		} elseif ($code == 21) {
287
+			return 'Wing in ground (WIG), Hazardous category A';
288
+		} elseif ($code == 22) {
289
+			return 'Wing in ground (WIG), Hazardous category B';
290
+		} elseif ($code == 23) {
291
+			return 'Wing in ground (WIG), Hazardous category C';
292
+		} elseif ($code == 24) {
293
+			return 'Wing in ground (WIG), Hazardous category D';
294
+		} elseif ($code == 25) {
295
+			return 'Wing in ground (WIG), Reserved for future use';
296
+		} elseif ($code == 26) {
297
+			return 'Wing in ground (WIG), Reserved for future use';
298
+		} elseif ($code == 27) {
299
+			return 'Wing in ground (WIG), Reserved for future use';
300
+		} elseif ($code == 28) {
301
+			return 'Wing in ground (WIG), Reserved for future use';
302
+		} elseif ($code == 29) {
303
+			return 'Wing in ground (WIG), Reserved for future use';
304
+		} elseif ($code == 30) {
305
+			return 'Fishing';
306
+		} elseif ($code == 31) {
307
+			return 'Towing';
308
+		} elseif ($code == 32) {
309
+			return 'Towing: length exceeds 200m or breadth exceeds 25m';
310
+		} elseif ($code == 33) {
311
+			return 'Dredging or underwater ops';
312
+		} elseif ($code == 34) {
313
+			return 'Diving ops';
314
+		} elseif ($code == 35) {
315
+			return 'Military ops';
316
+		} elseif ($code == 36) {
317
+			return 'Sailing';
318
+		} elseif ($code == 37) {
319
+			return 'Pleasure Craft';
320
+		} elseif ($code == 38) {
321
+			return 'Reserved';
322
+		} elseif ($code == 39) {
323
+			return 'Reserved';
324
+		} elseif ($code == 40) {
325
+			return 'High speed craft (HSC), all ships of this type';
326
+		} elseif ($code == 41) {
327
+			return 'High speed craft (HSC), Hazardous category A';
328
+		} elseif ($code == 42) {
329
+			return 'High speed craft (HSC), Hazardous category B';
330
+		} elseif ($code == 43) {
331
+			return 'High speed craft (HSC), Hazardous category C';
332
+		} elseif ($code == 44) {
333
+			return 'High speed craft (HSC), Hazardous category D';
334
+		} elseif ($code == 45) {
335
+			return 'High speed craft (HSC), Reserved for future use';
336
+		} elseif ($code == 46) {
337
+			return 'High speed craft (HSC), Reserved for future use';
338
+		} elseif ($code == 47) {
339
+			return 'High speed craft (HSC), Reserved for future use';
340
+		} elseif ($code == 48) {
341
+			return 'High speed craft (HSC), Reserved for future use';
342
+		} elseif ($code == 49) {
343
+			return 'High speed craft (HSC), No additional information';
344
+		} elseif ($code == 50) {
345
+			return 'Pilot Vessel';
346
+		} elseif ($code == 51) {
347
+			return 'Search and Rescue vessel';
348
+		} elseif ($code == 52) {
349
+			return 'Tug';
350
+		} elseif ($code == 53) {
351
+			return 'Port Tender';
352
+		} elseif ($code == 54) {
353
+			return 'Anti-pollution equipment';
354
+		} elseif ($code == 55) {
355
+			return 'Law Enforcement';
356
+		} elseif ($code == 56) {
357
+			return 'Spare - Local Vessel';
358
+		} elseif ($code == 57) {
359
+			return 'Spare - Local Vessel';
360
+		} elseif ($code == 58) {
361
+			return 'Medical Transport';
362
+		} elseif ($code == 59) {
363
+			return 'Noncombatant ship according to RR Resolution No. 18';
364
+		} elseif ($code == 60) {
365
+			return 'Passenger, all ships of this type';
366
+		} elseif ($code == 61) {
367
+			return 'Passenger, Hazardous category A';
368
+		} elseif ($code == 62) {
369
+			return 'Passenger, Hazardous category B';
370
+		} elseif ($code == 63) {
371
+			return 'Passenger, Hazardous category C';
372
+		} elseif ($code == 64) {
373
+			return 'Passenger, Hazardous category D';
374
+		} elseif ($code == 65) {
375
+			return 'Passenger, Reserved for future use';
376
+		} elseif ($code == 66) {
377
+			return 'Passenger, Reserved for future use';
378
+		} elseif ($code == 67) {
379
+			return 'Passenger, Reserved for future use';
380
+		} elseif ($code == 68) {
381
+			return 'Passenger, Reserved for future use';
382
+		} elseif ($code == 69) {
383
+			return 'Passenger, No additional information';
384
+		} elseif ($code == 70) {
385
+			return 'Cargo, all ships of this type';
386
+		} elseif ($code == 71) {
387
+			return 'Cargo, Hazardous category A';
388
+		} elseif ($code == 72) {
389
+			return 'Cargo, Hazardous category B';
390
+		} elseif ($code == 73) {
391
+			return 'Cargo, Hazardous category C';
392
+		} elseif ($code == 74) {
393
+			return 'Cargo, Hazardous category D';
394
+		} elseif ($code == 75) {
395
+			return 'Cargo, Reserved for future use';
396
+		} elseif ($code == 76) {
397
+			return 'Cargo, Reserved for future use';
398
+		} elseif ($code == 77) {
399
+			return 'Cargo, Reserved for future use';
400
+		} elseif ($code == 78) {
401
+			return 'Cargo, Reserved for future use';
402
+		} elseif ($code == 79) {
403
+			return 'Cargo, No additional information';
404
+		} elseif ($code == 80) {
405
+			return 'Tanker, all ships of this type';
406
+		} elseif ($code == 81) {
407
+			return 'Tanker, Hazardous category A';
408
+		} elseif ($code == 82) {
409
+			return 'Tanker, Hazardous category B';
410
+		} elseif ($code == 83) {
411
+			return 'Tanker, Hazardous category C';
412
+		} elseif ($code == 84) {
413
+			return 'Tanker, Hazardous category D';
414
+		} elseif ($code == 85) {
415
+			return 'Tanker, Reserved for future use';
416
+		} elseif ($code == 86) {
417
+			return 'Tanker, Reserved for future use';
418
+		} elseif ($code == 87) {
419
+			return 'Tanker, Reserved for future use';
420
+		} elseif ($code == 88) {
421
+			return 'Tanker, Reserved for future use';
422
+		} elseif ($code == 89) {
423
+			return 'Tanker, No additional information';
424
+		} elseif ($code == 90) {
425
+			return 'Other Type, all ships of this type';
426
+		} elseif ($code == 91) {
427
+			return 'Other Type, Hazardous category A';
428
+		} elseif ($code == 92) {
429
+			return 'Other Type, Hazardous category B';
430
+		} elseif ($code == 93) {
431
+			return 'Other Type, Hazardous category C';
432
+		} elseif ($code == 94) {
433
+			return 'Other Type, Hazardous category D';
434
+		} elseif ($code == 95) {
435
+			return 'Other Type, Reserved for future use';
436
+		} elseif ($code == 96) {
437
+			return 'Other Type, Reserved for future use';
438
+		} elseif ($code == 97) {
439
+			return 'Other Type, Reserved for future use';
440
+		} elseif ($code == 98) {
441
+			return 'Other Type, Reserved for future use';
442
+		} elseif ($code == 99) {
443
+			return 'Other Type, no additional information';
444
+		}
352 445
 	}
353 446
 
354 447
 	public function process_ais_itu($_itu, $_len, $_filler, $aux /*, $ais_ch*/) {
@@ -386,19 +479,34 @@  discard block
 block discarded – undo
386 479
 		// assume 1st ! is valid
387 480
 		// find * ensure that it is at correct position
388 481
 		$end = strrpos ( $rawdata , '*' );
389
-		if ($end === FALSE) return -1; // check for NULLS!!!
482
+		if ($end === FALSE) {
483
+			return -1;
484
+		}
485
+		// check for NULLS!!!
390 486
 		$cs = substr( $rawdata, $end + 1 );
391
-		if ( strlen($cs) != 2 ) return -1; // correct cs length
487
+		if ( strlen($cs) != 2 ) {
488
+			return -1;
489
+		}
490
+		// correct cs length
392 491
 		$dcs = (int)hexdec( $cs );
393
-		for ( $alias=1; $alias<$end; $alias++) $chksum ^= ord( $rawdata[$alias] ); // perform XOR for NMEA checksum
492
+		for ( $alias=1; $alias<$end; $alias++) {
493
+			$chksum ^= ord( $rawdata[$alias] );
494
+		}
495
+		// perform XOR for NMEA checksum
394 496
 		if ( $chksum == $dcs ) { // NMEA checksum pass
395 497
 			$pcs = explode(',', $rawdata);
396 498
 			// !AI??? identifier
397 499
 			$num_seq = (int)$pcs[1]; // number of sequences
398 500
 			$seq = (int)$pcs[2]; // get sequence
399 501
 			// get msg sequence id
400
-			if ($pcs[3] == '') $msg_sid = -1; // non-multipart message, set to -1
401
-			else $msg_sid = (int)$pcs[3]; // multipart message
502
+			if ($pcs[3] == '') {
503
+				$msg_sid = -1;
504
+			}
505
+			// non-multipart message, set to -1
506
+			else {
507
+				$msg_sid = (int)$pcs[3];
508
+			}
509
+			// multipart message
402 510
 			$ais_ch = $pcs[4]; // get AIS channel
403 511
 			// message sequence checking
404 512
 			if ($num_seq < 1 || $num_seq > 9) {
@@ -459,10 +567,18 @@  discard block
 block discarded – undo
459 567
 				//DEBUG echo "[$start $end $tst]\n";
460 568
 				$result = $this->process_ais_raw( $tst, "" );
461 569
 				$last_pos = $end + 1;
462
-			} else break;
570
+			} else {
571
+				break;
572
+			}
573
+		}
574
+		if ($last_pos > 0) {
575
+			$cbuf = substr($cbuf, $last_pos);
576
+		}
577
+		// move...
578
+		if (strlen($cbuf) > 1024) {
579
+			$cbuf = "";
463 580
 		}
464
-		if ($last_pos > 0) $cbuf = substr($cbuf, $last_pos); // move...
465
-		if (strlen($cbuf) > 1024) $cbuf = ""; // prevent overflow simple mode...
581
+		// prevent overflow simple mode...
466 582
 		return $result;
467 583
 	}
468 584
 
@@ -482,7 +598,9 @@  discard block
 block discarded – undo
482 598
 		if ($lat<0.0) {
483 599
 			$lat = -$lat;
484 600
 			$neg=true;
485
-		} else $neg=false;
601
+		} else {
602
+			$neg=false;
603
+		}
486 604
 		$latd = 0x00000000;
487 605
 		$latd = intval ($lat * 600000.0);
488 606
 		if ($neg==true) {
@@ -498,7 +616,9 @@  discard block
 block discarded – undo
498 616
 		if ($lon<0.0) {
499 617
 			$lon = -$lon;
500 618
 			$neg=true;
501
-		} else $neg=false;
619
+		} else {
620
+			$neg=false;
621
+		}
502 622
 		$lond = 0x00000000;
503 623
 		$lond = intval ($lon * 600000.0);
504 624
 		if ($neg==true) {
@@ -511,9 +631,14 @@  discard block
 block discarded – undo
511 631
 
512 632
 	private function char2bin($name, $max_len) {
513 633
 		$len = strlen($name);
514
-		if ($len > $max_len) $name = substr($name,0,$max_len);
515
-		if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len) * 6);
516
-		else $pad = '';
634
+		if ($len > $max_len) {
635
+			$name = substr($name,0,$max_len);
636
+		}
637
+		if ($len < $max_len) {
638
+			$pad = str_repeat('0', ($max_len - $len) * 6);
639
+		} else {
640
+			$pad = '';
641
+		}
517 642
 		$rv = '';
518 643
 		$ais_chars = array(
519 644
 		    '@'=>0, 'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 'I'=>9,
@@ -526,9 +651,12 @@  discard block
 block discarded – undo
526 651
 		);
527 652
 		// "
528 653
 		$_a = str_split($name);
529
-		if ($_a) foreach ($_a as $_1) {
654
+		if ($_a) {
655
+			foreach ($_a as $_1) {
530 656
 			if (isset($ais_chars[$_1])) $dec = $ais_chars[$_1];
531
-			else $dec = 0;
657
+		} else {
658
+				$dec = 0;
659
+			}
532 660
 			$bin = str_pad(decbin( $dec ), 6, '0', STR_PAD_LEFT);
533 661
 			$rv .= $bin;
534 662
 			//echo "$_1 $dec ($bin)<br/>";
@@ -540,7 +668,9 @@  discard block
 block discarded – undo
540 668
 		$len_bit = strlen($_enc);
541 669
 		$rem6 = $len_bit % 6;
542 670
 		$pad6_len = 0;
543
-		if ($rem6) $pad6_len = 6 - $rem6;
671
+		if ($rem6) {
672
+			$pad6_len = 6 - $rem6;
673
+		}
544 674
 		//echo  $pad6_len.'<br>';
545 675
 		$_enc .= str_repeat("0", $pad6_len); // pad the text...
546 676
 		$len_enc = strlen($_enc) / 6;
@@ -549,8 +679,11 @@  discard block
 block discarded – undo
549 679
 		for ($i=0; $i<$len_enc; $i++) {
550 680
 			$offset = $i * 6;
551 681
 			$dec = bindec(substr($_enc,$offset,6));
552
-			if ($dec < 40) $dec += 48;
553
-			else $dec += 56;
682
+			if ($dec < 40) {
683
+				$dec += 48;
684
+			} else {
685
+				$dec += 56;
686
+			}
554 687
 			//echo chr($dec)." $dec<br/>";
555 688
 			$itu .= chr($dec);
556 689
 		}
@@ -563,25 +696,41 @@  discard block
 block discarded – undo
563 696
 		}
564 697
 		$hex_arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
565 698
 		$lsb = $chksum & 0x0F;
566
-		if ($lsb >=0 && $lsb <= 15 ) $lsbc = $hex_arr[$lsb];
567
-		else $lsbc = '0';
699
+		if ($lsb >=0 && $lsb <= 15 ) {
700
+			$lsbc = $hex_arr[$lsb];
701
+		} else {
702
+			$lsbc = '0';
703
+		}
568 704
 		$msb = (($chksum & 0xF0) >> 4) & 0x0F;
569
-		if ($msb >=0 && $msb <= 15 ) $msbc = $hex_arr[$msb];
570
-		else $msbc = '0';
705
+		if ($msb >=0 && $msb <= 15 ) {
706
+			$msbc = $hex_arr[$msb];
707
+		} else {
708
+			$msbc = '0';
709
+		}
571 710
 		$itu = '!'.$itu."*{$msbc}{$lsbc}\r\n";
572 711
 		return $itu;
573 712
 	}
574 713
 
575 714
 	public function parse($buffer) {
576 715
 		$data = $this->process_ais_buf($buffer);
577
-		if (!is_object($data)) return array();
578
-		if ($data->lon != 0) $result['longitude'] = $data->lon;
579
-		if ($data->lat != 0) $result['latitude'] = $data->lat;
716
+		if (!is_object($data)) {
717
+			return array();
718
+		}
719
+		if ($data->lon != 0) {
720
+			$result['longitude'] = $data->lon;
721
+		}
722
+		if ($data->lat != 0) {
723
+			$result['latitude'] = $data->lat;
724
+		}
580 725
 		$result['ident'] = trim($data->name);
581 726
 		$result['timestamp'] = $data->ts;
582 727
 		$result['mmsi'] = $data->mmsi;
583
-		if ($data->sog != -1.0) $result['speed'] = $data->sog;
584
-		if ($data->cog != 0) $result['heading'] = $data->cog;
728
+		if ($data->sog != -1.0) {
729
+			$result['speed'] = $data->sog;
730
+		}
731
+		if ($data->cog != 0) {
732
+			$result['heading'] = $data->cog;
733
+		}
585 734
 		/*
586 735
 		    $ro->cls = 0; // AIS class undefined, also indicate unparsed msg
587 736
 		    $ro->id = bindec(substr($_aisdata,0,6));
@@ -591,15 +740,25 @@  discard block
 block discarded – undo
591 740
 
592 741
 	public function mmsitype($mmsi) {
593 742
 		if (strlen($mmsi) == 9) {
594
-			if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
595
-			elseif (substr($mmsi,0,3) == '972') return 'MOB (Man Overboard) device';
596
-			elseif (substr($mmsi,0,3) == '970') return 'AIS SART (Search and Rescue Transmitter)';
597
-			elseif (substr($mmsi,0,3) == '111') return 'SAR (Search and Rescue) aircraft';
598
-			elseif (substr($mmsi,0,2) == '98') return 'Auxiliary craft associated with a parent ship';
599
-			elseif (substr($mmsi,0,2) == '99') return 'Aids to Navigation';
600
-			elseif (substr($mmsi,0,2) == '00') return 'Coastal stations';
601
-			elseif (substr($mmsi,0,1) == '0') return 'Group of ships';
602
-			else return 'Ship';
743
+			if (substr($mmsi,0,3) == '974') {
744
+				return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS';
745
+			} elseif (substr($mmsi,0,3) == '972') {
746
+				return 'MOB (Man Overboard) device';
747
+			} elseif (substr($mmsi,0,3) == '970') {
748
+				return 'AIS SART (Search and Rescue Transmitter)';
749
+			} elseif (substr($mmsi,0,3) == '111') {
750
+				return 'SAR (Search and Rescue) aircraft';
751
+			} elseif (substr($mmsi,0,2) == '98') {
752
+				return 'Auxiliary craft associated with a parent ship';
753
+			} elseif (substr($mmsi,0,2) == '99') {
754
+				return 'Aids to Navigation';
755
+			} elseif (substr($mmsi,0,2) == '00') {
756
+				return 'Coastal stations';
757
+			} elseif (substr($mmsi,0,1) == '0') {
758
+				return 'Group of ships';
759
+			} else {
760
+				return 'Ship';
761
+			}
603 762
 		}
604 763
 
605 764
 	
@@ -616,32 +775,61 @@  discard block
 block discarded – undo
616 775
 			//if ($globalDebug) echo '==== Line format not supported : '.$buffer."\n";
617 776
 			return array();
618 777
 		}
619
-		if ($data->lon != 0) $result['longitude'] = $data->lon;
620
-		if ($data->lat != 0) $result['latitude'] = $data->lat;
778
+		if ($data->lon != 0) {
779
+			$result['longitude'] = $data->lon;
780
+		}
781
+		if ($data->lat != 0) {
782
+			$result['latitude'] = $data->lat;
783
+		}
621 784
 		$result['ident'] = trim(str_replace('@','',$data->name));
622 785
 		$result['timestamp'] = $data->ts;
623 786
 		$result['mmsi'] = $data->mmsi;
624
-		if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') $result['mmsi'] = '3'.$result['mmsi'];
787
+		if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') {
788
+			$result['mmsi'] = '3'.$result['mmsi'];
789
+		}
625 790
 		$result['mmsi_type'] = $this->mmsitype($result['mmsi']);
626
-		if ($data->sog != -1.0) $result['speed'] = $data->sog;
627
-		if ($data->heading != '') $result['heading'] = $data->heading;
628
-		elseif ($data->cog != 0) $result['heading'] = $data->cog;
629
-		if ($data->status != '') $result['status'] = $data->status;
630
-		if ($data->statusid != '') $result['statusid'] = $data->statusid;
631
-		if ($data->type != '') $result['type'] = $data->type;
632
-		if ($data->typeid != '') $result['typeid'] = $data->typeid;
633
-		if ($data->imo != '') $result['imo'] = $data->imo;
634
-		if ($data->callsign != '') $result['callsign'] = trim(str_replace('@','',$data->callsign));
791
+		if ($data->sog != -1.0) {
792
+			$result['speed'] = $data->sog;
793
+		}
794
+		if ($data->heading != '') {
795
+			$result['heading'] = $data->heading;
796
+		} elseif ($data->cog != 0) {
797
+			$result['heading'] = $data->cog;
798
+		}
799
+		if ($data->status != '') {
800
+			$result['status'] = $data->status;
801
+		}
802
+		if ($data->statusid != '') {
803
+			$result['statusid'] = $data->statusid;
804
+		}
805
+		if ($data->type != '') {
806
+			$result['type'] = $data->type;
807
+		}
808
+		if ($data->typeid != '') {
809
+			$result['typeid'] = $data->typeid;
810
+		}
811
+		if ($data->imo != '') {
812
+			$result['imo'] = $data->imo;
813
+		}
814
+		if ($data->callsign != '') {
815
+			$result['callsign'] = trim(str_replace('@','',$data->callsign));
816
+		}
635 817
 		if (is_numeric($data->eta_month) && $data->eta_month != 0 && is_numeric($data->eta_day) && $data->eta_day != 0 && $data->eta_hour !== '' && $data->eta_minute !== '') {
636 818
 			$eta_ts = strtotime(date('Y').'-'.sprintf("%02d",$data->eta_month).'-'.sprintf("%02d",$data->eta_day).' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00');
637
-			if ($eta_ts != '') $result['eta_ts'] = $eta_ts;
819
+			if ($eta_ts != '') {
820
+				$result['eta_ts'] = $eta_ts;
821
+			}
638 822
 		} elseif (is_numeric($data->eta_hour) && is_numeric($data->eta_minute)) {
639 823
 			$eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00');
640
-			if ($eta_ts != '') $result['eta_ts'] = $eta_ts;
824
+			if ($eta_ts != '') {
825
+				$result['eta_ts'] = $eta_ts;
826
+			}
641 827
 		}
642 828
 		if ($data->destination != '') {
643 829
 			$dest = trim(str_replace('@','',$data->destination));
644
-			if ($dest != '') $result['destination'] = $dest;
830
+			if ($dest != '') {
831
+				$result['destination'] = $dest;
832
+			}
645 833
 		}
646 834
 		$result['all'] = (array) $data;
647 835
 		/*
Please login to merge, or discard this patch.
require/class.APRS.php 1 patch
Braces   +152 added lines, -58 removed lines patch added patch discarded remove patch
@@ -107,17 +107,23 @@  discard block
 block discarded – undo
107 107
 	
108 108
 	/* Check that end was found and body has at least one byte. */
109 109
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
110
-	    if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
110
+	    if ($globalDebug) {
111
+	    	echo '!!! APRS invalid : '.$input."\n";
112
+	    }
111 113
 	    return false;
112 114
 	}
113 115
 	
114
-	if ($debug) echo 'input : '.$input."\n";
116
+	if ($debug) {
117
+		echo 'input : '.$input."\n";
118
+	}
115 119
 	/* Save header and body. */
116 120
 	$body = substr($input,$splitpos+1,$input_len);
117 121
 	$body_len = strlen($body);
118 122
 	$header = substr($input,0,$splitpos);
119 123
 	//$header_len = strlen($header);
120
-	if ($debug) echo 'header : '.$header."\n";
124
+	if ($debug) {
125
+		echo 'header : '.$header."\n";
126
+	}
121 127
 	
122 128
 	/* Parse source, target and path. */
123 129
 	//FLRDF0A52>APRS,qAS,LSTB
@@ -131,10 +137,14 @@  discard block
 block discarded – undo
131 137
 		$result['format_source'] = 'famaprs';
132 138
 		$result['source_type'] = 'ais';
133 139
 	    } else {
134
-		if ($debug) echo 'ident : '.$ident."\n";
140
+		if ($debug) {
141
+			echo 'ident : '.$ident."\n";
142
+		}
135 143
 		$result['ident'] = $ident;
136 144
 	    }
137
-	} else return false;
145
+	} else {
146
+		return false;
147
+	}
138 148
 	$elements = explode(',',$all_elements);
139 149
 	$source = end($elements);
140 150
 	$result['source'] = $source;
@@ -143,7 +153,9 @@  discard block
 block discarded – undo
143 153
 	        //echo "ok";
144 154
 	        //if ($element == 'TCPIP*') return false;
145 155
 	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
146
-		if ($debug) echo 'element : '.$element."\n";
156
+		if ($debug) {
157
+			echo 'element : '.$element."\n";
158
+		}
147 159
 		return false;
148 160
 	    }
149 161
 	    /*
@@ -156,13 +168,17 @@  discard block
 block discarded – undo
156 168
 	}
157 169
 	
158 170
 	$type = substr($body,0,1);
159
-	if ($debug) echo 'type : '.$type."\n";
171
+	if ($debug) {
172
+		echo 'type : '.$type."\n";
173
+	}
160 174
 	if ($type == ';') {
161 175
 		if (isset($result['source_type']) && $result['source_type'] == 'modes') {
162 176
 			$result['address'] = trim(substr($body,1,9));
163 177
 		} elseif (isset($result['source_type']) && $result['source_type'] == 'ais') {
164 178
 			$result['mmsi'] = trim(substr($body,1,9));
165
-		} else $result['ident'] = trim(substr($body,1,9));
179
+		} else {
180
+			$result['ident'] = trim(substr($body,1,9));
181
+		}
166 182
 	} elseif ($type == ',') {
167 183
 		// Invalid data or test data
168 184
 		return false;
@@ -230,7 +246,9 @@  discard block
 block discarded – undo
230 246
 		//$symbol_table = $matches[4];
231 247
 		$lat = intval($lat_deg);
232 248
 		$lon = intval($lon_deg);
233
-		if ($lat > 89 || $lon > 179) return false;
249
+		if ($lat > 89 || $lon > 179) {
250
+			return false;
251
+		}
234 252
 	    
235 253
 	    /*
236 254
 	    $tmp_5b = str_replace('.','',$lat_min);
@@ -240,8 +258,12 @@  discard block
 block discarded – undo
240 258
 	    */
241 259
 		$latitude = $lat + floatval($lat_min)/60;
242 260
 		$longitude = $lon + floatval($lon_min)/60;
243
-		if ($sind == 'S') $latitude = 0-$latitude;
244
-		if ($wind == 'W') $longitude = 0-$longitude;
261
+		if ($sind == 'S') {
262
+			$latitude = 0-$latitude;
263
+		}
264
+		if ($wind == 'W') {
265
+			$longitude = 0-$longitude;
266
+		}
245 267
 		$result['latitude'] = $latitude;
246 268
 		$result['longitude'] = $longitude;
247 269
 		$body_parse = substr($body_parse,18);
@@ -275,7 +297,9 @@  discard block
 block discarded – undo
275 297
 			$body_parse = substr($body_parse,1);
276 298
 			$body_parse_len = strlen($body_parse);
277 299
 			$result['symbol_code'] = $symbol_code;
278
-			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
300
+			if (isset($this->symbols[$symbol_code])) {
301
+				$result['symbol'] = $this->symbols[$symbol_code];
302
+			}
279 303
 			if ($symbol_code != '_') {
280 304
 			}
281 305
 		    //$body_parse = substr($body_parse,1);
@@ -286,7 +310,9 @@  discard block
 block discarded – undo
286 310
 		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
287 311
 		    	    $course = substr($body_parse,0,3);
288 312
 		    	    $tmp_s = intval($course);
289
-		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
313
+		    	    if ($tmp_s >= 1 && $tmp_s <= 360) {
314
+		    	    	$result['heading'] = intval($course);
315
+		    	    }
290 316
 		    	    $speed = substr($body_parse,4,3);
291 317
 		    	    if ($speed != '...') {
292 318
 		    		//$result['speed'] = round($speed*1.852);
@@ -327,10 +353,16 @@  discard block
 block discarded – undo
327 353
 			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
328 354
 			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
329 355
 			    
330
-				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
331
-				else $result['latitude'] += $lat_off;
332
-				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
333
-				else $result['longitude'] += $lon_off;
356
+				if ($result['latitude'] < 0) {
357
+					$result['latitude'] -= $lat_off;
358
+				} else {
359
+					$result['latitude'] += $lat_off;
360
+				}
361
+				if ($result['longitude'] < 0) {
362
+					$result['longitude'] -= $lon_off;
363
+				} else {
364
+					$result['longitude'] += $lon_off;
365
+				}
334 366
 			    }
335 367
 			    
336 368
 		            $body_parse = substr($body_parse,6);
@@ -369,27 +401,48 @@  discard block
 block discarded – undo
369 401
 			$address = substr($id,2);
370 402
 			//print_r($matches);
371 403
 			$addressType = (intval(substr($id,0,2),16))&3;
372
-			if ($addressType == 0) $result['addresstype'] = "RANDOM";
373
-			elseif ($addressType == 1) $result['addresstype'] = "ICAO";
374
-			elseif ($addressType == 2) $result['addresstype'] = "FLARM";
375
-			elseif ($addressType == 3) $result['addresstype'] = "OGN";
404
+			if ($addressType == 0) {
405
+				$result['addresstype'] = "RANDOM";
406
+			} elseif ($addressType == 1) {
407
+				$result['addresstype'] = "ICAO";
408
+			} elseif ($addressType == 2) {
409
+				$result['addresstype'] = "FLARM";
410
+			} elseif ($addressType == 3) {
411
+				$result['addresstype'] = "OGN";
412
+			}
376 413
 			$aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2);
377 414
 			$result['aircrafttype_code'] = $aircraftType;
378
-			if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN";
379
-			elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER";
380
-			elseif ($aircraftType == 2) $result['aircrafttype'] = "TOW_PLANE";
381
-			elseif ($aircraftType == 3) $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
382
-			elseif ($aircraftType == 4) $result['aircrafttype'] = "PARACHUTE";
383
-			elseif ($aircraftType == 5) $result['aircrafttype'] = "DROP_PLANE";
384
-			elseif ($aircraftType == 6) $result['aircrafttype'] = "HANG_GLIDER";
385
-			elseif ($aircraftType == 7) $result['aircrafttype'] = "PARA_GLIDER";
386
-			elseif ($aircraftType == 8) $result['aircrafttype'] = "POWERED_AIRCRAFT";
387
-			elseif ($aircraftType == 9) $result['aircrafttype'] = "JET_AIRCRAFT";
388
-			elseif ($aircraftType == 10) $result['aircrafttype'] = "UFO";
389
-			elseif ($aircraftType == 11) $result['aircrafttype'] = "BALLOON";
390
-			elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP";
391
-			elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV";
392
-			elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT";
415
+			if ($aircraftType == 0) {
416
+				$result['aircrafttype'] = "UNKNOWN";
417
+			} elseif ($aircraftType == 1) {
418
+				$result['aircrafttype'] = "GLIDER";
419
+			} elseif ($aircraftType == 2) {
420
+				$result['aircrafttype'] = "TOW_PLANE";
421
+			} elseif ($aircraftType == 3) {
422
+				$result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
423
+			} elseif ($aircraftType == 4) {
424
+				$result['aircrafttype'] = "PARACHUTE";
425
+			} elseif ($aircraftType == 5) {
426
+				$result['aircrafttype'] = "DROP_PLANE";
427
+			} elseif ($aircraftType == 6) {
428
+				$result['aircrafttype'] = "HANG_GLIDER";
429
+			} elseif ($aircraftType == 7) {
430
+				$result['aircrafttype'] = "PARA_GLIDER";
431
+			} elseif ($aircraftType == 8) {
432
+				$result['aircrafttype'] = "POWERED_AIRCRAFT";
433
+			} elseif ($aircraftType == 9) {
434
+				$result['aircrafttype'] = "JET_AIRCRAFT";
435
+			} elseif ($aircraftType == 10) {
436
+				$result['aircrafttype'] = "UFO";
437
+			} elseif ($aircraftType == 11) {
438
+				$result['aircrafttype'] = "BALLOON";
439
+			} elseif ($aircraftType == 12) {
440
+				$result['aircrafttype'] = "AIRSHIP";
441
+			} elseif ($aircraftType == 13) {
442
+				$result['aircrafttype'] = "UAV";
443
+			} elseif ($aircraftType == 15) {
444
+				$result['aircrafttype'] = "STATIC_OBJECT";
445
+			}
393 446
 			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
394 447
 			$result['stealth'] = $stealth;
395 448
 			$result['address'] = $address;
@@ -429,13 +482,21 @@  discard block
 block discarded – undo
429 482
 			$result['temp'] = round(5/9*(($matches[1])-32),1);
430 483
 		    }
431 484
 		}
432
-		} else $result['comment'] = trim($body_parse);
485
+		} else {
486
+			$result['comment'] = trim($body_parse);
487
+		}
433 488
 
434 489
 	    }
435 490
 	//}
436
-	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
437
-	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
438
-	if ($debug) print_r($result);
491
+	if (isset($result['latitude'])) {
492
+		$result['latitude'] = round($result['latitude'],4);
493
+	}
494
+	if (isset($result['longitude'])) {
495
+		$result['longitude'] = round($result['longitude'],4);
496
+	}
497
+	if ($debug) {
498
+		print_r($result);
499
+	}
439 500
 	return $result;
440 501
     }
441 502
     
@@ -444,12 +505,21 @@  discard block
 block discarded – undo
444 505
 	$aprs_connect = 0;
445 506
 	$aprs_keep = 120;
446 507
 	$aprs_last_tx = time();
447
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
448
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
449
-	if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid;
450
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
451
-	if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass;
452
-	else $aprs_pass = '-1';
508
+	if (isset($globalAPRSversion)) {
509
+		$aprs_version = $globalAPRSversion;
510
+	} else {
511
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
512
+	}
513
+	if (isset($globalServerAPRSssid)) {
514
+		$aprs_ssid = $globalServerAPRSssid;
515
+	} else {
516
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
517
+	}
518
+	if (isset($globalServerAPRSpass)) {
519
+		$aprs_pass = $globalServerAPRSpass;
520
+	} else {
521
+		$aprs_pass = '-1';
522
+	}
453 523
 	
454 524
 	$aprs_filter  = '';
455 525
 	$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
@@ -481,7 +551,9 @@  discard block
 block discarded – undo
481 551
     }
482 552
     
483 553
     public function send($data) {
484
-	if ($this->connected === false) $this->connect();
554
+	if ($this->connected === false) {
555
+		$this->connect();
556
+	}
485 557
 	$send = socket_send( $this->socket  , $data , strlen($data),0);
486 558
 	if ($send === FALSE) {
487 559
 		socket_close($this->socket);
@@ -503,18 +575,26 @@  discard block
 block discarded – undo
503 575
 			//$w = '00';
504 576
 			$custom = '';
505 577
 			if ($ident != '') {
506
-				if ($custom != '') $custom .= '/';
578
+				if ($custom != '') {
579
+					$custom .= '/';
580
+				}
507 581
 				$custom .= 'CS='.$ident;
508 582
 			}
509 583
 			if ($squawk != '') {
510
-				if ($custom != '') $custom .= '/';
584
+				if ($custom != '') {
585
+					$custom .= '/';
586
+				}
511 587
 				$custom .= 'SQ='.$squawk;
512 588
 			}
513 589
 			if ($aircraft_icao != '' && $aircraft_icao != 'NA') {
514
-				if ($custom != '') $custom .= '/';
590
+				if ($custom != '') {
591
+					$custom .= '/';
592
+				}
515 593
 				$custom .= 'AI='.$aircraft_icao;
516 594
 			}
517
-			if ($custom != '') $custom = ' '.$custom;
595
+			if ($custom != '') {
596
+				$custom = ' '.$custom;
597
+			}
518 598
 			$this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.'   *'.date('His',strtotime($datetime)).'h'.$coordinate.'^'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude_real,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
519 599
 		}
520 600
 	}
@@ -532,30 +612,44 @@  discard block
 block discarded – undo
532 612
 			//$w = '00';
533 613
 			$custom = '';
534 614
 			if ($ident != '') {
535
-				if ($custom != '') $custom .= '/';
615
+				if ($custom != '') {
616
+					$custom .= '/';
617
+				}
536 618
 				$custom .= 'CS='.$ident;
537 619
 			}
538 620
 			if ($typeid != '') {
539
-				if ($custom != '') $custom .= '/';
621
+				if ($custom != '') {
622
+					$custom .= '/';
623
+				}
540 624
 				$custom .= 'TI='.$typeid;
541 625
 			}
542 626
 			if ($statusid != '') {
543
-				if ($custom != '') $custom .= '/';
627
+				if ($custom != '') {
628
+					$custom .= '/';
629
+				}
544 630
 				$custom .= 'SI='.$statusid;
545 631
 			}
546 632
 			if ($imo != '') {
547
-				if ($custom != '') $custom .= '/';
633
+				if ($custom != '') {
634
+					$custom .= '/';
635
+				}
548 636
 				$custom .= 'IMO='.$imo;
549 637
 			}
550 638
 			if ($arrival_date != '') {
551
-				if ($custom != '') $custom .= '/';
639
+				if ($custom != '') {
640
+					$custom .= '/';
641
+				}
552 642
 				$custom .= 'AD='.strtotime($arrival_date);
553 643
 			}
554 644
 			if ($arrival_code != '') {
555
-				if ($custom != '') $custom .= '/';
645
+				if ($custom != '') {
646
+					$custom .= '/';
647
+				}
556 648
 				$custom .= 'AC='.$arrival_code;
557 649
 			}
558
-			if ($custom != '') $custom = ' '.$custom;
650
+			if ($custom != '') {
651
+				$custom = ' '.$custom;
652
+			}
559 653
 			$altitude = 0;
560 654
 			$this->send('MARINE>APRS,TCPIP*:;'.$mmsi.'*'.date('His',strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n");
561 655
 		}
Please login to merge, or discard this patch.
require/class.MarineImport.php 1 patch
Braces   +161 added lines, -55 removed lines patch added patch discarded remove patch
@@ -53,7 +53,9 @@  discard block
 block discarded – undo
53 53
 
54 54
     public function checkAll() {
55 55
 	global $globalDebug;
56
-	if ($globalDebug) echo "Update last seen tracked data...\n";
56
+	if ($globalDebug) {
57
+		echo "Update last seen tracked data...\n";
58
+	}
57 59
 	foreach ($this->all_tracked as $key => $flight) {
58 60
 	    if (isset($this->all_tracked[$key]['id'])) {
59 61
 		//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
@@ -66,13 +68,17 @@  discard block
 block discarded – undo
66 68
     public function del() {
67 69
 	global $globalDebug, $globalNoDB, $globalNoImport;
68 70
 	// Delete old infos
69
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
71
+	if ($globalDebug) {
72
+		echo 'Delete old values and update latest data...'."\n";
73
+	}
70 74
 	foreach ($this->all_tracked as $key => $flight) {
71 75
     	    if (isset($flight['lastupdate'])) {
72 76
         	if ($flight['lastupdate'] < (time()-3000)) {
73 77
             	    if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
74 78
             		if (isset($this->all_tracked[$key]['id'])) {
75
-            		    if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
79
+            		    if ($globalDebug) {
80
+            		    	echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
81
+            		    }
76 82
 			    /*
77 83
 			    $MarineLive = new MarineLive();
78 84
             		    $MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']);
@@ -82,7 +88,9 @@  discard block
 block discarded – undo
82 88
             		    $Marine = new Marine($this->db);
83 89
             		    if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
84 90
 				$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
85
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
91
+				if ($globalDebug && $result != 'success') {
92
+					echo '!!! ERROR : '.$result."\n";
93
+				}
86 94
 			    }
87 95
 			    // Put in archive
88 96
 //				$Marine->db = null;
@@ -96,7 +104,9 @@  discard block
 block discarded – undo
96 104
 
97 105
     public function add($line) {
98 106
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine;
99
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
107
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
108
+		$globalCoordMinChange = '0.02';
109
+	}
100 110
 	date_default_timezone_set('UTC');
101 111
 	$dataFound = false;
102 112
 	$send = false;
@@ -121,8 +131,11 @@  discard block
 block discarded – undo
121 131
 		
122 132
 		$Common = new Common();
123 133
 		$AIS = new AIS();
124
-	        if (!isset($line['id'])) $id = trim($line['mmsi']);
125
-	        else $id = trim($line['id']);
134
+	        if (!isset($line['id'])) {
135
+	        	$id = trim($line['mmsi']);
136
+	        } else {
137
+	        	$id = trim($line['id']);
138
+	        }
126 139
 		
127 140
 		if (!isset($this->all_tracked[$id])) {
128 141
 		    $this->all_tracked[$id] = array();
@@ -130,10 +143,16 @@  discard block
 block discarded – undo
130 143
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => ''));
131 144
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
132 145
 		    if (!isset($line['id'])) {
133
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
146
+			if (!isset($globalDaemon)) {
147
+				$globalDaemon = TRUE;
148
+			}
134 149
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
135
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
136
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
150
+		     } else {
151
+		     	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
152
+		     }
153
+		    if ($globalAllTracked !== FALSE) {
154
+		    	$dataFound = true;
155
+		    }
137 156
 		}
138 157
 		
139 158
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
@@ -183,34 +202,49 @@  discard block
 block discarded – undo
183 202
 				$Marine = new Marine($this->db);
184 203
 				$fromsource = NULL;
185 204
 				$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
186
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
205
+				if ($globalDebug && $result != 'success') {
206
+					echo '!!! ERROR : '.$result."\n";
207
+				}
187 208
 				$Marine->db = null;
188
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
209
+				if ($globalDebugTimeElapsed) {
210
+					echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
211
+				}
189 212
 			    }
190 213
 			}
191 214
 		    }
192
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
215
+		    if (!isset($this->all_tracked[$id]['id'])) {
216
+		    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
217
+		    }
193 218
 		}
194 219
 
195 220
 		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60 && strtotime($line['datetime']) < time()+20*60) {
196 221
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
197 222
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
198 223
 		    } else {
199
-				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
200
-				elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
224
+				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
225
+					echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
226
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
227
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
228
+				}
201 229
 				return '';
202 230
 		    }
203 231
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) {
204
-			if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!";
232
+			if ($globalDebug) {
233
+				echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!";
234
+			}
205 235
 			return '';
206 236
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) > time()+20*60) {
207
-			if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!";
237
+			if ($globalDebug) {
238
+				echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!";
239
+			}
208 240
 			return '';
209 241
 		} elseif (!isset($line['datetime'])) {
210 242
 			date_default_timezone_set('UTC');
211 243
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
212 244
 		} else {
213
-			if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!";
245
+			if ($globalDebug) {
246
+				echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!";
247
+			}
214 248
 			return '';
215 249
 		}
216 250
 
@@ -223,14 +257,21 @@  discard block
 block discarded – undo
223 257
 		    if ($distance > 1000 && $distance < 10000) {
224 258
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
225 259
 			$speed = $speed*3.6;
226
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
227
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
260
+			if ($speed < 1000) {
261
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
262
+			}
263
+  			if ($globalDebug) {
264
+  				echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
265
+  			}
228 266
 		    }
229 267
 		}
230 268
 
231 269
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
232
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
233
-	    	    else unset($timediff);
270
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) {
271
+	    	    	$timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
272
+	    	    } else {
273
+	    	    	unset($timediff);
274
+	    	    }
234 275
 	    	    if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) {
235 276
 			if (isset($this->all_tracked[$id]['archive_latitude']) && isset($this->all_tracked[$id]['archive_longitude']) && isset($this->all_tracked[$id]['livedb_latitude']) && isset($this->all_tracked[$id]['livedb_longitude'])) {
236 277
 			    if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
@@ -238,22 +279,32 @@  discard block
 block discarded – undo
238 279
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
239 280
 				$this->all_tracked[$id]['putinarchive'] = true;
240 281
 				
241
-				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
282
+				if ($globalDebug) {
283
+					echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
284
+				}
242 285
 				$timeelapsed = microtime(true);
243 286
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
244 287
 				    $Marine = new Marine($this->db);
245 288
 				    $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
246
-				    if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
289
+				    if (!empty($all_country)) {
290
+				    	$this->all_tracked[$id]['over_country'] = $all_country['iso2'];
291
+				    }
247 292
 				    $Marine->db = null;
248
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
293
+				    if ($globalDebugTimeElapsed) {
294
+				    	echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
295
+				    }
249 296
 				}
250 297
 				$this->tmd = 0;
251
-				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
298
+				if ($globalDebug) {
299
+					echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
300
+				}
252 301
 			    }
253 302
 			}
254 303
 
255 304
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
256
-				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
305
+				if (!isset($this->all_tracked[$id]['archive_latitude'])) {
306
+					$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
307
+				}
257 308
 				if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
258 309
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
259 310
 				    $dataFound = true;
@@ -262,8 +313,12 @@  discard block
 block discarded – undo
262 313
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
263 314
 			}
264 315
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
265
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
266
-				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
316
+			    if ($line['longitude'] > 180) {
317
+			    	$line['longitude'] = $line['longitude'] - 360;
318
+			    }
319
+				if (!isset($this->all_tracked[$id]['archive_longitude'])) {
320
+					$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
321
+				}
267 322
 				if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
268 323
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
269 324
 				    $dataFound = true;
@@ -281,7 +336,9 @@  discard block
 block discarded – undo
281 336
 		    }
282 337
 		}
283 338
 		if (isset($line['last_update']) && $line['last_update'] != '') {
284
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
339
+		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) {
340
+		    	$dataFound = true;
341
+		    }
285 342
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
286 343
 		}
287 344
 		if (isset($line['format_source']) && $line['format_source'] != '') {
@@ -302,15 +359,21 @@  discard block
 block discarded – undo
302 359
 		}
303 360
 		
304 361
 		if (isset($line['heading']) && $line['heading'] != '') {
305
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
362
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) {
363
+		    	$this->all_tracked[$id]['putinarchive'] = true;
364
+		    }
306 365
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
307 366
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
308 367
 		    //$dataFound = true;
309 368
   		} elseif (!isset($this->all_tracked[$id]['heading_fromsrc']) && isset($this->all_tracked[$id]['archive_latitude']) && $this->all_tracked[$id]['archive_latitude'] != $this->all_tracked[$id]['latitude'] && isset($this->all_tracked[$id]['archive_longitude']) && $this->all_tracked[$id]['archive_longitude'] != $this->all_tracked[$id]['longitude']) {
310 369
   		    $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
311 370
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
312
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
313
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
371
+		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) {
372
+		    	$this->all_tracked[$id]['putinarchive'] = true;
373
+		    }
374
+  		    if ($globalDebug) {
375
+  		    	echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
376
+  		    }
314 377
   		}
315 378
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
316 379
 
@@ -322,23 +385,38 @@  discard block
 block discarded – undo
322 385
 		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == ''  || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
323 386
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
324 387
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
325
-				    if ($globalDebug) echo "Check if aircraft is already in DB...";
388
+				    if ($globalDebug) {
389
+				    	echo "Check if aircraft is already in DB...";
390
+				    }
326 391
 				    $timeelapsed = microtime(true);
327 392
 				    $MarineLive = new MarineLive($this->db);
328 393
 				    if (isset($line['id'])) {
329 394
 					$recent_ident = $MarineLive->checkIdRecent($line['id']);
330
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
395
+					if ($globalDebugTimeElapsed) {
396
+						echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
397
+					}
331 398
 				    } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
332 399
 					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
333
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
400
+					if ($globalDebugTimeElapsed) {
401
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
402
+					}
334 403
 				    } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
335 404
 					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
336
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
337
-				    } else $recent_ident = '';
405
+					if ($globalDebugTimeElapsed) {
406
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
407
+					}
408
+				    } else {
409
+				    	$recent_ident = '';
410
+				    }
338 411
 				    $MarineLive->db=null;
339
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
340
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
341
-				} else $recent_ident = '';
412
+				    if ($globalDebug && $recent_ident == '') {
413
+				    	echo " Not in DB.\n";
414
+				    } elseif ($globalDebug && $recent_ident != '') {
415
+				    	echo " Already in DB.\n";
416
+				    }
417
+				} else {
418
+					$recent_ident = '';
419
+				}
342 420
 			    } else {
343 421
 				$recent_ident = '';
344 422
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
@@ -346,18 +424,26 @@  discard block
 block discarded – undo
346 424
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
347 425
 			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
348 426
 			    {
349
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
427
+				if ($globalDebug) {
428
+					echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
429
+				}
350 430
 				//adds the spotter data for the archive
351 431
 				    $highlight = '';
352
-				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
432
+				    if (!isset($this->all_tracked[$id]['id'])) {
433
+				    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
434
+				    }
353 435
 				    if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
354 436
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
355 437
 					    $timeelapsed = microtime(true);
356 438
 					    $Marine = new Marine($this->db);
357 439
 					    $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
358 440
 					    $Marine->db = null;
359
-					    if ($globalDebug && isset($result)) echo $result."\n";
360
-					    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
441
+					    if ($globalDebug && isset($result)) {
442
+					    	echo $result."\n";
443
+					    }
444
+					    if ($globalDebugTimeElapsed) {
445
+					    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
446
+					    }
361 447
 					}
362 448
 				    }
363 449
 				    /*
@@ -392,13 +478,17 @@  discard block
 block discarded – undo
392 478
 				$this->all_tracked[$id]['addedMarine'] = 1;
393 479
 				//print_r($this->all_tracked[$id]);
394 480
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
395
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
481
+				    if ($globalDebug) {
482
+				    	echo "---- Deleting Live Marine data older than 9 hours...";
483
+				    }
396 484
 				    //MarineLive->deleteLiveMarineDataNotUpdated();
397 485
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
398 486
 					$MarineLive = new MarineLive($this->db);
399 487
 					$MarineLive->deleteLiveMarineData();
400 488
 					$MarineLive->db=null;
401
-					if ($globalDebug) echo " Done\n";
489
+					if ($globalDebug) {
490
+						echo " Done\n";
491
+					}
402 492
 				    }
403 493
 				    $this->last_delete = time();
404 494
 				}
@@ -424,15 +514,21 @@  discard block
 block discarded – undo
424 514
 
425 515
 		    if (!$ignoreImport) {
426 516
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
427
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
517
+				if ($globalDebug) {
518
+					echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
519
+				}
428 520
 				if (!isset($globalNoImport) || $globalNoImport !== TRUE) {
429 521
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
430 522
 					$timeelapsed = microtime(true);
431 523
 					$MarineLive = new MarineLive($this->db);
432 524
 					$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
433 525
 					$MarineLive->db = null;
434
-					if ($globalDebug) echo $result."\n";
435
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
526
+					if ($globalDebug) {
527
+						echo $result."\n";
528
+					}
529
+					if ($globalDebugTimeElapsed) {
530
+						echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
531
+					}
436 532
 				    }
437 533
 				}
438 534
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) {
@@ -495,19 +591,27 @@  discard block
 block discarded – undo
495 591
 				*/
496 592
 
497 593
 				$this->all_tracked[$id]['lastupdate'] = time();
498
-				if ($this->all_tracked[$id]['putinarchive']) $send = true;
499
-			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
594
+				if ($this->all_tracked[$id]['putinarchive']) {
595
+					$send = true;
596
+				}
597
+			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
598
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
599
+			}
500 600
 			//$this->del();
501 601
 			
502 602
 			
503 603
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
504 604
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
505
-				if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
605
+				if ($globalDebug) {
606
+					echo "---- Deleting Live Marine data Not updated since 2 hour...";
607
+				}
506 608
 				$MarineLive = new MarineLive($this->db);
507 609
 				$MarineLive->deleteLiveMarineDataNotUpdated();
508 610
 				$MarineLive->db = null;
509 611
 				//MarineLive->deleteLiveMarineData();
510
-				if ($globalDebug) echo " Done\n";
612
+				if ($globalDebug) {
613
+					echo " Done\n";
614
+				}
511 615
 			    }
512 616
 			    $this->last_delete_hourly = time();
513 617
 			}
@@ -516,7 +620,9 @@  discard block
 block discarded – undo
516 620
 		    //$ignoreImport = false;
517 621
 		}
518 622
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
519
-		if ($send) return $this->all_tracked[$id];
623
+		if ($send) {
624
+			return $this->all_tracked[$id];
625
+		}
520 626
 	    }
521 627
 	}
522 628
     }
Please login to merge, or discard this patch.
require/class.Marine.php 1 patch
Braces   +156 added lines, -56 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) {
@@ -68,8 +70,11 @@  discard block
 block discarded – undo
68 70
 				$filter_query_where .= " AND EXTRACT(DAY FROM marine_output.date) = '".$filter['day']."'";
69 71
 			}
70 72
 		}
71
-		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
72
-		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
73
+		if ($filter_query_where == '' && $where) {
74
+			$filter_query_where = ' WHERE';
75
+		} elseif ($filter_query_where != '' && $and) {
76
+			$filter_query_where .= ' AND';
77
+		}
73 78
 		if ($filter_query_where != '') {
74 79
 			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
75 80
 		}
@@ -123,32 +128,54 @@  discard block
 block discarded – undo
123 128
 				$temp_array['spotter_id'] = $row['spotter_archive_id'];
124 129
 			} elseif (isset($row['spotter_archive_output_id'])) {
125 130
 				$temp_array['spotter_id'] = $row['spotter_archive_output_id'];
126
-			*/} 
127
-			elseif (isset($row['marineid'])) {
131
+			*/} elseif (isset($row['marineid'])) {
128 132
 				$temp_array['marineid'] = $row['marineid'];
129 133
 			} else {
130 134
 				$temp_array['marineid'] = '';
131 135
 			}
132
-			if (isset($row['fammarine_id'])) $temp_array['fammarine_id'] = $row['fammarine_id'];
133
-			if (isset($row['mmsi'])) $temp_array['mmsi'] = $row['mmsi'];
134
-			if (isset($row['type'])) $temp_array['type'] = $row['type'];
135
-			if (isset($row['type_id'])) $temp_array['type_id'] = $row['type_id'];
136
-			if (isset($row['ident'])) $temp_array['ident'] = $row['ident'];
137
-			if (isset($row['latitude'])) $temp_array['latitude'] = $row['latitude'];
138
-			if (isset($row['longitude'])) $temp_array['longitude'] = $row['longitude'];
139
-			if (isset($row['format_source'])) $temp_array['format_source'] = $row['format_source'];
136
+			if (isset($row['fammarine_id'])) {
137
+				$temp_array['fammarine_id'] = $row['fammarine_id'];
138
+			}
139
+			if (isset($row['mmsi'])) {
140
+				$temp_array['mmsi'] = $row['mmsi'];
141
+			}
142
+			if (isset($row['type'])) {
143
+				$temp_array['type'] = $row['type'];
144
+			}
145
+			if (isset($row['type_id'])) {
146
+				$temp_array['type_id'] = $row['type_id'];
147
+			}
148
+			if (isset($row['ident'])) {
149
+				$temp_array['ident'] = $row['ident'];
150
+			}
151
+			if (isset($row['latitude'])) {
152
+				$temp_array['latitude'] = $row['latitude'];
153
+			}
154
+			if (isset($row['longitude'])) {
155
+				$temp_array['longitude'] = $row['longitude'];
156
+			}
157
+			if (isset($row['format_source'])) {
158
+				$temp_array['format_source'] = $row['format_source'];
159
+			}
140 160
 			if (isset($row['heading'])) {
141 161
 				$temp_array['heading'] = $row['heading'];
142 162
 				$heading_direction = $this->parseDirection($row['heading']);
143
-				if (isset($heading_direction[0]['direction_fullname'])) $temp_array['heading_name'] = $heading_direction[0]['direction_fullname'];
163
+				if (isset($heading_direction[0]['direction_fullname'])) {
164
+					$temp_array['heading_name'] = $heading_direction[0]['direction_fullname'];
165
+				}
166
+			}
167
+			if (isset($row['ground_speed'])) {
168
+				$temp_array['ground_speed'] = $row['ground_speed'];
144 169
 			}
145
-			if (isset($row['ground_speed'])) $temp_array['ground_speed'] = $row['ground_speed'];
146 170
 
147 171
 			if($temp_array['mmsi'] != "" && isset($globalMarineImageFetch) && $globalMarineImageFetch === TRUE)
148 172
 			{
149 173
 				$Image = new Image($this->db);
150
-				if (isset($temp_array['ident']) && $temp_array['ident'] != '') $image_array = $Image->getMarineImage($temp_array['mmsi'],'',$temp_array['ident']);
151
-				else $image_array = $Image->getMarineImage($temp_array['mmsi']);
174
+				if (isset($temp_array['ident']) && $temp_array['ident'] != '') {
175
+					$image_array = $Image->getMarineImage($temp_array['mmsi'],'',$temp_array['ident']);
176
+				} else {
177
+					$image_array = $Image->getMarineImage($temp_array['mmsi']);
178
+				}
152 179
 				unset($Image);
153 180
 				if (count($image_array) > 0) {
154 181
 					$temp_array['image'] = $image_array[0]['image'];
@@ -200,13 +227,21 @@  discard block
 block discarded – undo
200 227
 			}
201 228
 			
202 229
 			$fromsource = NULL;
203
-			if (isset($row['source_name']) && $row['source_name'] != '') $temp_array['source_name'] = $row['source_name'];
204
-			if (isset($row['over_country']) && $row['over_country'] != '') $temp_array['over_country'] = $row['over_country'];
205
-			if (isset($row['distance']) && $row['distance'] != '') $temp_array['distance'] = $row['distance'];
230
+			if (isset($row['source_name']) && $row['source_name'] != '') {
231
+				$temp_array['source_name'] = $row['source_name'];
232
+			}
233
+			if (isset($row['over_country']) && $row['over_country'] != '') {
234
+				$temp_array['over_country'] = $row['over_country'];
235
+			}
236
+			if (isset($row['distance']) && $row['distance'] != '') {
237
+				$temp_array['distance'] = $row['distance'];
238
+			}
206 239
 			$temp_array['query_number_rows'] = $num_rows;
207 240
 			$spotter_array[] = $temp_array;
208 241
 		}
209
-		if ($num_rows == 0) return array();
242
+		if ($num_rows == 0) {
243
+			return array();
244
+		}
210 245
 		$spotter_array[0]['query_number_rows'] = $num_rows;
211 246
 		return $spotter_array;
212 247
 	}	
@@ -237,8 +272,12 @@  discard block
 block discarded – undo
237 272
 			{
238 273
 				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
239 274
 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
240
-			} else $limit_query = "";
241
-		} else $limit_query = "";
275
+			} else {
276
+				$limit_query = "";
277
+			}
278
+		} else {
279
+			$limit_query = "";
280
+		}
242 281
 		
243 282
 		if ($sort != "")
244 283
 		{
@@ -266,7 +305,9 @@  discard block
 block discarded – undo
266 305
 		global $global_query;
267 306
 		
268 307
 		date_default_timezone_set('UTC');
269
-		if ($id == '') return array();
308
+		if ($id == '') {
309
+			return array();
310
+		}
270 311
 		$additional_query = "marine_output.fammarine_id = :id";
271 312
 		$query_values = array(':id' => $id);
272 313
 		$query  = $global_query." WHERE ".$additional_query." ";
@@ -409,8 +450,11 @@  discard block
 block discarded – undo
409 450
 		$query .= " ORDER BY marine_output.source_name ASC";
410 451
 
411 452
 		$sth = $this->db->prepare($query);
412
-		if (!empty($query_values)) $sth->execute($query_values);
413
-		else $sth->execute();
453
+		if (!empty($query_values)) {
454
+			$sth->execute($query_values);
455
+		} else {
456
+			$sth->execute();
457
+		}
414 458
 
415 459
 		$source_array = array();
416 460
 		$temp_array = array();
@@ -465,8 +509,11 @@  discard block
 block discarded – undo
465 509
 		$sth = $this->db->prepare($query);
466 510
 		$sth->execute(array(':mmsi' => $mmsi));
467 511
 		$result = $sth->fetchAll(PDO::FETCH_ASSOC);
468
-		if (isset($result[0])) return $result[0];
469
-		else return array();
512
+		if (isset($result[0])) {
513
+			return $result[0];
514
+		} else {
515
+			return array();
516
+		}
470 517
 	}
471 518
 
472 519
 	/*
@@ -482,7 +529,9 @@  discard block
 block discarded – undo
482 529
 			date_default_timezone_set($globalTimezone);
483 530
 			$datetime = new DateTime();
484 531
 			$offset = $datetime->format('P');
485
-		} else $offset = '+00:00';
532
+		} else {
533
+			$offset = '+00:00';
534
+		}
486 535
 
487 536
 		if ($globalDBdriver == 'mysql') {
488 537
 			$query  = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date
@@ -686,9 +735,15 @@  discard block
 block discarded – undo
686 735
             		$latitude = 0;
687 736
             		$longitude = 0;
688 737
             	}
689
-                if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
690
-                if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
691
-                if ($arrival_date == '') $arrival_date = NULL;
738
+                if ($heading == '' || $Common->isInteger($heading) === false) {
739
+                	$heading = 0;
740
+                }
741
+                if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) {
742
+                	$groundspeed = 0;
743
+                }
744
+                if ($arrival_date == '') {
745
+                	$arrival_date = NULL;
746
+                }
692 747
 		$query  = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo,arrival_port_name,arrival_port_date) 
693 748
 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:speed,:date,:format_source, :source_name,:mmsi,:type,:status,:imo,:arrival_port_name,:arrival_port_date)";
694 749
 
@@ -852,12 +907,18 @@  discard block
 block discarded – undo
852 907
 		$query  = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count 
853 908
                     FROM marine_output".$filter_query." marine_output.ident <> ''";
854 909
 		 if ($olderthanmonths > 0) {
855
-			if ($globalDBdriver == 'mysql') $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
856
-			else $query .= " AND marine_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'";
910
+			if ($globalDBdriver == 'mysql') {
911
+				$query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
912
+			} else {
913
+				$query .= " AND marine_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'";
914
+			}
857 915
 		}
858 916
 		if ($sincedate != '') {
859
-			if ($globalDBdriver == 'mysql') $query .= " AND marine_output.date > '".$sincedate."'";
860
-			else $query .= " AND marine_output.date > CAST('".$sincedate."' AS TIMESTAMP)";
917
+			if ($globalDBdriver == 'mysql') {
918
+				$query .= " AND marine_output.date > '".$sincedate."'";
919
+			} else {
920
+				$query .= " AND marine_output.date > CAST('".$sincedate."' AS TIMESTAMP)";
921
+			}
861 922
 		}
862 923
 		$query_values = array();
863 924
 		if ($year != '') {
@@ -888,7 +949,9 @@  discard block
 block discarded – undo
888 949
 			}
889 950
 		}
890 951
 		$query .= " GROUP BY marine_output.ident ORDER BY callsign_icao_count DESC";
891
-		if ($limit) $query .= " LIMIT 10 OFFSET 0";
952
+		if ($limit) {
953
+			$query .= " LIMIT 10 OFFSET 0";
954
+		}
892 955
       		
893 956
 		$sth = $this->db->prepare($query);
894 957
 		$sth->execute($query_values);
@@ -923,7 +986,9 @@  discard block
 block discarded – undo
923 986
 			date_default_timezone_set($globalTimezone);
924 987
 			$datetime = new DateTime();
925 988
 			$offset = $datetime->format('P');
926
-		} else $offset = '+00:00';
989
+		} else {
990
+			$offset = '+00:00';
991
+		}
927 992
 
928 993
 		if ($globalDBdriver == 'mysql') {
929 994
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
@@ -973,7 +1038,9 @@  discard block
 block discarded – undo
973 1038
 			date_default_timezone_set($globalTimezone);
974 1039
 			$datetime = new DateTime();
975 1040
 			$offset = $datetime->format('P');
976
-		} else $offset = '+00:00';
1041
+		} else {
1042
+			$offset = '+00:00';
1043
+		}
977 1044
 		$filter_query = $this->getFilter($filters,true,true);
978 1045
 		if ($globalDBdriver == 'mysql') {
979 1046
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
@@ -1019,7 +1086,9 @@  discard block
 block discarded – undo
1019 1086
 			date_default_timezone_set($globalTimezone);
1020 1087
 			$datetime = new DateTime();
1021 1088
 			$offset = $datetime->format('P');
1022
-		} else $offset = '+00:00';
1089
+		} else {
1090
+			$offset = '+00:00';
1091
+		}
1023 1092
 		$filter_query = $this->getFilter($filters,true,true);
1024 1093
 		if ($globalDBdriver == 'mysql') {
1025 1094
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
@@ -1067,7 +1136,9 @@  discard block
 block discarded – undo
1067 1136
 			date_default_timezone_set($globalTimezone);
1068 1137
 			$datetime = new DateTime();
1069 1138
 			$offset = $datetime->format('P');
1070
-		} else $offset = '+00:00';
1139
+		} else {
1140
+			$offset = '+00:00';
1141
+		}
1071 1142
 
1072 1143
 		if ($globalDBdriver == 'mysql') {
1073 1144
 			$query  = "SELECT YEAR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS month_name, count(*) as date_count
@@ -1116,7 +1187,9 @@  discard block
 block discarded – undo
1116 1187
 			date_default_timezone_set($globalTimezone);
1117 1188
 			$datetime = new DateTime();
1118 1189
 			$offset = $datetime->format('P');
1119
-		} else $offset = '+00:00';
1190
+		} else {
1191
+			$offset = '+00:00';
1192
+		}
1120 1193
 		$filter_query = $this->getFilter($filters,true,true);
1121 1194
 		if ($globalDBdriver == 'mysql') {
1122 1195
 			$query  = "SELECT MONTH(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS month_name, YEAR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS year_name, count(*) as date_count
@@ -1165,7 +1238,9 @@  discard block
 block discarded – undo
1165 1238
 			date_default_timezone_set($globalTimezone);
1166 1239
 			$datetime = new DateTime();
1167 1240
 			$offset = $datetime->format('P');
1168
-		} else $offset = '+00:00';
1241
+		} else {
1242
+			$offset = '+00:00';
1243
+		}
1169 1244
 
1170 1245
 		$orderby_sql = '';
1171 1246
 		if ($orderby == "hour")
@@ -1234,7 +1309,9 @@  discard block
 block discarded – undo
1234 1309
 			date_default_timezone_set($globalTimezone);
1235 1310
 			$datetime = new DateTime($date);
1236 1311
 			$offset = $datetime->format('P');
1237
-		} else $offset = '+00:00';
1312
+		} else {
1313
+			$offset = '+00:00';
1314
+		}
1238 1315
 
1239 1316
 		if ($globalDBdriver == 'mysql') {
1240 1317
 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
@@ -1282,7 +1359,9 @@  discard block
 block discarded – undo
1282 1359
 			date_default_timezone_set($globalTimezone);
1283 1360
 			$datetime = new DateTime();
1284 1361
 			$offset = $datetime->format('P');
1285
-		} else $offset = '+00:00';
1362
+		} else {
1363
+			$offset = '+00:00';
1364
+		}
1286 1365
 
1287 1366
 		if ($globalDBdriver == 'mysql') {
1288 1367
 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
@@ -1346,8 +1425,11 @@  discard block
 block discarded – undo
1346 1425
 				$query_values = array_merge($query_values,array(':month' => $month));
1347 1426
 			}
1348 1427
 		}
1349
-		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1350
-		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1428
+		if (empty($query_values)) {
1429
+			$queryi .= $this->getFilter($filters);
1430
+		} else {
1431
+			$queryi .= $this->getFilter($filters,true,true).substr($query,4);
1432
+		}
1351 1433
 		
1352 1434
 		$sth = $this->db->prepare($queryi);
1353 1435
 		$sth->execute($query_values);
@@ -1369,7 +1451,9 @@  discard block
 block discarded – undo
1369 1451
 			date_default_timezone_set($globalTimezone);
1370 1452
 			$datetime = new DateTime();
1371 1453
 			$offset = $datetime->format('P');
1372
-		} else $offset = '+00:00';
1454
+		} else {
1455
+			$offset = '+00:00';
1456
+		}
1373 1457
 
1374 1458
 		if ($globalDBdriver == 'mysql') {
1375 1459
 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
@@ -1473,7 +1557,9 @@  discard block
 block discarded – undo
1473 1557
 	*/
1474 1558
 	public function parseDirection($direction = 0)
1475 1559
 	{
1476
-		if ($direction == '') $direction = 0;
1560
+		if ($direction == '') {
1561
+			$direction = 0;
1562
+		}
1477 1563
 		$direction_array = array();
1478 1564
 		$temp_array = array();
1479 1565
 
@@ -1562,7 +1648,9 @@  discard block
 block discarded – undo
1562 1648
 		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1563 1649
 	
1564 1650
 		$Connection = new Connection($this->db);
1565
-		if (!$Connection->tableExists('countries')) return '';
1651
+		if (!$Connection->tableExists('countries')) {
1652
+			return '';
1653
+		}
1566 1654
 	
1567 1655
 		try {
1568 1656
 			/*
@@ -1582,9 +1670,13 @@  discard block
 block discarded – undo
1582 1670
 			$sth->closeCursor();
1583 1671
 			if (count($row) > 0) {
1584 1672
 				return $row;
1585
-			} else return '';
1673
+			} else {
1674
+				return '';
1675
+			}
1586 1676
 		} catch (PDOException $e) {
1587
-			if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n";
1677
+			if (isset($globalDebug) && $globalDebug) {
1678
+				echo 'Error : '.$e->getMessage()."\n";
1679
+			}
1588 1680
 			return '';
1589 1681
 		}
1590 1682
 	
@@ -1602,7 +1694,9 @@  discard block
 block discarded – undo
1602 1694
 		$iso2 = filter_var($iso2,FILTER_SANITIZE_STRING);
1603 1695
 	
1604 1696
 		$Connection = new Connection($this->db);
1605
-		if (!$Connection->tableExists('countries')) return '';
1697
+		if (!$Connection->tableExists('countries')) {
1698
+			return '';
1699
+		}
1606 1700
 	
1607 1701
 		try {
1608 1702
 			$query = "SELECT name,iso2,iso3 FROM countries WHERE iso2 = :iso2 LIMIT 1";
@@ -1614,9 +1708,13 @@  discard block
 block discarded – undo
1614 1708
 			$sth->closeCursor();
1615 1709
 			if (count($row) > 0) {
1616 1710
 				return $row;
1617
-			} else return '';
1711
+			} else {
1712
+				return '';
1713
+			}
1618 1714
 		} catch (PDOException $e) {
1619
-			if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n";
1715
+			if (isset($globalDebug) && $globalDebug) {
1716
+				echo 'Error : '.$e->getMessage()."\n";
1717
+			}
1620 1718
 			return '';
1621 1719
 		}
1622 1720
 	
@@ -1634,7 +1732,9 @@  discard block
 block discarded – undo
1634 1732
 	{
1635 1733
 		global $globalBitlyAccessToken;
1636 1734
 		
1637
-		if ($globalBitlyAccessToken == '') return $url;
1735
+		if ($globalBitlyAccessToken == '') {
1736
+			return $url;
1737
+		}
1638 1738
         
1639 1739
 		$google_url = 'https://api-ssl.bitly.com/v3/shorten?access_token='.$globalBitlyAccessToken.'&longUrl='.$url;
1640 1740
 		
Please login to merge, or discard this patch.
require/class.SpotterImport.php 1 patch
Braces   +355 added lines, -125 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,12 +213,16 @@  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()-3000)) {
188 222
             	    if (isset($this->all_flights[$key]['id'])) {
189
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
223
+            		if ($globalDebug) {
224
+            			echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
225
+            		}
190 226
 			/*
191 227
 			$SpotterLive = new SpotterLive();
192 228
             		$SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']);
@@ -197,7 +233,9 @@  discard block
 block discarded – undo
197 233
             		    $Spotter = new Spotter($this->db);
198 234
             	    	    if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
199 235
 				$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']);
200
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
236
+				if ($globalDebug && $result != 'success') {
237
+					echo '!!! ERROR : '.$result."\n";
238
+				}
201 239
 			    }
202 240
 			// Put in archive
203 241
 //				$Spotter->db = null;
@@ -212,8 +250,10 @@  discard block
 block discarded – undo
212 250
     public function add($line) {
213 251
 	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;
214 252
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
215
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
216
-/*
253
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
254
+		$globalCoordMinChange = '0.02';
255
+	}
256
+	/*
217 257
 	$Spotter = new Spotter();
218 258
 	$dbc = $Spotter->db;
219 259
 	$SpotterLive = new SpotterLive($dbc);
@@ -241,11 +281,15 @@  discard block
 block discarded – undo
241 281
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
242 282
 		    $current_date = date('Y-m-d');
243 283
 		    $source = $line['source_name'];
244
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
284
+		    if ($source == '' || $line['format_source'] == 'aprs') {
285
+		    	$source = $line['format_source'];
286
+		    }
245 287
 		    if (!isset($this->stats[$current_date][$source]['msg'])) {
246 288
 		    	$this->stats[$current_date][$source]['msg']['date'] = time();
247 289
 		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
248
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
290
+		    } else {
291
+		    	$this->stats[$current_date][$source]['msg']['nb'] += 1;
292
+		    }
249 293
 		}
250 294
 		
251 295
 		/*
@@ -261,22 +305,35 @@  discard block
 block discarded – undo
261 305
 		//$this->db = $dbc;
262 306
 
263 307
 		//$hex = trim($line['hex']);
264
-	        if (!isset($line['id'])) $id = trim($line['hex']);
265
-	        else $id = trim($line['id']);
308
+	        if (!isset($line['id'])) {
309
+	        	$id = trim($line['hex']);
310
+	        } else {
311
+	        	$id = trim($line['id']);
312
+	        }
266 313
 		
267 314
 		if (!isset($this->all_flights[$id])) {
268 315
 		    $this->all_flights[$id] = array();
269 316
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
270 317
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', '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' => ''));
271
-		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
318
+		    if (isset($globalDaemon) && $globalDaemon === FALSE) {
319
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
320
+		    }
272 321
 		    if (!isset($line['id'])) {
273
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
274
-//			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')));
322
+			if (!isset($globalDaemon)) {
323
+				$globalDaemon = TRUE;
324
+			}
325
+			//			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')));
275 326
 //			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')));
276
-			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')));
327
+			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')) {
328
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
329
+			}
277 330
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
278
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
279
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
331
+		     } else {
332
+		     	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
333
+		     }
334
+		    if ($globalAllFlights !== FALSE) {
335
+		    	$dataFound = true;
336
+		    }
280 337
 		}
281 338
 		if (isset($line['source_type']) && $line['source_type'] != '') {
282 339
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
@@ -298,17 +355,27 @@  discard block
 block discarded – undo
298 355
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
299 356
 			    }
300 357
 			    $Spotter->db = null;
301
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
302
-			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
358
+			    if ($globalDebugTimeElapsed) {
359
+			    	echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
360
+			    }
361
+			    if ($aircraft_icao != '') {
362
+			    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
363
+			    }
303 364
 			}
304 365
 		    }
305
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
306
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
366
+		    if ($globalAllFlights !== FALSE) {
367
+		    	$dataFound = true;
368
+		    }
369
+		    if ($globalDebug) {
370
+		    	echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
371
+		    }
307 372
 		}
308 373
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
309 374
 			$icao = $line['aircraft_icao'];
310 375
 			$Spotter = new Spotter($this->db);
311
-			if (isset($Spotter->aircraft_correct_icaotype[$icao])) $icao = $Spotter->aircraft_correct_icaotype[$icao];
376
+			if (isset($Spotter->aircraft_correct_icaotype[$icao])) {
377
+				$icao = $Spotter->aircraft_correct_icaotype[$icao];
378
+			}
312 379
 			$Spotter->db = null;
313 380
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $icao));
314 381
 		}
@@ -318,15 +385,24 @@  discard block
 block discarded – undo
318 385
 				$Spotter = new Spotter($this->db);
319 386
 				$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
320 387
 				$Spotter->db = null;
321
-				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
388
+				if ($aircraft_icao != '') {
389
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
390
+				}
322 391
 			}
323 392
 		}
324 393
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) {
325
-			if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
326
-			elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
327
-			elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
328
-			elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
329
-			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
394
+			if ($line['aircraft_type'] == 'PARA_GLIDER') {
395
+				$aircraft_icao = 'GLID';
396
+			} elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') {
397
+				$aircraft_icao = 'UHEL';
398
+			} elseif ($line['aircraft_type'] == 'TOW_PLANE') {
399
+				$aircraft_icao = 'TOWPLANE';
400
+			} elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') {
401
+				$aircraft_icao = 'POWAIRC';
402
+			}
403
+			if (isset($aircraft_icao)) {
404
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
405
+			}
330 406
 		}
331 407
 		if (!isset($this->all_flights[$id]['aircraft_icao'])) {
332 408
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
@@ -336,8 +412,11 @@  discard block
 block discarded – undo
336 412
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
337 413
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
338 414
 		    } else {
339
-				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";
340
-				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";
415
+				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
416
+					echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
417
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
418
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
419
+				}
341 420
 				/*
342 421
 				echo strtotime($line['datetime']).' > '.strtotime($this->all_flights[$id]['datetime']);
343 422
 				print_r($this->all_flights[$id]);
@@ -346,16 +425,22 @@  discard block
 block discarded – undo
346 425
 				return '';
347 426
 		    }
348 427
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) {
349
-			if ($globalDebug) echo "!!! Date is too old ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!";
428
+			if ($globalDebug) {
429
+				echo "!!! Date is too old ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!";
430
+			}
350 431
 			return '';
351 432
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) > time()+20*60) {
352
-			if ($globalDebug) echo "!!! Date is in the future ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!";
433
+			if ($globalDebug) {
434
+				echo "!!! Date is in the future ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!";
435
+			}
353 436
 			return '';
354 437
 		} elseif (!isset($line['datetime'])) {
355 438
 			date_default_timezone_set('UTC');
356 439
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
357 440
 		} else {
358
-			if ($globalDebug) echo "!!! Unknow date error ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!";
441
+			if ($globalDebug) {
442
+				echo "!!! Unknow date error ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!";
443
+			}
359 444
 			return '';
360 445
 		}
361 446
 
@@ -379,15 +464,25 @@  discard block
 block discarded – undo
379 464
 			    $timeelapsed = microtime(true);
380 465
             		    $Spotter = new Spotter($this->db);
381 466
             		    $fromsource = NULL;
382
-            		    if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
383
-            		    elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
384
-			    elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
385
-			    elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
386
-			    elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
467
+            		    if (isset($globalAirlinesSource) && $globalAirlinesSource != '') {
468
+            		    	$fromsource = $globalAirlinesSource;
469
+            		    } elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') {
470
+            		    	$fromsource = 'vatsim';
471
+            		    } elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') {
472
+			    	$fromsource = 'ivao';
473
+			    } elseif (isset($globalVATSIM) && $globalVATSIM) {
474
+			    	$fromsource = 'vatsim';
475
+			    } elseif (isset($globalIVAO) && $globalIVAO) {
476
+			    	$fromsource = 'ivao';
477
+			    }
387 478
             		    $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
388
-			    if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
479
+			    if ($globalDebug && $result != 'success') {
480
+			    	echo '!!! ERROR : '.$result."\n";
481
+			    }
389 482
 			    $Spotter->db = null;
390
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
483
+			    if ($globalDebugTimeElapsed) {
484
+			    	echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
485
+			    }
391 486
 			}
392 487
 		    }
393 488
 
@@ -399,7 +494,9 @@  discard block
 block discarded – undo
399 494
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
400 495
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
401 496
   */
402
-		    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']));
497
+		    if (!isset($this->all_flights[$id]['id'])) {
498
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
499
+		    }
403 500
 
404 501
 		    //$putinarchive = true;
405 502
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
@@ -417,7 +514,9 @@  discard block
 block discarded – undo
417 514
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
418 515
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
419 516
 		    		$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' => ''));
420
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
517
+				if ($globalDebugTimeElapsed) {
518
+					echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
519
+				}
421 520
                         }
422 521
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
423 522
 			$timeelapsed = microtime(true);
@@ -431,7 +530,9 @@  discard block
 block discarded – undo
431 530
 				$Translation->db = null;
432 531
 			    }
433 532
 			    $Spotter->db = null;
434
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
533
+			    if ($globalDebugTimeElapsed) {
534
+			    	echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
535
+			    }
435 536
                     	}
436 537
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
437 538
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
@@ -440,9 +541,13 @@  discard block
 block discarded – undo
440 541
 		    		$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']));
441 542
 		    	    }
442 543
 			}
443
-			if (!isset($globalFork)) $globalFork = TRUE;
544
+			if (!isset($globalFork)) {
545
+				$globalFork = TRUE;
546
+			}
444 547
 			if (!$globalVA && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
445
-				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
548
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) {
549
+					$this->get_Schedule($id,trim($line['ident']));
550
+				}
446 551
 			}
447 552
 		    }
448 553
 		}
@@ -458,16 +563,23 @@  discard block
 block discarded – undo
458 563
 		    // use datetime
459 564
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
460 565
 			$speed = $speed*3.6;
461
-			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
462
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
566
+			if ($speed < 1000) {
567
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
568
+			}
569
+  			if ($globalDebug) {
570
+  				echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
571
+  			}
463 572
 		    }
464 573
 		}
465 574
 
466 575
 
467 576
 
468 577
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
469
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
470
-	    	    else unset($timediff);
578
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) {
579
+	    	    	$timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
580
+	    	    } else {
581
+	    	    	unset($timediff);
582
+	    	    }
471 583
 	    	    if ($this->tmd > 5 || (isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
472 584
 			if (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude'])) {
473 585
 			    if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
@@ -476,15 +588,23 @@  discard block
 block discarded – undo
476 588
 				$this->all_flights[$id]['putinarchive'] = true;
477 589
 				$this->tmd = 0;
478 590
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
479
-				    if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
591
+				    if ($globalDebug) {
592
+				    	echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
593
+				    }
480 594
 				    $timeelapsed = microtime(true);
481 595
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
482 596
 					$Spotter = new Spotter($this->db);
483 597
 					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
484
-					if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
598
+					if (!empty($all_country)) {
599
+						$this->all_flights[$id]['over_country'] = $all_country['iso2'];
600
+					}
485 601
 					$Spotter->db = null;
486
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
487
-					if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
602
+					if ($globalDebugTimeElapsed) {
603
+						echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
604
+					}
605
+					if ($globalDebug) {
606
+						echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
607
+					}
488 608
 				    }
489 609
 				}
490 610
 			    }
@@ -492,7 +612,9 @@  discard block
 block discarded – undo
492 612
 
493 613
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
494 614
 			    //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) {
495
-				if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
615
+				if (!isset($this->all_flights[$id]['archive_latitude'])) {
616
+					$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
617
+				}
496 618
 				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') {
497 619
 				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
498 620
 				    $dataFound = true;
@@ -514,9 +636,13 @@  discard block
 block discarded – undo
514 636
 			    */
515 637
 			}
516 638
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
517
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
639
+			    if ($line['longitude'] > 180) {
640
+			    	$line['longitude'] = $line['longitude'] - 360;
641
+			    }
518 642
 			    //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) {
519
-				if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
643
+				if (!isset($this->all_flights[$id]['archive_longitude'])) {
644
+					$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
645
+				}
520 646
 				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') {
521 647
 				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
522 648
 				    $dataFound = true;
@@ -547,7 +673,9 @@  discard block
 block discarded – undo
547 673
 		    }
548 674
 		}
549 675
 		if (isset($line['last_update']) && $line['last_update'] != '') {
550
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
676
+		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) {
677
+		    	$dataFound = true;
678
+		    }
551 679
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
552 680
 		}
553 681
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
@@ -569,41 +697,61 @@  discard block
 block discarded – undo
569 697
 			// Here we force archive of flight because after ground it's a new one (or should be)
570 698
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
571 699
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
572
-			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'].'-'.date('YmdGi')));
573
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
574
-			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']));
700
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) {
701
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
702
+			} elseif (isset($line['id'])) {
703
+		        	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
704
+		        } elseif (isset($this->all_flights[$id]['ident'])) {
705
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
706
+			}
707
+		    }
708
+		    if ($line['ground'] != 1) {
709
+		    	$line['ground'] = 0;
575 710
 		    }
576
-		    if ($line['ground'] != 1) $line['ground'] = 0;
577 711
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
578 712
 		    //$dataFound = true;
579 713
 		}
580 714
 		if (isset($line['squawk']) && $line['squawk'] != '') {
581 715
 		    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'])) {
582
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
716
+			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) {
717
+			    	$this->all_flights[$id]['putinarchive'] = true;
718
+			    }
583 719
 			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
584 720
 			    $highlight = '';
585
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
586
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
587
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
721
+			    if ($this->all_flights[$id]['squawk'] == '7500') {
722
+			    	$highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
723
+			    }
724
+			    if ($this->all_flights[$id]['squawk'] == '7600') {
725
+			    	$highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
726
+			    }
727
+			    if ($this->all_flights[$id]['squawk'] == '7700') {
728
+			    	$highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
729
+			    }
588 730
 			    if ($highlight != '') {
589 731
 				$timeelapsed = microtime(true);
590 732
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
591 733
 				    $Spotter = new Spotter($this->db);
592 734
 				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
593 735
 				    $Spotter->db = null;
594
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
736
+				    if ($globalDebugTimeElapsed) {
737
+				    	echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
738
+				    }
595 739
 				}
596 740
 				//$putinarchive = true;
597 741
 				//$highlight = '';
598 742
 			    }
599 743
 			    
600
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
744
+		    } else {
745
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
746
+		    }
601 747
 		    //$dataFound = true;
602 748
 		}
603 749
 
604 750
 		if (isset($line['altitude']) && $line['altitude'] != '') {
605 751
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
606
-			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;
752
+			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) {
753
+				$this->all_flights[$id]['putinarchive'] = true;
754
+			}
607 755
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
608 756
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
609 757
 			//$dataFound = true;
@@ -615,21 +763,30 @@  discard block
 block discarded – undo
615 763
 		}
616 764
 		
617 765
 		if (isset($line['heading']) && $line['heading'] != '') {
618
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
766
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) {
767
+		    	$this->all_flights[$id]['putinarchive'] = true;
768
+		    }
619 769
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
620 770
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
621 771
 		    //$dataFound = true;
622 772
   		} 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']) {
623 773
   		    $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']);
624 774
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
625
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
626
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
775
+		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) {
776
+		    	$this->all_flights[$id]['putinarchive'] = true;
777
+		    }
778
+  		    if ($globalDebug) {
779
+  		    	echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
780
+  		    }
627 781
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
628 782
   		    // If not enough messages and ACARS set heading to 0
629 783
   		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
630 784
   		}
631
-		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
632
-		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
785
+		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) {
786
+			$dataFound = false;
787
+		} elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) {
788
+			$dataFound = false;
789
+		}
633 790
 
634 791
 //		print_r($this->all_flights[$id]);
635 792
 		//gets the callsign from the last hour
@@ -645,23 +802,38 @@  discard block
 block discarded – undo
645 802
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
646 803
 			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
647 804
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
648
-				    if ($globalDebug) echo "Check if aircraft is already in DB...";
805
+				    if ($globalDebug) {
806
+				    	echo "Check if aircraft is already in DB...";
807
+				    }
649 808
 				    $timeelapsed = microtime(true);
650 809
 				    $SpotterLive = new SpotterLive($this->db);
651 810
 				    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')) {
652 811
 					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
653
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
812
+					if ($globalDebugTimeElapsed) {
813
+						echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
814
+					}
654 815
 				    } elseif (isset($line['id'])) {
655 816
 					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
656
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
817
+					if ($globalDebugTimeElapsed) {
818
+						echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
819
+					}
657 820
 				    } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
658 821
 					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
659
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
660
-				    } else $recent_ident = '';
822
+					if ($globalDebugTimeElapsed) {
823
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
824
+					}
825
+				    } else {
826
+				    	$recent_ident = '';
827
+				    }
661 828
 				    $SpotterLive->db=null;
662
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
663
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
664
-				} else $recent_ident = '';
829
+				    if ($globalDebug && $recent_ident == '') {
830
+				    	echo " Not in DB.\n";
831
+				    } elseif ($globalDebug && $recent_ident != '') {
832
+				    	echo " Already in DB.\n";
833
+				    }
834
+				} else {
835
+					$recent_ident = '';
836
+				}
665 837
 			    } else {
666 838
 				$recent_ident = '';
667 839
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
@@ -669,7 +841,9 @@  discard block
 block discarded – undo
669 841
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
670 842
 			    if($recent_ident == "")
671 843
 			    {
672
-				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
844
+				if ($globalDebug) {
845
+					echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
846
+				}
673 847
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
674 848
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
675 849
 				//adds the spotter data for the archive
@@ -713,31 +887,49 @@  discard block
 block discarded – undo
713 887
 				
714 888
 				if (!$ignoreImport) {
715 889
 				    $highlight = '';
716
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
717
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
718
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
719
-				    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')));
890
+				    if ($this->all_flights[$id]['squawk'] == '7500') {
891
+				    	$highlight = 'Squawk 7500 : Hijack';
892
+				    }
893
+				    if ($this->all_flights[$id]['squawk'] == '7600') {
894
+				    	$highlight = 'Squawk 7600 : Lost Comm (radio failure)';
895
+				    }
896
+				    if ($this->all_flights[$id]['squawk'] == '7700') {
897
+				    	$highlight = 'Squawk 7700 : Emergency';
898
+				    }
899
+				    if (!isset($this->all_flights[$id]['id'])) {
900
+				    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
901
+				    }
720 902
 				    $timeelapsed = microtime(true);
721 903
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
722 904
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
723 905
 					    $Spotter = new Spotter($this->db);
724 906
 					    $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']);
725 907
 					    $Spotter->db = null;
726
-					    if ($globalDebug && isset($result)) echo $result."\n";
908
+					    if ($globalDebug && isset($result)) {
909
+					    	echo $result."\n";
910
+					    }
727 911
 					}
728 912
 				    }
729
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
913
+				    if ($globalDebugTimeElapsed) {
914
+				    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
915
+				    }
730 916
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
731 917
 
732 918
 				    // Add source stat in DB
733 919
 				    $Stats = new Stats($this->db);
734 920
 				    if (!empty($this->stats)) {
735
-					if ($globalDebug) echo 'Add source stats : ';
921
+					if ($globalDebug) {
922
+						echo 'Add source stats : ';
923
+					}
736 924
 				        foreach($this->stats as $date => $data) {
737 925
 					    foreach($data as $source => $sourced) {
738 926
 					        //print_r($sourced);
739
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
740
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
927
+				    	        if (isset($sourced['polar'])) {
928
+				    	        	echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
929
+				    	        }
930
+				    	        if (isset($sourced['hist'])) {
931
+				    	        	echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
932
+				    	        }
741 933
 				    		if (isset($sourced['msg'])) {
742 934
 				    		    if (time() - $sourced['msg']['date'] > 10) {
743 935
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
@@ -750,13 +942,17 @@  discard block
 block discarded – undo
750 942
 			    			unset($this->stats[$date]);
751 943
 			    		    }
752 944
 				    	}
753
-				    	if ($globalDebug) echo 'Done'."\n";
945
+				    	if ($globalDebug) {
946
+				    		echo 'Done'."\n";
947
+				    	}
754 948
 
755 949
 				    }
756 950
 				    $Stats->db = null;
757 951
 				    }
758 952
 				    $this->del();
759
-				} elseif ($globalDebug) echo 'Ignore data'."\n";
953
+				} elseif ($globalDebug) {
954
+					echo 'Ignore data'."\n";
955
+				}
760 956
 				//$ignoreImport = false;
761 957
 				$this->all_flights[$id]['addedSpotter'] = 1;
762 958
 				//print_r($this->all_flights[$id]);
@@ -773,7 +969,9 @@  discard block
 block discarded – undo
773 969
 			*/
774 970
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
775 971
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
776
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
972
+				    if ($globalDebug) {
973
+				    	echo "---- Deleting Live Spotter data older than 9 hours...";
974
+				    }
777 975
 				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
778 976
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
779 977
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
@@ -782,7 +980,9 @@  discard block
 block discarded – undo
782 980
 					    $SpotterLive->db=null;
783 981
 					}
784 982
 				    }
785
-				    if ($globalDebug) echo " Done\n";
983
+				    if ($globalDebug) {
984
+				    	echo " Done\n";
985
+				    }
786 986
 				    $this->last_delete = time();
787 987
 				}
788 988
 			    } else {
@@ -809,11 +1009,17 @@  discard block
 block discarded – undo
809 1009
 		    //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";
810 1010
 		    if ($globalDebug) {
811 1011
 			if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
812
-				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";
813
-				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";
1012
+				if (isset($this->all_flights[$id]['source_name'])) {
1013
+					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";
1014
+				} else {
1015
+					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";
1016
+				}
814 1017
 			} else {
815
-				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";
816
-				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";
1018
+				if (isset($this->all_flights[$id]['source_name'])) {
1019
+					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";
1020
+				} else {
1021
+					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";
1022
+				}
817 1023
 			}
818 1024
 		    }
819 1025
 		    $ignoreImport = false;
@@ -859,22 +1065,30 @@  discard block
 block discarded – undo
859 1065
 
860 1066
 		    if (!$ignoreImport) {
861 1067
 			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'])) {
862
-				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')));
1068
+				if (!isset($this->all_flights[$id]['id'])) {
1069
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
1070
+				}
863 1071
 				$timeelapsed = microtime(true);
864 1072
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
865 1073
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
866
-					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1074
+					if ($globalDebug) {
1075
+						echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1076
+					}
867 1077
 					$SpotterLive = new SpotterLive($this->db);
868 1078
 					$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']);
869 1079
 					$SpotterLive->db = null;
870
-					if ($globalDebug) echo $result."\n";
1080
+					if ($globalDebug) {
1081
+						echo $result."\n";
1082
+					}
871 1083
 				    }
872 1084
 				}
873 1085
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) {
874 1086
 					$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']);
875 1087
 				}
876 1088
 				$this->all_flights[$id]['putinarchive'] = false;
877
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1089
+				if ($globalDebugTimeElapsed) {
1090
+					echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1091
+				}
878 1092
 
879 1093
 				// Put statistics in $this->stats variable
880 1094
 				//if ($line['format_source'] != 'aprs') {
@@ -882,7 +1096,9 @@  discard block
 block discarded – undo
882 1096
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
883 1097
 				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
884 1098
 					$source = $this->all_flights[$id]['source_name'];
885
-					if ($source == '') $source = $this->all_flights[$id]['format_source'];
1099
+					if ($source == '') {
1100
+						$source = $this->all_flights[$id]['format_source'];
1101
+					}
886 1102
 					if (!isset($this->source_location[$source])) {
887 1103
 						$Location = new Source();
888 1104
 						$coord = $Location->getLocationInfobySourceName($source);
@@ -903,7 +1119,9 @@  discard block
 block discarded – undo
903 1119
 					$stats_heading = round($stats_heading/22.5);
904 1120
 					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
905 1121
 					$current_date = date('Y-m-d');
906
-					if ($stats_heading == 16) $stats_heading = 0;
1122
+					if ($stats_heading == 16) {
1123
+						$stats_heading = 0;
1124
+					}
907 1125
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
908 1126
 						for ($i=0;$i<=15;$i++) {
909 1127
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
@@ -921,7 +1139,9 @@  discard block
 block discarded – undo
921 1139
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
922 1140
 						    end($this->stats[$current_date][$source]['hist']);
923 1141
 						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
924
-						} else $mini = 0;
1142
+						} else {
1143
+							$mini = 0;
1144
+						}
925 1145
 						for ($i=$mini;$i<=$distance;$i+=10) {
926 1146
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
927 1147
 						}
@@ -933,19 +1153,27 @@  discard block
 block discarded – undo
933 1153
 				}
934 1154
 
935 1155
 				$this->all_flights[$id]['lastupdate'] = time();
936
-				if ($this->all_flights[$id]['putinarchive']) $send = true;
1156
+				if ($this->all_flights[$id]['putinarchive']) {
1157
+					$send = true;
1158
+				}
937 1159
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
938
-			} 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";
1160
+			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
1161
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1162
+			}
939 1163
 			//$this->del();
940 1164
 			
941 1165
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
942 1166
 			    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
943
-				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1167
+				if ($globalDebug) {
1168
+					echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1169
+				}
944 1170
 				$SpotterLive = new SpotterLive($this->db);
945 1171
 				$SpotterLive->deleteLiveSpotterDataNotUpdated();
946 1172
 				$SpotterLive->db = null;
947 1173
 				//SpotterLive->deleteLiveSpotterData();
948
-				if ($globalDebug) echo " Done\n";
1174
+				if ($globalDebug) {
1175
+					echo " Done\n";
1176
+				}
949 1177
 				$this->last_delete_hourly = time();
950 1178
 			    } else {
951 1179
 				$this->del();
@@ -957,7 +1185,9 @@  discard block
 block discarded – undo
957 1185
 		    //$ignoreImport = false;
958 1186
 		}
959 1187
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
960
-		if ($send) return $this->all_flights[$id];
1188
+		if ($send) {
1189
+			return $this->all_flights[$id];
1190
+		}
961 1191
 	    }
962 1192
 	}
963 1193
     }
Please login to merge, or discard this patch.