Completed
Push — master ( 65a957...a0dd18 )
by Yannick
07:20
created
require/class.APRS.php 1 patch
Braces   +152 added lines, -58 removed lines patch added patch discarded remove patch
@@ -107,17 +107,23 @@  discard block
 block discarded – undo
107 107
 	
108 108
 	/* Check that end was found and body has at least one byte. */
109 109
 	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) {
110
-	    if ($globalDebug) echo '!!! APRS invalid : '.$input."\n";
110
+	    if ($globalDebug) {
111
+	    	echo '!!! APRS invalid : '.$input."\n";
112
+	    }
111 113
 	    return false;
112 114
 	}
113 115
 	
114
-	if ($debug) echo 'input : '.$input."\n";
116
+	if ($debug) {
117
+		echo 'input : '.$input."\n";
118
+	}
115 119
 	/* Save header and body. */
116 120
 	$body = substr($input,$splitpos+1,$input_len);
117 121
 	$body_len = strlen($body);
118 122
 	$header = substr($input,0,$splitpos);
119 123
 	//$header_len = strlen($header);
120
-	if ($debug) echo 'header : '.$header."\n";
124
+	if ($debug) {
125
+		echo 'header : '.$header."\n";
126
+	}
121 127
 	
122 128
 	/* Parse source, target and path. */
123 129
 	//FLRDF0A52>APRS,qAS,LSTB
@@ -131,10 +137,14 @@  discard block
 block discarded – undo
131 137
 		$result['format_source'] = 'famaprs';
132 138
 		$result['source_type'] = 'ais';
133 139
 	    } else {
134
-		if ($debug) echo 'ident : '.$ident."\n";
140
+		if ($debug) {
141
+			echo 'ident : '.$ident."\n";
142
+		}
135 143
 		$result['ident'] = $ident;
136 144
 	    }
137
-	} else return false;
145
+	} else {
146
+		return false;
147
+	}
138 148
 	$elements = explode(',',$all_elements);
139 149
 	$source = end($elements);
140 150
 	$result['source'] = $source;
@@ -143,7 +153,9 @@  discard block
 block discarded – undo
143 153
 	        //echo "ok";
144 154
 	        //if ($element == 'TCPIP*') return false;
145 155
 	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) {
146
-		if ($debug) echo 'element : '.$element."\n";
156
+		if ($debug) {
157
+			echo 'element : '.$element."\n";
158
+		}
147 159
 		return false;
148 160
 	    }
149 161
 	    /*
@@ -156,11 +168,15 @@  discard block
 block discarded – undo
156 168
 	}
157 169
 	
158 170
 	$type = substr($body,0,1);
159
-	if ($debug) echo 'type : '.$type."\n";
171
+	if ($debug) {
172
+		echo 'type : '.$type."\n";
173
+	}
160 174
 	if ($type == ';') {
161 175
 		if (isset($result['source_type']) && $result['source_type'] == 'modes') {
162 176
 			$result['address'] = trim(substr($body,1,9));
163
-		} else $result['ident'] = trim(substr($body,1,9));
177
+		} else {
178
+			$result['ident'] = trim(substr($body,1,9));
179
+		}
164 180
 	} elseif ($type == ',') {
165 181
 		// Invalid data or test data
166 182
 		return false;
@@ -228,7 +244,9 @@  discard block
 block discarded – undo
228 244
 		//$symbol_table = $matches[4];
229 245
 		$lat = intval($lat_deg);
230 246
 		$lon = intval($lon_deg);
231
-		if ($lat > 89 || $lon > 179) return false;
247
+		if ($lat > 89 || $lon > 179) {
248
+			return false;
249
+		}
232 250
 	    
233 251
 	    /*
234 252
 	    $tmp_5b = str_replace('.','',$lat_min);
@@ -238,8 +256,12 @@  discard block
 block discarded – undo
238 256
 	    */
239 257
 		$latitude = $lat + floatval($lat_min)/60;
240 258
 		$longitude = $lon + floatval($lon_min)/60;
241
-		if ($sind == 'S') $latitude = 0-$latitude;
242
-		if ($wind == 'W') $longitude = 0-$longitude;
259
+		if ($sind == 'S') {
260
+			$latitude = 0-$latitude;
261
+		}
262
+		if ($wind == 'W') {
263
+			$longitude = 0-$longitude;
264
+		}
243 265
 		$result['latitude'] = $latitude;
244 266
 		$result['longitude'] = $longitude;
245 267
 		$body_parse = substr($body_parse,18);
@@ -273,7 +295,9 @@  discard block
 block discarded – undo
273 295
 			$body_parse = substr($body_parse,1);
274 296
 			$body_parse_len = strlen($body_parse);
275 297
 			$result['symbol_code'] = $symbol_code;
276
-			if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code];
298
+			if (isset($this->symbols[$symbol_code])) {
299
+				$result['symbol'] = $this->symbols[$symbol_code];
300
+			}
277 301
 			if ($symbol_code != '_') {
278 302
 			}
279 303
 		    //$body_parse = substr($body_parse,1);
@@ -284,7 +308,9 @@  discard block
 block discarded – undo
284 308
 		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) {
285 309
 		    	    $course = substr($body_parse,0,3);
286 310
 		    	    $tmp_s = intval($course);
287
-		    	    if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course);
311
+		    	    if ($tmp_s >= 1 && $tmp_s <= 360) {
312
+		    	    	$result['heading'] = intval($course);
313
+		    	    }
288 314
 		    	    $speed = substr($body_parse,4,3);
289 315
 		    	    if ($speed != '...') {
290 316
 		    		    $result['speed'] = round($speed*1.852);
@@ -322,10 +348,16 @@  discard block
 block discarded – undo
322 348
 			        $lat_off = (($dao_split[1])-48.0)*0.001/60.0;
323 349
 			        $lon_off = (($dao_split[2])-48.0)*0.001/60.0;
324 350
 			    
325
-				if ($result['latitude'] < 0) $result['latitude'] -= $lat_off;
326
-				else $result['latitude'] += $lat_off;
327
-				if ($result['longitude'] < 0) $result['longitude'] -= $lon_off;
328
-				else $result['longitude'] += $lon_off;
351
+				if ($result['latitude'] < 0) {
352
+					$result['latitude'] -= $lat_off;
353
+				} else {
354
+					$result['latitude'] += $lat_off;
355
+				}
356
+				if ($result['longitude'] < 0) {
357
+					$result['longitude'] -= $lon_off;
358
+				} else {
359
+					$result['longitude'] += $lon_off;
360
+				}
329 361
 			    }
330 362
 		            $body_parse = substr($body_parse,6);
331 363
 		    }
@@ -360,27 +392,48 @@  discard block
 block discarded – undo
360 392
 			$address = substr($id,2);
361 393
 			//print_r($matches);
362 394
 			$addressType = (intval(substr($id,0,2),16))&3;
363
-			if ($addressType == 0) $result['addresstype'] = "RANDOM";
364
-			elseif ($addressType == 1) $result['addresstype'] = "ICAO";
365
-			elseif ($addressType == 2) $result['addresstype'] = "FLARM";
366
-			elseif ($addressType == 3) $result['addresstype'] = "OGN";
395
+			if ($addressType == 0) {
396
+				$result['addresstype'] = "RANDOM";
397
+			} elseif ($addressType == 1) {
398
+				$result['addresstype'] = "ICAO";
399
+			} elseif ($addressType == 2) {
400
+				$result['addresstype'] = "FLARM";
401
+			} elseif ($addressType == 3) {
402
+				$result['addresstype'] = "OGN";
403
+			}
367 404
 			$aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2);
368 405
 			$result['aircrafttype_code'] = $aircraftType;
369
-			if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN";
370
-			elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER";
371
-			elseif ($aircraftType == 2) $result['aircrafttype'] = "TOW_PLANE";
372
-			elseif ($aircraftType == 3) $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
373
-			elseif ($aircraftType == 4) $result['aircrafttype'] = "PARACHUTE";
374
-			elseif ($aircraftType == 5) $result['aircrafttype'] = "DROP_PLANE";
375
-			elseif ($aircraftType == 6) $result['aircrafttype'] = "HANG_GLIDER";
376
-			elseif ($aircraftType == 7) $result['aircrafttype'] = "PARA_GLIDER";
377
-			elseif ($aircraftType == 8) $result['aircrafttype'] = "POWERED_AIRCRAFT";
378
-			elseif ($aircraftType == 9) $result['aircrafttype'] = "JET_AIRCRAFT";
379
-			elseif ($aircraftType == 10) $result['aircrafttype'] = "UFO";
380
-			elseif ($aircraftType == 11) $result['aircrafttype'] = "BALLOON";
381
-			elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP";
382
-			elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV";
383
-			elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT";
406
+			if ($aircraftType == 0) {
407
+				$result['aircrafttype'] = "UNKNOWN";
408
+			} elseif ($aircraftType == 1) {
409
+				$result['aircrafttype'] = "GLIDER";
410
+			} elseif ($aircraftType == 2) {
411
+				$result['aircrafttype'] = "TOW_PLANE";
412
+			} elseif ($aircraftType == 3) {
413
+				$result['aircrafttype'] = "HELICOPTER_ROTORCRAFT";
414
+			} elseif ($aircraftType == 4) {
415
+				$result['aircrafttype'] = "PARACHUTE";
416
+			} elseif ($aircraftType == 5) {
417
+				$result['aircrafttype'] = "DROP_PLANE";
418
+			} elseif ($aircraftType == 6) {
419
+				$result['aircrafttype'] = "HANG_GLIDER";
420
+			} elseif ($aircraftType == 7) {
421
+				$result['aircrafttype'] = "PARA_GLIDER";
422
+			} elseif ($aircraftType == 8) {
423
+				$result['aircrafttype'] = "POWERED_AIRCRAFT";
424
+			} elseif ($aircraftType == 9) {
425
+				$result['aircrafttype'] = "JET_AIRCRAFT";
426
+			} elseif ($aircraftType == 10) {
427
+				$result['aircrafttype'] = "UFO";
428
+			} elseif ($aircraftType == 11) {
429
+				$result['aircrafttype'] = "BALLOON";
430
+			} elseif ($aircraftType == 12) {
431
+				$result['aircrafttype'] = "AIRSHIP";
432
+			} elseif ($aircraftType == 13) {
433
+				$result['aircrafttype'] = "UAV";
434
+			} elseif ($aircraftType == 15) {
435
+				$result['aircrafttype'] = "STATIC_OBJECT";
436
+			}
384 437
 			$stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0;
385 438
 			$result['stealth'] = $stealth;
386 439
 			$result['address'] = $address;
@@ -420,13 +473,21 @@  discard block
 block discarded – undo
420 473
 			$result['temp'] = round(5/9*(($matches[1])-32),1);
421 474
 		    }
422 475
 		}
423
-		} else $result['comment'] = trim($body_parse);
476
+		} else {
477
+			$result['comment'] = trim($body_parse);
478
+		}
424 479
 
425 480
 	    }
426 481
 	//}
427
-	if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4);
428
-	if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4);
429
-	if ($debug) print_r($result);
482
+	if (isset($result['latitude'])) {
483
+		$result['latitude'] = round($result['latitude'],4);
484
+	}
485
+	if (isset($result['longitude'])) {
486
+		$result['longitude'] = round($result['longitude'],4);
487
+	}
488
+	if ($debug) {
489
+		print_r($result);
490
+	}
430 491
 	return $result;
431 492
     }
432 493
     
@@ -435,12 +496,21 @@  discard block
 block discarded – undo
435 496
 	$aprs_connect = 0;
436 497
 	$aprs_keep = 120;
437 498
 	$aprs_last_tx = time();
438
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
439
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
440
-	if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid;
441
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
442
-	if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass;
443
-	else $aprs_pass = '-1';
499
+	if (isset($globalAPRSversion)) {
500
+		$aprs_version = $globalAPRSversion;
501
+	} else {
502
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
503
+	}
504
+	if (isset($globalServerAPRSssid)) {
505
+		$aprs_ssid = $globalServerAPRSssid;
506
+	} else {
507
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
508
+	}
509
+	if (isset($globalServerAPRSpass)) {
510
+		$aprs_pass = $globalServerAPRSpass;
511
+	} else {
512
+		$aprs_pass = '-1';
513
+	}
444 514
 	
445 515
 	$aprs_filter  = '';
446 516
 	$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
@@ -467,9 +537,13 @@  discard block
 block discarded – undo
467 537
     }
468 538
     
469 539
     function send($data) {
470
-	if ($this->connected === false) $this->connect();
540
+	if ($this->connected === false) {
541
+		$this->connect();
542
+	}
471 543
 	$send = socket_send( $this->socket  , $data , strlen($data),0);
472
-	if ($send === FALSE) $this->connect();
544
+	if ($send === FALSE) {
545
+		$this->connect();
546
+	}
473 547
     }
474 548
 }
475 549
 
@@ -486,18 +560,26 @@  discard block
 block discarded – undo
486 560
 			//$w = '00';
487 561
 			$custom = '';
