@@ -30,12 +30,12 @@ discard block |
||
30 | 30 | $currentdate = date('Y-m-d'); |
31 | 31 | $sourcestat = $Stats->getStatsSource($currentdate); |
32 | 32 | if (!empty($sourcestat)) { |
33 | - foreach($sourcestat as $srcst) { |
|
33 | + foreach ($sourcestat as $srcst) { |
|
34 | 34 | $type = $srcst['stats_type']; |
35 | 35 | if ($type == 'polar' || $type == 'hist') { |
36 | 36 | $source = $srcst['source_name']; |
37 | 37 | $data = $srcst['source_data']; |
38 | - $this->stats[$currentdate][$source][$type] = json_decode($data,true); |
|
38 | + $this->stats[$currentdate][$source][$type] = json_decode($data, true); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | |
47 | 47 | } |
48 | 48 | |
49 | - public function get_Schedule($id,$ident) { |
|
49 | + public function get_Schedule($id, $ident) { |
|
50 | 50 | global $globalDebug, $globalFork, $globalSchedulesFetch; |
51 | 51 | // Get schedule here, so it's done only one time |
52 | 52 | |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | $schedule = $Schedule->fetchSchedule($operator); |
72 | 72 | if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) { |
73 | 73 | if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n"; |
74 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime'])); |
|
75 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime'])); |
|
74 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $schedule['DepartureTime'])); |
|
75 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $schedule['ArrivalTime'])); |
|
76 | 76 | // Should also check if route schedule = route from DB |
77 | 77 | if ($schedule['DepartureAirportIATA'] != '') { |
78 | 78 | if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) { |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | } |
93 | 93 | } |
94 | 94 | } |
95 | - $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']); |
|
95 | + $Schedule->addSchedule($operator, $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['arrival_airport_time'], $schedule['Source']); |
|
96 | 96 | } |
97 | 97 | } else $scheduleexist = true; |
98 | 98 | } else $scheduleexist = true; |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | if ($scheduleexist) { |
101 | 101 | if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n"; |
102 | 102 | $sch = $Schedule->getSchedule($operator); |
103 | - $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'])); |
|
103 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport' => $sch['arrival_airport_icao'], 'departure_airport' => $sch['departure_airport_icao'], 'departure_airport_time' => $sch['departure_airport_time'], 'arrival_airport_time' => $sch['arrival_airport_time'])); |
|
104 | 104 | } |
105 | 105 | $Spotter->db = null; |
106 | 106 | $Schedule->db = null; |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].' '.$this->all_flights[$key]['longitude']."\n"; |
128 | 128 | $Spotter = new Spotter($this->db); |
129 | 129 | $real_arrival = $this->arrival($key); |
130 | - $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']); |
|
130 | + $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']); |
|
131 | 131 | } |
132 | 132 | } |
133 | 133 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | $airport_time = ''; |
142 | 142 | if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50; |
143 | 143 | if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { |
144 | - $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist); |
|
144 | + $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $globalClosestMinDist); |
|
145 | 145 | if (isset($closestAirports[0])) { |
146 | 146 | if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) { |
147 | 147 | $airport_icao = $closestAirports[0]['icao']; |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | break; |
157 | 157 | } |
158 | 158 | } |
159 | - } 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))) { |
|
159 | + } 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))) { |
|
160 | 160 | $airport_icao = $closestAirports[0]['icao']; |
161 | 161 | $airport_time = $this->all_flights[$key]['datetime']; |
162 | 162 | } else { |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | } else { |
170 | 170 | if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n"; |
171 | 171 | } |
172 | - return array('airport_icao' => $airport_icao,'airport_time' => $airport_time); |
|
172 | + return array('airport_icao' => $airport_icao, 'airport_time' => $airport_time); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
181 | 181 | foreach ($this->all_flights as $key => $flight) { |
182 | 182 | if (isset($flight['lastupdate'])) { |
183 | - if ($flight['lastupdate'] < (time()-3000)) { |
|
183 | + if ($flight['lastupdate'] < (time() - 3000)) { |
|
184 | 184 | if (isset($this->all_flights[$key]['id'])) { |
185 | 185 | if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n"; |
186 | 186 | /* |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | $real_arrival = $this->arrival($key); |
193 | 193 | $Spotter = new Spotter($this->db); |
194 | 194 | if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { |
195 | - $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']); |
|
195 | + $result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'], $this->all_flights[$key]['ident'], $this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $this->all_flights[$key]['altitude'], $this->all_flights[$key]['ground'], $this->all_flights[$key]['speed'], $this->all_flights[$key]['datetime'], $real_arrival['airport_icao'], $real_arrival['airport_time']); |
|
196 | 196 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
197 | 197 | } |
198 | 198 | // Put in archive |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | $send = false; |
230 | 230 | |
231 | 231 | // SBS format is CSV format |
232 | - if(is_array($line) && (isset($line['hex']) || isset($line['id']))) { |
|
232 | + if (is_array($line) && (isset($line['hex']) || isset($line['id']))) { |
|
233 | 233 | //print_r($line); |
234 | 234 | 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)) { |
235 | 235 | |
@@ -262,25 +262,25 @@ discard block |
||
262 | 262 | |
263 | 263 | if (!isset($this->all_flights[$id])) { |
264 | 264 | $this->all_flights[$id] = array(); |
265 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
|
266 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => '')); |
|
267 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time())); |
|
265 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0)); |
|
266 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => '', 'departure_airport' => '', 'arrival_airport' => '', 'latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '', 'altitude_real' => '', 'heading' => '', 'departure_airport_time' => '', 'arrival_airport_time' => '', 'squawk' => '', 'route_stop' => '', 'registration' => '', 'pilot_id' => '', 'pilot_name' => '', 'waypoints' => '', 'ground' => '0', 'format_source' => '', 'source_name' => '', 'over_country' => '', 'verticalrate' => '', 'noarchive' => false, 'putinarchive' => true, 'source_type' => '')); |
|
267 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('lastupdate' => time())); |
|
268 | 268 | if (!isset($line['id'])) { |
269 | 269 | if (!isset($globalDaemon)) $globalDaemon = TRUE; |
270 | 270 | // if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi'))); |
271 | 271 | // if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
272 | - if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
272 | + if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $id.'-'.date('YmdHi'))); |
|
273 | 273 | //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
274 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
274 | + } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id'])); |
|
275 | 275 | if ($globalAllFlights !== FALSE) $dataFound = true; |
276 | 276 | } |
277 | 277 | if (isset($line['source_type']) && $line['source_type'] != '') { |
278 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type'])); |
|
278 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('source_type' => $line['source_type'])); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | //print_r($this->all_flights); |
282 | 282 | if (isset($line['hex']) && !isset($this->all_flights[$id]['hex']) && ctype_xdigit($line['hex'])) { |
283 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex']))); |
|
283 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('hex' => trim($line['hex']))); |
|
284 | 284 | //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) { |
285 | 285 | //$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime'])); |
286 | 286 | //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s'))); |
@@ -288,41 +288,41 @@ discard block |
||
288 | 288 | $timeelapsed = microtime(true); |
289 | 289 | $Spotter = new Spotter($this->db); |
290 | 290 | if (isset($this->all_flights[$id]['source_type'])) { |
291 | - $aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']),$this->all_flights[$id]['source_type']); |
|
291 | + $aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']), $this->all_flights[$id]['source_type']); |
|
292 | 292 | } else { |
293 | 293 | $aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex'])); |
294 | 294 | } |
295 | 295 | $Spotter->db = null; |
296 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
297 | - if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
296 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
297 | + if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao)); |
|
298 | 298 | } |
299 | 299 | if ($globalAllFlights !== FALSE) $dataFound = true; |
300 | 300 | if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n"; |
301 | 301 | } |
302 | 302 | if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') { |
303 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao'])); |
|
303 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $line['aircraft_icao'])); |
|
304 | 304 | } |
305 | 305 | if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_name'])) { |
306 | 306 | // Get aircraft ICAO from aircraft name |
307 | 307 | $Spotter = new Spotter($this->db); |
308 | 308 | $aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']); |
309 | 309 | $Spotter->db = null; |
310 | - if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
310 | + if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao)); |
|
311 | 311 | } |
312 | 312 | if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) { |
313 | 313 | if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID'; |
314 | 314 | elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL'; |
315 | 315 | elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE'; |
316 | 316 | elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC'; |
317 | - if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
317 | + if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao)); |
|
318 | 318 | } |
319 | 319 | if (!isset($this->all_flights[$id]['aircraft_icao'])) { |
320 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA')); |
|
320 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => 'NA')); |
|
321 | 321 | } |
322 | 322 | //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) { |
323 | - if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60) { |
|
323 | + if (isset($line['datetime']) && strtotime($line['datetime']) > time() - 20*60) { |
|
324 | 324 | if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) { |
325 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime'])); |
|
325 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => $line['datetime'])); |
|
326 | 326 | } else { |
327 | 327 | if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
328 | 328 | elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
@@ -335,24 +335,24 @@ discard block |
||
335 | 335 | } |
336 | 336 | } else { |
337 | 337 | date_default_timezone_set('UTC'); |
338 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s'))); |
|
338 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => date('Y-m-d H:i:s'))); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') { |
342 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration'])); |
|
342 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('registration' => $line['registration'])); |
|
343 | 343 | } |
344 | 344 | if (isset($line['waypoints']) && $line['waypoints'] != '') { |
345 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints'])); |
|
345 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('waypoints' => $line['waypoints'])); |
|
346 | 346 | } |
347 | 347 | if (isset($line['pilot_id']) && $line['pilot_id'] != '') { |
348 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id'])); |
|
348 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_id' => $line['pilot_id'])); |
|
349 | 349 | } |
350 | 350 | if (isset($line['pilot_name']) && $line['pilot_name'] != '') { |
351 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name'])); |
|
351 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_name' => $line['pilot_name'])); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | 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'])) { |
355 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident']))); |
|
355 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => trim($line['ident']))); |
|
356 | 356 | if ($this->all_flights[$id]['addedSpotter'] == 1) { |
357 | 357 | $timeelapsed = microtime(true); |
358 | 358 | $Spotter = new Spotter($this->db); |
@@ -362,10 +362,10 @@ discard block |
||
362 | 362 | elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao'; |
363 | 363 | elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim'; |
364 | 364 | elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao'; |
365 | - $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource); |
|
365 | + $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $fromsource); |
|
366 | 366 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
367 | 367 | $Spotter->db = null; |
368 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
368 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | /* |
@@ -376,24 +376,24 @@ discard block |
||
376 | 376 | else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
377 | 377 | } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
378 | 378 | */ |
379 | - if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
379 | + if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
380 | 380 | |
381 | 381 | //$putinarchive = true; |
382 | 382 | if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) { |
383 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time'])); |
|
383 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $line['departure_airport_time'])); |
|
384 | 384 | } |
385 | 385 | if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) { |
386 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time'])); |
|
386 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $line['arrival_airport_time'])); |
|
387 | 387 | } |
388 | 388 | if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) { |
389 | - $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' => '')); |
|
389 | + $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' => '')); |
|
390 | 390 | } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) { |
391 | 391 | $timeelapsed = microtime(true); |
392 | 392 | $Spotter = new Spotter($this->db); |
393 | 393 | $line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']); |
394 | 394 | $line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']); |
395 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => '')); |
|
396 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
395 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport' => $line['departure_airport_icao'], 'arrival_airport' => $line['arrival_airport_icao'], 'route_stop' => '')); |
|
396 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
397 | 397 | |
398 | 398 | } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') { |
399 | 399 | $timeelapsed = microtime(true); |
@@ -406,34 +406,34 @@ discard block |
||
406 | 406 | $Translation->db = null; |
407 | 407 | } |
408 | 408 | $Spotter->db = null; |
409 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
409 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
410 | 410 | |
411 | 411 | if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) { |
412 | 412 | //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) { |
413 | 413 | if ($route['fromairport_icao'] != $route['toairport_icao']) { |
414 | 414 | // $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'])); |
415 | - $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'])); |
|
415 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport' => $route['fromairport_icao'], 'arrival_airport' => $route['toairport_icao'], 'route_stop' => $route['routestop'])); |
|
416 | 416 | } |
417 | 417 | } |
418 | 418 | if (!isset($globalFork)) $globalFork = TRUE; |
419 | 419 | if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) { |
420 | - if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident'])); |
|
420 | + if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id, trim($line['ident'])); |
|
421 | 421 | } |
422 | 422 | } |
423 | 423 | } |
424 | 424 | |
425 | 425 | if (isset($line['speed']) && $line['speed'] != '') { |
426 | 426 | // $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12])); |
427 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed']))); |
|
428 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true)); |
|
427 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($line['speed']))); |
|
428 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed_fromsrc' => true)); |
|
429 | 429 | //$dataFound = true; |
430 | 430 | } 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'])) { |
431 | - $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'); |
|
431 | + $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm'); |
|
432 | 432 | if ($distance > 1000 && $distance < 10000) { |
433 | 433 | // use datetime |
434 | 434 | $speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']); |
435 | 435 | $speed = $speed*3.6; |
436 | - if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed))); |
|
436 | + if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($speed))); |
|
437 | 437 | if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
438 | 438 | } |
439 | 439 | } |
@@ -441,11 +441,11 @@ discard block |
||
441 | 441 | |
442 | 442 | |
443 | 443 | if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
444 | - if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']); |
|
444 | + if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time() - $this->all_flights[$id]['time_last_coord']); |
|
445 | 445 | else unset($timediff); |
446 | - if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) { |
|
446 | + if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff, $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')))) { |
|
447 | 447 | if (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude'])) { |
448 | - if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) { |
|
448 | + if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'], $this->all_flights[$id]['archive_longitude'], $this->all_flights[$id]['livedb_latitude'], $this->all_flights[$id]['livedb_longitude'], $line['latitude'], $line['longitude'])) { |
|
449 | 449 | $this->all_flights[$id]['archive_latitude'] = $line['latitude']; |
450 | 450 | $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
451 | 451 | $this->all_flights[$id]['putinarchive'] = true; |
@@ -453,10 +453,10 @@ discard block |
||
453 | 453 | if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
454 | 454 | $timeelapsed = microtime(true); |
455 | 455 | $Spotter = new Spotter($this->db); |
456 | - $all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
|
456 | + $all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']); |
|
457 | 457 | if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2']; |
458 | 458 | $Spotter->db = null; |
459 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
459 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
460 | 460 | $this->tmd = 0; |
461 | 461 | if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n"; |
462 | 462 | } |
@@ -465,13 +465,13 @@ discard block |
||
465 | 465 | if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
466 | 466 | //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) { |
467 | 467 | if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude']; |
468 | - 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') { |
|
468 | + 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') { |
|
469 | 469 | $this->all_flights[$id]['livedb_latitude'] = $line['latitude']; |
470 | 470 | $dataFound = true; |
471 | 471 | $this->all_flights[$id]['time_last_coord'] = time(); |
472 | 472 | } |
473 | 473 | // elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n"; |
474 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude'])); |
|
474 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('latitude' => $line['latitude'])); |
|
475 | 475 | /* |
476 | 476 | if (abs($this->all_flights[$id]['archive_latitude']-$this->all_flights[$id]['latitude']) > 0.3) { |
477 | 477 | $this->all_flights[$id]['archive_latitude'] = $line['latitude']; |
@@ -489,13 +489,13 @@ discard block |
||
489 | 489 | if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
490 | 490 | //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) { |
491 | 491 | if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
492 | - 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') { |
|
492 | + 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') { |
|
493 | 493 | $this->all_flights[$id]['livedb_longitude'] = $line['longitude']; |
494 | 494 | $dataFound = true; |
495 | 495 | $this->all_flights[$id]['time_last_coord'] = time(); |
496 | 496 | } |
497 | 497 | // elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n"; |
498 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude'])); |
|
498 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('longitude' => $line['longitude'])); |
|
499 | 499 | /* |
500 | 500 | if (abs($this->all_flights[$id]['archive_longitude']-$this->all_flights[$id]['longitude']) > 0.3) { |
501 | 501 | $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
@@ -513,46 +513,46 @@ discard block |
||
513 | 513 | } else if ($globalDebug && $timediff > 20) { |
514 | 514 | $this->tmd = $this->tmd + 1; |
515 | 515 | echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n"; |
516 | - echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -"; |
|
517 | - echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - "; |
|
516 | + echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')."m -"; |
|
517 | + echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - "; |
|
518 | 518 | echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n"; |
519 | 519 | } |
520 | 520 | } |
521 | 521 | if (isset($line['last_update']) && $line['last_update'] != '') { |
522 | 522 | if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true; |
523 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update'])); |
|
523 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('last_update' => $line['last_update'])); |
|
524 | 524 | } |
525 | 525 | if (isset($line['verticalrate']) && $line['verticalrate'] != '') { |
526 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate'])); |
|
526 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('verticalrate' => $line['verticalrate'])); |
|
527 | 527 | //$dataFound = true; |
528 | 528 | } |
529 | 529 | if (isset($line['format_source']) && $line['format_source'] != '') { |
530 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source'])); |
|
530 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('format_source' => $line['format_source'])); |
|
531 | 531 | } |
532 | 532 | if (isset($line['source_name']) && $line['source_name'] != '') { |
533 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name'])); |
|
533 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('source_name' => $line['source_name'])); |
|
534 | 534 | } |
535 | 535 | if (isset($line['emergency']) && $line['emergency'] != '') { |
536 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency'])); |
|
536 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('emergency' => $line['emergency'])); |
|
537 | 537 | //$dataFound = true; |
538 | 538 | } |
539 | 539 | if (isset($line['ground']) && $line['ground'] != '') { |
540 | 540 | if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) { |
541 | 541 | // Here we force archive of flight because after ground it's a new one (or should be) |
542 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
|
543 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1)); |
|
544 | - if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi'))); |
|
545 | - elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
546 | - 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'])); |
|
542 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0)); |
|
543 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1)); |
|
544 | + if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi'))); |
|
545 | + elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id'])); |
|
546 | + 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'])); |
|
547 | 547 | } |
548 | 548 | if ($line['ground'] != 1) $line['ground'] = 0; |
549 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground'])); |
|
549 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ground' => $line['ground'])); |
|
550 | 550 | //$dataFound = true; |
551 | 551 | } |
552 | 552 | if (isset($line['squawk']) && $line['squawk'] != '') { |
553 | 553 | 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'])) { |
554 | 554 | if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true; |
555 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
555 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk'])); |
|
556 | 556 | $highlight = ''; |
557 | 557 | if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC'; |
558 | 558 | if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC'; |
@@ -560,47 +560,47 @@ discard block |
||
560 | 560 | if ($highlight != '') { |
561 | 561 | $timeelapsed = microtime(true); |
562 | 562 | $Spotter = new Spotter($this->db); |
563 | - $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight); |
|
563 | + $Spotter->setHighlightFlight($this->all_flights[$id]['id'], $highlight); |
|
564 | 564 | $Spotter->db = null; |
565 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
565 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
566 | 566 | |
567 | 567 | //$putinarchive = true; |
568 | 568 | //$highlight = ''; |
569 | 569 | } |
570 | 570 | |
571 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
571 | + } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk'])); |
|
572 | 572 | //$dataFound = true; |
573 | 573 | } |
574 | 574 | |
575 | 575 | if (isset($line['altitude']) && $line['altitude'] != '') { |
576 | 576 | //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) { |
577 | - 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; |
|
578 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100))); |
|
579 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude'])); |
|
577 | + 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; |
|
578 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude' => round($line['altitude']/100))); |
|
579 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude_real' => $line['altitude'])); |
|
580 | 580 | //$dataFound = true; |
581 | 581 | //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n"; |
582 | 582 | } |
583 | 583 | |
584 | 584 | if (isset($line['noarchive']) && $line['noarchive'] === true) { |
585 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true)); |
|
585 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('noarchive' => true)); |
|
586 | 586 | } |
587 | 587 | |
588 | 588 | if (isset($line['heading']) && $line['heading'] != '') { |
589 | - if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true; |
|
590 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading']))); |
|
591 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true)); |
|
589 | + if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading'] - round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true; |
|
590 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($line['heading']))); |
|
591 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading_fromsrc' => true)); |
|
592 | 592 | //$dataFound = true; |
593 | 593 | } 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']) { |
594 | - $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']); |
|
595 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading))); |
|
596 | - if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true; |
|
594 | + $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']); |
|
595 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($heading))); |
|
596 | + if (abs($this->all_flights[$id]['heading'] - round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true; |
|
597 | 597 | if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n"; |
598 | 598 | } elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') { |
599 | 599 | // If not enough messages and ACARS set heading to 0 |
600 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0)); |
|
600 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => 0)); |
|
601 | 601 | } |
602 | - if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
|
603 | - elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false; |
|
602 | + if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
|
603 | + elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false; |
|
604 | 604 | |
605 | 605 | // print_r($this->all_flights[$id]); |
606 | 606 | //gets the callsign from the last hour |
@@ -610,7 +610,7 @@ discard block |
||
610 | 610 | if ($dataFound === true && isset($this->all_flights[$id]['hex'])) { |
611 | 611 | $this->all_flights[$id]['lastupdate'] = time(); |
612 | 612 | if ($this->all_flights[$id]['addedSpotter'] == 0) { |
613 | - 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'])) { |
|
613 | + 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'])) { |
|
614 | 614 | //print_r($this->all_flights); |
615 | 615 | //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n"; |
616 | 616 | //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']); |
@@ -620,61 +620,61 @@ discard block |
||
620 | 620 | $SpotterLive = new SpotterLive($this->db); |
621 | 621 | 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')) { |
622 | 622 | $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']); |
623 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
623 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
624 | 624 | } elseif (isset($line['id'])) { |
625 | 625 | $recent_ident = $SpotterLive->checkIdRecent($line['id']); |
626 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
626 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
627 | 627 | } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') { |
628 | 628 | $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']); |
629 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
629 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
630 | 630 | } else $recent_ident = ''; |
631 | - $SpotterLive->db=null; |
|
631 | + $SpotterLive->db = null; |
|
632 | 632 | |
633 | 633 | if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
634 | 634 | elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
635 | 635 | } else { |
636 | 636 | $recent_ident = ''; |
637 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0)); |
|
637 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 0)); |
|
638 | 638 | } |
639 | 639 | //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
640 | - if($recent_ident == "") |
|
640 | + if ($recent_ident == "") |
|
641 | 641 | { |
642 | 642 | if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : "; |
643 | 643 | if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } |
644 | 644 | if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } |
645 | 645 | //adds the spotter data for the archive |
646 | 646 | $ignoreImport = false; |
647 | - foreach($globalAirportIgnore as $airportIgnore) { |
|
647 | + foreach ($globalAirportIgnore as $airportIgnore) { |
|
648 | 648 | if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
649 | 649 | $ignoreImport = true; |
650 | 650 | } |
651 | 651 | } |
652 | 652 | if (count($globalAirportAccept) > 0) { |
653 | 653 | $ignoreImport = true; |
654 | - foreach($globalAirportIgnore as $airportIgnore) { |
|
654 | + foreach ($globalAirportIgnore as $airportIgnore) { |
|
655 | 655 | if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
656 | 656 | $ignoreImport = false; |
657 | 657 | } |
658 | 658 | } |
659 | 659 | } |
660 | 660 | if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) { |
661 | - foreach($globalAirlineIgnore as $airlineIgnore) { |
|
662 | - 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)) { |
|
661 | + foreach ($globalAirlineIgnore as $airlineIgnore) { |
|
662 | + 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)) { |
|
663 | 663 | $ignoreImport = true; |
664 | 664 | } |
665 | 665 | } |
666 | 666 | } |
667 | 667 | if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) { |
668 | 668 | $ignoreImport = true; |
669 | - foreach($globalAirlineAccept as $airlineAccept) { |
|
670 | - 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)) { |
|
669 | + foreach ($globalAirlineAccept as $airlineAccept) { |
|
670 | + 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)) { |
|
671 | 671 | $ignoreImport = false; |
672 | 672 | } |
673 | 673 | } |
674 | 674 | } |
675 | 675 | if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) { |
676 | 676 | $ignoreImport = true; |
677 | - foreach($globalPilotIdAccept as $pilotIdAccept) { |
|
677 | + foreach ($globalPilotIdAccept as $pilotIdAccept) { |
|
678 | 678 | if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) { |
679 | 679 | $ignoreImport = false; |
680 | 680 | } |
@@ -686,29 +686,29 @@ discard block |
||
686 | 686 | if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack'; |
687 | 687 | if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)'; |
688 | 688 | if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency'; |
689 | - 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'))); |
|
689 | + 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'))); |
|
690 | 690 | $timeelapsed = microtime(true); |
691 | 691 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
692 | 692 | $Spotter = new Spotter($this->db); |
693 | - $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]['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']); |
|
693 | + $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]['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']); |
|
694 | 694 | $Spotter->db = null; |
695 | 695 | if ($globalDebug && isset($result)) echo $result."\n"; |
696 | 696 | } |
697 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
697 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
698 | 698 | |
699 | 699 | // Add source stat in DB |
700 | 700 | $Stats = new Stats($this->db); |
701 | 701 | if (!empty($this->stats)) { |
702 | 702 | if ($globalDebug) echo 'Add source stats : '; |
703 | - foreach($this->stats as $date => $data) { |
|
704 | - foreach($data as $source => $sourced) { |
|
703 | + foreach ($this->stats as $date => $data) { |
|
704 | + foreach ($data as $source => $sourced) { |
|
705 | 705 | //print_r($sourced); |
706 | - if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date); |
|
707 | - if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date); |
|
706 | + if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']), $source, 'polar', $date); |
|
707 | + if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']), $source, 'hist', $date); |
|
708 | 708 | if (isset($sourced['msg'])) { |
709 | 709 | if (time() - $sourced['msg']['date'] > 10) { |
710 | 710 | $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
711 | - echo $Stats->addStatSource($nbmsg,$source,'msg',$date); |
|
711 | + echo $Stats->addStatSource($nbmsg, $source, 'msg', $date); |
|
712 | 712 | unset($this->stats[$date][$source]['msg']); |
713 | 713 | } |
714 | 714 | } |
@@ -745,20 +745,20 @@ discard block |
||
745 | 745 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
746 | 746 | $SpotterLive = new SpotterLive($this->db); |
747 | 747 | $SpotterLive->deleteLiveSpotterData(); |
748 | - $SpotterLive->db=null; |
|
748 | + $SpotterLive->db = null; |
|
749 | 749 | } |
750 | 750 | if ($globalDebug) echo " Done\n"; |
751 | 751 | $this->last_delete = time(); |
752 | 752 | } |
753 | 753 | } else { |
754 | - 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')) { |
|
754 | + 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')) { |
|
755 | 755 | $this->all_flights[$id]['id'] = $recent_ident; |
756 | 756 | $this->all_flights[$id]['addedSpotter'] = 1; |
757 | 757 | } |
758 | 758 | if (isset($globalDaemon) && !$globalDaemon) { |
759 | 759 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
760 | 760 | $Spotter = new Spotter($this->db); |
761 | - $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]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']); |
|
761 | + $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]['ground'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['arrival_airport_time']); |
|
762 | 762 | $Spotter->db = null; |
763 | 763 | } |
764 | 764 | } |
@@ -783,37 +783,37 @@ discard block |
||
783 | 783 | if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } |
784 | 784 | if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } |
785 | 785 | |
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 = true; |
789 | 789 | } |
790 | 790 | } |
791 | 791 | if (count($globalAirportAccept) > 0) { |
792 | 792 | $ignoreImport = true; |
793 | - foreach($globalAirportIgnore as $airportIgnore) { |
|
793 | + foreach ($globalAirportIgnore as $airportIgnore) { |
|
794 | 794 | if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
795 | 795 | $ignoreImport = false; |
796 | 796 | } |
797 | 797 | } |
798 | 798 | } |
799 | 799 | if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) { |
800 | - foreach($globalAirlineIgnore as $airlineIgnore) { |
|
801 | - 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)) { |
|
800 | + foreach ($globalAirlineIgnore as $airlineIgnore) { |
|
801 | + 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)) { |
|
802 | 802 | $ignoreImport = true; |
803 | 803 | } |
804 | 804 | } |
805 | 805 | } |
806 | 806 | if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) { |
807 | 807 | $ignoreImport = true; |
808 | - foreach($globalAirlineAccept as $airlineAccept) { |
|
809 | - 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)) { |
|
808 | + foreach ($globalAirlineAccept as $airlineAccept) { |
|
809 | + 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)) { |
|
810 | 810 | $ignoreImport = false; |
811 | 811 | } |
812 | 812 | } |
813 | 813 | } |
814 | 814 | if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) { |
815 | 815 | $ignoreImport = true; |
816 | - foreach($globalPilotIdAccept as $pilotIdAccept) { |
|
816 | + foreach ($globalPilotIdAccept as $pilotIdAccept) { |
|
817 | 817 | if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) { |
818 | 818 | $ignoreImport = false; |
819 | 819 | } |
@@ -821,20 +821,20 @@ discard block |
||
821 | 821 | } |
822 | 822 | |
823 | 823 | if (!$ignoreImport) { |
824 | - 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'])) { |
|
824 | + 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'])) { |
|
825 | 825 | if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : "; |
826 | 826 | $timeelapsed = microtime(true); |
827 | 827 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
828 | 828 | $SpotterLive = new SpotterLive($this->db); |
829 | - $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]['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']); |
|
829 | + $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]['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']); |
|
830 | 830 | $SpotterLive->db = null; |
831 | 831 | if ($globalDebug) echo $result."\n"; |
832 | 832 | } |
833 | 833 | if (isset($globalServerAPRS) && $globalServerAPRS) { |
834 | - $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]['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']); |
|
834 | + $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]['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']); |
|
835 | 835 | } |
836 | 836 | $this->all_flights[$id]['putinarchive'] = false; |
837 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
837 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
838 | 838 | |
839 | 839 | // Put statistics in $this->stats variable |
840 | 840 | //if ($line['format_source'] != 'aprs') { |
@@ -852,19 +852,19 @@ discard block |
||
852 | 852 | $latitude = $globalCenterLatitude; |
853 | 853 | $longitude = $globalCenterLongitude; |
854 | 854 | } |
855 | - $this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude); |
|
855 | + $this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude); |
|
856 | 856 | } else { |
857 | 857 | $latitude = $this->source_location[$source]['latitude']; |
858 | 858 | $longitude = $this->source_location[$source]['longitude']; |
859 | 859 | } |
860 | - $stats_heading = $Common->getHeading($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']); |
|
860 | + $stats_heading = $Common->getHeading($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']); |
|
861 | 861 | //$stats_heading = $stats_heading%22.5; |
862 | 862 | $stats_heading = round($stats_heading/22.5); |
863 | - $stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']); |
|
863 | + $stats_distance = $Common->distance($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']); |
|
864 | 864 | $current_date = date('Y-m-d'); |
865 | 865 | if ($stats_heading == 16) $stats_heading = 0; |
866 | 866 | if (!isset($this->stats[$current_date][$source]['polar'][1])) { |
867 | - for ($i=0;$i<=15;$i++) { |
|
867 | + for ($i = 0; $i <= 15; $i++) { |
|
868 | 868 | $this->stats[$current_date][$source]['polar'][$i] = 0; |
869 | 869 | } |
870 | 870 | $this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance; |
@@ -879,9 +879,9 @@ discard block |
||
879 | 879 | if (!isset($this->stats[$current_date][$source]['hist'][$distance])) { |
880 | 880 | if (isset($this->stats[$current_date][$source]['hist'][0])) { |
881 | 881 | end($this->stats[$current_date][$source]['hist']); |
882 | - $mini = key($this->stats[$current_date][$source]['hist'])+10; |
|
882 | + $mini = key($this->stats[$current_date][$source]['hist']) + 10; |
|
883 | 883 | } else $mini = 0; |
884 | - for ($i=$mini;$i<=$distance;$i+=10) { |
|
884 | + for ($i = $mini; $i <= $distance; $i += 10) { |
|
885 | 885 | $this->stats[$current_date][$source]['hist'][$i] = 0; |
886 | 886 | } |
887 | 887 | $this->stats[$current_date][$source]['hist'][$distance] = 1; |
@@ -893,7 +893,7 @@ discard block |
||
893 | 893 | $this->all_flights[$id]['lastupdate'] = time(); |
894 | 894 | if ($this->all_flights[$id]['putinarchive']) $send = true; |
895 | 895 | //if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
896 | - } 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"; |
|
896 | + } 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"; |
|
897 | 897 | //$this->del(); |
898 | 898 | |
899 | 899 |
@@ -59,7 +59,9 @@ discard block |
||
59 | 59 | $dbc = $this->db; |
60 | 60 | $this->all_flights[$id]['schedule_check'] = true; |
61 | 61 | if ($globalSchedulesFetch) { |
62 | - if ($globalDebug) echo 'Getting schedule info...'."\n"; |
|
62 | + if ($globalDebug) { |
|
63 | + echo 'Getting schedule info...'."\n"; |
|
64 | + } |
|
63 | 65 | $Spotter = new Spotter($dbc); |
64 | 66 | $Schedule = new Schedule($dbc); |
65 | 67 | $Translation = new Translation($dbc); |
@@ -70,7 +72,9 @@ discard block |
||
70 | 72 | if ($Schedule->checkSchedule($operator) == 0) { |
71 | 73 | $schedule = $Schedule->fetchSchedule($operator); |
72 | 74 | if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) { |
73 | - if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n"; |
|
75 | + if ($globalDebug) { |
|
76 | + echo "-> Schedule info for ".$operator." (".$ident.")\n"; |
|
77 | + } |
|
74 | 78 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime'])); |
75 | 79 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime'])); |
76 | 80 | // Should also check if route schedule = route from DB |
@@ -79,7 +83,9 @@ discard block |
||
79 | 83 | $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']); |
80 | 84 | if (trim($airport_icao) != '') { |
81 | 85 | $this->all_flights[$id]['departure_airport'] = $airport_icao; |
82 | - if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n"; |
|
86 | + if ($globalDebug) { |
|
87 | + echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n"; |
|
88 | + } |
|
83 | 89 | } |
84 | 90 | } |
85 | 91 | } |
@@ -88,17 +94,25 @@ discard block |
||
88 | 94 | $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']); |
89 | 95 | if (trim($airport_icao) != '') { |
90 | 96 | $this->all_flights[$id]['arrival_airport'] = $airport_icao; |
91 | - if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n"; |
|
97 | + if ($globalDebug) { |
|
98 | + echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n"; |
|
99 | + } |
|
92 | 100 | } |
93 | 101 | } |
94 | 102 | } |
95 | 103 | $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']); |
96 | 104 | } |
97 | - } else $scheduleexist = true; |
|
98 | - } else $scheduleexist = true; |
|
105 | + } else { |
|
106 | + $scheduleexist = true; |
|
107 | + } |
|
108 | + } else { |
|
109 | + $scheduleexist = true; |
|
110 | + } |
|
99 | 111 | // close connection, at least one way will work ? |
100 | 112 | if ($scheduleexist) { |
101 | - if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n"; |
|
113 | + if ($globalDebug) { |
|
114 | + echo "-> get arrival/departure airport info for ".$ident."\n"; |
|
115 | + } |
|
102 | 116 | $sch = $Schedule->getSchedule($operator); |
103 | 117 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time'])); |
104 | 118 | } |
@@ -120,7 +134,9 @@ discard block |
||
120 | 134 | |
121 | 135 | public function checkAll() { |
122 | 136 | global $globalDebug, $globalNoImport; |
123 | - if ($globalDebug) echo "Update last seen flights data...\n"; |
|
137 | + if ($globalDebug) { |
|
138 | + echo "Update last seen flights data...\n"; |
|
139 | + } |
|
124 | 140 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
125 | 141 | foreach ($this->all_flights as $key => $flight) { |
126 | 142 | if (isset($this->all_flights[$key]['id'])) { |
@@ -135,24 +151,32 @@ discard block |
||
135 | 151 | |
136 | 152 | public function arrival($key) { |
137 | 153 | global $globalClosestMinDist, $globalDebug; |
138 | - if ($globalDebug) echo 'Update arrival...'."\n"; |
|
154 | + if ($globalDebug) { |
|
155 | + echo 'Update arrival...'."\n"; |
|
156 | + } |
|
139 | 157 | $Spotter = new Spotter($this->db); |
140 | 158 | $airport_icao = ''; |
141 | 159 | $airport_time = ''; |
142 | - if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50; |
|
160 | + if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') { |
|
161 | + $globalClosestMinDist = 50; |
|
162 | + } |
|
143 | 163 | if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { |
144 | 164 | $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist); |
145 | 165 | if (isset($closestAirports[0])) { |
146 | 166 | if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) { |
147 | 167 | $airport_icao = $closestAirports[0]['icao']; |
148 | 168 | $airport_time = $this->all_flights[$key]['datetime']; |
149 | - if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
169 | + if ($globalDebug) { |
|
170 | + echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
171 | + } |
|
150 | 172 | } elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') { |
151 | 173 | foreach ($closestAirports as $airport) { |
152 | 174 | if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) { |
153 | 175 | $airport_icao = $airport['icao']; |
154 | 176 | $airport_time = $this->all_flights[$key]['datetime']; |
155 | - if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
177 | + if ($globalDebug) { |
|
178 | + echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
179 | + } |
|
156 | 180 | break; |
157 | 181 | } |
158 | 182 | } |
@@ -160,14 +184,20 @@ discard block |
||
160 | 184 | $airport_icao = $closestAirports[0]['icao']; |
161 | 185 | $airport_time = $this->all_flights[$key]['datetime']; |
162 | 186 | } else { |
163 | - if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n"; |
|
187 | + if ($globalDebug) { |
|
188 | + echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n"; |
|
189 | + } |
|
164 | 190 | } |
165 | 191 | } else { |
166 | - if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n"; |
|
192 | + if ($globalDebug) { |
|
193 | + echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n"; |
|
194 | + } |
|
167 | 195 | } |
168 | 196 | |
169 | 197 | } else { |
170 | - if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n"; |
|
198 | + if ($globalDebug) { |
|
199 | + echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n"; |
|
200 | + } |
|
171 | 201 | } |
172 | 202 | return array('airport_icao' => $airport_icao,'airport_time' => $airport_time); |
173 | 203 | } |
@@ -177,12 +207,16 @@ discard block |
||
177 | 207 | public function del() { |
178 | 208 | global $globalDebug, $globalNoImport; |
179 | 209 | // Delete old infos |
180 | - if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
|
210 | + if ($globalDebug) { |
|
211 | + echo 'Delete old values and update latest data...'."\n"; |
|
212 | + } |
|
181 | 213 | foreach ($this->all_flights as $key => $flight) { |
182 | 214 | if (isset($flight['lastupdate'])) { |
183 | 215 | if ($flight['lastupdate'] < (time()-3000)) { |
184 | 216 | if (isset($this->all_flights[$key]['id'])) { |
185 | - if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n"; |
|
217 | + if ($globalDebug) { |
|
218 | + echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n"; |
|
219 | + } |
|
186 | 220 | /* |
187 | 221 | $SpotterLive = new SpotterLive(); |
188 | 222 | $SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']); |
@@ -193,7 +227,9 @@ discard block |
||
193 | 227 | $Spotter = new Spotter($this->db); |
194 | 228 | if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { |
195 | 229 | $result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']); |
196 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
230 | + if ($globalDebug && $result != 'success') { |
|
231 | + echo '!!! ERROR : '.$result."\n"; |
|
232 | + } |
|
197 | 233 | } |
198 | 234 | // Put in archive |
199 | 235 | // $Spotter->db = null; |
@@ -208,8 +244,10 @@ discard block |
||
208 | 244 | public function add($line) { |
209 | 245 | global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights, $globalServerAPRS, $APRSSpotter, $globalNoImport; |
210 | 246 | //if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE; |
211 | - if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02'; |
|
212 | -/* |
|
247 | + if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') { |
|
248 | + $globalCoordMinChange = '0.02'; |
|
249 | + } |
|
250 | + /* |
|
213 | 251 | $Spotter = new Spotter(); |
214 | 252 | $dbc = $Spotter->db; |
215 | 253 | $SpotterLive = new SpotterLive($dbc); |
@@ -237,11 +275,15 @@ discard block |
||
237 | 275 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) { |
238 | 276 | $current_date = date('Y-m-d'); |
239 | 277 | $source = $line['source_name']; |
240 | - if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source']; |
|
278 | + if ($source == '' || $line['format_source'] == 'aprs') { |
|
279 | + $source = $line['format_source']; |
|
280 | + } |
|
241 | 281 | if (!isset($this->stats[$current_date][$source]['msg'])) { |
242 | 282 | $this->stats[$current_date][$source]['msg']['date'] = time(); |
243 | 283 | $this->stats[$current_date][$source]['msg']['nb'] = 1; |
244 | - } else $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
284 | + } else { |
|
285 | + $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
286 | + } |
|
245 | 287 | } |
246 | 288 | |
247 | 289 | /* |
@@ -257,8 +299,11 @@ discard block |
||
257 | 299 | //$this->db = $dbc; |
258 | 300 | |
259 | 301 | //$hex = trim($line['hex']); |
260 | - if (!isset($line['id'])) $id = trim($line['hex']); |
|
261 | - else $id = trim($line['id']); |
|
302 | + if (!isset($line['id'])) { |
|
303 | + $id = trim($line['hex']); |
|
304 | + } else { |
|
305 | + $id = trim($line['id']); |
|
306 | + } |
|
262 | 307 | |
263 | 308 | if (!isset($this->all_flights[$id])) { |
264 | 309 | $this->all_flights[$id] = array(); |
@@ -266,13 +311,21 @@ discard block |
||
266 | 311 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => '')); |
267 | 312 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time())); |
268 | 313 | if (!isset($line['id'])) { |
269 | - if (!isset($globalDaemon)) $globalDaemon = TRUE; |
|
270 | -// if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi'))); |
|
314 | + if (!isset($globalDaemon)) { |
|
315 | + $globalDaemon = TRUE; |
|
316 | + } |
|
317 | + // if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi'))); |
|
271 | 318 | // if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
272 | - if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
319 | + if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) { |
|
320 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
321 | + } |
|
273 | 322 | //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
274 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
275 | - if ($globalAllFlights !== FALSE) $dataFound = true; |
|
323 | + } else { |
|
324 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
325 | + } |
|
326 | + if ($globalAllFlights !== FALSE) { |
|
327 | + $dataFound = true; |
|
328 | + } |
|
276 | 329 | } |
277 | 330 | if (isset($line['source_type']) && $line['source_type'] != '') { |
278 | 331 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type'])); |
@@ -293,11 +346,19 @@ discard block |
||
293 | 346 | $aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex'])); |
294 | 347 | } |
295 | 348 | $Spotter->db = null; |
296 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
297 | - if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
349 | + if ($globalDebugTimeElapsed) { |
|
350 | + echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
351 | + } |
|
352 | + if ($aircraft_icao != '') { |
|
353 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
354 | + } |
|
355 | + } |
|
356 | + if ($globalAllFlights !== FALSE) { |
|
357 | + $dataFound = true; |
|
358 | + } |
|
359 | + if ($globalDebug) { |
|
360 | + echo "*********** New aircraft hex : ".$line['hex']." ***********\n"; |
|
298 | 361 | } |
299 | - if ($globalAllFlights !== FALSE) $dataFound = true; |
|
300 | - if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n"; |
|
301 | 362 | } |
302 | 363 | if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') { |
303 | 364 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao'])); |
@@ -307,14 +368,23 @@ discard block |
||
307 | 368 | $Spotter = new Spotter($this->db); |
308 | 369 | $aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']); |
309 | 370 | $Spotter->db = null; |
310 | - if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
371 | + if ($aircraft_icao != '') { |
|
372 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
373 | + } |
|
311 | 374 | } |
312 | 375 | if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) { |
313 | - if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID'; |
|
314 | - elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL'; |
|
315 | - elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE'; |
|
316 | - elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC'; |
|
317 | - if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
376 | + if ($line['aircraft_type'] == 'PARA_GLIDER') { |
|
377 | + $aircraft_icao = 'GLID'; |
|
378 | + } elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') { |
|
379 | + $aircraft_icao = 'UHEL'; |
|
380 | + } elseif ($line['aircraft_type'] == 'TOW_PLANE') { |
|
381 | + $aircraft_icao = 'TOWPLANE'; |
|
382 | + } elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') { |
|
383 | + $aircraft_icao = 'POWAIRC'; |
|
384 | + } |
|
385 | + if (isset($aircraft_icao)) { |
|
386 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
387 | + } |
|
318 | 388 | } |
319 | 389 | if (!isset($this->all_flights[$id]['aircraft_icao'])) { |
320 | 390 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA')); |
@@ -324,8 +394,11 @@ discard block |
||
324 | 394 | if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) { |
325 | 395 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime'])); |
326 | 396 | } else { |
327 | - if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
328 | - elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
397 | + if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) { |
|
398 | + echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
399 | + } elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) { |
|
400 | + echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
401 | + } |
|
329 | 402 | /* |
330 | 403 | echo strtotime($line['datetime']).' > '.strtotime($this->all_flights[$id]['datetime']); |
331 | 404 | print_r($this->all_flights[$id]); |
@@ -357,15 +430,25 @@ discard block |
||
357 | 430 | $timeelapsed = microtime(true); |
358 | 431 | $Spotter = new Spotter($this->db); |
359 | 432 | $fromsource = NULL; |
360 | - if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource; |
|
361 | - elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim'; |
|
362 | - elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao'; |
|
363 | - elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim'; |
|
364 | - elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao'; |
|
433 | + if (isset($globalAirlinesSource) && $globalAirlinesSource != '') { |
|
434 | + $fromsource = $globalAirlinesSource; |
|
435 | + } elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') { |
|
436 | + $fromsource = 'vatsim'; |
|
437 | + } elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') { |
|
438 | + $fromsource = 'ivao'; |
|
439 | + } elseif (isset($globalVATSIM) && $globalVATSIM) { |
|
440 | + $fromsource = 'vatsim'; |
|
441 | + } elseif (isset($globalIVAO) && $globalIVAO) { |
|
442 | + $fromsource = 'ivao'; |
|
443 | + } |
|
365 | 444 | $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource); |
366 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
445 | + if ($globalDebug && $result != 'success') { |
|
446 | + echo '!!! ERROR : '.$result."\n"; |
|
447 | + } |
|
367 | 448 | $Spotter->db = null; |
368 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
449 | + if ($globalDebugTimeElapsed) { |
|
450 | + echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
451 | + } |
|
369 | 452 | } |
370 | 453 | |
371 | 454 | /* |
@@ -376,7 +459,9 @@ discard block |
||
376 | 459 | else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
377 | 460 | } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
378 | 461 | */ |
379 | - if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
462 | + if (!isset($this->all_flights[$id]['id'])) { |
|
463 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
464 | + } |
|
380 | 465 | |
381 | 466 | //$putinarchive = true; |
382 | 467 | if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) { |
@@ -393,7 +478,9 @@ discard block |
||
393 | 478 | $line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']); |
394 | 479 | $line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']); |
395 | 480 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => '')); |
396 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
481 | + if ($globalDebugTimeElapsed) { |
|
482 | + echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
483 | + } |
|
397 | 484 | |
398 | 485 | } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') { |
399 | 486 | $timeelapsed = microtime(true); |
@@ -406,7 +493,9 @@ discard block |
||
406 | 493 | $Translation->db = null; |
407 | 494 | } |
408 | 495 | $Spotter->db = null; |
409 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
496 | + if ($globalDebugTimeElapsed) { |
|
497 | + echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
498 | + } |
|
410 | 499 | |
411 | 500 | if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) { |
412 | 501 | //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) { |
@@ -415,9 +504,13 @@ discard block |
||
415 | 504 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop'])); |
416 | 505 | } |
417 | 506 | } |
418 | - if (!isset($globalFork)) $globalFork = TRUE; |
|
507 | + if (!isset($globalFork)) { |
|
508 | + $globalFork = TRUE; |
|
509 | + } |
|
419 | 510 | if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) { |
420 | - if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident'])); |
|
511 | + if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) { |
|
512 | + $this->get_Schedule($id,trim($line['ident'])); |
|
513 | + } |
|
421 | 514 | } |
422 | 515 | } |
423 | 516 | } |
@@ -433,16 +526,23 @@ discard block |
||
433 | 526 | // use datetime |
434 | 527 | $speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']); |
435 | 528 | $speed = $speed*3.6; |
436 | - if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed))); |
|
437 | - if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
|
529 | + if ($speed < 1000) { |
|
530 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed))); |
|
531 | + } |
|
532 | + if ($globalDebug) { |
|
533 | + echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
|
534 | + } |
|
438 | 535 | } |
439 | 536 | } |
440 | 537 | |
441 | 538 | |
442 | 539 | |
443 | 540 | if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
444 | - if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']); |
|
445 | - else unset($timediff); |
|
541 | + if (isset($this->all_flights[$id]['time_last_coord'])) { |
|
542 | + $timediff = round(time()-$this->all_flights[$id]['time_last_coord']); |
|
543 | + } else { |
|
544 | + unset($timediff); |
|
545 | + } |
|
446 | 546 | if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) { |
447 | 547 | if (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude'])) { |
448 | 548 | if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) { |
@@ -450,21 +550,31 @@ discard block |
||
450 | 550 | $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
451 | 551 | $this->all_flights[$id]['putinarchive'] = true; |
452 | 552 | |
453 | - if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
|
553 | + if ($globalDebug) { |
|
554 | + echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
|
555 | + } |
|
454 | 556 | $timeelapsed = microtime(true); |
455 | 557 | $Spotter = new Spotter($this->db); |
456 | 558 | $all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
457 | - if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2']; |
|
559 | + if (!empty($all_country)) { |
|
560 | + $this->all_flights[$id]['over_country'] = $all_country['iso2']; |
|
561 | + } |
|
458 | 562 | $Spotter->db = null; |
459 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
563 | + if ($globalDebugTimeElapsed) { |
|
564 | + echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
565 | + } |
|
460 | 566 | $this->tmd = 0; |
461 | - if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n"; |
|
567 | + if ($globalDebug) { |
|
568 | + echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n"; |
|
569 | + } |
|
462 | 570 | } |
463 | 571 | } |
464 | 572 | |
465 | 573 | if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
466 | 574 | //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) { |
467 | - if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude']; |
|
575 | + if (!isset($this->all_flights[$id]['archive_latitude'])) { |
|
576 | + $this->all_flights[$id]['archive_latitude'] = $line['latitude']; |
|
577 | + } |
|
468 | 578 | 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') { |
469 | 579 | $this->all_flights[$id]['livedb_latitude'] = $line['latitude']; |
470 | 580 | $dataFound = true; |
@@ -486,9 +596,13 @@ discard block |
||
486 | 596 | */ |
487 | 597 | } |
488 | 598 | if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { |
489 | - if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
599 | + if ($line['longitude'] > 180) { |
|
600 | + $line['longitude'] = $line['longitude'] - 360; |
|
601 | + } |
|
490 | 602 | //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) { |
491 | - if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
|
603 | + if (!isset($this->all_flights[$id]['archive_longitude'])) { |
|
604 | + $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
|
605 | + } |
|
492 | 606 | 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') { |
493 | 607 | $this->all_flights[$id]['livedb_longitude'] = $line['longitude']; |
494 | 608 | $dataFound = true; |
@@ -519,7 +633,9 @@ discard block |
||
519 | 633 | } |
520 | 634 | } |
521 | 635 | if (isset($line['last_update']) && $line['last_update'] != '') { |
522 | - if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
636 | + if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) { |
|
637 | + $dataFound = true; |
|
638 | + } |
|
523 | 639 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update'])); |
524 | 640 | } |
525 | 641 | if (isset($line['verticalrate']) && $line['verticalrate'] != '') { |
@@ -541,40 +657,60 @@ discard block |
||
541 | 657 | // Here we force archive of flight because after ground it's a new one (or should be) |
542 | 658 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
543 | 659 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1)); |
544 | - if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi'))); |
|
545 | - elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
546 | - 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'])); |
|
660 | + if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) { |
|
661 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi'))); |
|
662 | + } elseif (isset($line['id'])) { |
|
663 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
664 | + } elseif (isset($this->all_flights[$id]['ident'])) { |
|
665 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
666 | + } |
|
667 | + } |
|
668 | + if ($line['ground'] != 1) { |
|
669 | + $line['ground'] = 0; |
|
547 | 670 | } |
548 | - if ($line['ground'] != 1) $line['ground'] = 0; |
|
549 | 671 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground'])); |
550 | 672 | //$dataFound = true; |
551 | 673 | } |
552 | 674 | if (isset($line['squawk']) && $line['squawk'] != '') { |
553 | 675 | 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'])) { |
554 | - if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true; |
|
676 | + if ($this->all_flights[$id]['squawk'] != $line['squawk']) { |
|
677 | + $this->all_flights[$id]['putinarchive'] = true; |
|
678 | + } |
|
555 | 679 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
556 | 680 | $highlight = ''; |
557 | - if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC'; |
|
558 | - if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC'; |
|
559 | - if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC'; |
|
681 | + if ($this->all_flights[$id]['squawk'] == '7500') { |
|
682 | + $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC'; |
|
683 | + } |
|
684 | + if ($this->all_flights[$id]['squawk'] == '7600') { |
|
685 | + $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC'; |
|
686 | + } |
|
687 | + if ($this->all_flights[$id]['squawk'] == '7700') { |
|
688 | + $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC'; |
|
689 | + } |
|
560 | 690 | if ($highlight != '') { |
561 | 691 | $timeelapsed = microtime(true); |
562 | 692 | $Spotter = new Spotter($this->db); |
563 | 693 | $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight); |
564 | 694 | $Spotter->db = null; |
565 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
695 | + if ($globalDebugTimeElapsed) { |
|
696 | + echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
697 | + } |
|
566 | 698 | |
567 | 699 | //$putinarchive = true; |
568 | 700 | //$highlight = ''; |
569 | 701 | } |
570 | 702 | |
571 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
703 | + } else { |
|
704 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
705 | + } |
|
572 | 706 | //$dataFound = true; |
573 | 707 | } |
574 | 708 | |
575 | 709 | if (isset($line['altitude']) && $line['altitude'] != '') { |
576 | 710 | //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) { |
577 | - 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; |
|
711 | + if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) { |
|
712 | + $this->all_flights[$id]['putinarchive'] = true; |
|
713 | + } |
|
578 | 714 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100))); |
579 | 715 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude'])); |
580 | 716 | //$dataFound = true; |
@@ -586,21 +722,30 @@ discard block |
||
586 | 722 | } |
587 | 723 | |
588 | 724 | if (isset($line['heading']) && $line['heading'] != '') { |
589 | - if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true; |
|
725 | + if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) { |
|
726 | + $this->all_flights[$id]['putinarchive'] = true; |
|
727 | + } |
|
590 | 728 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading']))); |
591 | 729 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true)); |
592 | 730 | //$dataFound = true; |
593 | 731 | } 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']) { |
594 | 732 | $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']); |
595 | 733 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading))); |
596 | - if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true; |
|
597 | - if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n"; |
|
734 | + if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) { |
|
735 | + $this->all_flights[$id]['putinarchive'] = true; |
|
736 | + } |
|
737 | + if ($globalDebug) { |
|
738 | + echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n"; |
|
739 | + } |
|
598 | 740 | } elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') { |
599 | 741 | // If not enough messages and ACARS set heading to 0 |
600 | 742 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0)); |
601 | 743 | } |
602 | - if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
|
603 | - elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false; |
|
744 | + if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) { |
|
745 | + $dataFound = false; |
|
746 | + } elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) { |
|
747 | + $dataFound = false; |
|
748 | + } |
|
604 | 749 | |
605 | 750 | // print_r($this->all_flights[$id]); |
606 | 751 | //gets the callsign from the last hour |
@@ -615,23 +760,36 @@ discard block |
||
615 | 760 | //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n"; |
616 | 761 | //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']); |
617 | 762 | if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) { |
618 | - if ($globalDebug) echo "Check if aircraft is already in DB..."; |
|
763 | + if ($globalDebug) { |
|
764 | + echo "Check if aircraft is already in DB..."; |
|
765 | + } |
|
619 | 766 | $timeelapsed = microtime(true); |
620 | 767 | $SpotterLive = new SpotterLive($this->db); |
621 | 768 | 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')) { |
622 | 769 | $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']); |
623 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
770 | + if ($globalDebugTimeElapsed) { |
|
771 | + echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
772 | + } |
|
624 | 773 | } elseif (isset($line['id'])) { |
625 | 774 | $recent_ident = $SpotterLive->checkIdRecent($line['id']); |
626 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
775 | + if ($globalDebugTimeElapsed) { |
|
776 | + echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
777 | + } |
|
627 | 778 | } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') { |
628 | 779 | $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']); |
629 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
630 | - } else $recent_ident = ''; |
|
780 | + if ($globalDebugTimeElapsed) { |
|
781 | + echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
782 | + } |
|
783 | + } else { |
|
784 | + $recent_ident = ''; |
|
785 | + } |
|
631 | 786 | $SpotterLive->db=null; |
632 | 787 | |
633 | - if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
|
634 | - elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
|
788 | + if ($globalDebug && $recent_ident == '') { |
|
789 | + echo " Not in DB.\n"; |
|
790 | + } elseif ($globalDebug && $recent_ident != '') { |
|
791 | + echo " Already in DB.\n"; |
|
792 | + } |
|
635 | 793 | } else { |
636 | 794 | $recent_ident = ''; |
637 | 795 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0)); |
@@ -639,7 +797,9 @@ discard block |
||
639 | 797 | //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
640 | 798 | if($recent_ident == "") |
641 | 799 | { |
642 | - if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : "; |
|
800 | + if ($globalDebug) { |
|
801 | + echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : "; |
|
802 | + } |
|
643 | 803 | if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } |
644 | 804 | if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } |
645 | 805 | //adds the spotter data for the archive |
@@ -683,28 +843,46 @@ discard block |
||
683 | 843 | |
684 | 844 | if (!$ignoreImport) { |
685 | 845 | $highlight = ''; |
686 | - if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack'; |
|
687 | - if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)'; |
|
688 | - if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency'; |
|
689 | - 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'))); |
|
846 | + if ($this->all_flights[$id]['squawk'] == '7500') { |
|
847 | + $highlight = 'Squawk 7500 : Hijack'; |
|
848 | + } |
|
849 | + if ($this->all_flights[$id]['squawk'] == '7600') { |
|
850 | + $highlight = 'Squawk 7600 : Lost Comm (radio failure)'; |
|
851 | + } |
|
852 | + if ($this->all_flights[$id]['squawk'] == '7700') { |
|
853 | + $highlight = 'Squawk 7700 : Emergency'; |
|
854 | + } |
|
855 | + if (!isset($this->all_flights[$id]['id'])) { |
|
856 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
|
857 | + } |
|
690 | 858 | $timeelapsed = microtime(true); |
691 | 859 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
692 | 860 | $Spotter = new Spotter($this->db); |
693 | 861 | $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]['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']); |
694 | 862 | $Spotter->db = null; |
695 | - if ($globalDebug && isset($result)) echo $result."\n"; |
|
863 | + if ($globalDebug && isset($result)) { |
|
864 | + echo $result."\n"; |
|
865 | + } |
|
866 | + } |
|
867 | + if ($globalDebugTimeElapsed) { |
|
868 | + echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
696 | 869 | } |
697 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
698 | 870 | |
699 | 871 | // Add source stat in DB |
700 | 872 | $Stats = new Stats($this->db); |
701 | 873 | if (!empty($this->stats)) { |
702 | - if ($globalDebug) echo 'Add source stats : '; |
|
874 | + if ($globalDebug) { |
|
875 | + echo 'Add source stats : '; |
|
876 | + } |
|
703 | 877 | foreach($this->stats as $date => $data) { |
704 | 878 | foreach($data as $source => $sourced) { |
705 | 879 | //print_r($sourced); |
706 | - if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date); |
|
707 | - if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date); |
|
880 | + if (isset($sourced['polar'])) { |
|
881 | + echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date); |
|
882 | + } |
|
883 | + if (isset($sourced['hist'])) { |
|
884 | + echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date); |
|
885 | + } |
|
708 | 886 | if (isset($sourced['msg'])) { |
709 | 887 | if (time() - $sourced['msg']['date'] > 10) { |
710 | 888 | $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
@@ -717,13 +895,17 @@ discard block |
||
717 | 895 | unset($this->stats[$date]); |
718 | 896 | } |
719 | 897 | } |
720 | - if ($globalDebug) echo 'Done'."\n"; |
|
898 | + if ($globalDebug) { |
|
899 | + echo 'Done'."\n"; |
|
900 | + } |
|
721 | 901 | |
722 | 902 | } |
723 | 903 | $Stats->db = null; |
724 | 904 | |
725 | 905 | $this->del(); |
726 | - } elseif ($globalDebug) echo 'Ignore data'."\n"; |
|
906 | + } elseif ($globalDebug) { |
|
907 | + echo 'Ignore data'."\n"; |
|
908 | + } |
|
727 | 909 | //$ignoreImport = false; |
728 | 910 | $this->all_flights[$id]['addedSpotter'] = 1; |
729 | 911 | //print_r($this->all_flights[$id]); |
@@ -740,14 +922,18 @@ discard block |
||
740 | 922 | */ |
741 | 923 | //SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']); |
742 | 924 | if ($this->last_delete == 0 || time() - $this->last_delete > 1800) { |
743 | - if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours..."; |
|
925 | + if ($globalDebug) { |
|
926 | + echo "---- Deleting Live Spotter data older than 9 hours..."; |
|
927 | + } |
|
744 | 928 | //SpotterLive->deleteLiveSpotterDataNotUpdated(); |
745 | 929 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
746 | 930 | $SpotterLive = new SpotterLive($this->db); |
747 | 931 | $SpotterLive->deleteLiveSpotterData(); |
748 | 932 | $SpotterLive->db=null; |
749 | 933 | } |
750 | - if ($globalDebug) echo " Done\n"; |
|
934 | + if ($globalDebug) { |
|
935 | + echo " Done\n"; |
|
936 | + } |
|
751 | 937 | $this->last_delete = time(); |
752 | 938 | } |
753 | 939 | } else { |
@@ -772,11 +958,17 @@ discard block |
||
772 | 958 | //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"; |
773 | 959 | if ($globalDebug) { |
774 | 960 | if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) { |
775 | - 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"; |
|
776 | - 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"; |
|
961 | + if (isset($this->all_flights[$id]['source_name'])) { |
|
962 | + 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"; |
|
963 | + } else { |
|
964 | + 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"; |
|
965 | + } |
|
777 | 966 | } else { |
778 | - 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"; |
|
779 | - 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"; |
|
967 | + if (isset($this->all_flights[$id]['source_name'])) { |
|
968 | + 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"; |
|
969 | + } else { |
|
970 | + 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"; |
|
971 | + } |
|
780 | 972 | } |
781 | 973 | } |
782 | 974 | $ignoreImport = false; |
@@ -822,26 +1014,34 @@ discard block |
||
822 | 1014 | |
823 | 1015 | if (!$ignoreImport) { |
824 | 1016 | 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'])) { |
825 | - if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : "; |
|
1017 | + if ($globalDebug) { |
|
1018 | + echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : "; |
|
1019 | + } |
|
826 | 1020 | $timeelapsed = microtime(true); |
827 | 1021 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
828 | 1022 | $SpotterLive = new SpotterLive($this->db); |
829 | 1023 | $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]['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']); |
830 | 1024 | $SpotterLive->db = null; |
831 | - if ($globalDebug) echo $result."\n"; |
|
1025 | + if ($globalDebug) { |
|
1026 | + echo $result."\n"; |
|
1027 | + } |
|
832 | 1028 | } |
833 | 1029 | if (isset($globalServerAPRS) && $globalServerAPRS) { |
834 | 1030 | $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]['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']); |
835 | 1031 | } |
836 | 1032 | $this->all_flights[$id]['putinarchive'] = false; |
837 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
1033 | + if ($globalDebugTimeElapsed) { |
|
1034 | + echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
1035 | + } |
|
838 | 1036 | |
839 | 1037 | // Put statistics in $this->stats variable |
840 | 1038 | //if ($line['format_source'] != 'aprs') { |
841 | 1039 | //if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt')) { |
842 | 1040 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') { |
843 | 1041 | $source = $this->all_flights[$id]['source_name']; |
844 | - if ($source == '') $source = $this->all_flights[$id]['format_source']; |
|
1042 | + if ($source == '') { |
|
1043 | + $source = $this->all_flights[$id]['format_source']; |
|
1044 | + } |
|
845 | 1045 | if (!isset($this->source_location[$source])) { |
846 | 1046 | $Location = new Source(); |
847 | 1047 | $coord = $Location->getLocationInfobySourceName($source); |
@@ -862,7 +1062,9 @@ discard block |
||
862 | 1062 | $stats_heading = round($stats_heading/22.5); |
863 | 1063 | $stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']); |
864 | 1064 | $current_date = date('Y-m-d'); |
865 | - if ($stats_heading == 16) $stats_heading = 0; |
|
1065 | + if ($stats_heading == 16) { |
|
1066 | + $stats_heading = 0; |
|
1067 | + } |
|
866 | 1068 | if (!isset($this->stats[$current_date][$source]['polar'][1])) { |
867 | 1069 | for ($i=0;$i<=15;$i++) { |
868 | 1070 | $this->stats[$current_date][$source]['polar'][$i] = 0; |
@@ -880,7 +1082,9 @@ discard block |
||
880 | 1082 | if (isset($this->stats[$current_date][$source]['hist'][0])) { |
881 | 1083 | end($this->stats[$current_date][$source]['hist']); |
882 | 1084 | $mini = key($this->stats[$current_date][$source]['hist'])+10; |
883 | - } else $mini = 0; |
|
1085 | + } else { |
|
1086 | + $mini = 0; |
|
1087 | + } |
|
884 | 1088 | for ($i=$mini;$i<=$distance;$i+=10) { |
885 | 1089 | $this->stats[$current_date][$source]['hist'][$i] = 0; |
886 | 1090 | } |
@@ -891,19 +1095,27 @@ discard block |
||
891 | 1095 | } |
892 | 1096 | |
893 | 1097 | $this->all_flights[$id]['lastupdate'] = time(); |
894 | - if ($this->all_flights[$id]['putinarchive']) $send = true; |
|
1098 | + if ($this->all_flights[$id]['putinarchive']) { |
|
1099 | + $send = true; |
|
1100 | + } |
|
895 | 1101 | //if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
896 | - } 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"; |
|
1102 | + } elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) { |
|
1103 | + echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
|
1104 | + } |
|
897 | 1105 | //$this->del(); |
898 | 1106 | |
899 | 1107 | |
900 | 1108 | if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) { |
901 | - if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour..."; |
|
1109 | + if ($globalDebug) { |
|
1110 | + echo "---- Deleting Live Spotter data Not updated since 2 hour..."; |
|
1111 | + } |
|
902 | 1112 | $SpotterLive = new SpotterLive($this->db); |
903 | 1113 | $SpotterLive->deleteLiveSpotterDataNotUpdated(); |
904 | 1114 | $SpotterLive->db = null; |
905 | 1115 | //SpotterLive->deleteLiveSpotterData(); |
906 | - if ($globalDebug) echo " Done\n"; |
|
1116 | + if ($globalDebug) { |
|
1117 | + echo " Done\n"; |
|
1118 | + } |
|
907 | 1119 | $this->last_delete_hourly = time(); |
908 | 1120 | } |
909 | 1121 | |
@@ -911,7 +1123,9 @@ discard block |
||
911 | 1123 | //$ignoreImport = false; |
912 | 1124 | } |
913 | 1125 | //if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN); |
914 | - if ($send) return $this->all_flights[$id]; |
|
1126 | + if ($send) { |
|
1127 | + return $this->all_flights[$id]; |
|
1128 | + } |
|
915 | 1129 | } |
916 | 1130 | } |
917 | 1131 | } |