Completed
Push — master ( a3214e...3969e1 )
by Yannick
111:17 queued 84:43
created
require/class.SpotterImport.php 2 patches
Spacing   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -34,12 +34,12 @@  discard block
 block discarded – undo
34 34
 		$currentdate = date('Y-m-d');
35 35
 		$sourcestat = $Stats->getStatsSource($currentdate);
36 36
 		if (!empty($sourcestat)) {
37
-		    foreach($sourcestat as $srcst) {
37
+		    foreach ($sourcestat as $srcst) {
38 38
 		    	$type = $srcst['stats_type'];
39 39
 			if ($type == 'polar' || $type == 'hist') {
40 40
 			    $source = $srcst['source_name'];
41 41
 			    $data = $srcst['source_data'];
42
-			    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
42
+			    $this->stats[$currentdate][$source][$type] = json_decode($data, true);
43 43
 	    		}
44 44
 		    }
45 45
 		}
@@ -51,14 +51,14 @@  discard block
 block discarded – undo
51 51
 	if (isset($globalGeoid) && $globalGeoid) {
52 52
 		try {
53 53
 			$GeoidClass = new GeoidHeight();
54
-		} catch(Exception $e) {
54
+		} catch (Exception $e) {
55 55
 			if ($globalDebug) echo "Can't calculate geoid, check that you downloaded it via update_db.php (".$e.")\n";
56 56
 			$GeoidClass = FALSE;
57 57
 		}
58 58
 	}
59 59
     }
60 60
 
61
-    public function get_Schedule($id,$ident) {
61
+    public function get_Schedule($id, $ident) {
62 62
 	global $globalDebug, $globalFork, $globalSchedulesFetch;
63 63
 	// Get schedule here, so it's done only one time
64 64
 	
@@ -83,8 +83,8 @@  discard block
 block discarded – undo
83 83
 		$schedule = $Schedule->fetchSchedule($operator);
84 84
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
85 85
 		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
86
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
87
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
86
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $schedule['DepartureTime']));
87
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $schedule['ArrivalTime']));
88 88
 		    // Should also check if route schedule = route from DB
89 89
 		    if ($schedule['DepartureAirportIATA'] != '') {
90 90
 			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 			    }
105 105
 			}
106 106
 		    }
107
-		    $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
107
+		    $Schedule->addSchedule($operator, $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['arrival_airport_time'], $schedule['Source']);
108 108
 		}
109 109
 	    } else $scheduleexist = true;
110 110
 	} else $scheduleexist = true;
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
        if ($scheduleexist) {
113 113
 		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
114 114
     		$sch = $Schedule->getSchedule($operator);
115
-		$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']));
115
+		$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']));
116 116
        }
117 117
 	$Spotter->db = null;
118 118
 	$Schedule->db = null;
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 		    //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
140 140
     		    $Spotter = new Spotter($this->db);
141 141
         	    $real_arrival = $this->arrival($key);
142
-        	    if (isset($this->all_flights[$key]['altitude']) && isset($this->all_flights[$key]['datetime'])) $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']);
142
+        	    if (isset($this->all_flights[$key]['altitude']) && isset($this->all_flights[$key]['datetime'])) $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']);
143 143
         	}
144 144
 	    }
145 145
 	}
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
         $airport_time = '';
154 154
         if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
155 155
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
156
-	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
156
+	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $globalClosestMinDist);
157 157
     	    if (isset($closestAirports[0])) {
158 158
         	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
159 159
         	    $airport_icao = $closestAirports[0]['icao'];
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
         		    break;
169 169
         		}
170 170
         	    }
171
-        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
171
+        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude'] + 5000))) {
172 172
         		$airport_icao = $closestAirports[0]['icao'];
173 173
         		$airport_time = $this->all_flights[$key]['datetime'];
174 174
         	} else {
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
         } else {
182 182
         	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
183 183
         }
184
-        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
184
+        return array('airport_icao' => $airport_icao, 'airport_time' => $airport_time);
185 185
     }
186 186
 
187 187
 
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
193 193
 	foreach ($this->all_flights as $key => $flight) {
194 194
 	    if (isset($flight['lastupdate'])) {
195
-		if ($flight['lastupdate'] < (time()-5900)) {
195
+		if ($flight['lastupdate'] < (time() - 5900)) {
196 196
 		    $this->delKey($key);
197 197
 		}
198 198
 	    }
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 			$real_arrival = $this->arrival($key);
209 209
 			$Spotter = new Spotter($this->db);
210 210
 			if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
211
-				$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']);
211
+				$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']);
212 212
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
213 213
 			}
214 214
 		}
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 	$send = false;
242 242
 	
243 243
 	// SBS format is CSV format
244
-	if(is_array($line) && (isset($line['hex']) || isset($line['id']))) {
244
+	if (is_array($line) && (isset($line['hex']) || isset($line['id']))) {
245 245
 	    //print_r($line);
246 246
 	    if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']);
247 247
   	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
@@ -277,25 +277,25 @@  discard block
 block discarded – undo
277 277
 		if (!isset($this->all_flights[$id])) {
278 278
 		    if ($globalDebug) echo 'New flight...'."\n";
279 279
 		    $this->all_flights[$id] = array();
280
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
281
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '','altitude_previous' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
282
-		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
280
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
281
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => '', 'departure_airport' => '', 'arrival_airport' => '', 'latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '', 'altitude_real' => '', 'altitude_previous' => '', 'heading' => '', 'departure_airport_time' => '', 'arrival_airport_time' => '', 'squawk' => '', 'route_stop' => '', 'registration' => '', 'pilot_id' => '', 'pilot_name' => '', 'waypoints' => '', 'ground' => '0', 'format_source' => '', 'source_name' => '', 'over_country' => '', 'verticalrate' => '', 'noarchive' => false, 'putinarchive' => true, 'source_type' => ''));
282
+		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('lastupdate' => time()));
283 283
 		    if (!isset($line['id'])) {
284 284
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
285 285
 //			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')));
286 286
 //			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')));
287
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
287
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $id.'-'.date('YmdHi')));
288 288
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
289
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
289
+		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
290 290
 		    if ($globalAllFlights !== FALSE) $dataFound = true;
291 291
 		}
292 292
 		if (isset($line['source_type']) && $line['source_type'] != '') {
293
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
293
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('source_type' => $line['source_type']));
294 294
 		}
295 295
 		
296 296
 		//print_r($this->all_flights);
297 297
 		if (isset($line['hex']) && !isset($this->all_flights[$id]['hex']) && ctype_xdigit($line['hex'])) {
298
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex'])));
298
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('hex' => trim($line['hex'])));
299 299
 		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
300 300
 			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
301 301
 		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
@@ -304,27 +304,27 @@  discard block
 block discarded – undo
304 304
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
305 305
 			    $Spotter = new Spotter($this->db);
306 306
 			    if (isset($this->all_flights[$id]['source_type'])) {
307
-				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']),$this->all_flights[$id]['source_type']);
307
+				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']), $this->all_flights[$id]['source_type']);
308 308
 			    } else {
309 309
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
310 310
 			    }
311 311
 			    $Spotter->db = null;
312
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
313
-			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
312
+			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
313
+			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
314 314
 			}
315 315
 		    }
316 316
 		    if ($globalAllFlights !== FALSE) $dataFound = true;
317 317
 		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
318 318
 		}
319 319
 	        if (isset($line['id']) && !isset($line['hex'])) {
320
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
320
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('hex' => ''));
321 321
 	        }
322 322
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
323 323
 			$icao = $line['aircraft_icao'];
324 324
 			$Spotter = new Spotter($this->db);
325 325
 			if (isset($Spotter->aircraft_correct_icaotype[$icao])) $icao = $Spotter->aircraft_correct_icaotype[$icao];
326 326
 			$Spotter->db = null;
327
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $icao));
327
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $icao));
328 328
 		}
329 329
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_name'])) {
330 330
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 				$Spotter = new Spotter($this->db);
333 333
 				$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
334 334
 				$Spotter->db = null;
335
-				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
335
+				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
336 336
 			}
337 337
 		}
338 338
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) {
@@ -340,15 +340,15 @@  discard block
 block discarded – undo
340 340
 			elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
341 341
 			elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
342 342
 			elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
343
-			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
343
+			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao));
344 344
 		}
345 345
 		if (!isset($this->all_flights[$id]['aircraft_icao'])) {
346
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
346
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => 'NA'));
347 347
 		}
348 348
 		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
349
-		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60 && strtotime($line['datetime']) < time()+20*60) {
349
+		if (isset($line['datetime']) && strtotime($line['datetime']) > time() - 20*60 && strtotime($line['datetime']) < time() + 20*60) {
350 350
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
351
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
351
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => $line['datetime']));
352 352
 		    } else {
353 353
 				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";
354 354
 				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";
@@ -359,31 +359,31 @@  discard block
 block discarded – undo
359 359
 				*/
360 360
 				return '';
361 361
 		    }
