Completed
Push — master ( 0ab643...ed68c3 )
by Yannick
09:23
created
tools-geoid.php 1 patch
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -61,8 +61,11 @@
 block discarded – undo
61 61
 		print '<div class="col-sm-6">'.round($altitude-$geoid,3).'</div>';
62 62
 	}
63 63
 	print '<div class="col-sm-6"><b>Earth Gravity Model</b></div>';
64
-	if (isset($globalGeoidSource) && $globalGeoidSource != '') $geoidsource = $globalGeoidSource;
65
-	else $geoidsource = 'EGM96-15';
64
+	if (isset($globalGeoidSource) && $globalGeoidSource != '') {
65
+		$geoidsource = $globalGeoidSource;
66
+	} else {
67
+		$geoidsource = 'EGM96-15';
68
+	}
66 69
 	print '<div class="col-sm-6">'.$geoidsource.'</div>';
67 70
 	print '</div>';
68 71
 }
Please login to merge, or discard this patch.
scripts/daemon-spotter.php 1 patch
Braces   +1002 added lines, -345 removed lines patch added patch discarded remove patch
@@ -14,13 +14,17 @@  discard block
 block discarded – undo
14 14
 require_once(dirname(__FILE__).'/../require/class.Source.php');
15 15
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
16 16
 require_once(dirname(__FILE__).'/../require/class.Common.php');
17
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
17
+if (isset($globalTracker) && $globalTracker) {
18
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
19
+}
18 20
 if (isset($globalMarine) && $globalMarine) {
19 21
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
20 22
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
21 23
 }
22 24
 
23
-if (!isset($globalDebug)) $globalDebug = FALSE;
25
+if (!isset($globalDebug)) {
26
+	$globalDebug = FALSE;
27
+}
24 28
 
25 29
 // Check if schema is at latest version
26 30
 $Connection = new Connection();
@@ -55,35 +59,62 @@  discard block
 block discarded – undo
55 59
 //elseif (isset($options['source'])) $hosts = array($options['source']);
56 60
 if (isset($options['s'])) {
57 61
     $globalSources = array();
58
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']);
59
-    else $globalSources[] = array('host' => $options['s']);
60
-} elseif (isset($options['source'])) {
62
+    if (isset($options['format'])) {
63
+    	$globalSources[] = array('host' => $options['s'],'format' => $options['format']);
64
+    } else {
65
+    	$globalSources[] = array('host' => $options['s']);
66
+    }
67
+    } elseif (isset($options['source'])) {
61 68
     $globalSources = array();
62
-    if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']);
63
-    else $globalSources[] = array('host' => $options['source']);
64
-}
69
+    if (isset($options['format'])) {
70
+    	$globalSources[] = array('host' => $options['source'],'format' => $options['format']);
71
+    } else {
72
+    	$globalSources[] = array('host' => $options['source']);
73
+    }
74
+    }
65 75
 if (isset($options['aprsserverhost'])) {
66 76
 	$globalServerAPRS = TRUE;
67 77
 	$globalServerAPRShost = $options['aprsserverhost'];
68 78
 }
69
-if (isset($options['aprsserverport'])) $globalServerAPRSport = $options['aprsserverport'];
70
-if (isset($options['aprsserverssid'])) $globalServerAPRSssid = $options['aprsserverssid'];
71
-if (isset($options['aprsserverpass'])) $globalServerAPRSpass = $options['aprsserverpass'];
72
-if (isset($options['noaprsserver'])) $globalServerAPRS = FALSE; 
73
-if (isset($options['nodaemon'])) $globalDaemon = FALSE;
74
-if (isset($options['server'])) $globalServer = TRUE;
75
-if (isset($options['idsource'])) $id_source = $options['idsource'];
76
-else $id_source = 1;
79
+if (isset($options['aprsserverport'])) {
80
+	$globalServerAPRSport = $options['aprsserverport'];
81
+}
82
+if (isset($options['aprsserverssid'])) {
83
+	$globalServerAPRSssid = $options['aprsserverssid'];
84
+}
85
+if (isset($options['aprsserverpass'])) {
86
+	$globalServerAPRSpass = $options['aprsserverpass'];
87
+}
88
+if (isset($options['noaprsserver'])) {
89
+	$globalServerAPRS = FALSE;
90
+}
91
+if (isset($options['nodaemon'])) {
92
+	$globalDaemon = FALSE;
93
+}
94
+if (isset($options['server'])) {
95
+	$globalServer = TRUE;
96
+}
97
+if (isset($options['idsource'])) {
98
+	$id_source = $options['idsource'];
99
+} else {
100
+	$id_source = 1;
101
+}
77 102
 if (isset($globalServer) && $globalServer) {
78
-    if ($globalDebug) echo "Using Server Mode\n";
103
+    if ($globalDebug) {
104
+    	echo "Using Server Mode\n";
105
+    }
79 106
     $SI=new SpotterServer();
80 107
 /*
81 108
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
82 109
     $SI = new adsb2aprs();
83 110
     $SI->connect();
84 111
 */
85
-} else $SI=new SpotterImport($Connection->db);
86
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
112
+} else {
113
+	$SI=new SpotterImport($Connection->db);
114
+}
115
+if (isset($globalTracker) && $globalTracker) {
116
+	$TI = new TrackerImport($Connection->db);
117
+}
87 118
 if (isset($globalMarine) && $globalMarine) {
88 119
     $AIS = new AIS();
89 120
     $MI = new MarineImport($Connection->db);
@@ -106,7 +137,9 @@  discard block
 block discarded – undo
106 137
 }
107 138
 
108 139
 // let's try and connect
109
-if ($globalDebug) echo "Connecting...\n";
140
+if ($globalDebug) {
141
+	echo "Connecting...\n";
142
+}
110 143
 $use_aprs = false;
111 144
 $aprs_full = false;
112 145
 $reset = 0;
@@ -115,7 +148,9 @@  discard block
 block discarded – undo
115 148
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
116 149
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
117 150
     $reset++;
118
-    if ($globalDebug) echo 'Connect to all...'."\n";
151
+    if ($globalDebug) {
152
+    	echo 'Connect to all...'."\n";
153
+    }
119 154
     foreach ($hosts as $id => $value) {
120 155
 	$host = $value['host'];
121 156
 	$globalSources[$id]['last_exec'] = 0;
@@ -125,22 +160,30 @@  discard block
 block discarded – undo
125 160
         	//$formats[$id] = 'deltadbtxt';
126 161
         	$globalSources[$id]['format'] = 'deltadbtxt';
127 162
         	//$last_exec['deltadbtxt'] = 0;
128
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
163
+        	if ($globalDebug) {
164
+        		echo "Connect to deltadb source (".$host.")...\n";
165
+        	}
129 166
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
130 167
         	//$formats[$id] = 'vatsimtxt';
131 168
         	$globalSources[$id]['format'] = 'vatsimtxt';
132 169
         	//$last_exec['vatsimtxt'] = 0;
133
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
170
+        	if ($globalDebug) {
171
+        		echo "Connect to vatsim source (".$host.")...\n";
172
+        	}
134 173
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
135 174
         	//$formats[$id] = 'aircraftlistjson';
136 175
         	$globalSources[$id]['format'] = 'aircraftlistjson';
137 176
         	//$last_exec['aircraftlistjson'] = 0;
138
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
177
+        	if ($globalDebug) {
178
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
179
+        	}
139 180
     	    } else if (preg_match('/opensky/i',$host)) {
140 181
         	//$formats[$id] = 'aircraftlistjson';
141 182
         	$globalSources[$id]['format'] = 'opensky';
142 183
         	//$last_exec['aircraftlistjson'] = 0;
143
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
184
+        	if ($globalDebug) {
185
+        		echo "Connect to opensky source (".$host.")...\n";
186
+        	}
144 187
     	    /*
145 188
     	    // Disabled for now, site change source format
146 189
     	    } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) {
@@ -157,7 +200,9 @@  discard block
 block discarded – undo
157 200
         	//$formats[$id] = 'planeupdatefaa';
158 201
         	$globalSources[$id]['format'] = 'planeupdatefaa';
159 202
         	//$last_exec['planeupdatefaa'] = 0;
160
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
203
+        	if ($globalDebug) {
204
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
205
+        	}
161 206
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
162 207
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
163 208
         	    exit(0);
@@ -166,29 +211,41 @@  discard block
 block discarded – undo
166 211
         	//$formats[$id] = 'phpvmacars';
167 212
         	$globalSources[$id]['format'] = 'phpvmacars';
168 213
         	//$last_exec['phpvmacars'] = 0;
169
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
214
+        	if ($globalDebug) {
215
+        		echo "Connect to phpvmacars source (".$host.")...\n";
216
+        	}
170 217
             } else if (preg_match('/VAM-json.php$/i',$host)) {
171 218
         	//$formats[$id] = 'phpvmacars';
172 219
         	$globalSources[$id]['format'] = 'vam';
173
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
220
+        	if ($globalDebug) {
221
+        		echo "Connect to Vam source (".$host.")...\n";
222
+        	}
174 223
             } else if (preg_match('/whazzup/i',$host)) {
175 224
         	//$formats[$id] = 'whazzup';
176 225
         	$globalSources[$id]['format'] = 'whazzup';
177 226
         	//$last_exec['whazzup'] = 0;
178
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
227
+        	if ($globalDebug) {
228
+        		echo "Connect to whazzup source (".$host.")...\n";
229
+        	}
179 230
             } else if (preg_match('/airwhere/i',$host)) {
180 231
         	$globalSources[$id]['format'] = 'airwhere';
181
-        	if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n";
232
+        	if ($globalDebug) {
233
+        		echo "Connect to airwhere source (".$host.")...\n";
234
+        	}
182 235
             } else if (preg_match('/recentpireps/i',$host)) {
183 236
         	//$formats[$id] = 'pirepsjson';
184 237
         	$globalSources[$id]['format'] = 'pirepsjson';
185 238
         	//$last_exec['pirepsjson'] = 0;
186
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
239
+        	if ($globalDebug) {
240
+        		echo "Connect to pirepsjson source (".$host.")...\n";
241
+        	}
187 242
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
188 243
         	//$formats[$id] = 'fr24json';
189 244
         	$globalSources[$id]['format'] = 'fr24json';
190 245
         	//$last_exec['fr24json'] = 0;
191
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
246
+        	if ($globalDebug) {
247
+        		echo "Connect to fr24 source (".$host.")...\n";
248
+        	}
192 249
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
193 250
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
194 251
         	    exit(0);
@@ -197,7 +254,9 @@  discard block
 block discarded – undo
197 254
         	//$formats[$id] = 'fr24json';
198 255
         	$globalSources[$id]['format'] = 'myshiptracking';
199 256
         	//$last_exec['fr24json'] = 0;
200
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
257
+        	if ($globalDebug) {
258
+        		echo "Connect to myshiptracking source (".$host.")...\n";
259
+        	}
201 260
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
202 261
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
203 262
         	    exit(0);
@@ -206,17 +265,24 @@  discard block
 block discarded – undo
206 265
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
207 266
         	//$formats[$id] = 'tsv';
208 267
         	$globalSources[$id]['format'] = 'tsv';
209
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
268
+        	if ($globalDebug) {
269
+        		echo "Connect to tsv source (".$host.")...\n";
270
+        	}
210 271
             }
211 272
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
212 273
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
213 274
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
214 275
     		    if ($idf !== false) {
215 276
     			$httpfeeds[$id] = $idf;
216
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
277
+        		if ($globalDebug) {
278
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
279
+        		}
280
+    		    } elseif ($globalDebug) {
281
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
217 282
     		    }
218
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
219
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
283
+    		} elseif ($globalDebug) {
284
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
285
+    		}
220 286
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
221 287
 	    $hostport = explode(':',$host);
222 288
 	    if (isset($hostport[1])) {
@@ -256,17 +322,25 @@  discard block
 block discarded – undo
256 322
         		//$formats[$id] = 'beast';
257 323
         		$globalSources[$id]['format'] = 'beast';
258 324
 		    //} else $formats[$id] = 'sbs';
259
-		    } else $globalSources[$id]['format'] = 'sbs';
325
+		    } else {
326
+		    	$globalSources[$id]['format'] = 'sbs';
327
+		    }
260 328
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
261 329
 		}
262
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
330
+		if ($globalDebug) {
331
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
332
+		}
263 333
             } else {
264
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
334
+		if ($globalDebug) {
335
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
336
+		}
265 337
     	    }
266 338
         }
267 339
     }
268 340
 }
269
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
341
+if (!isset($globalMinFetch)) {
342
+	$globalMinFetch = 15;
343
+}
270 344
 
271 345
 // Initialize all
272 346
 $status = array();
@@ -275,13 +349,19 @@  discard block
 block discarded – undo
275 349
 $formats = array();
276 350
 $last_exec = array();
277 351
 $time = time();
278
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
279
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
280
-else $timeout = 20;
352
+if (isset($globalSourcesTimeout)) {
353
+	$timeout = $globalSourcesTimeOut;
354
+} else if (isset($globalSBS1TimeOut)) {
355
+	$timeout = $globalSBS1TimeOut;
356
+} else {
357
+	$timeout = 20;
358
+}
281 359
 $errno = '';
282 360
 $errstr='';
283 361
 
284
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
362
+if (!isset($globalDaemon)) {
363
+	$globalDaemon = TRUE;
364
+}
285 365
 /* Initiate connections to all the hosts simultaneously */
286 366
 //connect_all($hosts);
287 367
 //connect_all($globalSources);
@@ -310,7 +390,9 @@  discard block
 block discarded – undo
310 390
     if (isset($source['format']) && $source['format'] == 'aprs') {
311 391
 	$aprs_connect = 0;
312 392
 	$use_aprs = true;
313
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
393
+	if (isset($source['port']) && $source['port'] == '10152') {
394
+		$aprs_full = true;
395
+	}
314 396
 	break;
315 397
     }
316 398
 }
@@ -321,25 +403,48 @@  discard block
 block discarded – undo
321 403
 	$aprs_connect = 0;
322 404
 	$aprs_keep = 120;
323 405
 	$aprs_last_tx = time();
324
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
325
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
326
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
327
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
328
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
329
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
330
-	if ($aprs_full) $aprs_filter = '';
331
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
332
-	else $aprs_pass = '-1';
406
+	if (isset($globalAPRSversion)) {
407
+		$aprs_version = $globalAPRSversion;
408
+	} else {
409
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
410
+	}
411
+	if (isset($globalAPRSssid)) {
412
+		$aprs_ssid = $globalAPRSssid;
413
+	} else {
414
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
415
+	}
416
+	if (isset($globalAPRSfilter)) {
417
+		$aprs_filter = $globalAPRSfilter;
418
+	} else {
419
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
420
+	}
421
+	if ($aprs_full) {
422
+		$aprs_filter = '';
423
+	}
424
+	if (isset($globalAPRSpass)) {
425
+		$aprs_pass = $globalAPRSpass;
426
+	} else {
427
+		$aprs_pass = '-1';
428
+	}
333 429
 
334
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
335
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
336
-}
430
+	if ($aprs_filter != '') {
431
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
432
+	} else {
433
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
434
+	}
435
+	}
337 436
 
338 437
 // connected - lets do some work
339
-if ($globalDebug) echo "Connected!\n";
438
+if ($globalDebug) {
439
+	echo "Connected!\n";
440
+}
340 441
 sleep(1);
341
-if ($globalDebug) echo "SCAN MODE \n\n";
342
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
442
+if ($globalDebug) {
443
+	echo "SCAN MODE \n\n";
444
+}
445
+if (!isset($globalCronEnd)) {
446
+	$globalCronEnd = 60;
447
+}
343 448
 $endtime = time()+$globalCronEnd;
344 449
 $i = 1;
345 450
 $tt = array();
@@ -353,20 +458,28 @@  discard block
 block discarded – undo
353 458
 
354 459
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
355 460
 while ($i > 0) {
356
-    if (!$globalDaemon) $i = $endtime-time();
461
+    if (!$globalDaemon) {
462
+    	$i = $endtime-time();
463
+    }
357 464
     // Delete old ATC
358 465
     if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
359
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
466
+	if ($globalDebug) {
467
+		echo 'Delete old ATC...'."\n";
468
+	}
360 469
         $ATC->deleteOldATC();
361 470
     }
362 471
     
363 472
     if (count($last_exec) == count($globalSources)) {
364 473
 	$max = $globalMinFetch;
365 474
 	foreach ($last_exec as $last) {
366
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
475
+	    if ((time() - $last['last']) < $max) {
476
+	    	$max = time() - $last['last'];
477
+	    }
367 478
 	}
368 479
 	if ($max != $globalMinFetch) {
369
-	    if ($globalDebug) echo 'Sleeping...'."\n";
480
+	    if ($globalDebug) {
481
+	    	echo 'Sleeping...'."\n";
482
+	    }
370 483
 	    sleep($globalMinFetch-$max+2);
371 484
 	}
372 485
     }
@@ -375,11 +488,15 @@  discard block
 block discarded – undo
375 488
     //foreach ($formats as $id => $value) {
376 489
     foreach ($globalSources as $id => $value) {
377 490
 	date_default_timezone_set('UTC');
378
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
491
+	if (!isset($last_exec[$id]['last'])) {
492
+		$last_exec[$id]['last'] = 0;
493
+	}
379 494
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
380 495
 	    //$buffer = $Common->getData($hosts[$id]);
381 496
 	    $buffer = $Common->getData($value['host']);
382
-	    if ($buffer != '') $reset = 0;
497
+	    if ($buffer != '') {
498
+	    	$reset = 0;
499
+	    }
383 500
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
384 501
 	    $buffer = explode('\n',$buffer);
385 502
 	    foreach ($buffer as $line) {
@@ -388,20 +505,41 @@  discard block
 block discarded – undo
388 505
 	            $data = array();
389 506
 	            $data['hex'] = $line[1]; // hex
390 507
 	            $data['ident'] = $line[2]; // ident
391
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
392
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
393
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
394
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
395
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
508
+	            if (isset($line[3])) {
509
+	            	$data['altitude'] = $line[3];
510
+	            }
511
+	            // altitude
512
+	            if (isset($line[4])) {
513
+	            	$data['speed'] = $line[4];
514
+	            }
515
+	            // speed
516
+	            if (isset($line[5])) {
517
+	            	$data['heading'] = $line[5];
518
+	            }
519
+	            // heading
520
+	            if (isset($line[6])) {
521
+	            	$data['latitude'] = $line[6];
522
+	            }
523
+	            // lat
524
+	            if (isset($line[7])) {
525
+	            	$data['longitude'] = $line[7];
526
+	            }
527
+	            // long
396 528
 	            $data['verticalrate'] = ''; // vertical rate
397 529
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
398 530
 	            $data['emergency'] = ''; // emergency
399 531
 		    $data['datetime'] = date('Y-m-d H:i:s');
400 532
 		    $data['format_source'] = 'deltadbtxt';
401 533
     		    $data['id_source'] = $id_source;
402
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
403
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
404
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
534
+		    if (isset($value['name']) && $value['name'] != '') {
535
+		    	$data['source_name'] = $value['name'];
536
+		    }
537
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
538
+		    	$data['noarchive'] = true;
539
+		    }
540
+		    if (isset($value['sourcestats'])) {
541
+		    	$data['sourcestats'] = $value['sourcestats'];
542
+		    }
405 543
     		    $SI->add($data);
406 544
 		    unset($data);
407 545
     		}
@@ -411,7 +549,9 @@  discard block
 block discarded – undo
411 549
 	    date_default_timezone_set('CET');
412 550
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
413 551
 	    date_default_timezone_set('UTC');
414
-	    if ($buffer != '') $reset = 0;
552
+	    if ($buffer != '') {
553
+	    	$reset = 0;
554
+	    }
415 555
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
416 556
 	    $buffer = explode('\n',$buffer);
417 557
 	    foreach ($buffer as $line) {
@@ -420,16 +560,36 @@  discard block
 block discarded – undo
420 560
 		    $add = false;
421 561
 		    $ais_data = $AIS->parse_line(trim($line));
422 562
 		    $data = array();
423
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
424
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
425
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
426
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
427
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
428
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
429
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
430
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
431
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
432
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
563
+		    if (isset($ais_data['ident'])) {
564
+		    	$data['ident'] = $ais_data['ident'];
565
+		    }
566
+		    if (isset($ais_data['mmsi'])) {
567
+		    	$data['mmsi'] = $ais_data['mmsi'];
568
+		    }
569
+		    if (isset($ais_data['speed'])) {
570
+		    	$data['speed'] = $ais_data['speed'];
571
+		    }
572
+		    if (isset($ais_data['heading'])) {
573
+		    	$data['heading'] = $ais_data['heading'];
574
+		    }
575
+		    if (isset($ais_data['latitude'])) {
576
+		    	$data['latitude'] = $ais_data['latitude'];
577
+		    }
578
+		    if (isset($ais_data['longitude'])) {
579
+		    	$data['longitude'] = $ais_data['longitude'];
580
+		    }
581
+		    if (isset($ais_data['status'])) {
582
+		    	$data['status'] = $ais_data['status'];
583
+		    }
584
+		    if (isset($ais_data['type'])) {
585
+		    	$data['type'] = $ais_data['type'];
586
+		    }
587
+		    if (isset($ais_data['imo'])) {
588
+		    	$data['imo'] = $ais_data['imo'];
589
+		    }
590
+		    if (isset($ais_data['callsign'])) {
591
+		    	$data['callsign'] = $ais_data['callsign'];
592
+		    }
433 593
 		    if (isset($ais_data['timestamp'])) {
434 594
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
435 595
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -443,8 +603,12 @@  discard block
 block discarded – undo
443 603
 		    $data['format_source'] = 'aisnmeatxt';
444 604
     		    $data['id_source'] = $id_source;
445 605
 		    //print_r($data);
446
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
447
-		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
606
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
607
+		    	$data['noarchive'] = true;
608
+		    }
609
+		    if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
610
+		    	$MI->add($data);
611
+		    }
448 612
 		    unset($data);
449 613
 		}
450 614
     	    }
@@ -464,20 +628,48 @@  discard block
 block discarded – undo
464 628
 			    if ($line != '') {
465 629
 				$ais_data = $AIS->parse_line(trim($line));
466 630
 				$data = array();
467
-				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
468
-				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
469
-				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
470
-				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
471
-				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
472
-				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
473
-				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
474
-				if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
475
-				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
476
-				if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid'];
477
-				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
478
-				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
479
-				if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
480
-				if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
631
+				if (isset($ais_data['ident'])) {
632
+					$data['ident'] = $ais_data['ident'];
633
+				}
634
+				if (isset($ais_data['mmsi'])) {
635
+					$data['mmsi'] = $ais_data['mmsi'];
636
+				}
637
+				if (isset($ais_data['speed'])) {
638
+					$data['speed'] = $ais_data['speed'];
639
+				}
640
+				if (isset($ais_data['heading'])) {
641
+					$data['heading'] = $ais_data['heading'];
642
+				}
643
+				if (isset($ais_data['latitude'])) {
644
+					$data['latitude'] = $ais_data['latitude'];
645
+				}
646
+				if (isset($ais_data['longitude'])) {
647
+					$data['longitude'] = $ais_data['longitude'];
648
+				}
649
+				if (isset($ais_data['status'])) {
650
+					$data['status'] = $ais_data['status'];
651
+				}
652
+				if (isset($ais_data['statusid'])) {
653
+					$data['status_id'] = $ais_data['statusid'];
654
+				}
655
+				if (isset($ais_data['type'])) {
656
+					$data['type'] = $ais_data['type'];
657
+				}
658
+				if (isset($ais_data['typeid'])) {
659
+					$data['type_id'] = $ais_data['typeid'];
660
+				}
661
+				if (isset($ais_data['imo'])) {
662
+					$data['imo'] = $ais_data['imo'];
663
+				}
664
+				if (isset($ais_data['callsign'])) {
665
+					$data['callsign'] = $ais_data['callsign'];
666
+				}
667
+				if (isset($ais_data['destination'])) {
668
+					$data['arrival_code'] = $ais_data['destination'];
669
+				}
670
+				if (isset($ais_data['eta_ts'])) {
671
+					$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
672
+				}
481 673
 				if (isset($ais_data['timestamp'])) {
482 674
 				    $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
483 675
 				} else {
@@ -485,18 +677,27 @@  discard block
 block discarded – undo
485 677
 				}
486 678
 				$data['format_source'] = 'aisnmeahttp';
487 679
 				$data['id_source'] = $id_source;
488
-				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
489
-				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
680
+				if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
681
+					$data['noarchive'] = true;
682
+				}
683
+				if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
684
+					$MI->add($data);
685
+				}
490 686
 				unset($data);
491 687
 			    }
492 688
 			}
493 689
 		    }
494 690
 		} else {
495 691
 		    $format = $value['format'];
496
-		    if (isset($tt[$format])) $tt[$format]++;
497
-		    else $tt[$format] = 0;
692
+		    if (isset($tt[$format])) {
693
+		    	$tt[$format]++;
694
+		    } else {
695
+		    	$tt[$format] = 0;
696
+		    }
498 697
 		    if ($tt[$format] > 30) {
499
-			if ($globalDebug) echo 'Reconnect...'."\n";
698
+			if ($globalDebug) {
699
+				echo 'Reconnect...'."\n";
700
+			}
500 701
 			sleep(2);
501 702
 			$sourceeen[] = $value;
502 703
 			connect_all($sourceeen);
@@ -526,7 +727,9 @@  discard block
 block discarded – undo
526 727
 			    $data['datetime'] = date('Y-m-d H:i:s',$line['T']);
527 728
 			    $data['format_source'] = 'myshiptracking';
528 729
 			    $data['id_source'] = $id_source;
529
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
730
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
731
+			    	$data['noarchive'] = true;
732
+			    }
530 733
 			    $MI->add($data);
531 734
 			    unset($data);
532 735
 			}
@@ -546,7 +749,9 @@  discard block
 block discarded – undo
546 749
 			    $data['callsign'] = $line['callsign'];
547 750
 			    $data['mmsi'] = $line['mmsi'];
548 751
 			    $data['speed'] = $line['sog'];
549
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
752
+			    if ($line['heading'] != '511') {
753
+			    	$data['heading'] = $line['heading'];
754
+			    }
550 755
 			    $data['latitude'] = $line['latitude'];
551 756
 			    $data['longitude'] = $line['longitude'];
552 757
 			    $data['type_id'] = $line['shiptype'];
@@ -554,7 +759,9 @@  discard block
 block discarded – undo
554 759
 			    $data['datetime'] = $line['time'];
555 760
 			    $data['format_source'] = 'boatbeaconapp';
556 761
 			    $data['id_source'] = $id_source;
557
-			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
762
+			    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
763
+			    	$data['noarchive'] = true;
764
+			    }
558 765
 			    $MI->add($data);
559 766
 			    unset($data);
560 767
 			}
@@ -570,22 +777,44 @@  discard block
 block discarded – undo
570 777
 		if (isset($all_data['features'][0]['id'])) {
571 778
 		    foreach ($all_data['features'] as $line) {
572 779
 			$data = array();
573
-			if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name'];
574
-			if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign'];
575
-			if (isset($line['properties']['mmsi'])) $data['mmsi'] = $line['properties']['mmsi'];
576
-			if (isset($line['properties']['imo'])) $data['mmsi'] = $line['properties']['imo'];
577
-			if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed'];
578
-			if (isset($line['properties']['heading'])) $data['heading'] = $line['properties']['heading'];
780
+			if (isset($line['properties']['name'])) {
781
+				$data['ident'] = $line['properties']['name'];
782
+			}
783
+			if (isset($line['properties']['callsign'])) {
784
+				$data['callsign'] = $line['properties']['callsign'];
785
+			}
786
+			if (isset($line['properties']['mmsi'])) {
787
+				$data['mmsi'] = $line['properties']['mmsi'];
788
+			}
789
+			if (isset($line['properties']['imo'])) {
790
+				$data['mmsi'] = $line['properties']['imo'];
791
+			}
792
+			if (isset($line['properties']['speed'])) {
793
+				$data['speed'] = $line['properties']['speed'];
794
+			}
795
+			if (isset($line['properties']['heading'])) {
796
+				$data['heading'] = $line['properties']['heading'];
797
+			}
579 798
 			$data['latitude'] = $line['geometry']['coordinates'][1];
580 799
 			$data['longitude'] = $line['geometry']['coordinates'][0];
581
-			if (isset($line['properties']['vesselType'])) $data['type'] = $line['properties']['vesselType'];
582
-			if (isset($line['properties']['destination'])) $data['arrival_code'] = $line['properties']['destination'];
583
-			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') $data['arrival_date'] = $line['properties']['eta'];
800
+			if (isset($line['properties']['vesselType'])) {
801
+				$data['type'] = $line['properties']['vesselType'];
802
+			}
803
+			if (isset($line['properties']['destination'])) {
804
+				$data['arrival_code'] = $line['properties']['destination'];
805
+			}
806
+			if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') {
807
+				$data['arrival_date'] = $line['properties']['eta'];
808
+			}
584 809
 			$data['format_source'] = 'boatnerd';
585 810
 			$data['id_source'] = $id_source;
586 811
 			$data['datetime'] = date('Y-m-d H:i:s');
587
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
588
-			if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data);
812
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
813
+				$data['noarchive'] = true;
814
+			}
815
+			if ($line['properties']['vesselType'] != 'Navigation Aid') {
816
+				$MI->add($data);
817
+			}
589 818
 			unset($data);
590 819
 		    }
591 820
 		}
@@ -596,7 +825,9 @@  discard block
 block discarded – undo
596 825
 	    echo 'download...';
597 826
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
598 827
 	    echo 'done !'."\n";
599
-	    if ($buffer != '') $reset = 0;
828
+	    if ($buffer != '') {
829
+	    	$reset = 0;
830
+	    }
600 831
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
601 832
 	    $buffer = explode('\n',$buffer);
602 833
 	    foreach ($buffer as $line) {
@@ -621,7 +852,9 @@  discard block
 block discarded – undo
621 852
 		    //$data['etaTime'] = substr($line,135,5);
622 853
 		    $data['format_source'] = 'shipplotter';
623 854
     		    $data['id_source'] = $id_source;
624
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
855
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
856
+		    	$data['noarchive'] = true;
857
+		    }
625 858
 		    //print_r($data);
626 859
 		    echo 'Add...'."\n";
627 860
 		    $MI->add($data);
@@ -641,16 +874,28 @@  discard block
 block discarded – undo
641 874
     		    $line = explode(':', $line);
642 875
     		    if (count($line) > 30 && $line[0] != 'callsign') {
643 876
 			$data = array();
644
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
645
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
877
+			if (isset($line[37]) && $line[37] != '') {
878
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
879
+			} else {
880
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
881
+			}
646 882
 			$data['pilot_id'] = $line[1];
647 883
 			$data['pilot_name'] = $line[2];
648 884
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
649 885
 			$data['ident'] = $line[0]; // ident
650
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
886
+			if ($line[7] != '' && $line[7] != 0) {
887
+				$data['altitude'] = $line[7];
888
+			}
889
+			// altitude
651 890
 			$data['speed'] = $line[8]; // speed
652
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
653
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
891
+			if (isset($line[45])) {
892
+				$data['heading'] = $line[45];
893
+			}
894
+			// heading
895
+			elseif (isset($line[38])) {
896
+				$data['heading'] = $line[38];
897
+			}
898
+			// heading
654 899
 			$data['latitude'] = $line[5]; // lat
655 900
 	        	$data['longitude'] = $line[6]; // long
656 901
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -666,7 +911,9 @@  discard block
 block discarded – undo
666 911
 			$data['frequency'] = $line[4];
667 912
 			$data['type'] = $line[18];
668 913
 			$data['range'] = $line[19];
669
-			if (isset($line[35])) $data['info'] = $line[35];
914
+			if (isset($line[35])) {
915
+				$data['info'] = $line[35];
916
+			}
670 917
     			$data['id_source'] = $id_source;
671 918
 	    		//$data['arrival_airport_time'] = ;
672 919
 	    		if ($line[9] != '') {
@@ -680,27 +927,47 @@  discard block
 block discarded – undo
680 927
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
681 928
 	    		*/
682 929
 	    		$data['format_source'] = $value['format'];
683
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
684
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
685
-    			if ($line[3] == 'PILOT') $SI->add($data);
686
-			elseif ($line[3] == 'ATC') {
930
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
931
+				$data['noarchive'] = true;
932
+			}
933
+			if (isset($value['name']) && $value['name'] != '') {
934
+				$data['source_name'] = $value['name'];
935
+			}
936
+    			if ($line[3] == 'PILOT') {
937
+    				$SI->add($data);
938
+    			} elseif ($line[3] == 'ATC') {
687 939
 				//print_r($data);
688 940
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
689 941
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
690 942
 				$typec = substr($data['ident'],-3);
691
-				if ($typec == 'APP') $data['type'] = 'Approach';
692
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
693
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
694
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
695
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
696
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
697
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
698
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
699
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
700
-				if (!isset($data['source_name'])) $data['source_name'] = '';
943
+				if ($typec == 'APP') {
944
+					$data['type'] = 'Approach';
945
+				} elseif ($typec == 'TWR') {
946
+					$data['type'] = 'Tower';
947
+				} elseif ($typec == 'OBS') {
948
+					$data['type'] = 'Observer';
949
+				} elseif ($typec == 'GND') {
950
+					$data['type'] = 'Ground';
951
+				} elseif ($typec == 'DEL') {
952
+					$data['type'] = 'Delivery';
953
+				} elseif ($typec == 'DEP') {
954
+					$data['type'] = 'Departure';
955
+				} elseif ($typec == 'FSS') {
956
+					$data['type'] = 'Flight Service Station';
957
+				} elseif ($typec == 'CTR') {
958
+					$data['type'] = 'Control Radar or Centre';
959
+				} elseif ($data['type'] == '') {
960
+					$data['type'] = 'Observer';
961
+				}
962
+				if (!isset($data['source_name'])) {
963
+					$data['source_name'] = '';
964
+				}
701 965
 				if (isset($ATC)) {
702
-					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) echo $ATC->update($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
703
-					else echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
966
+					if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) {
967
+						echo $ATC->update($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
968
+					} else {
969
+						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']);
970
+					}
704 971
 				}
705 972
 			}
706 973
     			unset($data);
@@ -722,14 +989,20 @@  discard block
 block discarded – undo
722 989
 			$data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST'));
723 990
 			$data['latitude'] = (float)$line['pktLatitude'];
724 991
 			$data['longitude'] = (float)$line['pktLongitude'];
725
-			if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack'];
726
-			if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed'];
992
+			if ((float)$line['pktTrack'] != 0) {
993
+				$data['heading'] = (float)$line['pktTrack'];
994
+			}
995
+			if ((int)$line['pktSpeed'] != 0) {
996
+				$data['speed'] = (int)$line['pktSpeed'];
997
+			}
727 998
 			$data['altitude'] = round((int)$line['pktAltitude']*3.28084);
728 999
 			$data['altitude_relative'] = 'AMSL';
729 1000
 			$data['pilot_id'] = (int)$line['pktPilotID'];
730 1001
 			$data['aircraft_icao'] = 'PARAGLIDER';
731 1002
 			$pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id']));
732
-			if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4];
1003
+			if (isset($pilot_data[4])) {
1004
+				$data['pilot_name'] = $pilot_data[4];
1005
+			}
733 1006
 			$data['format_source'] = $value['format'];
734 1007
 			$SI->add($data);
735 1008
 			unset($data);
@@ -766,27 +1039,61 @@  discard block
 block discarded – undo
766 1039
 		foreach ($all_data['acList'] as $line) {
767 1040
 		    $data = array();
768 1041
 		    $data['hex'] = $line['Icao']; // hex
769
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
770
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
771
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
772
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
773
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
774
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1042
+		    if (isset($line['Call'])) {
1043
+		    	$data['ident'] = $line['Call'];
1044
+		    }
1045
+		    // ident
1046
+		    if (isset($line['Alt'])) {
1047
+		    	$data['altitude'] = $line['Alt'];
1048
+		    }
1049
+		    // altitude
1050
+		    if (isset($line['Spd'])) {
1051
+		    	$data['speed'] = $line['Spd'];
1052
+		    }
1053
+		    // speed
1054
+		    if (isset($line['Trak'])) {
1055
+		    	$data['heading'] = $line['Trak'];
1056
+		    }
1057
+		    // heading
1058
+		    if (isset($line['Lat'])) {
1059
+		    	$data['latitude'] = $line['Lat'];
1060
+		    }
1061
+		    // lat
1062
+		    if (isset($line['Long'])) {
1063
+		    	$data['longitude'] = $line['Long'];
1064
+		    }
1065
+		    // long
775 1066
 		    //$data['verticalrate'] = $line['']; // verticale rate
776
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1067
+		    if (isset($line['Sqk'])) {
1068
+		    	$data['squawk'] = $line['Sqk'];
1069
+		    }
1070
+		    // squawk
777 1071
 		    $data['emergency'] = ''; // emergency
778
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
1072
+		    if (isset($line['Reg'])) {
1073
+		    	$data['registration'] = $line['Reg'];
1074
+		    }
779 1075
 		    
780
-		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
781
-		    else $data['datetime'] = date('Y-m-d H:i:s');
1076
+		    if (isset($line['PosTime'])) {
1077
+		    	$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1078
+		    } else {
1079
+		    	$data['datetime'] = date('Y-m-d H:i:s');
1080
+		    }
782 1081
 		    
783 1082
 		    //$data['datetime'] = date('Y-m-d H:i:s');
784
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1083
+		    if (isset($line['Type'])) {
1084
+		    	$data['aircraft_icao'] = $line['Type'];
1085
+		    }
785 1086
 	    	    $data['format_source'] = 'aircraftlistjson';
786 1087
 		    $data['id_source'] = $id_source;
787
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
788
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
789
-		    if (isset($data['latitude'])) $SI->add($data);
1088
+		    if (isset($value['name']) && $value['name'] != '') {
1089
+		    	$data['source_name'] = $value['name'];
1090
+		    }
1091
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1092
+		    	$data['noarchive'] = true;
1093
+		    }
1094
+		    if (isset($data['latitude'])) {
1095
+		    	$SI->add($data);
1096
+		    }
790 1097
 		    unset($data);
791 1098
 		}
792 1099
 	    } elseif (is_array($all_data)) {
@@ -803,12 +1110,19 @@  discard block
 block discarded – undo
803 1110
 		    $data['verticalrate'] = $line['vrt']; // verticale rate
804 1111
 		    $data['squawk'] = $line['squawk']; // squawk
805 1112
 		    $data['emergency'] = ''; // emergency
806
-		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
807
-		    else $data['datetime'] = date('Y-m-d H:i:s');
1113
+		    if (isset($line['PosTime'])) {
1114
+		    	$data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000));
1115
+		    } else {
1116
+		    	$data['datetime'] = date('Y-m-d H:i:s');
1117
+		    }
808 1118
 	    	    $data['format_source'] = 'aircraftlistjson';
809 1119
     		    $data['id_source'] = $id_source;
810
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
811
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1120
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1121
+		    	$data['noarchive'] = true;
1122
+		    }
1123
+		    if (isset($value['name']) && $value['name'] != '') {
1124
+		    	$data['source_name'] = $value['name'];
1125
+		    }
812 1126
 		    $SI->add($data);
813 1127
 		    unset($data);
814 1128
 		}
@@ -844,8 +1158,12 @@  discard block
 block discarded – undo
844 1158
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
845 1159
 	    	    $data['format_source'] = 'planeupdatefaa';
846 1160
     		    $data['id_source'] = $id_source;
847
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
848
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1161
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1162
+		    	$data['noarchive'] = true;
1163
+		    }
1164
+		    if (isset($value['name']) && $value['name'] != '') {
1165
+		    	$data['source_name'] = $value['name'];
1166
+		    }
849 1167
 		    $SI->add($data);
850 1168
 		    unset($data);
851 1169
 		}
@@ -874,7 +1192,9 @@  discard block
 block discarded – undo
874 1192
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
875 1193
 	    	    $data['format_source'] = 'opensky';
876 1194
     		    $data['id_source'] = $id_source;
877
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1195
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1196
+		    	$data['noarchive'] = true;
1197
+		    }
878 1198
 		    $SI->add($data);
879 1199
 		    unset($data);
880 1200
 		}
@@ -886,7 +1206,9 @@  discard block
 block discarded – undo
886 1206
 	    //$buffer = $Common->getData($hosts[$id]);
887 1207
 	    $buffer = $Common->getData($value['host']);
888 1208
 	    $all_data = json_decode($buffer,true);
889
-	    if (!empty($all_data)) $reset = 0;
1209
+	    if (!empty($all_data)) {
1210
+	    	$reset = 0;
1211
+	    }
890 1212
 	    foreach ($all_data as $key => $line) {
891 1213
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
892 1214
 		    $data = array();
@@ -907,8 +1229,12 @@  discard block
 block discarded – undo
907 1229
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
908 1230
 	    	    $data['format_source'] = 'fr24json';
909 1231
     		    $data['id_source'] = $id_source;
910
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
911
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1232
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1233
+		    	$data['noarchive'] = true;
1234
+		    }
1235
+		    if (isset($value['name']) && $value['name'] != '') {
1236
+		    	$data['source_name'] = $value['name'];
1237
+		    }
912 1238
 		    $SI->add($data);
913 1239
 		    unset($data);
914 1240
 		}
@@ -932,24 +1258,42 @@  discard block
 block discarded – undo
932 1258
 		    if (isset($line['inf'])) {
933 1259
 			$data = array();
934 1260
 			$data['hex'] = $line['inf']['ia'];
935
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1261
+			if (isset($line['inf']['cs'])) {
1262
+				$data['ident'] = $line['inf']['cs'];
1263
+			}
1264
+			//$line[13]
936 1265
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
937
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
938
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1266
+	    		if (isset($line['inf']['gs'])) {
1267
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1268
+	    		}
1269
+	    		// speed
1270
+	    		if (isset($line['inf']['tr'])) {
1271
+	    			$data['heading'] = $line['inf']['tr'];
1272
+	    		}
1273
+	    		// heading
939 1274
 	    		$data['latitude'] = $line['pt'][0]; // lat
940 1275
 	    		$data['longitude'] = $line['pt'][1]; // long
941 1276
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
942
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1277
+	    		if (isset($line['inf']['sq'])) {
1278
+	    			$data['squawk'] = $line['inf']['sq'];
1279
+	    		}
1280
+	    		// squawk
943 1281
 	    		//$data['aircraft_icao'] = $line[8];
944
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1282
+	    		if (isset($line['inf']['rc'])) {
1283
+	    			$data['registration'] = $line['inf']['rc'];
1284
+	    		}
945 1285
 			//$data['departure_airport_iata'] = $line[11];
946 1286
 			//$data['arrival_airport_iata'] = $line[12];
947 1287
 	    		//$data['emergency'] = ''; // emergency
948 1288
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
949 1289
 	    		$data['format_source'] = 'radarvirtueljson';
950 1290
     			$data['id_source'] = $id_source;
951
-			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
952
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1291
+			if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1292
+				$data['noarchive'] = true;
1293
+			}
1294
+			if (isset($value['name']) && $value['name'] != '') {
1295
+				$data['source_name'] = $value['name'];
1296
+			}
953 1297
 			$SI->add($data);
954 1298
 			unset($data);
955 1299
 		    }
@@ -970,30 +1314,65 @@  discard block
 block discarded – undo
970 1314
 		    $data['id'] = $line['id'];
971 1315
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
972 1316
 		    $data['ident'] = $line['callsign']; // ident
973
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
974
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
975
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
976
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
977
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
978
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1317
+		    if (isset($line['pilotid'])) {
1318
+		    	$data['pilot_id'] = $line['pilotid'];
1319
+		    }
1320
+		    // pilot id
1321
+		    if (isset($line['name'])) {
1322
+		    	$data['pilot_name'] = $line['name'];
1323
+		    }
1324
+		    // pilot name
1325
+		    if (isset($line['alt'])) {
1326
+		    	$data['altitude'] = $line['alt'];
1327
+		    }
1328
+		    // altitude
1329
+		    if (isset($line['gs'])) {
1330
+		    	$data['speed'] = $line['gs'];
1331
+		    }
1332
+		    // speed
1333
+		    if (isset($line['heading'])) {
1334
+		    	$data['heading'] = $line['heading'];
1335
+		    }
1336
+		    // heading
1337
+		    if (isset($line['route'])) {
1338
+		    	$data['waypoints'] = $line['route'];
1339
+		    }
1340
+		    // route
979 1341
 		    $data['latitude'] = $line['lat']; // lat
980 1342
 		    $data['longitude'] = $line['lon']; // long
981 1343
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
982 1344
 		    //$data['squawk'] = $line['squawk']; // squawk
983 1345
 		    //$data['emergency'] = ''; // emergency
984
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
985
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
986
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1346
+		    if (isset($line['depicao'])) {
1347
+		    	$data['departure_airport_icao'] = $line['depicao'];
1348
+		    }
1349
+		    if (isset($line['deptime'])) {
1350
+		    	$data['departure_airport_time'] = $line['deptime'];
1351
+		    }
1352
+		    if (isset($line['arricao'])) {
1353
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1354
+		    }
987 1355
 		    //$data['arrival_airport_time'] = $line['arrtime'];
988
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
989
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
990
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
991
-		    else $data['info'] = '';
1356
+		    if (isset($line['aircraft'])) {
1357
+		    	$data['aircraft_icao'] = $line['aircraft'];
1358
+		    }
1359
+		    if (isset($line['transponder'])) {
1360
+		    	$data['squawk'] = $line['transponder'];
1361
+		    }
1362
+		    if (isset($line['atis'])) {
1363
+		    	$data['info'] = $line['atis'];
1364
+		    } else {
1365
+		    	$data['info'] = '';
1366
+		    }
992 1367
 		    $data['format_source'] = 'pireps';
993 1368
     		    $data['id_source'] = $id_source;
994 1369
 		    $data['datetime'] = date('Y-m-d H:i:s');
995
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
996
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1370
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1371
+		    	$data['noarchive'] = true;
1372
+		    }
1373
+		    if (isset($value['name']) && $value['name'] != '') {
1374
+		    	$data['source_name'] = $value['name'];
1375
+		    }
997 1376
 		    if ($line['icon'] == 'plane') {
998 1377
 			$SI->add($data);
999 1378
 		    //    print_r($data);
@@ -1002,16 +1381,28 @@  discard block
 block discarded – undo
1002 1381
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
1003 1382
 			$typec = substr($data['ident'],-3);
1004 1383
 			$data['type'] = '';
1005
-			if ($typec == 'APP') $data['type'] = 'Approach';
1006
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
1007
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
1008
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
1009
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
1010
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
1011
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
1012
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
1013
-			else $data['type'] = 'Observer';
1014
-			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']);
1384
+			if ($typec == 'APP') {
1385
+				$data['type'] = 'Approach';
1386
+			} elseif ($typec == 'TWR') {
1387
+				$data['type'] = 'Tower';
1388
+			} elseif ($typec == 'OBS') {
1389
+				$data['type'] = 'Observer';
1390
+			} elseif ($typec == 'GND') {
1391
+				$data['type'] = 'Ground';
1392
+			} elseif ($typec == 'DEL') {
1393
+				$data['type'] = 'Delivery';
1394
+			} elseif ($typec == 'DEP') {
1395
+				$data['type'] = 'Departure';
1396
+			} elseif ($typec == 'FSS') {
1397
+				$data['type'] = 'Flight Service Station';
1398
+			} elseif ($typec == 'CTR') {
1399
+				$data['type'] = 'Control Radar or Centre';
1400
+			} else {
1401
+				$data['type'] = 'Observer';
1402
+			}
1403
+			if (isset($ATC)) {
1404
+				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']);
1405
+			}
1015 1406
 		    }
1016 1407
 		    unset($data);
1017 1408
 		}
@@ -1021,7 +1412,9 @@  discard block
 block discarded – undo
1021 1412
     	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
1022 1413
     	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
1023 1414
 	    //$buffer = $Common->getData($hosts[$id]);
1024
-	    if ($globalDebug) echo 'Get Data...'."\n";
1415
+	    if ($globalDebug) {
1416
+	    	echo 'Get Data...'."\n";
1417
+	    }
1025 1418
 	    $buffer = $Common->getData($value['host']);
1026 1419
 	    $all_data = json_decode($buffer,true);
1027 1420
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1029,10 +1422,16 @@  discard block
 block discarded – undo
1029 1422
 		foreach ($all_data as $line) {
1030 1423
 	    	    $data = array();
1031 1424
 	    	    //$data['id'] = $line['id']; // id not usable
1032
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1425
+	    	    if (isset($line['pilotid'])) {
1426
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1427
+	    	    }
1033 1428
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
1034
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
1035
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1429
+	    	    if (isset($line['pilotname'])) {
1430
+	    	    	$data['pilot_name'] = $line['pilotname'];
1431
+	    	    }
1432
+	    	    if (isset($line['pilotid'])) {
1433
+	    	    	$data['pilot_id'] = $line['pilotid'];
1434
+	    	    }
1036 1435
 	    	    $data['ident'] = $line['flightnum']; // ident
1037 1436
 	    	    $data['altitude'] = $line['alt']; // altitude
1038 1437
 	    	    $data['speed'] = $line['gs']; // speed
@@ -1048,34 +1447,52 @@  discard block
 block discarded – undo
1048 1447
 	    		$datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone']));
1049 1448
 	    		$datetime->setTimeZone(new DateTimeZone('UTC'));
1050 1449
 	    		$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1051
-	    	    } else $data['datetime'] = date('Y-m-d H:i:s');
1450
+	    	    } else {
1451
+	    	    	$data['datetime'] = date('Y-m-d H:i:s');
1452
+	    	    }
1052 1453
 	    	    $data['departure_airport_icao'] = $line['depicao'];
1053 1454
 	    	    $data['departure_airport_time'] = $line['deptime'];
1054 1455
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
1055 1456
     		    $data['arrival_airport_time'] = $line['arrtime'];
1056 1457
     		    $data['registration'] = $line['aircraft'];
1057
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1058
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1458
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1459
+		    	$data['noarchive'] = true;
1460
+		    }
1461
+		    if (isset($line['route'])) {
1462
+		    	$data['waypoints'] = $line['route'];
1463
+		    }
1464
+		    // route
1059 1465
 		    if (isset($line['aircraftname'])) {
1060 1466
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
1061 1467
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
1062 1468
 	    		$aircraft_data = explode('-',$line['aircraftname']);
1063
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0];
1064
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1];
1065
-	    		else {
1469
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) {
1470
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1471
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) {
1472
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1473
+	    		} else {
1066 1474
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
1067
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1068
-	    		    else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1475
+	    		    if (isset($aircraft_data[1])) {
1476
+	    		    	$data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]);
1477
+	    		    } else {
1478
+	    		    	$data['aircraft_icao'] = str_replace('-','',$line['aircraftname']);
1479
+	    		    }
1069 1480
 	    		}
1070 1481
 	    	    }
1071
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1482
+    		    if (isset($line['route'])) {
1483
+    		    	$data['waypoints'] = $line['route'];
1484
+    		    }
1072 1485
     		    $data['id_source'] = $id_source;
1073 1486
 	    	    $data['format_source'] = 'phpvmacars';
1074
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1487
+		    if (isset($value['name']) && $value['name'] != '') {
1488
+		    	$data['source_name'] = $value['name'];
1489
+		    }
1075 1490
 		    $SI->add($data);
1076 1491
 		    unset($data);
1077 1492
 		}
1078
-		if ($globalDebug) echo 'No more data...'."\n";
1493
+		if ($globalDebug) {
1494
+			echo 'No more data...'."\n";
1495
+		}
1079 1496
 		unset($buffer);
1080 1497
 		unset($all_data);
1081 1498
 	    }
@@ -1083,7 +1500,9 @@  discard block
 block discarded – undo
1083 1500
     	    $last_exec[$id]['last'] = time();
1084 1501
     	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
1085 1502
 	    //$buffer = $Common->getData($hosts[$id]);
1086
-	    if ($globalDebug) echo 'Get Data...'."\n";
1503
+	    if ($globalDebug) {
1504
+	    	echo 'Get Data...'."\n";
1505
+	    }
1087 1506
 	    $buffer = $Common->getData($value['host']);
1088 1507
 	    $all_data = json_decode($buffer,true);
1089 1508
 	    if ($buffer != '' && is_array($all_data)) {
@@ -1112,16 +1531,25 @@  discard block
 block discarded – undo
1112 1531
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
1113 1532
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
1114 1533
     		    //$data['registration'] = $line['aircraft'];
1115
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1534
+		    if (isset($line['route'])) {
1535
+		    	$data['waypoints'] = $line['route'];
1536
+		    }
1537
+		    // route
1116 1538
 	    	    $data['aircraft_icao'] = $line['plane_type'];
1117 1539
     		    $data['id_source'] = $id_source;
1118 1540
 	    	    $data['format_source'] = 'vam';
1119
-		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true;
1120
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1541
+		    if (isset($value['noarchive']) && $value['noarchive'] === TRUE) {
1542
+		    	$data['noarchive'] = true;
1543
+		    }
1544
+		    if (isset($value['name']) && $value['name'] != '') {
1545
+		    	$data['source_name'] = $value['name'];
1546
+		    }
1121 1547
 		    $SI->add($data);
1122 1548
 		    unset($data);
1123 1549
 		}
1124
-		if ($globalDebug) echo 'No more data...'."\n";
1550
+		if ($globalDebug) {
1551
+			echo 'No more data...'."\n";
1552
+		}
1125 1553
 		unset($buffer);
1126 1554
 		unset($all_data);
1127 1555
 	    }
@@ -1129,7 +1557,9 @@  discard block
 block discarded – undo
1129 1557
     	    $last_exec[$id]['last'] = time();
1130 1558
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
1131 1559
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'famaprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais' || $value['format'] == 'vrstcp') {
1132
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1560
+	    if (function_exists('pcntl_fork')) {
1561
+	    	pcntl_signal_dispatch();
1562
+	    }
1133 1563
     	    //$last_exec[$id]['last'] = time();
1134 1564
 
1135 1565
 	    //$read = array( $sockets[$id] );
@@ -1137,7 +1567,9 @@  discard block
 block discarded – undo
1137 1567
 	    $write = NULL;
1138 1568
 	    $e = NULL;
1139 1569
 	    $n = socket_select($read, $write, $e, $timeout);
1140
-	    if ($e != NULL) var_dump($e);
1570
+	    if ($e != NULL) {
1571
+	    	var_dump($e);
1572
+	    }
1141 1573
 	    if ($n > 0) {
1142 1574
 		$reset = 0;
1143 1575
 		foreach ($read as $nb => $r) {
@@ -1158,12 +1590,16 @@  discard block
 block discarded – undo
1158 1590
 		    //$SI::del();
1159 1591
 		    if ($format == 'vrstcp') {
1160 1592
 			$buffer = explode('},{',$buffer);
1161
-		    } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1593
+		    } else {
1594
+		    	$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
1595
+		    }
1162 1596
 		    // SBS format is CSV format
1163 1597
 		    if ($buffer !== FALSE && $buffer != '') {
1164 1598
 			$tt[$format] = 0;
1165 1599
 			if ($format == 'acarssbs3') {
1166
-			    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1600
+			    if ($globalDebug) {
1601
+			    	echo 'ACARS : '.$buffer."\n";
1602
+			    }
1167 1603
 			    $ACARS->add(trim($buffer));
1168 1604
 			    $ACARS->deleteLiveAcarsData();
1169 1605
 			} elseif ($format == 'raw') {
@@ -1172,30 +1608,70 @@  discard block
 block discarded – undo
1172 1608
 			    if (is_array($data)) {
1173 1609
 				$data['datetime'] = date('Y-m-d H:i:s');
1174 1610
 				$data['format_source'] = 'raw';
1175
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1176
-				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1177
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1178
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1611
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1612
+					$data['source_name'] = $globalSources[$nb]['name'];
1613
+				}
1614
+				if (isset($globalSources[$nb]['sourcestats'])) {
1615
+					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1616
+				}
1617
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1618
+					$data['noarchive'] = true;
1619
+				}
1620
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1621
+					$SI->add($data);
1622
+				}
1179 1623
 			    }
1180 1624
 			} elseif ($format == 'ais') {
1181 1625
 			    $ais_data = $AIS->parse_line(trim($buffer));
1182 1626
 			    $data = array();
1183
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1184
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1185
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1186
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1187
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1188
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1189
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1190
-			    if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid'];
1191
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1192
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1193
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1194
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1195
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1196
-			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1197
-			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1198
-			    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1627
+			    if (isset($ais_data['ident'])) {
1628
+			    	$data['ident'] = $ais_data['ident'];
1629
+			    }
1630
+			    if (isset($ais_data['mmsi'])) {
1631
+			    	$data['mmsi'] = $ais_data['mmsi'];
1632
+			    }
1633
+			    if (isset($ais_data['speed'])) {
1634
+			    	$data['speed'] = $ais_data['speed'];
1635
+			    }
1636
+			    if (isset($ais_data['heading'])) {
1637
+			    	$data['heading'] = $ais_data['heading'];
1638
+			    }
1639
+			    if (isset($ais_data['latitude'])) {
1640
+			    	$data['latitude'] = $ais_data['latitude'];
1641
+			    }
1642
+			    if (isset($ais_data['longitude'])) {
1643
+			    	$data['longitude'] = $ais_data['longitude'];
1644
+			    }
1645
+			    if (isset($ais_data['status'])) {
1646
+			    	$data['status'] = $ais_data['status'];
1647
+			    }
1648
+			    if (isset($ais_data['statusid'])) {
1649
+			    	$data['status_id'] = $ais_data['statusid'];
1650
+			    }
1651
+			    if (isset($ais_data['type'])) {
1652
+			    	$data['type'] = $ais_data['type'];
1653
+			    }
1654
+			    if (isset($ais_data['imo'])) {
1655
+			    	$data['imo'] = $ais_data['imo'];
1656
+			    }
1657
+			    if (isset($ais_data['callsign'])) {
1658
+			    	$data['callsign'] = $ais_data['callsign'];
1659
+			    }
1660
+			    if (isset($ais_data['destination'])) {
1661
+			    	$data['arrival_code'] = $ais_data['destination'];
1662
+			    }
1663
+			    if (isset($ais_data['eta_ts'])) {
1664
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1665
+			    }
1666
+			    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1667
+			    	$data['noarchive'] = true;
1668
+			    }
1669
+			    if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1670
+			    	$data['source_name'] = $globalSources[$nb]['name'];
1671
+			    }
1672
+			    if (isset($globalSources[$nb]['sourcestats'])) {
1673
+			    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1674
+			    }
1199 1675
 
1200 1676
 			    if (isset($ais_data['timestamp'])) {
1201 1677
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1204,7 +1680,9 @@  discard block
 block discarded – undo
1204 1680
 			    }
1205 1681
 			    $data['format_source'] = 'aisnmea';
1206 1682
     			    $data['id_source'] = $id_source;
1207
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1683
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
1684
+			    	$MI->add($data);
1685
+			    }
1208 1686
 			    unset($data);
1209 1687
                         } elseif ($format == 'flightgearsp') {
1210 1688
                     	    //echo $buffer."\n";
@@ -1222,12 +1700,18 @@  discard block
 block discarded – undo
1222 1700
 				$data['speed'] = round($line[5]*1.94384);
1223 1701
 				$data['datetime'] = date('Y-m-d H:i:s');
1224 1702
 				$data['format_source'] = 'flightgearsp';
1225
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1226
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1703
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1704
+					$data['noarchive'] = true;
1705
+				}
1706
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1707
+					$SI->add($data);
1708
+				}
1227 1709
 				//$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1228 1710
 			    }
1229 1711
                         } elseif ($format == 'acars') {
1230
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1712
+                    	    if ($globalDebug) {
1713
+                    	    	echo 'ACARS : '.$buffer."\n";
1714
+                    	    }
1231 1715
 			    $ACARS->add(trim($buffer));
1232 1716
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1233 1717
 			    $ACARS->deleteLiveAcarsData();
@@ -1248,8 +1732,12 @@  discard block
 block discarded – undo
1248 1732
 				    $aircraft_type = $line[10];
1249 1733
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1250 1734
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1251
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1252
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1735
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1736
+				    	$data['noarchive'] = true;
1737
+				    }
1738
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1739
+				    	$SI->add($data);
1740
+				    }
1253 1741
 				}
1254 1742
 			    }
1255 1743
 			} elseif ($format == 'beast') {
@@ -1259,28 +1747,62 @@  discard block
 block discarded – undo
1259 1747
 			    foreach($buffer as $all_data) {
1260 1748
 				$line = json_decode('{'.$all_data.'}',true);
1261 1749
 				$data = array();
1262
-				if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex
1263
-				if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
1264
-				if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
1265
-				if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
1266
-				if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
1267
-				if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
1268
-				if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
1750
+				if (isset($line['Icao'])) {
1751
+					$data['hex'] = $line['Icao'];
1752
+				}
1753
+				// hex
1754
+				if (isset($line['Call'])) {
1755
+					$data['ident'] = $line['Call'];
1756
+				}
1757
+				// ident
1758
+				if (isset($line['Alt'])) {
1759
+					$data['altitude'] = $line['Alt'];
1760
+				}
1761
+				// altitude
1762
+				if (isset($line['Spd'])) {
1763
+					$data['speed'] = $line['Spd'];
1764
+				}
1765
+				// speed
1766
+				if (isset($line['Trak'])) {
1767
+					$data['heading'] = $line['Trak'];
1768
+				}
1769
+				// heading
1770
+				if (isset($line['Lat'])) {
1771
+					$data['latitude'] = $line['Lat'];
1772
+				}
1773
+				// lat
1774
+				if (isset($line['Long'])) {
1775
+					$data['longitude'] = $line['Long'];
1776
+				}
1777
+				// long
1269 1778
 				//$data['verticalrate'] = $line['']; // verticale rate
1270
-				if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
1779
+				if (isset($line['Sqk'])) {
1780
+					$data['squawk'] = $line['Sqk'];
1781
+				}
1782
+				// squawk
1271 1783
 				$data['emergency'] = ''; // emergency
1272
-				if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
1784
+				if (isset($line['Reg'])) {
1785
+					$data['registration'] = $line['Reg'];
1786
+				}
1273 1787
 				/*
1274 1788
 				if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
1275 1789
 				else $data['datetime'] = date('Y-m-d H:i:s');
1276 1790
 				*/
1277 1791
 				$data['datetime'] = date('Y-m-d H:i:s');
1278
-				if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
1792
+				if (isset($line['Type'])) {
1793
+					$data['aircraft_icao'] = $line['Type'];
1794
+				}
1279 1795
 		    		$data['format_source'] = 'vrstcp';
1280 1796
 				$data['id_source'] = $id_source;
1281
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1282
-				if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1283
-				if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data);
1797
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1798
+					$data['noarchive'] = true;
1799
+				}
1800
+				if (isset($value['name']) && $value['name'] != '') {
1801
+					$data['source_name'] = $value['name'];
1802
+				}
1803
+				if (isset($data['latitude']) && isset($data['hex'])) {
1804
+					$SI->add($data);
1805
+				}
1284 1806
 				unset($data);
1285 1807
 			    }
1286 1808
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
@@ -1293,22 +1815,46 @@  discard block
 block discarded – undo
1293 1815
     				$data['hex'] = $lined['hexid'];
1294 1816
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1295 1817
     				$data['datetime'] = date('Y-m-d H:i:s');;
1296
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1297
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1298
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1299
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1300
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1301
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1302
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1818
+    				if (isset($lined['ident'])) {
1819
+    					$data['ident'] = $lined['ident'];
1820
+    				}
1821
+    				if (isset($lined['lat'])) {
1822
+    					$data['latitude'] = $lined['lat'];
1823
+    				}
1824
+    				if (isset($lined['lon'])) {
1825
+    					$data['longitude'] = $lined['lon'];
1826
+    				}
1827
+    				if (isset($lined['speed'])) {
1828
+    					$data['speed'] = $lined['speed'];
1829
+    				}
1830
+    				if (isset($lined['squawk'])) {
1831
+    					$data['squawk'] = $lined['squawk'];
1832
+    				}
1833
+    				if (isset($lined['alt'])) {
1834
+    					$data['altitude'] = $lined['alt'];
1835
+    				}
1836
+    				if (isset($lined['heading'])) {
1837
+    					$data['heading'] = $lined['heading'];
1838
+    				}
1303 1839
     				$data['id_source'] = $id_source;
1304 1840
     				$data['format_source'] = 'tsv';
1305
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1306
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1307
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1308
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1841
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1842
+    					$data['source_name'] = $globalSources[$nb]['name'];
1843
+    				}
1844
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1845
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1846
+    				}
1847
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1848
+					$data['noarchive'] = true;
1849
+				}
1850
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1851
+    					$SI->add($data);
1852
+    				}
1309 1853
     				unset($lined);
1310 1854
     				unset($data);
1311
-    			    } else $error = true;
1855
+    			    } else {
1856
+    			    	$error = true;
1857
+    			    }
1312 1858
 			} elseif ($format == 'aprs' && $use_aprs) {
1313 1859
 			    if ($aprs_connect == 0) {
1314 1860
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1333,53 +1879,107 @@  discard block
 block discarded – undo
1333 1879
 				    $aprs_last_tx = time();
1334 1880
 				    $data = array();
1335 1881
 				    //print_r($line);
1336
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1337
-				    if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi'];
1338
-				    if (isset($line['imo'])) $data['imo'] = $line['imo'];
1339
-				    if (isset($line['squawk'])) $data['squawk'] = $line['squawk'];
1340
-				    if (isset($line['arrival_code'])) $data['arrical_code'] = $line['arrival_code'];
1341
-				    if (isset($line['arrival_date'])) $data['arrical_date'] = $line['arrival_date'];
1342
-				    if (isset($line['type_id'])) $data['type_id'] = $line['typeid'];
1343
-				    if (isset($line['status_id'])) $data['status_id'] = $line['statusid'];
1344
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1345
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1882
+				    if (isset($line['address'])) {
1883
+				    	$data['hex'] = $line['address'];
1884
+				    }
1885
+				    if (isset($line['mmsi'])) {
1886
+				    	$data['mmsi'] = $line['mmsi'];
1887
+				    }
1888
+				    if (isset($line['imo'])) {
1889
+				    	$data['imo'] = $line['imo'];
1890
+				    }
1891
+				    if (isset($line['squawk'])) {
1892
+				    	$data['squawk'] = $line['squawk'];
1893
+				    }
1894
+				    if (isset($line['arrival_code'])) {
1895
+				    	$data['arrical_code'] = $line['arrival_code'];
1896
+				    }
1897
+				    if (isset($line['arrival_date'])) {
1898
+				    	$data['arrical_date'] = $line['arrival_date'];
1899
+				    }
1900
+				    if (isset($line['type_id'])) {
1901
+				    	$data['type_id'] = $line['typeid'];
1902
+				    }
1903
+				    if (isset($line['status_id'])) {
1904
+				    	$data['status_id'] = $line['statusid'];
1905
+				    }
1906
+				    if (isset($line['timestamp'])) {
1907
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1908
+				    } else {
1909
+				    	$data['datetime'] = date('Y-m-d H:i:s');
1910
+				    }
1346 1911
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1347
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1912
+				    if (isset($line['ident'])) {
1913
+				    	$data['ident'] = $line['ident'];
1914
+				    }
1348 1915
 				    $data['latitude'] = $line['latitude'];
1349 1916
 				    $data['longitude'] = $line['longitude'];
1350 1917
 				    //$data['verticalrate'] = $line[16];
1351
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1918
+				    if (isset($line['speed'])) {
1919
+				    	$data['speed'] = $line['speed'];
1920
+				    }
1352 1921
 				    //else $data['speed'] = 0;
1353
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1354
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1355
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1356
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1922
+				    if (isset($line['altitude'])) {
1923
+				    	$data['altitude'] = $line['altitude'];
1924
+				    }
1925
+				    if (isset($line['comment'])) {
1926
+				    	$data['comment'] = $line['comment'];
1927
+				    }
1928
+				    if (isset($line['symbol'])) {
1929
+				    	$data['type'] = $line['symbol'];
1930
+				    }
1931
+				    if (isset($line['heading'])) {
1932
+				    	$data['heading'] = $line['heading'];
1933
+				    }
1357 1934
 				    //else $data['heading'] = 0;
1358
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1935
+				    if (isset($line['stealth'])) {
1936
+				    	$data['aircraft_type'] = $line['stealth'];
1937
+				    }
1359 1938
 				    //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true;
1360
-				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true;
1361
-				    elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false;
1362
-				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
1363
-				    elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false;
1939
+				    if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) {
1940
+				    	$data['noarchive'] = true;
1941
+				    } elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) {
1942
+				    	$data['noarchive'] = false;
1943
+				    }
1944
+				    if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
1945
+				    	$data['noarchive'] = true;
1946
+				    } elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) {
1947
+				    	$data['noarchive'] = false;
1948
+				    }
1364 1949
     				    $data['id_source'] = $id_source;
1365
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1366
-				    else $data['format_source'] = 'aprs';
1950
+    				    if (isset($line['format_source'])) {
1951
+    				    	$data['format_source'] = $line['format_source'];
1952
+    				    } else {
1953
+				    	$data['format_source'] = 'aprs';
1954
+				    }
1367 1955
 				    $data['source_name'] = $line['source'];
1368
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1369
-				    else $data['source_type'] = 'flarm';
1370
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1956
+				    if (isset($line['source_type'])) {
1957
+				    	$data['source_type'] = $line['source_type'];
1958
+				    } else {
1959
+				    	$data['source_type'] = 'flarm';
1960
+				    }
1961
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
1962
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1963
+    				    }
1371 1964
 				    $currentdate = date('Y-m-d H:i:s');
1372 1965
 				    $aprsdate = strtotime($data['datetime']);
1373
-				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL';
1966
+				    if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') {
1967
+				    	$data['altitude_relative'] = 'AMSL';
1968
+				    }
1374 1969
 				    // Accept data if time <= system time + 20s
1375 1970
 				    //if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1376 1971
 				    if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1377 1972
 					$send = $SI->add($data);
1378 1973
 				    } elseif ($data['source_type'] == 'ais') {
1379
-					if (isset($globalMarine) && $globalMarine) $send = $MI->add($data);
1974
+					if (isset($globalMarine) && $globalMarine) {
1975
+						$send = $MI->add($data);
1976
+					}
1380 1977
 				    } elseif (isset($line['stealth'])) {
1381
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1382
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1978
+					if ($line['stealth'] != 0) {
1979
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1980
+					} else {
1981
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1982
+					}
1383 1983
 				    } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && (
1384 1984
 					    $line['symbol'] == 'Balloon' || $line['symbol'] == 'Glider' || 
1385 1985
 					    $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
@@ -1413,9 +2013,13 @@  discard block
 block discarded – undo
1413 2013
 				    //} 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') {
1414 2014
 				//    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1415 2015
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1416
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
2016
+					if (isset($globalTracker) && $globalTracker) {
2017
+						$send = $TI->add($data);
2018
+					}
1417 2019
 				    } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) {
1418
-					if (!isset($data['altitude'])) $data['altitude'] = 0;
2020
+					if (!isset($data['altitude'])) {
2021
+						$data['altitude'] = 0;
2022
+					}
1419 2023
 					$Source->deleteOldLocationByType('gs');
1420 2024
 					if (count($Source->getLocationInfoByName($data['ident'])) > 0) {
1421 2025
 						$Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']);
@@ -1427,12 +2031,9 @@  discard block
 block discarded – undo
1427 2031
 				    	print_r($line);
1428 2032
 				    }
1429 2033
 				    unset($data);
1430
-				} 
1431
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
2034
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1432 2035
 					echo '!! Weather Station not yet supported'."\n";
1433
-				}
1434
-				 
1435
-				elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
2036
+				} elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') {
1436 2037
 					$Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']);
1437 2038
 				}
1438 2039
 				/*
@@ -1441,7 +2042,9 @@  discard block
 block discarded – undo
1441 2042
 				}
1442 2043
 				*/
1443 2044
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1444
-				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
2045
+				elseif ($line == true && $globalDebug) {
2046
+					echo '!! Failed : '.$buffer."!!\n";
2047
+				}
1445 2048
 			    }
1446 2049
 			} else {
1447 2050
 			    $line = explode(',', $buffer);
@@ -1470,26 +2073,45 @@  discard block
 block discarded – undo
1470 2073
     				$data['ground'] = $line[21];
1471 2074
     				$data['emergency'] = $line[19];
1472 2075
     				$data['format_source'] = 'sbs';
1473
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1474
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1475
-				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true;
2076
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
2077
+					$data['source_name'] = $globalSources[$nb]['name'];
2078
+				}
2079
+    				if (isset($globalSources[$nb]['sourcestats'])) {
2080
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
2081
+    				}
2082
+				if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) {
2083
+					$data['noarchive'] = true;
2084
+				}
1476 2085
     				$data['id_source'] = $id_source;
1477
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1478
-    				else $error = true;
2086
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
2087
+    					$send = $SI->add($data);
2088
+    				} else {
2089
+    					$error = true;
2090
+    				}
1479 2091
     				unset($data);
1480
-    			    } else $error = true;
2092
+    			    } else {
2093
+    			    	$error = true;
2094
+    			    }
1481 2095
 			    if ($error) {
1482 2096
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1483
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
2097
+					if ($globalDebug) {
2098
+						echo "Not a message. Ignoring... \n";
2099
+					}
1484 2100
 				} else {
1485
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
2101
+					if ($globalDebug) {
2102
+						echo "Wrong line format. Ignoring... \n";
2103
+					}
1486 2104
 					if ($globalDebug) {
1487 2105
 						echo $buffer;
1488 2106
 						//print_r($line);
1489 2107
 					}
1490 2108
 					//socket_close($r);
1491
-					if ($globalDebug) echo "Reconnect after an error...\n";
1492
-					if ($format == 'aprs') $aprs_connect = 0;
2109
+					if ($globalDebug) {
2110
+						echo "Reconnect after an error...\n";
2111
+					}
2112
+					if ($format == 'aprs') {
2113
+						$aprs_connect = 0;
2114
+					}
1493 2115
 					$sourceer[$nb] = $globalSources[$nb];
1494 2116
 					connect_all($sourceer);
1495 2117
 					$sourceer = array();
@@ -1497,10 +2119,14 @@  discard block
 block discarded – undo
1497 2119
 			    }
1498 2120
 			}
1499 2121
 			// Sleep for xxx microseconds
1500
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
2122
+			if (isset($globalSBSSleep)) {
2123
+				usleep($globalSBSSleep);
2124
+			}
1501 2125
 		    } else {
1502 2126
 			if ($format == 'flightgearmp') {
1503
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
2127
+			    	if ($globalDebug) {
2128
+			    		echo "Reconnect FlightGear MP...";
2129
+			    	}
1504 2130
 				//@socket_close($r);
1505 2131
 				sleep($globalMinFetch);
1506 2132
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1509,10 +2135,15 @@  discard block
 block discarded – undo
1509 2135
 				break;
1510 2136
 				
1511 2137
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1512
-			    if (isset($tt[$format])) $tt[$format]++;
1513
-			    else $tt[$format] = 0;
2138
+			    if (isset($tt[$format])) {
2139
+			    	$tt[$format]++;
2140
+			    } else {
2141
+			    	$tt[$format] = 0;
2142
+			    }
1514 2143
 			    if ($tt[$format] > 30) {
1515
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
2144
+				if ($globalDebug) {
2145
+					echo "ERROR : Reconnect ".$format."...";
2146
+				}
1516 2147
 				//@socket_close($r);
1517 2148
 				sleep(2);
1518 2149
 				$aprs_connect = 0;
@@ -1529,11 +2160,17 @@  discard block
 block discarded – undo
1529 2160
 	    } else {
1530 2161
 		$error = socket_strerror(socket_last_error());
1531 2162
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1532
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1533
-			if (isset($globalDebug)) echo "Restarting...\n";
2163
+			if ($globalDebug) {
2164
+				echo "ERROR : socket_select give this error ".$error . "\n";
2165
+			}
2166
+			if (isset($globalDebug)) {
2167
+				echo "Restarting...\n";
2168
+			}
1534 2169
 			// Restart the script if possible
1535 2170
 			if (is_array($sockets)) {
1536
-			    if ($globalDebug) echo "Shutdown all sockets...";
2171
+			    if ($globalDebug) {
2172
+			    	echo "Shutdown all sockets...";
2173
+			    }
1537 2174
 			    
1538 2175
 			    foreach ($sockets as $sock) {
1539 2176
 				@socket_shutdown($sock,2);
@@ -1541,25 +2178,45 @@  discard block
 block discarded – undo
1541 2178
 			    }
1542 2179
 			    
1543 2180
 			}
1544
-			if ($globalDebug) echo "Waiting...";
2181
+			if ($globalDebug) {
2182
+				echo "Waiting...";
2183
+			}
1545 2184
 			sleep(2);
1546 2185
 			$time = time();
1547 2186
 			//connect_all($hosts);
1548 2187
 			$aprs_connect = 0;
1549
-			if ($reset%5 == 0) sleep(20);
1550
-			if ($reset%10 == 0) sleep(100);
1551
-			if ($reset%20 == 0) sleep(200);
1552
-			if ($reset > 100) exit('Too many attempts...');
1553
-			if ($globalDebug) echo "Restart all connections...";
2188
+			if ($reset%5 == 0) {
2189
+				sleep(20);
2190
+			}
2191
+			if ($reset%10 == 0) {
2192
+				sleep(100);
2193
+			}
2194
+			if ($reset%20 == 0) {
2195
+				sleep(200);
2196
+			}
2197
+			if ($reset > 100) {
2198
+				exit('Too many attempts...');
2199
+			}
2200
+			if ($globalDebug) {
2201
+				echo "Restart all connections...";
2202
+			}
1554 2203
 			connect_all($globalSources);
1555 2204
 		}
1556 2205
 	    }
1557 2206
 	}
1558 2207
 	if ($globalDaemon === false) {
1559
-	    if ($globalDebug) echo 'Check all...'."\n";
1560
-	    if (isset($SI)) $SI->checkAll();
1561
-	    if (isset($TI)) $TI->checkAll();
1562
-	    if (isset($MI)) $MI->checkAll();
2208
+	    if ($globalDebug) {
2209
+	    	echo 'Check all...'."\n";
2210
+	    }
2211
+	    if (isset($SI)) {
2212
+	    	$SI->checkAll();
2213
+	    }
2214
+	    if (isset($TI)) {
2215
+	    	$TI->checkAll();
2216
+	    }
2217
+	    if (isset($MI)) {
2218
+	    	$MI->checkAll();
2219
+	    }
1563 2220
 	}
1564 2221
     }
1565 2222
 }
Please login to merge, or discard this patch.
install/class.update_db.php 1 patch
Braces   +956 added lines, -331 removed lines patch added patch discarded remove patch
@@ -17,7 +17,9 @@  discard block
 block discarded – undo
17 17
 		curl_setopt($ch, CURLOPT_URL, $url);
18 18
 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
19 19
 		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
20
-		if ($referer != '') curl_setopt($ch, CURLOPT_REFERER, $referer);
20
+		if ($referer != '') {
21
+			curl_setopt($ch, CURLOPT_REFERER, $referer);
22
+		}
21 23
 		curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
22 24
 		curl_setopt($ch, CURLOPT_FILE, $fp);
23 25
 		curl_exec($ch);
@@ -28,12 +30,16 @@  discard block
 block discarded – undo
28 30
 	public static function gunzip($in_file,$out_file_name = '') {
29 31
 		//echo $in_file.' -> '.$out_file_name."\n";
30 32
 		$buffer_size = 4096; // read 4kb at a time
31
-		if ($out_file_name == '') $out_file_name = str_replace('.gz', '', $in_file); 
33
+		if ($out_file_name == '') {
34
+			$out_file_name = str_replace('.gz', '', $in_file);
35
+		}
32 36
 		if ($in_file != '' && file_exists($in_file)) {
33 37
 			// PHP version of Ubuntu use gzopen64 instead of gzopen
34
-			if (function_exists('gzopen')) $file = gzopen($in_file,'rb');
35
-			elseif (function_exists('gzopen64')) $file = gzopen64($in_file,'rb');
36
-			else {
38
+			if (function_exists('gzopen')) {
39
+				$file = gzopen($in_file,'rb');
40
+			} elseif (function_exists('gzopen64')) {
41
+				$file = gzopen64($in_file,'rb');
42
+			} else {
37 43
 				echo 'gzopen not available';
38 44
 				die;
39 45
 			}
@@ -54,8 +60,12 @@  discard block
 block discarded – undo
54 60
 			if ($res === TRUE) {
55 61
 				$zip->extractTo($path);
56 62
 				$zip->close();
57
-			} else return false;
58
-		} else return false;
63
+			} else {
64
+				return false;
65
+			}
66
+		} else {
67
+			return false;
68
+		}
59 69
 	}
60 70
 	
61 71
 	public static function connect_sqlite($database) {
@@ -70,7 +80,9 @@  discard block
 block discarded – undo
70 80
 	public static function retrieve_route_sqlite_to_dest($database_file) {
71 81
 		global $globalDebug, $globalTransaction;
72 82
 		//$query = 'TRUNCATE TABLE routes';
73
-		if ($globalDebug) echo " - Delete previous routes from DB -";
83
+		if ($globalDebug) {
84
+			echo " - Delete previous routes from DB -";
85
+		}
74 86
 		$query = "DELETE FROM routes WHERE Source = '' OR Source = :source";
75 87
 		$Connection = new Connection();
76 88
 		try {
@@ -81,7 +93,9 @@  discard block
 block discarded – undo
81 93
                         return "error : ".$e->getMessage();
82 94
                 }
83 95
 
84
-    		if ($globalDebug) echo " - Add routes to DB -";
96
+    		if ($globalDebug) {
97
+    			echo " - Add routes to DB -";
98
+    		}
85 99
     		update_db::connect_sqlite($database_file);
86 100
 		//$query = 'select Route.RouteID, Route.callsign, operator.Icao AS operator_icao, FromAir.Icao AS FromAirportIcao, ToAir.Icao AS ToAirportIcao from Route inner join operator ON Route.operatorId = operator.operatorId LEFT JOIN Airport AS FromAir ON route.FromAirportId = FromAir.AirportId LEFT JOIN Airport AS ToAir ON ToAir.AirportID = route.ToAirportID';
87 101
 		$query = "select Route.RouteID, Route.callsign, operator.Icao AS operator_icao, FromAir.Icao AS FromAirportIcao, ToAir.Icao AS ToAirportIcao, rstp.allstop AS AllStop from Route inner join operator ON Route.operatorId = operator.operatorId LEFT JOIN Airport AS FromAir ON route.FromAirportId = FromAir.AirportId LEFT JOIN Airport AS ToAir ON ToAir.AirportID = route.ToAirportID LEFT JOIN (select RouteId,GROUP_CONCAT(icao,' ') as allstop from routestop left join Airport as air ON routestop.AirportId = air.AirportID group by RouteID) AS rstp ON Route.RouteID = rstp.RouteID";
@@ -96,15 +110,21 @@  discard block
 block discarded – undo
96 110
 		$Connection = new Connection();
97 111
 		$sth_dest = $Connection->db->prepare($query_dest);
98 112
 		try {
99
-			if ($globalTransaction) $Connection->db->beginTransaction();
113
+			if ($globalTransaction) {
114
+				$Connection->db->beginTransaction();
115
+			}
100 116
             		while ($values = $sth->fetch(PDO::FETCH_ASSOC)) {
101 117
 				//$query_dest_values = array(':RouteID' => $values['RouteId'],':CallSign' => $values['Callsign'],':Operator_ICAO' => $values['operator_icao'],':FromAirport_ICAO' => $values['FromAirportIcao'],':ToAirport_ICAO' => $values['ToAirportIcao'],':routestop' => $values['AllStop'],':source' => $database_file);
102 118
 				$query_dest_values = array(':CallSign' => $values['Callsign'],':Operator_ICAO' => $values['operator_icao'],':FromAirport_ICAO' => $values['FromAirportIcao'],':ToAirport_ICAO' => $values['ToAirportIcao'],':routestop' => $values['AllStop'],':source' => $database_file);
103 119
 				$sth_dest->execute($query_dest_values);
104 120
             		}
105
-			if ($globalTransaction) $Connection->db->commit();
121
+			if ($globalTransaction) {
122
+				$Connection->db->commit();
123
+			}
106 124
 		} catch(PDOException $e) {
107
-			if ($globalTransaction) $Connection->db->rollBack(); 
125
+			if ($globalTransaction) {
126
+				$Connection->db->rollBack();
127
+			}
108 128
 			return "error : ".$e->getMessage();
109 129
 		}
110 130
                 return '';
@@ -112,7 +132,9 @@  discard block
 block discarded – undo
112 132
 	public static function retrieve_route_oneworld($database_file) {
113 133
 		global $globalDebug, $globalTransaction;
114 134
 		//$query = 'TRUNCATE TABLE routes';
115
-		if ($globalDebug) echo " - Delete previous routes from DB -";
135
+		if ($globalDebug) {
136
+			echo " - Delete previous routes from DB -";
137
+		}
116 138
 		$query = "DELETE FROM routes WHERE Source = '' OR Source = :source";
117 139
 		$Connection = new Connection();
118 140
 		try {
@@ -123,14 +145,18 @@  discard block
 block discarded – undo
123 145
                         return "error : ".$e->getMessage();
124 146
                 }
125 147
 
126
-    		if ($globalDebug) echo " - Add routes to DB -";
148
+    		if ($globalDebug) {
149
+    			echo " - Add routes to DB -";
150
+    		}
127 151
 		require_once(dirname(__FILE__).'/../require/class.Spotter.php');
128 152
 		$Spotter = new Spotter();
129 153
 		if ($fh = fopen($database_file,"r")) {
130 154
 			$query_dest = 'INSERT INTO routes (CallSign,Operator_ICAO,FromAirport_ICAO,FromAirport_Time,ToAirport_ICAO,ToAirport_Time,RouteStop,Source) VALUES (:CallSign, :Operator_ICAO, :FromAirport_ICAO,:FromAirport_Time, :ToAirport_ICAO, :ToAirport_Time,:routestop, :source)';
131 155
 			$Connection = new Connection();
132 156
 			$sth_dest = $Connection->db->prepare($query_dest);
133
-			if ($globalTransaction) $Connection->db->beginTransaction();
157
+			if ($globalTransaction) {
158
+				$Connection->db->beginTransaction();
159
+			}
134 160
 			while (!feof($fh)) {
135 161
 				$line = fgetcsv($fh,9999,',');
136 162
 				if ($line[0] != '') {
@@ -139,13 +165,17 @@  discard block
 block discarded – undo
139 165
 							$query_dest_values = array(':CallSign' => str_replace('*','',$line[7]),':Operator_ICAO' => '',':FromAirport_ICAO' => $Spotter->getAirportICAO($line[0]),':FromAirport_Time' => $line[5],':ToAirport_ICAO' => $Spotter->getAirportICAO($line[1]),':ToAirport_Time' => $line[6],':routestop' => '',':source' => 'oneworld');
140 166
 							$sth_dest->execute($query_dest_values);
141 167
 						} catch(PDOException $e) {
142
-							if ($globalTransaction) $Connection->db->rollBack(); 
168
+							if ($globalTransaction) {
169
+								$Connection->db->rollBack();
170
+							}
143 171
 							return "error : ".$e->getMessage();
144 172
 						}
145 173
 					}
146 174
 				}
147 175
 			}
148
-			if ($globalTransaction) $Connection->db->commit();
176
+			if ($globalTransaction) {
177
+				$Connection->db->commit();
178
+			}
149 179
 		}
150 180
                 return '';
151 181
 	}
@@ -153,7 +183,9 @@  discard block
 block discarded – undo
153 183
 	public static function retrieve_route_skyteam($database_file) {
154 184
 		global $globalDebug, $globalTransaction;
155 185
 		//$query = 'TRUNCATE TABLE routes';
156
-		if ($globalDebug) echo " - Delete previous routes from DB -";
186
+		if ($globalDebug) {
187
+			echo " - Delete previous routes from DB -";
188
+		}
157 189
 		$query = "DELETE FROM routes WHERE Source = '' OR Source = :source";
158 190
 		$Connection = new Connection();
159 191
 		try {
@@ -164,7 +196,9 @@  discard block
 block discarded – undo
164 196
                         return "error : ".$e->getMessage();
165 197
                 }
166 198
 
167
-    		if ($globalDebug) echo " - Add routes to DB -";
199
+    		if ($globalDebug) {
200
+    			echo " - Add routes to DB -";
201
+    		}
168 202
 
169 203
 		require_once(dirname(__FILE__).'/../require/class.Spotter.php');
170 204
 		$Spotter = new Spotter();
@@ -173,7 +207,9 @@  discard block
 block discarded – undo
173 207
 			$Connection = new Connection();
174 208
 			$sth_dest = $Connection->db->prepare($query_dest);
175 209
 			try {
176
-				if ($globalTransaction) $Connection->db->beginTransaction();
210
+				if ($globalTransaction) {
211
+					$Connection->db->beginTransaction();
212
+				}
177 213
 				while (!feof($fh)) {
178 214
 					$line = fgetcsv($fh,9999,',');
179 215
 					if ($line[0] != '') {
@@ -184,9 +220,13 @@  discard block
 block discarded – undo
184 220
 						}
185 221
 					}
186 222
 				}
187
-				if ($globalTransaction) $Connection->db->commit();
223
+				if ($globalTransaction) {
224
+					$Connection->db->commit();
225
+				}
188 226
 			} catch(PDOException $e) {
189
-				if ($globalTransaction) $Connection->db->rollBack(); 
227
+				if ($globalTransaction) {
228
+					$Connection->db->rollBack();
229
+				}
190 230
 				return "error : ".$e->getMessage();
191 231
 			}
192 232
 		}
@@ -229,11 +269,16 @@  discard block
 block discarded – undo
229 269
 		$sth_dest = $Connection->db->prepare($query_dest);
230 270
 		$sth_dest_owner = $Connection->db->prepare($query_dest_owner);
231 271
 		try {
232
-			if ($globalTransaction) $Connection->db->beginTransaction();
272
+			if ($globalTransaction) {
273
+				$Connection->db->beginTransaction();
274
+			}
233 275
             		while ($values = $sth->fetch(PDO::FETCH_ASSOC)) {
234 276
 			//$query_dest_values = array(':AircraftID' => $values['AircraftID'],':FirstCreated' => $values['FirstCreated'],':LastModified' => $values['LastModified'],':ModeS' => $values['ModeS'],':ModeSCountry' => $values['ModeSCountry'],':Registration' => $values['Registration'],':ICAOTypeCode' => $values['ICAOTypeCode'],':SerialNo' => $values['SerialNo'], ':OperatorFlagCode' => $values['OperatorFlagCode'], ':Manufacturer' => $values['Manufacturer'], ':Type' => $values['Type'], ':FirstRegDate' => $values['FirstRegDate'], ':CurrentRegDate' => $values['CurrentRegDate'], ':Country' => $values['Country'], ':PreviousID' => $values['PreviousID'], ':DeRegDate' => $values['DeRegDate'], ':Status' => $values['Status'], ':PopularName' => $values['PopularName'],':GenericName' => $values['GenericName'],':AircraftClass' => $values['AircraftClass'], ':Engines' => $values['Engines'], ':OwnershipStatus' => $values['OwnershipStatus'],':RegisteredOwners' => $values['RegisteredOwners'],':MTOW' => $values['MTOW'], ':TotalHours' => $values['TotalHours'],':YearBuilt' => $values['YearBuilt'], ':CofACategory' => $values['CofACategory'], ':CofAExpiry' => $values['CofAExpiry'], ':UserNotes' => $values['UserNotes'], ':Interested' => $values['Interested'], ':UserTag' => $values['UserTag'], ':InfoUrl' => $values['InfoURL'], ':PictureUrl1' => $values['PictureURL1'], ':PictureUrl2' => $values['PictureURL2'], ':PictureUrl3' => $values['PictureURL3'], ':UserBool1' => $values['UserBool1'], ':UserBool2' => $values['UserBool2'], ':UserBool3' => $values['UserBool3'], ':UserBool4' => $values['UserBool4'], ':UserBool5' => $values['UserBool5'], ':UserString1' => $values['UserString1'], ':UserString2' => $values['UserString2'], ':UserString3' => $values['UserString3'], ':UserString4' => $values['UserString4'], ':UserString5' => $values['UserString5'], ':UserInt1' => $values['UserInt1'], ':UserInt2' => $values['UserInt2'], ':UserInt3' => $values['UserInt3'], ':UserInt4' => $values['UserInt4'], ':UserInt5' => $values['UserInt5']);
235
-				if ($values['UserString4'] == 'M') $type = 'military';
236
-				else $type = null;
277
+				if ($values['UserString4'] == 'M') {
278
+					$type = 'military';
279
+				} else {
280
+					$type = null;
281
+				}
237 282
 				$query_dest_values = array(':LastModified' => $values['LastModified'],':ModeS' => $values['ModeS'],':ModeSCountry' => $values['ModeSCountry'],':Registration' => $values['Registration'],':ICAOTypeCode' => $values['ICAOTypeCode'],':source' => $database_file,':type' => $type);
238 283
 				$sth_dest->execute($query_dest_values);
239 284
 				if ($values['RegisteredOwners'] != '' && $values['RegisteredOwners'] != NULL && $values['RegisteredOwners'] != 'Private') {
@@ -241,7 +286,9 @@  discard block
 block discarded – undo
241 286
 				    $sth_dest_owner->execute($query_dest_owner_values);
242 287
 				}
243 288
             		}
244
-			if ($globalTransaction) $Connection->db->commit();
289
+			if ($globalTransaction) {
290
+				$Connection->db->commit();
291
+			}
245 292
 		} catch(PDOException $e) {
246 293
 			return "error : ".$e->getMessage();
247 294
 		}
@@ -278,7 +325,9 @@  discard block
 block discarded – undo
278 325
 			$Connection = new Connection();
279 326
 			$sth_dest = $Connection->db->prepare($query_dest);
280 327
 			try {
281
-				if ($globalTransaction) $Connection->db->beginTransaction();
328
+				if ($globalTransaction) {
329
+					$Connection->db->beginTransaction();
330
+				}
282 331
             			while (!feof($fh)) {
283 332
             				$values = array();
284 333
             				$line = $Common->hex2str(fgets($fh,9999));
@@ -289,7 +338,9 @@  discard block
 block discarded – undo
289 338
             				// Check if we can find ICAO, else set it to GLID
290 339
             				$aircraft_name_split = explode(' ',$aircraft_name);
291 340
             				$search_more = '';
292
-            				if (count($aircraft_name) > 1 && strlen($aircraft_name_split[1]) > 3) $search_more .= " AND LIKE '%".$aircraft_name_split[0]."%'";
341
+            				if (count($aircraft_name) > 1 && strlen($aircraft_name_split[1]) > 3) {
342
+            					$search_more .= " AND LIKE '%".$aircraft_name_split[0]."%'";
343
+            				}
293 344
             				$query_search = "SELECT * FROM aircraft WHERE type LIKE '%".$aircraft_name."%'".$search_more;
294 345
             				$sth_search = $Connection->db->prepare($query_search);
295 346
 					try {
@@ -302,7 +353,9 @@  discard block
 block discarded – undo
302 353
 					} catch(PDOException $e) {
303 354
 						return "error : ".$e->getMessage();
304 355
 					}
305
-					if (!isset($values['ICAOTypeCode'])) $values['ICAOTypeCode'] = 'GLID';
356
+					if (!isset($values['ICAOTypeCode'])) {
357
+						$values['ICAOTypeCode'] = 'GLID';
358
+					}
306 359
 					// Add data to db
307 360
 					if ($values['Registration'] != '' && $values['Registration'] != '0000') {
308 361
 						//$query_dest_values = array(':AircraftID' => $values['AircraftID'],':FirstCreated' => $values['FirstCreated'],':LastModified' => $values['LastModified'],':ModeS' => $values['ModeS'],':ModeSCountry' => $values['ModeSCountry'],':Registration' => $values['Registration'],':ICAOTypeCode' => $values['ICAOTypeCode'],':SerialNo' => $values['SerialNo'], ':OperatorFlagCode' => $values['OperatorFlagCode'], ':Manufacturer' => $values['Manufacturer'], ':Type' => $values['Type'], ':FirstRegDate' => $values['FirstRegDate'], ':CurrentRegDate' => $values['CurrentRegDate'], ':Country' => $values['Country'], ':PreviousID' => $values['PreviousID'], ':DeRegDate' => $values['DeRegDate'], ':Status' => $values['Status'], ':PopularName' => $values['PopularName'],':GenericName' => $values['GenericName'],':AircraftClass' => $values['AircraftClass'], ':Engines' => $values['Engines'], ':OwnershipStatus' => $values['OwnershipStatus'],':RegisteredOwners' => $values['RegisteredOwners'],':MTOW' => $values['MTOW'], ':TotalHours' => $values['TotalHours'],':YearBuilt' => $values['YearBuilt'], ':CofACategory' => $values['CofACategory'], ':CofAExpiry' => $values['CofAExpiry'], ':UserNotes' => $values['UserNotes'], ':Interested' => $values['Interested'], ':UserTag' => $values['UserTag'], ':InfoUrl' => $values['InfoURL'], ':PictureUrl1' => $values['PictureURL1'], ':PictureUrl2' => $values['PictureURL2'], ':PictureUrl3' => $values['PictureURL3'], ':UserBool1' => $values['UserBool1'], ':UserBool2' => $values['UserBool2'], ':UserBool3' => $values['UserBool3'], ':UserBool4' => $values['UserBool4'], ':UserBool5' => $values['UserBool5'], ':UserString1' => $values['UserString1'], ':UserString2' => $values['UserString2'], ':UserString3' => $values['UserString3'], ':UserString4' => $values['UserString4'], ':UserString5' => $values['UserString5'], ':UserInt1' => $values['UserInt1'], ':UserInt2' => $values['UserInt2'], ':UserInt3' => $values['UserInt3'], ':UserInt4' => $values['UserInt4'], ':UserInt5' => $values['UserInt5']);
@@ -311,7 +364,9 @@  discard block
 block discarded – undo
311 364
 						$sth_dest->execute($query_dest_values);
312 365
 					}
313 366
 				}
314
-				if ($globalTransaction) $Connection->db->commit();
367
+				if ($globalTransaction) {
368
+					$Connection->db->commit();
369
+				}
315 370
 			} catch(PDOException $e) {
316 371
 				return "error : ".$e->getMessage();
317 372
 			}
@@ -347,7 +402,9 @@  discard block
 block discarded – undo
347 402
 			$Connection = new Connection();
348 403
 			$sth_dest = $Connection->db->prepare($query_dest);
349 404
 			try {
350
-				if ($globalTransaction) $Connection->db->beginTransaction();
405
+				if ($globalTransaction) {
406
+					$Connection->db->beginTransaction();
407
+				}
351 408
 				$tmp = fgetcsv($fh,9999,',',"'");
352 409
             			while (!feof($fh)) {
353 410
             				$line = fgetcsv($fh,9999,',',"'");
@@ -361,13 +418,17 @@  discard block
 block discarded – undo
361 418
             				// Check if we can find ICAO, else set it to GLID
362 419
             				$aircraft_name_split = explode(' ',$aircraft_name);
363 420
             				$search_more = '';
364
-            				if (count($aircraft_name) > 1 && strlen($aircraft_name_split[1]) > 3) $search_more .= " AND LIKE '%".$aircraft_name_split[0]."%'";
421
+            				if (count($aircraft_name) > 1 && strlen($aircraft_name_split[1]) > 3) {
422
+            					$search_more .= " AND LIKE '%".$aircraft_name_split[0]."%'";
423
+            				}
365 424
             				$query_search = "SELECT * FROM aircraft WHERE type LIKE '%".$aircraft_name."%'".$search_more;
366 425
             				$sth_search = $Connection->db->prepare($query_search);
367 426
 					try {
368 427
                                     		$sth_search->execute();
369 428
 	            				$result = $sth_search->fetch(PDO::FETCH_ASSOC);
370
-	            				if (isset($result['icao']) && $result['icao'] != '') $values['ICAOTypeCode'] = $result['icao'];
429
+	            				if (isset($result['icao']) && $result['icao'] != '') {
430
+	            					$values['ICAOTypeCode'] = $result['icao'];
431
+	            				}
371 432
 					} catch(PDOException $e) {
372 433
 						return "error : ".$e->getMessage();
373 434
 					}
@@ -380,7 +441,9 @@  discard block
 block discarded – undo
380 441
 						$sth_dest->execute($query_dest_values);
381 442
 					}
382 443
 				}
383
-				if ($globalTransaction) $Connection->db->commit();
444
+				if ($globalTransaction) {
445
+					$Connection->db->commit();
446
+				}
384 447
 			} catch(PDOException $e) {
385 448
 				return "error : ".$e->getMessage();
386 449
 			}
@@ -419,7 +482,9 @@  discard block
 block discarded – undo
419 482
 			$sth_dest = $Connection->db->prepare($query_dest);
420 483
 			$sth_modes = $Connection->db->prepare($query_modes);
421 484
 			try {
422
-				if ($globalTransaction) $Connection->db->beginTransaction();
485
+				if ($globalTransaction) {
486
+					$Connection->db->beginTransaction();
487
+				}
423 488
 				$tmp = fgetcsv($fh,9999,',','"');
424 489
             			while (!feof($fh)) {
425 490
             				$line = fgetcsv($fh,9999,',','"');
@@ -429,16 +494,22 @@  discard block
 block discarded – undo
429 494
             				    $values['registration'] = $line[0];
430 495
             				    $values['base'] = $line[4];
431 496
             				    $values['owner'] = $line[5];
432
-            				    if ($line[6] == '') $values['date_first_reg'] = null;
433
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[6]));
497
+            				    if ($line[6] == '') {
498
+            				    	$values['date_first_reg'] = null;
499
+            				    } else {
500
+					    	$values['date_first_reg'] = date("Y-m-d",strtotime($line[6]));
501
+					    }
434 502
 					    $values['cancel'] = $line[7];
435 503
 					} elseif ($country == 'EI') {
436 504
 					    // TODO : add modeS & reg to aircraft_modes
437 505
             				    $values['registration'] = $line[0];
438 506
             				    $values['base'] = $line[3];
439 507
             				    $values['owner'] = $line[2];
440
-            				    if ($line[1] == '') $values['date_first_reg'] = null;
441
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[1]));
508
+            				    if ($line[1] == '') {
509
+            				    	$values['date_first_reg'] = null;
510
+            				    } else {
511
+					    	$values['date_first_reg'] = date("Y-m-d",strtotime($line[1]));
512
+					    }
442 513
 					    $values['cancel'] = '';
443 514
 					    $values['modes'] = $line[7];
444 515
 					    $values['icao'] = $line[8];
@@ -457,16 +528,22 @@  discard block
 block discarded – undo
457 528
             				    $values['registration'] = $line[3];
458 529
             				    $values['base'] = null;
459 530
             				    $values['owner'] = $line[5];
460
-            				    if ($line[18] == '') $values['date_first_reg'] = null;
461
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[18]));
531
+            				    if ($line[18] == '') {
532
+            				    	$values['date_first_reg'] = null;
533
+            				    } else {
534
+					    	$values['date_first_reg'] = date("Y-m-d",strtotime($line[18]));
535
+					    }
462 536
 					    $values['cancel'] = '';
463 537
 					} elseif ($country == 'VH') {
464 538
 					    // TODO : add modeS & reg to aircraft_modes
465 539
             				    $values['registration'] = $line[0];
466 540
             				    $values['base'] = null;
467 541
             				    $values['owner'] = $line[12];
468
-            				    if ($line[28] == '') $values['date_first_reg'] = null;
469
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[28]));
542
+            				    if ($line[28] == '') {
543
+            				    	$values['date_first_reg'] = null;
544
+            				    } else {
545
+					    	$values['date_first_reg'] = date("Y-m-d",strtotime($line[28]));
546
+					    }
470 547
 
471 548
 					    $values['cancel'] = $line[39];
472 549
 					} elseif ($country == 'OE' || $country == '9A' || $country == 'VP' || $country == 'LX' || $country == 'P2' || $country == 'HC') {
@@ -485,29 +562,41 @@  discard block
 block discarded – undo
485 562
             				    $values['registration'] = $line[0];
486 563
             				    $values['base'] = null;
487 564
             				    $values['owner'] = $line[8];
488
-            				    if ($line[7] == '') $values['date_first_reg'] = null;
489
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[7]));
565
+            				    if ($line[7] == '') {
566
+            				    	$values['date_first_reg'] = null;
567
+            				    } else {
568
+					    	$values['date_first_reg'] = date("Y-m-d",strtotime($line[7]));
569
+					    }
490 570
 					    $values['cancel'] = '';
491 571
 					} elseif ($country == 'PP') {
492 572
             				    $values['registration'] = $line[0];
493 573
             				    $values['base'] = null;
494 574
             				    $values['owner'] = $line[4];
495
-            				    if ($line[6] == '') $values['date_first_reg'] = null;
496
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[6]));
575
+            				    if ($line[6] == '') {
576
+            				    	$values['date_first_reg'] = null;
577
+            				    } else {
578
+					    	$values['date_first_reg'] = date("Y-m-d",strtotime($line[6]));
579
+					    }
497 580
 					    $values['cancel'] = $line[7];
498 581
 					} elseif ($country == 'E7') {
499 582
             				    $values['registration'] = $line[0];
500 583
             				    $values['base'] = null;
501 584
             				    $values['owner'] = $line[4];
502
-            				    if ($line[5] == '') $values['date_first_reg'] = null;
503
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[5]));
585
+            				    if ($line[5] == '') {
586
+            				    	$values['date_first_reg'] = null;
587
+            				    } else {
588
+					    	$values['date_first_reg'] = date("Y-m-d",strtotime($line[5]));
589
+					    }
504 590
 					    $values['cancel'] = '';
505 591
 					} elseif ($country == '8Q') {
506 592
             				    $values['registration'] = $line[0];
507 593
             				    $values['base'] = null;
508 594
             				    $values['owner'] = $line[3];
509
-            				    if ($line[7] == '') $values['date_first_reg'] = null;
510
-					    else $values['date_first_reg'] = date("Y-m-d",strtotime($line[7]));
595
+            				    if ($line[7] == '') {
596
+            				    	$values['date_first_reg'] = null;
597
+            				    } else {
598
+					    	$values['date_first_reg'] = date("Y-m-d",strtotime($line[7]));
599
+					    }
511 600
 					    $values['cancel'] = '';
512 601
 					} elseif ($country == 'ZK') {
513 602
             				    $values['registration'] = $line[0];
@@ -552,7 +641,9 @@  discard block
 block discarded – undo
552 641
 						$sth_modes->execute($query_modes_values);
553 642
 					}
554 643
 				}
555
-				if ($globalTransaction) $Connection->db->commit();
644
+				if ($globalTransaction) {
645
+					$Connection->db->commit();
646
+				}
556 647
 			} catch(PDOException $e) {
557 648
 				return "error : ".$e->getMessage();
558 649
 			}
@@ -688,25 +779,45 @@  discard block
 block discarded – undo
688 779
 		    VALUES (:name, :city, :country, :iata, :icao, :latitude, :longitude, :altitude, :type, :home_link, :wikipedia_link, :image_thumb, :image)";
689 780
 		$Connection = new Connection();
690 781
 		$sth_dest = $Connection->db->prepare($query_dest);
691
-		if ($globalTransaction) $Connection->db->beginTransaction();
782
+		if ($globalTransaction) {
783
+			$Connection->db->beginTransaction();
784
+		}
692 785
   
693 786
 		$i = 0;
694 787
 		while($row = sparql_fetch_array($result))
695 788
 		{
696 789
 			if ($i >= 1) {
697 790
 			//print_r($row);
698
-			if (!isset($row['iata'])) $row['iata'] = '';
699
-			if (!isset($row['icao'])) $row['icao'] = '';
700
-			if (!isset($row['type'])) $row['type'] = '';
701
-			if (!isset($row['altitude'])) $row['altitude'] = '';
791
+			if (!isset($row['iata'])) {
792
+				$row['iata'] = '';
793
+			}
794
+			if (!isset($row['icao'])) {
795
+				$row['icao'] = '';
796
+			}
797
+			if (!isset($row['type'])) {
798
+				$row['type'] = '';
799
+			}
800
+			if (!isset($row['altitude'])) {
801
+				$row['altitude'] = '';
802
+			}
702 803
 			if (isset($row['city_bis'])) {
703 804
 				$row['city'] = $row['city_bis'];
704 805
 			}
705
-			if (!isset($row['city'])) $row['city'] = '';
706
-			if (!isset($row['country'])) $row['country'] = '';
707
-			if (!isset($row['homepage'])) $row['homepage'] = '';
708
-			if (!isset($row['wikipedia_page'])) $row['wikipedia_page'] = '';
709
-			if (!isset($row['name'])) continue;
806
+			if (!isset($row['city'])) {
807
+				$row['city'] = '';
808
+			}
809
+			if (!isset($row['country'])) {
810
+				$row['country'] = '';
811
+			}
812
+			if (!isset($row['homepage'])) {
813
+				$row['homepage'] = '';
814
+			}
815
+			if (!isset($row['wikipedia_page'])) {
816
+				$row['wikipedia_page'] = '';
817
+			}
818
+			if (!isset($row['name'])) {
819
+				continue;
820
+			}
710 821
 			if (!isset($row['image'])) {
711 822
 				$row['image'] = '';
712 823
 				$row['image_thumb'] = '';
@@ -762,7 +873,9 @@  discard block
 block discarded – undo
762 873
 
763 874
 			$i++;
764 875
 		}
765
-		if ($globalTransaction) $Connection->db->commit();
876
+		if ($globalTransaction) {
877
+			$Connection->db->commit();
878
+		}
766 879
 		/*
767 880
 		echo "Delete duplicate rows...\n";
768 881
 		$query = 'ALTER IGNORE TABLE airport ADD UNIQUE INDEX icaoidx (icao)';
@@ -805,7 +918,9 @@  discard block
 block discarded – undo
805 918
 		$delimiter = ',';
806 919
 		$out_file = $tmp_dir.'airports.csv';
807 920
 		update_db::download('http://ourairports.com/data/airports.csv',$out_file);
808
-		if (!file_exists($out_file) || !is_readable($out_file)) return FALSE;
921
+		if (!file_exists($out_file) || !is_readable($out_file)) {
922
+			return FALSE;
923
+		}
809 924
 		echo "Add data from ourairports.com...\n";
810 925
 
811 926
 		$header = NULL;
@@ -815,8 +930,9 @@  discard block
 block discarded – undo
815 930
 			//$Connection->db->beginTransaction();
816 931
 			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
817 932
 			{
818
-				if(!$header) $header = $row;
819
-				else {
933
+				if(!$header) {
934
+					$header = $row;
935
+				} else {
820 936
 					$data = array();
821 937
 					$data = array_combine($header, $row);
822 938
 					try {
@@ -857,7 +973,9 @@  discard block
 block discarded – undo
857 973
 		echo "Download data from another free database...\n";
858 974
 		$out_file = $tmp_dir.'GlobalAirportDatabase.zip';
859 975
 		update_db::download('http://www.partow.net/downloads/GlobalAirportDatabase.zip',$out_file);
860
-		if (!file_exists($out_file) || !is_readable($out_file)) return FALSE;
976
+		if (!file_exists($out_file) || !is_readable($out_file)) {
977
+			return FALSE;
978
+		}
861 979
 		update_db::unzip($out_file);
862 980
 		$header = NULL;
863 981
 		echo "Add data from another free database...\n";
@@ -868,8 +986,9 @@  discard block
 block discarded – undo
868 986
 			//$Connection->db->beginTransaction();
869 987
 			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
870 988
 			{
871
-				if(!$header) $header = $row;
872
-				else {
989
+				if(!$header) {
990
+					$header = $row;
991
+				} else {
873 992
 					$data = $row;
874 993
 
875 994
 					$query = 'UPDATE airport SET city = :city, country = :country WHERE icao = :icao';
@@ -1042,7 +1161,9 @@  discard block
 block discarded – undo
1042 1161
 		if (($handle = fopen($tmp_dir.'MASTER.txt', 'r')) !== FALSE)
1043 1162
 		{
1044 1163
 			$i = 0;
1045
-			if ($globalTransaction) $Connection->db->beginTransaction();
1164
+			if ($globalTransaction) {
1165
+				$Connection->db->beginTransaction();
1166
+			}
1046 1167
 			while (($data = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
1047 1168
 			{
1048 1169
 				if ($i > 0) {
@@ -1055,7 +1176,9 @@  discard block
 block discarded – undo
1055 1176
 					}
1056 1177
 					$result_search = $sths->fetchAll(PDO::FETCH_ASSOC);
1057 1178
 					if (!empty($result_search)) {
1058
-						if ($globalDebug) echo '.';
1179
+						if ($globalDebug) {
1180
+							echo '.';
1181
+						}
1059 1182
 							//if ($globalDBdriver == 'mysql') {
1060 1183
 							//	$queryi = 'INSERT INTO faamfr (mfr,icao) VALUES (:mfr,:icao) ON DUPLICATE KEY UPDATE icao = :icao';
1061 1184
 							//} else {
@@ -1077,8 +1200,12 @@  discard block
 block discarded – undo
1077 1200
 						}
1078 1201
 						$result_search_mfr = $sthsm->fetchAll(PDO::FETCH_ASSOC);
1079 1202
 						if (!empty($result_search_mfr)) {
1080
-							if (trim($data[16]) == '' && trim($data[23]) != '') $data[16] = $data[23];
1081
-							if (trim($data[16]) == '' && trim($data[15]) != '') $data[16] = $data[15];
1203
+							if (trim($data[16]) == '' && trim($data[23]) != '') {
1204
+								$data[16] = $data[23];
1205
+							}
1206
+							if (trim($data[16]) == '' && trim($data[15]) != '') {
1207
+								$data[16] = $data[15];
1208
+							}
1082 1209
 							$queryf = 'INSERT INTO aircraft_modes (FirstCreated,LastModified,ModeS,ModeSCountry,Registration,ICAOTypeCode,Source) VALUES (:FirstCreated,:LastModified,:ModeS,:ModeSCountry,:Registration,:ICAOTypeCode,:source)';
1083 1210
 							try {
1084 1211
 								$sthf = $Connection->db->prepare($queryf);
@@ -1089,7 +1216,9 @@  discard block
 block discarded – undo
1089 1216
 						}
1090 1217
 					}
1091 1218
 					if (strtotime($data[29]) > time()) {
1092
-						if ($globalDebug) echo 'i';
1219
+						if ($globalDebug) {
1220
+							echo 'i';
1221
+						}
1093 1222
 						$query = 'INSERT INTO aircraft_owner (registration,base,owner,date_first_reg,Source) VALUES (:registration,:base,:owner,:date_first_reg,:source)';
1094 1223
 						try {
1095 1224
 							$sth = $Connection->db->prepare($query);
@@ -1100,13 +1229,19 @@  discard block
 block discarded – undo
1100 1229
 					}
1101 1230
 				}
1102 1231
 				if ($i % 90 == 0) {
1103
-					if ($globalTransaction) $Connection->db->commit();
1104
-					if ($globalTransaction) $Connection->db->beginTransaction();
1232
+					if ($globalTransaction) {
1233
+						$Connection->db->commit();
1234
+					}
1235
+					if ($globalTransaction) {
1236
+						$Connection->db->beginTransaction();
1237
+					}
1105 1238
 				}
1106 1239
 				$i++;
1107 1240
 			}
1108 1241
 			fclose($handle);
1109
-			if ($globalTransaction) $Connection->db->commit();
1242
+			if ($globalTransaction) {
1243
+				$Connection->db->commit();
1244
+			}
1110 1245
 		}
1111 1246
 		print_r($mfr);
1112 1247
 		return '';
@@ -1131,11 +1266,15 @@  discard block
 block discarded – undo
1131 1266
 			$i = 0;
1132 1267
 			//$Connection->db->setAttribute(PDO::ATTR_AUTOCOMMIT, FALSE);
1133 1268
 			//$Connection->db->beginTransaction();
1134
-			if ($globalTransaction) $Connection->db->beginTransaction();
1269
+			if ($globalTransaction) {
1270
+				$Connection->db->beginTransaction();
1271
+			}
1135 1272
 			while (($data = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
1136 1273
 			{
1137 1274
 				if ($i > 0) {
1138
-					if ($data[1] == 'NULL') $data[1] = $data[0];
1275
+					if ($data[1] == 'NULL') {
1276
+						$data[1] = $data[0];
1277
+					}
1139 1278
 					$query = 'INSERT INTO aircraft_modes (FirstCreated,LastModified,ModeS,ModeSCountry,Registration,ICAOTypeCode,type_flight,Source) VALUES (:FirstCreated,:LastModified,:ModeS,:ModeSCountry,:Registration,:ICAOTypeCode,:type_flight,:source)';
1140 1279
 					try {
1141 1280
 						$sth = $Connection->db->prepare($query);
@@ -1147,7 +1286,9 @@  discard block
 block discarded – undo
1147 1286
 				$i++;
1148 1287
 			}
1149 1288
 			fclose($handle);
1150
-			if ($globalTransaction) $Connection->db->commit();
1289
+			if ($globalTransaction) {
1290
+				$Connection->db->commit();
1291
+			}
1151 1292
 		}
1152 1293
 		return '';
1153 1294
         }
@@ -1168,7 +1309,9 @@  discard block
 block discarded – undo
1168 1309
 		if (($handle = fopen($tmp_dir.'owners.tsv', 'r')) !== FALSE)
1169 1310
 		{
1170 1311
 			$i = 0;
1171
-			if ($globalTransaction) $Connection->db->beginTransaction();
1312
+			if ($globalTransaction) {
1313
+				$Connection->db->beginTransaction();
1314
+			}
1172 1315
 			while (($data = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
1173 1316
 			{
1174 1317
 				if ($i > 0) {
@@ -1184,7 +1327,9 @@  discard block
 block discarded – undo
1184 1327
 				$i++;
1185 1328
 			}
1186 1329
 			fclose($handle);
1187
-			if ($globalTransaction) $Connection->db->commit();
1330
+			if ($globalTransaction) {
1331
+				$Connection->db->commit();
1332
+			}
1188 1333
 		}
1189 1334
 		return '';
1190 1335
         }
@@ -1204,7 +1349,9 @@  discard block
 block discarded – undo
1204 1349
 		if (($handle = fopen($tmp_dir.'routes.tsv', 'r')) !== FALSE)
1205 1350
 		{
1206 1351
 			$i = 0;
1207
-			if ($globalTransaction) $Connection->db->beginTransaction();
1352
+			if ($globalTransaction) {
1353
+				$Connection->db->beginTransaction();
1354
+			}
1208 1355
 			while (($data = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
1209 1356
 			{
1210 1357
 				if ($i > 0) {
@@ -1213,13 +1360,17 @@  discard block
 block discarded – undo
1213 1360
 						$sth = $Connection->db->prepare($query);
1214 1361
 						$sth->execute(array(':CallSign' => $data[0],':Operator_ICAO' => $data[1],':FromAirport_ICAO' => $data[2],':FromAirport_Time' => $data[3], ':ToAirport_ICAO' => $data[4],':ToAirport_Time' => $data[5],':RouteStop' => $data[6],':source' => 'website_fam'));
1215 1362
 					} catch(PDOException $e) {
1216
-						if ($globalDebug) echo "error: ".$e->getMessage()." - data: ".implode(',',$data);
1363
+						if ($globalDebug) {
1364
+							echo "error: ".$e->getMessage()." - data: ".implode(',',$data);
1365
+						}
1217 1366
 					}
1218 1367
 				}
1219 1368
 				$i++;
1220 1369
 			}
1221 1370
 			fclose($handle);
1222
-			if ($globalTransaction) $Connection->db->commit();
1371
+			if ($globalTransaction) {
1372
+				$Connection->db->commit();
1373
+			}
1223 1374
 		}
1224 1375
 		return '';
1225 1376
         }
@@ -1244,7 +1395,9 @@  discard block
 block discarded – undo
1244 1395
 			$i = 0;
1245 1396
 			//$Connection->db->setAttribute(PDO::ATTR_AUTOCOMMIT, FALSE);
1246 1397
 			//$Connection->db->beginTransaction();
1247
-			if ($globalTransaction) $Connection->db->beginTransaction();
1398
+			if ($globalTransaction) {
1399
+				$Connection->db->beginTransaction();
1400
+			}
1248 1401
 			while (($data = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
1249 1402
 			{
1250 1403
 				if ($i > 0) {
@@ -1260,7 +1413,9 @@  discard block
 block discarded – undo
1260 1413
 				$i++;
1261 1414
 			}
1262 1415
 			fclose($handle);
1263
-			if ($globalTransaction) $Connection->db->commit();
1416
+			if ($globalTransaction) {
1417
+				$Connection->db->commit();
1418
+			}
1264 1419
 		}
1265 1420
 		return '';
1266 1421
         }
@@ -1279,7 +1434,9 @@  discard block
 block discarded – undo
1279 1434
 		$Connection = new Connection();
1280 1435
 		if (($handle = fopen($tmp_dir.'ban_eu.csv', 'r')) !== FALSE)
1281 1436
 		{
1282
-			if ($globalTransaction) $Connection->db->beginTransaction();
1437
+			if ($globalTransaction) {
1438
+				$Connection->db->beginTransaction();
1439
+			}
1283 1440
 			while (($data = fgetcsv($handle, 1000)) !== FALSE)
1284 1441
 			{
1285 1442
 				$query = 'UPDATE airlines SET ban_eu = 1 WHERE icao = :icao AND forsource IS NULL';
@@ -1294,7 +1451,9 @@  discard block
 block discarded – undo
1294 1451
 				}
1295 1452
 			}
1296 1453
 			fclose($handle);
1297
-			if ($globalTransaction) $Connection->db->commit();
1454
+			if ($globalTransaction) {
1455
+				$Connection->db->commit();
1456
+			}
1298 1457
 		}
1299 1458
 		return '';
1300 1459
         }
@@ -1445,7 +1604,9 @@  discard block
 block discarded – undo
1445 1604
 		if (($handle = fopen($filename, 'r')) !== FALSE)
1446 1605
 		{
1447 1606
 			$i = 0;
1448
-			if ($globalTransaction) $Connection->db->beginTransaction();
1607
+			if ($globalTransaction) {
1608
+				$Connection->db->beginTransaction();
1609
+			}
1449 1610
 			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
1450 1611
 			{
1451 1612
 				$i++;
@@ -1473,7 +1634,9 @@  discard block
 block discarded – undo
1473 1634
 				}
1474 1635
 			}
1475 1636
 			fclose($handle);
1476
-			if ($globalTransaction) $Connection->db->commit();
1637
+			if ($globalTransaction) {
1638
+				$Connection->db->commit();
1639
+			}
1477 1640
 		}
1478 1641
 		return '';
1479 1642
         }
@@ -1496,7 +1659,9 @@  discard block
 block discarded – undo
1496 1659
 		$Connection = new Connection();
1497 1660
 		if (($handle = fopen($filename, 'r')) !== FALSE)
1498 1661
 		{
1499
-			if ($globalTransaction) $Connection->db->beginTransaction();
1662
+			if ($globalTransaction) {
1663
+				$Connection->db->beginTransaction();
1664
+			}
1500 1665
 			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
1501 1666
 			{
1502 1667
 				if(count($row) > 1) {
@@ -1510,7 +1675,9 @@  discard block
 block discarded – undo
1510 1675
 				}
1511 1676
 			}
1512 1677
 			fclose($handle);
1513
-			if ($globalTransaction) $Connection->db->commit();
1678
+			if ($globalTransaction) {
1679
+				$Connection->db->commit();
1680
+			}
1514 1681
 		}
1515 1682
 		return '';
1516 1683
         }
@@ -1530,8 +1697,9 @@  discard block
 block discarded – undo
1530 1697
 	        }
1531 1698
 
1532 1699
 
1533
-		if ($globalDBdriver == 'mysql') update_db::gunzip('../db/airspace.sql.gz',$tmp_dir.'airspace.sql');
1534
-		else {
1700
+		if ($globalDBdriver == 'mysql') {
1701
+			update_db::gunzip('../db/airspace.sql.gz',$tmp_dir.'airspace.sql');
1702
+		} else {
1535 1703
 			update_db::gunzip('../db/pgsql/airspace.sql.gz',$tmp_dir.'airspace.sql');
1536 1704
 			$query = "CREATE EXTENSION postgis";
1537 1705
 			$Connection = new Connection(null,null,$_SESSION['database_root'],$_SESSION['database_rootpass']);
@@ -1550,20 +1718,30 @@  discard block
 block discarded – undo
1550 1718
 		global $tmp_dir, $globalDebug;
1551 1719
 		include_once('class.create_db.php');
1552 1720
 		require_once(dirname(__FILE__).'/../require/class.NOTAM.php');
1553
-		if ($globalDebug) echo "NOTAM from FlightAirMap website : Download...";
1721
+		if ($globalDebug) {
1722
+			echo "NOTAM from FlightAirMap website : Download...";
1723
+		}
1554 1724
 		update_db::download('http://data.flightairmap.fr/data/notam.txt.gz',$tmp_dir.'notam.txt.gz');
1555 1725
 		$error = '';
1556 1726
 		if (file_exists($tmp_dir.'notam.txt.gz')) {
1557
-			if ($globalDebug) echo "Gunzip...";
1727
+			if ($globalDebug) {
1728
+				echo "Gunzip...";
1729
+			}
1558 1730
 			update_db::gunzip($tmp_dir.'notam.txt.gz');
1559
-			if ($globalDebug) echo "Add to DB...";
1731
+			if ($globalDebug) {
1732
+				echo "Add to DB...";
1733
+			}
1560 1734
 			//$error = create_db::import_file($tmp_dir.'notam.sql');
1561 1735
 			$NOTAM = new NOTAM();
1562 1736
 			$NOTAM->updateNOTAMfromTextFile($tmp_dir.'notam.txt');
1563
-		} else $error = "File ".$tmp_dir.'notam.txt.gz'." doesn't exist. Download failed.";
1737
+		} else {
1738
+			$error = "File ".$tmp_dir.'notam.txt.gz'." doesn't exist. Download failed.";
1739
+		}
1564 1740
 		if ($error != '') {
1565 1741
 			return $error;
1566
-		} elseif ($globalDebug) echo "Done\n";
1742
+		} elseif ($globalDebug) {
1743
+			echo "Done\n";
1744
+		}
1567 1745
 		return '';
1568 1746
 	}
1569 1747
 
@@ -1617,67 +1795,111 @@  discard block
 block discarded – undo
1617 1795
 		//if ($globalDebug) echo "IVAO : Download...";
1618 1796
 		//update_db::download('http://fr.mirror.ivao.aero/software/ivae_feb2013.zip',$tmp_dir.'ivae_feb2013.zip');
1619 1797
 		if (file_exists($tmp_dir.'ivae_feb2013.zip')) {
1620
-			if ($globalDebug) echo "Unzip...";
1798
+			if ($globalDebug) {
1799
+				echo "Unzip...";
1800
+			}
1621 1801
 			update_db::unzip($tmp_dir.'ivae_feb2013.zip');
1622
-			if ($globalDebug) echo "Add to DB...";
1802
+			if ($globalDebug) {
1803
+				echo "Add to DB...";
1804
+			}
1623 1805
 			update_db::ivao_airlines($tmp_dir.'data/airlines.dat');
1624
-			if ($globalDebug) echo "Copy airlines logos to airlines images directory...";
1806
+			if ($globalDebug) {
1807
+				echo "Copy airlines logos to airlines images directory...";
1808
+			}
1625 1809
 			if (is_writable(dirname(__FILE__).'/../images/airlines')) {
1626
-				if (!$Common->xcopy($tmp_dir.'logos/',dirname(__FILE__).'/../images/airlines/')) $error = "Failed to copy airlines logo.";
1627
-			} else $error = "The directory ".dirname(__FILE__).'/../images/airlines'." must be writable";
1628
-		} else $error = "File ".$tmp_dir.'ivao.zip'." doesn't exist. Download failed.";
1810
+				if (!$Common->xcopy($tmp_dir.'logos/',dirname(__FILE__).'/../images/airlines/')) {
1811
+					$error = "Failed to copy airlines logo.";
1812
+				}
1813
+			} else {
1814
+				$error = "The directory ".dirname(__FILE__).'/../images/airlines'." must be writable";
1815
+			}
1816
+		} else {
1817
+			$error = "File ".$tmp_dir.'ivao.zip'." doesn't exist. Download failed.";
1818
+		}
1629 1819
 		if ($error != '') {
1630 1820
 			return $error;
1631
-		} elseif ($globalDebug) echo "Done\n";
1821
+		} elseif ($globalDebug) {
1822
+			echo "Done\n";
1823
+		}
1632 1824
 		return '';
1633 1825
 	}
1634 1826
 
1635 1827
 	public static function update_routes() {
1636 1828
 		global $tmp_dir, $globalDebug;
1637 1829
 		$error = '';
1638
-		if ($globalDebug) echo "Routes : Download...";
1830
+		if ($globalDebug) {
1831
+			echo "Routes : Download...";
1832
+		}
1639 1833
 		update_db::download('http://www.virtualradarserver.co.uk/Files/StandingData.sqb.gz',$tmp_dir.'StandingData.sqb.gz');
1640 1834
 		if (file_exists($tmp_dir.'StandingData.sqb.gz')) {
1641
-			if ($globalDebug) echo "Gunzip...";
1835
+			if ($globalDebug) {
1836
+				echo "Gunzip...";
1837
+			}
1642 1838
 			update_db::gunzip($tmp_dir.'StandingData.sqb.gz');
1643
-			if ($globalDebug) echo "Add to DB...";
1839
+			if ($globalDebug) {
1840
+				echo "Add to DB...";
1841
+			}
1644 1842
 			$error = update_db::retrieve_route_sqlite_to_dest($tmp_dir.'StandingData.sqb');
1645
-		} else $error = "File ".$tmp_dir.'StandingData.sqb.gz'." doesn't exist. Download failed.";
1843
+		} else {
1844
+			$error = "File ".$tmp_dir.'StandingData.sqb.gz'." doesn't exist. Download failed.";
1845
+		}
1646 1846
 		if ($error != '') {
1647 1847
 			return $error;
1648
-		} elseif ($globalDebug) echo "Done\n";
1848
+		} elseif ($globalDebug) {
1849
+			echo "Done\n";
1850
+		}
1649 1851
 		return '';
1650 1852
 	}
1651 1853
 	public static function update_oneworld() {
1652 1854
 		global $tmp_dir, $globalDebug;
1653 1855
 		$error = '';
1654
-		if ($globalDebug) echo "Schedules Oneworld : Download...";
1856
+		if ($globalDebug) {
1857
+			echo "Schedules Oneworld : Download...";
1858
+		}
1655 1859
 		update_db::download('http://data.flightairmap.fr/data/schedules/oneworld.csv.gz',$tmp_dir.'oneworld.csv.gz');
1656 1860
 		if (file_exists($tmp_dir.'oneworld.csv.gz')) {
1657
-			if ($globalDebug) echo "Gunzip...";
1861
+			if ($globalDebug) {
1862
+				echo "Gunzip...";
1863
+			}
1658 1864
 			update_db::gunzip($tmp_dir.'oneworld.csv.gz');
1659
-			if ($globalDebug) echo "Add to DB...";
1865
+			if ($globalDebug) {
1866
+				echo "Add to DB...";
1867
+			}
1660 1868
 			$error = update_db::retrieve_route_oneworld($tmp_dir.'oneworld.csv');
1661
-		} else $error = "File ".$tmp_dir.'oneworld.csv.gz'." doesn't exist. Download failed.";
1869
+		} else {
1870
+			$error = "File ".$tmp_dir.'oneworld.csv.gz'." doesn't exist. Download failed.";
1871
+		}
1662 1872
 		if ($error != '') {
1663 1873
 			return $error;
1664
-		} elseif ($globalDebug) echo "Done\n";
1874
+		} elseif ($globalDebug) {
1875
+			echo "Done\n";
1876
+		}
1665 1877
 		return '';
1666 1878
 	}
1667 1879
 	public static function update_skyteam() {
1668 1880
 		global $tmp_dir, $globalDebug;
1669 1881
 		$error = '';
1670
-		if ($globalDebug) echo "Schedules Skyteam : Download...";
1882
+		if ($globalDebug) {
1883
+			echo "Schedules Skyteam : Download...";
1884
+		}
1671 1885
 		update_db::download('http://data.flightairmap.fr/data/schedules/skyteam.csv.gz',$tmp_dir.'skyteam.csv.gz');
1672 1886
 		if (file_exists($tmp_dir.'skyteam.csv.gz')) {
1673
-			if ($globalDebug) echo "Gunzip...";
1887
+			if ($globalDebug) {
1888
+				echo "Gunzip...";
1889
+			}
1674 1890
 			update_db::gunzip($tmp_dir.'skyteam.csv.gz');
1675
-			if ($globalDebug) echo "Add to DB...";
1891
+			if ($globalDebug) {
1892
+				echo "Add to DB...";
1893
+			}
1676 1894
 			$error = update_db::retrieve_route_skyteam($tmp_dir.'skyteam.csv');
1677
-		} else $error = "File ".$tmp_dir.'skyteam.csv.gz'." doesn't exist. Download failed.";
1895
+		} else {
1896
+			$error = "File ".$tmp_dir.'skyteam.csv.gz'." doesn't exist. Download failed.";
1897
+		}
1678 1898
 		if ($error != '') {
1679 1899
 			return $error;
1680
-		} elseif ($globalDebug) echo "Done\n";
1900
+		} elseif ($globalDebug) {
1901
+			echo "Done\n";
1902
+		}
1681 1903
 		return '';
1682 1904
 	}
1683 1905
 	public static function update_ModeS() {
@@ -1694,355 +1916,619 @@  discard block
 block discarded – undo
1694 1916
 			exit;
1695 1917
 		} elseif ($globalDebug) echo "Done\n";
1696 1918
 */
1697
-		if ($globalDebug) echo "Modes : Download...";
1698
-//		update_db::download('http://planebase.biz/sqb.php?f=basestationall.zip',$tmp_dir.'basestation_latest.zip','http://planebase.biz/bstnsqb');
1919
+		if ($globalDebug) {
1920
+			echo "Modes : Download...";
1921
+		}
1922
+		//		update_db::download('http://planebase.biz/sqb.php?f=basestationall.zip',$tmp_dir.'basestation_latest.zip','http://planebase.biz/bstnsqb');
1699 1923
 		update_db::download('http://data.flightairmap.fr/data/BaseStation.sqb.gz',$tmp_dir.'BaseStation.sqb.gz');
1700 1924
 
1701 1925
 //		if (file_exists($tmp_dir.'basestation_latest.zip')) {
1702 1926
 		if (file_exists($tmp_dir.'BaseStation.sqb.gz')) {
1703
-			if ($globalDebug) echo "Unzip...";
1704
-//			update_db::unzip($tmp_dir.'basestation_latest.zip');
1927
+			if ($globalDebug) {
1928
+				echo "Unzip...";
1929
+			}
1930
+			//			update_db::unzip($tmp_dir.'basestation_latest.zip');
1705 1931
 			update_db::gunzip($tmp_dir.'BaseStation.sqb.gz');
1706
-			if ($globalDebug) echo "Add to DB...";
1932
+			if ($globalDebug) {
1933
+				echo "Add to DB...";
1934
+			}
1707 1935
 			$error = update_db::retrieve_modes_sqlite_to_dest($tmp_dir.'BaseStation.sqb');
1708 1936
 //			$error = update_db::retrieve_modes_sqlite_to_dest($tmp_dir.'basestation.sqb');
1709
-		} else $error = "File ".$tmp_dir.'basestation_latest.zip'." doesn't exist. Download failed.";
1937
+		} else {
1938
+			$error = "File ".$tmp_dir.'basestation_latest.zip'." doesn't exist. Download failed.";
1939
+		}
1710 1940
 		if ($error != '') {
1711 1941
 			return $error;
1712
-		} elseif ($globalDebug) echo "Done\n";
1942
+		} elseif ($globalDebug) {
1943
+			echo "Done\n";
1944
+		}
1713 1945
 		return '';
1714 1946
 	}
1715 1947
 
1716 1948
 	public static function update_ModeS_faa() {
1717 1949
 		global $tmp_dir, $globalDebug;
1718
-		if ($globalDebug) echo "Modes FAA: Download...";
1950
+		if ($globalDebug) {
1951
+			echo "Modes FAA: Download...";
1952
+		}
1719 1953
 		update_db::download('http://registry.faa.gov/database/ReleasableAircraft.zip',$tmp_dir.'ReleasableAircraft.zip');
1720 1954
 		if (file_exists($tmp_dir.'ReleasableAircraft.zip')) {
1721
-			if ($globalDebug) echo "Unzip...";
1955
+			if ($globalDebug) {
1956
+				echo "Unzip...";
1957
+			}
1722 1958
 			update_db::unzip($tmp_dir.'ReleasableAircraft.zip');
1723
-			if ($globalDebug) echo "Add to DB...";
1959
+			if ($globalDebug) {
1960
+				echo "Add to DB...";
1961
+			}
1724 1962
 			$error = update_db::modes_faa();
1725
-		} else $error = "File ".$tmp_dir.'ReleasableAircraft.zip'." doesn't exist. Download failed.";
1963
+		} else {
1964
+			$error = "File ".$tmp_dir.'ReleasableAircraft.zip'." doesn't exist. Download failed.";
1965
+		}
1726 1966
 		if ($error != '') {
1727 1967
 			return $error;
1728
-		} elseif ($globalDebug) echo "Done\n";
1968
+		} elseif ($globalDebug) {
1969
+			echo "Done\n";
1970
+		}
1729 1971
 		return '';
1730 1972
 	}
1731 1973
 
1732 1974
 	public static function update_ModeS_flarm() {
1733 1975
 		global $tmp_dir, $globalDebug;
1734
-		if ($globalDebug) echo "Modes Flarmnet: Download...";
1976
+		if ($globalDebug) {
1977
+			echo "Modes Flarmnet: Download...";
1978
+		}
1735 1979
 		update_db::download('http://flarmnet.org/files/data.fln',$tmp_dir.'data.fln');
1736 1980
 		if (file_exists($tmp_dir.'data.fln')) {
1737
-			if ($globalDebug) echo "Add to DB...";
1981
+			if ($globalDebug) {
1982
+				echo "Add to DB...";
1983
+			}
1738 1984
 			$error = update_db::retrieve_modes_flarmnet($tmp_dir.'data.fln');
1739
-		} else $error = "File ".$tmp_dir.'data.fln'." doesn't exist. Download failed.";
1985
+		} else {
1986
+			$error = "File ".$tmp_dir.'data.fln'." doesn't exist. Download failed.";
1987
+		}
1740 1988
 		if ($error != '') {
1741 1989
 			return $error;
1742
-		} elseif ($globalDebug) echo "Done\n";
1990
+		} elseif ($globalDebug) {
1991
+			echo "Done\n";
1992
+		}
1743 1993
 		return '';
1744 1994
 	}
1745 1995
 
1746 1996
 	public static function update_ModeS_ogn() {
1747 1997
 		global $tmp_dir, $globalDebug;
1748
-		if ($globalDebug) echo "Modes OGN: Download...";
1998
+		if ($globalDebug) {
1999
+			echo "Modes OGN: Download...";
2000
+		}
1749 2001
 		update_db::download('http://ddb.glidernet.org/download/',$tmp_dir.'ogn.csv');
1750 2002
 		if (file_exists($tmp_dir.'ogn.csv')) {
1751
-			if ($globalDebug) echo "Add to DB...";
2003
+			if ($globalDebug) {
2004
+				echo "Add to DB...";
2005
+			}
1752 2006
 			$error = update_db::retrieve_modes_ogn($tmp_dir.'ogn.csv');
1753
-		} else $error = "File ".$tmp_dir.'ogn.csv'." doesn't exist. Download failed.";
2007
+		} else {
2008
+			$error = "File ".$tmp_dir.'ogn.csv'." doesn't exist. Download failed.";
2009
+		}
1754 2010
 		if ($error != '') {
1755 2011
 			return $error;
1756
-		} elseif ($globalDebug) echo "Done\n";
2012
+		} elseif ($globalDebug) {
2013
+			echo "Done\n";
2014
+		}
1757 2015
 		return '';
1758 2016
 	}
1759 2017
 
1760 2018
 	public static function update_owner() {
1761 2019
 		global $tmp_dir, $globalDebug, $globalMasterSource;
1762 2020
 		
1763
-		if ($globalDebug) echo "Owner France: Download...";
2021
+		if ($globalDebug) {
2022
+			echo "Owner France: Download...";
2023
+		}
1764 2024
 		update_db::download('http://antonakis.co.uk/registers/France.txt',$tmp_dir.'owner_f.csv');
1765 2025
 		if (file_exists($tmp_dir.'owner_f.csv')) {
1766
-			if ($globalDebug) echo "Add to DB...";
2026
+			if ($globalDebug) {
2027
+				echo "Add to DB...";
2028
+			}
1767 2029
 			$error = update_db::retrieve_owner($tmp_dir.'owner_f.csv','F');
1768
-		} else $error = "File ".$tmp_dir.'owner_f.csv'." doesn't exist. Download failed.";
2030
+		} else {
2031
+			$error = "File ".$tmp_dir.'owner_f.csv'." doesn't exist. Download failed.";
2032
+		}
1769 2033
 		if ($error != '') {
1770 2034
 			return $error;
1771
-		} elseif ($globalDebug) echo "Done\n";
2035
+		} elseif ($globalDebug) {
2036
+			echo "Done\n";
2037
+		}
1772 2038
 		
1773
-		if ($globalDebug) echo "Owner Ireland: Download...";
2039
+		if ($globalDebug) {
2040
+			echo "Owner Ireland: Download...";
2041
+		}
1774 2042
 		update_db::download('http://antonakis.co.uk/registers/Ireland.txt',$tmp_dir.'owner_ei.csv');
1775 2043
 		if (file_exists($tmp_dir.'owner_ei.csv')) {
1776
-			if ($globalDebug) echo "Add to DB...";
2044
+			if ($globalDebug) {
2045
+				echo "Add to DB...";
2046
+			}
1777 2047
 			$error = update_db::retrieve_owner($tmp_dir.'owner_ei.csv','EI');
1778
-		} else $error = "File ".$tmp_dir.'owner_ei.csv'." doesn't exist. Download failed.";
2048
+		} else {
2049
+			$error = "File ".$tmp_dir.'owner_ei.csv'." doesn't exist. Download failed.";
2050
+		}
1779 2051
 		if ($error != '') {
1780 2052
 			return $error;
1781
-		} elseif ($globalDebug) echo "Done\n";
1782
-		if ($globalDebug) echo "Owner Switzerland: Download...";
2053
+		} elseif ($globalDebug) {
2054
+			echo "Done\n";
2055
+		}
2056
+		if ($globalDebug) {
2057
+			echo "Owner Switzerland: Download...";
2058
+		}
1783 2059
 		update_db::download('http://antonakis.co.uk/registers/Switzerland.txt',$tmp_dir.'owner_hb.csv');
1784 2060
 		if (file_exists($tmp_dir.'owner_hb.csv')) {
1785
-			if ($globalDebug) echo "Add to DB...";
2061
+			if ($globalDebug) {
2062
+				echo "Add to DB...";
2063
+			}
1786 2064
 			$error = update_db::retrieve_owner($tmp_dir.'owner_hb.csv','HB');
1787
-		} else $error = "File ".$tmp_dir.'owner_hb.csv'." doesn't exist. Download failed.";
2065
+		} else {
2066
+			$error = "File ".$tmp_dir.'owner_hb.csv'." doesn't exist. Download failed.";
2067
+		}
1788 2068
 		if ($error != '') {
1789 2069
 			return $error;
1790
-		} elseif ($globalDebug) echo "Done\n";
1791
-		if ($globalDebug) echo "Owner Czech Republic: Download...";
2070
+		} elseif ($globalDebug) {
2071
+			echo "Done\n";
2072
+		}
2073
+		if ($globalDebug) {
2074
+			echo "Owner Czech Republic: Download...";
2075
+		}
1792 2076
 		update_db::download('http://antonakis.co.uk/registers/CzechRepublic.txt',$tmp_dir.'owner_ok.csv');
1793 2077
 		if (file_exists($tmp_dir.'owner_ok.csv')) {
1794
-			if ($globalDebug) echo "Add to DB...";
2078
+			if ($globalDebug) {
2079
+				echo "Add to DB...";
2080
+			}
1795 2081
 			$error = update_db::retrieve_owner($tmp_dir.'owner_ok.csv','OK');
1796
-		} else $error = "File ".$tmp_dir.'owner_ok.csv'." doesn't exist. Download failed.";
2082
+		} else {
2083
+			$error = "File ".$tmp_dir.'owner_ok.csv'." doesn't exist. Download failed.";
2084
+		}
1797 2085
 		if ($error != '') {
1798 2086
 			return $error;
1799
-		} elseif ($globalDebug) echo "Done\n";
1800
-		if ($globalDebug) echo "Owner Australia: Download...";
2087
+		} elseif ($globalDebug) {
2088
+			echo "Done\n";
2089
+		}
2090
+		if ($globalDebug) {
2091
+			echo "Owner Australia: Download...";
2092
+		}
1801 2093
 		update_db::download('http://antonakis.co.uk/registers/Australia.txt',$tmp_dir.'owner_vh.csv');
1802 2094
 		if (file_exists($tmp_dir.'owner_vh.csv')) {
1803
-			if ($globalDebug) echo "Add to DB...";
2095
+			if ($globalDebug) {
2096
+				echo "Add to DB...";
2097
+			}
1804 2098
 			$error = update_db::retrieve_owner($tmp_dir.'owner_vh.csv','VH');
1805
-		} else $error = "File ".$tmp_dir.'owner_vh.csv'." doesn't exist. Download failed.";
2099
+		} else {
2100
+			$error = "File ".$tmp_dir.'owner_vh.csv'." doesn't exist. Download failed.";
2101
+		}
1806 2102
 		if ($error != '') {
1807 2103
 			return $error;
1808
-		} elseif ($globalDebug) echo "Done\n";
1809
-		if ($globalDebug) echo "Owner Austria: Download...";
2104
+		} elseif ($globalDebug) {
2105
+			echo "Done\n";
2106
+		}
2107
+		if ($globalDebug) {
2108
+			echo "Owner Austria: Download...";
2109
+		}
1810 2110
 		update_db::download('http://antonakis.co.uk/registers/Austria.txt',$tmp_dir.'owner_oe.csv');
1811 2111
 		if (file_exists($tmp_dir.'owner_oe.csv')) {
1812
-			if ($globalDebug) echo "Add to DB...";
2112
+			if ($globalDebug) {
2113
+				echo "Add to DB...";
2114
+			}
1813 2115
 			$error = update_db::retrieve_owner($tmp_dir.'owner_oe.csv','OE');
1814
-		} else $error = "File ".$tmp_dir.'owner_oe.csv'." doesn't exist. Download failed.";
2116
+		} else {
2117
+			$error = "File ".$tmp_dir.'owner_oe.csv'." doesn't exist. Download failed.";
2118
+		}
1815 2119
 		if ($error != '') {
1816 2120
 			return $error;
1817
-		} elseif ($globalDebug) echo "Done\n";
1818
-		if ($globalDebug) echo "Owner Chile: Download...";
2121
+		} elseif ($globalDebug) {
2122
+			echo "Done\n";
2123
+		}
2124
+		if ($globalDebug) {
2125
+			echo "Owner Chile: Download...";
2126
+		}
1819 2127
 		update_db::download('http://antonakis.co.uk/registers/Chile.txt',$tmp_dir.'owner_cc.csv');
1820 2128
 		if (file_exists($tmp_dir.'owner_cc.csv')) {
1821
-			if ($globalDebug) echo "Add to DB...";
2129
+			if ($globalDebug) {
2130
+				echo "Add to DB...";
2131
+			}
1822 2132
 			$error = update_db::retrieve_owner($tmp_dir.'owner_cc.csv','CC');
1823
-		} else $error = "File ".$tmp_dir.'owner_cc.csv'." doesn't exist. Download failed.";
2133
+		} else {
2134
+			$error = "File ".$tmp_dir.'owner_cc.csv'." doesn't exist. Download failed.";
2135
+		}
1824 2136
 		if ($error != '') {
1825 2137
 			return $error;
1826
-		} elseif ($globalDebug) echo "Done\n";
1827
-		if ($globalDebug) echo "Owner Colombia: Download...";
2138
+		} elseif ($globalDebug) {
2139
+			echo "Done\n";
2140
+		}
2141
+		if ($globalDebug) {
2142
+			echo "Owner Colombia: Download...";
2143
+		}
1828 2144
 		update_db::download('http://antonakis.co.uk/registers/Colombia.txt',$tmp_dir.'owner_hj.csv');
1829 2145
 		if (file_exists($tmp_dir.'owner_hj.csv')) {
1830
-			if ($globalDebug) echo "Add to DB...";
2146
+			if ($globalDebug) {
2147
+				echo "Add to DB...";
2148
+			}
1831 2149
 			$error = update_db::retrieve_owner($tmp_dir.'owner_hj.csv','HJ');
1832
-		} else $error = "File ".$tmp_dir.'owner_hj.csv'." doesn't exist. Download failed.";
2150
+		} else {
2151
+			$error = "File ".$tmp_dir.'owner_hj.csv'." doesn't exist. Download failed.";
2152
+		}
1833 2153
 		if ($error != '') {
1834 2154
 			return $error;
1835
-		} elseif ($globalDebug) echo "Done\n";
1836
-		if ($globalDebug) echo "Owner Bosnia Herzegobina: Download...";
2155
+		} elseif ($globalDebug) {
2156
+			echo "Done\n";
2157
+		}
2158
+		if ($globalDebug) {
2159
+			echo "Owner Bosnia Herzegobina: Download...";
2160
+		}
1837 2161
 		update_db::download('http://antonakis.co.uk/registers/BosniaHerzegovina.txt',$tmp_dir.'owner_e7.csv');
1838 2162
 		if (file_exists($tmp_dir.'owner_e7.csv')) {
1839
-			if ($globalDebug) echo "Add to DB...";
2163
+			if ($globalDebug) {
2164
+				echo "Add to DB...";
2165
+			}
1840 2166
 			$error = update_db::retrieve_owner($tmp_dir.'owner_e7.csv','E7');
1841
-		} else $error = "File ".$tmp_dir.'owner_e7.csv'." doesn't exist. Download failed.";
2167
+		} else {
2168
+			$error = "File ".$tmp_dir.'owner_e7.csv'." doesn't exist. Download failed.";
2169
+		}
1842 2170
 		if ($error != '') {
1843 2171
 			return $error;
1844
-		} elseif ($globalDebug) echo "Done\n";
1845
-		if ($globalDebug) echo "Owner Brazil: Download...";
2172
+		} elseif ($globalDebug) {
2173
+			echo "Done\n";
2174
+		}
2175
+		if ($globalDebug) {
2176
+			echo "Owner Brazil: Download...";
2177
+		}
1846 2178
 		update_db::download('http://antonakis.co.uk/registers/Brazil.txt',$tmp_dir.'owner_pp.csv');
1847 2179
 		if (file_exists($tmp_dir.'owner_pp.csv')) {
1848
-			if ($globalDebug) echo "Add to DB...";
2180
+			if ($globalDebug) {
2181
+				echo "Add to DB...";
2182
+			}
1849 2183
 			$error = update_db::retrieve_owner($tmp_dir.'owner_pp.csv','PP');
1850
-		} else $error = "File ".$tmp_dir.'owner_pp.csv'." doesn't exist. Download failed.";
2184
+		} else {
2185
+			$error = "File ".$tmp_dir.'owner_pp.csv'." doesn't exist. Download failed.";
2186
+		}
1851 2187
 		if ($error != '') {
1852 2188
 			return $error;
1853
-		} elseif ($globalDebug) echo "Done\n";
1854
-		if ($globalDebug) echo "Owner Cayman Islands: Download...";
2189
+		} elseif ($globalDebug) {
2190
+			echo "Done\n";
2191
+		}
2192
+		if ($globalDebug) {
2193
+			echo "Owner Cayman Islands: Download...";
2194
+		}
1855 2195
 		update_db::download('http://antonakis.co.uk/registers/CaymanIslands.txt',$tmp_dir.'owner_vp.csv');
1856 2196
 		if (file_exists($tmp_dir.'owner_vp.csv')) {
1857
-			if ($globalDebug) echo "Add to DB...";
2197
+			if ($globalDebug) {
2198
+				echo "Add to DB...";
2199
+			}
1858 2200
 			$error = update_db::retrieve_owner($tmp_dir.'owner_vp.csv','VP');
1859
-		} else $error = "File ".$tmp_dir.'owner_vp.csv'." doesn't exist. Download failed.";
2201
+		} else {
2202
+			$error = "File ".$tmp_dir.'owner_vp.csv'." doesn't exist. Download failed.";
2203
+		}
1860 2204
 		if ($error != '') {
1861 2205
 			return $error;
1862
-		} elseif ($globalDebug) echo "Done\n";
1863
-		if ($globalDebug) echo "Owner Croatia: Download...";
2206
+		} elseif ($globalDebug) {
2207
+			echo "Done\n";
2208
+		}
2209
+		if ($globalDebug) {
2210
+			echo "Owner Croatia: Download...";
2211
+		}
1864 2212
 		update_db::download('http://antonakis.co.uk/registers/Croatia.txt',$tmp_dir.'owner_9a.csv');
1865 2213
 		if (file_exists($tmp_dir.'owner_9a.csv')) {
1866
-			if ($globalDebug) echo "Add to DB...";
2214
+			if ($globalDebug) {
2215
+				echo "Add to DB...";
2216
+			}
1867 2217
 			$error = update_db::retrieve_owner($tmp_dir.'owner_9a.csv','9A');
1868
-		} else $error = "File ".$tmp_dir.'owner_9a.csv'." doesn't exist. Download failed.";
2218
+		} else {
2219
+			$error = "File ".$tmp_dir.'owner_9a.csv'." doesn't exist. Download failed.";
2220
+		}
1869 2221
 		if ($error != '') {
1870 2222
 			return $error;
1871
-		} elseif ($globalDebug) echo "Done\n";
1872
-		if ($globalDebug) echo "Owner Luxembourg: Download...";
2223
+		} elseif ($globalDebug) {
2224
+			echo "Done\n";
2225
+		}
2226
+		if ($globalDebug) {
2227
+			echo "Owner Luxembourg: Download...";
2228
+		}
1873 2229
 		update_db::download('http://antonakis.co.uk/registers/Luxembourg.txt',$tmp_dir.'owner_lx.csv');
1874 2230
 		if (file_exists($tmp_dir.'owner_lx.csv')) {
1875
-			if ($globalDebug) echo "Add to DB...";
2231
+			if ($globalDebug) {
2232
+				echo "Add to DB...";
2233
+			}
1876 2234
 			$error = update_db::retrieve_owner($tmp_dir.'owner_lx.csv','LX');
1877
-		} else $error = "File ".$tmp_dir.'owner_lx.csv'." doesn't exist. Download failed.";
2235
+		} else {
2236
+			$error = "File ".$tmp_dir.'owner_lx.csv'." doesn't exist. Download failed.";
2237
+		}
1878 2238
 		if ($error != '') {
1879 2239
 			return $error;
1880
-		} elseif ($globalDebug) echo "Done\n";
1881
-		if ($globalDebug) echo "Owner Maldives: Download...";
2240
+		} elseif ($globalDebug) {
2241
+			echo "Done\n";
2242
+		}
2243
+		if ($globalDebug) {
2244
+			echo "Owner Maldives: Download...";
2245
+		}
1882 2246
 		update_db::download('http://antonakis.co.uk/registers/Maldives.txt',$tmp_dir.'owner_8q.csv');
1883 2247
 		if (file_exists($tmp_dir.'owner_8q.csv')) {
1884
-			if ($globalDebug) echo "Add to DB...";
2248
+			if ($globalDebug) {
2249
+				echo "Add to DB...";
2250
+			}
1885 2251
 			$error = update_db::retrieve_owner($tmp_dir.'owner_8q.csv','8Q');
1886
-		} else $error = "File ".$tmp_dir.'owner_8q.csv'." doesn't exist. Download failed.";
2252
+		} else {
2253
+			$error = "File ".$tmp_dir.'owner_8q.csv'." doesn't exist. Download failed.";
2254
+		}
1887 2255
 		if ($error != '') {
1888 2256
 			return $error;
1889
-		} elseif ($globalDebug) echo "Done\n";
1890
-		if ($globalDebug) echo "Owner New Zealand: Download...";
2257
+		} elseif ($globalDebug) {
2258
+			echo "Done\n";
2259
+		}
2260
+		if ($globalDebug) {
2261
+			echo "Owner New Zealand: Download...";
2262
+		}
1891 2263
 		update_db::download('http://antonakis.co.uk/registers/NewZealand.txt',$tmp_dir.'owner_zk.csv');
1892 2264
 		if (file_exists($tmp_dir.'owner_zk.csv')) {
1893
-			if ($globalDebug) echo "Add to DB...";
2265
+			if ($globalDebug) {
2266
+				echo "Add to DB...";
2267
+			}
1894 2268
 			$error = update_db::retrieve_owner($tmp_dir.'owner_zk.csv','ZK');
1895
-		} else $error = "File ".$tmp_dir.'owner_zk.csv'." doesn't exist. Download failed.";
2269
+		} else {
2270
+			$error = "File ".$tmp_dir.'owner_zk.csv'." doesn't exist. Download failed.";
2271
+		}
1896 2272
 		if ($error != '') {
1897 2273
 			return $error;
1898
-		} elseif ($globalDebug) echo "Done\n";
1899
-		if ($globalDebug) echo "Owner Papua New Guinea: Download...";
2274
+		} elseif ($globalDebug) {
2275
+			echo "Done\n";
2276
+		}
2277
+		if ($globalDebug) {
2278
+			echo "Owner Papua New Guinea: Download...";
2279
+		}
1900 2280
 		update_db::download('http://antonakis.co.uk/registers/PapuaNewGuinea.txt',$tmp_dir.'owner_p2.csv');
1901 2281
 		if (file_exists($tmp_dir.'owner_p2.csv')) {
1902
-			if ($globalDebug) echo "Add to DB...";
2282
+			if ($globalDebug) {
2283
+				echo "Add to DB...";
2284
+			}
1903 2285
 			$error = update_db::retrieve_owner($tmp_dir.'owner_p2.csv','P2');
1904
-		} else $error = "File ".$tmp_dir.'owner_p2.csv'." doesn't exist. Download failed.";
2286
+		} else {
2287
+			$error = "File ".$tmp_dir.'owner_p2.csv'." doesn't exist. Download failed.";
2288
+		}
1905 2289
 		if ($error != '') {
1906 2290
 			return $error;
1907
-		} elseif ($globalDebug) echo "Done\n";
1908
-		if ($globalDebug) echo "Owner Slovakia: Download...";
2291
+		} elseif ($globalDebug) {
2292
+			echo "Done\n";
2293
+		}
2294
+		if ($globalDebug) {
2295
+			echo "Owner Slovakia: Download...";
2296
+		}
1909 2297
 		update_db::download('http://antonakis.co.uk/registers/Slovakia.txt',$tmp_dir.'owner_om.csv');
1910 2298
 		if (file_exists($tmp_dir.'owner_om.csv')) {
1911
-			if ($globalDebug) echo "Add to DB...";
2299
+			if ($globalDebug) {
2300
+				echo "Add to DB...";
2301
+			}
1912 2302
 			$error = update_db::retrieve_owner($tmp_dir.'owner_om.csv','OM');
1913
-		} else $error = "File ".$tmp_dir.'owner_om.csv'." doesn't exist. Download failed.";
2303
+		} else {
2304
+			$error = "File ".$tmp_dir.'owner_om.csv'." doesn't exist. Download failed.";
2305
+		}
1914 2306
 		if ($error != '') {
1915 2307
 			return $error;
1916
-		} elseif ($globalDebug) echo "Done\n";
1917
-		if ($globalDebug) echo "Owner Ecuador: Download...";
2308
+		} elseif ($globalDebug) {
2309
+			echo "Done\n";
2310
+		}
2311
+		if ($globalDebug) {
2312
+			echo "Owner Ecuador: Download...";
2313
+		}
1918 2314
 		update_db::download('http://antonakis.co.uk/registers/Ecuador.txt',$tmp_dir.'owner_hc.csv');
1919 2315
 		if (file_exists($tmp_dir.'owner_hc.csv')) {
1920
-			if ($globalDebug) echo "Add to DB...";
2316
+			if ($globalDebug) {
2317
+				echo "Add to DB...";
2318
+			}
1921 2319
 			$error = update_db::retrieve_owner($tmp_dir.'owner_hc.csv','HC');
1922
-		} else $error = "File ".$tmp_dir.'owner_hc.csv'." doesn't exist. Download failed.";
2320
+		} else {
2321
+			$error = "File ".$tmp_dir.'owner_hc.csv'." doesn't exist. Download failed.";
2322
+		}
1923 2323
 		if ($error != '') {
1924 2324
 			return $error;
1925
-		} elseif ($globalDebug) echo "Done\n";
1926
-		if ($globalDebug) echo "Owner Iceland: Download...";
2325
+		} elseif ($globalDebug) {
2326
+			echo "Done\n";
2327
+		}
2328
+		if ($globalDebug) {
2329
+			echo "Owner Iceland: Download...";
2330
+		}
1927 2331
 		update_db::download('http://antonakis.co.uk/registers/Iceland.txt',$tmp_dir.'owner_tf.csv');
1928 2332
 		if (file_exists($tmp_dir.'owner_tf.csv')) {
1929
-			if ($globalDebug) echo "Add to DB...";
2333
+			if ($globalDebug) {
2334
+				echo "Add to DB...";
2335
+			}
1930 2336
 			$error = update_db::retrieve_owner($tmp_dir.'owner_tf.csv','TF');
1931
-		} else $error = "File ".$tmp_dir.'owner_tf.csv'." doesn't exist. Download failed.";
2337
+		} else {
2338
+			$error = "File ".$tmp_dir.'owner_tf.csv'." doesn't exist. Download failed.";
2339
+		}
1932 2340
 		if ($error != '') {
1933 2341
 			return $error;
1934
-		} elseif ($globalDebug) echo "Done\n";
1935
-		if ($globalDebug) echo "Owner Isle of Man: Download...";
2342
+		} elseif ($globalDebug) {
2343
+			echo "Done\n";
2344
+		}
2345
+		if ($globalDebug) {
2346
+			echo "Owner Isle of Man: Download...";
2347
+		}
1936 2348
 		update_db::download('http://antonakis.co.uk/registers/IsleOfMan.txt',$tmp_dir.'owner_m.csv');
1937 2349
 		if (file_exists($tmp_dir.'owner_m.csv')) {
1938
-			if ($globalDebug) echo "Add to DB...";
2350
+			if ($globalDebug) {
2351
+				echo "Add to DB...";
2352
+			}
1939 2353
 			$error = update_db::retrieve_owner($tmp_dir.'owner_m.csv','M');
1940
-		} else $error = "File ".$tmp_dir.'owner_m.csv'." doesn't exist. Download failed.";
2354
+		} else {
2355
+			$error = "File ".$tmp_dir.'owner_m.csv'." doesn't exist. Download failed.";
2356
+		}
1941 2357
 		if ($error != '') {
1942 2358
 			return $error;
1943
-		} elseif ($globalDebug) echo "Done\n";
2359
+		} elseif ($globalDebug) {
2360
+			echo "Done\n";
2361
+		}
1944 2362
 		if ($globalMasterSource) {
1945
-			if ($globalDebug) echo "ModeS Netherlands: Download...";
2363
+			if ($globalDebug) {
2364
+				echo "ModeS Netherlands: Download...";
2365
+			}
1946 2366
 			update_db::download('http://antonakis.co.uk/registers/Netherlands.txt',$tmp_dir.'owner_ph.csv');
1947 2367
 			if (file_exists($tmp_dir.'owner_ph.csv')) {
1948
-				if ($globalDebug) echo "Add to DB...";
2368
+				if ($globalDebug) {
2369
+					echo "Add to DB...";
2370
+				}
1949 2371
 				$error = update_db::retrieve_owner($tmp_dir.'owner_ph.csv','PH');
1950
-			} else $error = "File ".$tmp_dir.'owner_ph.csv'." doesn't exist. Download failed.";
2372
+			} else {
2373
+				$error = "File ".$tmp_dir.'owner_ph.csv'." doesn't exist. Download failed.";
2374
+			}
1951 2375
 			if ($error != '') {
1952 2376
 				return $error;
1953
-			} elseif ($globalDebug) echo "Done\n";
1954
-			if ($globalDebug) echo "ModeS Denmark: Download...";
2377
+			} elseif ($globalDebug) {
2378
+				echo "Done\n";
2379
+			}
2380
+			if ($globalDebug) {
2381
+				echo "ModeS Denmark: Download...";
2382
+			}
1955 2383
 			update_db::download('http://antonakis.co.uk/registers/Denmark.txt',$tmp_dir.'owner_oy.csv');
1956 2384
 			if (file_exists($tmp_dir.'owner_oy.csv')) {
1957
-				if ($globalDebug) echo "Add to DB...";
2385
+				if ($globalDebug) {
2386
+					echo "Add to DB...";
2387
+				}
1958 2388
 				$error = update_db::retrieve_owner($tmp_dir.'owner_oy.csv','OY');
1959
-			} else $error = "File ".$tmp_dir.'owner_oy.csv'." doesn't exist. Download failed.";
2389
+			} else {
2390
+				$error = "File ".$tmp_dir.'owner_oy.csv'." doesn't exist. Download failed.";
2391
+			}
1960 2392
 			if ($error != '') {
1961 2393
 				return $error;
1962
-			} elseif ($globalDebug) echo "Done\n";
1963
-		} elseif ($globalDebug) echo "Done\n";
2394
+			} elseif ($globalDebug) {
2395
+				echo "Done\n";
2396
+			}
2397
+		} elseif ($globalDebug) {
2398
+			echo "Done\n";
2399
+		}
1964 2400
 		return '';
1965 2401
 	}
1966 2402
 
1967 2403
 	public static function update_translation() {
1968 2404
 		global $tmp_dir, $globalDebug;
1969 2405
 		$error = '';
1970
-		if ($globalDebug) echo "Translation : Download...";
2406
+		if ($globalDebug) {
2407
+			echo "Translation : Download...";
2408
+		}
1971 2409
 		update_db::download('http://www.acarsd.org/download/translation.php',$tmp_dir.'translation.zip');
1972 2410
 		if (file_exists($tmp_dir.'translation.zip')) {
1973
-			if ($globalDebug) echo "Unzip...";
2411
+			if ($globalDebug) {
2412
+				echo "Unzip...";
2413
+			}
1974 2414
 			update_db::unzip($tmp_dir.'translation.zip');
1975
-			if ($globalDebug) echo "Add to DB...";
2415
+			if ($globalDebug) {
2416
+				echo "Add to DB...";
2417
+			}
1976 2418
 			$error = update_db::translation();
1977
-		} else $error = "File ".$tmp_dir.'translation.zip'." doesn't exist. Download failed.";
2419
+		} else {
2420
+			$error = "File ".$tmp_dir.'translation.zip'." doesn't exist. Download failed.";
2421
+		}
1978 2422
 		if ($error != '') {
1979 2423
 			return $error;
1980
-		} elseif ($globalDebug) echo "Done\n";
2424
+		} elseif ($globalDebug) {
2425
+			echo "Done\n";
2426
+		}
1981 2427
 		return '';
1982 2428
 	}
1983 2429
 
1984 2430
 	public static function update_translation_fam() {
1985 2431
 		global $tmp_dir, $globalDebug;
1986
-		if ($globalDebug) echo "Translation from FlightAirMap website : Download...";
2432
+		if ($globalDebug) {
2433
+			echo "Translation from FlightAirMap website : Download...";
2434
+		}
1987 2435
 		update_db::download('http://data.flightairmap.fr/data/translation.tsv.gz',$tmp_dir.'translation.tsv.gz');
1988 2436
 		if (file_exists($tmp_dir.'translation.tsv.gz')) {
1989
-			if ($globalDebug) echo "Gunzip...";
2437
+			if ($globalDebug) {
2438
+				echo "Gunzip...";
2439
+			}
1990 2440
 			update_db::gunzip($tmp_dir.'translation.tsv.gz');
1991
-			if ($globalDebug) echo "Add to DB...";
2441
+			if ($globalDebug) {
2442
+				echo "Add to DB...";
2443
+			}
1992 2444
 			$error = update_db::translation_fam();
1993
-		} else $error = "File ".$tmp_dir.'translation.tsv.gz'." doesn't exist. Download failed.";
2445
+		} else {
2446
+			$error = "File ".$tmp_dir.'translation.tsv.gz'." doesn't exist. Download failed.";
2447
+		}
1994 2448
 		if ($error != '') {
1995 2449
 			return $error;
1996
-		} elseif ($globalDebug) echo "Done\n";
2450
+		} elseif ($globalDebug) {
2451
+			echo "Done\n";
2452
+		}
1997 2453
 		return '';
1998 2454
 	}
1999 2455
 	public static function update_ModeS_fam() {
2000 2456
 		global $tmp_dir, $globalDebug;
2001
-		if ($globalDebug) echo "ModeS from FlightAirMap website : Download...";
2457
+		if ($globalDebug) {
2458
+			echo "ModeS from FlightAirMap website : Download...";
2459
+		}
2002 2460
 		update_db::download('http://data.flightairmap.fr/data/modes.tsv.gz',$tmp_dir.'modes.tsv.gz');
2003 2461
 		if (file_exists($tmp_dir.'modes.tsv.gz')) {
2004
-			if ($globalDebug) echo "Gunzip...";
2462
+			if ($globalDebug) {
2463
+				echo "Gunzip...";
2464
+			}
2005 2465
 			update_db::gunzip($tmp_dir.'modes.tsv.gz');
2006
-			if ($globalDebug) echo "Add to DB...";
2466
+			if ($globalDebug) {
2467
+				echo "Add to DB...";
2468
+			}
2007 2469
 			$error = update_db::modes_fam();
2008
-		} else $error = "File ".$tmp_dir.'modes.tsv.gz'." doesn't exist. Download failed.";
2470
+		} else {
2471
+			$error = "File ".$tmp_dir.'modes.tsv.gz'." doesn't exist. Download failed.";
2472
+		}
2009 2473
 		if ($error != '') {
2010 2474
 			return $error;
2011
-		} elseif ($globalDebug) echo "Done\n";
2475
+		} elseif ($globalDebug) {
2476
+			echo "Done\n";
2477
+		}
2012 2478
 		return '';
2013 2479
 	}
2014 2480
 	public static function update_owner_fam() {
2015 2481
 		global $tmp_dir, $globalDebug, $globalOwner;
2016
-		if ($globalDebug) echo "owner from FlightAirMap website : Download...";
2482
+		if ($globalDebug) {
2483
+			echo "owner from FlightAirMap website : Download...";
2484
+		}
2017 2485
 		if ($globalOwner === TRUE) {
2018 2486
 			update_db::download('http://data.flightairmap.fr/data/owners_all.tsv.gz',$tmp_dir.'owners.tsv.gz');
2019 2487
 		} else {
2020 2488
 			update_db::download('http://data.flightairmap.fr/data/owners.tsv.gz',$tmp_dir.'owners.tsv.gz');
2021 2489
 		}
2022 2490
 		if (file_exists($tmp_dir.'owners.tsv.gz')) {
2023
-			if ($globalDebug) echo "Gunzip...";
2491
+			if ($globalDebug) {
2492
+				echo "Gunzip...";
2493
+			}
2024 2494
 			update_db::gunzip($tmp_dir.'owners.tsv.gz');
2025
-			if ($globalDebug) echo "Add to DB...";
2495
+			if ($globalDebug) {
2496
+				echo "Add to DB...";
2497
+			}
2026 2498
 			$error = update_db::owner_fam();
2027
-		} else $error = "File ".$tmp_dir.'owners.tsv.gz'." doesn't exist. Download failed.";
2499
+		} else {
2500
+			$error = "File ".$tmp_dir.'owners.tsv.gz'." doesn't exist. Download failed.";
2501
+		}
2028 2502
 		if ($error != '') {
2029 2503
 			return $error;
2030
-		} elseif ($globalDebug) echo "Done\n";
2504
+		} elseif ($globalDebug) {
2505
+			echo "Done\n";
2506
+		}
2031 2507
 		return '';
2032 2508
 	}
2033 2509
 	public static function update_routes_fam() {
2034 2510
 		global $tmp_dir, $globalDebug;
2035
-		if ($globalDebug) echo "Routes from FlightAirMap website : Download...";
2511
+		if ($globalDebug) {
2512
+			echo "Routes from FlightAirMap website : Download...";
2513
+		}
2036 2514
 		update_db::download('http://data.flightairmap.fr/data/routes.tsv.gz',$tmp_dir.'routes.tsv.gz');
2037 2515
 		if (file_exists($tmp_dir.'routes.tsv.gz')) {
2038
-			if ($globalDebug) echo "Gunzip...";
2516
+			if ($globalDebug) {
2517
+				echo "Gunzip...";
2518
+			}
2039 2519
 			update_db::gunzip($tmp_dir.'routes.tsv.gz');
2040
-			if ($globalDebug) echo "Add to DB...";
2520
+			if ($globalDebug) {
2521
+				echo "Add to DB...";
2522
+			}
2041 2523
 			$error = update_db::routes_fam();
2042
-		} else $error = "File ".$tmp_dir.'routes.tsv.gz'." doesn't exist. Download failed.";
2524
+		} else {
2525
+			$error = "File ".$tmp_dir.'routes.tsv.gz'." doesn't exist. Download failed.";
2526
+		}
2043 2527
 		if ($error != '') {
2044 2528
 			return $error;
2045
-		} elseif ($globalDebug) echo "Done\n";
2529
+		} elseif ($globalDebug) {
2530
+			echo "Done\n";
2531
+		}
2046 2532
 		return '';
2047 2533
 	}
2048 2534
 	public static function update_marine_identity_fam() {
@@ -2052,14 +2538,22 @@  discard block
 block discarded – undo
2052 2538
 			$marine_identity_md5_file = explode(' ',file_get_contents($tmp_dir.'marine_identity.tsv.gz.md5'));
2053 2539
 			$marine_identity_md5 = $marine_identity_md5_file[0];
2054 2540
 			if (!update_db::check_marine_identity_version($marine_identity_md5)) {
2055
-				if ($globalDebug) echo "Marine identity from FlightAirMap website : Download...";
2541
+				if ($globalDebug) {
2542
+					echo "Marine identity from FlightAirMap website : Download...";
2543
+				}
2056 2544
 				update_db::download('http://data.flightairmap.fr/data/marine_identity.tsv.gz',$tmp_dir.'marine_identity.tsv.gz');
2057 2545
 				if (file_exists($tmp_dir.'marine_identity.tsv.gz')) {
2058
-					if ($globalDebug) echo "Gunzip...";
2546
+					if ($globalDebug) {
2547
+						echo "Gunzip...";
2548
+					}
2059 2549
 					update_db::gunzip($tmp_dir.'marine_identity.tsv.gz');
2060
-					if ($globalDebug) echo "Add to DB...";
2550
+					if ($globalDebug) {
2551
+						echo "Add to DB...";
2552
+					}
2061 2553
 					$error = update_db::marine_identity_fam();
2062
-				} else $error = "File ".$tmp_dir.'marine_identity.tsv.gz'." doesn't exist. Download failed.";
2554
+				} else {
2555
+					$error = "File ".$tmp_dir.'marine_identity.tsv.gz'." doesn't exist. Download failed.";
2556
+				}
2063 2557
 				if ($error != '') {
2064 2558
 					return $error;
2065 2559
 				} elseif ($globalDebug) {
@@ -2072,17 +2566,25 @@  discard block
 block discarded – undo
2072 2566
 	}
2073 2567
 	public static function update_banned_fam() {
2074 2568
 		global $tmp_dir, $globalDebug;
2075
-		if ($globalDebug) echo "Banned airlines in Europe from FlightAirMap website : Download...";
2569
+		if ($globalDebug) {
2570
+			echo "Banned airlines in Europe from FlightAirMap website : Download...";
2571
+		}
2076 2572
 		update_db::download('http://data.flightairmap.fr/data/ban-eu.csv',$tmp_dir.'ban_eu.csv');
2077 2573
 		if (file_exists($tmp_dir.'ban_eu.csv')) {
2078 2574
 			//if ($globalDebug) echo "Gunzip...";
2079 2575
 			//update_db::gunzip($tmp_dir.'ban_ue.csv');
2080
-			if ($globalDebug) echo "Add to DB...";
2576
+			if ($globalDebug) {
2577
+				echo "Add to DB...";
2578
+			}
2081 2579
 			$error = update_db::banned_fam();
2082
-		} else $error = "File ".$tmp_dir.'ban_eu.csv'." doesn't exist. Download failed.";
2580
+		} else {
2581
+			$error = "File ".$tmp_dir.'ban_eu.csv'." doesn't exist. Download failed.";
2582
+		}
2083 2583
 		if ($error != '') {
2084 2584
 			return $error;
2085
-		} elseif ($globalDebug) echo "Done\n";
2585
+		} elseif ($globalDebug) {
2586
+			echo "Done\n";
2587
+		}
2086 2588
 		return '';
2087 2589
 	}
2088 2590
 
@@ -2090,7 +2592,9 @@  discard block
 block discarded – undo
2090 2592
 		global $tmp_dir, $globalDebug, $globalDBdriver;
2091 2593
 		include_once('class.create_db.php');
2092 2594
 		$error = '';
2093
-		if ($globalDebug) echo "Airspace from FlightAirMap website : Download...";
2595
+		if ($globalDebug) {
2596
+			echo "Airspace from FlightAirMap website : Download...";
2597
+		}
2094 2598
 		if ($globalDBdriver == 'mysql') {
2095 2599
 			update_db::download('http://data.flightairmap.fr/data/airspace_mysql.sql.gz.md5',$tmp_dir.'airspace.sql.gz.md5');
2096 2600
 		} else {
@@ -2106,9 +2610,13 @@  discard block
 block discarded – undo
2106 2610
 					update_db::download('http://data.flightairmap.fr/data/airspace_pgsql.sql.gz',$tmp_dir.'airspace.sql.gz');
2107 2611
 				}
2108 2612
 				if (file_exists($tmp_dir.'airspace.sql.gz')) {
2109
-					if ($globalDebug) echo "Gunzip...";
2613
+					if ($globalDebug) {
2614
+						echo "Gunzip...";
2615
+					}
2110 2616
 					update_db::gunzip($tmp_dir.'airspace.sql.gz');
2111
-					if ($globalDebug) echo "Add to DB...";
2617
+					if ($globalDebug) {
2618
+						echo "Add to DB...";
2619
+					}
2112 2620
 					$Connection = new Connection();
2113 2621
 					if ($Connection->tableExists('airspace')) {
2114 2622
 						$query = 'DROP TABLE airspace';
@@ -2121,19 +2629,27 @@  discard block
 block discarded – undo
2121 2629
 		    			}
2122 2630
 					$error = create_db::import_file($tmp_dir.'airspace.sql');
2123 2631
 					update_db::insert_airspace_version($airspace_md5);
2124
-				} else $error = "File ".$tmp_dir.'airpsace.sql.gz'." doesn't exist. Download failed.";
2632
+				} else {
2633
+					$error = "File ".$tmp_dir.'airpsace.sql.gz'." doesn't exist. Download failed.";
2634
+				}
2125 2635
 			}
2126
-		} else $error = "File ".$tmp_dir.'airpsace.sql.gz.md5'." doesn't exist. Download failed.";
2636
+		} else {
2637
+			$error = "File ".$tmp_dir.'airpsace.sql.gz.md5'." doesn't exist. Download failed.";
2638
+		}
2127 2639
 		if ($error != '') {
2128 2640
 			return $error;
2129
-		} elseif ($globalDebug) echo "Done\n";
2641
+		} elseif ($globalDebug) {
2642
+			echo "Done\n";
2643
+		}
2130 2644
 		return '';
2131 2645
 	}
2132 2646
 
2133 2647
 	public static function update_geoid_fam() {
2134 2648
 		global $tmp_dir, $globalDebug, $globalGeoidSource;
2135 2649
 		$error = '';
2136
-		if ($globalDebug) echo "Geoid from FlightAirMap website : Download...";
2650
+		if ($globalDebug) {
2651
+			echo "Geoid from FlightAirMap website : Download...";
2652
+		}
2137 2653
 		update_db::download('http://data.flightairmap.fr/data/geoid/'.$globalGeoidSource.'.pgm.gz.md5',$tmp_dir.$globalGeoidSource.'.pgm.gz.md5');
2138 2654
 		if (file_exists($tmp_dir.$globalGeoidSource.'.pgm.gz.md5')) {
2139 2655
 			$geoid_md5_file = explode(' ',file_get_contents($tmp_dir.$globalGeoidSource.'.pgm.gz.md5'));
@@ -2141,36 +2657,54 @@  discard block
 block discarded – undo
2141 2657
 			if (!update_db::check_geoid_version($geoid_md5)) {
2142 2658
 				update_db::download('http://data.flightairmap.fr/data/geoid/'.$globalGeoidSource.'.pgm.gz',$tmp_dir.$globalGeoidSource.'.pgm.gz');
2143 2659
 				if (file_exists($tmp_dir.$globalGeoidSource.'.pgm.gz')) {
2144
-					if ($globalDebug) echo "Gunzip...";
2660
+					if ($globalDebug) {
2661
+						echo "Gunzip...";
2662
+					}
2145 2663
 					update_db::gunzip($tmp_dir.$globalGeoidSource.'.pgm.gz',dirname(__FILE__).'/../data/'.$globalGeoidSource.'.pgm');
2146 2664
 					if (file_exists(dirname(__FILE__).'/../data/'.$globalGeoidSource.'.pgm')) {
2147 2665
 						update_db::insert_geoid_version($geoid_md5);
2148 2666
 					}
2149
-				} else $error = "File ".$tmp_dir.$globalGeoidSource.'.pgm.gz'." doesn't exist. Download failed.";
2667
+				} else {
2668
+					$error = "File ".$tmp_dir.$globalGeoidSource.'.pgm.gz'." doesn't exist. Download failed.";
2669
+				}
2150 2670
 			}
2151
-		} else $error = "File ".$tmp_dir.$globalGeoidSource.'.pgm.gz.md5'." doesn't exist. Download failed.";
2671
+		} else {
2672
+			$error = "File ".$tmp_dir.$globalGeoidSource.'.pgm.gz.md5'." doesn't exist. Download failed.";
2673
+		}
2152 2674
 		if ($error != '') {
2153 2675
 			return $error;
2154
-		} elseif ($globalDebug) echo "Done\n";
2676
+		} elseif ($globalDebug) {
2677
+			echo "Done\n";
2678
+		}
2155 2679
 		return '';
2156 2680
 	}
2157 2681
 
2158 2682
 	public static function update_tle() {
2159 2683
 		global $tmp_dir, $globalDebug;
2160
-		if ($globalDebug) echo "Download TLE : Download...";
2684
+		if ($globalDebug) {
2685
+			echo "Download TLE : Download...";
2686
+		}
2161 2687
 		$alltle = array('stations.txt','gps-ops.txt','glo-ops.txt','galileo.txt','weather.txt','noaa.txt','goes.txt','resource.txt','dmc.txt','tdrss.txt','geo.txt','intelsat.txt','gorizont.txt',
2162 2688
 		'raduga.txt','molniya.txt','iridium.txt','orbcomm.txt','globalstar.txt','amateur.txt','x-comm.txt','other-comm.txt','sbas.txt','nnss.txt','musson.txt','science.txt','geodetic.txt',
2163 2689
 		'engineering.txt','education.txt','military.txt','radar.txt','cubesat.txt','other.txt','tle-new.txt');
2164 2690
 		foreach ($alltle as $filename) {
2165
-			if ($globalDebug) echo "downloading ".$filename.'...';
2691
+			if ($globalDebug) {
2692
+				echo "downloading ".$filename.'...';
2693
+			}
2166 2694
 			update_db::download('http://celestrak.com/NORAD/elements/'.$filename,$tmp_dir.$filename);
2167 2695
 			if (file_exists($tmp_dir.$filename)) {
2168
-				if ($globalDebug) echo "Add to DB ".$filename."...";
2696
+				if ($globalDebug) {
2697
+					echo "Add to DB ".$filename."...";
2698
+				}
2169 2699
 				$error = update_db::tle($tmp_dir.$filename,str_replace('.txt','',$filename));
2170
-			} else $error = "File ".$tmp_dir.$filename." doesn't exist. Download failed.";
2700
+			} else {
2701
+				$error = "File ".$tmp_dir.$filename." doesn't exist. Download failed.";
2702
+			}
2171 2703
 			if ($error != '') {
2172 2704
 				echo $error."\n";
2173
-			} elseif ($globalDebug) echo "Done\n";
2705
+			} elseif ($globalDebug) {
2706
+				echo "Done\n";
2707
+			}
2174 2708
 		}
2175 2709
 		return '';
2176 2710
 	}
@@ -2178,10 +2712,14 @@  discard block
 block discarded – undo
2178 2712
 	public static function update_models() {
2179 2713
 		global $tmp_dir, $globalDebug;
2180 2714
 		$error = '';
2181
-		if ($globalDebug) echo "Models from FlightAirMap website : Download...";
2715
+		if ($globalDebug) {
2716
+			echo "Models from FlightAirMap website : Download...";
2717
+		}
2182 2718
 		update_db::download('http://data.flightairmap.fr/data/models/models.md5sum',$tmp_dir.'models.md5sum');
2183 2719
 		if (file_exists($tmp_dir.'models.md5sum')) {
2184
-			if ($globalDebug) echo "Check files...\n";
2720
+			if ($globalDebug) {
2721
+				echo "Check files...\n";
2722
+			}
2185 2723
 			$newmodelsdb = array();
2186 2724
 			if (($handle = fopen($tmp_dir.'models.md5sum','r')) !== FALSE) {
2187 2725
 				while (($row = fgetcsv($handle,1000," ")) !== FALSE) {
@@ -2200,25 +2738,35 @@  discard block
 block discarded – undo
2200 2738
 			}
2201 2739
 			$diff = array_diff($newmodelsdb,$modelsdb);
2202 2740
 			foreach ($diff as $key => $value) {
2203
-				if ($globalDebug) echo 'Downloading model '.$key.' ...'."\n";
2741
+				if ($globalDebug) {
2742
+					echo 'Downloading model '.$key.' ...'."\n";
2743
+				}
2204 2744
 				update_db::download('http://data.flightairmap.fr/data/models/'.$key,dirname(__FILE__).'/../models/'.$key);
2205 2745
 				
2206 2746
 			}
2207 2747
 			update_db::download('http://data.flightairmap.fr/data/models/models.md5sum',dirname(__FILE__).'/../models/models.md5sum');
2208
-		} else $error = "File ".$tmp_dir.'models.md5sum'." doesn't exist. Download failed.";
2748
+		} else {
2749
+			$error = "File ".$tmp_dir.'models.md5sum'." doesn't exist. Download failed.";
2750
+		}
2209 2751
 		if ($error != '') {
2210 2752
 			return $error;
2211
-		} elseif ($globalDebug) echo "Done\n";
2753
+		} elseif ($globalDebug) {
2754
+			echo "Done\n";
2755
+		}
2212 2756
 		return '';
2213 2757
 	}
2214 2758
 
2215 2759
 	public static function update_space_models() {
2216 2760
 		global $tmp_dir, $globalDebug;
2217 2761
 		$error = '';
2218
-		if ($globalDebug) echo "Space models from FlightAirMap website : Download...";
2762
+		if ($globalDebug) {
2763
+			echo "Space models from FlightAirMap website : Download...";
2764
+		}
2219 2765
 		update_db::download('http://data.flightairmap.fr/data/models/space/space_models.md5sum',$tmp_dir.'space_models.md5sum');
2220 2766
 		if (file_exists($tmp_dir.'space_models.md5sum')) {
2221
-			if ($globalDebug) echo "Check files...\n";
2767
+			if ($globalDebug) {
2768
+				echo "Check files...\n";
2769
+			}
2222 2770
 			$newmodelsdb = array();
2223 2771
 			if (($handle = fopen($tmp_dir.'space_models.md5sum','r')) !== FALSE) {
2224 2772
 				while (($row = fgetcsv($handle,1000," ")) !== FALSE) {
@@ -2237,25 +2785,35 @@  discard block
 block discarded – undo
2237 2785
 			}
2238 2786
 			$diff = array_diff($newmodelsdb,$modelsdb);
2239 2787
 			foreach ($diff as $key => $value) {
2240
-				if ($globalDebug) echo 'Downloading space model '.$key.' ...'."\n";
2788
+				if ($globalDebug) {
2789
+					echo 'Downloading space model '.$key.' ...'."\n";
2790
+				}
2241 2791
 				update_db::download('http://data.flightairmap.fr/data/models/space/'.$key,dirname(__FILE__).'/../models/space/'.$key);
2242 2792
 				
2243 2793
 			}
2244 2794
 			update_db::download('http://data.flightairmap.fr/data/models/space/space_models.md5sum',dirname(__FILE__).'/../models/space/space_models.md5sum');
2245
-		} else $error = "File ".$tmp_dir.'models.md5sum'." doesn't exist. Download failed.";
2795
+		} else {
2796
+			$error = "File ".$tmp_dir.'models.md5sum'." doesn't exist. Download failed.";
2797
+		}
2246 2798
 		if ($error != '') {
2247 2799
 			return $error;
2248
-		} elseif ($globalDebug) echo "Done\n";
2800
+		} elseif ($globalDebug) {
2801
+			echo "Done\n";
2802
+		}
2249 2803
 		return '';
2250 2804
 	}
2251 2805
 
2252 2806
 	public static function update_vehicules_models() {
2253 2807
 		global $tmp_dir, $globalDebug;
2254 2808
 		$error = '';
2255
-		if ($globalDebug) echo "Vehicules models from FlightAirMap website : Download...";
2809
+		if ($globalDebug) {
2810
+			echo "Vehicules models from FlightAirMap website : Download...";
2811
+		}
2256 2812
 		update_db::download('http://data.flightairmap.fr/data/models/vehicules/vehicules_models.md5sum',$tmp_dir.'vehicules_models.md5sum');
2257 2813
 		if (file_exists($tmp_dir.'vehicules_models.md5sum')) {
2258
-			if ($globalDebug) echo "Check files...\n";
2814
+			if ($globalDebug) {
2815
+				echo "Check files...\n";
2816
+			}
2259 2817
 			$newmodelsdb = array();
2260 2818
 			if (($handle = fopen($tmp_dir.'vehicules_models.md5sum','r')) !== FALSE) {
2261 2819
 				while (($row = fgetcsv($handle,1000," ")) !== FALSE) {
@@ -2274,15 +2832,21 @@  discard block
 block discarded – undo
2274 2832
 			}
2275 2833
 			$diff = array_diff($newmodelsdb,$modelsdb);
2276 2834
 			foreach ($diff as $key => $value) {
2277
-				if ($globalDebug) echo 'Downloading vehicules model '.$key.' ...'."\n";
2835
+				if ($globalDebug) {
2836
+					echo 'Downloading vehicules model '.$key.' ...'."\n";
2837
+				}
2278 2838
 				update_db::download('http://data.flightairmap.fr/data/models/vehicules/'.$key,dirname(__FILE__).'/../models/vehicules/'.$key);
2279 2839
 				
2280 2840
 			}
2281 2841
 			update_db::download('http://data.flightairmap.fr/data/models/vehicules/vehicules_models.md5sum',dirname(__FILE__).'/../models/vehicules/vehicules_models.md5sum');
2282
-		} else $error = "File ".$tmp_dir.'models.md5sum'." doesn't exist. Download failed.";
2842
+		} else {
2843
+			$error = "File ".$tmp_dir.'models.md5sum'." doesn't exist. Download failed.";
2844
+		}
2283 2845
 		if ($error != '') {
2284 2846
 			return $error;
2285
-		} elseif ($globalDebug) echo "Done\n";
2847
+		} elseif ($globalDebug) {
2848
+			echo "Done\n";
2849
+		}
2286 2850
 		return '';
2287 2851
 	}
2288 2852
 
@@ -2325,7 +2889,9 @@  discard block
 block discarded – undo
2325 2889
                 }
2326 2890
 
2327 2891
 		$error = '';
2328
-		if ($globalDebug) echo "Notam : Download...";
2892
+		if ($globalDebug) {
2893
+			echo "Notam : Download...";
2894
+		}
2329 2895
 		update_db::download($globalNOTAMSource,$tmp_dir.'notam.rss');
2330 2896
 		if (file_exists($tmp_dir.'notam.rss')) {
2331 2897
 			$notams = json_decode(json_encode(simplexml_load_file($tmp_dir.'notam.rss')),true);
@@ -2340,14 +2906,30 @@  discard block
 block discarded – undo
2340 2906
 				$data['fir'] = $q[0];
2341 2907
 				$data['code'] = $q[1];
2342 2908
 				$ifrvfr = $q[2];
2343
-				if ($ifrvfr == 'IV') $data['rules'] = 'IFR/VFR';
2344
-				if ($ifrvfr == 'I') $data['rules'] = 'IFR';
2345
-				if ($ifrvfr == 'V') $data['rules'] = 'VFR';
2346
-				if ($q[4] == 'A') $data['scope'] = 'Airport warning';
2347
-				if ($q[4] == 'E') $data['scope'] = 'Enroute warning';
2348
-				if ($q[4] == 'W') $data['scope'] = 'Navigation warning';
2349
-				if ($q[4] == 'AE') $data['scope'] = 'Airport/Enroute warning';
2350
-				if ($q[4] == 'AW') $data['scope'] = 'Airport/Navigation warning';
2909
+				if ($ifrvfr == 'IV') {
2910
+					$data['rules'] = 'IFR/VFR';
2911
+				}
2912
+				if ($ifrvfr == 'I') {
2913
+					$data['rules'] = 'IFR';
2914
+				}
2915
+				if ($ifrvfr == 'V') {
2916
+					$data['rules'] = 'VFR';
2917
+				}
2918
+				if ($q[4] == 'A') {
2919
+					$data['scope'] = 'Airport warning';
2920
+				}
2921
+				if ($q[4] == 'E') {
2922
+					$data['scope'] = 'Enroute warning';
2923
+				}
2924
+				if ($q[4] == 'W') {
2925
+					$data['scope'] = 'Navigation warning';
2926
+				}
2927
+				if ($q[4] == 'AE') {
2928
+					$data['scope'] = 'Airport/Enroute warning';
2929
+				}
2930
+				if ($q[4] == 'AW') {
2931
+					$data['scope'] = 'Airport/Navigation warning';
2932
+				}
2351 2933
 				//$data['scope'] = $q[4];
2352 2934
 				$data['lower_limit'] = $q[5];
2353 2935
 				$data['upper_limit'] = $q[6];
@@ -2355,8 +2937,12 @@  discard block
 block discarded – undo
2355 2937
 				sscanf($latlonrad,'%4c%c%5c%c%3d',$las,$lac,$lns,$lnc,$radius);
2356 2938
 				$latitude = $Common->convertDec($las,'latitude');
2357 2939
 				$longitude = $Common->convertDec($lns,'longitude');
2358
-				if ($lac == 'S') $latitude = '-'.$latitude;
2359
-				if ($lnc == 'W') $longitude = '-'.$longitude;
2940
+				if ($lac == 'S') {
2941
+					$latitude = '-'.$latitude;
2942
+				}
2943
+				if ($lnc == 'W') {
2944
+					$longitude = '-'.$longitude;
2945
+				}
2360 2946
 				$data['center_latitude'] = $latitude;
2361 2947
 				$data['center_longitude'] = $longitude;
2362 2948
 				$data['radius'] = intval($radius);
@@ -2386,10 +2972,14 @@  discard block
 block discarded – undo
2386 2972
 				$NOTAM->addNOTAM($data['ref'],$data['title'],'',$data['fir'],$data['code'],'',$data['scope'],$data['lower_limit'],$data['upper_limit'],$data['center_latitude'],$data['center_longitude'],$data['radius'],$data['date_begin'],$data['date_end'],$data['permanent'],$data['text'],$data['full_notam']);
2387 2973
 				unset($data);
2388 2974
 			} 
2389
-		} else $error = "File ".$tmp_dir.'notam.rss'." doesn't exist. Download failed.";
2975
+		} else {
2976
+			$error = "File ".$tmp_dir.'notam.rss'." doesn't exist. Download failed.";
2977
+		}
2390 2978
 		if ($error != '') {
2391 2979
 			return $error;
2392
-		} elseif ($globalDebug) echo "Done\n";
2980
+		} elseif ($globalDebug) {
2981
+			echo "Done\n";
2982
+		}
2393 2983
 		return '';
2394 2984
 	}
2395 2985
 	
@@ -2414,7 +3004,9 @@  discard block
 block discarded – undo
2414 3004
 		$airspace_lst = $Common->getData('https://raw.githubusercontent.com/XCSoar/xcsoar-data-repository/master/data/airspace.json');
2415 3005
 		$airspace_json = json_decode($airspace_lst,true);
2416 3006
 		foreach ($airspace_json['records'] as $airspace) {
2417
-			if ($globalDebug) echo $airspace['name']."...\n";
3007
+			if ($globalDebug) {
3008
+				echo $airspace['name']."...\n";
3009
+			}
2418 3010
 			update_db::download($airspace['uri'],$tmp_dir.$airspace['name']);
2419 3011
 			if (file_exists($tmp_dir.$airspace['name'])) {
2420 3012
 				file_put_contents($tmp_dir.$airspace['name'], utf8_encode(file_get_contents($tmp_dir.$airspace['name'])));
@@ -2458,8 +3050,11 @@  discard block
 block discarded – undo
2458 3050
                         return "error : ".$e->getMessage();
2459 3051
                 }
2460 3052
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
2461
-                if ($row['nb'] > 0) return false;
2462
-                else return true;
3053
+                if ($row['nb'] > 0) {
3054
+                	return false;
3055
+                } else {
3056
+                	return true;
3057
+                }
2463 3058
 	}
2464 3059
 
2465 3060
 	public static function insert_last_update() {
@@ -2484,8 +3079,11 @@  discard block
 block discarded – undo
2484 3079
                         return "error : ".$e->getMessage();
2485 3080
                 }
2486 3081
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
2487
-                if ($row['nb'] > 0) return true;
2488
-                else return false;
3082
+                if ($row['nb'] > 0) {
3083
+                	return true;
3084
+                } else {
3085
+                	return false;
3086
+                }
2489 3087
 	}
2490 3088
 
2491 3089
 	public static function check_geoid_version($version) {
@@ -2498,8 +3096,11 @@  discard block
 block discarded – undo
2498 3096
                         return "error : ".$e->getMessage();
2499 3097
                 }
2500 3098
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
2501
-                if ($row['nb'] > 0) return true;
2502
-                else return false;
3099
+                if ($row['nb'] > 0) {
3100
+                	return true;
3101
+                } else {
3102
+                	return false;
3103
+                }
2503 3104
 	}
2504 3105
 
2505 3106
 	public static function check_marine_identity_version($version) {
@@ -2512,8 +3113,11 @@  discard block
 block discarded – undo
2512 3113
                         return "error : ".$e->getMessage();
2513 3114
                 }
2514 3115
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
2515
-                if ($row['nb'] > 0) return true;
2516
-                else return false;
3116
+                if ($row['nb'] > 0) {
3117
+                	return true;
3118
+                } else {
3119
+                	return false;
3120
+                }
2517 3121
 	}
2518 3122
 
2519 3123
 
@@ -2568,8 +3172,11 @@  discard block
 block discarded – undo
2568 3172
                         return "error : ".$e->getMessage();
2569 3173
                 }
2570 3174
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
2571
-                if ($row['nb'] > 0) return false;
2572
-                else return true;
3175
+                if ($row['nb'] > 0) {
3176
+                	return false;
3177
+                } else {
3178
+                	return true;
3179
+                }
2573 3180
 	}
2574 3181
 
2575 3182
 	public static function insert_last_notam_update() {
@@ -2599,8 +3206,11 @@  discard block
 block discarded – undo
2599 3206
                         return "error : ".$e->getMessage();
2600 3207
                 }
2601 3208
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
2602
-                if ($row['nb'] > 0) return false;
2603
-                else return true;
3209
+                if ($row['nb'] > 0) {
3210
+                	return false;
3211
+                } else {
3212
+                	return true;
3213
+                }
2604 3214
 	}
2605 3215
 
2606 3216
 	public static function insert_last_airspace_update() {
@@ -2630,8 +3240,11 @@  discard block
 block discarded – undo
2630 3240
                         return "error : ".$e->getMessage();
2631 3241
                 }
2632 3242
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
2633
-                if ($row['nb'] > 0) return false;
2634
-                else return true;
3243
+                if ($row['nb'] > 0) {
3244
+                	return false;
3245
+                } else {
3246
+                	return true;
3247
+                }
2635 3248
 	}
2636 3249
 
2637 3250
 	public static function insert_last_geoid_update() {
@@ -2661,8 +3274,11 @@  discard block
 block discarded – undo
2661 3274
                         return "error : ".$e->getMessage();
2662 3275
                 }
2663 3276
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
2664
-                if ($row['nb'] > 0) return false;
2665
-                else return true;
3277
+                if ($row['nb'] > 0) {
3278
+                	return false;
3279
+                } else {
3280
+                	return true;
3281
+                }
2666 3282
 	}
2667 3283
 
2668 3284
 	public static function insert_last_owner_update() {
@@ -2691,8 +3307,11 @@  discard block
 block discarded – undo
2691 3307
                         return "error : ".$e->getMessage();
2692 3308
                 }
2693 3309
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
2694
-                if ($row['nb'] > 0) return false;
2695
-                else return true;
3310
+                if ($row['nb'] > 0) {
3311
+                	return false;
3312
+                } else {
3313
+                	return true;
3314
+                }
2696 3315
 	}
2697 3316
 
2698 3317
 	public static function insert_last_schedules_update() {
@@ -2721,8 +3340,11 @@  discard block
 block discarded – undo
2721 3340
                         return "error : ".$e->getMessage();
2722 3341
                 }
2723 3342
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
2724
-                if ($row['nb'] > 0) return false;
2725
-                else return true;
3343
+                if ($row['nb'] > 0) {
3344
+                	return false;
3345
+                } else {
3346
+                	return true;
3347
+                }
2726 3348
 	}
2727 3349
 
2728 3350
 	public static function insert_last_tle_update() {
@@ -2751,8 +3373,11 @@  discard block
 block discarded – undo
2751 3373
                         return "error : ".$e->getMessage();
2752 3374
                 }
2753 3375
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
2754
-                if ($row['nb'] > 0) return false;
2755
-                else return true;
3376
+                if ($row['nb'] > 0) {
3377
+                	return false;
3378
+                } else {
3379
+                	return true;
3380
+                }
2756 3381
 	}
2757 3382
 
2758 3383
 	public static function insert_last_marine_identity_update() {
Please login to merge, or discard this patch.
require/class.ACARS.php 1 patch
Braces   +409 added lines, -261 removed lines patch added patch discarded remove patch
@@ -23,14 +23,19 @@  discard block
 block discarded – undo
23 23
 	*/
24 24
 	public function ident2icao($ident) {
25 25
 		if (substr($ident,0,2) == 'AF') {
26
-			if (filter_var(substr($ident,2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $ident;
27
-			else $icao = 'AFR'.ltrim(substr($ident,2),'0');
26
+			if (filter_var(substr($ident,2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) {
27
+				$icao = $ident;
28
+			} else {
29
+				$icao = 'AFR'.ltrim(substr($ident,2),'0');
30
+			}
28 31
 		} else {
29 32
 			$Spotter = new Spotter($this->db);
30 33
 			$identicao = $Spotter->getAllAirlineInfo(substr($ident,0,2));
31 34
 			if (isset($identicao[0])) {
32 35
 				$icao = $identicao[0]['icao'].ltrim(substr($ident,2),'0');
33
-			} else $icao = $ident;
36
+			} else {
37
+				$icao = $ident;
38
+			}
34 39
 		}
35 40
 		return $icao;
36 41
 	}
@@ -103,14 +108,24 @@  discard block
 block discarded – undo
103 108
 		$message = '';
104 109
 		$result = array();
105 110
 		$n = sscanf($data,'(null) %*d %*02d/%*02d/%*04d %*02d:%*02d:%*02d %*d %*[0-9-] %*[A-Z0-9] %7s %*c %2[0-9a-zA-Z_] %d %4[0-9A-Z] %6[0-9A-Z] %[^\r\n]',$registration,$label,$block_id,$msg_no,$ident,$message);
106
-		if ($n == 0) $n = sscanf($data,'AC%*c %7s %*c %2[0-9a-zA-Z_] %d %4[0-9A-Z] %6[0-9A-Z] %[^\r\n]',$registration,$label,$block_id,$msg_no,$ident,$message);
107
-		if ($n == 0) $n = sscanf($data,'%*04d-%*02d-%*02d,%*02d:%*02d:%*02d,%*7s,%*c,%6[0-9A-Z-],%*c,%2[0-9a-zA-Z_],%d,%4[0-9A-Z],%6[0-9A-Z],%[^\r\n]',$registration,$label,$block_id,$msg_no,$ident,$message);
108
-		if ($n == 0) $n = sscanf($data,'%*04d-%*02d-%*02d,%*02d:%*02d:%*02d,%*7s,%*c,%5[0-9A-Z],%*c,%2[0-9a-zA-Z_],%d,%4[0-9A-Z],%6[0-9A-Z],%[^\r\n]',$registration,$label,$block_id,$msg_no,$ident,$message);
111
+		if ($n == 0) {
112
+			$n = sscanf($data,'AC%*c %7s %*c %2[0-9a-zA-Z_] %d %4[0-9A-Z] %6[0-9A-Z] %[^\r\n]',$registration,$label,$block_id,$msg_no,$ident,$message);
113
+		}
114
+		if ($n == 0) {
115
+			$n = sscanf($data,'%*04d-%*02d-%*02d,%*02d:%*02d:%*02d,%*7s,%*c,%6[0-9A-Z-],%*c,%2[0-9a-zA-Z_],%d,%4[0-9A-Z],%6[0-9A-Z],%[^\r\n]',$registration,$label,$block_id,$msg_no,$ident,$message);
116
+		}
117
+		if ($n == 0) {
118
+			$n = sscanf($data,'%*04d-%*02d-%*02d,%*02d:%*02d:%*02d,%*7s,%*c,%5[0-9A-Z],%*c,%2[0-9a-zA-Z_],%d,%4[0-9A-Z],%6[0-9A-Z],%[^\r\n]',$registration,$label,$block_id,$msg_no,$ident,$message);
119
+		}
109 120
 		if ($n != 0) {
110 121
 			$registration = str_replace('.','',$registration);
111 122
 			$result = array('registration' => $registration, 'ident' => $ident,'label' => $label, 'block_id' => $block_id,'msg_no' => $msg_no,'message' => $message);
112
-			if ($globalDebug) echo "Reg. : ".$registration." - Ident : ".$ident." - Label : ".$label." - Message : ".$message."\n";
113
-		} else $message = $data;
123
+			if ($globalDebug) {
124
+				echo "Reg. : ".$registration." - Ident : ".$ident." - Label : ".$label." - Message : ".$message."\n";
125
+			}
126
+		} else {
127
+			$message = $data;
128
+		}
114 129
 		$decode = array();
115 130
 		$found = false;
116 131
 //		if ($registration != '' && $ident != '' && $registration != '!') {
@@ -130,12 +145,21 @@  discard block
 block discarded – undo
130 145
 				if ($n > 5 && ($lac == 'N' || $lac == 'S') && ($lnc == 'E' || $lnc == 'W')) {
131 146
 					$latitude = $la / 10000.0;
132 147
 					$longitude = $ln / 10000.0;
133
-					if ($lac == 'S') $latitude = '-'.$latitude;
134
-					if ($lnc == 'W') $longitude = '-'.$longitude;
148
+					if ($lac == 'S') {
149
+						$latitude = '-'.$latitude;
150
+					}
151
+					if ($lnc == 'W') {
152
+						$longitude = '-'.$longitude;
153
+					}
135 154
 					// Temp not always available
136
-					if ($globalDebug) echo 'latitude : '.$latitude.' - longitude : '.$longitude.' - airport depart : '.$dair.' - airport arrival : '.$darr.' - température : '.$temp."°C\n";
137
-					if ($temp == '') $decode = array('Latitude' => $latitude, 'Longitude' =>  $longitude, 'Departure airport' => $dair, 'Arrival airport' => $darr,'Altitude' => $alt);
138
-					else $decode = array('Latitude' => $latitude, 'Longitude' =>  $longitude, 'Departure airport' => $dair, 'Arrival airport' => $darr, 'Altitude' => 'FL'.$alt,'Temperature' => $temp.'°C');
155
+					if ($globalDebug) {
156
+						echo 'latitude : '.$latitude.' - longitude : '.$longitude.' - airport depart : '.$dair.' - airport arrival : '.$darr.' - température : '.$temp."°C\n";
157
+					}
158
+					if ($temp == '') {
159
+						$decode = array('Latitude' => $latitude, 'Longitude' =>  $longitude, 'Departure airport' => $dair, 'Arrival airport' => $darr,'Altitude' => $alt);
160
+					} else {
161
+						$decode = array('Latitude' => $latitude, 'Longitude' =>  $longitude, 'Departure airport' => $dair, 'Arrival airport' => $darr, 'Altitude' => 'FL'.$alt,'Temperature' => $temp.'°C');
162
+					}
139 163
 
140 164
 					//$icao = $Translation->checkTranslation($ident);
141 165
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
@@ -149,25 +173,35 @@  discard block
 block discarded – undo
149 173
 				$ahour = '';
150 174
 				$n = sscanf($message, "ARR01 %4[A-Z]%4d %4[A-Z]%4d", $dair, $dhour, $darr,$ahour);
151 175
 				if ($n == 4 && strlen($darr) == 4) {
152
-					if ($dhour != '') $dhour = substr(sprintf('%04d',$dhour),0,2).':'.substr(sprintf('%04d',$dhour),2);
153
-					if ($ahour != '') $ahour = substr(sprintf('%04d',$ahour),0,2).':'.substr(sprintf('%04d',$ahour),2);
154
-					if ($globalDebug) echo 'departure airport : '.$dair.' - arrival airport : '. $darr.' - departure hour : '. $dhour.' - arrival hour : '.$ahour."\n";
176
+					if ($dhour != '') {
177
+						$dhour = substr(sprintf('%04d',$dhour),0,2).':'.substr(sprintf('%04d',$dhour),2);
178
+					}
179
+					if ($ahour != '') {
180
+						$ahour = substr(sprintf('%04d',$ahour),0,2).':'.substr(sprintf('%04d',$ahour),2);
181
+					}
182
+					if ($globalDebug) {
183
+						echo 'departure airport : '.$dair.' - arrival airport : '. $darr.' - departure hour : '. $dhour.' - arrival hour : '.$ahour."\n";
184
+					}
155 185
 					//$icao = ACARS->ident2icao($ident);
156 186
 					//$icao = $Translation->checkTranslation($ident);
157 187
 					//$Schedule->addSchedule($icao,$dair,$dhour,$darr,$ahour,'ACARS');
158 188
 					$decode = array('Departure airport' => $dair, 'Departure hour' => $dhour, 'Arrival airport' => $darr, 'Arrival hour' => $ahour);
159 189
 					$found = true;
160
-				}
161
-				elseif ($n == 2 || $n  == 4) {
162
-					if ($dhour != '') $dhour = substr(sprintf('%04d',$dhour),0,2).':'.substr(sprintf('%04d',$dhour),2);
163
-					if ($globalDebug) echo 'airport arrival : '.$dair.' - arrival hour : '.$dhour."\n";
190
+				} elseif ($n == 2 || $n  == 4) {
191
+					if ($dhour != '') {
192
+						$dhour = substr(sprintf('%04d',$dhour),0,2).':'.substr(sprintf('%04d',$dhour),2);
193
+					}
194
+					if ($globalDebug) {
195
+						echo 'airport arrival : '.$dair.' - arrival hour : '.$dhour."\n";
196
+					}
164 197
 					//$icao = ACARS->ident2icao($ident);
165 198
 					//$icao = $Translation->checkTranslation($ident);
166 199
 					$decode = array('Arrival airport' => $dair, 'Arrival hour' => $dhour);
167 200
 					$found = true;
168
-				}
169
-				elseif ($n == 1) {
170
-					if ($globalDebug) echo 'airport arrival : '.$darr."\n";
201
+				} elseif ($n == 1) {
202
+					if ($globalDebug) {
203
+						echo 'airport arrival : '.$darr."\n";
204
+					}
171 205
 					//$icao = ACARS->ident2icao($ident);
172 206
 					//$icao = $Translation->checkTranslation($ident);
173 207
 					$decode = array('Arrival airport' => $darr);
@@ -185,7 +219,9 @@  discard block
 block discarded – undo
185 219
 				$darr = '';
186 220
 				$n = sscanf($message, "%4c,%4c,%*7s,%*d", $dair, $darr);
187 221
 				if ($n == 4) {
188
-					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
222
+					if ($globalDebug) {
223
+						echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
224
+					}
189 225
 					//$icao = ACARS->ident2icao($ident);
190 226
 					//$icao = $Translation->checkTranslation($ident);
191 227
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
@@ -219,14 +255,23 @@  discard block
 block discarded – undo
219 255
 				$apiste = '';
220 256
 				$n = sscanf(str_replace(array("\r\n", "\n", "\r"),'',$message), "%*[0-9A-Z]/%*3d/%4s/%*cSCH/%6[0-9A-Z ]/%4c/%4c/%5s/%4d%*3c/%4d/%4c/%[0-9A-Z ]/", $airicao,$aident,$dair, $darr, $ddate, $dhour,$ahour, $aair, $apiste);
221 257
 				if ($n > 8) {
222
-					if ($globalDebug) echo 'airicao : '. $airicao.' - ident : '.$aident.' - departure airport : '.$dair.' - arrival airport : '. $darr.' - date depart : '.$ddate.' - departure hour : '. $dhour.' - arrival hour : '.$ahour.' - arrival airport : '.$aair.' - arrival piste : '.$apiste."\n";
223
-					if ($dhour != '') $dhour = substr(sprintf('%04d',$dhour),0,2).':'.substr(sprintf('%04d',$dhour),2);
224
-					if ($ahour != '') $ahour = substr(sprintf('%04d',$ahour),0,2).':'.substr(sprintf('%04d',$ahour),2);
258
+					if ($globalDebug) {
259
+						echo 'airicao : '. $airicao.' - ident : '.$aident.' - departure airport : '.$dair.' - arrival airport : '. $darr.' - date depart : '.$ddate.' - departure hour : '. $dhour.' - arrival hour : '.$ahour.' - arrival airport : '.$aair.' - arrival piste : '.$apiste."\n";
260
+					}
261
+					if ($dhour != '') {
262
+						$dhour = substr(sprintf('%04d',$dhour),0,2).':'.substr(sprintf('%04d',$dhour),2);
263
+					}
264
+					if ($ahour != '') {
265
+						$ahour = substr(sprintf('%04d',$ahour),0,2).':'.substr(sprintf('%04d',$ahour),2);
266
+					}
225 267
 					$icao = trim($aident);
226 268
 
227 269
 					//$decode = 'Departure airport : '.$dair.' ('.$ddate.' at '.$dhour.') - Arrival Airport : '.$aair.' (at '.$ahour.') way '.$apiste;
228
-					if ($ahour == '') $decode = array('Departure airport' => $dair, 'Departure date' => $ddate, 'Departure hour' => $dhour, 'Arrival airport' => $darr);
229
-					else $decode = array('Departure airport' => $dair, 'Departure date' => $ddate, 'Departure hour' => $dhour, 'Arrival airport' => $darr, 'Arrival hour' => $ahour, 'Arrival way' => $apiste);
270
+					if ($ahour == '') {
271
+						$decode = array('Departure airport' => $dair, 'Departure date' => $ddate, 'Departure hour' => $dhour, 'Arrival airport' => $darr);
272
+					} else {
273
+						$decode = array('Departure airport' => $dair, 'Departure date' => $ddate, 'Departure hour' => $dhour, 'Arrival airport' => $darr, 'Arrival hour' => $ahour, 'Arrival way' => $apiste);
274
+					}
230 275
 					//$Schedule->addSchedule($icao,$dair,$dhour,$darr,$ahour,'ACARS');
231 276
 					$decode['icao'] = $icao;
232 277
 					$found = true;
@@ -248,9 +293,15 @@  discard block
 block discarded – undo
248 293
 					$lns = $lns.'.'.$lns;
249 294
 					$latitude = $las / 1000.0;
250 295
 					$longitude = $lns / 1000.0;
251
-					if ($lac == 'S') $latitude = '-'.$latitude;
252
-					if ($lnc == 'W') $longitude = '-'.$longitude;
253
-					if ($globalDebug) echo 'latitude : '.$latitude.' - longitude : '.$longitude."\n";
296
+					if ($lac == 'S') {
297
+						$latitude = '-'.$latitude;
298
+					}
299
+					if ($lnc == 'W') {
300
+						$longitude = '-'.$longitude;
301
+					}
302
+					if ($globalDebug) {
303
+						echo 'latitude : '.$latitude.' - longitude : '.$longitude."\n";
304
+					}
254 305
 					$decode = array('Latitude' => $latitude, 'Longitude' => $longitude);
255 306
 					$found = true;
256 307
 				}
@@ -268,7 +319,9 @@  discard block
 block discarded – undo
268 319
 				$darr = '';
269 320
 				$n = sscanf($message, "%*[0-9A-Z ]/%*s %4c/%4c .", $dair, $darr);
270 321
 				if ($n == 4) {
271
-					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
322
+					if ($globalDebug) {
323
+						echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
324
+					}
272 325
 					//$icao = $Translation->checkTranslation($ident);
273 326
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
274 327
 					$decode = array('Departure airport' => $dair, 'Arrival airport' => $darr);
@@ -281,7 +334,9 @@  discard block
 block discarded – undo
281 334
 				$darr = '';
282 335
 				$n = sscanf($message, "%*[0-9],%4c,%4c,", $dair, $darr);
283 336
 				if ($n == 4) {
284
-					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
337
+					if ($globalDebug) {
338
+						echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
339
+					}
285 340
 					//$icao = $Translation->checkTranslation($ident);
286 341
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
287 342
 					$decode = array('Departure airport' => $dair, 'Arrival airport' => $darr);
@@ -294,7 +349,9 @@  discard block
 block discarded – undo
294 349
 				$darr = '';
295 350
 				$n = sscanf($message, "002AF %4c %4c ", $dair, $darr);
296 351
 				if ($n == 2) {
297
-					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
352
+					if ($globalDebug) {
353
+						echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
354
+					}
298 355
 					//$icao = $Translation->checkTranslation($ident);
299 356
 					$decode = array('Departure airport' => $dair, 'Arrival airport' => $darr);
300 357
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
@@ -308,7 +365,9 @@  discard block
 block discarded – undo
308 365
 				$darr = '';
309 366
 				$n = sscanf($message, "#DFBA%*02d/%*[A-Z-],%*[0-9A-Z],%*d,%4c,%4c", $dair, $darr);
310 367
 				if ($n == 6) {
311
-					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
368
+					if ($globalDebug) {
369
+						echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
370
+					}
312 371
 					//$icao = $Translation->checkTranslation($ident);
313 372
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
314 373
 					$decode = array('Departure airport' => $dair, 'Arrival airport' => $darr);
@@ -321,7 +380,9 @@  discard block
 block discarded – undo
321 380
 				$darr = '';
322 381
 				$n = sscanf($message, "#DFBA%*02d/%*[0-9A-Z,]/%*[A-Z-],%*[0-9A-Z],%*d,%4c,%4c", $dair, $darr);
323 382
 				if ($n == 7) {
324
-					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
383
+					if ($globalDebug) {
384
+						echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
385
+					}
325 386
 					//$icao = $Translation->checkTranslation($ident);
326 387
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
327 388
 					$decode = array('Departure airport' => $dair, 'Arrival airport' => $darr);
@@ -349,8 +410,12 @@  discard block
 block discarded – undo
349 410
 					$decode['icao'] = $icao;
350 411
 					$latitude = $las / 100.0;
351 412
 					$longitude = $lns / 100.0;
352
-					if ($lac == 'S') $latitude = '-'.$latitude;
353
-					if ($lnc == 'W') $longitude = '-'.$longitude;
413
+					if ($lac == 'S') {
414
+						$latitude = '-'.$latitude;
415
+					}
416
+					if ($lnc == 'W') {
417
+						$longitude = '-'.$longitude;
418
+					}
354 419
 
355 420
 					$decode = array('Latitude' => $latitude,'Longitude' => $longitude,'Altitude' => 'FL'.$alt,'Fuel' => $fuel,'speed' => $speed);
356 421
 					$found = true;
@@ -368,8 +433,12 @@  discard block
 block discarded – undo
368 433
 				if ($n == 4) {
369 434
 					$latitude = $las;
370 435
 					$longitude = $lns;
371
-					if ($lac == 'S') $latitude = '-'.$latitude;
372
-					if ($lnc == 'W') $longitude = '-'.$longitude;
436
+					if ($lac == 'S') {
437
+						$latitude = '-'.$latitude;
438
+					}
439
+					if ($lnc == 'W') {
440
+						$longitude = '-'.$longitude;
441
+					}
373 442
 
374 443
 					$decode = array('Latitude' => $latitude,'Longitude' => $longitude);
375 444
 					$found = true;
@@ -385,7 +454,9 @@  discard block
 block discarded – undo
385 454
 				$darr = '';
386 455
 				$n = sscanf($message, "%*[0-9A-Z] NLINFO %*d/%*d %4c/%4c .", $dair, $darr);
387 456
 				if ($n == 5) {
388
-					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
457
+					if ($globalDebug) {
458
+						echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
459
+					}
389 460
 					//$icao = $Translation->checkTranslation($ident);
390 461
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
391 462
 					$decode = array('Departure airport' => $dair, 'Arrival airport' => $darr);
@@ -406,7 +477,9 @@  discard block
 block discarded – undo
406 477
 				$aident = '';
407 478
 				$n = sscanf(str_replace(array("\r\n", "\n", "\r"),'',$message), "%*[0-9A-Z],,%*[0-9A-Z],%*[0-9A-Z],%4s,%4s,.%*6s,%*4[A-Z],%[0-9A-Z],", $dair, $darr, $aident);
408 479
 				if ($n == 8) {
409
-					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
480
+					if ($globalDebug) {
481
+						echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
482
+					}
410 483
 					$icao = trim($aident);
411 484
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
412 485
 					$decode['icao'] = $icao;
@@ -423,7 +496,9 @@  discard block
 block discarded – undo
423 496
 				$darr = '';
424 497
 				$n = sscanf($message, "%*d/%*d %4s/%4s .%*6s", $dair, $darr);
425 498
 				if ($n == 5) {
426
-					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
499
+					if ($globalDebug) {
500
+						echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
501
+					}
427 502
 					//$icao = $Translation->checkTranslation($ident);
428 503
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
429 504
 					$decode = array('Departure airport' => $dair, 'Arrival airport' => $darr);
@@ -438,7 +513,9 @@  discard block
 block discarded – undo
438 513
 				$darr = '';
439 514
 				$n = sscanf($message,'%4[A-Z]%4[A-Z]%*4d',$dair,$darr);
440 515
 				if ($n == 3) {
441
-					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
516
+					if ($globalDebug) {
517
+						echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
518
+					}
442 519
 					//$icao = $Translation->checkTranslation($ident);
443 520
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
444 521
 					$decode = array('Departure airport' => $dair, 'Arrival airport' => $darr);
@@ -453,7 +530,9 @@  discard block
 block discarded – undo
453 530
 				$darr = '';
454 531
 				$n = sscanf($message,'3J01 DSPTCH %*d/%*d %4s/%4s .%*6s',$dair,$darr);
455 532
 				if ($n == 3) {
456
-					if ($globalDebug) echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
533
+					if ($globalDebug) {
534
+						echo 'airport depart : '.$dair.' - airport arrival : '.$darr."\n";
535
+					}
457 536
 					//$icao = $Translation->checkTranslation($ident);
458 537
 					//$Schedule->addSchedule($icao,$dair,'',$darr,'','ACARS');
459 538
 					$decode = array('Departure airport' => $dair, 'Arrival airport' => $darr);
@@ -463,7 +542,9 @@  discard block
 block discarded – undo
463 542
 			if (!$found) {
464 543
 				$n = sscanf($message,'MET01%4c',$airport);
465 544
 				if ($n == 1) {
466
-					if ($globalDebug) echo 'airport name : '.$airport;
545
+					if ($globalDebug) {
546
+						echo 'airport name : '.$airport;
547
+					}
467 548
 					$decode = array('Airport/Waypoint name' => $airport);
468 549
 					$found = true;
469 550
 				}
@@ -471,184 +552,126 @@  discard block
 block discarded – undo
471 552
 			if ($label == 'H1') {
472 553
 				if (preg_match('/^#CFBFLR/',$message) || preg_match('/^#CFBWRN/',$message)) {
473 554
 					$decode = array_merge(array('Message nature' => 'Equipment failure'),$decode);
474
-				}
475
-				elseif (preg_match('/^#DFB\*TKO/',$message) || preg_match('/^#DFBTKO/',$message)) {
555
+				} elseif (preg_match('/^#DFB\*TKO/',$message) || preg_match('/^#DFBTKO/',$message)) {
476 556
 					$decode = array_merge(array('Message nature' => 'Take off performance data'),$decode);
477
-				}
478
-				elseif (preg_match('/^#DFB\*CRZ/',$message) || preg_match('/^#DFBCRZ/',$message)) {
557
+				} elseif (preg_match('/^#DFB\*CRZ/',$message) || preg_match('/^#DFBCRZ/',$message)) {
479 558
 					$decode = array_merge(array('Message nature' => 'Cruise performance data'),$decode);
480
-				}
481
-				elseif (preg_match('/^#DFB\*WOB/',$message) || preg_match('/^#DFBWOB/',$message)) {
559
+				} elseif (preg_match('/^#DFB\*WOB/',$message) || preg_match('/^#DFBWOB/',$message)) {
482 560
 					$decode = array_merge(array('Message nature' => 'Weather observation'),$decode);
483
-				}
484
-				elseif (preg_match(':^#DFB/PIREP:',$message)) {
561
+				} elseif (preg_match(':^#DFB/PIREP:',$message)) {
485 562
 					$decode = array_merge(array('Message nature' => 'Pilot Report'),$decode);
486
-				}
487
-				elseif (preg_match('/^#DFBEDA/',$message) || preg_match('/^#DFBENG/',$message)) {
563
+				} elseif (preg_match('/^#DFBEDA/',$message) || preg_match('/^#DFBENG/',$message)) {
488 564
 					$decode = array_merge(array('Message nature' => 'Engine Data'),$decode);
489
-				}
490
-				elseif (preg_match(':^#M1AAEP:',$message)) {
565
+				} elseif (preg_match(':^#M1AAEP:',$message)) {
491 566
 					$decode = array_merge(array('Message nature' => 'Position/Weather Report'),$decode);
492
-				}
493
-				elseif (preg_match(':^#M2APWD:',$message)) {
567
+				} elseif (preg_match(':^#M2APWD:',$message)) {
494 568
 					$decode = array_merge(array('Message nature' => 'Flight plan predicted wind data'),$decode);
495
-				}
496
-				elseif (preg_match(':^#M1BREQPWI:',$message)) {
569
+				} elseif (preg_match(':^#M1BREQPWI:',$message)) {
497 570
 					$decode = array_merge(array('Message nature' => 'Predicted wind info request'),$decode);
498
-				}
499
-				elseif (preg_match(':^#CF:',$message)) {
571
+				} elseif (preg_match(':^#CF:',$message)) {
500 572
 					$decode = array_merge(array('Message nature' => 'Central Fault Display'),$decode);
501
-				}
502
-				elseif (preg_match(':^#DF:',$message)) {
573
+				} elseif (preg_match(':^#DF:',$message)) {
503 574
 					$decode = array_merge(array('Message nature' => 'Digital Flight Data Acquisition Unit'),$decode);
504
-				}
505
-				elseif (preg_match(':^#EC:',$message)) {
575
+				} elseif (preg_match(':^#EC:',$message)) {
506 576
 					$decode = array_merge(array('Message nature' => 'Engine Display System'),$decode);
507
-				}
508
-				elseif (preg_match(':^#EI:',$message)) {
577
+				} elseif (preg_match(':^#EI:',$message)) {
509 578
 					$decode = array_merge(array('Message nature' => 'Engine Report'),$decode);
510
-				}
511
-				elseif (preg_match(':^#H1:',$message)) {
579
+				} elseif (preg_match(':^#H1:',$message)) {
512 580
 					$decode = array_merge(array('Message nature' => 'HF Data Radio - Left'),$decode);
513
-				}
514
-				elseif (preg_match(':^#H2:',$message)) {
581
+				} elseif (preg_match(':^#H2:',$message)) {
515 582
 					$decode = array_merge(array('Message nature' => 'HF Data Radio - Right'),$decode);
516
-				}
517
-				elseif (preg_match(':^#HD:',$message)) {
583
+				} elseif (preg_match(':^#HD:',$message)) {
518 584
 					$decode = array_merge(array('Message nature' => 'HF Data Radio - Selected'),$decode);
519
-				}
520
-				elseif (preg_match(':^#M1:',$message)) {
585
+				} elseif (preg_match(':^#M1:',$message)) {
521 586
 					$decode = array_merge(array('Message nature' => 'Flight Management Computer - Left'),$decode);
522
-				}
523
-				elseif (preg_match(':^#M2:',$message)) {
587
+				} elseif (preg_match(':^#M2:',$message)) {
524 588
 					$decode = array_merge(array('Message nature' => 'Flight Management Computer - Right'),$decode);
525
-				}
526
-				elseif (preg_match(':^#M3:',$message)) {
589
+				} elseif (preg_match(':^#M3:',$message)) {
527 590
 					$decode = array_merge(array('Message nature' => 'Flight Management Computer - Center'),$decode);
528
-				}
529
-				elseif (preg_match(':^#MD:',$message)) {
591
+				} elseif (preg_match(':^#MD:',$message)) {
530 592
 					$decode = array_merge(array('Message nature' => 'Flight Management Computer - Selected'),$decode);
531
-				}
532
-				elseif (preg_match(':^#PS:',$message)) {
593
+				} elseif (preg_match(':^#PS:',$message)) {
533 594
 					$decode = array_merge(array('Message nature' => 'Keyboard/Display Unit'),$decode);
534
-				}
535
-				elseif (preg_match(':^#S1:',$message)) {
595
+				} elseif (preg_match(':^#S1:',$message)) {
536 596
 					$decode = array_merge(array('Message nature' => 'SDU - Left'),$decode);
537
-				}
538
-				elseif (preg_match(':^#S2:',$message)) {
597
+				} elseif (preg_match(':^#S2:',$message)) {
539 598
 					$decode = array_merge(array('Message nature' => 'SDU - Right'),$decode);
540
-				}
541
-				elseif (preg_match(':^#SD:',$message)) {
599
+				} elseif (preg_match(':^#SD:',$message)) {
542 600
 					$decode = array_merge(array('Message nature' => 'SDU - Selected'),$decode);
543
-				}
544
-				elseif (preg_match(':^#T[0-8]:',$message)) {
601
+				} elseif (preg_match(':^#T[0-8]:',$message)) {
545 602
 					$decode = array_merge(array('Message nature' => 'Cabin Terminal Messages'),$decode);
546
-				}
547
-				elseif (preg_match(':^#WO:',$message)) {
603
+				} elseif (preg_match(':^#WO:',$message)) {
548 604
 					$decode = array_merge(array('Message nature' => 'Weather Observation Report'),$decode);
549
-				}
550
-				elseif (preg_match(':^#A1:',$message)) {
605
+				} elseif (preg_match(':^#A1:',$message)) {
551 606
 					$decode = array_merge(array('Message nature' => 'Oceanic Clearance'),$decode);
552
-				}
553
-				elseif (preg_match(':^#A3:',$message)) {
607
+				} elseif (preg_match(':^#A3:',$message)) {
554 608
 					$decode = array_merge(array('Message nature' => 'Departure Clearance Response'),$decode);
555
-				}
556
-				elseif (preg_match(':^#A4:',$message)) {
609
+				} elseif (preg_match(':^#A4:',$message)) {
557 610
 					$decode = array_merge(array('Message nature' => 'Flight Systems Message'),$decode);
558
-				}
559
-				elseif (preg_match(':^#A6:',$message)) {
611
+				} elseif (preg_match(':^#A6:',$message)) {
560 612
 					$decode = array_merge(array('Message nature' => 'Request ADS Reports'),$decode);
561
-				}
562
-				elseif (preg_match(':^#A8:',$message)) {
613
+				} elseif (preg_match(':^#A8:',$message)) {
563 614
 					$decode = array_merge(array('Message nature' => 'Deliver Departure Slot'),$decode);
564
-				}
565
-				elseif (preg_match(':^#A9:',$message)) {
615
+				} elseif (preg_match(':^#A9:',$message)) {
566 616
 					$decode = array_merge(array('Message nature' => 'ATIS report'),$decode);
567
-				}
568
-				elseif (preg_match(':^#A0:',$message)) {
617
+				} elseif (preg_match(':^#A0:',$message)) {
569 618
 					$decode = array_merge(array('Message nature' => 'ATIS Facility Notification (AFN)'),$decode);
570
-				}
571
-				elseif (preg_match(':^#AA:',$message)) {
619
+				} elseif (preg_match(':^#AA:',$message)) {
572 620
 					$decode = array_merge(array('Message nature' => 'ATCComm'),$decode);
573
-				}
574
-				elseif (preg_match(':^#AB:',$message)) {
621
+				} elseif (preg_match(':^#AB:',$message)) {
575 622
 					$decode = array_merge(array('Message nature' => 'TWIP Report'),$decode);
576
-				}
577
-				elseif (preg_match(':^#AC:',$message)) {
623
+				} elseif (preg_match(':^#AC:',$message)) {
578 624
 					$decode = array_merge(array('Message nature' => 'Pushback Clearance'),$decode);
579
-				}
580
-				elseif (preg_match(':^#AD:',$message)) {
625
+				} elseif (preg_match(':^#AD:',$message)) {
581 626
 					$decode = array_merge(array('Message nature' => 'Expected Taxi Clearance'),$decode);
582
-				}
583
-				elseif (preg_match(':^#AF:',$message)) {
627
+				} elseif (preg_match(':^#AF:',$message)) {
584 628
 					$decode = array_merge(array('Message nature' => 'CPC Command/Response'),$decode);
585
-				}
586
-				elseif (preg_match(':^#B1:',$message)) {
629
+				} elseif (preg_match(':^#B1:',$message)) {
587 630
 					$decode = array_merge(array('Message nature' => 'Request Oceanic Clearance'),$decode);
588
-				}
589
-				elseif (preg_match(':^#B2:',$message)) {
631
+				} elseif (preg_match(':^#B2:',$message)) {
590 632
 					$decode = array_merge(array('Message nature' => 'Oceanic Clearance Readback'),$decode);
591
-				}
592
-				elseif (preg_match(':^#B3:',$message)) {
633
+				} elseif (preg_match(':^#B3:',$message)) {
593 634
 					$decode = array_merge(array('Message nature' => 'Request Departure Clearance'),$decode);
594
-				}
595
-				elseif (preg_match(':^#B4:',$message)) {
635
+				} elseif (preg_match(':^#B4:',$message)) {
596 636
 					$decode = array_merge(array('Message nature' => 'Departure Clearance Readback'),$decode);
597
-				}
598
-				elseif (preg_match(':^#B6:',$message)) {
637
+				} elseif (preg_match(':^#B6:',$message)) {
599 638
 					$decode = array_merge(array('Message nature' => 'Provide ADS Report'),$decode);
600
-				}
601
-				elseif (preg_match(':^#B8:',$message)) {
639
+				} elseif (preg_match(':^#B8:',$message)) {
602 640
 					$decode = array_merge(array('Message nature' => 'Request Departure Slot'),$decode);
603
-				}
604
-				elseif (preg_match(':^#B9:',$message)) {
641
+				} elseif (preg_match(':^#B9:',$message)) {
605 642
 					$decode = array_merge(array('Message nature' => 'Request ATIS Report'),$decode);
606
-				}
607
-				elseif (preg_match(':^#B0:',$message)) {
643
+				} elseif (preg_match(':^#B0:',$message)) {
608 644
 					$decode = array_merge(array('Message nature' => 'ATS Facility Notification'),$decode);
609
-				}
610
-				elseif (preg_match(':^#BA:',$message)) {
645
+				} elseif (preg_match(':^#BA:',$message)) {
611 646
 					$decode = array_merge(array('Message nature' => 'ATCComm'),$decode);
612
-				}
613
-				elseif (preg_match(':^#BB:',$message)) {
647
+				} elseif (preg_match(':^#BB:',$message)) {
614 648
 					$decode = array_merge(array('Message nature' => 'Request TWIP Report'),$decode);
615
-				}
616
-				elseif (preg_match(':^#BC:',$message)) {
649
+				} elseif (preg_match(':^#BC:',$message)) {
617 650
 					$decode = array_merge(array('Message nature' => 'Pushback Clearance Request'),$decode);
618
-				}
619
-				elseif (preg_match(':^#BD:',$message)) {
651
+				} elseif (preg_match(':^#BD:',$message)) {
620 652
 					$decode = array_merge(array('Message nature' => 'Expected Taxi Clearance Request'),$decode);
621
-				}
622
-				elseif (preg_match(':^#BE:',$message)) {
653
+				} elseif (preg_match(':^#BE:',$message)) {
623 654
 					$decode = array_merge(array('Message nature' => 'CPC Aircraft Log-On/Off Request'),$decode);
624
-				}
625
-				elseif (preg_match(':^#BF:',$message)) {
655
+				} elseif (preg_match(':^#BF:',$message)) {
626 656
 					$decode = array_merge(array('Message nature' => 'CPC WILCO/UNABLE Response'),$decode);
627
-				}
628
-				elseif (preg_match(':^#H3:',$message)) {
657
+				} elseif (preg_match(':^#H3:',$message)) {
629 658
 					$decode = array_merge(array('Message nature' => 'Icing Report'),$decode);
630 659
 				}
631 660
 			}
632 661
 			if ($label == '10') {
633 662
 				if (preg_match(':^DTO01:',$message)) {
634 663
 					$decode = array_merge(array('Message nature' => 'Delayed Takeoff Report'),$decode);
635
-				}
636
-				elseif (preg_match(':^AIS01:',$message)) {
664
+				} elseif (preg_match(':^AIS01:',$message)) {
637 665
 					$decode = array_merge(array('Message nature' => 'AIS Request'),$decode);
638
-				}
639
-				elseif (preg_match(':^FTX01:',$message)) {
666
+				} elseif (preg_match(':^FTX01:',$message)) {
640 667
 					$decode = array_merge(array('Message nature' => 'Free Text Downlink'),$decode);
641
-				}
642
-				elseif (preg_match(':^FPL01:',$message)) {
668
+				} elseif (preg_match(':^FPL01:',$message)) {
643 669
 					$decode = array_merge(array('Message nature' => 'Flight Plan Request'),$decode);
644
-				}
645
-				elseif (preg_match(':^WAB01:',$message)) {
670
+				} elseif (preg_match(':^WAB01:',$message)) {
646 671
 					$decode = array_merge(array('Message nature' => 'Weight & Balance Request'),$decode);
647
-				}
648
-				elseif (preg_match(':^MET01:',$message)) {
672
+				} elseif (preg_match(':^MET01:',$message)) {
649 673
 					$decode = array_merge(array('Message nature' => 'Weather Data Request'),$decode);
650
-				}
651
-				elseif (preg_match(':^WAB02:',$message)) {
674
+				} elseif (preg_match(':^WAB02:',$message)) {
652 675
 					$decode = array_merge(array('Message nature' => 'Weight and Balance Acknowledgement'),$decode);
653 676
 				}
654 677
 			}
@@ -663,38 +686,28 @@  discard block
 block discarded – undo
663 686
 					$vsta = array('Version' => $version);
664 687
 					if ($state == 'E') {
665 688
 						$vsta = array_merge($vsta,array('Link state' => 'Established'));
666
-					}
667
-					elseif ($state == 'L') {
689
+					} elseif ($state == 'L') {
668 690
 						$vsta = array_merge($vsta,array('Link state' => 'Lost'));
669
-					}
670
-					else {
691
+					} else {
671 692
 						$vsta = array_merge($vsta,array('Link state' => 'Unknown'));
672 693
 					}
673 694
 					if ($type == 'V') {
674 695
 						$vsta = array_merge($vsta,array('Link type' => 'VHF ACARS'));
675
-					}
676
-					elseif ($type == 'S') {
696
+					} elseif ($type == 'S') {
677 697
 						$vsta = array_merge($vsta,array('Link type' => 'Generic SATCOM'));
678
-					}
679
-					elseif ($type == 'H') {
698
+					} elseif ($type == 'H') {
680 699
 						$vsta = array_merge($vsta,array('Link type' => 'HF'));
681
-					}
682
-					elseif ($type == 'G') {
700
+					} elseif ($type == 'G') {
683 701
 						$vsta = array_merge($vsta,array('Link type' => 'GlobalStar SATCOM'));
684
-					}
685
-					elseif ($type == 'C') {
702
+					} elseif ($type == 'C') {
686 703
 						$vsta = array_merge($vsta,array('Link type' => 'ICO SATCOM'));
687
-					}
688
-					elseif ($type == '2') {
704
+					} elseif ($type == '2') {
689 705
 						$vsta = array_merge($vsta,array('Link type' => 'VDL Mode 2'));
690
-					}
691
-					elseif ($type == 'X') {
706
+					} elseif ($type == 'X') {
692 707
 						$vsta = array_merge($vsta,array('Link type' => 'Inmarsat Aero'));
693
-					}
694
-					elseif ($type == 'I') {
708
+					} elseif ($type == 'I') {
695 709
 						$vsta = array_merge($vsta,array('Link type' => 'Irridium SATCOM'));
696
-					}
697
-					else {
710
+					} else {
698 711
 						$vsta = array_merge($vsta,array('Link type' => 'Unknown'));
699 712
 					}
700 713
 					$vsta = array_merge($vsta,array('Event occured at' => implode(':',str_split($at,2))));
@@ -703,7 +716,9 @@  discard block
 block discarded – undo
703 716
 			}
704 717
 
705 718
 			$title = $this->getTitlefromLabel($label);
706
-			if ($title != '') $decode = array_merge(array('Message title' => $title),$decode);
719
+			if ($title != '') {
720
+				$decode = array_merge(array('Message title' => $title),$decode);
721
+			}
707 722
 			/*
708 723
 			// Business jets always use GS0001
709 724
 			if ($ident != 'GS0001') $info = $this->addModeSData($ident,$registration,$icao,$airicao,$latitude,$longitude);
@@ -738,31 +753,54 @@  discard block
 block discarded – undo
738 753
 			$msg = $message['message'];
739 754
 			$decode = $message['decode'];
740 755
 			$registration = (string)$message['registration'];
741
-			if (isset($decode['latitude'])) $latitude = $decode['latitude'];
742
-			else $latitude = '';
743
-			if (isset($decode['longitude'])) $longitude = $decode['longitude'];
744
-			else $longitude = '';
745
-			if (isset($decode['airicao'])) $airicao = $decode['airicao'];
746
-			else $airicao = '';
747
-			if (isset($decode['icao'])) $icao = $decode['icao'];
748
-			else $icao = $Translation->checkTranslation($ident);
756
+			if (isset($decode['latitude'])) {
757
+				$latitude = $decode['latitude'];
758
+			} else {
759
+				$latitude = '';
760
+			}
761
+			if (isset($decode['longitude'])) {
762
+				$longitude = $decode['longitude'];
763
+			} else {
764
+				$longitude = '';
765
+			}
766
+			if (isset($decode['airicao'])) {
767
+				$airicao = $decode['airicao'];
768
+			} else {
769
+				$airicao = '';
770
+			}
771
+			if (isset($decode['icao'])) {
772
+				$icao = $decode['icao'];
773
+			} else {
774
+				$icao = $Translation->checkTranslation($ident);
775
+			}
749 776
 			$image_array = $Image->getSpotterImage($registration);
750 777
 			if (!isset($image_array[0]['registration'])) {
751 778
 				$Image->addSpotterImage($registration);
752 779
 			}
753 780
 			// Business jets always use GS0001
754
-			if ($ident != 'GS0001') $info = $this->addModeSData($ident,$registration,$icao,$airicao,$latitude,$longitude);
755
-			if ($globalDebug && isset($info) && $info != '') echo $info;
756
-			if (count($decode) > 0) $decode_json = json_encode($decode);
757
-			else $decode_json = '';
781
+			if ($ident != 'GS0001') {
782
+				$info = $this->addModeSData($ident,$registration,$icao,$airicao,$latitude,$longitude);
783
+			}
784
+			if ($globalDebug && isset($info) && $info != '') {
785
+				echo $info;
786
+			}
787
+			if (count($decode) > 0) {
788
+				$decode_json = json_encode($decode);
789
+			} else {
790
+				$decode_json = '';
791
+			}
758 792
 			if (isset($decode['Departure airport']) && isset($decode['Departure hour']) && isset($decode['Arrival airport']) && isset($decode['Arrival hour'])) {
759 793
 				$Schedule->addSchedule($icao,$decode['Departure airport'],$decode['Departure hour'],$decode['Arrival airport'],$decode['Arrival hour'],'ACARS');
760 794
 			} elseif (isset($decode['Departure airport']) && isset($decode['Arrival airport'])) {
761 795
 				$Schedule->addSchedule($icao,$decode['Departure airport'],'',$decode['Arrival airport'],'','ACARS');
762 796
 			}
763 797
 			$result = $this->addLiveAcarsData($ident,$registration,$label,$block_id,$msg_no,$msg,$decode_json);
764
-			if (!isset($globalACARSArchive)) $globalACARSArchive = array('10','80','81','82','3F');
765
-			if ($result && in_array($label,$globalACARSArchive)) $this->addArchiveAcarsData($ident,$registration,$label,$block_id,$msg_no,$msg,$decode_json);
798
+			if (!isset($globalACARSArchive)) {
799
+				$globalACARSArchive = array('10','80','81','82','3F');
800
+			}
801
+			if ($result && in_array($label,$globalACARSArchive)) {
802
+				$this->addArchiveAcarsData($ident,$registration,$label,$block_id,$msg_no,$msg,$decode_json);
803
+			}
766 804
 			if ($globalDebug && count($decode) > 0) {
767 805
 				echo "Human readable data : ".implode(' - ',$decode)."\n";
768 806
 			}
@@ -785,7 +823,9 @@  discard block
 block discarded – undo
785 823
 		if ($label != 'SQ' && $label != 'Q0' && $label != '_d' && $message != '') {
786 824
 			$Connection = new Connection($this->db);
787 825
 			$this->db = $Connection->db;
788
-			if ($globalDebug) echo "Test if not already in Live ACARS table...";
826
+			if ($globalDebug) {
827
+				echo "Test if not already in Live ACARS table...";
828
+			}
789 829
 			$query_test = "SELECT COUNT(*) as nb FROM acars_live WHERE ident = :ident AND registration = :registration AND message = :message";
790 830
 			$query_test_values = array(':ident' => $ident,':registration' => $registration, ':message' => $message);
791 831
 			try {
@@ -795,7 +835,9 @@  discard block
 block discarded – undo
795 835
 				return "error : ".$e->getMessage();
796 836
 			}
797 837
 			if ($stht->fetchColumn() == 0) {
798
-				if ($globalDebug) echo "Add Live ACARS data...";
838
+				if ($globalDebug) {
839
+					echo "Add Live ACARS data...";
840
+				}
799 841
 				$query = "INSERT INTO acars_live (ident,registration,label,block_id,msg_no,message,decode,date) VALUES (:ident,:registration,:label,:block_id,:msg_no,:message,:decode,:date)";
800 842
 				$query_values = array(':ident' => $ident,':registration' => $registration, ':label' => $label,':block_id' => $block_id, ':msg_no' => $msg_no, ':message' => $message, ':decode' => $decode,':date' => date("Y-m-d H:i:s"));
801 843
 				try {
@@ -805,10 +847,14 @@  discard block
 block discarded – undo
805 847
 					return "error : ".$e->getMessage();
806 848
 				}
807 849
 			} else {
808
-				if ($globalDebug) echo "Data already in DB...\n";
850
+				if ($globalDebug) {
851
+					echo "Data already in DB...\n";
852
+				}
809 853
 				return false;
810 854
 			}
811
-			if ($globalDebug) echo "Done\n";
855
+			if ($globalDebug) {
856
+				echo "Done\n";
857
+			}
812 858
 			return true;
813 859
 		}
814 860
 	}
@@ -839,7 +885,9 @@  discard block
 block discarded – undo
839 885
 			    	    }
840 886
 				    if ($stht->fetchColumn() == 0) {
841 887
 			*/
842
-			if ($globalDebug) echo "Add Live ACARS data...";
888
+			if ($globalDebug) {
889
+				echo "Add Live ACARS data...";
890
+			}
843 891
 			$query = "INSERT INTO acars_archive (ident,registration,label,block_id,msg_no,message,decode) VALUES (:ident,:registration,:label,:block_id,:msg_no,:message,:decode)";
844 892
 			$query_values = array(':ident' => $ident,':registration' => $registration, ':label' => $label,':block_id' => $block_id, ':msg_no' => $msg_no, ':message' => $message, ':decode' => $decode);
845 893
 			try {
@@ -848,7 +896,9 @@  discard block
 block discarded – undo
848 896
 			} catch(PDOException $e) {
849 897
 				return "error : ".$e->getMessage();
850 898
 			}
851
-			if ($globalDebug) echo "Done\n";
899
+			if ($globalDebug) {
900
+				echo "Done\n";
901
+			}
852 902
 		}
853 903
 	}
854 904
 
@@ -871,8 +921,11 @@  discard block
 block discarded – undo
871 921
 			die;
872 922
 		}
873 923
 		$row = $sth->fetchAll(PDO::FETCH_ASSOC);
874
-		if (count($row) > 0) return $row[0]['title'];
875
-		else return '';
924
+		if (count($row) > 0) {
925
+			return $row[0]['title'];
926
+		} else {
927
+			return '';
928
+		}
876 929
 	}
877 930
 
878 931
 	/**
@@ -891,8 +944,11 @@  discard block
 block discarded – undo
891 944
 			die;
892 945
 		}
893 946
 		$row = $sth->fetchAll(PDO::FETCH_ASSOC);
894
-		if (count($row) > 0) return $row;
895
-		else return array();
947
+		if (count($row) > 0) {
948
+			return $row;
949
+		} else {
950
+			return array();
951
+		}
896 952
 	}
897 953
 
898 954
 	/**
@@ -912,8 +968,11 @@  discard block
 block discarded – undo
912 968
 			die;
913 969
 		}
914 970
 		$row = $sth->fetchAll(PDO::FETCH_ASSOC);
915
-		if (count($row) > 0) return $row[0];
916
-		else return array();
971
+		if (count($row) > 0) {
972
+			return $row[0];
973
+		} else {
974
+			return array();
975
+		}
917 976
 	}
918 977
 
919 978
 	/**
@@ -958,19 +1017,35 @@  discard block
 block discarded – undo
958 1017
 			if ($row['registration'] != '') {
959 1018
 				$row['registration'] = str_replace('.','',$row['registration']);
960 1019
 				$image_array = $Image->getSpotterImage($row['registration']);
961
-				if (count($image_array) > 0) $data = array_merge($data,array('image' => $image_array[0]['image'],'image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website']));
962
-				else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
963
-			} else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
964
-			if ($row['registration'] == '') $row['registration'] = 'NA';
965
-			if ($row['ident'] == '') $row['ident'] = 'NA';
1020
+				if (count($image_array) > 0) {
1021
+					$data = array_merge($data,array('image' => $image_array[0]['image'],'image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website']));
1022
+				} else {
1023
+					$data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
1024
+				}
1025
+			} else {
1026
+				$data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
1027
+			}
1028
+			if ($row['registration'] == '') {
1029
+				$row['registration'] = 'NA';
1030
+			}
1031
+			if ($row['ident'] == '') {
1032
+				$row['ident'] = 'NA';
1033
+			}
966 1034
 			$identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,2));
967 1035
 			if (isset($identicao[0])) {
968 1036
 				if (substr($row['ident'],0,2) == 'AF') {
969
-					if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident'];
970
-					else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
971
-				} else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
1037
+					if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) {
1038
+						$icao = $row['ident'];
1039
+					} else {
1040
+						$icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
1041
+					}
1042
+				} else {
1043
+					$icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
1044
+				}
972 1045
 				$data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name']));
973
-			} else $icao = $row['ident'];
1046
+			} else {
1047
+				$icao = $row['ident'];
1048
+			}
974 1049
 			$icao = $Translation->checkTranslation($icao,false);
975 1050
 			$decode = json_decode($row['decode'],true);
976 1051
 			$found = false;
@@ -995,7 +1070,9 @@  discard block
 block discarded – undo
995 1070
 					$found = true;
996 1071
 				}
997 1072
 			}
998
-			if ($found) $row['decode'] = json_encode($decode);
1073
+			if ($found) {
1074
+				$row['decode'] = json_encode($decode);
1075
+			}
999 1076
 			$data = array_merge($data,array('registration' => $row['registration'],'message' => $row['message'], 'date' => $row['date'], 'ident' => $icao, 'decode' => $row['decode']));
1000 1077
 			$result[] = $data;
1001 1078
 			$i++;
@@ -1003,8 +1080,9 @@  discard block
 block discarded – undo
1003 1080
 		if (isset($result)) {
1004 1081
 			$result[0]['query_number_rows'] = $i;
1005 1082
 			return $result;
1083
+		} else {
1084
+			return array();
1006 1085
 		}
1007
-		else return array();
1008 1086
 	}
1009 1087
 
1010 1088
 	/**
@@ -1053,31 +1131,51 @@  discard block
 block discarded – undo
1053 1131
 			if ($row['registration'] != '') {
1054 1132
 				$row['registration'] = str_replace('.','',$row['registration']);
1055 1133
 				$image_array = $Image->getSpotterImage($row['registration']);
1056
-				if (count($image_array) > 0) $data = array_merge($data,array('image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website']));
1057
-				else $data = array_merge($data,array('image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
1058
-			} else $data = array_merge($data,array('image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
1134
+				if (count($image_array) > 0) {
1135
+					$data = array_merge($data,array('image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website']));
1136
+				} else {
1137
+					$data = array_merge($data,array('image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
1138
+				}
1139
+			} else {
1140
+				$data = array_merge($data,array('image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
1141
+			}
1059 1142
 			$icao = '';
1060
-			if ($row['registration'] == '') $row['registration'] = 'NA';
1061
-			if ($row['ident'] == '') $row['ident'] = 'NA';
1143
+			if ($row['registration'] == '') {
1144
+				$row['registration'] = 'NA';
1145
+			}
1146
+			if ($row['ident'] == '') {
1147
+				$row['ident'] = 'NA';
1148
+			}
1062 1149
 			$identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,2));
1063 1150
 			if (isset($identicao[0])) {
1064 1151
 				if (substr($row['ident'],0,2) == 'AF') {
1065
-					if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident'];
1066
-					else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
1067
-				} else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
1152
+					if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) {
1153
+						$icao = $row['ident'];
1154
+					} else {
1155
+						$icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
1156
+					}
1157
+				} else {
1158
+					$icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
1159
+				}
1068 1160
 				$data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name']));
1069
-			} else $icao = $row['ident'];
1161
+			} else {
1162
+				$icao = $row['ident'];
1163
+			}
1070 1164
 			$icao = $Translation->checkTranslation($icao);
1071 1165
 			$decode = json_decode($row['decode'],true);
1072 1166
 			$found = false;
1073 1167
 			if ($decode != '' && array_key_exists('Departure airport',$decode)) {
1074 1168
 				$airport_info = $Spotter->getAllAirportInfo($decode['Departure airport']);
1075
-				if (isset($airport_info[0]['icao'])) $decode['Departure airport'] = '<a href="'.$globalURL.'/airport/'.$airport_info[0]['icao'].'">'.$airport_info[0]['city'].','.$airport_info[0]['country'].' ('.$airport_info[0]['icao'].')</a>';
1169
+				if (isset($airport_info[0]['icao'])) {
1170
+					$decode['Departure airport'] = '<a href="'.$globalURL.'/airport/'.$airport_info[0]['icao'].'">'.$airport_info[0]['city'].','.$airport_info[0]['country'].' ('.$airport_info[0]['icao'].')</a>';
1171
+				}
1076 1172
 				$found = true;
1077 1173
 			}
1078 1174
 			if ($decode != '' && array_key_exists('Arrival airport',$decode)) {
1079 1175
 				$airport_info = $Spotter->getAllAirportInfo($decode['Arrival airport']);
1080
-				if (isset($airport_info[0]['icao'])) $decode['Arrival airport'] = '<a href="'.$globalURL.'/airport/'.$airport_info[0]['icao'].'">'.$airport_info[0]['city'].','.$airport_info[0]['country'].' ('.$airport_info[0]['icao'].')</a>';
1176
+				if (isset($airport_info[0]['icao'])) {
1177
+					$decode['Arrival airport'] = '<a href="'.$globalURL.'/airport/'.$airport_info[0]['icao'].'">'.$airport_info[0]['city'].','.$airport_info[0]['country'].' ('.$airport_info[0]['icao'].')</a>';
1178
+				}
1081 1179
 				$found = true;
1082 1180
 			}
1083 1181
 			if ($decode != '' && array_key_exists('Airport/Waypoint name',$decode)) {
@@ -1087,7 +1185,9 @@  discard block
 block discarded – undo
1087 1185
 					$found = true;
1088 1186
 				}
1089 1187
 			}
1090
-			if ($found) $row['decode'] = json_encode($decode);
1188
+			if ($found) {
1189
+				$row['decode'] = json_encode($decode);
1190
+			}
1091 1191
 			$data = array_merge($data,array('registration' => $row['registration'],'message' => $row['message'], 'date' => $row['date'], 'ident' => $icao, 'decode' => $row['decode']));
1092 1192
 			$result[] = $data;
1093 1193
 			$i++;
@@ -1095,7 +1195,9 @@  discard block
 block discarded – undo
1095 1195
 		if (isset($result)) {
1096 1196
 			$result[0]['query_number_rows'] = $i;
1097 1197
 			return $result;
1098
-		} else return array();
1198
+		} else {
1199
+			return array();
1200
+		}
1099 1201
 	}
1100 1202
 
1101 1203
 	/**
@@ -1111,25 +1213,37 @@  discard block
 block discarded – undo
1111 1213
 		$ident = trim($ident);
1112 1214
 		$Translation = new Translation($this->db);
1113 1215
 		$Spotter = new Spotter($this->db);
1114
-		if ($globalDebug) echo "Test if we add ModeS data...";
1216
+		if ($globalDebug) {
1217
+			echo "Test if we add ModeS data...";
1218
+		}
1115 1219
 		//if ($icao == '') $icao = ACARS->ident2icao($ident);
1116
-		if ($icao == '') $icao = $Translation->checkTranslation($ident);
1117
-		if ($globalDebug) echo '- Ident : '.$icao.' - ';
1220
+		if ($icao == '') {
1221
+			$icao = $Translation->checkTranslation($ident);
1222
+		}
1223
+		if ($globalDebug) {
1224
+			echo '- Ident : '.$icao.' - ';
1225
+		}
1118 1226
 		if ($ident == '' || $registration == '') {
1119
-			if ($globalDebug) echo "Ident or registration null, exit\n";
1227
+			if ($globalDebug) {
1228
+				echo "Ident or registration null, exit\n";
1229
+			}
1120 1230
 			return '';
1121 1231
 		}
1122 1232
 		$registration = str_replace('.','',$registration);
1123 1233
 		$ident = $Translation->ident2icao($ident);
1124 1234
 		// Check if a flight with same registration is flying now, if ok check if callsign = name in ACARS, else add it to translation
1125
-		if ($globalDebug) echo "Check if needed to add translation ".$ident.'... ';
1235
+		if ($globalDebug) {
1236
+			echo "Check if needed to add translation ".$ident.'... ';
1237
+		}
1126 1238
 		$querysi = "SELECT ident FROM spotter_live s,aircraft_modes a WHERE a.ModeS = s.ModeS AND a.Registration = :registration AND s.format_source <> 'ACARS' LIMIT 1";
1127 1239
 		$querysi_values = array(':registration' => $registration);
1128 1240
 		try {
1129 1241
 			$sthsi = $this->db->prepare($querysi);
1130 1242
 			$sthsi->execute($querysi_values);
1131 1243
 		} catch(PDOException $e) {
1132
-			if ($globalDebug) echo $e->getMessage();
1244
+			if ($globalDebug) {
1245
+				echo $e->getMessage();
1246
+			}
1133 1247
 			return "error : ".$e->getMessage();
1134 1248
 		}
1135 1249
 		$resultsi = $sthsi->fetch(PDO::FETCH_ASSOC);
@@ -1137,9 +1251,14 @@  discard block
 block discarded – undo
1137 1251
 		if (count($resultsi) > 0 && $resultsi['ident'] != $ident && $resultsi['ident'] != '') {
1138 1252
 			$Translation = new Translation($this->db);
1139 1253
 			$trans_ident = $Translation->getOperator($resultsi['ident']);
1140
-			if ($globalDebug) echo 'Add translation to table : '.$ident.' -> '.$resultsi['ident'].' ';
1141
-			if ($ident != $trans_ident) $Translation->addOperator($resultsi['ident'],$ident,'ACARS');
1142
-			elseif ($trans_ident == $ident) $Translation->updateOperator($resultsi['ident'],$ident,'ACARS');
1254
+			if ($globalDebug) {
1255
+				echo 'Add translation to table : '.$ident.' -> '.$resultsi['ident'].' ';
1256
+			}
1257
+			if ($ident != $trans_ident) {
1258
+				$Translation->addOperator($resultsi['ident'],$ident,'ACARS');
1259
+			} elseif ($trans_ident == $ident) {
1260
+				$Translation->updateOperator($resultsi['ident'],$ident,'ACARS');
1261
+			}
1143 1262
 		} else {
1144 1263
 			if ($registration != '' && $latitude != '' && $longitude != '') {
1145 1264
 				$query = "SELECT ModeS FROM aircraft_modes WHERE Registration = :registration LIMIT 1";
@@ -1148,32 +1267,44 @@  discard block
 block discarded – undo
1148 1267
 					$sth = $this->db->prepare($query);
1149 1268
 					$sth->execute($query_values);
1150 1269
 				} catch(PDOException $e) {
1151
-					if ($globalDebug) echo $e->getMessage();
1270
+					if ($globalDebug) {
1271
+						echo $e->getMessage();
1272
+					}
1152 1273
 					return "error : ".$e->getMessage();
1153 1274
 				}
1154 1275
 				$result = $sth->fetch(PDO::FETCH_ASSOC);
1155 1276
 				$sth->closeCursor();
1156
-				if (isset($result['modes'])) $hex = $result['modes'];
1157
-				else $hex = '';
1277
+				if (isset($result['modes'])) {
1278
+					$hex = $result['modes'];
1279
+				} else {
1280
+					$hex = '';
1281
+				}
1158 1282
 				$SI_data = array('hex' => $hex,'ident' => $ident,'aircraft_icao' => $ICAOTypeCode,'registration' => $registration,'latitude' => $latitude,'$longitude' => $longitude,'format_source' => 'ACARS');
1159 1283
 				$this->SI->add($SI_data);
1160 1284
 			}
1161 1285
 		}
1162
-		if ($globalDebug) echo 'Done'."\n";
1286
+		if ($globalDebug) {
1287
+			echo 'Done'."\n";
1288
+		}
1163 1289
 		$query = "SELECT flightaware_id, ModeS FROM spotter_output WHERE ident = :ident AND format_source <> 'ACARS' ORDER BY spotter_id DESC LIMIT 1";
1164 1290
 		$query_values = array(':ident' => $icao);
1165 1291
 		try {
1166 1292
 			$sth = $this->db->prepare($query);
1167 1293
 			$sth->execute($query_values);
1168 1294
 		} catch(PDOException $e) {
1169
-			if ($globalDebug) echo $e->getMessage();
1295
+			if ($globalDebug) {
1296
+				echo $e->getMessage();
1297
+			}
1170 1298
 			return "error : ".$e->getMessage();
1171 1299
 		}
1172 1300
 		$result = $sth->fetch(PDO::FETCH_ASSOC);
1173 1301
 		$sth->closeCursor();
1174 1302
 		if (isset($result['flightaware_id'])) {
1175
-			if (isset($result['ModeS'])) $ModeS = $result['ModeS'];
1176
-			else $ModeS = '';
1303
+			if (isset($result['ModeS'])) {
1304
+				$ModeS = $result['ModeS'];
1305
+			} else {
1306
+				$ModeS = '';
1307
+			}
1177 1308
 			if ($ModeS == '') {
1178 1309
 				$id = explode('-',$result['flightaware_id']);
1179 1310
 				$ModeS = $id[0];
@@ -1186,24 +1317,32 @@  discard block
 block discarded – undo
1186 1317
 					$sthc = $this->db->prepare($queryc);
1187 1318
 					$sthc->execute($queryc_values);
1188 1319
 				} catch(PDOException $e) {
1189
-					if ($globalDebug) echo $e->getMessage();
1320
+					if ($globalDebug) {
1321
+						echo $e->getMessage();
1322
+					}
1190 1323
 					return "error : ".$e->getMessage();
1191 1324
 				}
1192 1325
 				$row = $sthc->fetch(PDO::FETCH_ASSOC);
1193 1326
 				$sthc->closeCursor();
1194 1327
 				if (count($row) ==  0) {
1195
-					if ($globalDebug) echo " Add to ModeS table - ";
1328
+					if ($globalDebug) {
1329
+						echo " Add to ModeS table - ";
1330
+					}
1196 1331
 					$queryi = "INSERT INTO aircraft_modes (ModeS,ModeSCountry,Registration,ICAOTypeCode,Source) VALUES (:ModeS,:ModeSCountry,:Registration, :ICAOTypeCode,'ACARS')";
1197 1332
 					$queryi_values = array(':ModeS' => $ModeS,':ModeSCountry' => $country,':Registration' => $registration, ':ICAOTypeCode' => $ICAOTypeCode);
1198 1333
 					try {
1199 1334
 						$sthi = $this->db->prepare($queryi);
1200 1335
 						$sthi->execute($queryi_values);
1201 1336
 					} catch(PDOException $e) {
1202
-						if ($globalDebug) echo $e->getMessage();
1337
+						if ($globalDebug) {
1338
+							echo $e->getMessage();
1339
+						}
1203 1340
 						return "error : ".$e->getMessage();
1204 1341
 					}
1205 1342
 				} else {
1206
-					if ($globalDebug) echo " Update ModeS table - ";
1343
+					if ($globalDebug) {
1344
+						echo " Update ModeS table - ";
1345
+					}
1207 1346
 					if ($ICAOTypeCode != '') {
1208 1347
 						$queryi = "UPDATE aircraft_modes SET ModeSCountry = :ModeSCountry,Registration = :Registration,ICAOTypeCode = :ICAOTypeCode,Source = 'ACARS',LastModified = NOW() WHERE ModeS = :ModeS";
1209 1348
 						$queryi_values = array(':ModeS' => $ModeS,':ModeSCountry' => $country,':Registration' => $registration, ':ICAOTypeCode' => $ICAOTypeCode);
@@ -1215,7 +1354,9 @@  discard block
 block discarded – undo
1215 1354
 						$sthi = $this->db->prepare($queryi);
1216 1355
 						$sthi->execute($queryi_values);
1217 1356
 					} catch(PDOException $e) {
1218
-						if ($globalDebug) echo $e->getMessage();
1357
+						if ($globalDebug) {
1358
+							echo $e->getMessage();
1359
+						}
1219 1360
 						return "error : ".$e->getMessage();
1220 1361
 					}
1221 1362
 				}
@@ -1236,7 +1377,9 @@  discard block
 block discarded – undo
1236 1377
 					    return "error : ".$e->getMessage();
1237 1378
 				}
1238 1379
 				*/
1239
-				if ($globalDebug) echo " Update Spotter_output table - ";
1380
+				if ($globalDebug) {
1381
+					echo " Update Spotter_output table - ";
1382
+				}
1240 1383
 				if ($ICAOTypeCode != '') {
1241 1384
 					if ($globalDBdriver == 'mysql') {
1242 1385
 						$queryi = "UPDATE spotter_output SET registration = :Registration,aircraft_icao = :ICAOTypeCode WHERE ident = :ident AND date >= date_sub(UTC_TIMESTAMP(), INTERVAL 1 HOUR)";
@@ -1247,8 +1390,7 @@  discard block
 block discarded – undo
1247 1390
 				} else {
1248 1391
 					if ($globalDBdriver == 'mysql') {
1249 1392
 						$queryi = "UPDATE spotter_output SET registration = :Registration WHERE ident = :ident AND date >= date_sub(UTC_TIMESTAMP(), INTERVAL 1 HOUR)";
1250
-					}
1251
-					elseif ($globalDBdriver == 'pgsql') {
1393
+					} elseif ($globalDBdriver == 'pgsql') {
1252 1394
 						$queryi = "UPDATE spotter_output SET registration = :Registration WHERE ident = :ident AND date >= NOW() AT TIME ZONE 'UTC' - INTERVAL '1 HOUR'";
1253 1395
 					}
1254 1396
 					$queryi_values = array(':Registration' => $registration,':ident' => $icao);
@@ -1257,14 +1399,20 @@  discard block
 block discarded – undo
1257 1399
 					$sthi = $this->db->prepare($queryi);
1258 1400
 					$sthi->execute($queryi_values);
1259 1401
 				} catch(PDOException $e) {
1260
-					if ($globalDebug) echo $e->getMessage();
1402
+					if ($globalDebug) {
1403
+						echo $e->getMessage();
1404
+					}
1261 1405
 					return "error : ".$e->getMessage();
1262 1406
 				}
1263 1407
 			}
1264 1408
 		} else {
1265
-			if ($globalDebug) echo " Can't find ModeS in spotter_output - ";
1409
+			if ($globalDebug) {
1410
+				echo " Can't find ModeS in spotter_output - ";
1411
+			}
1412
+		}
1413
+		if ($globalDebug) {
1414
+			echo "Done\n";
1266 1415
 		}
1267
-		if ($globalDebug) echo "Done\n";
1268 1416
 	}
1269 1417
 }
1270 1418
 ?>
Please login to merge, or discard this patch.
require/class.APRS.php 1 patch
Braces   +163 added lines, -62 removed lines patch added patch discarded remove patch
@@ -183,17 +183,23 @@  discard block
 block discarded – undo
183 183
 	
184 184
 	/* Check that end was found and body has at least one byte. */
185 185
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
186
-	    if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
186
+	    if ($globalDebug) {
187
+	    	echo '!!! APRS invalid : '.$input."\n";
188
+	    }
187 189
 	    return false;
188 190
 	}
189 191
 	
190
-	if ($debug) echo 'input : '.$input."\n";
192
+	if ($debug) {
193
+		echo 'input : '.$input."\n";
194
+	}
191 195
 	/* Save header and body. */
192 196
 	$body = substr($input,$splitpos+1,$input_len);
193 197
 	$body_len = strlen($body);
194 198
 	$header = substr($input,0,$splitpos);
195 199
 	//$header_len = strlen($header);
196
-	if ($debug) echo 'header : '.$header."\n";
200
+	if ($debug) {
201
+		echo 'header : '.$header."\n";
202
+	}
197 203
 	
198 204
 	/* Parse source, target and path. */
199 205
 	//FLRDF0A52>APRS,qAS,LSTB
@@ -207,11 +213,15 @@  discard block
 block discarded – undo
207 213
 		$result['format_source'] = 'famaprs';
208 214
 		$result['source_type'] = 'ais';
209 215
 	    } else {
210
-		if ($debug) echo 'ident : '.$ident."\n";
216
+		if ($debug) {
217
+			echo 'ident : '.$ident."\n";
218
+		}
211 219
 		$result['ident'] = $ident;
212 220
 	    }
213 221
 	} else {
214
-	    if ($debug) 'No ident'."\n";
222
+	    if ($debug) {
223
+	    	'No ident'."\n";
224
+	    }
215 225
 	    return false;
216 226
 	}
217 227
 	$elements = explode(',',$all_elements);
@@ -222,7 +232,9 @@  discard block
 block discarded – undo
222 232
 	        //echo "ok";
223 233
 	        //if ($element == 'TCPIP*') return false;
224 234
 	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
225
-		if ($debug) echo 'element : '.$element."\n";
235
+		if ($debug) {
236
+			echo 'element : '.$element."\n";
237
+		}
226 238
 		return false;
227 239
 	    }
228 240
 	    /*
@@ -235,13 +247,17 @@  discard block
 block discarded – undo
235 247
 	}
236 248
 	
237 249
 	$type = substr($body,0,1);
238
-	if ($debug) echo 'type : '.$type."\n";
250
+	if ($debug) {
251
+		echo 'type : '.$type."\n";
252
+	}
239 253
 	if ($type == ';') {
240 254
 		if (isset($result['source_type']) && $result['source_type'] == 'modes') {
241 255
 			$result['address'] = trim(substr($body,1,9));
242 256
 		} elseif (isset($result['source_type']) && $result['source_type'] == 'ais') {
243 257
 			$result['mmsi'] = trim(substr($body,1,9));
244
-		} else $result['ident'] = trim(substr($body,1,9));
258
+		} else {
259
+			$result['ident'] = trim(substr($body,1,9));
260
+		}
245 261
 	} elseif ($type == ',') {
246 262
 		// Invalid data or test data
247 263
 		return false;
@@ -310,7 +326,9 @@  discard block
 block discarded – undo
310 326
 		//$symbol_table = $matches[4];
311 327
 		$lat = intval($lat_deg);
312 328
 		$lon = intval($lon_deg);
313
-		if ($lat > 89 || $lon > 179) return false;
329
+		if ($lat > 89 || $lon > 179) {
330
+			return false;
331
+		}
314 332
 	    
315 333
 	    /*
316 334
 	    $tmp_5b = str_replace('.','',$lat_min);
@@ -320,8 +338,12 @@  discard block
 block discarded – undo
320 338
 	    */
321 339
 		$latitude = $lat + floatval($lat_min)/60;
322 340
 		$longitude = $lon + floatval($lon_min)/60;
323
-		if ($sind == 'S') $latitude = 0-$latitude;
324
-		if ($wind == 'W') $longitude = 0-$longitude;
341
+		if ($sind == 'S') {
342
+			$latitude = 0-$latitude;
343
+		}
344
+		if ($wind == 'W') {
345
+			$longitude = 0-$longitude;
346
+		}
325 347
 		$result['latitude'] = $latitude;
326 348
 		$result['longitude'] = $longitude;
327 349
 		$body_parse = substr($body_parse,18);
@@ -348,8 +370,11 @@  discard block
 block discarded – undo
348 370
 		if ($find) {
349 371
 			$body_split = str_split($body_parse);
350 372
 			$symbol_code = $body_split[0];
351
-			if (!isset($symbolll) || $symbolll == '/') $symbol_code = '/'.$symbol_code;
352
-			else $symbol_code = '\\'.$symbol_code;
373
+			if (!isset($symbolll) || $symbolll == '/') {
374
+				$symbol_code = '/'.$symbol_code;
375
+			} else {
376
+				$symbol_code = '\\'.$symbol_code;
377
+			}
353 378
 		//}
354 379
 		//echo $body_parse;
355 380
 			//if ($type != ';' && $type != '>') {
@@ -357,7 +382,9 @@  discard block
 block discarded – undo
357 382
 			$body_parse = substr($body_parse,1);
358 383
 			$body_parse_len = strlen($body_parse);
359 384
 			$result['symbol_code'] = $symbol_code;
360
-			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
385
+			if (isset($this->symbols[$symbol_code])) {
386
+				$result['symbol'] = $this->symbols[$symbol_code];
387
+			}
361 388
 			if ($symbol_code != '_') {
362 389
 			}
363 390
 		    //$body_parse = substr($body_parse,1);
@@ -368,7 +395,9 @@  discard block
 block discarded – undo
368 395
 		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
369 396
 		    	    $course = substr($body_parse,0,3);
370 397
 		    	    $tmp_s = intval($course);
371
-		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
398
+		    	    if ($tmp_s >= 1 && $tmp_s <= 360) {
399
+		    	    	$result['heading'] = intval($course);
400
+		    	    }
372 401
 		    	    $speed = substr($body_parse,4,3);
373 402
 		    	    if ($speed != '...') {
374 403
 		    		//$result['speed'] = round($speed*1.852);
@@ -409,10 +438,16 @@  discard block
 block discarded – undo
409 438
 			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
410 439
 			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
411 440
 			    
412
-				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
413
-				else $result['latitude'] += $lat_off;
414
-				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
415
-				else $result['longitude'] += $lon_off;
441
+				if ($result['latitude'] < 0) {
442
+					$result['latitude'] -= $lat_off;
443
+				} else {
444
+					$result['latitude'] += $lat_off;
445
+				}
446
+				if ($result['longitude'] < 0) {
447
+					$result['longitude'] -= $lon_off;
448
+				} else {
449
+					$result['longitude'] += $lon_off;
450
+				}
416 451
 			    }
417 452
 			    
418 453
 		            $body_parse = substr($body_parse,6);
@@ -454,27 +489,48 @@  discard block
 block discarded – undo
454 489
 			$address = substr($id,2);
455 490
 			//print_r($matches);
456 491
 			$addressType = (intval(substr($id,0,2),16))&3;
457
-			if ($addressType == 0) $result['addresstype'] = "RANDOM";
458
-			elseif ($addressType == 1) $result['addresstype'] = "ICAO";
459
-			elseif ($addressType == 2) $result['addresstype'] = "FLARM";
460
-			elseif ($addressType == 3) $result['addresstype'] = "OGN";
492
+			if ($addressType == 0) {
493
+				$result['addresstype'] = "RANDOM";
494
+			} elseif ($addressType == 1) {
495
+				$result['addresstype'] = "ICAO";
496
+			} elseif ($addressType == 2) {
497
+				$result['addresstype'] = "FLARM";
498
+			} elseif ($addressType == 3) {
499
+				$result['addresstype'] = "OGN";
500
+			}
461 501
 			$aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2);
462 502
 			$result['aircrafttype_code'] = $aircraftType;
463
-			if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN";
464
-			elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER";
465
-			elseif ($aircraftType == 2) $result['aircrafttype'] = "TOW_PLANE";
466
-			elseif ($aircraftType == 3) $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
467
-			elseif ($aircraftType == 4) $result['aircrafttype'] = "PARACHUTE";
468
-			elseif ($aircraftType == 5) $result['aircrafttype'] = "DROP_PLANE";
469
-			elseif ($aircraftType == 6) $result['aircrafttype'] = "HANG_GLIDER";
470
-			elseif ($aircraftType == 7) $result['aircrafttype'] = "PARA_GLIDER";
471
-			elseif ($aircraftType == 8) $result['aircrafttype'] = "POWERED_AIRCRAFT";
472
-			elseif ($aircraftType == 9) $result['aircrafttype'] = "JET_AIRCRAFT";
473
-			elseif ($aircraftType == 10) $result['aircrafttype'] = "UFO";
474
-			elseif ($aircraftType == 11) $result['aircrafttype'] = "BALLOON";
475
-			elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP";
476
-			elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV";
477
-			elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT";
503
+			if ($aircraftType == 0) {
504
+				$result['aircrafttype'] = "UNKNOWN";
505
+			} elseif ($aircraftType == 1) {
506
+				$result['aircrafttype'] = "GLIDER";
507
+			} elseif ($aircraftType == 2) {
508
+				$result['aircrafttype'] = "TOW_PLANE";
509
+			} elseif ($aircraftType == 3) {
510
+				$result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
511
+			} elseif ($aircraftType == 4) {
512
+				$result['aircrafttype'] = "PARACHUTE";
513
+			} elseif ($aircraftType == 5) {
514
+				$result['aircrafttype'] = "DROP_PLANE";
515
+			} elseif ($aircraftType == 6) {
516
+				$result['aircrafttype'] = "HANG_GLIDER";
517
+			} elseif ($aircraftType == 7) {
518
+				$result['aircrafttype'] = "PARA_GLIDER";
519
+			} elseif ($aircraftType == 8) {
520
+				$result['aircrafttype'] = "POWERED_AIRCRAFT";
521
+			} elseif ($aircraftType == 9) {
522
+				$result['aircrafttype'] = "JET_AIRCRAFT";
523
+			} elseif ($aircraftType == 10) {
524
+				$result['aircrafttype'] = "UFO";
525
+			} elseif ($aircraftType == 11) {
526
+				$result['aircrafttype'] = "BALLOON";
527
+			} elseif ($aircraftType == 12) {
528
+				$result['aircrafttype'] = "AIRSHIP";
529
+			} elseif ($aircraftType == 13) {
530
+				$result['aircrafttype'] = "UAV";
531
+			} elseif ($aircraftType == 15) {
532
+				$result['aircrafttype'] = "STATIC_OBJECT";
533
+			}
478 534
 			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
479 535
 			$result['stealth'] = $stealth;
480 536
 			$result['address'] = $address;
@@ -514,13 +570,21 @@  discard block
 block discarded – undo
514 570
 			$result['temp'] = round(5/9*(($matches[1])-32),1);
515 571
 		    }
516 572
 		}
517
-		} else $result['comment'] = trim($body_parse);
573
+		} else {
574
+			$result['comment'] = trim($body_parse);
575
+		}
518 576
 
519 577
 	    }
520 578
 	//}
521
-	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
522
-	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
523
-	if ($debug) print_r($result);
579
+	if (isset($result['latitude'])) {
580
+		$result['latitude'] = round($result['latitude'],4);
581
+	}
582
+	if (isset($result['longitude'])) {
583
+		$result['longitude'] = round($result['longitude'],4);
584
+	}
585
+	if ($debug) {
586
+		print_r($result);
587
+	}
524 588
 	return $result;
525 589
     }
526 590
     
@@ -529,12 +593,21 @@  discard block
 block discarded – undo
529 593
 	$aprs_connect = 0;
530 594
 	$aprs_keep = 120;
531 595
 	$aprs_last_tx = time();
532
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
533
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
534
-	if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid;
535
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
536
-	if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass;
537
-	else $aprs_pass = '-1';
596
+	if (isset($globalAPRSversion)) {
597
+		$aprs_version = $globalAPRSversion;
598
+	} else {
599
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
600
+	}
601
+	if (isset($globalServerAPRSssid)) {
602
+		$aprs_ssid = $globalServerAPRSssid;
603
+	} else {
604
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
605
+	}
606
+	if (isset($globalServerAPRSpass)) {
607
+		$aprs_pass = $globalServerAPRSpass;
608
+	} else {
609
+		$aprs_pass = '-1';
610
+	}
538 611
 	
539 612
 	$aprs_filter  = '';
540 613
 	$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
@@ -567,10 +640,14 @@  discard block
 block discarded – undo
567 640
     
568 641
     public function send($data) {
569 642
 	global $globalDebug;
570
-	if ($this->connected === false) $this->connect();
643
+	if ($this->connected === false) {
644
+		$this->connect();
645
+	}
571 646
 	$send = socket_send( $this->socket  , $data , strlen($data),0);
572 647
 	if ($send === FALSE) {
573
-		if ($globalDebug) echo 'Reconnect...';
648
+		if ($globalDebug) {
649
+			echo 'Reconnect...';
650
+		}
574 651
 		socket_close($this->socket);
575 652
 		$this->connect();
576 653
 	}
@@ -590,22 +667,32 @@  discard block
 block discarded – undo
590 667
 			//$w = '00';
591 668
 			$custom = '';
592 669
 			if ($ident != '') {
593
-				if ($custom != '') $custom .= '/';
670
+				if ($custom != '') {
671
+					$custom .= '/';
672
+				}
594 673
 				$custom .= 'CS='.$ident;
595 674
 			}
596 675
 			if ($squawk != '') {
597
-				if ($custom != '') $custom .= '/';
676
+				if ($custom != '') {
677
+					$custom .= '/';
678
+				}
598 679
 				$custom .= 'SQ='.$squawk;
599 680
 			}
600 681
 			if ($verticalrate != '') {
601
-				if ($custom != '') $custom .= '/';
682
+				if ($custom != '') {
683
+					$custom .= '/';
684
+				}
602 685
 				$custom .= 'VR='.$verticalrate;
603 686
 			}
604 687
 			if ($aircraft_icao != '' && $aircraft_icao != 'NA') {
605
-				if ($custom != '') $custom .= '/';
688
+				if ($custom != '') {
689
+					$custom .= '/';
690
+				}
606 691
 				$custom .= 'AI='.$aircraft_icao;
607 692
 			}
608
-			if ($custom != '') $custom = ' '.$custom;
693
+			if ($custom != '') {
694
+				$custom = ' '.$custom;
695
+			}
609 696
 			$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");
610 697
 		}
611 698
 	}
@@ -623,30 +710,44 @@  discard block
 block discarded – undo
623 710
 			//$w = '00';
624 711
 			$custom = '';
625 712
 			if ($ident != '') {
626
-				if ($custom != '') $custom .= '/';
713
+				if ($custom != '') {
714
+					$custom .= '/';
715
+				}
627 716
 				$custom .= 'CS='.str_replace(' ','_',$ident);
628 717
 			}
629 718
 			if ($typeid != '') {
630
-				if ($custom != '') $custom .= '/';
719
+				if ($custom != '') {
720
+					$custom .= '/';
721
+				}
631 722
 				$custom .= 'TI='.$typeid;
632 723
 			}
633 724
 			if ($statusid != '') {
634
-				if ($custom != '') $custom .= '/';
725
+				if ($custom != '') {
726
+					$custom .= '/';
727
+				}
635 728
 				$custom .= 'SI='.$statusid;
636 729
 			}
637 730
 			if ($imo != '') {
638
-				if ($custom != '') $custom .= '/';
731
+				if ($custom != '') {
732
+					$custom .= '/';
733
+				}
639 734
 				$custom .= 'IMO='.$imo;
640 735
 			}
641 736
 			if ($arrival_date != '') {
642
-				if ($custom != '') $custom .= '/';
737
+				if ($custom != '') {
738
+					$custom .= '/';
739
+				}
643 740
 				$custom .= 'AD='.strtotime($arrival_date);
644 741
 			}
645 742
 			if ($arrival_code != '') {
646
-				if ($custom != '') $custom .= '/';
743
+				if ($custom != '') {
744
+					$custom .= '/';
745
+				}
647 746
 				$custom .= 'AC='.str_replace(' ','_',$arrival_code);
648 747
 			}
649
-			if ($custom != '') $custom = ' '.$custom;
748
+			if ($custom != '') {
749
+				$custom = ' '.$custom;
750
+			}
650 751
 			$altitude = 0;
651 752
 			$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");
652 753
 		}
Please login to merge, or discard this patch.
require/class.ATC.php 1 patch
Braces   +17 added lines, -6 removed lines patch added patch discarded remove patch
@@ -19,20 +19,27 @@  discard block
 block discarded – undo
19 19
 		if (is_array($globalStatsFilters) && isset($globalStatsFilters[$globalFilterName])) {
20 20
 			if (isset($globalStatsFilters[$globalFilterName][0]['source'])) {
21 21
 				foreach($globalStatsFilters[$globalFilterName] as $source) {
22
-					if (isset($source['source'])) $filter['source'][] = $source['source'];
22
+					if (isset($source['source'])) {
23
+						$filter['source'][] = $source['source'];
24
+					}
23 25
 				}
24 26
 			} else {
25 27
 				$filter = $globalStatsFilters[$globalFilterName];
26 28
 			}
27 29
 		}
28
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
30
+		if (is_array($globalFilter)) {
31
+			$filter = array_merge($filter,$globalFilter);
32
+		}
29 33
 		$filter_query_join = '';
30 34
 		$filter_query_where = '';
31 35
 		if (isset($filter['source']) && !empty($filter['source'])) {
32 36
 			$filter_query_where = " WHERE format_source IN ('".implode("','",$filter['source'])."')";
33 37
 		}
34
-		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
35
-		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
38
+		if ($filter_query_where == '' && $where) {
39
+			$filter_query_where = ' WHERE';
40
+		} elseif ($filter_query_where != '' && $and) {
41
+			$filter_query_where .= ' AND';
42
+		}
36 43
 		$filter_query = $filter_query_join.$filter_query_where;
37 44
 		return $filter_query;
38 45
 	}
@@ -89,7 +96,9 @@  discard block
 block discarded – undo
89 96
 		$info = str_replace('^','<br />',$info);
90 97
 		$info = str_replace('&amp;sect;','',$info);
91 98
 		$info = str_replace('"','',$info);
92
-		if ($type == '') $type = NULL;
99
+		if ($type == '') {
100
+			$type = NULL;
101
+		}
93 102
 		$query = "INSERT INTO atc (ident,frequency,latitude,longitude,atc_range,info,atc_lastseen,type,ivao_id,ivao_name,format_source,source_name) VALUES (:ident,:frequency,:latitude,:longitude,:range,:info,:date,:type,:ivao_id,:ivao_name,:format_source,:source_name)";
94 103
 		$query_values = array(':ident' => $ident,':frequency' => $frequency,':latitude' => $latitude,':longitude' => $longitude,':range' => $range,':info' => $info,':date' => $date,':ivao_id' => $ivao_id,':ivao_name' => $ivao_name, ':type' => $type,':format_source' => $format_source,':source_name' => $source_name);
95 104
 		try {
@@ -105,7 +114,9 @@  discard block
 block discarded – undo
105 114
 		$info = str_replace('^','<br />',$info);
106 115
 		$info = str_replace('&amp;sect;','',$info);
107 116
 		$info = str_replace('"','',$info);
108
-		if ($type == '') $type = NULL;
117
+		if ($type == '') {
118
+			$type = NULL;
119
+		}
109 120
 		$query = "UPDATE atc SET frequency = :frequency,latitude = :latitude,longitude = :longitude,atc_range = :range,info = :info,atc_lastseen = :date,type = :type,ivao_id = :ivao_id,ivao_name = :ivao_name WHERE ident = :ident AND format_source = :format_source AND source_name = :source_name";
110 121
 		$query_values = array(':ident' => $ident,':frequency' => $frequency,':latitude' => $latitude,':longitude' => $longitude,':range' => $range,':info' => $info,':date' => $date,':ivao_id' => $ivao_id,':ivao_name' => $ivao_name, ':type' => $type,':format_source' => $format_source,':source_name' => $source_name);
111 122
 		try {
Please login to merge, or discard this patch.
require/class.METAR.php 1 patch
Braces   +100 added lines, -38 removed lines patch added patch discarded remove patch
@@ -59,8 +59,11 @@  discard block
 block discarded – undo
59 59
 		}
60 60
 		$row = $sth->fetch(PDO::FETCH_ASSOC);
61 61
 		$sth->closeCursor();
62
-		if ($row['nb'] > 0) return false;
63
-		else return true;
62
+		if ($row['nb'] > 0) {
63
+			return false;
64
+		} else {
65
+			return true;
66
+		}
64 67
 	}
65 68
 
66 69
 	public static function insert_last_update() {
@@ -82,9 +85,14 @@  discard block
 block discarded – undo
82 85
 		//$pieces = explode(' ',$data);
83 86
 		$pieces = preg_split('/\s/',$data);
84 87
 		$pos = 0;
85
-		if ($pieces[0] == 'METAR') $pos++;
86
-		elseif ($pieces[0] == 'SPECI') $pos++;
87
-		if (strlen($pieces[$pos]) != 4) $pos++;
88
+		if ($pieces[0] == 'METAR') {
89
+			$pos++;
90
+		} elseif ($pieces[0] == 'SPECI') {
91
+			$pos++;
92
+		}
93
+		if (strlen($pieces[$pos]) != 4) {
94
+			$pos++;
95
+		}
88 96
 		$result = array();
89 97
 		$result['location'] = $pieces[$pos];
90 98
 		$pos++;
@@ -93,16 +101,26 @@  discard block
 block discarded – undo
93 101
 		$c = count($pieces);
94 102
 		for($pos++; $pos < $c; $pos++) {
95 103
 			$piece = $pieces[$pos];
96
-			if ($piece == 'RMK') break;
97
-			if ($piece == 'AUTO') $result['auto'] = true;
98
-			if ($piece == 'COR') $result['correction'] = true;
104
+			if ($piece == 'RMK') {
105
+				break;
106
+			}
107
+			if ($piece == 'AUTO') {
108
+				$result['auto'] = true;
109
+			}
110
+			if ($piece == 'COR') {
111
+				$result['correction'] = true;
112
+			}
99 113
 			// Wind Speed
100 114
 			if (preg_match('#(VRB|\d\d\d)(\d\d)(?:G(\d\d))?(KT|MPS|KPH)(?: (\d{1,3})V(\d{1,3}))?$#', $piece, $matches)) {
101 115
 				$result['wind']['direction'] = (float)$matches[1];
102 116
 				$result['wind']['unit'] = $matches[4];
103
-				if ($result['wind']['unit'] == 'KT') $result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2);
104
-				elseif ($result['wind']['unit'] == 'KPH') $result['wind']['speed'] = round(((float)$matches[2])*1000,2);
105
-				elseif ($result['wind']['unit'] == 'MPS') $result['wind']['speed'] = round(((float)$matches[2]),2);
117
+				if ($result['wind']['unit'] == 'KT') {
118
+					$result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2);
119
+				} elseif ($result['wind']['unit'] == 'KPH') {
120
+					$result['wind']['speed'] = round(((float)$matches[2])*1000,2);
121
+				} elseif ($result['wind']['unit'] == 'MPS') {
122
+					$result['wind']['speed'] = round(((float)$matches[2]),2);
123
+				}
106 124
 				$result['wind']['gust'] = (float)$matches[3];
107 125
 				$result['wind']['unit'] = $matches[4];
108 126
 				$result['wind']['min_variation'] = array_key_exists(5,$matches) ? $matches[5] : 0;
@@ -185,14 +203,23 @@  discard block
 block discarded – undo
185 203
 				//$this->addCloudCover($matches[1], ((float)$matches[2]) * 100, isset($matches[3]) ? $matches[3] : '');
186 204
 				$type = $matches[1];
187 205
 				$cloud = array();
188
-				if ($type == 'SKC') $cloud['type'] = 'No cloud/Sky clear';
189
-				elseif ($type == 'CLR') $cloud['type'] = 'No cloud below 12,000ft (3700m)';
190
-				elseif ($type == 'NSC') $cloud['type'] = 'No significant cloud';
191
-				elseif ($type == 'FEW') $cloud['type'] = 'Few';
192
-				elseif ($type == 'SCT') $cloud['type'] = 'Scattered';
193
-				elseif ($type == 'BKN') $cloud['type'] = 'Broken';
194
-				elseif ($type == 'OVC') $cloud['type'] = 'Overcast/Full cloud coverage';
195
-				elseif ($type == 'VV') $cloud['type'] = 'Vertical visibility';
206
+				if ($type == 'SKC') {
207
+					$cloud['type'] = 'No cloud/Sky clear';
208
+				} elseif ($type == 'CLR') {
209
+					$cloud['type'] = 'No cloud below 12,000ft (3700m)';
210
+				} elseif ($type == 'NSC') {
211
+					$cloud['type'] = 'No significant cloud';
212
+				} elseif ($type == 'FEW') {
213
+					$cloud['type'] = 'Few';
214
+				} elseif ($type == 'SCT') {
215
+					$cloud['type'] = 'Scattered';
216
+				} elseif ($type == 'BKN') {
217
+					$cloud['type'] = 'Broken';
218
+				} elseif ($type == 'OVC') {
219
+					$cloud['type'] = 'Overcast/Full cloud coverage';
220
+				} elseif ($type == 'VV') {
221
+					$cloud['type'] = 'Vertical visibility';
222
+				}
196 223
 				$cloud['type_code'] = $type;
197 224
 				$cloud['level'] = round(((float)$matches[2]) * 100 * 0.3048);
198 225
 				$cloud['significant'] = isset($matches[3]) ? $matches[3] : '';
@@ -218,8 +245,11 @@  discard block
 block discarded – undo
218 245
 				$result['RVR']['friction'] = $matches[5];
219 246
 			}
220 247
 			if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) {
221
-				if (isset($matches[5])) $range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M');
222
-				else $range = array('exact' => (float)$matches[2], 'unit' => 'M');
248
+				if (isset($matches[5])) {
249
+					$range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M');
250
+				} else {
251
+					$range = array('exact' => (float)$matches[2], 'unit' => 'M');
252
+				}
223 253
 				if (isset($matches[3])) {
224 254
 					$range = Array(
225 255
 					    'from' => (float)$matches[2],
@@ -252,8 +282,11 @@  discard block
 block discarded – undo
252 282
 				if (isset($matches[3])) {
253 283
 					$text[] = $this->texts[$matches[3]];
254 284
 				}
255
-				if (!isset($result['weather'])) $result['weather'] = implode(' ', $text);
256
-				else $result['weather'] = $result['weather'].' / '.implode(' ', $text);
285
+				if (!isset($result['weather'])) {
286
+					$result['weather'] = implode(' ', $text);
287
+				} else {
288
+					$result['weather'] = $result['weather'].' / '.implode(' ', $text);
289
+				}
257 290
 			}
258 291
 		}
259 292
 		return $result;
@@ -264,8 +297,11 @@  discard block
 block discarded – undo
264 297
 		if (isset($globalMETARcycle) && $globalMETARcycle) {
265 298
 			$query = "SELECT * FROM metar WHERE metar_location = :icao";
266 299
 		} else {
267
-			if ($globalDBdriver == 'mysql') $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 10 HOUR) LIMIT 1";
268
-			else $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= now() AT TIMEZONE 'UTC' - '10 HOUR'->INTERVAL LIMIT 0,1";
300
+			if ($globalDBdriver == 'mysql') {
301
+				$query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 10 HOUR) LIMIT 1";
302
+			} else {
303
+				$query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= now() AT TIMEZONE 'UTC' - '10 HOUR'->INTERVAL LIMIT 0,1";
304
+			}
269 305
 		}
270 306
 		$query_values = array(':icao' => $icao);
271 307
 		try {
@@ -321,7 +357,9 @@  discard block
 block discarded – undo
321 357
 
322 358
 	public function addMETARCycle() {
323 359
 		global $globalDebug, $globalIVAO, $globalTransaction;
324
-		if (isset($globalDebug) && $globalDebug) echo "Downloading METAR cycle...";
360
+		if (isset($globalDebug) && $globalDebug) {
361
+			echo "Downloading METAR cycle...";
362
+		}
325 363
 		date_default_timezone_set("UTC");
326 364
 		$Common = new Common();
327 365
 		if (isset($globalIVAO) && $globalIVAO) {
@@ -332,31 +370,47 @@  discard block
 block discarded – undo
332 370
 			$handle = fopen(dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT',"r");
333 371
 		}
334 372
 		if ($handle) {
335
-			if (isset($globalDebug) && $globalDebug) echo "Done - Updating DB...";
373
+			if (isset($globalDebug) && $globalDebug) {
374
+				echo "Done - Updating DB...";
375
+			}
336 376
 			$date = '';
337
-			if ($globalTransaction) $this->db->beginTransaction();
377
+			if ($globalTransaction) {
378
+				$this->db->beginTransaction();
379
+			}
338 380
 			while(($line = fgets($handle,4096)) !== false) {
339 381
 				if (preg_match('#^([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{2}):([0-9]{2})$#',$line)) {
340 382
 					$date = $line;
341 383
 				} elseif ($line != '') {
342
-					if ($date == '') $date = date('Y/m/d H:m');
384
+					if ($date == '') {
385
+						$date = date('Y/m/d H:m');
386
+					}
343 387
 					$pos = 0;
344 388
 					$pieces = preg_split('/\s/',$line);
345
-					if ($pieces[0] == 'METAR') $pos++;
346
-					if (strlen($pieces[$pos]) != 4) $pos++;
389
+					if ($pieces[0] == 'METAR') {
390
+						$pos++;
391
+					}
392
+					if (strlen($pieces[$pos]) != 4) {
393
+						$pos++;
394
+					}
347 395
 					$location = $pieces[$pos];
348 396
 					echo $this->addMETAR($location,$line,$date);
349 397
 				}
350 398
 			}
351 399
 			fclose($handle);
352
-			if ($globalTransaction) $this->db->commit();
400
+			if ($globalTransaction) {
401
+				$this->db->commit();
402
+			}
403
+		}
404
+		if (isset($globalDebug) && $globalDebug) {
405
+			echo "Done\n";
353 406
 		}
354
-		if (isset($globalDebug) && $globalDebug) echo "Done\n";
355 407
 	}
356 408
 
357 409
 	public function downloadMETAR($icao) {
358 410
 		global $globalMETARurl;
359
-		if ($globalMETARurl == '') return array();
411
+		if ($globalMETARurl == '') {
412
+			return array();
413
+		}
360 414
 		date_default_timezone_set("UTC");
361 415
 		$Common = new Common();
362 416
 		$url = str_replace('{icao}',$icao,$globalMETARurl);
@@ -367,16 +421,24 @@  discard block
 block discarded – undo
367 421
 				$date = $line;
368 422
 			} 
369 423
 			if ($line != '') {
370
-				if ($date == '') $date = date('Y/m/d H:m');
424
+				if ($date == '') {
425
+					$date = date('Y/m/d H:m');
426
+				}
371 427
 				$pos = 0;
372 428
 				$pieces = preg_split('/\s/',$line);
373
-				if ($pieces[0] == 'METAR') $pos++;
374
-				if (strlen($pieces[$pos]) != 4) $pos++;
429
+				if ($pieces[0] == 'METAR') {
430
+					$pos++;
431
+				}
432
+				if (strlen($pieces[$pos]) != 4) {
433
+					$pos++;
434
+				}
375 435
 				$location = $pieces[$pos];
376 436
 				if (strlen($location == 4)) {
377 437
 					$this->addMETAR($location,$line,$date);
378 438
 					return array('0' => array('metar_date' => $date, 'metar_location' => $location, 'metar' => $line));
379
-				} else return array();
439
+				} else {
440
+					return array();
441
+				}
380 442
 			}
381 443
 		}
382 444
 		return array();
Please login to merge, or discard this patch.