488 562
 			if ($ident != '') {
489
-				if ($custom != '') $custom .= '/';
563
+				if ($custom != '') {
564
+					$custom .= '/';
565
+				}
490 566
 				$custom .= 'CS='.$ident;
491 567
 			}
492 568
 			if ($squawk != '') {
493
-				if ($custom != '') $custom .= '/';
569
+				if ($custom != '') {
570
+					$custom .= '/';
571
+				}
494 572
 				$custom .= 'SQ='.$squawk;
495 573
 			}
496 574
 			if ($aircraft_icao != '' && $aircraft_icao != 'NA') {
497
-				if ($custom != '') $custom .= '/';
575
+				if ($custom != '') {
576
+					$custom .= '/';
577
+				}
498 578
 				$custom .= 'AI='.$aircraft_icao;
499 579
 			}
500
-			if ($custom != '') $custom = ' '.$custom;
580
+			if ($custom != '') {
581
+				$custom = ' '.$custom;
582
+			}
501 583
 			$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");
502 584
 		}
503 585
 	}
@@ -515,26 +597,38 @@  discard block
 block discarded – undo
515 597
 			//$w = '00';
516 598
 			$custom = '';
517 599
 			if ($ident != '') {
518
-				if ($custom != '') $custom .= '/';
600
+				if ($custom != '') {
601
+					$custom .= '/';
602
+				}
519 603
 				$custom .= 'CS='.$ident;
520 604
 			}
521 605
 			if ($typeid != '') {
522
-				if ($custom != '') $custom .= '/';
606
+				if ($custom != '') {
607
+					$custom .= '/';
608
+				}
523 609
 				$custom .= 'TI='.$typeid;
524 610
 			}
525 611
 			if ($imo != '') {
526
-				if ($custom != '') $custom .= '/';
612
+				if ($custom != '') {
613
+					$custom .= '/';
614
+				}
527 615
 				$custom .= 'IMO='.$imo;
528 616
 			}
529 617
 			if ($arrival_date != '') {
530
-				if ($custom != '') $custom .= '/';
618
+				if ($custom != '') {
619
+					$custom .= '/';
620
+				}
531 621
 				$custom .= 'AD='.strtotime($arrival_date);
532 622
 			}
533 623
 			if ($arrival_code != '') {
534
-				if ($custom != '') $custom .= '/';
624
+				if ($custom != '') {
625
+					$custom .= '/';
626
+				}
535 627
 				$custom .= 'AC='.$arrival_code;
536 628
 			}
537
-			if ($custom != '') $custom = ' '.$custom;
629
+			if ($custom != '') {
630
+				$custom = ' '.$custom;
631
+			}
538 632
 			$altitude = 0;
539 633
 			$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");
540 634
 		}
Please login to merge, or discard this patch.
require/class.SpotterImport.php 1 patch
Braces   +331 added lines, -117 removed lines patch added patch discarded remove patch
@@ -59,7 +59,9 @@  discard block
 block discarded – undo
59 59
 	$dbc = $this->db;
60 60
 	$this->all_flights[$id]['schedule_check'] = true;
61 61
 	if ($globalSchedulesFetch) {
62
-	if ($globalDebug) echo 'Getting schedule info...'."\n";
62
+	if ($globalDebug) {
63
+		echo 'Getting schedule info...'."\n";
64
+	}
63 65
 	$Spotter = new Spotter($dbc);
64 66
 	$Schedule = new Schedule($dbc);
65 67
 	$Translation = new Translation($dbc);
@@ -70,7 +72,9 @@  discard block
 block discarded – undo
70 72
 	    if ($Schedule->checkSchedule($operator) == 0) {
71 73
 		$schedule = $Schedule->fetchSchedule($operator);
72 74
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
73
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
75
+		    if ($globalDebug) {
76
+		    	echo "-> Schedule info for ".$operator." (".$ident.")\n";
77
+		    }
74 78
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
75 79
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
76 80
 		    // Should also check if route schedule = route from DB
@@ -79,7 +83,9 @@  discard block
 block discarded – undo
79 83
 			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
80 84
 			    if (trim($airport_icao) != '') {
81 85
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
82
-				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
86
+				if ($globalDebug) {
87
+					echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
88
+				}
83 89
 			    }
84 90
 			}
85 91
 		    }
@@ -88,17 +94,25 @@  discard block
 block discarded – undo
88 94
 			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
89 95
 			    if (trim($airport_icao) != '') {
90 96
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
91
-				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
97
+				if ($globalDebug) {
98
+					echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
99
+				}
92 100
 			    }
93 101
 			}
94 102
 		    }
95 103
 		    $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
96 104
 		}
97
-	    } else $scheduleexist = true;
98
-	} else $scheduleexist = true;
105
+	    } else {
106
+	    	$scheduleexist = true;
107
+	    }
108
+	} else {
109
+		$scheduleexist = true;
110
+	}
99 111
 	// close connection, at least one way will work ?
100 112
        if ($scheduleexist) {
101
-		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
113
+		if ($globalDebug) {
114
+			echo "-> get arrival/departure airport info for ".$ident."\n";
115
+		}
102 116
     		$sch = $Schedule->getSchedule($operator);
103 117
 		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time']));
104 118
        }
@@ -120,7 +134,9 @@  discard block
 block discarded – undo
120 134
 
121 135
     public function checkAll() {
122 136
 	global $globalDebug, $globalNoImport;
123
-	if ($globalDebug) echo "Update last seen flights data...\n";
137
+	if ($globalDebug) {
138
+		echo "Update last seen flights data...\n";
139
+	}
124 140
 	if (!isset($globalNoImport) || $globalNoImport === FALSE) {
125 141
 	    foreach ($this->all_flights as $key => $flight) {
126 142
 		if (isset($this->all_flights[$key]['id'])) {
@@ -135,24 +151,32 @@  discard block
 block discarded – undo
135 151
 
136 152
     public function arrival($key) {
137 153
 	global $globalClosestMinDist, $globalDebug;
138
-	if ($globalDebug) echo 'Update arrival...'."\n";
154
+	if ($globalDebug) {
155
+		echo 'Update arrival...'."\n";
156
+	}
139 157
 	$Spotter = new Spotter($this->db);
140 158
         $airport_icao = '';
141 159
         $airport_time = '';
142
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
160
+        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') {
161
+        	$globalClosestMinDist = 50;
162
+        }
143 163
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
144 164
 	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
145 165
     	    if (isset($closestAirports[0])) {
146 166
         	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
147 167
         	    $airport_icao = $closestAirports[0]['icao'];
148 168
         	    $airport_time = $this->all_flights[$key]['datetime'];
149
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
169
+        	    if ($globalDebug) {
170
+        	    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
171
+        	    }
150 172
         	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
151 173
         	    foreach ($closestAirports as $airport) {
152 174
         		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
153 175
         		    $airport_icao = $airport['icao'];
154 176
         		    $airport_time = $this->all_flights[$key]['datetime'];
155
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
177
+        		    if ($globalDebug) {
178
+        		    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
179
+        		    }
156 180
         		    break;
157 181
         		}
158 182
         	    }
@@ -160,14 +184,20 @@  discard block
 block discarded – undo
160 184
         		$airport_icao = $closestAirports[0]['icao'];
161 185
         		$airport_time = $this->all_flights[$key]['datetime'];
162 186
         	} else {
163
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
187
+        		if ($globalDebug) {
188
+        			echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
189
+        		}
164 190
         	}
165 191
     	    } else {
166
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
192
+    		    if ($globalDebug) {
193
+    		    	echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
194
+    		    }
167 195
     	    }
168 196
 
169 197
         } else {
170
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
198
+        	if ($globalDebug) {
199
+        		echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
200
+        	}
171 201
         }
172 202
         return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
173 203
     }
@@ -177,12 +207,16 @@  discard block
 block discarded – undo
177 207
     public function del() {
178 208
 	global $globalDebug, $globalNoImport;
179 209
 	// Delete old infos
180
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
210
+	if ($globalDebug) {
211
+		echo 'Delete old values and update latest data...'."\n";
212
+	}
181 213
 	foreach ($this->all_flights as $key => $flight) {
182 214
     	    if (isset($flight['lastupdate'])) {
183 215
         	if ($flight['lastupdate'] < (time()-3000)) {
184 216
             	    if (isset($this->all_flights[$key]['id'])) {
185
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
217
+            		if ($globalDebug) {
218
+            			echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
219
+            		}
186 220
 			/*
187 221
 			$SpotterLive = new SpotterLive();
188 222
             		$SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']);
@@ -193,7 +227,9 @@  discard block
 block discarded – undo
193 227
             		    $Spotter = new Spotter($this->db);
194 228
             	    	    if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
195 229
 				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
196
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
230
+				if ($globalDebug && $result != 'success') {
231
+					echo '!!! ERROR : '.$result."\n";
232
+				}
197 233
 			    }
198 234
 			// Put in archive
199 235
 //				$Spotter->db = null;
@@ -208,8 +244,10 @@  discard block
 block discarded – undo
208 244
     public function add($line) {
209 245
 	global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights, $globalServerAPRS, $APRSSpotter, $globalNoImport;
210 246
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
211
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
212
-/*
247
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
248
+		$globalCoordMinChange = '0.02';
249
+	}
250
+	/*
213 251
 	$Spotter = new Spotter();
214 252
 	$dbc = $Spotter->db;
215 253
 	$SpotterLive = new SpotterLive($dbc);
@@ -237,11 +275,15 @@  discard block
 block discarded – undo
237 275
 		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
238 276
 		    $current_date = date('Y-m-d');
239 277
 		    $source = $line['source_name'];
240
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
278
+		    if ($source == '' || $line['format_source'] == 'aprs') {
279
+		    	$source = $line['format_source'];
280
+		    }
241 281
 		    if (!isset($this->stats[$current_date][$source]['msg'])) {
242 282
 		    	$this->stats[$current_date][$source]['msg']['date'] = time();
243 283
 		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
244
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
284
+		    } else {
285
+		    	$this->stats[$current_date][$source]['msg']['nb'] += 1;
286
+		    }
245 287
 		}
246 288
 		
247 289
 		/*
@@ -257,8 +299,11 @@  discard block
 block discarded – undo
257 299
 		//$this->db = $dbc;
258 300
 
259 301
 		//$hex = trim($line['hex']);
260
-	        if (!isset($line['id'])) $id = trim($line['hex']);
261
-	        else $id = trim($line['id']);
302
+	        if (!isset($line['id'])) {
303
+	        	$id = trim($line['hex']);
304
+	        } else {
305
+	        	$id = trim($line['id']);
306
+	        }
262 307
 		
263 308
 		if (!isset($this->all_flights[$id])) {
264 309
 		    $this->all_flights[$id] = array();
@@ -266,13 +311,21 @@  discard block
 block discarded – undo
266 311
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
267 312
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
268 313
 		    if (!isset($line['id'])) {
269
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
270
-//			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
314
+			if (!isset($globalDaemon)) {
315
+				$globalDaemon = TRUE;
316
+			}
317
+			//			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
271 318
 //			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
272
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
319
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) {
320
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
321
+			}
273 322
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
274
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
275
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
323
+		     } else {
324
+		     	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
325
+		     }
326
+		    if ($globalAllFlights !== FALSE) {
327
+		    	$dataFound = true;
328
+		    }
276 329
 		}
277 330
 		if (isset($line['source_type']) && $line['source_type'] != '') {
278 331
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
@@ -293,11 +346,19 @@  discard block
 block discarded – undo
293 346
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
294 347
 			}
295 348
 			$Spotter->db = null;
296
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
297
-			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
349
+			if ($globalDebugTimeElapsed) {
350
+				echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
351
+			}
352
+			if ($aircraft_icao != '') {
353
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
354
+			}
355
+		    }
356
+		    if ($globalAllFlights !== FALSE) {
357
+		    	$dataFound = true;
358
+		    }
359
+		    if ($globalDebug) {
360
+		    	echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
298 361
 		    }
299
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
300
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
301 362
 		}
302 363
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
303 364
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
@@ -307,14 +368,23 @@  discard block
 block discarded – undo
307 368
 			$Spotter = new Spotter($this->db);
308 369
 			$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
309 370
 			$Spotter->db = null;
310
-			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
371
+			if ($aircraft_icao != '') {
372
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
373
+			}
311 374
 		}
312 375
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) {
313
-			if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
314
-			elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
315
-			elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
316
-			elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
317
-			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
376
+			if ($line['aircraft_type'] == 'PARA_GLIDER') {
377
+				$aircraft_icao = 'GLID';
378
+			} elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') {
379
+				$aircraft_icao = 'UHEL';
380
+			} elseif ($line['aircraft_type'] == 'TOW_PLANE') {
381
+				$aircraft_icao = 'TOWPLANE';
382
+			} elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') {
383
+				$aircraft_icao = 'POWAIRC';
384
+			}
385
+			if (isset($aircraft_icao)) {
386
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
387
+			}
318 388
 		}
319 389
 		if (!isset($this->all_flights[$id]['aircraft_icao'])) {
320 390
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
@@ -324,8 +394,11 @@  discard block
 block discarded – undo
324 394
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
325 395
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
326 396
 		    } else {
327
-				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
328
-				elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
397
+				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
398
+					echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
399
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
400
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
401
+				}
329 402
 				/*
330 403
 				echo strtotime($line['datetime']).' > '.strtotime($this->all_flights[$id]['datetime']);
331 404
 				print_r($this->all_flights[$id]);
@@ -357,15 +430,25 @@  discard block
 block discarded – undo
357 430
 			$timeelapsed = microtime(true);
358 431
             		$Spotter = new Spotter($this->db);
359 432
             		$fromsource = NULL;
360
-            		if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
361
-            		elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
362
-			elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
363
-			elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
364
-			elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
433
+            		if (isset($globalAirlinesSource) && $globalAirlinesSource != '') {
434
+            			$fromsource = $globalAirlinesSource;
435
+            		} elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') {
436
+            			$fromsource = 'vatsim';
437
+            		} elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') {
438
+				$fromsource = 'ivao';
439
+			} elseif (isset($globalVATSIM) && $globalVATSIM) {
440
+				$fromsource = 'vatsim';
441
+			} elseif (isset($globalIVAO) && $globalIVAO) {
442
+				$fromsource = 'ivao';
443
+			}
365 444
             		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
366
-			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
445
+			if ($globalDebug && $result != 'success') {
446
+				echo '!!! ERROR : '.$result."\n";
447
+			}
367 448
 			$Spotter->db = null;
368
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
449
+			if ($globalDebugTimeElapsed) {
450
+				echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
451
+			}
369 452
 		    }
370 453
 
371 454
 /*
@@ -376,7 +459,9 @@  discard block
 block discarded – undo
376 459
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
377 460
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
378 461
   */
379
-		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
462
+		    if (!isset($this->all_flights[$id]['id'])) {
463
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
464
+		    }
380 465
 
381 466
 		    //$putinarchive = true;
382 467
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
@@ -393,7 +478,9 @@  discard block
 block discarded – undo
393 478
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
394 479
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
395 480
 		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
396
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
481
+				if ($globalDebugTimeElapsed) {
482
+					echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
483
+				}
397 484
 
398 485
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
399 486
 			$timeelapsed = microtime(true);
@@ -406,7 +493,9 @@  discard block
 block discarded – undo
406 493
 				$Translation->db = null;
407 494
 			}
408 495
 			$Spotter->db = null;
409
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
496
+			if ($globalDebugTimeElapsed) {
497
+				echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
498
+			}
410 499
 
411 500
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
412 501
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
@@ -415,9 +504,13 @@  discard block
 block discarded – undo
415 504
 		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
416 505
 		    	    }
417 506
 			}
418
-			if (!isset($globalFork)) $globalFork = TRUE;
507
+			if (!isset($globalFork)) {
508
+				$globalFork = TRUE;
509
+			}
419 510
 			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
420
-				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
511
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) {
512
+					$this->get_Schedule($id,trim($line['ident']));
513
+				}
421 514
 			}
422 515
 		    }
423 516
 		}
@@ -433,16 +526,23 @@  discard block
 block discarded – undo
433 526
 		    // use datetime
434 527
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
435 528
 			$speed = $speed*3.6;
436
-			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
437
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
529
+			if ($speed < 1000) {
530
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
531
+			}
532
+  			if ($globalDebug) {
533
+  				echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
534
+  			}
438 535
 		    }
439 536
 		}
440 537
 
441 538
 
442 539
 
443 540
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
444
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
445
-	    	    else unset($timediff);
541
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) {
542
+	    	    	$timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
543
+	    	    } else {
544
+	    	    	unset($timediff);
545
+	    	    }
446 546
 	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
447 547
 			if (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude'])) {
448 548
 			    if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
@@ -451,21 +551,31 @@  discard block
 block discarded – undo
451 551
 				$this->all_flights[$id]['putinarchive'] = true;
452 552
 				$this->tmd = 0;
453 553
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
454
-				    if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
554
+				    if ($globalDebug) {
555
+				    	echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
556
+				    }
455 557
 				    $timeelapsed = microtime(true);
456 558
 				    $Spotter = new Spotter($this->db);
457 559
 				    $all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
458
-				    if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
560
+				    if (!empty($all_country)) {
561
+				    	$this->all_flights[$id]['over_country'] = $all_country['iso2'];
562
+				    }
459 563
 				    $Spotter->db = null;
460
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
461
-				    if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
564
+				    if ($globalDebugTimeElapsed) {
565
+				    	echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
566
+				    }
567
+				    if ($globalDebug) {
568
+				    	echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
569
+				    }
462 570
 				}
463 571
 			    }
464 572
 			}
465 573
 
466 574
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
467 575
 			    //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
468
-				if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
576
+				if (!isset($this->all_flights[$id]['archive_latitude'])) {
577
+					$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
578
+				}
469 579
 				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
470 580
 				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
471 581
 				    $dataFound = true;
@@ -487,9 +597,13 @@  discard block
 block discarded – undo
487 597
 			    */
488 598
 			}
489 599
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
490
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
600
+			    if ($line['longitude'] > 180) {
601
+			    	$line['longitude'] = $line['longitude'] - 360;
602
+			    }
491 603
 			    //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
492
-				if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
604
+				if (!isset($this->all_flights[$id]['archive_longitude'])) {
605
+					$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
606
+				}
493 607
 				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
494 608
 				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
495 609
 				    $dataFound = true;
@@ -520,7 +634,9 @@  discard block
 block discarded – undo
520 634
 		    }
521 635
 		}
522 636
 		if (isset($line['last_update']) && $line['last_update'] != '') {
523
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
637
+		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) {
638
+		    	$dataFound = true;
639
+		    }
524 640
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
525 641
 		}
526 642
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
@@ -542,40 +658,60 @@  discard block
 block discarded – undo
542 658
 			// Here we force archive of flight because after ground it's a new one (or should be)
543 659
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
544 660
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
545
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
546
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
547
-			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
661
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) {
662
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
663
+			} elseif (isset($line['id'])) {
664
+		        	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
665
+		        } elseif (isset($this->all_flights[$id]['ident'])) {
666
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
667
+			}
668
+		    }
669
+		    if ($line['ground'] != 1) {
670
+		    	$line['ground'] = 0;
548 671
 		    }
549
-		    if ($line['ground'] != 1) $line['ground'] = 0;
550 672
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
551 673
 		    //$dataFound = true;
552 674
 		}
553 675
 		if (isset($line['squawk']) && $line['squawk'] != '') {
554 676
 		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
555
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
677
+			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) {
678
+			    	$this->all_flights[$id]['putinarchive'] = true;
679
+			    }
556 680
 			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
557 681
 			    $highlight = '';
558
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
559
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
560
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
682
+			    if ($this->all_flights[$id]['squawk'] == '7500') {
683
+			    	$highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
684
+			    }
685
+			    if ($this->all_flights[$id]['squawk'] == '7600') {
686
+			    	$highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
687
+			    }
688
+			    if ($this->all_flights[$id]['squawk'] == '7700') {
689
+			    	$highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
690
+			    }
561 691
 			    if ($highlight != '') {
562 692
 				$timeelapsed = microtime(true);
563 693
 				$Spotter = new Spotter($this->db);
564 694
 				$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
565 695
 				$Spotter->db = null;
566
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
696
+				if ($globalDebugTimeElapsed) {
697
+					echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
698
+				}
567 699
 
568 700
 				//$putinarchive = true;
569 701
 				//$highlight = '';
570 702
 			    }
571 703
 			    
572
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
704
+		    } else {
705
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
706
+		    }
573 707
 		    //$dataFound = true;
574 708
 		}
575 709
 
576 710
 		if (isset($line['altitude']) && $line['altitude'] != '') {
577 711
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
578
-			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;
712
+			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) {
713
+				$this->all_flights[$id]['putinarchive'] = true;
714
+			}
579 715
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
580 716
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
581 717
 			//$dataFound = true;
@@ -587,21 +723,30 @@  discard block
 block discarded – undo
587 723
 		}
588 724
 		
589 725
 		if (isset($line['heading']) && $line['heading'] != '') {
590
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
726
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) {
727
+		    	$this->all_flights[$id]['putinarchive'] = true;
728
+		    }
591 729
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
592 730
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
593 731
 		    //$dataFound = true;
594 732
   		} elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) {
595 733
   		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
596 734
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
597
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
598
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
735
+		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) {
736
+		    	$this->all_flights[$id]['putinarchive'] = true;
737
+		    }
738
+  		    if ($globalDebug) {
739
+  		    	echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
740
+  		    }
599 741
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
600 742
   		    // If not enough messages and ACARS set heading to 0
601 743
   		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
602 744
   		}
603
-		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
604
-		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
745
+		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) {
746
+			$dataFound = false;
747
+		} elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) {
748
+			$dataFound = false;
749
+		}
605 750
 
606 751
 //		print_r($this->all_flights[$id]);
607 752
 		//gets the callsign from the last hour
@@ -616,23 +761,36 @@  discard block
 block discarded – undo
616 761
 			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
617 762
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
618 763
 			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
619
-				if ($globalDebug) echo "Check if aircraft is already in DB...";
764
+				if ($globalDebug) {
765
+					echo "Check if aircraft is already in DB...";
766
+				}
620 767
 				$timeelapsed = microtime(true);
621 768
 				$SpotterLive = new SpotterLive($this->db);
622 769
 				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) {
623 770
 				    $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
624
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
771
+				    if ($globalDebugTimeElapsed) {
772
+				    	echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
773
+				    }
625 774
 				} elseif (isset($line['id'])) {
626 775
 				    $recent_ident = $SpotterLive->checkIdRecent($line['id']);
627
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
776
+				    if ($globalDebugTimeElapsed) {
777
+				    	echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
778
+				    }
628 779
 				} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
629 780
 				    $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
630
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
631
-				} else $recent_ident = '';
781
+				    if ($globalDebugTimeElapsed) {
782
+				    	echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
783
+				    }
784
+				} else {
785
+					$recent_ident = '';
786
+				}
632 787
 				$SpotterLive->db=null;
633 788
 
634
-				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
635
-				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
789
+				if ($globalDebug && $recent_ident == '') {
790
+					echo " Not in DB.\n";
791
+				} elseif ($globalDebug && $recent_ident != '') {
792
+					echo " Already in DB.\n";
793
+				}
636 794
 			    } else {
637 795
 				$recent_ident = '';
638 796
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
@@ -640,7 +798,9 @@  discard block
 block discarded – undo
640 798
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
641 799
 			    if($recent_ident == "")
642 800
 			    {
643
-				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
801
+				if ($globalDebug) {
802
+					echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
803
+				}
644 804
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
645 805
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
646 806
 				//adds the spotter data for the archive
@@ -684,28 +844,46 @@  discard block
 block discarded – undo
684 844
 				
685 845
 				if (!$ignoreImport) {
686 846
 				    $highlight = '';
687
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
688
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
689
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
690
-				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
847
+				    if ($this->all_flights[$id]['squawk'] == '7500') {
848
+				    	$highlight = 'Squawk 7500 : Hijack';
849
+				    }
850
+				    if ($this->all_flights[$id]['squawk'] == '7600') {
851
+				    	$highlight = 'Squawk 7600 : Lost Comm (radio failure)';
852
+				    }
853
+				    if ($this->all_flights[$id]['squawk'] == '7700') {
854
+				    	$highlight = 'Squawk 7700 : Emergency';
855
+				    }
856
+				    if (!isset($this->all_flights[$id]['id'])) {
857
+				    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
858
+				    }
691 859
 				    $timeelapsed = microtime(true);
692 860
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
693 861
 					$Spotter = new Spotter($this->db);
694 862
 					$result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']);
695 863
 					$Spotter->db = null;
696
-					if ($globalDebug && isset($result)) echo $result."\n";
864
+					if ($globalDebug && isset($result)) {
865
+						echo $result."\n";
866
+					}
867
+				    }
868
+				    if ($globalDebugTimeElapsed) {
869
+				    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
697 870
 				    }
698
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
699 871
 				    
700 872
 				    // Add source stat in DB
701 873
 				    $Stats = new Stats($this->db);
702 874
 				    if (!empty($this->stats)) {
703
-					if ($globalDebug) echo 'Add source stats : ';
875
+					if ($globalDebug) {
876
+						echo 'Add source stats : ';
877
+					}
704 878
 				        foreach($this->stats as $date => $data) {
705 879
 					    foreach($data as $source => $sourced) {
706 880
 					        //print_r($sourced);
707
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
708
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
881
+				    	        if (isset($sourced['polar'])) {
882
+				    	        	echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
883
+				    	        }
884
+				    	        if (isset($sourced['hist'])) {
885
+				    	        	echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
886
+				    	        }
709 887
 				    		if (isset($sourced['msg'])) {
710 888
 				    		    if (time() - $sourced['msg']['date'] > 10) {
711 889
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
@@ -718,13 +896,17 @@  discard block
 block discarded – undo
718 896
 			    			unset($this->stats[$date]);
719 897
 			    		    }
720 898
 				    	}
721
-				    	if ($globalDebug) echo 'Done'."\n";
899
+				    	if ($globalDebug) {
900
+				    		echo 'Done'."\n";
901
+				    	}
722 902
 
723 903
 				    }
724 904
 				    $Stats->db = null;
725 905
 				    
726 906
 				    $this->del();
727
-				} elseif ($globalDebug) echo 'Ignore data'."\n";
907
+				} elseif ($globalDebug) {
908
+					echo 'Ignore data'."\n";
909
+				}
728 910
 				//$ignoreImport = false;
729 911
 				$this->all_flights[$id]['addedSpotter'] = 1;
730 912
 				//print_r($this->all_flights[$id]);
@@ -741,14 +923,18 @@  discard block
 block discarded – undo
741 923
 			*/
742 924
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
743 925
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
744
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
926
+				    if ($globalDebug) {
927
+				    	echo "---- Deleting Live Spotter data older than 9 hours...";
928
+				    }
745 929
 				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
746 930
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
747 931
 					$SpotterLive = new SpotterLive($this->db);
748 932
 					$SpotterLive->deleteLiveSpotterData();
749 933
 					$SpotterLive->db=null;
750 934
 				    }
751
-				    if ($globalDebug) echo " Done\n";
935
+				    if ($globalDebug) {
936
+				    	echo " Done\n";
937
+				    }
752 938
 				    $this->last_delete = time();
753 939
 				}
754 940
 			    } else {
@@ -773,11 +959,17 @@  discard block
 block discarded – undo
773 959
 		    //echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n";
774 960
 		    if ($globalDebug) {
775 961
 			if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
776
-				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";
777
-				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
962
+				if (isset($this->all_flights[$id]['source_name'])) {
963
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";
964
+				} else {
965
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
966
+				}
778 967
 			} else {
779
-				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";
780
-				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";
968
+				if (isset($this->all_flights[$id]['source_name'])) {
969
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";
970
+				} else {
971
+					echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";
972
+				}
781 973
 			}
782 974
 		    }
783 975
 		    $ignoreImport = false;
@@ -825,24 +1017,32 @@  discard block
 block discarded – undo
825 1017
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
826 1018
 				$timeelapsed = microtime(true);
827 1019
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
828
-					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1020
+					if ($globalDebug) {
1021
+						echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1022
+					}
829 1023
 					$SpotterLive = new SpotterLive($this->db);
830 1024
 					$result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
831 1025
 					$SpotterLive->db = null;
832
-					if ($globalDebug) echo $result."\n";
1026
+					if ($globalDebug) {
1027
+						echo $result."\n";
1028
+					}
833 1029
 				}
834 1030
 				if (isset($globalServerAPRS) && $globalServerAPRS) {
835 1031
 					$APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
836 1032
 				}
837 1033
 				$this->all_flights[$id]['putinarchive'] = false;
838
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1034
+				if ($globalDebugTimeElapsed) {
1035
+					echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1036
+				}
839 1037
 
840 1038
 				// Put statistics in $this->stats variable
841 1039
 				//if ($line['format_source'] != 'aprs') {
842 1040
 				//if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt')) {
843 1041
 				if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
844 1042
 					$source = $this->all_flights[$id]['source_name'];
845
-					if ($source == '') $source = $this->all_flights[$id]['format_source'];
1043
+					if ($source == '') {
1044
+						$source = $this->all_flights[$id]['format_source'];
1045
+					}
846 1046
 					if (!isset($this->source_location[$source])) {
847 1047
 						$Location = new Source();
848 1048
 						$coord = $Location->getLocationInfobySourceName($source);
@@ -863,7 +1063,9 @@  discard block
 block discarded – undo
863 1063
 					$stats_heading = round($stats_heading/22.5);
864 1064
 					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
865 1065
 					$current_date = date('Y-m-d');
866
-					if ($stats_heading == 16) $stats_heading = 0;
1066
+					if ($stats_heading == 16) {
1067
+						$stats_heading = 0;
1068
+					}
867 1069
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
868 1070
 						for ($i=0;$i<=15;$i++) {
869 1071
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
@@ -881,7 +1083,9 @@  discard block
 block discarded – undo
881 1083
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
882 1084
 						    end($this->stats[$current_date][$source]['hist']);
883 1085
 						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
884
-						} else $mini = 0;
1086
+						} else {
1087
+							$mini = 0;
1088
+						}
885 1089
 						for ($i=$mini;$i<=$distance;$i+=10) {
886 1090
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
887 1091
 						}
@@ -892,19 +1096,27 @@  discard block
 block discarded – undo
892 1096
 				}
893 1097
 
894 1098
 				$this->all_flights[$id]['lastupdate'] = time();
895
-				if ($this->all_flights[$id]['putinarchive']) $send = true;
1099
+				if ($this->all_flights[$id]['putinarchive']) {
1100
+					$send = true;
1101
+				}
896 1102
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
897
-			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1103
+			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
1104
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1105
+			}
898 1106
 			//$this->del();
899 1107
 			
900 1108
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
901 1109
 			    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
902
-				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1110
+				if ($globalDebug) {
1111
+					echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1112
+				}
903 1113
 				$SpotterLive = new SpotterLive($this->db);
904 1114
 				$SpotterLive->deleteLiveSpotterDataNotUpdated();
905 1115
 				$SpotterLive->db = null;
906 1116
 				//SpotterLive->deleteLiveSpotterData();
907
-				if ($globalDebug) echo " Done\n";
1117
+				if ($globalDebug) {
1118
+					echo " Done\n";
1119
+				}
908 1120
 				$this->last_delete_hourly = time();
909 1121
 			    } else {
910 1122
 				$this->del();
@@ -916,7 +1128,9 @@  discard block
 block discarded – undo
916 1128
 		    //$ignoreImport = false;
917 1129
 		}
918 1130
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
919
-		if ($send) return $this->all_flights[$id];
1131
+		if ($send) {
1132
+			return $this->all_flights[$id];
1133
+		}
920 1134
 	    }
921 1135
 	}
922 1136
     }
Please login to merge, or discard this patch.
scripts/daemon-spotter.php 1 patch
Braces   +719 added lines, -248 removed lines patch added patch discarded remove patch
@@ -13,13 +13,17 @@  discard block
 block discarded – undo
13 13
 require_once(dirname(__FILE__).'/../require/class.SBS.php');
14 14
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
15 15
 require_once(dirname(__FILE__).'/../require/class.Common.php');
16
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
16
+if (isset($globalTracker) && $globalTracker) {
17
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
18
+}
17 19
 if (isset($globalMarine) && $globalMarine) {
18 20
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
19 21
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
20 22
 }
21 23
 
22
-if (!isset($globalDebug)) $globalDebug = FALSE;
24
+if (!isset($globalDebug)) {
25
+	$globalDebug = FALSE;
26
+}
23 27
 
24 28
 // Check if schema is at latest version
25 29
 $Connection = new Connection();
@@ -59,19 +63,30 @@  discard block
 block discarded – undo
59 63
     $globalSources = array();
60 64
     $globalSources[] = array('host' => $options['source']);
61 65
 }
62
-if (isset($options['server'])) $globalServer = TRUE;
63
-if (isset($options['idsource'])) $id_source = $options['idsource'];
64
-else $id_source = 1;
66
+if (isset($options['server'])) {
67
+	$globalServer = TRUE;
68
+}
69
+if (isset($options['idsource'])) {
70
+	$id_source = $options['idsource'];
71
+} else {
72
+	$id_source = 1;
73
+}
65 74
 if (isset($globalServer) && $globalServer) {
66
-    if ($globalDebug) echo "Using Server Mode\n";
75
+    if ($globalDebug) {
76
+    	echo "Using Server Mode\n";
77
+    }
67 78
     $SI=new SpotterServer();
68 79
 /*
69 80
     require_once(dirname(__FILE__).'/../require/class.APRS.php');
70 81
     $SI = new adsb2aprs();
71 82
     $SI->connect();
72 83
 */
73
-} else $SI=new SpotterImport($Connection->db);
74
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
84
+} else {
85
+	$SI=new SpotterImport($Connection->db);
86
+}
87
+if (isset($globalTracker) && $globalTracker) {
88
+	$TI = new TrackerImport($Connection->db);
89
+}
75 90
 if (isset($globalMarine) && $globalMarine) {
76 91
     $AIS = new AIS();
77 92
     $MI = new MarineImport($Connection->db);
@@ -93,7 +108,9 @@  discard block
 block discarded – undo
93 108
 }
94 109
 
95 110
 // let's try and connect
96
-if ($globalDebug) echo "Connecting...\n";
111
+if ($globalDebug) {
112
+	echo "Connecting...\n";
113
+}
97 114
 $use_aprs = false;
98 115
 $aprs_full = false;
99 116
 $reset = 0;
@@ -102,7 +119,9 @@  discard block
 block discarded – undo
102 119
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
103 120
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
104 121
     $reset++;
105
-    if ($globalDebug) echo 'Connect to all...'."\n";
122
+    if ($globalDebug) {
123
+    	echo 'Connect to all...'."\n";
124
+    }
106 125
     foreach ($hosts as $id => $value) {
107 126
 	$host = $value['host'];
108 127
 	$globalSources[$id]['last_exec'] = 0;
@@ -112,27 +131,37 @@  discard block
 block discarded – undo
112 131
         	//$formats[$id] = 'deltadbtxt';
113 132
         	$globalSources[$id]['format'] = 'deltadbtxt';
114 133
         	//$last_exec['deltadbtxt'] = 0;
115
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
134
+        	if ($globalDebug) {
135
+        		echo "Connect to deltadb source (".$host.")...\n";
136
+        	}
116 137
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
117 138
         	//$formats[$id] = 'vatsimtxt';
118 139
         	$globalSources[$id]['format'] = 'vatsimtxt';
119 140
         	//$last_exec['vatsimtxt'] = 0;
120
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
141
+        	if ($globalDebug) {
142
+        		echo "Connect to vatsim source (".$host.")...\n";
143
+        	}
121 144
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
122 145
         	//$formats[$id] = 'aircraftlistjson';
123 146
         	$globalSources[$id]['format'] = 'aircraftlistjson';
124 147
         	//$last_exec['aircraftlistjson'] = 0;
125
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
148
+        	if ($globalDebug) {
149
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
150
+        	}
126 151
     	    } else if (preg_match('/opensky/i',$host)) {
127 152
         	//$formats[$id] = 'aircraftlistjson';
128 153
         	$globalSources[$id]['format'] = 'opensky';
129 154
         	//$last_exec['aircraftlistjson'] = 0;
130
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
155
+        	if ($globalDebug) {
156
+        		echo "Connect to opensky source (".$host.")...\n";
157
+        	}
131 158
     	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
132 159
         	//$formats[$id] = 'radarvirtueljson';
133 160
         	$globalSources[$id]['format'] = 'radarvirtueljson';
134 161
         	//$last_exec['radarvirtueljson'] = 0;
135
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
162
+        	if ($globalDebug) {
163
+        		echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
164
+        	}
136 165
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
137 166
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
138 167
         	    exit(0);
@@ -141,7 +170,9 @@  discard block
 block discarded – undo
141 170
         	//$formats[$id] = 'planeupdatefaa';
142 171
         	$globalSources[$id]['format'] = 'planeupdatefaa';
143 172
         	//$last_exec['planeupdatefaa'] = 0;
144
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
173
+        	if ($globalDebug) {
174
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
175
+        	}
145 176
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
146 177
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
147 178
         	    exit(0);
@@ -150,26 +181,36 @@  discard block
 block discarded – undo
150 181
         	//$formats[$id] = 'phpvmacars';
151 182
         	$globalSources[$id]['format'] = 'phpvmacars';
152 183
         	//$last_exec['phpvmacars'] = 0;
153
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
184
+        	if ($globalDebug) {
185
+        		echo "Connect to phpvmacars source (".$host.")...\n";
186
+        	}
154 187
             } else if (preg_match('/VAM-json.php$/i',$host)) {
155 188
         	//$formats[$id] = 'phpvmacars';
156 189
         	$globalSources[$id]['format'] = 'vam';
157
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
190
+        	if ($globalDebug) {
191
+        		echo "Connect to Vam source (".$host.")...\n";
192
+        	}
158 193
             } else if (preg_match('/whazzup/i',$host)) {
159 194
         	//$formats[$id] = 'whazzup';
160 195
         	$globalSources[$id]['format'] = 'whazzup';
161 196
         	//$last_exec['whazzup'] = 0;
162
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
197
+        	if ($globalDebug) {
198
+        		echo "Connect to whazzup source (".$host.")...\n";
199
+        	}
163 200
             } else if (preg_match('/recentpireps/i',$host)) {
164 201
         	//$formats[$id] = 'pirepsjson';
165 202
         	$globalSources[$id]['format'] = 'pirepsjson';
166 203
         	//$last_exec['pirepsjson'] = 0;
167
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
204
+        	if ($globalDebug) {
205
+        		echo "Connect to pirepsjson source (".$host.")...\n";
206
+        	}
168 207
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
169 208
         	//$formats[$id] = 'fr24json';
170 209
         	$globalSources[$id]['format'] = 'fr24json';
171 210
         	//$last_exec['fr24json'] = 0;
172
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
211
+        	if ($globalDebug) {
212
+        		echo "Connect to fr24 source (".$host.")...\n";
213
+        	}
173 214
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
174 215
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
175 216
         	    exit(0);
@@ -178,7 +219,9 @@  discard block
 block discarded – undo
178 219
         	//$formats[$id] = 'fr24json';
179 220
         	$globalSources[$id]['format'] = 'myshiptracking';
180 221
         	//$last_exec['fr24json'] = 0;
181
-        	if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n";
222
+        	if ($globalDebug) {
223
+        		echo "Connect to myshiptracking source (".$host.")...\n";
224
+        	}
182 225
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
183 226
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
184 227
         	    exit(0);
@@ -187,17 +230,24 @@  discard block
 block discarded – undo
187 230
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
188 231
         	//$formats[$id] = 'tsv';
189 232
         	$globalSources[$id]['format'] = 'tsv';
190
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
233
+        	if ($globalDebug) {
234
+        		echo "Connect to tsv source (".$host.")...\n";
235
+        	}
191 236
             }
192 237
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
193 238
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
194 239
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
195 240
     		    if ($idf !== false) {
196 241
     			$httpfeeds[$id] = $idf;
197
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
242
+        		if ($globalDebug) {
243
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
244
+        		}
245
+    		    } elseif ($globalDebug) {
246
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
198 247
     		    }
199
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
200
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
248
+    		} elseif ($globalDebug) {
249
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
250
+    		}
201 251
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
202 252
 	    $hostport = explode(':',$host);
203 253
 	    if (isset($hostport[1])) {
@@ -235,17 +285,25 @@  discard block
 block discarded – undo
235 285
         		//$formats[$id] = 'beast';
236 286
         		$globalSources[$id]['format'] = 'beast';
237 287
 		    //} else $formats[$id] = 'sbs';
238
-		    } else $globalSources[$id]['format'] = 'sbs';
288
+		    } else {
289
+		    	$globalSources[$id]['format'] = 'sbs';
290
+		    }
239 291
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
240 292
 		}
241
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
293
+		if ($globalDebug) {
294
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
295
+		}
242 296
             } else {
243
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
297
+		if ($globalDebug) {
298
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
299
+		}
244 300
     	    }
245 301
         }
246 302
     }
247 303
 }
248
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
304
+if (!isset($globalMinFetch)) {
305
+	$globalMinFetch = 15;
306
+}
249 307
 
250 308
 // Initialize all
251 309
 $status = array();
@@ -254,13 +312,19 @@  discard block
 block discarded – undo
254 312
 $formats = array();
255 313
 $last_exec = array();
256 314
 $time = time();
257
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
258
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
259
-else $timeout = 20;
315
+if (isset($globalSourcesTimeout)) {
316
+	$timeout = $globalSourcesTimeOut;
317
+} else if (isset($globalSBS1TimeOut)) {
318
+	$timeout = $globalSBS1TimeOut;
319
+} else {
320
+	$timeout = 20;
321
+}
260 322
 $errno = '';
261 323
 $errstr='';
262 324
 
263
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
325
+if (!isset($globalDaemon)) {
326
+	$globalDaemon = TRUE;
327
+}
264 328
 /* Initiate connections to all the hosts simultaneously */
265 329
 //connect_all($hosts);
266 330
 //connect_all($globalSources);
@@ -286,7 +350,9 @@  discard block
 block discarded – undo
286 350
     if (isset($source['format']) && $source['format'] == 'aprs') {
287 351
 	$aprs_connect = 0;
288 352
 	$use_aprs = true;
289
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
353
+	if (isset($source['port']) && $source['port'] == '10152') {
354
+		$aprs_full = true;
355
+	}
290 356
 	break;
291 357
     }
292 358
 }
@@ -297,26 +363,49 @@  discard block
 block discarded – undo
297 363
 	$aprs_connect = 0;
298 364
 	$aprs_keep = 120;
299 365
 	$aprs_last_tx = time();
300
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
301
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
302
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
303
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
304
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
305
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
306
-	if ($aprs_full) $aprs_filter = '';
307
-	if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass;
308
-	else $aprs_pass = '-1';
366
+	if (isset($globalAPRSversion)) {
367
+		$aprs_version = $globalAPRSversion;
368
+	} else {
369
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
370
+	}
371
+	if (isset($globalAPRSssid)) {
372
+		$aprs_ssid = $globalAPRSssid;
373
+	} else {
374
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
375
+	}
376
+	if (isset($globalAPRSfilter)) {
377
+		$aprs_filter = $globalAPRSfilter;
378
+	} else {
379
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
380
+	}
381
+	if ($aprs_full) {
382
+		$aprs_filter = '';
383
+	}
384
+	if (isset($globalAPRSpass)) {
385
+		$aprs_pass = $globalAPRSpass;
386
+	} else {
387
+		$aprs_pass = '-1';
388
+	}
309 389
 
310
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
311
-	else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
390
+	if ($aprs_filter != '') {
391
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n";
392
+	} else {
393
+		$aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n";
394
+	}
312 395
 	echo $aprs_login."\n";
313 396
 }
314 397
 
315 398
 // connected - lets do some work
316
-if ($globalDebug) echo "Connected!\n";
399
+if ($globalDebug) {
400
+	echo "Connected!\n";
401
+}
317 402
 sleep(1);
318
-if ($globalDebug) echo "SCAN MODE \n\n";
319
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
403
+if ($globalDebug) {
404
+	echo "SCAN MODE \n\n";
405
+}
406
+if (!isset($globalCronEnd)) {
407
+	$globalCronEnd = 60;
408
+}
320 409
 $endtime = time()+$globalCronEnd;
321 410
 $i = 1;
322 411
 $tt = array();
@@ -330,10 +419,14 @@  discard block
 block discarded – undo
330 419
 
331 420
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
332 421
 while ($i > 0) {
333
-    if (!$globalDaemon) $i = $endtime-time();
422
+    if (!$globalDaemon) {
423
+    	$i = $endtime-time();
424
+    }
334 425
     // Delete old ATC
335 426
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
336
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
427
+	if ($globalDebug) {
428
+		echo 'Delete old ATC...'."\n";
429
+	}
337 430
         $ATC->deleteOldATC();
338 431
     }
339 432
     
@@ -341,10 +434,14 @@  discard block
 block discarded – undo
341 434
     if (count($last_exec) == count($globalSources)) {
342 435
 	$max = $globalMinFetch;
343 436
 	foreach ($last_exec as $last) {
344
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
437
+	    if ((time() - $last['last']) < $max) {
438
+	    	$max = time() - $last['last'];
439
+	    }
345 440
 	}
346 441
 	if ($max != $globalMinFetch) {
347
-	    if ($globalDebug) echo 'Sleeping...'."\n";
442
+	    if ($globalDebug) {
443
+	    	echo 'Sleeping...'."\n";
444
+	    }
348 445
 	    sleep($globalMinFetch-$max+2);
349 446
 	}
350 447
     }
@@ -353,11 +450,15 @@  discard block
 block discarded – undo
353 450
     //foreach ($formats as $id => $value) {
354 451
     foreach ($globalSources as $id => $value) {
355 452
 	date_default_timezone_set('UTC');
356
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
453
+	if (!isset($last_exec[$id]['last'])) {
454
+		$last_exec[$id]['last'] = 0;
455
+	}
357 456
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
358 457
 	    //$buffer = $Common->getData($hosts[$id]);
359 458
 	    $buffer = $Common->getData($value['host']);
360
-	    if ($buffer != '') $reset = 0;
459
+	    if ($buffer != '') {
460
+	    	$reset = 0;
461
+	    }
361 462
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
362 463
 	    $buffer = explode('\n',$buffer);
363 464
 	    foreach ($buffer as $line) {
@@ -366,19 +467,38 @@  discard block
 block discarded – undo
366 467
 	            $data = array();
367 468
 	            $data['hex'] = $line[1]; // hex
368 469
 	            $data['ident'] = $line[2]; // ident
369
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
370
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
371
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
372
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
373
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
470
+	            if (isset($line[3])) {
471
+	            	$data['altitude'] = $line[3];
472
+	            }
473
+	            // altitude
474
+	            if (isset($line[4])) {
475
+	            	$data['speed'] = $line[4];
476
+	            }
477
+	            // speed
478
+	            if (isset($line[5])) {
479
+	            	$data['heading'] = $line[5];
480
+	            }
481
+	            // heading
482
+	            if (isset($line[6])) {
483
+	            	$data['latitude'] = $line[6];
484
+	            }
485
+	            // lat
486
+	            if (isset($line[7])) {
487
+	            	$data['longitude'] = $line[7];
488
+	            }
489
+	            // long
374 490
 	            $data['verticalrate'] = ''; // vertical rate
375 491
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
376 492
 	            $data['emergency'] = ''; // emergency
377 493
 		    $data['datetime'] = date('Y-m-d H:i:s');
378 494
 		    $data['format_source'] = 'deltadbtxt';
379 495
     		    $data['id_source'] = $id_source;
380
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
381
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
496
+		    if (isset($value['name']) && $value['name'] != '') {
497
+		    	$data['source_name'] = $value['name'];
498
+		    }
499
+		    if (isset($value['sourcestats'])) {
500
+		    	$data['sourcestats'] = $value['sourcestats'];
501
+		    }
382 502
     		    $SI->add($data);
383 503
 		    unset($data);
384 504
     		}
@@ -388,7 +508,9 @@  discard block
 block discarded – undo
388 508
 	    date_default_timezone_set('CET');
389 509
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
390 510
 	    date_default_timezone_set('UTC');
391
-	    if ($buffer != '') $reset = 0;
511
+	    if ($buffer != '') {
512
+	    	$reset = 0;
513
+	    }
392 514
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
393 515
 	    $buffer = explode('\n',$buffer);
394 516
 	    foreach ($buffer as $line) {
@@ -397,16 +519,36 @@  discard block
 block discarded – undo
397 519
 		    $add = false;
398 520
 		    $ais_data = $AIS->parse_line(trim($line));
399 521
 		    $data = array();
400
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
401
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
402
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
403
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
404
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
405
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
406
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
407
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
408
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
409
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
522
+		    if (isset($ais_data['ident'])) {
523
+		    	$data['ident'] = $ais_data['ident'];
524
+		    }
525
+		    if (isset($ais_data['mmsi'])) {
526
+		    	$data['mmsi'] = $ais_data['mmsi'];
527
+		    }
528
+		    if (isset($ais_data['speed'])) {
529
+		    	$data['speed'] = $ais_data['speed'];
530
+		    }
531
+		    if (isset($ais_data['heading'])) {
532
+		    	$data['heading'] = $ais_data['heading'];
533
+		    }
534
+		    if (isset($ais_data['latitude'])) {
535
+		    	$data['latitude'] = $ais_data['latitude'];
536
+		    }
537
+		    if (isset($ais_data['longitude'])) {
538
+		    	$data['longitude'] = $ais_data['longitude'];
539
+		    }
540
+		    if (isset($ais_data['status'])) {
541
+		    	$data['status'] = $ais_data['status'];
542
+		    }
543
+		    if (isset($ais_data['type'])) {
544
+		    	$data['type'] = $ais_data['type'];
545
+		    }
546
+		    if (isset($ais_data['imo'])) {
547
+		    	$data['imo'] = $ais_data['imo'];
548
+		    }
549
+		    if (isset($ais_data['callsign'])) {
550
+		    	$data['callsign'] = $ais_data['callsign'];
551
+		    }
410 552
 		    if (isset($ais_data['timestamp'])) {
411 553
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
412 554
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -421,7 +563,9 @@  discard block
 block discarded – undo
421 563
     		    $data['id_source'] = $id_source;
422 564
 		    print_r($data);
423 565
 		    echo 'Add...'."\n";
424
-		    if ($add && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
566
+		    if ($add && $ais_data['mmsi_type'] == 'Ship') {
567
+		    	$MI->add($data);
568
+		    }
425 569
 		    unset($data);
426 570
 		}
427 571
     	    }
@@ -441,18 +585,42 @@  discard block
 block discarded – undo
441 585
 			if ($line != '') {
442 586
 			    $ais_data = $AIS->parse_line(trim($line));
443 587
 			    $data = array();
444
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
445
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
446
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
447
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
448
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
449
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
450
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
451
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
452
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
453
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
454
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
455
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
588
+			    if (isset($ais_data['ident'])) {
589
+			    	$data['ident'] = $ais_data['ident'];
590
+			    }
591
+			    if (isset($ais_data['mmsi'])) {
592
+			    	$data['mmsi'] = $ais_data['mmsi'];
593
+			    }
594
+			    if (isset($ais_data['speed'])) {
595
+			    	$data['speed'] = $ais_data['speed'];
596
+			    }
597
+			    if (isset($ais_data['heading'])) {
598
+			    	$data['heading'] = $ais_data['heading'];
599
+			    }
600
+			    if (isset($ais_data['latitude'])) {
601
+			    	$data['latitude'] = $ais_data['latitude'];
602
+			    }
603
+			    if (isset($ais_data['longitude'])) {
604
+			    	$data['longitude'] = $ais_data['longitude'];
605
+			    }
606
+			    if (isset($ais_data['status'])) {
607
+			    	$data['status'] = $ais_data['status'];
608
+			    }
609
+			    if (isset($ais_data['type'])) {
610
+			    	$data['type'] = $ais_data['type'];
611
+			    }
612
+			    if (isset($ais_data['imo'])) {
613
+			    	$data['imo'] = $ais_data['imo'];
614
+			    }
615
+			    if (isset($ais_data['callsign'])) {
616
+			    	$data['callsign'] = $ais_data['callsign'];
617
+			    }
618
+			    if (isset($ais_data['destination'])) {
619
+			    	$data['arrival_code'] = $ais_data['destination'];
620
+			    }
621
+			    if (isset($ais_data['eta_ts'])) {
622
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
623
+			    }
456 624
 			    if (isset($ais_data['timestamp'])) {
457 625
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
458 626
 			    } else {
@@ -460,7 +628,9 @@  discard block
 block discarded – undo
460 628
 			    }
461 629
 			    $data['format_source'] = 'aisnmeahttp';
462 630
 			    $data['id_source'] = $id_source;
463
-			    if ($ais_data['mmsi_type'] == 'Ship') $MI->add($data);
631
+			    if ($ais_data['mmsi_type'] == 'Ship') {
632
+			    	$MI->add($data);
633
+			    }
464 634
 			    unset($data);
465 635
 			}
466 636
 		    }
@@ -509,7 +679,9 @@  discard block
 block discarded – undo
509 679
 			    $data['callsign'] = $line['callsign'];
510 680
 			    $data['mmsi'] = $line['mmsi'];
511 681
 			    $data['speed'] = $line['sog'];
512
-			    if ($line['heading'] != '511') $data['heading'] = $line['heading'];
682
+			    if ($line['heading'] != '511') {
683
+			    	$data['heading'] = $line['heading'];
684
+			    }
513 685
 			    $data['latitude'] = $line['latitude'];
514 686
 			    $data['longitude'] = $line['longitude'];
515 687
 			    $data['type_id'] = $line['shiptype'];
@@ -529,7 +701,9 @@  discard block
 block discarded – undo
529 701
 	    echo 'download...';
530 702
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
531 703
 	    echo 'done !'."\n";
532
-	    if ($buffer != '') $reset = 0;
704
+	    if ($buffer != '') {
705
+	    	$reset = 0;
706
+	    }
533 707
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
534 708
 	    $buffer = explode('\n',$buffer);
535 709
 	    foreach ($buffer as $line) {
@@ -573,16 +747,28 @@  discard block
 block discarded – undo
573 747
     		    $line = explode(':', $line);
574 748
     		    if (count($line) > 30 && $line[0] != 'callsign') {
575 749
 			$data = array();
576
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
577
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
750
+			if (isset($line[37]) && $line[37] != '') {
751
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
752
+			} else {
753
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
754
+			}
578 755
 			$data['pilot_id'] = $line[1];
579 756
 			$data['pilot_name'] = $line[2];
580 757
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
581 758
 			$data['ident'] = $line[0]; // ident
582
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
759
+			if ($line[7] != '' && $line[7] != 0) {
760
+				$data['altitude'] = $line[7];
761
+			}
762
+			// altitude
583 763
 			$data['speed'] = $line[8]; // speed
584
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
585
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
764
+			if (isset($line[45])) {
765
+				$data['heading'] = $line[45];
766
+			}
767
+			// heading
768
+			elseif (isset($line[38])) {
769
+				$data['heading'] = $line[38];
770
+			}
771
+			// heading
586 772
 			$data['latitude'] = $line[5]; // lat
587 773
 	        	$data['longitude'] = $line[6]; // long
588 774
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -598,7 +784,9 @@  discard block
 block discarded – undo
598 784
 			$data['frequency'] = $line[4];
599 785
 			$data['type'] = $line[18];
600 786
 			$data['range'] = $line[19];
601
-			if (isset($line[35])) $data['info'] = $line[35];
787
+			if (isset($line[35])) {
788
+				$data['info'] = $line[35];
789
+			}
602 790
     			$data['id_source'] = $id_source;
603 791
 	    		//$data['arrival_airport_time'] = ;
604 792
 	    		if ($line[9] != '') {
@@ -612,24 +800,41 @@  discard block
 block discarded – undo
612 800
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
613 801
 	    		*/
614 802
 	    		$data['format_source'] = $value['format'];
615
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
616
-    			if ($line[3] == 'PILOT') $SI->add($data);
617
-			elseif ($line[3] == 'ATC') {
803
+			if (isset($value['name']) && $value['name'] != '') {
804
+				$data['source_name'] = $value['name'];
805
+			}
806
+    			if ($line[3] == 'PILOT') {
807
+    				$SI->add($data);
808
+    			} elseif ($line[3] == 'ATC') {
618 809
 				//print_r($data);
619 810
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
620 811
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
621 812
 				$typec = substr($data['ident'],-3);
622
-				if ($typec == 'APP') $data['type'] = 'Approach';
623
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
624
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
625
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
626
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
627
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
628
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
629
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
630
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
631
-				if (!isset($data['source_name'])) $data['source_name'] = '';
632
-				if (isset($ATC)) echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);
813
+				if ($typec == 'APP') {
814
+					$data['type'] = 'Approach';
815
+				} elseif ($typec == 'TWR') {
816
+					$data['type'] = 'Tower';
817
+				} elseif ($typec == 'OBS') {
818
+					$data['type'] = 'Observer';
819
+				} elseif ($typec == 'GND') {
820
+					$data['type'] = 'Ground';
821
+				} elseif ($typec == 'DEL') {
822
+					$data['type'] = 'Delivery';
823
+				} elseif ($typec == 'DEP') {
824
+					$data['type'] = 'Departure';
825
+				} elseif ($typec == 'FSS') {
826
+					$data['type'] = 'Flight Service Station';
827
+				} elseif ($typec == 'CTR') {
828
+					$data['type'] = 'Control Radar or Centre';
829
+				} elseif ($data['type'] == '') {
830
+					$data['type'] = 'Observer';
831
+				}
832
+				if (!isset($data['source_name'])) {
833
+					$data['source_name'] = '';
834
+				}
835
+				if (isset($ATC)) {
836
+					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']);
837
+				}
633 838
 			}
634 839
     			unset($data);
635 840
     		    }
@@ -648,26 +853,55 @@  discard block
 block discarded – undo
648 853
 		foreach ($all_data['acList'] as $line) {
649 854
 		    $data = array();
650 855
 		    $data['hex'] = $line['Icao']; // hex
651
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
652
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
653
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
654
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
655
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
656
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
856
+		    if (isset($line['Call'])) {
857
+		    	$data['ident'] = $line['Call'];
858
+		    }
859
+		    // ident
860
+		    if (isset($line['Alt'])) {
861
+		    	$data['altitude'] = $line['Alt'];
862
+		    }
863
+		    // altitude
864
+		    if (isset($line['Spd'])) {
865
+		    	$data['speed'] = $line['Spd'];
866
+		    }
867
+		    // speed
868
+		    if (isset($line['Trak'])) {
869
+		    	$data['heading'] = $line['Trak'];
870
+		    }
871
+		    // heading
872
+		    if (isset($line['Lat'])) {
873
+		    	$data['latitude'] = $line['Lat'];
874
+		    }
875
+		    // lat
876
+		    if (isset($line['Long'])) {
877
+		    	$data['longitude'] = $line['Long'];
878
+		    }
879
+		    // long
657 880
 		    //$data['verticalrate'] = $line['']; // verticale rate
658
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
881
+		    if (isset($line['Sqk'])) {
882
+		    	$data['squawk'] = $line['Sqk'];
883
+		    }
884
+		    // squawk
659 885
 		    $data['emergency'] = ''; // emergency
660
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
886
+		    if (isset($line['Reg'])) {
887
+		    	$data['registration'] = $line['Reg'];
888
+		    }
661 889
 		    /*
662 890
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
663 891
 		    else $data['datetime'] = date('Y-m-d H:i:s');
664 892
 		    */
665 893
 		    $data['datetime'] = date('Y-m-d H:i:s');
666
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
894
+		    if (isset($line['Type'])) {
895
+		    	$data['aircraft_icao'] = $line['Type'];
896
+		    }
667 897
 	    	    $data['format_source'] = 'aircraftlistjson';
668 898
 		    $data['id_source'] = $id_source;
669
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
670
-		    if (isset($data['datetime'])) $SI->add($data);
899
+		    if (isset($value['name']) && $value['name'] != '') {
900
+		    	$data['source_name'] = $value['name'];
901
+		    }
902
+		    if (isset($data['datetime'])) {
903
+		    	$SI->add($data);
904
+		    }
671 905
 		    unset($data);
672 906
 		}
673 907
 	    } else {
@@ -687,7 +921,9 @@  discard block
 block discarded – undo
687 921
 		    $data['datetime'] = date('Y-m-d H:i:s');
688 922
 	    	    $data['format_source'] = 'aircraftlistjson';
689 923
     		    $data['id_source'] = $id_source;
690
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
924
+		    if (isset($value['name']) && $value['name'] != '') {
925
+		    	$data['source_name'] = $value['name'];
926
+		    }
691 927
 		    $SI->add($data);
692 928
 		    unset($data);
693 929
 		}
@@ -723,7 +959,9 @@  discard block
 block discarded – undo
723 959
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
724 960
 	    	    $data['format_source'] = 'planeupdatefaa';
725 961
     		    $data['id_source'] = $id_source;
726
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
962
+		    if (isset($value['name']) && $value['name'] != '') {
963
+		    	$data['source_name'] = $value['name'];
964
+		    }
727 965
 		    $SI->add($data);
728 966
 		    unset($data);
729 967
 		}
@@ -763,7 +1001,9 @@  discard block
 block discarded – undo
763 1001
 	    //$buffer = $Common->getData($hosts[$id]);
764 1002
 	    $buffer = $Common->getData($value['host']);
765 1003
 	    $all_data = json_decode($buffer,true);
766
-	    if (!empty($all_data)) $reset = 0;
1004
+	    if (!empty($all_data)) {
1005
+	    	$reset = 0;
1006
+	    }
767 1007
 	    foreach ($all_data as $key => $line) {
768 1008
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
769 1009
 		    $data = array();
@@ -784,7 +1024,9 @@  discard block
 block discarded – undo
784 1024
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
785 1025
 	    	    $data['format_source'] = 'fr24json';
786 1026
     		    $data['id_source'] = $id_source;
787
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1027
+		    if (isset($value['name']) && $value['name'] != '') {
1028
+		    	$data['source_name'] = $value['name'];
1029
+		    }
788 1030
 		    $SI->add($data);
789 1031
 		    unset($data);
790 1032
 		}
@@ -808,23 +1050,39 @@  discard block
 block discarded – undo
808 1050
 		    if (isset($line['inf'])) {
809 1051
 			$data = array();
810 1052
 			$data['hex'] = $line['inf']['ia'];
811
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
1053
+			if (isset($line['inf']['cs'])) {
1054
+				$data['ident'] = $line['inf']['cs'];
1055
+			}
1056
+			//$line[13]
812 1057
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
813
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
814
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
1058
+	    		if (isset($line['inf']['gs'])) {
1059
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
1060
+	    		}
1061
+	    		// speed
1062
+	    		if (isset($line['inf']['tr'])) {
1063
+	    			$data['heading'] = $line['inf']['tr'];
1064
+	    		}
1065
+	    		// heading
815 1066
 	    		$data['latitude'] = $line['pt'][0]; // lat
816 1067
 	    		$data['longitude'] = $line['pt'][1]; // long
817 1068
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
818
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1069
+	    		if (isset($line['inf']['sq'])) {
1070
+	    			$data['squawk'] = $line['inf']['sq'];
1071
+	    		}
1072
+	    		// squawk
819 1073
 	    		//$data['aircraft_icao'] = $line[8];
820
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1074
+	    		if (isset($line['inf']['rc'])) {
1075
+	    			$data['registration'] = $line['inf']['rc'];
1076
+	    		}
821 1077
 			//$data['departure_airport_iata'] = $line[11];
822 1078
 			//$data['arrival_airport_iata'] = $line[12];
823 1079
 	    		//$data['emergency'] = ''; // emergency
824 1080
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
825 1081
 	    		$data['format_source'] = 'radarvirtueljson';
826 1082
     			$data['id_source'] = $id_source;
827
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1083
+			if (isset($value['name']) && $value['name'] != '') {
1084
+				$data['source_name'] = $value['name'];
1085
+			}
828 1086
 			$SI->add($data);
829 1087
 			unset($data);
830 1088
 		    }
@@ -845,29 +1103,62 @@  discard block
 block discarded – undo
845 1103
 		    $data['id'] = $line['id'];
846 1104
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
847 1105
 		    $data['ident'] = $line['callsign']; // ident
848
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
849
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
850
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
851
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
852
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
853
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1106
+		    if (isset($line['pilotid'])) {
1107
+		    	$data['pilot_id'] = $line['pilotid'];
1108
+		    }
1109
+		    // pilot id
1110
+		    if (isset($line['name'])) {
1111
+		    	$data['pilot_name'] = $line['name'];
1112
+		    }
1113
+		    // pilot name
1114
+		    if (isset($line['alt'])) {
1115
+		    	$data['altitude'] = $line['alt'];
1116
+		    }
1117
+		    // altitude
1118
+		    if (isset($line['gs'])) {
1119
+		    	$data['speed'] = $line['gs'];
1120
+		    }
1121
+		    // speed
1122
+		    if (isset($line['heading'])) {
1123
+		    	$data['heading'] = $line['heading'];
1124
+		    }
1125
+		    // heading
1126
+		    if (isset($line['route'])) {
1127
+		    	$data['waypoints'] = $line['route'];
1128
+		    }
1129
+		    // route
854 1130
 		    $data['latitude'] = $line['lat']; // lat
855 1131
 		    $data['longitude'] = $line['lon']; // long
856 1132
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
857 1133
 		    //$data['squawk'] = $line['squawk']; // squawk
858 1134
 		    //$data['emergency'] = ''; // emergency
859
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
860
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
861
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1135
+		    if (isset($line['depicao'])) {
1136
+		    	$data['departure_airport_icao'] = $line['depicao'];
1137
+		    }
1138
+		    if (isset($line['deptime'])) {
1139
+		    	$data['departure_airport_time'] = $line['deptime'];
1140
+		    }
1141
+		    if (isset($line['arricao'])) {
1142
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1143
+		    }
862 1144
 		    //$data['arrival_airport_time'] = $line['arrtime'];
863
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
864
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
865
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
866
-		    else $data['info'] = '';
1145
+		    if (isset($line['aircraft'])) {
1146
+		    	$data['aircraft_icao'] = $line['aircraft'];
1147
+		    }
1148
+		    if (isset($line['transponder'])) {
1149
+		    	$data['squawk'] = $line['transponder'];
1150
+		    }
1151
+		    if (isset($line['atis'])) {
1152
+		    	$data['info'] = $line['atis'];
1153
+		    } else {
1154
+		    	$data['info'] = '';
1155
+		    }
867 1156
 		    $data['format_source'] = 'pireps';
868 1157
     		    $data['id_source'] = $id_source;
869 1158
 		    $data['datetime'] = date('Y-m-d H:i:s');
870
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1159
+		    if (isset($value['name']) && $value['name'] != '') {
1160
+		    	$data['source_name'] = $value['name'];
1161
+		    }
871 1162
 		    if ($line['icon'] == 'plane') {
872 1163
 			$SI->add($data);
873 1164
 		    //    print_r($data);
@@ -876,16 +1167,28 @@  discard block
 block discarded – undo
876 1167
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
877 1168
 			$typec = substr($data['ident'],-3);
878 1169
 			$data['type'] = '';
879
-			if ($typec == 'APP') $data['type'] = 'Approach';
880
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
881
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
882
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
883
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
884
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
885
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
886
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
887
-			else $data['type'] = 'Observer';
888
-			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']);
1170
+			if ($typec == 'APP') {
1171
+				$data['type'] = 'Approach';
1172
+			} elseif ($typec == 'TWR') {
1173
+				$data['type'] = 'Tower';
1174
+			} elseif ($typec == 'OBS') {
1175
+				$data['type'] = 'Observer';
1176
+			} elseif ($typec == 'GND') {
1177
+				$data['type'] = 'Ground';
1178
+			} elseif ($typec == 'DEL') {
1179
+				$data['type'] = 'Delivery';
1180
+			} elseif ($typec == 'DEP') {
1181
+				$data['type'] = 'Departure';
1182
+			} elseif ($typec == 'FSS') {
1183
+				$data['type'] = 'Flight Service Station';
1184
+			} elseif ($typec == 'CTR') {
1185
+				$data['type'] = 'Control Radar or Centre';
1186
+			} else {
1187
+				$data['type'] = 'Observer';
1188
+			}
1189
+			if (isset($ATC)) {
1190
+				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']);
1191
+			}
889 1192
 		    }
890 1193
 		    unset($data);
891 1194
 		}
@@ -895,7 +1198,9 @@  discard block
 block discarded – undo
895 1198
     	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
896 1199
     	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
897 1200
 	    //$buffer = $Common->getData($hosts[$id]);
898
-	    if ($globalDebug) echo 'Get Data...'."\n";
1201
+	    if ($globalDebug) {
1202
+	    	echo 'Get Data...'."\n";
1203
+	    }
899 1204
 	    $buffer = $Common->getData($value['host']);
900 1205
 	    $all_data = json_decode($buffer,true);
901 1206
 	    if ($buffer != '' && is_array($all_data)) {
@@ -903,10 +1208,16 @@  discard block
 block discarded – undo
903 1208
 		foreach ($all_data as $line) {
904 1209
 	    	    $data = array();
905 1210
 	    	    //$data['id'] = $line['id']; // id not usable
906
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1211
+	    	    if (isset($line['pilotid'])) {
1212
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1213
+	    	    }
907 1214
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
908
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
909
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1215
+	    	    if (isset($line['pilotname'])) {
1216
+	    	    	$data['pilot_name'] = $line['pilotname'];
1217
+	    	    }
1218
+	    	    if (isset($line['pilotid'])) {
1219
+	    	    	$data['pilot_id'] = $line['pilotid'];
1220
+	    	    }
910 1221
 	    	    $data['ident'] = $line['flightnum']; // ident
911 1222
 	    	    $data['altitude'] = $line['alt']; // altitude
912 1223
 	    	    $data['speed'] = $line['gs']; // speed
@@ -924,27 +1235,41 @@  discard block
 block discarded – undo
924 1235
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
925 1236
     		    $data['arrival_airport_time'] = $line['arrtime'];
926 1237
     		    $data['registration'] = $line['aircraft'];
927
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1238
+		    if (isset($line['route'])) {
1239
+		    	$data['waypoints'] = $line['route'];
1240
+		    }
1241
+		    // route
928 1242
 		    if (isset($line['aircraftname'])) {
929 1243
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
930 1244
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
931 1245
 	    		$aircraft_data = explode('-',$line['aircraftname']);
932
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
933
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
934
-	    		else {
1246
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) {
1247
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1248
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) {
1249
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1250
+	    		} else {
935 1251
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
936
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
937
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
1252
+	    		    if (isset($aircraft_data[1])) {
1253
+	    		    	$data['aircraft_icao'] = $aircraft_data[1];
1254
+	    		    } else {
1255
+	    		    	$data['aircraft_icao'] = $line['aircraftname'];
1256
+	    		    }
938 1257
 	    		}
939 1258
 	    	    }
940
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1259
+    		    if (isset($line['route'])) {
1260
+    		    	$data['waypoints'] = $line['route'];
1261
+    		    }
941 1262
     		    $data['id_source'] = $id_source;
942 1263
 	    	    $data['format_source'] = 'phpvmacars';
943
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1264
+		    if (isset($value['name']) && $value['name'] != '') {
1265
+		    	$data['source_name'] = $value['name'];
1266
+		    }
944 1267
 		    $SI->add($data);
945 1268
 		    unset($data);
946 1269
 		}
947
-		if ($globalDebug) echo 'No more data...'."\n";
1270
+		if ($globalDebug) {
1271
+			echo 'No more data...'."\n";
1272
+		}
948 1273
 		unset($buffer);
949 1274
 		unset($all_data);
950 1275
 	    }
@@ -952,7 +1277,9 @@  discard block
 block discarded – undo
952 1277
     	    $last_exec[$id]['last'] = time();
953 1278
     	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
954 1279
 	    //$buffer = $Common->getData($hosts[$id]);
955
-	    if ($globalDebug) echo 'Get Data...'."\n";
1280
+	    if ($globalDebug) {
1281
+	    	echo 'Get Data...'."\n";
1282
+	    }
956 1283
 	    $buffer = $Common->getData($value['host']);
957 1284
 	    $all_data = json_decode($buffer,true);
958 1285
 	    if ($buffer != '' && is_array($all_data)) {
@@ -981,15 +1308,22 @@  discard block
 block discarded – undo
981 1308
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
982 1309
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
983 1310
     		    //$data['registration'] = $line['aircraft'];
984
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1311
+		    if (isset($line['route'])) {
1312
+		    	$data['waypoints'] = $line['route'];
1313
+		    }
1314
+		    // route
985 1315
 	    	    $data['aircraft_icao'] = $line['plane_type'];
986 1316
     		    $data['id_source'] = $id_source;
987 1317
 	    	    $data['format_source'] = 'vam';
988
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1318
+		    if (isset($value['name']) && $value['name'] != '') {
1319
+		    	$data['source_name'] = $value['name'];
1320
+		    }
989 1321
 		    $SI->add($data);
990 1322
 		    unset($data);
991 1323
 		}
992
-		if ($globalDebug) echo 'No more data...'."\n";
1324
+		if ($globalDebug) {
1325
+			echo 'No more data...'."\n";
1326
+		}
993 1327
 		unset($buffer);
994 1328
 		unset($all_data);
995 1329
 	    }
@@ -997,7 +1331,9 @@  discard block
 block discarded – undo
997 1331
     	    $last_exec[$id]['last'] = time();
998 1332
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
999 1333
 	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais') {
1000
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1334
+	    if (function_exists('pcntl_fork')) {
1335
+	    	pcntl_signal_dispatch();
1336
+	    }
1001 1337
     	    //$last_exec[$id]['last'] = time();
1002 1338
 
1003 1339
 	    //$read = array( $sockets[$id] );
@@ -1005,7 +1341,9 @@  discard block
 block discarded – undo
1005 1341
 	    $write = NULL;
1006 1342
 	    $e = NULL;
1007 1343
 	    $n = socket_select($read, $write, $e, $timeout);
1008
-	    if ($e != NULL) var_dump($e);
1344
+	    if ($e != NULL) {
1345
+	    	var_dump($e);
1346
+	    }
1009 1347
 	    if ($n > 0) {
1010 1348
 		$reset = 0;
1011 1349
 		foreach ($read as $nb => $r) {
@@ -1027,7 +1365,9 @@  discard block
 block discarded – undo
1027 1365
 		    if ($buffer != '') {
1028 1366
 			$tt[$format] = 0;
1029 1367
 			if ($format == 'acarssbs3') {
1030
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1368
+                    	    if ($globalDebug) {
1369
+                    	    	echo 'ACARS : '.$buffer."\n";
1370
+                    	    }
1031 1371
 			    $ACARS->add(trim($buffer));
1032 1372
 			    $ACARS->deleteLiveAcarsData();
1033 1373
 			} elseif ($format == 'raw') {
@@ -1036,25 +1376,55 @@  discard block
 block discarded – undo
1036 1376
 			    if (is_array($data)) {
1037 1377
 				$data['datetime'] = date('Y-m-d H:i:s');
1038 1378
 				$data['format_source'] = 'raw';
1039
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1040
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1041
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1379
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1380
+					$data['source_name'] = $globalSources[$nb]['name'];
1381
+				}
1382
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1383
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1384
+    				}
1385
+                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1386
+                                	$SI->add($data);
1387
+                                }
1042 1388
                             }
1043 1389
                         } elseif ($format == 'ais') {
1044 1390
 			    $ais_data = $AIS->parse_line(trim($buffer));
1045 1391
 			    $data = array();
1046
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
1047
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
1048
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
1049
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1050
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1051
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1052
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1053
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1054
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1055
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1056
-			    if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination'];
1057
-			    if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1392
+			    if (isset($ais_data['ident'])) {
1393
+			    	$data['ident'] = $ais_data['ident'];
1394
+			    }
1395
+			    if (isset($ais_data['mmsi'])) {
1396
+			    	$data['mmsi'] = $ais_data['mmsi'];
1397
+			    }
1398
+			    if (isset($ais_data['speed'])) {
1399
+			    	$data['speed'] = $ais_data['speed'];
1400
+			    }
1401
+			    if (isset($ais_data['heading'])) {
1402
+			    	$data['heading'] = $ais_data['heading'];
1403
+			    }
1404
+			    if (isset($ais_data['latitude'])) {
1405
+			    	$data['latitude'] = $ais_data['latitude'];
1406
+			    }
1407
+			    if (isset($ais_data['longitude'])) {
1408
+			    	$data['longitude'] = $ais_data['longitude'];
1409
+			    }
1410
+			    if (isset($ais_data['status'])) {
1411
+			    	$data['status'] = $ais_data['status'];
1412
+			    }
1413
+			    if (isset($ais_data['type'])) {
1414
+			    	$data['type'] = $ais_data['type'];
1415
+			    }
1416
+			    if (isset($ais_data['imo'])) {
1417
+			    	$data['imo'] = $ais_data['imo'];
1418
+			    }
1419
+			    if (isset($ais_data['callsign'])) {
1420
+			    	$data['callsign'] = $ais_data['callsign'];
1421
+			    }
1422
+			    if (isset($ais_data['destination'])) {
1423
+			    	$data['arrival_code'] = $ais_data['destination'];
1424
+			    }
1425
+			    if (isset($ais_data['eta_ts'])) {
1426
+			    	$data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']);
1427
+			    }
1058 1428
 
1059 1429
 			    if (isset($ais_data['timestamp'])) {
1060 1430
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1063,7 +1433,9 @@  discard block
 block discarded – undo
1063 1433
 			    }
1064 1434
 			    $data['format_source'] = 'aisnmea';
1065 1435
     			    $data['id_source'] = $id_source;
1066
-			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data);
1436
+			    if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') {
1437
+			    	$MI->add($data);
1438
+			    }
1067 1439
 			    unset($data);
1068 1440
                         } elseif ($format == 'flightgearsp') {
1069 1441
                     	    //echo $buffer."\n";
@@ -1081,11 +1453,15 @@  discard block
 block discarded – undo
1081 1453
 				$data['speed'] = round($line[5]*1.94384);
1082 1454
 				$data['datetime'] = date('Y-m-d H:i:s');
1083 1455
 				$data['format_source'] = 'flightgearsp';
1084
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1456
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1457
+					$SI->add($data);
1458
+				}
1085 1459
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1086 1460
 			    }
1087 1461
                         } elseif ($format == 'acars') {
1088
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1462
+                    	    if ($globalDebug) {
1463
+                    	    	echo 'ACARS : '.$buffer."\n";
1464
+                    	    }
1089 1465
 			    $ACARS->add(trim($buffer));
1090 1466
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1091 1467
 			    $ACARS->deleteLiveAcarsData();
@@ -1106,7 +1482,9 @@  discard block
 block discarded – undo
1106 1482
 				    $aircraft_type = $line[10];
1107 1483
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1108 1484
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1109
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1485
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1486
+				    	$SI->add($data);
1487
+				    }
1110 1488
 				}
1111 1489
 			    }
1112 1490
 			} elseif ($format == 'beast') {
@@ -1122,21 +1500,43 @@  discard block
 block discarded – undo
1122 1500
     				$data['hex'] = $lined['hexid'];
1123 1501
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1124 1502
     				$data['datetime'] = date('Y-m-d H:i:s');;
1125
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1126
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1127
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1128
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1129
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1130
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1131
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1503
+    				if (isset($lined['ident'])) {
1504
+    					$data['ident'] = $lined['ident'];
1505
+    				}
1506
+    				if (isset($lined['lat'])) {
1507
+    					$data['latitude'] = $lined['lat'];
1508
+    				}
1509
+    				if (isset($lined['lon'])) {
1510
+    					$data['longitude'] = $lined['lon'];
1511
+    				}
1512
+    				if (isset($lined['speed'])) {
1513
+    					$data['speed'] = $lined['speed'];
1514
+    				}
1515
+    				if (isset($lined['squawk'])) {
1516
+    					$data['squawk'] = $lined['squawk'];
1517
+    				}
1518
+    				if (isset($lined['alt'])) {
1519
+    					$data['altitude'] = $lined['alt'];
1520
+    				}
1521
+    				if (isset($lined['heading'])) {
1522
+    					$data['heading'] = $lined['heading'];
1523
+    				}
1132 1524
     				$data['id_source'] = $id_source;
1133 1525
     				$data['format_source'] = 'tsv';
1134
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1135
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1136
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1526
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1527
+    					$data['source_name'] = $globalSources[$nb]['name'];
1528
+    				}
1529
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1530
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1531
+    				}
1532
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1533
+    					$SI->add($data);
1534
+    				}
1137 1535
     				unset($lined);
1138 1536
     				unset($data);
1139
-    			    } else $error = true;
1537
+    			    } else {
1538
+    			    	$error = true;
1539
+    			    }
1140 1540
 			} elseif ($format == 'aprs' && $use_aprs) {
1141 1541
 			    if ($aprs_connect == 0) {
1142 1542
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1162,49 +1562,82 @@  discard block
 block discarded – undo
1162 1562
 				    $aprs_last_tx = time();
1163 1563
 				    $data = array();
1164 1564
 				    //print_r($line);
1165
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1166
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1167
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1565
+				    if (isset($line['address'])) {
1566
+				    	$data['hex'] = $line['address'];
1567
+				    }
1568
+				    if (isset($line['timestamp'])) {
1569
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1570
+				    } else {
1571
+				    	$data['datetime'] = date('Y-m-d H:i:s');
1572
+				    }
1168 1573
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1169
-				    if (isset($line['ident'])) $data['ident'] = $line['ident'];
1574
+				    if (isset($line['ident'])) {
1575
+				    	$data['ident'] = $line['ident'];
1576
+				    }
1170 1577
 				    $data['latitude'] = $line['latitude'];
1171 1578
 				    $data['longitude'] = $line['longitude'];
1172 1579
 				    //$data['verticalrate'] = $line[16];
1173
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1174
-				    else $data['speed'] = 0;
1175
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1176
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1177
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1178
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1580
+				    if (isset($line['speed'])) {
1581
+				    	$data['speed'] = $line['speed'];
1582
+				    } else {
1583
+				    	$data['speed'] = 0;
1584
+				    }
1585
+				    if (isset($line['altitude'])) {
1586
+				    	$data['altitude'] = $line['altitude'];
1587
+				    }
1588
+				    if (isset($line['comment'])) {
1589
+				    	$data['comment'] = $line['comment'];
1590
+				    }
1591
+				    if (isset($line['symbol'])) {
1592
+				    	$data['type'] = $line['symbol'];
1593
+				    }
1594
+				    if (isset($line['heading'])) {
1595
+				    	$data['heading'] = $line['heading'];
1596
+				    }
1179 1597
 				    //else $data['heading'] = 0;
1180
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1181
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1598
+				    if (isset($line['stealth'])) {
1599
+				    	$data['aircraft_type'] = $line['stealth'];
1600
+				    }
1601
+				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) {
1602
+				    	$data['noarchive'] = true;
1603
+				    }
1182 1604
     				    $data['id_source'] = $id_source;
1183
-    				    if (isset($line['format_source'])) $data['format_source'] = $line['format_source'];
1184
-				    else $data['format_source'] = 'aprs';
1605
+    				    if (isset($line['format_source'])) {
1606
+    				    	$data['format_source'] = $line['format_source'];
1607
+    				    } else {
1608
+				    	$data['format_source'] = 'aprs';
1609
+				    }
1185 1610
 				    $data['source_name'] = $line['source'];
1186
-				    if (isset($line['source_type'])) $data['source_type'] = $line['source_type'];
1187
-				    else $data['source_type'] = 'flarm';
1188
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1611
+				    if (isset($line['source_type'])) {
1612
+				    	$data['source_type'] = $line['source_type'];
1613
+				    } else {
1614
+				    	$data['source_type'] = 'flarm';
1615
+				    }
1616
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
1617
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1618
+    				    }
1189 1619
 				    $currentdate = date('Y-m-d H:i:s');
1190 1620
 				    $aprsdate = strtotime($data['datetime']);
1191 1621
 				    // Accept data if time <= system time + 20s
1192 1622
 				    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'])))) {
1193 1623
 					$send = $SI->add($data);
1194 1624
 				    } elseif (isset($line['stealth'])) {
1195
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1196
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1625
+					if ($line['stealth'] != 0) {
1626
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1627
+					} else {
1628
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1629
+					}
1197 1630
 				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1198 1631
 				    } 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') {
1199 1632
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1200
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1633
+					if (isset($globalTracker) && $globalTracker) {
1634
+						$send = $TI->add($data);
1635
+					}
1201 1636
 				    }
1202 1637
 				    unset($data);
1203
-				} 
1204
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1638
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1205 1639
 					echo '!! Weather Station not yet supported'."\n";
1206
-				}
1207
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle')) {
1640
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle')) {
1208 1641
 					echo '!! Car & Trucks not yet supported'."\n";
1209 1642
 				}
1210 1643
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
@@ -1237,25 +1670,42 @@  discard block
 block discarded – undo
1237 1670
     				$data['ground'] = $line[21];
1238 1671
     				$data['emergency'] = $line[19];
1239 1672
     				$data['format_source'] = 'sbs';
1240
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1241
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1673
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1674
+					$data['source_name'] = $globalSources[$nb]['name'];
1675
+				}
1676
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1677
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1678
+    				}
1242 1679
     				$data['id_source'] = $id_source;
1243
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1244
-    				else $error = true;
1680
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1681
+    					$send = $SI->add($data);
1682
+    				} else {
1683
+    					$error = true;
1684
+    				}
1245 1685
     				unset($data);
1246
-    			    } else $error = true;
1686
+    			    } else {
1687
+    			    	$error = true;
1688
+    			    }
1247 1689
 			    if ($error) {
1248 1690
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1249
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
1691
+					if ($globalDebug) {
1692
+						echo "Not a message. Ignoring... \n";
1693
+					}
1250 1694
 				} else {
1251
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
1695
+					if ($globalDebug) {
1696
+						echo "Wrong line format. Ignoring... \n";
1697
+					}
1252 1698
 					if ($globalDebug) {
1253 1699
 						echo $buffer;
1254 1700
 						print_r($line);
1255 1701
 					}
1256 1702
 					//socket_close($r);
1257
-					if ($globalDebug) echo "Reconnect after an error...\n";
1258
-					if ($format == 'aprs') $aprs_connect = 0;
1703
+					if ($globalDebug) {
1704
+						echo "Reconnect after an error...\n";
1705
+					}
1706
+					if ($format == 'aprs') {
1707
+						$aprs_connect = 0;
1708
+					}
1259 1709
 					$sourceer[$nb] = $globalSources[$nb];
1260 1710
 					connect_all($sourceer);
1261 1711
 					$sourceer = array();
@@ -1263,10 +1713,14 @@  discard block
 block discarded – undo
1263 1713
 			    }
1264 1714
 			}
1265 1715
 			// Sleep for xxx microseconds
1266
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1716
+			if (isset($globalSBSSleep)) {
1717
+				usleep($globalSBSSleep);
1718
+			}
1267 1719
 		    } else {
1268 1720
 			if ($format == 'flightgearmp') {
1269
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1721
+			    	if ($globalDebug) {
1722
+			    		echo "Reconnect FlightGear MP...";
1723
+			    	}
1270 1724
 				//@socket_close($r);
1271 1725
 				sleep($globalMinFetch);
1272 1726
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1275,10 +1729,15 @@  discard block
 block discarded – undo
1275 1729
 				break;
1276 1730
 				
1277 1731
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1278
-			    if (isset($tt[$format])) $tt[$format]++;
1279
-			    else $tt[$format] = 0;
1732
+			    if (isset($tt[$format])) {
1733
+			    	$tt[$format]++;
1734
+			    } else {
1735
+			    	$tt[$format] = 0;
1736
+			    }
1280 1737
 			    if ($tt[$format] > 30) {
1281
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1738
+				if ($globalDebug) {
1739
+					echo "ERROR : Reconnect ".$format."...";
1740
+				}
1282 1741
 				//@socket_close($r);
1283 1742
 				sleep(2);
1284 1743
 				$aprs_connect = 0;
@@ -1295,11 +1754,17 @@  discard block
 block discarded – undo
1295 1754
 	    } else {
1296 1755
 		$error = socket_strerror(socket_last_error());
1297 1756
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1298
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1299
-			if (isset($globalDebug)) echo "Restarting...\n";
1757
+			if ($globalDebug) {
1758
+				echo "ERROR : socket_select give this error ".$error . "\n";
1759
+			}
1760
+			if (isset($globalDebug)) {
1761
+				echo "Restarting...\n";
1762
+			}
1300 1763
 			// Restart the script if possible
1301 1764
 			if (is_array($sockets)) {
1302
-			    if ($globalDebug) echo "Shutdown all sockets...";
1765
+			    if ($globalDebug) {
1766
+			    	echo "Shutdown all sockets...";
1767
+			    }
1303 1768
 			    
1304 1769
 			    foreach ($sockets as $sock) {
1305 1770
 				@socket_shutdown($sock,2);
@@ -1307,18 +1772,24 @@  discard block
 block discarded – undo
1307 1772
 			    }
1308 1773
 			    
1309 1774
 			}
1310
-			if ($globalDebug) echo "Restart all connections...";
1775
+			if ($globalDebug) {
1776
+				echo "Restart all connections...";
1777
+			}
1311 1778
 			sleep(2);
1312 1779
 			$time = time();
1313 1780
 			//connect_all($hosts);
1314 1781
 			$aprs_connect = 0;
1315
-			if ($reset > 40) exit('Too many attempts...');
1782
+			if ($reset > 40) {
1783
+				exit('Too many attempts...');
1784
+			}
1316 1785
 			connect_all($globalSources);
1317 1786
 		}
1318 1787
 	    }
1319 1788
 	}
1320 1789
 	if ($globalDaemon === false) {
1321
-	    if ($globalDebug) echo 'Check all...'."\n";
1790
+	    if ($globalDebug) {
1791
+	    	echo 'Check all...'."\n";
1792
+	    }
1322 1793
 	    $SI->checkAll();
1323 1794
 	}
1324 1795
     }
Please login to merge, or discard this patch.