362
-		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) {
362
+		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time() - 20*60) {
363 363
 			if ($globalDebug) echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n";
364 364
 			return '';
365
-		} elseif (isset($line['datetime']) && strtotime($line['datetime']) > time()+20*60) {
365
+		} elseif (isset($line['datetime']) && strtotime($line['datetime']) > time() + 20*60) {
366 366
 			if ($globalDebug) echo "!!! Date is in the future ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n";
367 367
 			return '';
368 368
 		} elseif (!isset($line['datetime'])) {
369 369
 			date_default_timezone_set('UTC');
370
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
370
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => date('Y-m-d H:i:s')));
371 371
 		} else {
372 372
 			if ($globalDebug) echo "!!! Unknow date error ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!";
373 373
 			return '';
374 374
 		}
375 375
 
376 376
 		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') {
377
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
377
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('registration' => $line['registration']));
378 378
 		}
379 379
 		if (isset($line['waypoints']) && $line['waypoints'] != '') {
380
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
380
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('waypoints' => $line['waypoints']));
381 381
 		}
382 382
 		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
383
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => trim($line['pilot_id'])));
383
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_id' => trim($line['pilot_id'])));
384 384
 		}
385 385
 		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
386
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => trim($line['pilot_name'])));
386
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_name' => trim($line['pilot_name'])));
387 387
 		}
388 388
  
389 389
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) {
@@ -391,13 +391,13 @@  discard block
 block discarded – undo
391 391
 		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
392 392
 			if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
393 393
 				if ($globalDebug) echo '---!!!! New ident, reset aircraft data...'."\n";
394
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
395
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
396
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
397
-				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
398
-				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']));
394
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
395
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1));
396
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $id.'-'.date('YmdHi')));
397
+				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
398
+				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']));
399 399
 			} else {
400
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
400
+			    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => trim($line['ident'])));
401 401
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
402 402
 				$timeelapsed = microtime(true);
403 403
             			$Spotter = new Spotter($this->db);
@@ -407,13 +407,13 @@  discard block
 block discarded – undo
407 407
 				elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
408 408
 				elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
409 409
 				elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
410
-            			$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
410
+            			$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $fromsource);
411 411
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
412 412
 				$Spotter->db = null;
413
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
413
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
414 414
 			    }
415 415
 			}
416
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
416
+		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => trim($line['ident'])));
417 417
 		    
418 418
 /*
419 419
 		    if (!isset($line['id'])) {
@@ -423,25 +423,25 @@  discard block
 block discarded – undo
423 423
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
424 424
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
425 425
   */
426
-		    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']));
426
+		    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']));
427 427
 
428 428
 		    //$putinarchive = true;
429 429
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
430
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
430
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $line['departure_airport_time']));
431 431
 		    }
432 432
 		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
433
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
433
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $line['arrival_airport_time']));
434 434
 		    }
435 435
 		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
436
-		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
436
+		    		$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' => ''));
437 437
 		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
438 438
 			$timeelapsed = microtime(true);
439 439
 			if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
440 440
 				$Spotter = new Spotter($this->db);
441 441
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
442 442
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
443
-		    		$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' => ''));
444
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
443
+		    		$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' => ''));
444
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
445 445
                         }
446 446
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
447 447
 			$timeelapsed = microtime(true);
@@ -455,35 +455,35 @@  discard block
 block discarded – undo
455 455
 				$Translation->db = null;
456 456
 			    }
457 457
 			    $Spotter->db = null;
458
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
458
+			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
459 459
                     	}
460 460
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
461 461
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
462 462
 			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
463 463
 				//    $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']));
464
-		    		$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']));
464
+		    		$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']));
465 465
 		    	    }
466 466
 			}
467 467
 			if (!isset($globalFork)) $globalFork = TRUE;
468 468
 			if (!$globalVA && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
469
-				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
469
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id, trim($line['ident']));
470 470
 			}
471 471
 		    }
472 472
 		}
473 473
 
474 474
 		if (isset($line['speed']) && $line['speed'] != '' && $line['speed'] != 0) {
475 475
 		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
476
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
477
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
476
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($line['speed'])));
477
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed_fromsrc' => true));
478 478
 		    //$dataFound = true;
479 479
 		} else if (!isset($this->all_flights[$id]['speed_fromsrc']) && isset($this->all_flights[$id]['time_last_coord']) && $this->all_flights[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
480
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
480
+		    $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm');
481 481
 		    if ($distance > 1000 && $distance < 10000) {
482 482
 		    // use datetime
483 483
 			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
484 484
 			$speed = $speed*3.6;
485 485
 			if ($speed < 1000) {
486
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
486
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($speed)));
487 487
 	  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
488 488
 	  		} else {
489 489
 	  			if ($globalDebug) echo "ø IGNORED : Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
@@ -498,9 +498,9 @@  discard block
 block discarded – undo
498 498
 	    	    	if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
499 499
 	    	    	return false;
500 500
 	    	    }
501
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
501
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time() - $this->all_flights[$id]['time_last_coord']);
502 502
 	    	    else unset($timediff);
503
-	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
503
+	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time() - $this->all_flights[$id]['time_last_archive_coord']);
504 504
 	    	    else unset($timediff_archive);
