| Conditions | 429 |
| Paths | 0 |
| Total Lines | 710 |
| Code Lines | 422 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 208 | public function add($line) { |
||
| 209 | 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 | //if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE; |
||
| 211 | if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02'; |
||
| 212 | /* |
||
| 213 | $Spotter = new Spotter(); |
||
| 214 | $dbc = $Spotter->db; |
||
| 215 | $SpotterLive = new SpotterLive($dbc); |
||
| 216 | $Common = new Common(); |
||
| 217 | $Schedule = new Schedule($dbc); |
||
| 218 | */ |
||
| 219 | date_default_timezone_set('UTC'); |
||
| 220 | // signal handler - playing nice with sockets and dump1090 |
||
| 221 | // pcntl_signal_dispatch(); |
||
| 222 | |||
| 223 | // get the time (so we can figure the timeout) |
||
| 224 | //$time = time(); |
||
| 225 | |||
| 226 | //pcntl_signal_dispatch(); |
||
| 227 | $dataFound = false; |
||
| 228 | //$putinarchive = false; |
||
| 229 | $send = false; |
||
| 230 | |||
| 231 | // SBS format is CSV format |
||
| 232 | if(is_array($line) && (isset($line['hex']) || isset($line['id']))) { |
||
| 233 | //print_r($line); |
||
| 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 | |||
| 236 | // Increment message number |
||
| 237 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) { |
||
| 238 | $current_date = date('Y-m-d'); |
||
| 239 | $source = $line['source_name']; |
||
| 240 | if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source']; |
||
| 241 | if (!isset($this->stats[$current_date][$source]['msg'])) { |
||
| 242 | $this->stats[$current_date][$source]['msg']['date'] = time(); |
||
| 243 | $this->stats[$current_date][$source]['msg']['nb'] = 1; |
||
| 244 | } else $this->stats[$current_date][$source]['msg']['nb'] += 1; |
||
| 245 | } |
||
| 246 | |||
| 247 | /* |
||
| 248 | $dbc = $this->db; |
||
| 249 | $Connection = new Connection($dbc); |
||
| 250 | $Connection->connectionExists(); |
||
| 251 | $dbc = $Connection->db; |
||
| 252 | */ |
||
| 253 | //$Spotter = new Spotter($dbc); |
||
| 254 | //$SpotterLive = new SpotterLive($dbc); |
||
| 255 | $Common = new Common(); |
||
| 256 | // echo $this->nb++."\n"; |
||
| 257 | //$this->db = $dbc; |
||
| 258 | |||
| 259 | //$hex = trim($line['hex']); |
||
| 260 | if (!isset($line['id'])) $id = trim($line['hex']); |
||
| 261 | else $id = trim($line['id']); |
||
| 262 | |||
| 263 | if (!isset($this->all_flights[$id])) { |
||
| 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())); |
||
| 268 | 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'))); |
||
| 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'))); |
||
| 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'])); |
||
| 275 | if ($globalAllFlights !== FALSE) $dataFound = true; |
||
| 276 | } |
||
| 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'])); |
||
| 279 | } |
||
| 280 | |||
| 281 | //print_r($this->all_flights); |
||
| 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']))); |
||
| 284 | //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) { |
||
| 285 | //$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime'])); |
||
| 286 | //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s'))); |
||
| 287 | if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????') && $line['format_source'] != 'whazzup' && $line['format_source'] != 'vatsimtxt' && $line['format_source'] != 'pireps' && $line['format_source'] != 'phpvmacars' && $line['format_source'] != 'vam' && $line['format_source'] != 'flightgearsp' && $line['format_source'] != 'flightgearmp') { |
||
| 288 | $timeelapsed = microtime(true); |
||
| 289 | $Spotter = new Spotter($this->db); |
||
| 290 | if (isset($this->all_flights[$id]['source_type'])) { |
||
| 291 | $aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']),$this->all_flights[$id]['source_type']); |
||
| 292 | } else { |
||
| 293 | $aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex'])); |
||
| 294 | } |
||
| 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)); |
||
| 298 | } |
||
| 299 | if ($globalAllFlights !== FALSE) $dataFound = true; |
||
| 300 | if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n"; |
||
| 301 | } |
||
| 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'])); |
||
| 304 | } |
||
| 305 | if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_name'])) { |
||
| 306 | // Get aircraft ICAO from aircraft name |
||
| 307 | $Spotter = new Spotter($this->db); |
||
| 308 | $aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']); |
||
| 309 | $Spotter->db = null; |
||
| 310 | if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
||
| 311 | } |
||
| 312 | 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)); |
||
| 318 | } |
||
| 319 | if (!isset($this->all_flights[$id]['aircraft_icao'])) { |
||
| 320 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA')); |
||
| 321 | } |
||
| 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) { |
||
| 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'])); |
||
| 326 | } 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"; |
||
| 329 | /* |
||
| 330 | echo strtotime($line['datetime']).' > '.strtotime($this->all_flights[$id]['datetime']); |
||
| 331 | print_r($this->all_flights[$id]); |
||
| 332 | print_r($line); |
||
| 333 | */ |
||
| 334 | return ''; |
||
| 335 | } |
||
| 336 | } else { |
||
| 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'))); |
||
| 339 | } |
||
| 340 | |||
| 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'])); |
||
| 343 | } |
||
| 344 | if (isset($line['waypoints']) && $line['waypoints'] != '') { |
||
| 345 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints'])); |
||
| 346 | } |
||
| 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'])); |
||
| 349 | } |
||
| 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'])); |
||
| 352 | } |
||
| 353 | |||
| 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']))); |
||
| 356 | if ($this->all_flights[$id]['addedSpotter'] == 1) { |
||
| 357 | $timeelapsed = microtime(true); |
||
| 358 | $Spotter = new Spotter($this->db); |
||
| 359 | $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'; |
||
| 365 | $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource); |
||
| 366 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
||
| 367 | $Spotter->db = null; |
||
| 368 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 369 | } |
||
| 370 | |||
| 371 | /* |
||
| 372 | if (!isset($line['id'])) { |
||
| 373 | if (!isset($globalDaemon)) $globalDaemon = TRUE; |
||
| 374 | // 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'))); |
||
| 375 | 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'))); |
||
| 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 | } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
||
| 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'])); |
||
| 380 | |||
| 381 | //$putinarchive = true; |
||
| 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'])); |
||
| 384 | } |
||
| 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'])); |
||
| 387 | } |
||
| 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' => '')); |
||
| 390 | } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) { |
||
| 391 | $timeelapsed = microtime(true); |
||
| 392 | $Spotter = new Spotter($this->db); |
||
| 393 | $line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']); |
||
| 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"; |
||
| 397 | |||
| 398 | } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') { |
||
| 399 | $timeelapsed = microtime(true); |
||
| 400 | $Spotter = new Spotter($this->db); |
||
| 401 | $route = $Spotter->getRouteInfo(trim($line['ident'])); |
||
| 402 | if (!isset($route['fromairport_icao']) && !isset($route['toairport_icao'])) { |
||
| 403 | $Translation = new Translation($this->db); |
||
| 404 | $ident = $Translation->checkTranslation(trim($line['ident'])); |
||
| 405 | $route = $Spotter->getRouteInfo($ident); |
||
| 406 | $Translation->db = null; |
||
| 407 | } |
||
| 408 | $Spotter->db = null; |
||
| 409 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 410 | |||
| 411 | if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) { |
||
| 412 | //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) { |
||
| 413 | if ($route['fromairport_icao'] != $route['toairport_icao']) { |
||
| 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'])); |
||
| 416 | } |
||
| 417 | } |
||
| 418 | if (!isset($globalFork)) $globalFork = TRUE; |
||
| 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'])); |
||
| 421 | } |
||
| 422 | } |
||
| 423 | } |
||
| 424 | |||
| 425 | if (isset($line['speed']) && $line['speed'] != '') { |
||
| 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)); |
||
| 429 | //$dataFound = true; |
||
| 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'); |
||
| 432 | if ($distance > 1000 && $distance < 10000) { |
||
| 433 | // use datetime |
||
| 434 | $speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']); |
||
| 435 | $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"; |
||
| 438 | } |
||
| 439 | } |
||
| 440 | |||
| 441 | |||
| 442 | |||
| 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']); |
||
| 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')))) { |
||
| 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'])) { |
||
| 449 | $this->all_flights[$id]['archive_latitude'] = $line['latitude']; |
||
| 450 | $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
||
| 451 | $this->all_flights[$id]['putinarchive'] = true; |
||
| 452 | |||
| 453 | if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
||
| 454 | $timeelapsed = microtime(true); |
||
| 455 | $Spotter = new Spotter($this->db); |
||
| 456 | $all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
||
| 457 | if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2']; |
||
| 458 | $Spotter->db = null; |
||
| 459 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 460 | $this->tmd = 0; |
||
| 461 | if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n"; |
||
| 462 | } |
||
| 463 | } |
||
| 464 | |||
| 465 | if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
||
| 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 | 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') { |
||
| 469 | $this->all_flights[$id]['livedb_latitude'] = $line['latitude']; |
||
| 470 | $dataFound = true; |
||
| 471 | $this->all_flights[$id]['time_last_coord'] = time(); |
||
| 472 | } |
||
| 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'])); |
||
| 475 | /* |
||
| 476 | if (abs($this->all_flights[$id]['archive_latitude']-$this->all_flights[$id]['latitude']) > 0.3) { |
||
| 477 | $this->all_flights[$id]['archive_latitude'] = $line['latitude']; |
||
| 478 | $this->all_flights[$id]['putinarchive'] = true; |
||
| 479 | //$putinarchive = true; |
||
| 480 | } |
||
| 481 | */ |
||
| 482 | /* |
||
| 483 | } elseif (isset($this->all_flights[$id]['latitude'])) { |
||
| 484 | if ($globalDebug) echo '!!! Strange latitude value - diff : '.abs($this->all_flights[$id]['latitude']-$line['latitude']).'- previous lat : '.$this->all_flights[$id]['latitude'].'- new lat : '.$line['latitude']."\n"; |
||
| 485 | } |
||
| 486 | */ |
||
| 487 | } |
||
| 488 | 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; |
||
| 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 | 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') { |
||
| 493 | $this->all_flights[$id]['livedb_longitude'] = $line['longitude']; |
||
| 494 | $dataFound = true; |
||
| 495 | $this->all_flights[$id]['time_last_coord'] = time(); |
||
| 496 | } |
||
| 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'])); |
||
| 499 | /* |
||
| 500 | if (abs($this->all_flights[$id]['archive_longitude']-$this->all_flights[$id]['longitude']) > 0.3) { |
||
| 501 | $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
||
| 502 | $this->all_flights[$id]['putinarchive'] = true; |
||
| 503 | //$putinarchive = true; |
||
| 504 | } |
||
| 505 | */ |
||
| 506 | /* |
||
| 507 | } elseif (isset($this->all_flights[$id]['longitude'])) { |
||
| 508 | if ($globalDebug) echo '!!! Strange longitude value - diff : '.abs($this->all_flights[$id]['longitude']-$line['longitude']).'- previous lat : '.$this->all_flights[$id]['longitude'].'- new lat : '.$line['longitude']."\n"; |
||
| 509 | } |
||
| 510 | */ |
||
| 511 | } |
||
| 512 | |||
| 513 | } else if ($globalDebug && $timediff > 20) { |
||
| 514 | $this->tmd = $this->tmd + 1; |
||
| 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 - "; |
||
| 518 | echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n"; |
||
| 519 | } |
||
| 520 | } |
||
| 521 | 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; |
||
| 523 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update'])); |
||
| 524 | } |
||
| 525 | if (isset($line['verticalrate']) && $line['verticalrate'] != '') { |
||
| 526 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate'])); |
||
| 527 | //$dataFound = true; |
||
| 528 | } |
||
| 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'])); |
||
| 531 | } |
||
| 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'])); |
||
| 534 | } |
||
| 535 | if (isset($line['emergency']) && $line['emergency'] != '') { |
||
| 536 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency'])); |
||
| 537 | //$dataFound = true; |
||
| 538 | } |
||
| 539 | if (isset($line['ground']) && $line['ground'] != '') { |
||
| 540 | if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) { |
||
| 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'])); |
||
| 547 | } |
||
| 548 | if ($line['ground'] != 1) $line['ground'] = 0; |
||
| 549 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground'])); |
||
| 550 | //$dataFound = true; |
||
| 551 | } |
||
| 552 | if (isset($line['squawk']) && $line['squawk'] != '') { |
||
| 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 | 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'])); |
||
| 556 | $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'; |
||
| 560 | if ($highlight != '') { |
||
| 561 | $timeelapsed = microtime(true); |
||
| 562 | $Spotter = new Spotter($this->db); |
||
| 563 | $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight); |
||
| 564 | $Spotter->db = null; |
||
| 565 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 566 | |||
| 567 | //$putinarchive = true; |
||
| 568 | //$highlight = ''; |
||
| 569 | } |
||
| 570 | |||
| 571 | } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
||
| 572 | //$dataFound = true; |
||
| 573 | } |
||
| 574 | |||
| 575 | if (isset($line['altitude']) && $line['altitude'] != '') { |
||
| 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'])); |
||
| 580 | //$dataFound = true; |
||
| 581 | //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n"; |
||
| 582 | } |
||
| 583 | |||
| 584 | if (isset($line['noarchive']) && $line['noarchive'] === true) { |
||
| 585 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true)); |
||
| 586 | } |
||
| 587 | |||
| 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)); |
||
| 592 | //$dataFound = true; |
||
| 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; |
||
| 597 | if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n"; |
||
| 598 | } elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') { |
||
| 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)); |
||
| 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; |
||
| 604 | |||
| 605 | // print_r($this->all_flights[$id]); |
||
| 606 | //gets the callsign from the last hour |
||
| 607 | //if (time()-$this->all_flights[$id]['lastupdate'] > 30 && $dataFound == true && $this->all_flights[$id]['ident'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') { |
||
| 608 | //if ($dataFound == true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['ident'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') { |
||
| 609 | //if ($dataFound === true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['heading'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') { |
||
| 610 | if ($dataFound === true && isset($this->all_flights[$id]['hex'])) { |
||
| 611 | $this->all_flights[$id]['lastupdate'] = time(); |
||
| 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'])) { |
||
| 614 | //print_r($this->all_flights); |
||
| 615 | //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n"; |
||
| 616 | //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']); |
||
| 617 | if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) { |
||
| 618 | if ($globalDebug) echo "Check if aircraft is already in DB..."; |
||
| 619 | $timeelapsed = microtime(true); |
||
| 620 | $SpotterLive = new SpotterLive($this->db); |
||
| 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 | $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"; |
||
| 624 | } elseif (isset($line['id'])) { |
||
| 625 | $recent_ident = $SpotterLive->checkIdRecent($line['id']); |
||
| 626 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 627 | } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') { |
||
| 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"; |
||
| 630 | } else $recent_ident = ''; |
||
| 631 | $SpotterLive->db=null; |
||
| 632 | |||
| 633 | if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
||
| 634 | elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
||
| 635 | } else { |
||
| 636 | $recent_ident = ''; |
||
| 637 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0)); |
||
| 638 | } |
||
| 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 == "") |
||
| 641 | { |
||
| 642 | if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : "; |
||
| 643 | if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } |
||
| 644 | if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } |
||
| 645 | //adds the spotter data for the archive |
||
| 646 | $ignoreImport = false; |
||
| 647 | foreach($globalAirportIgnore as $airportIgnore) { |
||
| 648 | if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
||
| 649 | $ignoreImport = true; |
||
| 650 | } |
||
| 651 | } |
||
| 652 | if (count($globalAirportAccept) > 0) { |
||
| 653 | $ignoreImport = true; |
||
| 654 | foreach($globalAirportIgnore as $airportIgnore) { |
||
| 655 | if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
||
| 656 | $ignoreImport = false; |
||
| 657 | } |
||
| 658 | } |
||
| 659 | } |
||
| 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)) { |
||
| 663 | $ignoreImport = true; |
||
| 664 | } |
||
| 665 | } |
||
| 666 | } |
||
| 667 | if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) { |
||
| 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)) { |
||
| 671 | $ignoreImport = false; |
||
| 672 | } |
||
| 673 | } |
||
| 674 | } |
||
| 675 | if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) { |
||
| 676 | $ignoreImport = true; |
||
| 677 | foreach($globalPilotIdAccept as $pilotIdAccept) { |
||
| 678 | if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) { |
||
| 679 | $ignoreImport = false; |
||
| 680 | } |
||
| 681 | } |
||
| 682 | } |
||
| 683 | |||
| 684 | if (!$ignoreImport) { |
||
| 685 | $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'))); |
||
| 690 | $timeelapsed = microtime(true); |
||
| 691 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
||
| 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']); |
||
| 694 | $Spotter->db = null; |
||
| 695 | if ($globalDebug && isset($result)) echo $result."\n"; |
||
| 696 | } |
||
| 697 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 698 | |||
| 699 | // Add source stat in DB |
||
| 700 | $Stats = new Stats($this->db); |
||
| 701 | if (!empty($this->stats)) { |
||
| 702 | if ($globalDebug) echo 'Add source stats : '; |
||
| 703 | foreach($this->stats as $date => $data) { |
||
| 704 | foreach($data as $source => $sourced) { |
||
| 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); |
||
| 708 | if (isset($sourced['msg'])) { |
||
| 709 | if (time() - $sourced['msg']['date'] > 10) { |
||
| 710 | $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
||
| 711 | echo $Stats->addStatSource($nbmsg,$source,'msg',$date); |
||
| 712 | unset($this->stats[$date][$source]['msg']); |
||
| 713 | } |
||
| 714 | } |
||
| 715 | } |
||
| 716 | if ($date != date('Y-m-d')) { |
||
| 717 | unset($this->stats[$date]); |
||
| 718 | } |
||
| 719 | } |
||
| 720 | if ($globalDebug) echo 'Done'."\n"; |
||
| 721 | |||
| 722 | } |
||
| 723 | $Stats->db = null; |
||
| 724 | |||
| 725 | $this->del(); |
||
| 726 | } elseif ($globalDebug) echo 'Ignore data'."\n"; |
||
| 727 | //$ignoreImport = false; |
||
| 728 | $this->all_flights[$id]['addedSpotter'] = 1; |
||
| 729 | //print_r($this->all_flights[$id]); |
||
| 730 | /* |
||
| 731 | if (isset($globalArchive) && $globalArchive) { |
||
| 732 | $archives_ident = SpotterLive->getAllLiveSpotterDataByIdent($this->all_flights[$id]['ident']); |
||
| 733 | foreach ($archives_ident as $archive) { |
||
| 734 | SpotterArchive->addSpotterArchiveData($archive['flightaware_id'], $archive['ident'], $archive['registration'],$archive['airline_name'],$archive['airline_icao'],$archive['airline_country'],$archive['airline_type'],$archive['aircraft_icao'],$archive['aircraft_shadow'],$archive['aircraft_name'],$archive['aircraft_manufacturer'], $archive['departure_airport_icao'],$archive['departure_airport_name'],$archive['departure_airport_city'],$archive['departure_airport_country'],$archive['departure_airport_time'], |
||
| 735 | $archive['arrival_airport_icao'],$archive['arrival_airport_name'],$archive['arrival_airport_city'],$archive['arrival_airport_country'],$archive['arrival_airport_time'], |
||
| 736 | $archive['route_stop'],$archive['date'],$archive['latitude'], $archive['longitude'], $archive['waypoints'], $archive['altitude'], $archive['heading'], $archive['ground_speed'], |
||
| 737 | $archive['squawk'],$archive['ModeS']); |
||
| 738 | } |
||
| 739 | } |
||
| 740 | */ |
||
| 741 | //SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']); |
||
| 742 | if ($this->last_delete == 0 || time() - $this->last_delete > 1800) { |
||
| 743 | if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours..."; |
||
| 744 | //SpotterLive->deleteLiveSpotterDataNotUpdated(); |
||
| 745 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
||
| 746 | $SpotterLive = new SpotterLive($this->db); |
||
| 747 | $SpotterLive->deleteLiveSpotterData(); |
||
| 748 | $SpotterLive->db=null; |
||
| 749 | } |
||
| 750 | if ($globalDebug) echo " Done\n"; |
||
| 751 | $this->last_delete = time(); |
||
| 752 | } |
||
| 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')) { |
||
| 755 | $this->all_flights[$id]['id'] = $recent_ident; |
||
| 756 | $this->all_flights[$id]['addedSpotter'] = 1; |
||
| 757 | } |
||
| 758 | if (isset($globalDaemon) && !$globalDaemon) { |
||
| 759 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
||
| 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']); |
||
| 762 | $Spotter->db = null; |
||
| 763 | } |
||
| 764 | } |
||
| 765 | |||
| 766 | } |
||
| 767 | } |
||
| 768 | } |
||
| 769 | //adds the spotter LIVE data |
||
| 770 | //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed); |
||
| 771 | //echo "\nAdd in Live !! \n"; |
||
| 772 | //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 | if ($globalDebug) { |
||
| 774 | 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"; |
||
| 777 | } 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"; |
||
| 780 | } |
||
| 781 | } |
||
| 782 | $ignoreImport = false; |
||
| 783 | if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } |
||
| 784 | if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } |
||
| 785 | |||
| 786 | foreach($globalAirportIgnore as $airportIgnore) { |
||
| 787 | if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
||
| 788 | $ignoreImport = true; |
||
| 789 | } |
||
| 790 | } |
||
| 791 | if (count($globalAirportAccept) > 0) { |
||
| 792 | $ignoreImport = true; |
||
| 793 | foreach($globalAirportIgnore as $airportIgnore) { |
||
| 794 | if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
||
| 795 | $ignoreImport = false; |
||
| 796 | } |
||
| 797 | } |
||
| 798 | } |
||
| 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)) { |
||
| 802 | $ignoreImport = true; |
||
| 803 | } |
||
| 804 | } |
||
| 805 | } |
||
| 806 | if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) { |
||
| 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)) { |
||
| 810 | $ignoreImport = false; |
||
| 811 | } |
||
| 812 | } |
||
| 813 | } |
||
| 814 | if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) { |
||
| 815 | $ignoreImport = true; |
||
| 816 | foreach($globalPilotIdAccept as $pilotIdAccept) { |
||
| 817 | if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) { |
||
| 818 | $ignoreImport = false; |
||
| 819 | } |
||
| 820 | } |
||
| 821 | } |
||
| 822 | |||
| 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'])) { |
||
| 825 | if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : "; |
||
| 826 | $timeelapsed = microtime(true); |
||
| 827 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
||
| 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']); |
||
| 830 | $SpotterLive->db = null; |
||
| 831 | } |
||
| 832 | if (isset($globalServerAPRS) && $globalServerAPRS) { |
||
| 833 | $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 | } |
||
| 835 | $this->all_flights[$id]['putinarchive'] = false; |
||
| 836 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
||
| 837 | |||
| 838 | // Put statistics in $this->stats variable |
||
| 839 | //if ($line['format_source'] != 'aprs') { |
||
| 840 | //if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt')) { |
||
| 841 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') { |
||
| 842 | $source = $this->all_flights[$id]['source_name']; |
||
| 843 | if ($source == '') $source = $this->all_flights[$id]['format_source']; |
||
| 844 | if (!isset($this->source_location[$source])) { |
||
| 845 | $Location = new Source(); |
||
| 846 | $coord = $Location->getLocationInfobySourceName($source); |
||
| 847 | if (count($coord) > 0) { |
||
| 848 | $latitude = $coord[0]['latitude']; |
||
| 849 | $longitude = $coord[0]['longitude']; |
||
| 850 | } else { |
||
| 851 | $latitude = $globalCenterLatitude; |
||
| 852 | $longitude = $globalCenterLongitude; |
||
| 853 | } |
||
| 854 | $this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude); |
||
| 855 | } else { |
||
| 856 | $latitude = $this->source_location[$source]['latitude']; |
||
| 857 | $longitude = $this->source_location[$source]['longitude']; |
||
| 858 | } |
||
| 859 | $stats_heading = $Common->getHeading($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']); |
||
| 860 | //$stats_heading = $stats_heading%22.5; |
||
| 861 | $stats_heading = round($stats_heading/22.5); |
||
| 862 | $stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']); |
||
| 863 | $current_date = date('Y-m-d'); |
||
| 864 | if ($stats_heading == 16) $stats_heading = 0; |
||
| 865 | if (!isset($this->stats[$current_date][$source]['polar'][1])) { |
||
| 866 | for ($i=0;$i<=15;$i++) { |
||
| 867 | $this->stats[$current_date][$source]['polar'][$i] = 0; |
||
| 868 | } |
||
| 869 | $this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance; |
||
| 870 | } else { |
||
| 871 | if ($this->stats[$current_date][$source]['polar'][$stats_heading] < $stats_distance) { |
||
| 872 | $this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance; |
||
| 873 | } |
||
| 874 | } |
||
| 875 | $distance = (round($stats_distance/10)*10); |
||
| 876 | //echo '$$$$$$$$$$ DISTANCE : '.$distance.' - '.$source."\n"; |
||
| 877 | //var_dump($this->stats); |
||
| 878 | if (!isset($this->stats[$current_date][$source]['hist'][$distance])) { |
||
| 879 | if (isset($this->stats[$current_date][$source]['hist'][0])) { |
||
| 880 | end($this->stats[$current_date][$source]['hist']); |
||
| 881 | $mini = key($this->stats[$current_date][$source]['hist'])+10; |
||
| 882 | } else $mini = 0; |
||
| 883 | for ($i=$mini;$i<=$distance;$i+=10) { |
||
| 884 | $this->stats[$current_date][$source]['hist'][$i] = 0; |
||
| 885 | } |
||
| 886 | $this->stats[$current_date][$source]['hist'][$distance] = 1; |
||
| 887 | } else { |
||
| 888 | $this->stats[$current_date][$source]['hist'][$distance] += 1; |
||
| 889 | } |
||
| 890 | } |
||
| 891 | |||
| 892 | $this->all_flights[$id]['lastupdate'] = time(); |
||
| 893 | if ($this->all_flights[$id]['putinarchive']) $send = true; |
||
| 894 | //if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
||
| 895 | if ($globalDebug) echo $result."\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 | //$this->del(); |
||
| 898 | |||
| 899 | |||
| 900 | 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..."; |
||
| 902 | $SpotterLive = new SpotterLive($this->db); |
||
| 903 | $SpotterLive->deleteLiveSpotterDataNotUpdated(); |
||
| 904 | $SpotterLive->db = null; |
||
| 905 | //SpotterLive->deleteLiveSpotterData(); |
||
| 906 | if ($globalDebug) echo " Done\n"; |
||
| 907 | $this->last_delete_hourly = time(); |
||
| 908 | } |
||
| 909 | |||
| 910 | } |
||
| 911 | //$ignoreImport = false; |
||
| 912 | } |
||
| 913 | //if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN); |
||
| 914 | if ($send) return $this->all_flights[$id]; |
||
| 915 | } |
||
| 916 | } |
||
| 917 | } |
||
| 918 | } |
||
| 920 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: