Completed
Push — master ( f94762...48307c )
by Yannick
05:44
created
scripts/daemon-spotter.php 1 patch
Braces   +535 added lines, -183 removed lines patch added patch discarded remove patch
@@ -14,7 +14,9 @@  discard block
 block discarded – undo
14 14
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
15 15
 require_once(dirname(__FILE__).'/../require/class.Common.php');
16 16
 
17
-if (!isset($globalDebug)) $globalDebug = FALSE;
17
+if (!isset($globalDebug)) {
18
+	$globalDebug = FALSE;
19
+}
18 20
 
19 21
 // Check if schema is at latest version
20 22
 $Connection = new Connection();
@@ -54,13 +56,22 @@  discard block
 block discarded – undo
54 56
     $globalSources = array();
55 57
     $globalSources[] = array('host' => $options['source']);
56 58
 }
57
-if (isset($options['server'])) $globalServer = TRUE;
58
-if (isset($options['idsource'])) $id_source = $options['idsource'];
59
-else $id_source = 1;
59
+if (isset($options['server'])) {
60
+	$globalServer = TRUE;
61
+}
62
+if (isset($options['idsource'])) {
63
+	$id_source = $options['idsource'];
64
+} else {
65
+	$id_source = 1;
66
+}
60 67
 if (isset($globalServer) && $globalServer) {
61
-    if ($globalDebug) echo "Using Server Mode\n";
68
+    if ($globalDebug) {
69
+    	echo "Using Server Mode\n";
70
+    }
62 71
     $SI=new SpotterServer();
63
-} else $SI=new SpotterImport($Connection->db);
72
+} else {
73
+	$SI=new SpotterImport($Connection->db);
74
+}
64 75
 //$APRS=new APRS($Connection->db);
65 76
 $SBS=new SBS();
66 77
 $ACARS=new ACARS($Connection->db);
@@ -78,7 +89,9 @@  discard block
 block discarded – undo
78 89
 }
79 90
 
80 91
 // let's try and connect
81
-if ($globalDebug) echo "Connecting...\n";
92
+if ($globalDebug) {
93
+	echo "Connecting...\n";
94
+}
82 95
 $use_aprs = false;
83 96
 $aprs_full = false;
84 97
 
@@ -86,7 +99,9 @@  discard block
 block discarded – undo
86 99
     $ip = gethostbyname($host);
87 100
     $s = socket_create(AF_INET, SOCK_STREAM, 0);
88 101
     $r = @socket_connect($s, $ip, $port);
89
-    if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
102
+    if (!socket_set_nonblock($s)) {
103
+    	echo "Unable to set nonblock on socket\n";
104
+    }
90 105
     if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
91 106
         return $s;
92 107
     }
@@ -113,7 +128,9 @@  discard block
 block discarded – undo
113 128
 function connect_all($hosts) {
114 129
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
115 130
     global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
116
-    if ($globalDebug) echo 'Connect to all...'."\n";
131
+    if ($globalDebug) {
132
+    	echo 'Connect to all...'."\n";
133
+    }
117 134
     foreach ($hosts as $id => $value) {
118 135
 	$host = $value['host'];
119 136
 	$globalSources[$id]['last_exec'] = 0;
@@ -123,27 +140,37 @@  discard block
 block discarded – undo
123 140
         	//$formats[$id] = 'deltadbtxt';
124 141
         	$globalSources[$id]['format'] = 'deltadbtxt';
125 142
         	//$last_exec['deltadbtxt'] = 0;
126
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
143
+        	if ($globalDebug) {
144
+        		echo "Connect to deltadb source (".$host.")...\n";
145
+        	}
127 146
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
128 147
         	//$formats[$id] = 'vatsimtxt';
129 148
         	$globalSources[$id]['format'] = 'vatsimtxt';
130 149
         	//$last_exec['vatsimtxt'] = 0;
131
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
150
+        	if ($globalDebug) {
151
+        		echo "Connect to vatsim source (".$host.")...\n";
152
+        	}
132 153
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
133 154
         	//$formats[$id] = 'aircraftlistjson';
134 155
         	$globalSources[$id]['format'] = 'aircraftlistjson';
135 156
         	//$last_exec['aircraftlistjson'] = 0;
136
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
157
+        	if ($globalDebug) {
158
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
159
+        	}
137 160
     	    } else if (preg_match('/opensky/i',$host)) {
138 161
         	//$formats[$id] = 'aircraftlistjson';
139 162
         	$globalSources[$id]['format'] = 'opensky';
140 163
         	//$last_exec['aircraftlistjson'] = 0;
141
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
164
+        	if ($globalDebug) {
165
+        		echo "Connect to opensky source (".$host.")...\n";
166
+        	}
142 167
     	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
143 168
         	//$formats[$id] = 'radarvirtueljson';
144 169
         	$globalSources[$id]['format'] = 'radarvirtueljson';
145 170
         	//$last_exec['radarvirtueljson'] = 0;
146
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
171
+        	if ($globalDebug) {
172
+        		echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
173
+        	}
147 174
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
148 175
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
149 176
         	    exit(0);
@@ -152,7 +179,9 @@  discard block
 block discarded – undo
152 179
         	//$formats[$id] = 'planeupdatefaa';
153 180
         	$globalSources[$id]['format'] = 'planeupdatefaa';
154 181
         	//$last_exec['planeupdatefaa'] = 0;
155
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
182
+        	if ($globalDebug) {
183
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
184
+        	}
156 185
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
157 186
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
158 187
         	    exit(0);
@@ -161,26 +190,36 @@  discard block
 block discarded – undo
161 190
         	//$formats[$id] = 'phpvmacars';
162 191
         	$globalSources[$id]['format'] = 'phpvmacars';
163 192
         	//$last_exec['phpvmacars'] = 0;
164
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
193
+        	if ($globalDebug) {
194
+        		echo "Connect to phpvmacars source (".$host.")...\n";
195
+        	}
165 196
             } else if (preg_match('/VAM-json.php$/i',$host)) {
166 197
         	//$formats[$id] = 'phpvmacars';
167 198
         	$globalSources[$id]['format'] = 'vam';
168
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
199
+        	if ($globalDebug) {
200
+        		echo "Connect to Vam source (".$host.")...\n";
201
+        	}
169 202
             } else if (preg_match('/whazzup/i',$host)) {
170 203
         	//$formats[$id] = 'whazzup';
171 204
         	$globalSources[$id]['format'] = 'whazzup';
172 205
         	//$last_exec['whazzup'] = 0;
173
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
206
+        	if ($globalDebug) {
207
+        		echo "Connect to whazzup source (".$host.")...\n";
208
+        	}
174 209
             } else if (preg_match('/recentpireps/i',$host)) {
175 210
         	//$formats[$id] = 'pirepsjson';
176 211
         	$globalSources[$id]['format'] = 'pirepsjson';
177 212
         	//$last_exec['pirepsjson'] = 0;
178
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
213
+        	if ($globalDebug) {
214
+        		echo "Connect to pirepsjson source (".$host.")...\n";
215
+        	}
179 216
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
180 217
         	//$formats[$id] = 'fr24json';
181 218
         	$globalSources[$id]['format'] = 'fr24json';
182 219
         	//$last_exec['fr24json'] = 0;
183
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
220
+        	if ($globalDebug) {
221
+        		echo "Connect to fr24 source (".$host.")...\n";
222
+        	}
184 223
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
185 224
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
186 225
         	    exit(0);
@@ -189,10 +228,14 @@  discard block
 block discarded – undo
189 228
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
190 229
         	//$formats[$id] = 'tsv';
191 230
         	$globalSources[$id]['format'] = 'tsv';
192
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
231
+        	if ($globalDebug) {
232
+        		echo "Connect to tsv source (".$host.")...\n";
233
+        	}
193 234
             }
194 235
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
195
-        	if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
236
+        	if ($globalDebug) {
237
+        		echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
238
+        	}
196 239
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
197 240
 	    $hostport = explode(':',$host);
198 241
 	    if (isset($hostport[1])) {
@@ -229,17 +272,25 @@  discard block
 block discarded – undo
229 272
         		//$formats[$id] = 'beast';
230 273
         		$globalSources[$id]['format'] = 'beast';
231 274
 		    //} else $formats[$id] = 'sbs';
232
-		    } else $globalSources[$id]['format'] = 'sbs';
275
+		    } else {
276
+		    	$globalSources[$id]['format'] = 'sbs';
277
+		    }
233 278
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
234 279
 		}
235
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
280
+		if ($globalDebug) {
281
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
282
+		}
236 283
             } else {
237
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
284
+		if ($globalDebug) {
285
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
286
+		}
238 287
     	    }
239 288
         }
240 289
     }
241 290
 }
242
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
291
+if (!isset($globalMinFetch)) {
292
+	$globalMinFetch = 15;
293
+}
243 294
 
244 295
 // Initialize all
245 296
 $status = array();
@@ -247,13 +298,19 @@  discard block
 block discarded – undo
247 298
 $formats = array();
248 299
 $last_exec = array();
249 300
 $time = time();
250
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
251
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
252
-else $timeout = 20;
301
+if (isset($globalSourcesTimeout)) {
302
+	$timeout = $globalSourcesTimeOut;
303
+} else if (isset($globalSBS1TimeOut)) {
304
+	$timeout = $globalSBS1TimeOut;
305
+} else {
306
+	$timeout = 20;
307
+}
253 308
 $errno = '';
254 309
 $errstr='';
255 310
 
256
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
311
+if (!isset($globalDaemon)) {
312
+	$globalDaemon = TRUE;
313
+}
257 314
 /* Initiate connections to all the hosts simultaneously */
258 315
 //connect_all($hosts);
259 316
 //connect_all($globalSources);
@@ -273,7 +330,9 @@  discard block
 block discarded – undo
273 330
     if (isset($source['format']) && $source['format'] == 'aprs') {
274 331
 	$aprs_connect = 0;
275 332
 	$use_aprs = true;
276
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
333
+	if (isset($source['port']) && $source['port'] == '10152') {
334
+		$aprs_full = true;
335
+	}
277 336
 	break;
278 337
     }
279 338
 }
@@ -284,24 +343,44 @@  discard block
 block discarded – undo
284 343
 	$aprs_connect = 0;
285 344
 	$aprs_keep = 120;
286 345
 	$aprs_last_tx = time();
287
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
288
-	else $aprs_version = $globalName.' using FlightAirMap';
346
+	if (isset($globalAPRSversion)) {
347
+		$aprs_version = $globalAPRSversion;
348
+	} else {
349
+		$aprs_version = $globalName.' using FlightAirMap';
350
+	}
289 351
 	//else $aprs_version = 'Perl Example App';
290
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
291
-	else $aprs_ssid = 'FAM';
352
+	if (isset($globalAPRSssid)) {
353
+		$aprs_ssid = $globalAPRSssid;
354
+	} else {
355
+		$aprs_ssid = 'FAM';
356
+	}
292 357
 	//else $aprs_ssid = 'PerlEx';
293
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
294
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
295
-	if ($aprs_full) $aprs_filter = '';
296
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} appid {$aprs_version} filter {$aprs_filter}\n";
297
-	else $aprs_login = "user {$aprs_ssid} appid {$aprs_version}\n";
298
-}
358
+	if (isset($globalAPRSfilter)) {
359
+		$aprs_filter = $globalAPRSfilter;
360
+	} else {
361
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
362
+	}
363
+	if ($aprs_full) {
364
+		$aprs_filter = '';
365
+	}
366
+	if ($aprs_filter != '') {
367
+		$aprs_login = "user {$aprs_ssid} appid {$aprs_version} filter {$aprs_filter}\n";
368
+	} else {
369
+		$aprs_login = "user {$aprs_ssid} appid {$aprs_version}\n";
370
+	}
371
+	}
299 372
 
300 373
 // connected - lets do some work
301
-if ($globalDebug) echo "Connected!\n";
374
+if ($globalDebug) {
375
+	echo "Connected!\n";
376
+}
302 377
 sleep(1);
303
-if ($globalDebug) echo "SCAN MODE \n\n";
304
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
378
+if ($globalDebug) {
379
+	echo "SCAN MODE \n\n";
380
+}
381
+if (!isset($globalCronEnd)) {
382
+	$globalCronEnd = 60;
383
+}
305 384
 $endtime = time()+$globalCronEnd;
306 385
 $i = 1;
307 386
 $tt = array();
@@ -315,20 +394,28 @@  discard block
 block discarded – undo
315 394
 
316 395
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
317 396
 while ($i > 0) {
318
-    if (!$globalDaemon) $i = $endtime-time();
397
+    if (!$globalDaemon) {
398
+    	$i = $endtime-time();
399
+    }
319 400
     // Delete old ATC
320 401
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
321
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
402
+	if ($globalDebug) {
403
+		echo 'Delete old ATC...'."\n";
404
+	}
322 405
         $ATC->deleteOldATC();
323 406
     }
324 407
     
325 408
     if (count($last_exec) > 0) {
326 409
 	$max = $globalMinFetch;
327 410
 	foreach ($last_exec as $last) {
328
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
411
+	    if ((time() - $last['last']) < $max) {
412
+	    	$max = time() - $last['last'];
413
+	    }
329 414
 	}
330 415
 	if ($max != $globalMinFetch) {
331
-	    if ($globalDebug) echo 'Sleeping...'."\n";
416
+	    if ($globalDebug) {
417
+	    	echo 'Sleeping...'."\n";
418
+	    }
332 419
 	    sleep($globalMinFetch-$max+2);
333 420
 	}
334 421
     }
@@ -336,7 +423,9 @@  discard block
 block discarded – undo
336 423
     
337 424
     //foreach ($formats as $id => $value) {
338 425
     foreach ($globalSources as $id => $value) {
339
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
426
+	if (!isset($last_exec[$id]['last'])) {
427
+		$last_exec[$id]['last'] = 0;
428
+	}
340 429
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
341 430
 	    //$buffer = $Common->getData($hosts[$id]);
342 431
 	    $buffer = $Common->getData($value['host']);
@@ -348,19 +437,38 @@  discard block
 block discarded – undo
348 437
 	            $data = array();
349 438
 	            $data['hex'] = $line[1]; // hex
350 439
 	            $data['ident'] = $line[2]; // ident
351
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
352
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
353
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
354
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
355
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
440
+	            if (isset($line[3])) {
441
+	            	$data['altitude'] = $line[3];
442
+	            }
443
+	            // altitude
444
+	            if (isset($line[4])) {
445
+	            	$data['speed'] = $line[4];
446
+	            }
447
+	            // speed
448
+	            if (isset($line[5])) {
449
+	            	$data['heading'] = $line[5];
450
+	            }
451
+	            // heading
452
+	            if (isset($line[6])) {
453
+	            	$data['latitude'] = $line[6];
454
+	            }
455
+	            // lat
456
+	            if (isset($line[7])) {
457
+	            	$data['longitude'] = $line[7];
458
+	            }
459
+	            // long
356 460
 	            $data['verticalrate'] = ''; // vertical rate
357 461
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
358 462
 	            $data['emergency'] = ''; // emergency
359 463
 		    $data['datetime'] = date('Y-m-d H:i:s');
360 464
 		    $data['format_source'] = 'deltadbtxt';
361 465
     		    $data['id_source'] = $id_source;
362
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
363
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
466
+		    if (isset($value['name']) && $value['name'] != '') {
467
+		    	$data['source_name'] = $value['name'];
468
+		    }
469
+		    if (isset($value['sourcestats'])) {
470
+		    	$data['sourcestats'] = $value['sourcestats'];
471
+		    }
364 472
     		    $SI->add($data);
365 473
 		    unset($data);
366 474
     		}
@@ -382,10 +490,19 @@  discard block
 block discarded – undo
382 490
 			$data['pilot_name'] = $line[2];
383 491
 			$data['hex'] = str_pad(dechex($line[1]),6,'000000',STR_PAD_LEFT);
384 492
 			$data['ident'] = $line[0]; // ident
385
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
493
+			if ($line[7] != '' && $line[7] != 0) {
494
+				$data['altitude'] = $line[7];
495
+			}
496
+			// altitude
386 497
 			$data['speed'] = $line[8]; // speed
387
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
388
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
498
+			if (isset($line[45])) {
499
+				$data['heading'] = $line[45];
500
+			}
501
+			// heading
502
+			elseif (isset($line[38])) {
503
+				$data['heading'] = $line[38];
504
+			}
505
+			// heading
389 506
 			$data['latitude'] = $line[5]; // lat
390 507
 	        	$data['longitude'] = $line[6]; // long
391 508
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -394,14 +511,18 @@  discard block
 block discarded – undo
394 511
 	        	$data['waypoints'] = $line[30];
395 512
 			$data['datetime'] = date('Y-m-d H:i:s');
396 513
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
397
-			if (isset($line[37])) $data['last_update'] = $line[37];
514
+			if (isset($line[37])) {
515
+				$data['last_update'] = $line[37];
516
+			}
398 517
 		        $data['departure_airport_icao'] = $line[11];
399 518
 		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
400 519
 		        $data['arrival_airport_icao'] = $line[13];
401 520
 			$data['frequency'] = $line[4];
402 521
 			$data['type'] = $line[18];
403 522
 			$data['range'] = $line[19];
404
-			if (isset($line[35])) $data['info'] = $line[35];
523
+			if (isset($line[35])) {
524
+				$data['info'] = $line[35];
525
+			}
405 526
     			$data['id_source'] = $id_source;
406 527
 	    		//$data['arrival_airport_time'] = ;
407 528
 	    		if ($line[9] != '') {
@@ -415,23 +536,38 @@  discard block
 block discarded – undo
415 536
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
416 537
 	    		*/
417 538
 	    		$data['format_source'] = $value['format'];
418
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
419
-    			if ($line[3] == 'PILOT') $SI->add($data);
420
-			elseif ($line[3] == 'ATC') {
539
+			if (isset($value['name']) && $value['name'] != '') {
540
+				$data['source_name'] = $value['name'];
541
+			}
542
+    			if ($line[3] == 'PILOT') {
543
+    				$SI->add($data);
544
+    			} elseif ($line[3] == 'ATC') {
421 545
 				//print_r($data);
422 546
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
423 547
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
424 548
 				$typec = substr($data['ident'],-3);
425
-				if ($typec == 'APP') $data['type'] = 'Approach';
426
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
427
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
428
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
429
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
430
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
431
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
432
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
433
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
434
-				if (!isset($data['source_name'])) $data['source_name'] = '';
549
+				if ($typec == 'APP') {
550
+					$data['type'] = 'Approach';
551
+				} elseif ($typec == 'TWR') {
552
+					$data['type'] = 'Tower';
553
+				} elseif ($typec == 'OBS') {
554
+					$data['type'] = 'Observer';
555
+				} elseif ($typec == 'GND') {
556
+					$data['type'] = 'Ground';
557
+				} elseif ($typec == 'DEL') {
558
+					$data['type'] = 'Delivery';
559
+				} elseif ($typec == 'DEP') {
560
+					$data['type'] = 'Departure';
561
+				} elseif ($typec == 'FSS') {
562
+					$data['type'] = 'Flight Service Station';
563
+				} elseif ($typec == 'CTR') {
564
+					$data['type'] = 'Control Radar or Centre';
565
+				} elseif ($data['type'] == '') {
566
+					$data['type'] = 'Observer';
567
+				}
568
+				if (!isset($data['source_name'])) {
569
+					$data['source_name'] = '';
570
+				}
435 571
 				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']);
436 572
 			}
437 573
     			unset($data);
@@ -450,26 +586,55 @@  discard block
 block discarded – undo
450 586
 		foreach ($all_data['acList'] as $line) {
451 587
 		    $data = array();
452 588
 		    $data['hex'] = $line['Icao']; // hex
453
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
454
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
455
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
456
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
457
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
458
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
589
+		    if (isset($line['Call'])) {
590
+		    	$data['ident'] = $line['Call'];
591
+		    }
592
+		    // ident
593
+		    if (isset($line['Alt'])) {
594
+		    	$data['altitude'] = $line['Alt'];
595
+		    }
596
+		    // altitude
597
+		    if (isset($line['Spd'])) {
598
+		    	$data['speed'] = $line['Spd'];
599
+		    }
600
+		    // speed
601
+		    if (isset($line['Trak'])) {
602
+		    	$data['heading'] = $line['Trak'];
603
+		    }
604
+		    // heading
605
+		    if (isset($line['Lat'])) {
606
+		    	$data['latitude'] = $line['Lat'];
607
+		    }
608
+		    // lat
609
+		    if (isset($line['Long'])) {
610
+		    	$data['longitude'] = $line['Long'];
611
+		    }
612
+		    // long
459 613
 		    //$data['verticalrate'] = $line['']; // verticale rate
460
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
614
+		    if (isset($line['Sqk'])) {
615
+		    	$data['squawk'] = $line['Sqk'];
616
+		    }
617
+		    // squawk
461 618
 		    $data['emergency'] = ''; // emergency
462
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
619
+		    if (isset($line['Reg'])) {
620
+		    	$data['registration'] = $line['Reg'];
621
+		    }
463 622
 		    /*
464 623
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
465 624
 		    else $data['datetime'] = date('Y-m-d H:i:s');
466 625
 		    */
467 626
 		    $data['datetime'] = date('Y-m-d H:i:s');
468
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
627
+		    if (isset($line['Type'])) {
628
+		    	$data['aircraft_icao'] = $line['Type'];
629
+		    }
469 630
 	    	    $data['format_source'] = 'aircraftlistjson';
470 631
 		    $data['id_source'] = $id_source;
471
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
472
-		    if (isset($data['datetime'])) $SI->add($data);
632
+		    if (isset($value['name']) && $value['name'] != '') {
633
+		    	$data['source_name'] = $value['name'];
634
+		    }
635
+		    if (isset($data['datetime'])) {
636
+		    	$SI->add($data);
637
+		    }
473 638
 		    unset($data);
474 639
 		}
475 640
 	    } else {
@@ -488,7 +653,9 @@  discard block
 block discarded – undo
488 653
 		    $data['datetime'] = date('Y-m-d H:i:s');
489 654
 	    	    $data['format_source'] = 'aircraftlistjson';
490 655
     		    $data['id_source'] = $id_source;
491
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
656
+		    if (isset($value['name']) && $value['name'] != '') {
657
+		    	$data['source_name'] = $value['name'];
658
+		    }
492 659
 		    $SI->add($data);
493 660
 		    unset($data);
494 661
 		}
@@ -523,7 +690,9 @@  discard block
 block discarded – undo
523 690
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
524 691
 	    	    $data['format_source'] = 'planeupdatefaa';
525 692
     		    $data['id_source'] = $id_source;
526
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
693
+		    if (isset($value['name']) && $value['name'] != '') {
694
+		    	$data['source_name'] = $value['name'];
695
+		    }
527 696
 		    $SI->add($data);
528 697
 		    unset($data);
529 698
 		}
@@ -582,7 +751,9 @@  discard block
 block discarded – undo
582 751
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
583 752
 	    	    $data['format_source'] = 'fr24json';
584 753
     		    $data['id_source'] = $id_source;
585
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
754
+		    if (isset($value['name']) && $value['name'] != '') {
755
+		    	$data['source_name'] = $value['name'];
756
+		    }
586 757
 		    $SI->add($data);
587 758
 		    unset($data);
588 759
 		}
@@ -605,23 +776,39 @@  discard block
 block discarded – undo
605 776
 		    if (isset($line['inf'])) {
606 777
 			$data = array();
607 778
 			$data['hex'] = $line['inf']['ia'];
608
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
779
+			if (isset($line['inf']['cs'])) {
780
+				$data['ident'] = $line['inf']['cs'];
781
+			}
782
+			//$line[13]
609 783
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
610
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
611
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
784
+	    		if (isset($line['inf']['gs'])) {
785
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
786
+	    		}
787
+	    		// speed
788
+	    		if (isset($line['inf']['tr'])) {
789
+	    			$data['heading'] = $line['inf']['tr'];
790
+	    		}
791
+	    		// heading
612 792
 	    		$data['latitude'] = $line['pt'][0]; // lat
613 793
 	    		$data['longitude'] = $line['pt'][1]; // long
614 794
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
615
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
795
+	    		if (isset($line['inf']['sq'])) {
796
+	    			$data['squawk'] = $line['inf']['sq'];
797
+	    		}
798
+	    		// squawk
616 799
 	    		//$data['aircraft_icao'] = $line[8];
617
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
800
+	    		if (isset($line['inf']['rc'])) {
801
+	    			$data['registration'] = $line['inf']['rc'];
802
+	    		}
618 803
 			//$data['departure_airport_iata'] = $line[11];
619 804
 			//$data['arrival_airport_iata'] = $line[12];
620 805
 	    		//$data['emergency'] = ''; // emergency
621 806
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
622 807
 	    		$data['format_source'] = 'radarvirtueljson';
623 808
     			$data['id_source'] = $id_source;
624
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
809
+			if (isset($value['name']) && $value['name'] != '') {
810
+				$data['source_name'] = $value['name'];
811
+			}
625 812
 			$SI->add($data);
626 813
 			unset($data);
627 814
 		    }
@@ -641,29 +828,62 @@  discard block
 block discarded – undo
641 828
 		    $data['id'] = $line['id'];
642 829
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
643 830
 		    $data['ident'] = $line['callsign']; // ident
644
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
645
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
646
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
647
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
648
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
649
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
831
+		    if (isset($line['pilotid'])) {
832
+		    	$data['pilot_id'] = $line['pilotid'];
833
+		    }
834
+		    // pilot id
835
+		    if (isset($line['name'])) {
836
+		    	$data['pilot_name'] = $line['name'];
837
+		    }
838
+		    // pilot name
839
+		    if (isset($line['alt'])) {
840
+		    	$data['altitude'] = $line['alt'];
841
+		    }
842
+		    // altitude
843
+		    if (isset($line['gs'])) {
844
+		    	$data['speed'] = $line['gs'];
845
+		    }
846
+		    // speed
847
+		    if (isset($line['heading'])) {
848
+		    	$data['heading'] = $line['heading'];
849
+		    }
850
+		    // heading
851
+		    if (isset($line['route'])) {
852
+		    	$data['waypoints'] = $line['route'];
853
+		    }
854
+		    // route
650 855
 		    $data['latitude'] = $line['lat']; // lat
651 856
 		    $data['longitude'] = $line['lon']; // long
652 857
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
653 858
 		    //$data['squawk'] = $line['squawk']; // squawk
654 859
 		    //$data['emergency'] = ''; // emergency
655
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
656
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
657
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
860
+		    if (isset($line['depicao'])) {
861
+		    	$data['departure_airport_icao'] = $line['depicao'];
862
+		    }
863
+		    if (isset($line['deptime'])) {
864
+		    	$data['departure_airport_time'] = $line['deptime'];
865
+		    }
866
+		    if (isset($line['arricao'])) {
867
+		    	$data['arrival_airport_icao'] = $line['arricao'];
868
+		    }
658 869
 		    //$data['arrival_airport_time'] = $line['arrtime'];
659
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
660
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
661
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
662
-		    else $data['info'] = '';
870
+		    if (isset($line['aircraft'])) {
871
+		    	$data['aircraft_icao'] = $line['aircraft'];
872
+		    }
873
+		    if (isset($line['transponder'])) {
874
+		    	$data['squawk'] = $line['transponder'];
875
+		    }
876
+		    if (isset($line['atis'])) {
877
+		    	$data['info'] = $line['atis'];
878
+		    } else {
879
+		    	$data['info'] = '';
880
+		    }
663 881
 		    $data['format_source'] = 'pireps';
664 882
     		    $data['id_source'] = $id_source;
665 883
 		    $data['datetime'] = date('Y-m-d H:i:s');
666
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
884
+		    if (isset($value['name']) && $value['name'] != '') {
885
+		    	$data['source_name'] = $value['name'];
886
+		    }
667 887
 		    if ($line['icon'] == 'plane') {
668 888
 			$SI->add($data);
669 889
 		    //    print_r($data);
@@ -672,15 +892,25 @@  discard block
 block discarded – undo
672 892
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
673 893
 			$typec = substr($data['ident'],-3);
674 894
 			$data['type'] = '';
675
-			if ($typec == 'APP') $data['type'] = 'Approach';
676
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
677
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
678
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
679
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
680
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
681
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
682
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
683
-			else $data['type'] = 'Observer';
895
+			if ($typec == 'APP') {
896
+				$data['type'] = 'Approach';
897
+			} elseif ($typec == 'TWR') {
898
+				$data['type'] = 'Tower';
899
+			} elseif ($typec == 'OBS') {
900
+				$data['type'] = 'Observer';
901
+			} elseif ($typec == 'GND') {
902
+				$data['type'] = 'Ground';
903
+			} elseif ($typec == 'DEL') {
904
+				$data['type'] = 'Delivery';
905
+			} elseif ($typec == 'DEP') {
906
+				$data['type'] = 'Departure';
907
+			} elseif ($typec == 'FSS') {
908
+				$data['type'] = 'Flight Service Station';
909
+			} elseif ($typec == 'CTR') {
910
+				$data['type'] = 'Control Radar or Centre';
911
+			} else {
912
+				$data['type'] = 'Observer';
913
+			}
684 914
 			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']);
685 915
 		    }
686 916
 		    unset($data);
@@ -691,17 +921,25 @@  discard block
 block discarded – undo
691 921
     	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
692 922
     	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
693 923
 	    //$buffer = $Common->getData($hosts[$id]);
694
-	    if ($globalDebug) echo 'Get Data...'."\n";
924
+	    if ($globalDebug) {
925
+	    	echo 'Get Data...'."\n";
926
+	    }
695 927
 	    $buffer = $Common->getData($value['host']);
696 928
 	    $all_data = json_decode($buffer,true);
697 929
 	    if ($buffer != '' && is_array($all_data)) {
698 930
 		foreach ($all_data as $line) {
699 931
 	    	    $data = array();
700 932
 	    	    //$data['id'] = $line['id']; // id not usable
701
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
933
+	    	    if (isset($line['pilotid'])) {
934
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
935
+	    	    }
702 936
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
703
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
704
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
937
+	    	    if (isset($line['pilotname'])) {
938
+	    	    	$data['pilot_name'] = $line['pilotname'];
939
+	    	    }
940
+	    	    if (isset($line['pilotid'])) {
941
+	    	    	$data['pilot_id'] = $line['pilotid'];
942
+	    	    }
705 943
 	    	    $data['ident'] = $line['flightnum']; // ident
706 944
 	    	    $data['altitude'] = $line['alt']; // altitude
707 945
 	    	    $data['speed'] = $line['gs']; // speed
@@ -719,27 +957,41 @@  discard block
 block discarded – undo
719 957
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
720 958
     		    $data['arrival_airport_time'] = $line['arrtime'];
721 959
     		    $data['registration'] = $line['aircraft'];
722
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
960
+		    if (isset($line['route'])) {
961
+		    	$data['waypoints'] = $line['route'];
962
+		    }
963
+		    // route
723 964
 		    if (isset($line['aircraftname'])) {
724 965
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
725 966
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
726 967
 	    		$aircraft_data = explode('-',$line['aircraftname']);
727
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
728
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
729
-	    		else {
968
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) {
969
+	    			$data['aircraft_icao'] = $aircraft_data[0];
970
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) {
971
+	    			$data['aircraft_icao'] = $aircraft_data[1];
972
+	    		} else {
730 973
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
731
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
732
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
974
+	    		    if (isset($aircraft_data[1])) {
975
+	    		    	$data['aircraft_icao'] = $aircraft_data[1];
976
+	    		    } else {
977
+	    		    	$data['aircraft_icao'] = $line['aircraftname'];
978
+	    		    }
733 979
 	    		}
734 980
 	    	    }
735
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
981
+    		    if (isset($line['route'])) {
982
+    		    	$data['waypoints'] = $line['route'];
983
+    		    }
736 984
     		    $data['id_source'] = $id_source;
737 985
 	    	    $data['format_source'] = 'phpvmacars';
738
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
986
+		    if (isset($value['name']) && $value['name'] != '') {
987
+		    	$data['source_name'] = $value['name'];
988
+		    }
739 989
 		    $SI->add($data);
740 990
 		    unset($data);
741 991
 		}
742
-		if ($globalDebug) echo 'No more data...'."\n";
992
+		if ($globalDebug) {
993
+			echo 'No more data...'."\n";
994
+		}
743 995
 		unset($buffer);
744 996
 		unset($all_data);
745 997
 	    }
@@ -747,7 +999,9 @@  discard block
 block discarded – undo
747 999
     	    $last_exec[$id]['last'] = time();
748 1000
     	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
749 1001
 	    //$buffer = $Common->getData($hosts[$id]);
750
-	    if ($globalDebug) echo 'Get Data...'."\n";
1002
+	    if ($globalDebug) {
1003
+	    	echo 'Get Data...'."\n";
1004
+	    }
751 1005
 	    $buffer = $Common->getData($value['host']);
752 1006
 	    $all_data = json_decode($buffer,true);
753 1007
 	    if ($buffer != '' && is_array($all_data)) {
@@ -775,15 +1029,22 @@  discard block
 block discarded – undo
775 1029
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
776 1030
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
777 1031
     		    //$data['registration'] = $line['aircraft'];
778
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1032
+		    if (isset($line['route'])) {
1033
+		    	$data['waypoints'] = $line['route'];
1034
+		    }
1035
+		    // route
779 1036
 	    	    $data['aircraft_icao'] = $line['plane_type'];
780 1037
     		    $data['id_source'] = $id_source;
781 1038
 	    	    $data['format_source'] = 'vam';
782
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1039
+		    if (isset($value['name']) && $value['name'] != '') {
1040
+		    	$data['source_name'] = $value['name'];
1041
+		    }
783 1042
 		    $SI->add($data);
784 1043
 		    unset($data);
785 1044
 		}
786
-		if ($globalDebug) echo 'No more data...'."\n";
1045
+		if ($globalDebug) {
1046
+			echo 'No more data...'."\n";
1047
+		}
787 1048
 		unset($buffer);
788 1049
 		unset($all_data);
789 1050
 	    }
@@ -791,7 +1052,9 @@  discard block
 block discarded – undo
791 1052
     	    $last_exec[$id]['last'] = time();
792 1053
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
793 1054
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3') {
794
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1055
+	    if (function_exists('pcntl_fork')) {
1056
+	    	pcntl_signal_dispatch();
1057
+	    }
795 1058
     	    //$last_exec[$id]['last'] = time();
796 1059
 
797 1060
 	    //$read = array( $sockets[$id] );
@@ -799,7 +1062,9 @@  discard block
 block discarded – undo
799 1062
 	    $write = NULL;
800 1063
 	    $e = NULL;
801 1064
 	    $n = socket_select($read, $write, $e, $timeout);
802
-	    if ($e != NULL) var_dump($e);
1065
+	    if ($e != NULL) {
1066
+	    	var_dump($e);
1067
+	    }
803 1068
 	    if ($n > 0) {
804 1069
 		foreach ($read as $nb => $r) {
805 1070
 		    //$value = $formats[$nb];
@@ -820,7 +1085,9 @@  discard block
 block discarded – undo
820 1085
 		    if ($buffer != '') {
821 1086
 			$tt[$format] = 0;
822 1087
 			if ($format == 'acarssbs3') {
823
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1088
+                    	    if ($globalDebug) {
1089
+                    	    	echo 'ACARS : '.$buffer."\n";
1090
+                    	    }
824 1091
 			    $ACARS->add(trim($buffer));
825 1092
 			    $ACARS->deleteLiveAcarsData();
826 1093
 			} elseif ($format == 'raw') {
@@ -829,9 +1096,15 @@  discard block
 block discarded – undo
829 1096
 			    if (is_array($data)) {
830 1097
 				$data['datetime'] = date('Y-m-d H:i:s');
831 1098
 				$data['format_source'] = 'raw';
832
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
833
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
834
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1099
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1100
+					$data['source_name'] = $globalSources[$nb]['name'];
1101
+				}
1102
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1103
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1104
+    				}
1105
+                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1106
+                                	$SI->add($data);
1107
+                                }
835 1108
                             }
836 1109
                         } elseif ($format == 'flightgearsp') {
837 1110
                     	    //echo $buffer."\n";
@@ -849,11 +1122,15 @@  discard block
 block discarded – undo
849 1122
 				$data['speed'] = round($line[5]*1.94384);
850 1123
 				$data['datetime'] = date('Y-m-d H:i:s');
851 1124
 				$data['format_source'] = 'flightgearsp';
852
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1125
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1126
+					$SI->add($data);
1127
+				}
853 1128
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
854 1129
 			    }
855 1130
                         } elseif ($format == 'acars') {
856
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1131
+                    	    if ($globalDebug) {
1132
+                    	    	echo 'ACARS : '.$buffer."\n";
1133
+                    	    }
857 1134
 			    $ACARS->add(trim($buffer));
858 1135
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
859 1136
 			    $ACARS->deleteLiveAcarsData();
@@ -874,7 +1151,9 @@  discard block
 block discarded – undo
874 1151
 				    $aircraft_type = $line[10];
875 1152
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
876 1153
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
877
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1154
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1155
+				    	$SI->add($data);
1156
+				    }
878 1157
 				}
879 1158
 			    }
880 1159
 			} elseif ($format == 'beast') {
@@ -890,21 +1169,43 @@  discard block
 block discarded – undo
890 1169
     				$data['hex'] = $lined['hexid'];
891 1170
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
892 1171
     				$data['datetime'] = date('Y-m-d H:i:s');;
893
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
894
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
895
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
896
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
897
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
898
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
899
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1172
+    				if (isset($lined['ident'])) {
1173
+    					$data['ident'] = $lined['ident'];
1174
+    				}
1175
+    				if (isset($lined['lat'])) {
1176
+    					$data['latitude'] = $lined['lat'];
1177
+    				}
1178
+    				if (isset($lined['lon'])) {
1179
+    					$data['longitude'] = $lined['lon'];
1180
+    				}
1181
+    				if (isset($lined['speed'])) {
1182
+    					$data['speed'] = $lined['speed'];
1183
+    				}
1184
+    				if (isset($lined['squawk'])) {
1185
+    					$data['squawk'] = $lined['squawk'];
1186
+    				}
1187
+    				if (isset($lined['alt'])) {
1188
+    					$data['altitude'] = $lined['alt'];
1189
+    				}
1190
+    				if (isset($lined['heading'])) {
1191
+    					$data['heading'] = $lined['heading'];
1192
+    				}
900 1193
     				$data['id_source'] = $id_source;
901 1194
     				$data['format_source'] = 'tsv';
902
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
903
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
904
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1195
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1196
+    					$data['source_name'] = $globalSources[$nb]['name'];
1197
+    				}
1198
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1199
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1200
+    				}
1201
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1202
+    					$SI->add($data);
1203
+    				}
905 1204
     				unset($lined);
906 1205
     				unset($data);
907
-    			    } else $error = true;
1206
+    			    } else {
1207
+    			    	$error = true;
1208
+    			    }
908 1209
 			} elseif ($format == 'aprs' && $use_aprs) {
909 1210
 			    if ($aprs_connect == 0) {
910 1211
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -930,29 +1231,44 @@  discard block
 block discarded – undo
930 1231
 				    $data['latitude'] = $line['latitude'];
931 1232
 				    $data['longitude'] = $line['longitude'];
932 1233
 				    //$data['verticalrate'] = $line[16];
933
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
934
-				    else $data['speed'] = 0;
1234
+				    if (isset($line['speed'])) {
1235
+				    	$data['speed'] = $line['speed'];
1236
+				    } else {
1237
+				    	$data['speed'] = 0;
1238
+				    }
935 1239
 				    $data['altitude'] = $line['altitude'];
936
-				    if (isset($line['course'])) $data['heading'] = $line['course'];
1240
+				    if (isset($line['course'])) {
1241
+				    	$data['heading'] = $line['course'];
1242
+				    }
937 1243
 				    //else $data['heading'] = 0;
938 1244
 				    $data['aircraft_type'] = $line['stealth'];
939
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1245
+				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) {
1246
+				    	$data['noarchive'] = true;
1247
+				    }
940 1248
     				    $data['id_source'] = $id_source;
941 1249
 				    $data['format_source'] = 'aprs';
942 1250
 				    $data['source_name'] = $line['source'];
943
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1251
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
1252
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1253
+    				    }
944 1254
 				    $currentdate = date('Y-m-d H:i:s');
945 1255
 				    $aprsdate = strtotime($data['datetime']);
946 1256
 				    // Accept data if time <= system time + 20s
947
-				    if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) $send = $SI->add($data);
948
-				    else {
949
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
950
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1257
+				    if ($line['stealth'] == 0 && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1258
+				    	$send = $SI->add($data);
1259
+				    } else {
1260
+					if ($line['stealth'] != 0) {
1261
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1262
+					} else {
1263
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1264
+					}
951 1265
 				    }
952 1266
 				    unset($data);
953 1267
 				} 
954 1268
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
955
-				elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1269
+				elseif ($line == true && $globalDebug) {
1270
+					echo '!! Failed : '.$buffer."!!\n";
1271
+				}
956 1272
 			    }
957 1273
 			} else {
958 1274
 			    $line = explode(',', $buffer);
@@ -980,25 +1296,42 @@  discard block
 block discarded – undo
980 1296
     				$data['ground'] = $line[21];
981 1297
     				$data['emergency'] = $line[19];
982 1298
     				$data['format_source'] = 'sbs';
983
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
984
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1299
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1300
+					$data['source_name'] = $globalSources[$nb]['name'];
1301
+				}
1302
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1303
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1304
+    				}
985 1305
     				$data['id_source'] = $id_source;
986
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
987
-    				else $error = true;
1306
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1307
+    					$send = $SI->add($data);
1308
+    				} else {
1309
+    					$error = true;
1310
+    				}
988 1311
     				unset($data);
989
-    			    } else $error = true;
1312
+    			    } else {
1313
+    			    	$error = true;
1314
+    			    }
990 1315
 			    if ($error) {
991 1316
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
992
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
1317
+					if ($globalDebug) {
1318
+						echo "Not a message. Ignoring... \n";
1319
+					}
993 1320
 				} else {
994
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
1321
+					if ($globalDebug) {
1322
+						echo "Wrong line format. Ignoring... \n";
1323
+					}
995 1324
 					if ($globalDebug) {
996 1325
 						echo $buffer;
997 1326
 						print_r($line);
998 1327
 					}
999 1328
 					//socket_close($r);
1000
-					if ($globalDebug) echo "Reconnect after an error...\n";
1001
-					if ($format == 'aprs') $aprs_connect = 0;
1329
+					if ($globalDebug) {
1330
+						echo "Reconnect after an error...\n";
1331
+					}
1332
+					if ($format == 'aprs') {
1333
+						$aprs_connect = 0;
1334
+					}
1002 1335
 					$sourceer[$nb] = $globalSources[$nb];
1003 1336
 					connect_all($sourceer);
1004 1337
 					$sourceer = array();
@@ -1006,10 +1339,14 @@  discard block
 block discarded – undo
1006 1339
 			    }
1007 1340
 			}
1008 1341
 			// Sleep for xxx microseconds
1009
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1342
+			if (isset($globalSBSSleep)) {
1343
+				usleep($globalSBSSleep);
1344
+			}
1010 1345
 		    } else {
1011 1346
 			if ($format == 'flightgearmp') {
1012
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1347
+			    	if ($globalDebug) {
1348
+			    		echo "Reconnect FlightGear MP...";
1349
+			    	}
1013 1350
 				//@socket_close($r);
1014 1351
 				sleep($globalMinFetch);
1015 1352
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1018,10 +1355,15 @@  discard block
 block discarded – undo
1018 1355
 				break;
1019 1356
 				
1020 1357
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1021
-			    if (isset($tt[$format])) $tt[$format]++;
1022
-			    else $tt[$format] = 0;
1358
+			    if (isset($tt[$format])) {
1359
+			    	$tt[$format]++;
1360
+			    } else {
1361
+			    	$tt[$format] = 0;
1362
+			    }
1023 1363
 			    if ($tt[$format] > 30) {
1024
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1364
+				if ($globalDebug) {
1365
+					echo "ERROR : Reconnect ".$format."...";
1366
+				}
1025 1367
 				//@socket_close($r);
1026 1368
 				sleep(2);
1027 1369
 				$aprs_connect = 0;
@@ -1037,12 +1379,18 @@  discard block
 block discarded – undo
1037 1379
 		}
1038 1380
 	    } else {
1039 1381
 		$error = socket_strerror(socket_last_error());
1040
-		if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1382
+		if ($globalDebug) {
1383
+			echo "ERROR : socket_select give this error ".$error . "\n";
1384
+		}
1041 1385
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || time() - $time >= $timeout) {
1042
-			if (isset($globalDebug)) echo "Restarting...\n";
1386
+			if (isset($globalDebug)) {
1387
+				echo "Restarting...\n";
1388
+			}
1043 1389
 			// Restart the script if possible
1044 1390
 			if (is_array($sockets)) {
1045
-			    if ($globalDebug) echo "Shutdown all sockets...";
1391
+			    if ($globalDebug) {
1392
+			    	echo "Shutdown all sockets...";
1393
+			    }
1046 1394
 			    
1047 1395
 			    foreach ($sockets as $sock) {
1048 1396
 				@socket_shutdown($sock,2);
@@ -1050,7 +1398,9 @@  discard block
 block discarded – undo
1050 1398
 			    }
1051 1399
 			    
1052 1400
 			}
1053
-			    if ($globalDebug) echo "Restart all connections...";
1401
+			    if ($globalDebug) {
1402
+			    	echo "Restart all connections...";
1403
+			    }
1054 1404
 			    sleep(2);
1055 1405
 			    $time = time();
1056 1406
 			    //connect_all($hosts);
@@ -1061,7 +1411,9 @@  discard block
 block discarded – undo
1061 1411
 	    }
1062 1412
 	}
1063 1413
 	if ($globalDaemon === false) {
1064
-	    if ($globalDebug) echo 'Check all...'."\n";
1414
+	    if ($globalDebug) {
1415
+	    	echo 'Check all...'."\n";
1416
+	    }
1065 1417
 	    $SI->checkAll();
1066 1418
 	}
1067 1419
     }
Please login to merge, or discard this patch.
install/class.update_schema.php 1 patch
Braces   +225 added lines, -84 removed lines patch added patch discarded remove patch
@@ -258,7 +258,9 @@  discard block
 block discarded – undo
258 258
     		// Update table countries
259 259
     		if ($Connection->tableExists('airspace')) {
260 260
     		    $error .= update_db::update_countries();
261
-		    if ($error != '') return $error;
261
+		    if ($error != '') {
262
+		    	return $error;
263
+		    }
262 264
 		}
263 265
 		// Update schema_version to 7
264 266
 		$query = "UPDATE `config` SET `value` = '7' WHERE `name` = 'schema_version'";
@@ -314,7 +316,9 @@  discard block
 block discarded – undo
314 316
     		$error = '';
315 317
     		// Update table aircraft
316 318
 		$error .= create_db::import_file('../db/source_location.sql');
317
-		if ($error != '') return $error;
319
+		if ($error != '') {
320
+			return $error;
321
+		}
318 322
 		// Update schema_version to 6
319 323
 		$query = "UPDATE `config` SET `value` = '8' WHERE `name` = 'schema_version'";
320 324
         	try {
@@ -331,7 +335,9 @@  discard block
 block discarded – undo
331 335
     		$error = '';
332 336
     		// Update table aircraft
333 337
 		$error .= create_db::import_file('../db/notam.sql');
334
-		if ($error != '') return $error;
338
+		if ($error != '') {
339
+			return $error;
340
+		}
335 341
 		$query = "DELETE FROM config WHERE name = 'last_update_db';
336 342
                         INSERT INTO config (name,value) VALUES ('last_update_db',NOW());
337 343
                         DELETE FROM config WHERE name = 'last_update_notam_db';
@@ -365,7 +371,9 @@  discard block
 block discarded – undo
365 371
 		$error = '';
366 372
     		// Update table atc
367 373
 		$error .= create_db::import_file('../db/atc.sql');
368
-		if ($error != '') return $error;
374
+		if ($error != '') {
375
+			return $error;
376
+		}
369 377
 		
370 378
 		$query = "UPDATE `config` SET `value` = '10' WHERE `name` = 'schema_version'";
371 379
         	try {
@@ -389,13 +397,21 @@  discard block
 block discarded – undo
389 397
 		$error = '';
390 398
     		// Add tables
391 399
 		$error .= create_db::import_file('../db/aircraft_owner.sql');
392
-		if ($error != '') return $error;
400
+		if ($error != '') {
401
+			return $error;
402
+		}
393 403
 		$error .= create_db::import_file('../db/metar.sql');
394
-		if ($error != '') return $error;
404
+		if ($error != '') {
405
+			return $error;
406
+		}
395 407
 		$error .= create_db::import_file('../db/taf.sql');
396
-		if ($error != '') return $error;
408
+		if ($error != '') {
409
+			return $error;
410
+		}
397 411
 		$error .= create_db::import_file('../db/airport.sql');
398
-		if ($error != '') return $error;
412
+		if ($error != '') {
413
+			return $error;
414
+		}
399 415
 		
400 416
 		$query = "UPDATE `config` SET `value` = '11' WHERE `name` = 'schema_version'";
401 417
         	try {
@@ -469,19 +485,33 @@  discard block
 block discarded – undo
469 485
 		$error = '';
470 486
     		// Add tables
471 487
 		$error .= create_db::import_file('../db/stats.sql');
472
-		if ($error != '') return $error;
488
+		if ($error != '') {
489
+			return $error;
490
+		}
473 491
 		$error .= create_db::import_file('../db/stats_aircraft.sql');
474
-		if ($error != '') return $error;
492
+		if ($error != '') {
493
+			return $error;
494
+		}
475 495
 		$error .= create_db::import_file('../db/stats_airline.sql');
476
-		if ($error != '') return $error;
496
+		if ($error != '') {
497
+			return $error;
498
+		}
477 499
 		$error .= create_db::import_file('../db/stats_airport.sql');
478
-		if ($error != '') return $error;
500
+		if ($error != '') {
501
+			return $error;
502
+		}
479 503
 		$error .= create_db::import_file('../db/stats_owner.sql');
480
-		if ($error != '') return $error;
504
+		if ($error != '') {
505
+			return $error;
506
+		}
481 507
 		$error .= create_db::import_file('../db/stats_pilot.sql');
482
-		if ($error != '') return $error;
508
+		if ($error != '') {
509
+			return $error;
510
+		}
483 511
 		$error .= create_db::import_file('../db/spotter_archive_output.sql');
484
-		if ($error != '') return $error;
512
+		if ($error != '') {
513
+			return $error;
514
+		}
485 515
 		
486 516
 		$query = "UPDATE `config` SET `value` = '13' WHERE `name` = 'schema_version'";
487 517
         	try {
@@ -521,7 +551,9 @@  discard block
 block discarded – undo
521 551
     		// Add tables
522 552
     		if (!$Connection->tableExists('stats_flight')) {
523 553
 			$error .= create_db::import_file('../db/stats_flight.sql');
524
-			if ($error != '') return $error;
554
+			if ($error != '') {
555
+				return $error;
556
+			}
525 557
 		}
526 558
 		$query = "UPDATE `config` SET `value` = '15' WHERE `name` = 'schema_version'";
527 559
         	try {
@@ -545,7 +577,9 @@  discard block
 block discarded – undo
545 577
     		} catch(PDOException $e) {
546 578
 		    return "error (update stats) : ".$e->getMessage()."\n";
547 579
     		}
548
-		if ($error != '') return $error;
580
+		if ($error != '') {
581
+			return $error;
582
+		}
549 583
 		$query = "UPDATE `config` SET `value` = '16' WHERE `name` = 'schema_version'";
550 584
         	try {
551 585
             	    $sth = $Connection->db->prepare($query);
@@ -566,7 +600,9 @@  discard block
 block discarded – undo
566 600
     		if (!$Connection->tableExists('stats_callsign')) {
567 601
 			$error .= create_db::import_file('../db/stats_callsign.sql');
568 602
 		}
569
-		if ($error != '') return $error;
603
+		if ($error != '') {
604
+			return $error;
605
+		}
570 606
 		$query = "UPDATE `config` SET `value` = '17' WHERE `name` = 'schema_version'";
571 607
         	try {
572 608
             	    $sth = $Connection->db->prepare($query);
@@ -584,7 +620,9 @@  discard block
 block discarded – undo
584 620
     		if (!$Connection->tableExists('stats_country')) {
585 621
 			$error .= create_db::import_file('../db/stats_country.sql');
586 622
 		}
587
-		if ($error != '') return $error;
623
+		if ($error != '') {
624
+			return $error;
625
+		}
588 626
 		$query = "UPDATE `config` SET `value` = '18' WHERE `name` = 'schema_version'";
589 627
         	try {
590 628
             	    $sth = $Connection->db->prepare($query);
@@ -607,7 +645,9 @@  discard block
 block discarded – undo
607 645
 			    return "error (update stats) : ".$e->getMessage()."\n";
608 646
     			}
609 647
     		}
610
-		if ($error != '') return $error;
648
+		if ($error != '') {
649
+			return $error;
650
+		}
611 651
 		$query = "UPDATE `config` SET `value` = '19' WHERE `name` = 'schema_version'";
612 652
         	try {
613 653
             	    $sth = $Connection->db->prepare($query);
@@ -623,7 +663,9 @@  discard block
 block discarded – undo
623 663
 		$error = '';
624 664
     		// Update airport table
625 665
 		$error .= create_db::import_file('../db/airport.sql');
626
-		if ($error != '') return 'Import airport.sql : '.$error;
666
+		if ($error != '') {
667
+			return 'Import airport.sql : '.$error;
668
+		}
627 669
 		// Remove primary key on Spotter_Archive
628 670
 		$query = "alter table spotter_archive drop spotter_archive_id";
629 671
         	try {
@@ -699,7 +741,9 @@  discard block
 block discarded – undo
699 741
 				return "error (add source_name column) : ".$e->getMessage()."\n";
700 742
     			}
701 743
     		}
702
-		if ($error != '') return $error;
744
+		if ($error != '') {
745
+			return $error;
746
+		}
703 747
 		$query = "UPDATE `config` SET `value` = '20' WHERE `name` = 'schema_version'";
704 748
         	try {
705 749
             	    $sth = $Connection->db->prepare($query);
@@ -717,7 +761,9 @@  discard block
 block discarded – undo
717 761
     		// Update airline table
718 762
     		if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS) {
719 763
 			$error .= create_db::import_file('../db/airlines.sql');
720
-			if ($error != '') return 'Import airlines.sql : '.$error;
764
+			if ($error != '') {
765
+				return 'Import airlines.sql : '.$error;
766
+			}
721 767
 		}
722 768
 		if (!$Connection->checkColumnName('aircraft_modes','type_flight')) {
723 769
 			// Add column over_country
@@ -729,7 +775,9 @@  discard block
 block discarded – undo
729 775
 				return "error (add over_country) : ".$e->getMessage()."\n";
730 776
     			}
731 777
     		}
732
-		if ($error != '') return $error;
778
+		if ($error != '') {
779
+			return $error;
780
+		}
733 781
 		/*
734 782
     		if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS) {
735 783
 			// Force update ModeS (this will put type_flight data
@@ -759,7 +807,9 @@  discard block
 block discarded – undo
759 807
 			} catch(PDOException $e) {
760 808
 				return "error (rename type to stats_type on stats*) : ".$e->getMessage()."\n";
761 809
 			}
762
-			if ($error != '') return $error;
810
+			if ($error != '') {
811
+				return $error;
812
+			}
763 813
 		}
764 814
 		$query = "UPDATE `config` SET `value` = '22' WHERE `name` = 'schema_version'";
765 815
         	try {
@@ -782,7 +832,9 @@  discard block
 block discarded – undo
782 832
 			} else {
783 833
 				$error .= create_db::import_file('../db/pgsql/stats_source.sql');
784 834
 			}
785
-			if ($error != '') return $error;
835
+			if ($error != '') {
836
+				return $error;
837
+			}
786 838
 		}
787 839
 		$query = "UPDATE config SET value = '23' WHERE name = 'schema_version'";
788 840
         	try {
@@ -804,12 +856,16 @@  discard block
 block discarded – undo
804 856
 		if ($globalDBdriver == 'mysql') {
805 857
 			if (!$Connection->tableExists('tle')) {
806 858
 				$error .= create_db::import_file('../db/tle.sql');
807
-				if ($error != '') return $error;
859
+				if ($error != '') {
860
+					return $error;
861
+				}
808 862
 			}
809 863
 		} else {
810 864
 			if (!$Connection->tableExists('tle')) {
811 865
 				$error .= create_db::import_file('../db/pgsql/tle.sql');
812
-				if ($error != '') return $error;
866
+				if ($error != '') {
867
+					return $error;
868
+				}
813 869
 			}
814 870
 			$query = "create index flightaware_id_idx ON spotter_archive USING btree(flightaware_id)";
815 871
 			try {
@@ -849,7 +905,9 @@  discard block
 block discarded – undo
849 905
 		} else {
850 906
 			$error .= create_db::import_file('../db/pgsql/airlines.sql');
851 907
 		}
852
-		if ($error != '') return 'Import airlines.sql : '.$error;
908
+		if ($error != '') {
909
+			return 'Import airlines.sql : '.$error;
910
+		}
853 911
 		if (!$Connection->checkColumnName('airlines','forsource')) {
854 912
 			// Add forsource to airlines
855 913
 			$query = "ALTER TABLE airlines ADD forsource VARCHAR(255) NULL DEFAULT NULL";
@@ -1136,8 +1194,11 @@  discard block
 block discarded – undo
1136 1194
     	    if ($Connection->tableExists('aircraft')) {
1137 1195
     		if (!$Connection->tableExists('config')) {
1138 1196
     		    $version = '1';
1139
-    		    if ($update) return self::update_from_1();
1140
-    		    else return $version;
1197
+    		    if ($update) {
1198
+    		    	return self::update_from_1();
1199
+    		    } else {
1200
+    		    	return $version;
1201
+    		    }
1141 1202
 		} else {
1142 1203
     		    $Connection = new Connection();
1143 1204
 		    $query = "SELECT value FROM config WHERE name = 'schema_version' LIMIT 1";
@@ -1151,110 +1212,190 @@  discard block
 block discarded – undo
1151 1212
     		    if ($update) {
1152 1213
     			if ($result['value'] == '2') {
1153 1214
     			    $error = self::update_from_2();
1154
-    			    if ($error != '') return $error;
1155
-    			    else return self::check_version(true);
1215
+    			    if ($error != '') {
1216
+    			    	return $error;
1217
+    			    } else {
1218
+    			    	return self::check_version(true);
1219
+    			    }
1156 1220
     			} elseif ($result['value'] == '3') {
1157 1221
     			    $error = self::update_from_3();
1158
-    			    if ($error != '') return $error;
1159
-    			    else return self::check_version(true);
1222
+    			    if ($error != '') {
1223
+    			    	return $error;
1224
+    			    } else {
1225
+    			    	return self::check_version(true);
1226
+    			    }
1160 1227
     			} elseif ($result['value'] == '4') {
1161 1228
     			    $error = self::update_from_4();
1162
-    			    if ($error != '') return $error;
1163
-    			    else return self::check_version(true);
1229
+    			    if ($error != '') {
1230
+    			    	return $error;
1231
+    			    } else {
1232
+    			    	return self::check_version(true);
1233
+    			    }
1164 1234
     			} elseif ($result['value'] == '5') {
1165 1235
     			    $error = self::update_from_5();
1166
-    			    if ($error != '') return $error;
1167
-    			    else return self::check_version(true);
1236
+    			    if ($error != '') {
1237
+    			    	return $error;
1238
+    			    } else {
1239
+    			    	return self::check_version(true);
1240
+    			    }
1168 1241
     			} elseif ($result['value'] == '6') {
1169 1242
     			    $error = self::update_from_6();
1170
-    			    if ($error != '') return $error;
1171
-    			    else return self::check_version(true);
1243
+    			    if ($error != '') {
1244
+    			    	return $error;
1245
+    			    } else {
1246
+    			    	return self::check_version(true);
1247
+    			    }
1172 1248
     			} elseif ($result['value'] == '7') {
1173 1249
     			    $error = self::update_from_7();
1174
-    			    if ($error != '') return $error;
1175
-    			    else return self::check_version(true);
1250
+    			    if ($error != '') {
1251
+    			    	return $error;
1252
+    			    } else {
1253
+    			    	return self::check_version(true);
1254
+    			    }
1176 1255
     			} elseif ($result['value'] == '8') {
1177 1256
     			    $error = self::update_from_8();
1178
-    			    if ($error != '') return $error;
1179
-    			    else return self::check_version(true);
1257
+    			    if ($error != '') {
1258
+    			    	return $error;
1259
+    			    } else {
1260
+    			    	return self::check_version(true);
1261
+    			    }
1180 1262
     			} elseif ($result['value'] == '9') {
1181 1263
     			    $error = self::update_from_9();
1182
-    			    if ($error != '') return $error;
1183
-    			    else return self::check_version(true);
1264
+    			    if ($error != '') {
1265
+    			    	return $error;
1266
+    			    } else {
1267
+    			    	return self::check_version(true);
1268
+    			    }
1184 1269
     			} elseif ($result['value'] == '10') {
1185 1270
     			    $error = self::update_from_10();
1186
-    			    if ($error != '') return $error;
1187
-    			    else return self::check_version(true);
1271
+    			    if ($error != '') {
1272
+    			    	return $error;
1273
+    			    } else {
1274
+    			    	return self::check_version(true);
1275
+    			    }
1188 1276
     			} elseif ($result['value'] == '11') {
1189 1277
     			    $error = self::update_from_11();
1190
-    			    if ($error != '') return $error;
1191
-    			    else return self::check_version(true);
1278
+    			    if ($error != '') {
1279
+    			    	return $error;
1280
+    			    } else {
1281
+    			    	return self::check_version(true);
1282
+    			    }
1192 1283
     			} elseif ($result['value'] == '12') {
1193 1284
     			    $error = self::update_from_12();
1194
-    			    if ($error != '') return $error;
1195
-    			    else return self::check_version(true);
1285
+    			    if ($error != '') {
1286
+    			    	return $error;
1287
+    			    } else {
1288
+    			    	return self::check_version(true);
1289
+    			    }
1196 1290
     			} elseif ($result['value'] == '13') {
1197 1291
     			    $error = self::update_from_13();
1198
-    			    if ($error != '') return $error;
1199
-    			    else return self::check_version(true);
1292
+    			    if ($error != '') {
1293
+    			    	return $error;
1294
+    			    } else {
1295
+    			    	return self::check_version(true);
1296
+    			    }
1200 1297
     			} elseif ($result['value'] == '14') {
1201 1298
     			    $error = self::update_from_14();
1202
-    			    if ($error != '') return $error;
1203
-    			    else return self::check_version(true);
1299
+    			    if ($error != '') {
1300
+    			    	return $error;
1301
+    			    } else {
1302
+    			    	return self::check_version(true);
1303
+    			    }
1204 1304
     			} elseif ($result['value'] == '15') {
1205 1305
     			    $error = self::update_from_15();
1206
-    			    if ($error != '') return $error;
1207
-    			    else return self::check_version(true);
1306
+    			    if ($error != '') {
1307
+    			    	return $error;
1308
+    			    } else {
1309
+    			    	return self::check_version(true);
1310
+    			    }
1208 1311
     			} elseif ($result['value'] == '16') {
1209 1312
     			    $error = self::update_from_16();
1210
-    			    if ($error != '') return $error;
1211
-    			    else return self::check_version(true);
1313
+    			    if ($error != '') {
1314
+    			    	return $error;
1315
+    			    } else {
1316
+    			    	return self::check_version(true);
1317
+    			    }
1212 1318
     			} elseif ($result['value'] == '17') {
1213 1319
     			    $error = self::update_from_17();
1214
-    			    if ($error != '') return $error;
1215
-    			    else return self::check_version(true);
1320
+    			    if ($error != '') {
1321
+    			    	return $error;
1322
+    			    } else {
1323
+    			    	return self::check_version(true);
1324
+    			    }
1216 1325
     			} elseif ($result['value'] == '18') {
1217 1326
     			    $error = self::update_from_18();
1218
-    			    if ($error != '') return $error;
1219
-    			    else return self::check_version(true);
1327
+    			    if ($error != '') {
1328
+    			    	return $error;
1329
+    			    } else {
1330
+    			    	return self::check_version(true);
1331
+    			    }
1220 1332
     			} elseif ($result['value'] == '19') {
1221 1333
     			    $error = self::update_from_19();
1222
-    			    if ($error != '') return $error;
1223
-    			    else return self::check_version(true);
1334
+    			    if ($error != '') {
1335
+    			    	return $error;
1336
+    			    } else {
1337
+    			    	return self::check_version(true);
1338
+    			    }
1224 1339
     			} elseif ($result['value'] == '20') {
1225 1340
     			    $error = self::update_from_20();
1226
-    			    if ($error != '') return $error;
1227
-    			    else return self::check_version(true);
1341
+    			    if ($error != '') {
1342
+    			    	return $error;
1343
+    			    } else {
1344
+    			    	return self::check_version(true);
1345
+    			    }
1228 1346
     			} elseif ($result['value'] == '21') {
1229 1347
     			    $error = self::update_from_21();
1230
-    			    if ($error != '') return $error;
1231
-    			    else return self::check_version(true);
1348
+    			    if ($error != '') {
1349
+    			    	return $error;
1350
+    			    } else {
1351
+    			    	return self::check_version(true);
1352
+    			    }
1232 1353
     			} elseif ($result['value'] == '22') {
1233 1354
     			    $error = self::update_from_22();
1234
-    			    if ($error != '') return $error;
1235
-    			    else return self::check_version(true);
1355
+    			    if ($error != '') {
1356
+    			    	return $error;
1357
+    			    } else {
1358
+    			    	return self::check_version(true);
1359
+    			    }
1236 1360
     			} elseif ($result['value'] == '23') {
1237 1361
     			    $error = self::update_from_23();
1238
-    			    if ($error != '') return $error;
1239
-    			    else return self::check_version(true);
1362
+    			    if ($error != '') {
1363
+    			    	return $error;
1364
+    			    } else {
1365
+    			    	return self::check_version(true);
1366
+    			    }
1240 1367
     			} elseif ($result['value'] == '24') {
1241 1368
     			    $error = self::update_from_24();
1242
-    			    if ($error != '') return $error;
1243
-    			    else return self::check_version(true);
1369
+    			    if ($error != '') {
1370
+    			    	return $error;
1371
+    			    } else {
1372
+    			    	return self::check_version(true);
1373
+    			    }
1244 1374
     			} elseif ($result['value'] == '25') {
1245 1375
     			    $error = self::update_from_25();
1246
-    			    if ($error != '') return $error;
1247
-    			    else return self::check_version(true);
1376
+    			    if ($error != '') {
1377
+    			    	return $error;
1378
+    			    } else {
1379
+    			    	return self::check_version(true);
1380
+    			    }
1248 1381
     			} elseif ($result['value'] == '26') {
1249 1382
     			    $error = self::update_from_26();
1250
-    			    if ($error != '') return $error;
1251
-    			    else return self::check_version(true);
1252
-    			} else return '';
1383
+    			    if ($error != '') {
1384
+    			    	return $error;
1385
+    			    } else {
1386
+    			    	return self::check_version(true);
1387
+    			    }
1388
+    			} else {
1389
+    				return '';
1390
+    			}
1391
+    		    } else {
1392
+    		    	return $result['value'];
1253 1393
     		    }
1254
-    		    else return $result['value'];
1255 1394
 		}
1256 1395
 		
1257
-	    } else return $version;
1396
+	    } else {
1397
+	    	return $version;
1398
+	    }
1258 1399
     	}
1259 1400
     	
1260 1401
 }
Please login to merge, or discard this patch.