505 505
 	    	    if ($this->tmd > 5
506 506
 	    	        || (isset($line['format_source']) 
@@ -524,14 +524,14 @@  discard block
 block discarded – undo
524 524
 	    	    	|| ($timediff > 30 
525 525
 	    	    	    && isset($this->all_flights[$id]['latitude']) 
526 526
 	    	    	    && isset($this->all_flights[$id]['longitude']) 
527
-	    	    	    && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'))
527
+	    	    	    && $Common->withinThreshold($timediff, $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm'))
528 528
 	    	    	    )
529 529
 	    	    	) {
530 530
 
531 531
 			if ((isset($timediff) && !isset($timediff_archive)) || (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']))) {
532 532
 			    if ((isset($timediff_archive) && $timediff_archive > $globalAircraftMaxUpdate)
533 533
 				|| (isset($line['format_source']) && $line['format_source'] == 'airwhere') 
534
-				|| !$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'])) {
534
+				|| !$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'])) {
535 535
 				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
536 536
 				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
537 537
 				$this->all_flights[$id]['putinarchive'] = true;
@@ -541,11 +541,11 @@  discard block
 block discarded – undo
541 541
 				    $timeelapsed = microtime(true);
542 542
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
543 543
 					$Spotter = new Spotter($this->db);
544
-					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
544
+					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']);
545 545
 					if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
546 546
 					else $this->all_flights[$id]['over_country'] = '';
547 547
 					$Spotter->db = null;
548
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
548
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
549 549
 					if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
550 550
 				    }
551 551
 				}
@@ -571,13 +571,13 @@  discard block
 block discarded – undo
571 571
 					$this->all_flights[$id]['time_last_coord'] = time();
572 572
 				}
573 573
 				//if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs' || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > 0.0001)) {
574
-				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > 0.0001)) {
574
+				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude'] - $line['latitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude'] - $line['latitude']) > 0.0001)) {
575 575
 				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
576 576
 				    $dataFound = true;
577 577
 				    $this->all_flights[$id]['time_last_coord'] = time();
578 578
 				}
579 579
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
580
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
580
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('latitude' => $line['latitude']));
581 581
 				/*
582 582
 				if (abs($this->all_flights[$id]['archive_latitude']-$this->all_flights[$id]['latitude']) > 0.3) {
583 583
 				    $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
@@ -599,13 +599,13 @@  discard block
 block discarded – undo
599 599
 					$this->all_flights[$id]['time_last_coord'] = time();
600 600
 				}
601 601
 				//if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs' || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > 0.0001)) {
602
-				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > 0.0001)) {
602
+				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude'] - $line['longitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude'] - $line['longitude']) > 0.0001)) {
603 603
 				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
604 604
 				    $dataFound = true;
605 605
 				    $this->all_flights[$id]['time_last_coord'] = time();
606 606
 				}
607 607
 				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
608
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
608
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('longitude' => $line['longitude']));
609 609
 				/*
610 610
 				if (abs($this->all_flights[$id]['archive_longitude']-$this->all_flights[$id]['longitude']) > 0.3) {
611 611
 				    $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
@@ -623,46 +623,46 @@  discard block
 block discarded – undo
623 623
 		    } else if ($globalDebug && $timediff > 30) {
624 624
 			$this->tmd = $this->tmd + 1;
625 625
 			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
626
-			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
627
-			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
626
+			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')."m -";
627
+			echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - ";
628 628
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
629 629
 		    }
630 630
 		}
631 631
 		if (isset($line['last_update']) && $line['last_update'] != '') {
632 632
 		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
633
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
633
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('last_update' => $line['last_update']));
634 634
 		}
635 635
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
636
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
636
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('verticalrate' => $line['verticalrate']));
637 637
 		    //$dataFound = true;
638 638
 		}
639 639
 		if (isset($line['format_source']) && $line['format_source'] != '') {
640
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
640
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('format_source' => $line['format_source']));
641 641
 		}
642 642
 		if (isset($line['source_name']) && $line['source_name'] != '') {
643
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
643
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('source_name' => $line['source_name']));
644 644
 		}
645 645
 		if (isset($line['emergency']) && $line['emergency'] != '') {
646
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
646
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('emergency' => $line['emergency']));
647 647
 		    //$dataFound = true;
648 648
 		}
649 649
 		if (isset($line['ground']) && $line['ground'] != '') {
650 650
 		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
651 651
 			// Here we force archive of flight because after ground it's a new one (or should be)
652
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
653
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
654
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
655
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
656
-			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']));
652
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
653
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1));
654
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $id.'-'.date('YmdHi')));
655
+		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
656
+			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']));
657 657
 		    }
658 658
 		    if ($line['ground'] != 1) $line['ground'] = 0;
659
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
659
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ground' => $line['ground']));
660 660
 		    //$dataFound = true;
661 661
 		}
662 662
 		if (isset($line['squawk']) && $line['squawk'] != '') {
663 663
 		    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'])) {
664 664
 			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
665
-			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
665
+			    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk']));
666 666
 			    $highlight = '';
667 667
 			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
668 668
 			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
@@ -671,66 +671,66 @@  discard block
 block discarded – undo
671 671
 				$timeelapsed = microtime(true);
672 672
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
673 673
 				    $Spotter = new Spotter($this->db);
674
-				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
674
+				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'], $highlight);
675 675
 				    $Spotter->db = null;
676
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
676
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
677 677
 				}
678 678
 				//$putinarchive = true;
679 679
 				//$highlight = '';
680 680
 			    }
681 681
 			    
682
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
682
+		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk']));
683 683
 		    //$dataFound = true;
684 684
 		}
685 685
 
686 686
 		if (isset($line['altitude']) && $line['altitude'] != '') {
687 687
 			if (isset($line['altitude_relative']) && isset($GeoidClass) && is_object($GeoidClass)) {
688 688
 				if ($line['altitude_relative'] == 'AMSL' || $line['altitude_relative'] == 'MSL') {
689
-					$geoid = round($GeoidClass->get($this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'])*3.28084,2);
689
+					$geoid = round($GeoidClass->get($this->all_flights[$id]['livedb_latitude'], $this->all_flights[$id]['livedb_longitude'])*3.28084, 2);
690 690
 					//if ($globalDebug) echo '=> Set altitude to WGS84 Ellipsoid, add '.$geoid.' to '.$line['altitude']."\n";
691 691
 					$line['altitude'] = $line['altitude'] - $geoid;
692 692
 				}
693 693
 			}
694 694
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
695
-			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;
696
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
697
-			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
695
+			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;
696
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude' => round($line['altitude']/100)));
697
+			$this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude_real' => $line['altitude']));
698 698
 			//$dataFound = true;
699 699
 		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
700 700
 		    if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
701 701
 			if (isset($this->all_flights[$id]['over_country']) && $this->all_flights[$id]['over_country'] != '' && isset($this->all_flights[$id]['altitude_previous']) && $this->all_flights[$id]['altitude_previous'] != '' && $this->all_flights[$id]['altitude_previous'] < $this->all_flights[$id]['altitude_real'] && isset($this->all_flights[$id]['lastupdate']) && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
702 702
 				if ($globalDebug) echo '--- Reset because of altitude'."\n";
703
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
704
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
705
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
706
-				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
707
-				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']));
703
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0));
704
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1));
705
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $id.'-'.date('YmdHi')));
706
+				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id']));
707
+				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']));
708 708
 			}
709 709
 		    }
710
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
710
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude_previous' => $line['altitude']));
711 711
 		}
712 712
 
713 713
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
714
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
714
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('noarchive' => true));
715 715
 		}
716 716
 		
717 717
 		if (isset($line['heading']) && $line['heading'] != '') {
718
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
719
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
720
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
718
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading'] - round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
719
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($line['heading'])));
720
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading_fromsrc' => true));
721 721
 		    //$dataFound = true;
722 722
   		} 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']) {
723
-  		    $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']);
724
-		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
725
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
723
+  		    $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']);
724
+		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($heading)));
725
+		    if (abs($this->all_flights[$id]['heading'] - round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
726 726
   		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['id']." : ".$heading."\n";
727 727
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
728 728
   		    // If not enough messages and ACARS set heading to 0
729
-  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
729
+  		    $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => 0));
730 730
   		}
731
-		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
732
-		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
733
-		elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalAircraftMinupdate) $dataFound = false;
731
+		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
732
+		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
733
+		elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalAircraftMinupdate) $dataFound = false;
734 734
 
735 735
 //		print_r($this->all_flights[$id]);
736 736
 		//gets the callsign from the last hour
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
 		if ($dataFound === true && isset($this->all_flights[$id]['id'])) {
742 742
 		    $this->all_flights[$id]['lastupdate'] = time();
743 743
 		    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) {
744
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
744
+		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == '' || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
745 745
 			    //print_r($this->all_flights);
746 746
 			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
747 747
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
@@ -752,61 +752,61 @@  discard block
 block discarded – undo
752 752
 				    $SpotterLive = new SpotterLive($this->db);
753 753
 				    if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
754 754
 					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
755
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
755
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
756 756
 				    } elseif (isset($line['id'])) {
757 757
 					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
758
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
758
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
759 759
 				    } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
760 760
 					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
761
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
761
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
762 762
 				    } else $recent_ident = '';
763
-				    $SpotterLive->db=null;
763
+				    $SpotterLive->db = null;
764 764
 				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
765 765
 				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
766 766
 				} else $recent_ident = '';
767 767
 			    } else {
768 768
 				$recent_ident = '';
769
-				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
769
+				$this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 0));
770 770
 			    }
771 771
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
772
-			    if($recent_ident == "")
772
+			    if ($recent_ident == "")
773 773
 			    {
774 774
 				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
775 775
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
776 776
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
777 777
 				//adds the spotter data for the archive
778 778
 				$ignoreImport = false;
779
-				foreach($globalAirportIgnore as $airportIgnore) {
779
+				foreach ($globalAirportIgnore as $airportIgnore) {
780 780
 				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
781 781
 					$ignoreImport = true;
782 782
 				    }
783 783
 				}
784 784
 				if (count($globalAirportAccept) > 0) {
785 785
 				    $ignoreImport = true;
786
-				    foreach($globalAirportIgnore as $airportIgnore) {
786
+				    foreach ($globalAirportIgnore as $airportIgnore) {
787 787
 					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
788 788
 					    $ignoreImport = false;
789 789
 					}
790 790
 				    }
791 791
 				}
792 792
 				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
793
-				    foreach($globalAirlineIgnore as $airlineIgnore) {
794
-					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
793
+				    foreach ($globalAirlineIgnore as $airlineIgnore) {
794
+					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineIgnore)) {
795 795
 					    $ignoreImport = true;
796 796
 					}
797 797
 				    }
798 798
 				}
799 799
 				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
800 800
 				    $ignoreImport = true;
801
-				    foreach($globalAirlineAccept as $airlineAccept) {
802
-					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
801
+				    foreach ($globalAirlineAccept as $airlineAccept) {
802
+					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineAccept)) {
803 803
 					    $ignoreImport = false;
804 804
 					}
805 805
 				    }
806 806
 				}
807 807
 				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
808 808
 				    $ignoreImport = true;
809
-				    foreach($globalPilotIdAccept as $pilotIdAccept) {
809
+				    foreach ($globalPilotIdAccept as $pilotIdAccept) {
810 810
 					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
811 811
 					    $ignoreImport = false;
812 812
 					}
@@ -818,32 +818,32 @@  discard block
 block discarded – undo
818 818
 				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
819 819
 				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
820 820
 				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
821
-				    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')));
821
+				    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')));
822 822
 				    $timeelapsed = microtime(true);
823 823
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
824 824
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
825 825
 					    $Spotter = new Spotter($this->db);
826
-					    $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']);
826
+					    $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']);
827 827
 					    $Spotter->db = null;
828 828
 					    if ($globalDebug && isset($result)) echo $result."\n";
829 829
 					}
830 830
 				    }
831
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
831
+				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
832 832
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
833 833
 
834 834
 				    // Add source stat in DB
835 835
 				    $Stats = new Stats($this->db);
836 836
 				    if (!empty($this->stats)) {
837 837
 					if ($globalDebug) echo 'Add source stats : ';
838
-				        foreach($this->stats as $date => $data) {
839
-					    foreach($data as $source => $sourced) {
838
+				        foreach ($this->stats as $date => $data) {
839
+					    foreach ($data as $source => $sourced) {
840 840
 					        //print_r($sourced);
841
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
842
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
841
+				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']), $source, 'polar', $date);
842
+				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']), $source, 'hist', $date);
843 843
 				    		if (isset($sourced['msg'])) {
844 844
 				    		    if (time() - $sourced['msg']['date'] > 10) {
845 845
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
846
-				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
846
+				    		        echo $Stats->addStatSource($nbmsg, $source, 'msg', $date);
847 847
 			    			        unset($this->stats[$date][$source]['msg']);
848 848
 			    			    }
849 849
 			    			}
@@ -881,14 +881,14 @@  discard block
 block discarded – undo
881 881
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
882 882
 					    $SpotterLive = new SpotterLive($this->db);
883 883
 					    $SpotterLive->deleteLiveSpotterData();
884
-					    $SpotterLive->db=null;
884
+					    $SpotterLive->db = null;
885 885
 					}
886 886
 				    }
887 887
 				    if ($globalDebug) echo " Done\n";
888 888
 				    $this->last_delete = time();
889 889
 				}
890 890
 			    } else {
891
-				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'] === 'famaprs' || $line['format_source'] === 'airwhere')) {
891
+				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'] === 'famaprs' || $line['format_source'] === 'airwhere')) {
892 892
 				    $this->all_flights[$id]['id'] = $recent_ident;
893 893
 				    $this->all_flights[$id]['addedSpotter'] = 1;
894 894
 				}
@@ -896,7 +896,7 @@  discard block
 block discarded – undo
896 896
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
897 897
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
898 898
 					    $Spotter = new Spotter($this->db);
899
-					    $Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']);
899
+					    $Spotter->updateLatestSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['arrival_airport_time']);
900 900
 					    $Spotter->db = null;
901 901
 					}
902 902
 				    }
@@ -922,37 +922,37 @@  discard block
 block discarded – undo
922 922
 		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
923 923
 		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
924 924
 
925
-		    foreach($globalAirportIgnore as $airportIgnore) {
925
+		    foreach ($globalAirportIgnore as $airportIgnore) {
926 926
 		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
927 927
 			    $ignoreImport = true;
928 928
 			}
929 929
 		    }
930 930
 		    if (count($globalAirportAccept) > 0) {
931 931
 		        $ignoreImport = true;
932
-		        foreach($globalAirportIgnore as $airportIgnore) {
932
+		        foreach ($globalAirportIgnore as $airportIgnore) {
933 933
 			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
934 934
 				$ignoreImport = false;
935 935
 			    }
936 936
 			}
937 937
 		    }
938 938
 		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
939
-			foreach($globalAirlineIgnore as $airlineIgnore) {
940
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
939
+			foreach ($globalAirlineIgnore as $airlineIgnore) {
940
+			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineIgnore)) {
941 941
 				$ignoreImport = true;
942 942
 			    }
943 943
 			}
944 944
 		    }
945 945
 		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
946 946
 			$ignoreImport = true;
947
-			foreach($globalAirlineAccept as $airlineAccept) {
948
-			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
947
+			foreach ($globalAirlineAccept as $airlineAccept) {
948
+			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineAccept)) {
949 949
 				$ignoreImport = false;
950 950
 			    }
951 951
 			}
952 952
 		    }
953 953
 		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
954 954
 			$ignoreImport = true;
955
-			foreach($globalPilotIdAccept as $pilotIdAccept) {
955
+			foreach ($globalPilotIdAccept as $pilotIdAccept) {
956 956
 			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
957 957
 			        $ignoreImport = false;
958 958
 			    }
@@ -960,23 +960,23 @@  discard block
 block discarded – undo
960 960
 		    }
961 961
 
962 962
 		    if (!$ignoreImport) {
963
-			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'])) {
964
-				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')));
963
+			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'])) {
964
+				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')));
965 965
 				$timeelapsed = microtime(true);
966 966
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
967 967
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
968 968
 					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
969 969
 					$SpotterLive = new SpotterLive($this->db);
970
-					$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']);
970
+					$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']);
971 971
 					$SpotterLive->db = null;
972 972
 					if ($globalDebug) echo $result."\n";
973 973
 				    }
974 974
 				}
975 975
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) {
976
-					$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']);
976
+					$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']);
977 977
 				}
978 978
 				$this->all_flights[$id]['putinarchive'] = false;
979
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
979
+				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n";
980 980
 
981 981
 				// Put statistics in $this->stats variable
982 982
 				//if ($line['format_source'] != 'aprs') {
@@ -995,19 +995,19 @@  discard block
 block discarded – undo
995 995
 							$latitude = $globalCenterLatitude;
996 996
 							$longitude = $globalCenterLongitude;
997 997
 						}
998
-						$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude);
998
+						$this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude);
999 999
 					} else {
1000 1000
 						$latitude = $this->source_location[$source]['latitude'];
1001 1001
 						$longitude = $this->source_location[$source]['longitude'];
1002 1002
 					}
1003
-					$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
1003
+					$stats_heading = $Common->getHeading($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
1004 1004
 					//$stats_heading = $stats_heading%22.5;
1005 1005
 					$stats_heading = round($stats_heading/22.5);
1006
-					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
1006
+					$stats_distance = $Common->distance($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']);
1007 1007
 					$current_date = date('Y-m-d');
1008 1008
 					if ($stats_heading == 16) $stats_heading = 0;
1009 1009
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
1010
-						for ($i=0;$i<=15;$i++) {
1010
+						for ($i = 0; $i <= 15; $i++) {
1011 1011
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
1012 1012
 						}
1013 1013
 						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
@@ -1022,9 +1022,9 @@  discard block
 block discarded – undo
1022 1022
 					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
1023 1023
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
1024 1024
 						    end($this->stats[$current_date][$source]['hist']);
1025
-						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
1025
+						    $mini = key($this->stats[$current_date][$source]['hist']) + 10;
1026 1026
 						} else $mini = 0;
1027
-						for ($i=$mini;$i<=$distance;$i+=10) {
1027
+						for ($i = $mini; $i <= $distance; $i += 10) {
1028 1028
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
1029 1029
 						}
1030 1030
 						$this->stats[$current_date][$source]['hist'][$distance] = 1;
@@ -1037,7 +1037,7 @@  discard block
 block discarded – undo
1037 1037
 				$this->all_flights[$id]['lastupdate'] = time();
1038 1038
 				if ($this->all_flights[$id]['putinarchive']) $send = true;
1039 1039
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1040
-			} 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";
1040
+			} 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";
1041 1041
 			//$this->del();
1042 1042
 			
1043 1043
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
Please login to merge, or discard this patch.
Braces   +401 added lines, -143 removed lines patch added patch discarded remove patch
@@ -52,7 +52,9 @@  discard block
 block discarded – undo
52 52
 		try {
53 53
 			$GeoidClass = new GeoidHeight();
54 54
 		} catch(Exception $e) {
55
-			if ($globalDebug) echo "Can't calculate geoid, check that you downloaded it via update_db.php (".$e.")\n";
55
+			if ($globalDebug) {
56
+				echo "Can't calculate geoid, check that you downloaded it via update_db.php (".$e.")\n";
57
+			}
56 58
 			$GeoidClass = FALSE;
57 59
 		}
58 60
 	}
@@ -71,7 +73,9 @@  discard block
 block discarded – undo
71 73
 	$dbc = $this->db;
72 74
 	$this->all_flights[$id]['schedule_check'] = true;
73 75
 	if ($globalSchedulesFetch) {
74
-	if ($globalDebug) echo 'Getting schedule info...'."\n";
76
+	if ($globalDebug) {
77
+		echo 'Getting schedule info...'."\n";
78
+	}
75 79
 	$Spotter = new Spotter($dbc);
76 80
 	$Schedule = new Schedule($dbc);
77 81
 	$Translation = new Translation($dbc);
@@ -82,7 +86,9 @@  discard block
 block discarded – undo
82 86
 	    if ($Schedule->checkSchedule($operator) == 0) {
83 87
 		$schedule = $Schedule->fetchSchedule($operator);
84 88
 		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
85
-		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
89
+		    if ($globalDebug) {
90
+		    	echo "-> Schedule info for ".$operator." (".$ident.")\n";
91
+		    }
86 92
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
87 93
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
88 94
 		    // Should also check if route schedule = route from DB
@@ -91,7 +97,9 @@  discard block
 block discarded – undo
91 97
 			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
92 98
 			    if (trim($airport_icao) != '') {
93 99
 				$this->all_flights[$id]['departure_airport'] = $airport_icao;
94
-				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
100
+				if ($globalDebug) {
101
+					echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
102
+				}
95 103
 			    }
96 104
 			}
97 105
 		    }
@@ -100,17 +108,25 @@  discard block
 block discarded – undo
100 108
 			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
101 109
 			    if (trim($airport_icao) != '') {
102 110
 				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
103
-				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
111
+				if ($globalDebug) {
112
+					echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
113
+				}
104 114
 			    }
105 115
 			}
106 116
 		    }
107 117
 		    $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']);
108 118
 		}
109
-	    } else $scheduleexist = true;
110
-	} else $scheduleexist = true;
119
+	    } else {
120
+	    	$scheduleexist = true;
121
+	    }
122
+	} else {
123
+		$scheduleexist = true;
124
+	}
111 125
 	// close connection, at least one way will work ?
112 126
        if ($scheduleexist) {
113
-		if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";
127
+		if ($globalDebug) {
128
+			echo "-> get arrival/departure airport info for ".$ident."\n";
129
+		}
114 130
     		$sch = $Schedule->getSchedule($operator);
115 131
 		$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']));
116 132
        }
@@ -132,14 +148,18 @@  discard block
 block discarded – undo
132 148
 
133 149
     public function checkAll() {
134 150
 	global $globalDebug, $globalNoImport;
135
-	if ($globalDebug) echo "Update last seen flights data...\n";
151
+	if ($globalDebug) {
152
+		echo "Update last seen flights data...\n";
153
+	}
136 154
 	if (!isset($globalNoImport) || $globalNoImport === FALSE) {
137 155
 	    foreach ($this->all_flights as $key => $flight) {
138 156
 		if (isset($this->all_flights[$key]['id'])) {
139 157
 		    //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
140 158
     		    $Spotter = new Spotter($this->db);
141 159
         	    $real_arrival = $this->arrival($key);
142
-        	    if (isset($this->all_flights[$key]['altitude']) && isset($this->all_flights[$key]['datetime'])) $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']);
160
+        	    if (isset($this->all_flights[$key]['altitude']) && isset($this->all_flights[$key]['datetime'])) {
161
+        	    	$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']);
162
+        	    }
143 163
         	}
144 164
 	    }
145 165
 	}
@@ -147,24 +167,32 @@  discard block
 block discarded – undo
147 167
 
148 168
     public function arrival($key) {
149 169
 	global $globalClosestMinDist, $globalDebug;
150
-	if ($globalDebug) echo 'Update arrival...'."\n";
170
+	if ($globalDebug) {
171
+		echo 'Update arrival...'."\n";
172
+	}
151 173
 	$Spotter = new Spotter($this->db);
152 174
         $airport_icao = '';
153 175
         $airport_time = '';
154
-        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
176
+        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') {
177
+        	$globalClosestMinDist = 50;
178
+        }
155 179
 	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
156 180
 	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
157 181
     	    if (isset($closestAirports[0])) {
158 182
         	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
159 183
         	    $airport_icao = $closestAirports[0]['icao'];
160 184
         	    $airport_time = $this->all_flights[$key]['datetime'];
161
-        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
185
+        	    if ($globalDebug) {
186
+        	    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
187
+        	    }
162 188
         	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
163 189
         	    foreach ($closestAirports as $airport) {
164 190
         		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
165 191
         		    $airport_icao = $airport['icao'];
166 192
         		    $airport_time = $this->all_flights[$key]['datetime'];
167
-        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
193
+        		    if ($globalDebug) {
194
+        		    	echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
195
+        		    }
168 196
         		    break;
169 197
         		}
170 198
         	    }
@@ -172,14 +200,20 @@  discard block
 block discarded – undo
172 200
         		$airport_icao = $closestAirports[0]['icao'];
173 201
         		$airport_time = $this->all_flights[$key]['datetime'];
174 202
         	} else {
175
-        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
203
+        		if ($globalDebug) {
204
+        			echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
205
+        		}
176 206
         	}
177 207
     	    } else {
178
-    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
208
+    		    if ($globalDebug) {
209
+    		    	echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
210
+    		    }
179 211
     	    }
180 212
 
181 213
         } else {
182
-        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
214
+        	if ($globalDebug) {
215
+        		echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
216
+        	}
183 217
         }
184 218
         return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
185 219
     }
@@ -189,7 +223,9 @@  discard block
 block discarded – undo
189 223
     public function del() {
190 224
 	global $globalDebug, $globalNoImport, $globalNoDB;
191 225
 	// Delete old infos
192
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
226
+	if ($globalDebug) {
227
+		echo 'Delete old values and update latest data...'."\n";
228
+	}
193 229
 	foreach ($this->all_flights as $key => $flight) {
194 230
 	    if (isset($flight['lastupdate'])) {
195 231
 		if ($flight['lastupdate'] < (time()-5900)) {
@@ -203,13 +239,17 @@  discard block
 block discarded – undo
203 239
 	global $globalDebug, $globalNoImport, $globalNoDB;
204 240
 	// Delete old infos
205 241
 	if (isset($this->all_flights[$key]['id'])) {
206
-		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
242
+		if ($globalDebug) {
243
+			echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
244
+		}
207 245
 		if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
208 246
 			$real_arrival = $this->arrival($key);
209 247
 			$Spotter = new Spotter($this->db);
210 248
 			if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
211 249
 				$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']);
212
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
250
+				if ($globalDebug && $result != 'success') {
251
+					echo '!!! ERROR : '.$result."\n";
252
+				}
213 253
 			}
214 254
 		}
215 255
 	}
@@ -219,9 +259,13 @@  discard block
 block discarded – undo
219 259
     public function add($line) {
220 260
 	global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights, $globalServerAPRS, $APRSSpotter, $globalNoImport, $globalNoDB, $globalVA, $globalAircraftMaxUpdate, $globalAircraftMinUpdate, $globalLiveInterval, $GeoidClass;
221 261
 	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
222
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
223
-	if (!isset($globalAircraftMaxUpdate) || $globalAircraftMaxUpdate == '') $globalAircraftMaxUpdate = 3000;
224
-/*
262
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
263
+		$globalCoordMinChange = '0.02';
264
+	}
265
+	if (!isset($globalAircraftMaxUpdate) || $globalAircraftMaxUpdate == '') {
266
+		$globalAircraftMaxUpdate = 3000;
267
+	}
268
+	/*
225 269
 	$Spotter = new Spotter();
226 270
 	$dbc = $Spotter->db;
227 271
 	$SpotterLive = new SpotterLive($dbc);
@@ -243,19 +287,28 @@  discard block
 block discarded – undo
243 287
 	// SBS format is CSV format
244 288
 	if(is_array($line) && (isset($line['hex']) || isset($line['id']))) {
245 289
 	    //print_r($line);
246
-	    if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']);
290
+	    if (isset($line['hex'])) {
291
+	    	$line['hex'] = strtoupper($line['hex']);
292
+	    }
247 293
   	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) {
248 294
 
249 295
 		// Increment message number
250 296
 		if (isset($line['sourcestats']) && $line['sourcestats'] === TRUE) {
251 297
 		    $current_date = date('Y-m-d');
252
-		    if (isset($line['source_name'])) $source = $line['source_name'];
253
-		    else $source = '';
254
-		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
298
+		    if (isset($line['source_name'])) {
299
+		    	$source = $line['source_name'];
300
+		    } else {
301
+		    	$source = '';
302
+		    }
303
+		    if ($source == '' || $line['format_source'] == 'aprs') {
304
+		    	$source = $line['format_source'];
305
+		    }
255 306
 		    if (!isset($this->stats[$current_date][$source]['msg'])) {
256 307
 		    	$this->stats[$current_date][$source]['msg']['date'] = time();
257 308
 		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
258
-		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
309
+		    } else {
310
+		    	$this->stats[$current_date][$source]['msg']['nb'] += 1;
311
+		    }
259 312
 		}
260 313
 		
261 314
 		/*
@@ -271,23 +324,38 @@  discard block
 block discarded – undo
271 324
 		//$this->db = $dbc;
272 325
 
273 326
 		//$hex = trim($line['hex']);
274
-	        if (!isset($line['id'])) $id = trim($line['hex']);
275
-	        else $id = trim($line['id']);
327
+	        if (!isset($line['id'])) {
328
+	        	$id = trim($line['hex']);
329
+	        } else {
330
+	        	$id = trim($line['id']);
331
+	        }
276 332
 		
277 333
 		if (!isset($this->all_flights[$id])) {
278
-		    if ($globalDebug) echo 'New flight...'."\n";
334
+		    if ($globalDebug) {
335
+		    	echo 'New flight...'."\n";
336
+		    }
279 337
 		    $this->all_flights[$id] = array();
280 338
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
281 339
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '','altitude_previous' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => ''));
282
-		    if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
340
+		    if (isset($globalDaemon) && $globalDaemon === FALSE) {
341
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
342
+		    }
283 343
 		    if (!isset($line['id'])) {
284
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
285
-//			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')));
344
+			if (!isset($globalDaemon)) {
345
+				$globalDaemon = TRUE;
346
+			}
347
+			//			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')));
286 348
 //			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')));
287
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
349
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
350
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
351
+			}
288 352
 		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
289
-		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
290
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
353
+		     } else {
354
+		     	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
355
+		     }
356
+		    if ($globalAllFlights !== FALSE) {
357
+		    	$dataFound = true;
358
+		    }
291 359
 		}
292 360
 		if (isset($line['source_type']) && $line['source_type'] != '') {
293 361
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type']));
@@ -309,12 +377,20 @@  discard block
 block discarded – undo
309 377
 				$aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));
310 378
 			    }
311 379
 			    $Spotter->db = null;
312
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
313
-			    if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
380
+			    if ($globalDebugTimeElapsed) {
381
+			    	echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
382
+			    }
383
+			    if ($aircraft_icao != '') {
384
+			    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
385
+			    }
314 386
 			}
315 387
 		    }
316
-		    if ($globalAllFlights !== FALSE) $dataFound = true;
317
-		    if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
388
+		    if ($globalAllFlights !== FALSE) {
389
+		    	$dataFound = true;
390
+		    }
391
+		    if ($globalDebug) {
392
+		    	echo "*********** New aircraft hex : ".$line['hex']." ***********\n";
393
+		    }
318 394
 		}
319 395
 	        if (isset($line['id']) && !isset($line['hex'])) {
320 396
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => ''));
@@ -322,7 +398,9 @@  discard block
 block discarded – undo
322 398
 		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') {
323 399
 			$icao = $line['aircraft_icao'];
324 400
 			$Spotter = new Spotter($this->db);
325
-			if (isset($Spotter->aircraft_correct_icaotype[$icao])) $icao = $Spotter->aircraft_correct_icaotype[$icao];
401
+			if (isset($Spotter->aircraft_correct_icaotype[$icao])) {
402
+				$icao = $Spotter->aircraft_correct_icaotype[$icao];
403
+			}
326 404
 			$Spotter->db = null;
327 405
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $icao));
328 406
 		}
@@ -332,15 +410,24 @@  discard block
 block discarded – undo
332 410
 				$Spotter = new Spotter($this->db);
333 411
 				$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
334 412
 				$Spotter->db = null;
335
-				if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
413
+				if ($aircraft_icao != '') {
414
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
415
+				}
336 416
 			}
337 417
 		}
338 418
 		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) {
339
-			if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
340
-			elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
341
-			elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
342
-			elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
343
-			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
419
+			if ($line['aircraft_type'] == 'PARA_GLIDER') {
420
+				$aircraft_icao = 'GLID';
421
+			} elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') {
422
+				$aircraft_icao = 'UHEL';
423
+			} elseif ($line['aircraft_type'] == 'TOW_PLANE') {
424
+				$aircraft_icao = 'TOWPLANE';
425
+			} elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') {
426
+				$aircraft_icao = 'POWAIRC';
427
+			}
428
+			if (isset($aircraft_icao)) {
429
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
430
+			}
344 431
 		}
345 432
 		if (!isset($this->all_flights[$id]['aircraft_icao'])) {
346 433
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
@@ -350,8 +437,11 @@  discard block
 block discarded – undo
350 437
 		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
351 438
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
352 439
 		    } else {
353
-				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";
354
-				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";
440
+				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
441
+					echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
442
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) {
443
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
444
+				}
355 445
 				/*
356 446
 				echo strtotime($line['datetime']).' > '.strtotime($this->all_flights[$id]['datetime']);
357 447
 				print_r($this->all_flights[$id]);
@@ -360,16 +450,22 @@  discard block
 block discarded – undo
360 450
 				return '';
361 451
 		    }
362 452
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) {
363
-			if ($globalDebug) echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n";
453
+			if ($globalDebug) {
454
+				echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n";
455
+			}
364 456
 			return '';
365 457
 		} elseif (isset($line['datetime']) && strtotime($line['datetime']) > time()+20*60) {
366
-			if ($globalDebug) echo "!!! Date is in the future ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n";
458
+			if ($globalDebug) {
459
+				echo "!!! Date is in the future ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n";
460
+			}
367 461
 			return '';
368 462
 		} elseif (!isset($line['datetime'])) {
369 463
 			date_default_timezone_set('UTC');
370 464
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
371 465
 		} else {
372
-			if ($globalDebug) echo "!!! Unknow date error ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!";
466
+			if ($globalDebug) {
467
+				echo "!!! Unknow date error ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!";
468
+			}
373 469
 			return '';
374 470
 		}
375 471
 
@@ -390,30 +486,48 @@  discard block
 block discarded – undo
390 486
 
391 487
 		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
392 488
 			if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
393
-				if ($globalDebug) echo '---!!!! New ident, reset aircraft data...'."\n";
489
+				if ($globalDebug) {
490
+					echo '---!!!! New ident, reset aircraft data...'."\n";
491
+				}
394 492
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
395 493
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
396
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
397
-				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
398
-				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']));
494
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
495
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
496
+				} elseif (isset($line['id'])) {
497
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
498
+				} elseif (isset($this->all_flights[$id]['ident'])) {
499
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
500
+				}
399 501
 			} else {
400 502
 			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
401 503
 			    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
402 504
 				$timeelapsed = microtime(true);
403 505
             			$Spotter = new Spotter($this->db);
404 506
             			$fromsource = NULL;
405
-            			if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;
406
-            			elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';
407
-				elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';
408
-				elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';
409
-				elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';
507
+            			if (isset($globalAirlinesSource) && $globalAirlinesSource != '') {
508
+            				$fromsource = $globalAirlinesSource;
509
+            			} elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') {
510
+            				$fromsource = 'vatsim';
511
+            			} elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') {
512
+					$fromsource = 'ivao';
513
+				} elseif (isset($globalVATSIM) && $globalVATSIM) {
514
+					$fromsource = 'vatsim';
515
+				} elseif (isset($globalIVAO) && $globalIVAO) {
516
+					$fromsource = 'ivao';
517
+				}
410 518
             			$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);
411
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
519
+				if ($globalDebug && $result != 'success') {
520
+					echo '!!! ERROR : '.$result."\n";
521
+				}
412 522
 				$Spotter->db = null;
413
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
523
+				if ($globalDebugTimeElapsed) {
524
+					echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
525
+				}
414 526
 			    }
415 527
 			}
416
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
528
+		    } else {
529
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
530
+		    }
417 531
 		    
418 532
 /*
419 533
 		    if (!isset($line['id'])) {
@@ -423,7 +537,9 @@  discard block
 block discarded – undo
423 537
 		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
424 538
 		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
425 539
   */
426
-		    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']));
540
+		    if (!isset($this->all_flights[$id]['id'])) {
541
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
542
+		    }
427 543
 
428 544
 		    //$putinarchive = true;
429 545
 		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
@@ -441,7 +557,9 @@  discard block
 block discarded – undo
441 557
 				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
442 558
 				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
443 559
 		    		$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' => ''));
444
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
560
+				if ($globalDebugTimeElapsed) {
561
+					echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
562
+				}
445 563
                         }
446 564
 		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
447 565
 			$timeelapsed = microtime(true);
@@ -455,7 +573,9 @@  discard block
 block discarded – undo
455 573
 				$Translation->db = null;
456 574
 			    }
457 575
 			    $Spotter->db = null;
458
-			    if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
576
+			    if ($globalDebugTimeElapsed) {
577
+			    	echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
578
+			    }
459 579
                     	}
460 580
 			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
461 581
 			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
@@ -464,9 +584,13 @@  discard block
 block discarded – undo
464 584
 		    		$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']));
465 585
 		    	    }
466 586
 			}
467
-			if (!isset($globalFork)) $globalFork = TRUE;
587
+			if (!isset($globalFork)) {
588
+				$globalFork = TRUE;
589
+			}
468 590
 			if (!$globalVA && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
469
-				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));
591
+				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) {
592
+					$this->get_Schedule($id,trim($line['ident']));
593
+				}
470 594
 			}
471 595
 		    }
472 596
 		}
@@ -484,9 +608,13 @@  discard block
 block discarded – undo
484 608
 			$speed = $speed*3.6;
485 609
 			if ($speed < 1000) {
486 610
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
487
-	  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
611
+	  			if ($globalDebug) {
612
+	  				echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
613
+	  			}
488 614
 	  		} else {
489
-	  			if ($globalDebug) echo "ø IGNORED : Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
615
+	  			if ($globalDebug) {
616
+	  				echo "ø IGNORED : Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n";
617
+	  			}
490 618
 	  		}
491 619
 		    }
492 620
 		}
@@ -495,13 +623,21 @@  discard block
 block discarded – undo
495 623
 
496 624
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
497 625
 	    	    if (ctype_digit(strval($line['latitude'])) || ctype_digit(strval($line['longitude']))) {
498
-	    	    	if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
626
+	    	    	if ($globalDebug) {
627
+	    	    		echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n";
628
+	    	    	}
499 629
 	    	    	return false;
500 630
 	    	    }
501
-	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
502
-	    	    else unset($timediff);
503
-	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
504
-	    	    else unset($timediff_archive);
631
+	    	    if (isset($this->all_flights[$id]['time_last_coord'])) {
632
+	    	    	$timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
633
+	    	    } else {
634
+	    	    	unset($timediff);
635
+	    	    }
636
+	    	    if (isset($this->all_flights[$id]['time_last_archive_coord'])) {
637
+	    	    	$timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']);
638
+	    	    } else {
639
+	    	    	unset($timediff_archive);
640
+	    	    }
505 641
 	    	    if ($this->tmd > 5
506 642
 	    	        || (isset($line['format_source']) 
507 643
 	    	    	    && $line['format_source'] == 'airwhere' 
@@ -537,16 +673,25 @@  discard block
 block discarded – undo
537 673
 				$this->all_flights[$id]['putinarchive'] = true;
538 674
 				$this->tmd = 0;
539 675
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
540
-				    if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
676
+				    if ($globalDebug) {
677
+				    	echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
678
+				    }
541 679
 				    $timeelapsed = microtime(true);
542 680
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
543 681
 					$Spotter = new Spotter($this->db);
544 682
 					$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
545
-					if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
546
-					else $this->all_flights[$id]['over_country'] = '';
683
+					if (!empty($all_country)) {
684
+						$this->all_flights[$id]['over_country'] = $all_country['iso2'];
685
+					} else {
686
+						$this->all_flights[$id]['over_country'] = '';
687
+					}
547 688
 					$Spotter->db = null;
548
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
549
-					if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
689
+					if ($globalDebugTimeElapsed) {
690
+						echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
691
+					}
692
+					if ($globalDebug) {
693
+						echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
694
+					}
550 695
 				    }
551 696
 				}
552 697
 				$this->all_flights[$id]['time_last_archive_coord'] = time();
@@ -592,7 +737,9 @@  discard block
 block discarded – undo
592 737
 			    */
593 738
 			}
594 739
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
595
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
740
+			    if ($line['longitude'] > 180) {
741
+			    	$line['longitude'] = $line['longitude'] - 360;
742
+			    }
596 743
 			    //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) {
597 744
 				if (!isset($this->all_flights[$id]['archive_longitude'])) {
598 745
 					$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
@@ -629,7 +776,9 @@  discard block
 block discarded – undo
629 776
 		    }
630 777
 		}
631 778
 		if (isset($line['last_update']) && $line['last_update'] != '') {
632
-		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;
779
+		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) {
780
+		    	$dataFound = true;
781
+		    }
633 782
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update']));
634 783
 		}
635 784
 		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
@@ -651,35 +800,53 @@  discard block
 block discarded – undo
651 800
 			// Here we force archive of flight because after ground it's a new one (or should be)
652 801
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
653 802
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
654
-			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
655
-		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
656
-			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']));
803
+			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
804
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
805
+			} elseif (isset($line['id'])) {
806
+		        	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
807
+		        } elseif (isset($this->all_flights[$id]['ident'])) {
808
+				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
809
+			}
810
+		    }
811
+		    if ($line['ground'] != 1) {
812
+		    	$line['ground'] = 0;
657 813
 		    }
658
-		    if ($line['ground'] != 1) $line['ground'] = 0;
659 814
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
660 815
 		    //$dataFound = true;
661 816
 		}
662 817
 		if (isset($line['squawk']) && $line['squawk'] != '') {
663 818
 		    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'])) {
664
-			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;
819
+			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) {
820
+			    	$this->all_flights[$id]['putinarchive'] = true;
821
+			    }
665 822
 			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
666 823
 			    $highlight = '';
667
-			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
668
-			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
669
-			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
824
+			    if ($this->all_flights[$id]['squawk'] == '7500') {
825
+			    	$highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
826
+			    }
827
+			    if ($this->all_flights[$id]['squawk'] == '7600') {
828
+			    	$highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
829
+			    }
830
+			    if ($this->all_flights[$id]['squawk'] == '7700') {
831
+			    	$highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
832
+			    }
670 833
 			    if ($highlight != '') {
671 834
 				$timeelapsed = microtime(true);
672 835
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
673 836
 				    $Spotter = new Spotter($this->db);
674 837
 				    $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
675 838
 				    $Spotter->db = null;
676
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
839
+				    if ($globalDebugTimeElapsed) {
840
+				    	echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
841
+				    }
677 842
 				}
678 843
 				//$putinarchive = true;
679 844
 				//$highlight = '';
680 845
 			    }
681 846
 			    
682
-		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
847
+		    } else {
848
+		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
849
+		    }
683 850
 		    //$dataFound = true;
684 851
 		}
685 852
 
@@ -692,19 +859,27 @@  discard block
 block discarded – undo
692 859
 				}
693 860
 			}
694 861
 		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
695
-			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;
862
+			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) {
863
+				$this->all_flights[$id]['putinarchive'] = true;
864
+			}
696 865
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
697 866
 			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
698 867
 			//$dataFound = true;
699 868
 		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
700 869
 		    if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) {
701 870
 			if (isset($this->all_flights[$id]['over_country']) && $this->all_flights[$id]['over_country'] != '' && isset($this->all_flights[$id]['altitude_previous']) && $this->all_flights[$id]['altitude_previous'] != '' && $this->all_flights[$id]['altitude_previous'] < $this->all_flights[$id]['altitude_real'] && isset($this->all_flights[$id]['lastupdate']) && $this->all_flights[$id]['lastupdate'] < time() - 1600) {
702
-				if ($globalDebug) echo '--- Reset because of altitude'."\n";
871
+				if ($globalDebug) {
872
+					echo '--- Reset because of altitude'."\n";
873
+				}
703 874
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
704 875
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
705
-				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
706
-				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
707
-				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']));
876
+				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
877
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi')));
878
+				} elseif (isset($line['id'])) {
879
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
880
+				} elseif (isset($this->all_flights[$id]['ident'])) {
881
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
882
+				}
708 883
 			}
709 884
 		    }
710 885
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude']));
@@ -715,22 +890,32 @@  discard block
 block discarded – undo
715 890
 		}
716 891
 		
717 892
 		if (isset($line['heading']) && $line['heading'] != '') {
718
-		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;
893
+		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) {
894
+		    	$this->all_flights[$id]['putinarchive'] = true;
895
+		    }
719 896
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
720 897
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
721 898
 		    //$dataFound = true;
722 899
   		} 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']) {
723 900
   		    $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']);
724 901
 		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
725
-		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;
726
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['id']." : ".$heading."\n";
902
+		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) {
903
+		    	$this->all_flights[$id]['putinarchive'] = true;
904
+		    }
905
+  		    if ($globalDebug) {
906
+  		    	echo "ø Calculated Heading for ".$this->all_flights[$id]['id']." : ".$heading."\n";
907
+  		    }
727 908
   		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
728 909
   		    // If not enough messages and ACARS set heading to 0
729 910
   		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
730 911
   		}
731
-		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
732
-		elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
733
-		elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalAircraftMinupdate) $dataFound = false;
912
+		if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) {
913
+			$dataFound = false;
914
+		} elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) {
915
+			$dataFound = false;
916
+		} elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalAircraftMinupdate) {
917
+			$dataFound = false;
918
+		}
734 919
 
735 920
 //		print_r($this->all_flights[$id]);
736 921
 		//gets the callsign from the last hour
@@ -747,23 +932,38 @@  discard block
 block discarded – undo
747 932
 			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
748 933
 			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
749 934
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
750
-				    if ($globalDebug) echo "Check if aircraft is already in DB...";
935
+				    if ($globalDebug) {
936
+				    	echo "Check if aircraft is already in DB...";
937
+				    }
751 938
 				    $timeelapsed = microtime(true);
752 939
 				    $SpotterLive = new SpotterLive($this->db);
753 940
 				    if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) {
754 941
 					$recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
755
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
942
+					if ($globalDebugTimeElapsed) {
943
+						echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
944
+					}
756 945
 				    } elseif (isset($line['id'])) {
757 946
 					$recent_ident = $SpotterLive->checkIdRecent($line['id']);
758
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
947
+					if ($globalDebugTimeElapsed) {
948
+						echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
949
+					}
759 950
 				    } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
760 951
 					$recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
761
-					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
762
-				    } else $recent_ident = '';
952
+					if ($globalDebugTimeElapsed) {
953
+						echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
954
+					}
955
+				    } else {
956
+				    	$recent_ident = '';
957
+				    }
763 958
 				    $SpotterLive->db=null;
764
-				    if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
765
-				    elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
766
-				} else $recent_ident = '';
959
+				    if ($globalDebug && $recent_ident == '') {
960
+				    	echo " Not in DB.\n";
961
+				    } elseif ($globalDebug && $recent_ident != '') {
962
+				    	echo " Already in DB.\n";
963
+				    }
964
+				} else {
965
+					$recent_ident = '';
966
+				}
767 967
 			    } else {
768 968
 				$recent_ident = '';
769 969
 				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
@@ -771,7 +971,9 @@  discard block
 block discarded – undo
771 971
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
772 972
 			    if($recent_ident == "")
773 973
 			    {
774
-				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
974
+				if ($globalDebug) {
975
+					echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
976
+				}
775 977
 				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
776 978
 				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
777 979
 				//adds the spotter data for the archive
@@ -815,31 +1017,49 @@  discard block
 block discarded – undo
815 1017
 				
816 1018
 				if (!$ignoreImport) {
817 1019
 				    $highlight = '';
818
-				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
819
-				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
820
-				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
821
-				    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')));
1020
+				    if ($this->all_flights[$id]['squawk'] == '7500') {
1021
+				    	$highlight = 'Squawk 7500 : Hijack';
1022
+				    }
1023
+				    if ($this->all_flights[$id]['squawk'] == '7600') {
1024
+				    	$highlight = 'Squawk 7600 : Lost Comm (radio failure)';
1025
+				    }
1026
+				    if ($this->all_flights[$id]['squawk'] == '7700') {
1027
+				    	$highlight = 'Squawk 7700 : Emergency';
1028
+				    }
1029
+				    if (!isset($this->all_flights[$id]['id'])) {
1030
+				    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
1031
+				    }
822 1032
 				    $timeelapsed = microtime(true);
823 1033
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
824 1034
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
825 1035
 					    $Spotter = new Spotter($this->db);
826 1036
 					    $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']);
827 1037
 					    $Spotter->db = null;
828
-					    if ($globalDebug && isset($result)) echo $result."\n";
1038
+					    if ($globalDebug && isset($result)) {
1039
+					    	echo $result."\n";
1040
+					    }
829 1041
 					}
830 1042
 				    }
831
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1043
+				    if ($globalDebugTimeElapsed) {
1044
+				    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1045
+				    }
832 1046
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
833 1047
 
834 1048
 				    // Add source stat in DB
835 1049
 				    $Stats = new Stats($this->db);
836 1050
 				    if (!empty($this->stats)) {
837
-					if ($globalDebug) echo 'Add source stats : ';
1051
+					if ($globalDebug) {
1052
+						echo 'Add source stats : ';
1053
+					}
838 1054
 				        foreach($this->stats as $date => $data) {
839 1055
 					    foreach($data as $source => $sourced) {
840 1056
 					        //print_r($sourced);
841
-				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
842
-				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
1057
+				    	        if (isset($sourced['polar'])) {
1058
+				    	        	echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
1059
+				    	        }
1060
+				    	        if (isset($sourced['hist'])) {
1061
+				    	        	echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
1062
+				    	        }
843 1063
 				    		if (isset($sourced['msg'])) {
844 1064
 				    		    if (time() - $sourced['msg']['date'] > 10) {
845 1065
 				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
@@ -852,13 +1072,17 @@  discard block
 block discarded – undo
852 1072
 			    			unset($this->stats[$date]);
853 1073
 			    		    }
854 1074
 				    	}
855
-				    	if ($globalDebug) echo 'Done'."\n";
1075
+				    	if ($globalDebug) {
1076
+				    		echo 'Done'."\n";
1077
+				    	}
856 1078
 
857 1079
 				    }
858 1080
 				    $Stats->db = null;
859 1081
 				    }
860 1082
 				    $this->del();
861
-				} elseif ($globalDebug) echo 'Ignore data'."\n";
1083
+				} elseif ($globalDebug) {
1084
+					echo 'Ignore data'."\n";
1085
+				}
862 1086
 				//$ignoreImport = false;
863 1087
 				$this->all_flights[$id]['addedSpotter'] = 1;
864 1088
 				//print_r($this->all_flights[$id]);
@@ -875,7 +1099,9 @@  discard block
 block discarded – undo
875 1099
 			*/
876 1100
 			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
877 1101
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
878
-				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
1102
+				    if ($globalDebug) {
1103
+				    	echo "---- Deleting Live Spotter data older than 9 hours...";
1104
+				    }
879 1105
 				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
880 1106
 				    if (!isset($globalNoImport) || $globalNoImport === FALSE) {
881 1107
 					if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
@@ -884,7 +1110,9 @@  discard block
 block discarded – undo
884 1110
 					    $SpotterLive->db=null;
885 1111
 					}
886 1112
 				    }
887
-				    if ($globalDebug) echo " Done\n";
1113
+				    if ($globalDebug) {
1114
+				    	echo " Done\n";
1115
+				    }
888 1116
 				    $this->last_delete = time();
889 1117
 				}
890 1118
 			    } else {
@@ -911,11 +1139,17 @@  discard block
 block discarded – undo
911 1139
 		    //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";
912 1140
 		    if ($globalDebug) {
913 1141
 			if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) {
914
-				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";
915
-				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";
1142
+				if (isset($this->all_flights[$id]['source_name'])) {
1143
+					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";
1144
+				} else {
1145
+					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";
1146
+				}
916 1147
 			} else {
917
-				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";
918
-				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";
1148
+				if (isset($this->all_flights[$id]['source_name'])) {
1149
+					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";
1150
+				} else {
1151
+					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";
1152
+				}
919 1153
 			}
920 1154
 		    }
921 1155
 		    $ignoreImport = false;
@@ -961,22 +1195,30 @@  discard block
 block discarded – undo
961 1195
 
962 1196
 		    if (!$ignoreImport) {
963 1197
 			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'])) {
964
-				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')));
1198
+				if (!isset($this->all_flights[$id]['id'])) {
1199
+					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
1200
+				}
965 1201
 				$timeelapsed = microtime(true);
966 1202
 				if (!isset($globalNoImport) || $globalNoImport === FALSE) {
967 1203
 				    if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
968
-					if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1204
+					if ($globalDebug) {
1205
+						echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
1206
+					}
969 1207
 					$SpotterLive = new SpotterLive($this->db);
970 1208
 					$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']);
971 1209
 					$SpotterLive->db = null;
972
-					if ($globalDebug) echo $result."\n";
1210
+					if ($globalDebug) {
1211
+						echo $result."\n";
1212
+					}
973 1213
 				    }
974 1214
 				}
975 1215
 				if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) {
976 1216
 					$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']);
977 1217
 				}
978 1218
 				$this->all_flights[$id]['putinarchive'] = false;
979
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1219
+				if ($globalDebugTimeElapsed) {
1220
+					echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
1221
+				}
980 1222
 
981 1223
 				// Put statistics in $this->stats variable
982 1224
 				//if ($line['format_source'] != 'aprs') {
@@ -984,7 +1226,9 @@  discard block
 block discarded – undo
984 1226
 				if (!isset($globalNoDB) || $globalNoDB !== TRUE) {
985 1227
 				    if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
986 1228
 					$source = $this->all_flights[$id]['source_name'];
987
-					if ($source == '') $source = $this->all_flights[$id]['format_source'];
1229
+					if ($source == '') {
1230
+						$source = $this->all_flights[$id]['format_source'];
1231
+					}
988 1232
 					if (!isset($this->source_location[$source])) {
989 1233
 						$Location = new Source($this->db);
990 1234
 						$coord = $Location->getLocationInfobySourceName($source);
@@ -1005,7 +1249,9 @@  discard block
 block discarded – undo
1005 1249
 					$stats_heading = round($stats_heading/22.5);
1006 1250
 					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
1007 1251
 					$current_date = date('Y-m-d');
1008
-					if ($stats_heading == 16) $stats_heading = 0;
1252
+					if ($stats_heading == 16) {
1253
+						$stats_heading = 0;
1254
+					}
1009 1255
 					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
1010 1256
 						for ($i=0;$i<=15;$i++) {
1011 1257
 						    $this->stats[$current_date][$source]['polar'][$i] = 0;
@@ -1023,7 +1269,9 @@  discard block
 block discarded – undo
1023 1269
 						if (isset($this->stats[$current_date][$source]['hist'][0])) {
1024 1270
 						    end($this->stats[$current_date][$source]['hist']);
1025 1271
 						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
1026
-						} else $mini = 0;
1272
+						} else {
1273
+							$mini = 0;
1274
+						}
1027 1275
 						for ($i=$mini;$i<=$distance;$i+=10) {
1028 1276
 						    $this->stats[$current_date][$source]['hist'][$i] = 0;
1029 1277
 						}
@@ -1035,19 +1283,27 @@  discard block
 block discarded – undo
1035 1283
 				}
1036 1284
 
1037 1285
 				$this->all_flights[$id]['lastupdate'] = time();
1038
-				if ($this->all_flights[$id]['putinarchive']) $send = true;
1286
+				if ($this->all_flights[$id]['putinarchive']) {
1287
+					$send = true;
1288
+				}
1039 1289
 				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1040
-			} 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";
1290
+			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
1291
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
1292
+			}
1041 1293
 			//$this->del();
1042 1294
 			
1043 1295
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
1044 1296
 			    if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) {
1045
-				if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1297
+				if ($globalDebug) {
1298
+					echo "---- Deleting Live Spotter data Not updated since 2 hour...";
1299
+				}
1046 1300
 				$SpotterLive = new SpotterLive($this->db);
1047 1301
 				$SpotterLive->deleteLiveSpotterDataNotUpdated();
1048 1302
 				$SpotterLive->db = null;
1049 1303
 				//SpotterLive->deleteLiveSpotterData();
1050
-				if ($globalDebug) echo " Done\n";
1304
+				if ($globalDebug) {
1305
+					echo " Done\n";
1306
+				}
1051 1307
 				$this->last_delete_hourly = time();
1052 1308
 			    } else {
1053 1309
 				$this->del();
@@ -1059,7 +1315,9 @@  discard block
 block discarded – undo
1059 1315
 		    //$ignoreImport = false;
1060 1316
 		}
1061 1317
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
1062
-		if ($send) return $this->all_flights[$id];
1318
+		if ($send) {
1319
+			return $this->all_flights[$id];
1320
+		}
1063 1321
 	    }
1064 1322
 	}
1065 1323
     }
Please login to merge, or discard this patch.