public function resetdistances() { echo '<h3>Updating and Calculating Distances</h3>'; # Update all of the schedules echo '<p><strong>Updating schedules...</strong></p>'; //$allschedules = SchedulesData::GetSchedulesNoDistance(); $allschedules = SchedulesData::findSchedules(array()); if (!$allschedules) { echo 'No schedules to update'; $allschedules = array(); } # Check 'em foreach ($allschedules as $sched) { $distance = SchedulesData::distanceBetweenPoints($sched->deplat, $sched->deplng, $sched->arrlat, $sched->arrlng); $distance = sprintf("%.6f", $distance); echo "{$sched->code}{$sched->flightnum} - {$sched->depname} to {$sched->arrname} " . "is {$distance} " . Config::Get('UNIT') . '<br />'; SchedulesData::updateScheduleFields($sched->id, array('distance' => $distance)); } # Update all of the PIREPS echo '<p><strong>Updating PIREPs...</strong></p>'; $allpireps = PIREPData::findPIREPS(array()); if (!$allpireps) { echo 'No PIREPs need updating!'; $allpireps = array(); } foreach ($allpireps as $pirep) { # Find the schedule, and the distance supplied by the schedule: $distance = SchedulesData::distanceBetweenPoints($pirep->deplat, $pirep->deplng, $pirep->arrlat, $pirep->arrlng); $distance = sprintf("%.2f", $distance); echo "PIREP Number {$pirep->pirepid} ({$pirep->code}{$pirep->flightnum}) " . "{$pirep->depname} to {$pirep->arrname} is {$distance} " . Config::Get('UNIT') . '<br />'; PIREPData::editPIREPFields($pirep->pirepid, array('distance' => $distance)); } echo '<p>Completed!</p><br />'; LogData::addLog(Auth::$userinfo->pilotid, 'Reset distances'); }
public function index() { if ($_SERVER['REQUEST_METHOD'] === 'POST') { $postText = file_get_contents('php://input'); $rec_xml = trim(utf8_encode(file_get_contents('php://input'))); $xml = simplexml_load_string($rec_xml); if (!$xml) { #$this->log("Invalid XML Sent: \n".$rec_xml, 'kacars'); return; } #$this->log(print_r($xml->asXML(), true), 'kacars'); $case = strtolower($xml->switch->data); switch ($case) { case 'verify': $results = Auth::ProcessLogin($xml->verify->pilotID, $xml->verify->password); if ($results) { $params = array('loginStatus' => '1'); //echo 1; } else { $params = array('loginStatus' => '0'); //echo 0; } $send = self::sendXML($params); break; case 'getbid': $pilotid = PilotData::parsePilotID($xml->verify->pilotID); $pilotinfo = PilotData::getPilotData($pilotid); $biddata = SchedulesData::getLatestBid($pilotid); $aircraftinfo = OperationsData::getAircraftByReg($biddata->registration); if (count($biddata) == 1) { if ($aircraftinfo->enabled == 1) { $params = array('flightStatus' => '1', 'flightNumber' => $biddata->code . $biddata->flightnum, 'aircraftReg' => $biddata->registration, 'aircraftICAO' => $aircraftinfo->icao, 'aircraftFullName' => $aircraftinfo->fullname, 'flightLevel' => $biddata->flightlevel, 'aircraftMaxPax' => $aircraftinfo->maxpax, 'aircraftCargo' => $aircraftinfo->maxcargo, 'depICAO' => $biddata->depicao, 'arrICAO' => $biddata->arricao, 'route' => $biddata->route, 'depTime' => $biddata->deptime, 'arrTime' => $biddata->arrtime, 'flightTime' => $biddata->flighttime, 'flightType' => $biddata->flighttype, 'aircraftName' => $aircraftinfo->name, 'aircraftRange' => $aircraftinfo->range, 'aircraftWeight' => $aircraftinfo->weight, 'aircraftCruise' => $aircraftinfo->cruise); } else { $params = array('flightStatus' => '3'); // Aircraft Out of Service. } } else { $params = array('flightStatus' => '2'); // You have no bids! } $send = $this->sendXML($params); break; case 'getflight': $flightinfo = SchedulesData::getProperFlightNum($xml->pirep->flightNumber); $params = array('s.code' => $flightinfo['code'], 's.flightnum' => $flightinfo['flightnum'], 's.enabled' => 1); $biddata = SchedulesData::findSchedules($params, 1); $aircraftinfo = OperationsData::getAircraftByReg($biddata[0]->registration); if (count($biddata) == 1) { $params = array('flightStatus' => '1', 'flightNumber' => $biddata[0]->code . $biddata[0]->flightnum, 'aircraftReg' => $biddata[0]->registration, 'aircraftICAO' => $aircraftinfo->icao, 'aircraftFullName' => $aircraftinfo->fullname, 'flightLevel' => $biddata[0]->flightlevel, 'aircraftMaxPax' => $aircraftinfo->maxpax, 'aircraftCargo' => $aircraftinfo->maxcargo, 'depICAO' => $biddata[0]->depicao, 'arrICAO' => $biddata[0]->arricao, 'route' => $biddata[0]->route, 'depTime' => $biddata[0]->deptime, 'arrTime' => $biddata[0]->arrtime, 'flightTime' => $biddata[0]->flighttime, 'flightType' => $biddata[0]->flighttype, 'aircraftName' => $aircraftinfo->name, 'aircraftRange' => $aircraftinfo->range, 'aircraftWeight' => $aircraftinfo->weight, 'aircraftCruise' => $aircraftinfo->cruise); } else { $params = array('flightStatus' => '2'); } $send = $this->sendXML($params); break; case 'liveupdate': $pilotid = PilotData::parsePilotID($xml->verify->pilotID); # Get the distance remaining $depapt = OperationsData::GetAirportInfo($xml->liveupdate->depICAO); $arrapt = OperationsData::GetAirportInfo($xml->liveupdate->arrICAO); $dist_remain = round(SchedulesData::distanceBetweenPoints($xml->liveupdate->latitude, $xml->liveupdate->longitude, $arrapt->lat, $arrapt->lng)); # Estimate the time remaining if ($xml->liveupdate->groundSpeed > 0) { $Minutes = round($dist_remain / $xml->liveupdate->groundSpeed * 60); $time_remain = self::ConvertMinutes2Hours($Minutes); } else { $time_remain = '00:00'; } $lat = str_replace(",", ".", $xml->liveupdate->latitude); $lon = str_replace(",", ".", $xml->liveupdate->longitude); $fields = array('pilotid' => $pilotid, 'flightnum' => $xml->liveupdate->flightNumber, 'pilotname' => '', 'aircraft' => $xml->liveupdate->registration, 'lat' => $lat, 'lng' => $lon, 'heading' => $xml->liveupdate->heading, 'alt' => $xml->liveupdate->altitude, 'gs' => $xml->liveupdate->groundSpeed, 'depicao' => $xml->liveupdate->depICAO, 'arricao' => $xml->liveupdate->arrICAO, 'deptime' => $xml->liveupdate->depTime, 'arrtime' => '', 'route' => $xml->liveupdate->route, 'distremain' => $dist_remain, 'timeremaining' => $time_remain, 'phasedetail' => $xml->liveupdate->status, 'online' => '', 'client' => 'kACARS'); #$this->log("UpdateFlightData: \n".print_r($fields, true), 'kacars'); ACARSData::UpdateFlightData($pilotid, $fields); break; case 'pirep': $flightinfo = SchedulesData::getProperFlightNum($xml->pirep->flightNumber); $code = $flightinfo['code']; $flightnum = $flightinfo['flightnum']; $pilotid = PilotData::parsePilotID($xml->verify->pilotID); # Make sure airports exist: # If not, add them. if (!OperationsData::GetAirportInfo($xml->pirep->depICAO)) { OperationsData::RetrieveAirportInfo($xml->pirep->depICAO); } if (!OperationsData::GetAirportInfo($xml->pirep->arrICAO)) { OperationsData::RetrieveAirportInfo($xml->pirep->arrICAO); } # Get aircraft information $reg = trim($xml->pirep->registration); $ac = OperationsData::GetAircraftByReg($reg); # Load info /* If no passengers set, then set it to the cargo */ $load = $xml->pirep->pax; if (empty($load)) { $load = $xml->pirep->cargo; } /* Fuel conversion - kAcars only reports in lbs */ $fuelused = $xml->pirep->fuelUsed; if (Config::Get('LiquidUnit') == '0') { # Convert to KGs, divide by density since d = mass * volume $fuelused = $fuelused * 0.45359237 / 0.8075; } elseif (Config::Get('LiquidUnit') == '1') { $fuelused = $fuelused * 6.84; } elseif (Config::Get('LiquidUnit') == '2') { $fuelused = $fuelused * 0.45359237; } $data = array('pilotid' => $pilotid, 'code' => $code, 'flightnum' => $flightnum, 'depicao' => $xml->pirep->depICAO, 'arricao' => $xml->pirep->arrICAO, 'aircraft' => $ac->id, 'flighttime' => $xml->pirep->flightTime, 'submitdate' => 'NOW()', 'comment' => $xml->pirep->comments, 'fuelused' => $fuelused, 'source' => 'kACARS', 'load' => $load, 'landingrate' => $xml->pirep->landing, 'log' => $xml->pirep->log); #$this->log("File PIREP: \n".print_r($data, true), 'kacars'); $ret = ACARSData::FilePIREP($pilotid, $data); if ($ret) { $params = array('pirepStatus' => '1'); // Pirep Filed! } else { $params = array('pirepStatus' => '2'); // Please Try Again! } $send = $this->sendXML($params); break; case 'aircraft': $this->getAllAircraft(); break; } } }
/** * Process ACARS messages here * */ public function acars() { if (!isset($_REQUEST['DATA1'])) { die("0|Invalid Data"); } if (!isset($_REQUEST['DATA1'])) { die("0|Invalid Data"); } // TEST, BEGINFLIGHT, PAUSEFLIGHT, ENDFLIGHT and MESSAGE $method = strtoupper($_REQUEST['DATA2']); if (!isset($_REQUEST['DATA3'])) { $value = ''; } else { $value = $_REQUEST['DATA3']; } if (!isset($_REQUEST['DATA4'])) { $message = ''; } else { $message = $_REQUEST['DATA4']; } $this->log("Method: {$method}", 'fsfk'); $fields = array(); # Go through each method now if ($method == 'TEST') { $pilotid = $value; echo '1|30'; return; } elseif ($method == 'BEGINFLIGHT') { $flight_data = explode('|', $value); if (count($flight_data) < 10) { echo '0|Invalid login data'; return; } /*preg_match('/^([A-Za-z]*)(\d*)/', $flight_data[0], $matches); $code = $matches[1]; $pilotid = intval($matches[2]) - Config::Get('PILOTID_OFFSET');*/ $pilotid = PilotData::parsePilotID($flight_data[0]); $coords = $this->get_coordinates($flight_data[6]); $route = explode('~', $flight_data[5]); $depicao = $route[0]; $arricao = $route[count($route) - 1]; unset($route[0]); unset($route[count($route) - 1]); $route = implode(' ', $route); $flightinfo = SchedulesData::getProperFlightNum($flight_data[2]); $code = $flightinfo['code']; $flightnum = $flightinfo['flightnum']; $aircraft = $flight_data[3]; $heading = $flight_data[12]; $alt = $flight_data[7]; $gs = 0; $dist_remain = $flight_data[16]; $time_remain = 0; $deptime = time(); $online = 0; $fields = array('pilotid' => $pilotid, 'flightnum' => $code . $flightnum, 'aircraft' => $aircraft, 'lat' => $coords['lat'], 'lng' => $coords['lng'], 'heading' => $heading, 'route' => $route, 'alt' => $alt, 'gs' => $gs, 'depicao' => $depicao, 'arricao' => $arricao, 'distremain' => $dist_remain, 'timeremaining' => $time_remain, 'phasedetail' => 'On the ground', 'online' => $online, 'client' => 'fsfk'); } elseif ($method == 'MESSAGE') { $pilotid = $value; $flight_data = ACARSData::get_flight_by_pilot($pilotid); // Get the flight preg_match("/Flight ID: (.*)\n/", $message, $matches); $flightinfo = SchedulesData::getProperFlightNum($matches[1]); $code = $flightinfo['code']; $flightnum = $flightinfo['flightnum']; // Get the aircraft preg_match("/.*Aircraft Reg: \\.\\.(.*)\n/", $message, $matches); $aircraft_data = OperationsData::GetAircraftByReg(trim($matches[1])); $aircraft = $aircraft_data->id; $depicao = $flight_data->depicao; $arricao = $flight_data->arricao; // Get coordinates from ACARS message $count = preg_match("/POS(.*)\n/", $message, $matches); if ($count > 0) { $coords = $this->get_coordinates(trim($matches[1])); } else { $coords = array('lat' => $flight_data->lat, 'lng' => $flight_data->lng); } // Get our heading preg_match("/\\/HDG.(.*)\n/", $message, $matches); $heading = $matches[1]; // Get our altitude preg_match("/\\/ALT.(.*)\n/", $message, $matches); $alt = $matches[1]; // Get our speed preg_match("/\\/IAS.(.*)\\//", $message, $matches); $gs = $matches[1]; $fields = array('pilotid' => $pilotid, 'aircraft' => $aircraft, 'lat' => $coords['lat'], 'lng' => $coords['lng'], 'heading' => $heading, 'alt' => $alt, 'gs' => $gs, 'phasedetail' => 'Enroute'); } elseif ($method == 'UPDATEFLIGHTPLAN') { $flight_id = $value; $flight_data = explode("|", $message); echo '1|'; return; } $depapt = OperationsData::GetAirportInfo($depicao); $dist_remain = SchedulesData::distanceBetweenPoints($coords->lat, $coords->lng, $depapt->lat, $depapt->lng); # Estimate the time remaining if ($gs != 0) { $time_remain = $dist_remain / $gs; } else { $time_remain = '0'; } $fields['distremain'] = $dist_remain; $fields['timeremaining'] = $time_remain; if ($deptime != '') { $fields['deptime'] = $deptime; } if ($arrtime != '') { $fields['arrtime'] = $arrtime; } Debug::log(print_r($fields, true), 'fsfk'); ACARSData::updateFlightData($pilotid, $fields); $id = DB::$insert_id; if ($method == 'BEGINFLIGHT') { echo '1|' . $pilotid; return; } echo '1|'; }
/** * Pass in a string with the route, and return back an array * with the data about each segment of the route. Pass a schedule * result into it. * * You can pass in a PIREP, schedule, or ACARS result, as long as it * has the following fields: * lat * lng * route * * To cache the route, use ScheduleData::getRouteDetails() instead. * This function bypasses any cached info * * @param mixed $route_string This is a description * @return mixed This is the return value description * */ public static function parseRoute($schedule) { $fromlat = $schedule->deplat; $fromlng = $schedule->deplng; $route_string = $schedule->route; if ($route_string == '') { return array(); } // Remove any SID/STAR text $route_string = str_replace('SID', '', $route_string); $route_string = str_replace('STAR', '', $route_string); $navpoints = array(); $all_points = explode(' ', $route_string); foreach ($all_points as $key => $value) { if (empty($value) === true) { continue; } $navpoints[] = strtoupper(trim($value)); } $allpoints = array(); $total = count($navpoints); $airways = self::getAirways($navpoints); for ($i = 0; $i < $total; $i++) { $name = self::cleanName($navpoints[$i]); /* the current point is an airway, so go through the airway list and add each corresponding point between the entry and exit to the list. */ if (isset($airways[$name])) { $entry_name = self::cleanName($navpoints[$i - 1]); $exit_name = self::cleanName($navpoints[$i + 1]); $entry = self::getPointIndex($entry_name, $airways[$name]); $exit = self::getPointIndex($exit_name, $airways[$name]); if ($entry == -1) { $entry = $exit; } else { /* Add information abotu the entry point in first, if it's valid and exists */ $allpoints[$entry_name] = $airways[$name][$entry]; } if ($exit == -1) { continue; } if ($entry < $exit) { # Go forwards through the list adding each one for ($l = $entry; $l <= $exit; $l++) { $allpoints[$airways[$name][$l]->name] = $airways[$name][$l]; } } elseif ($entry > $exit) { # Go backwards through the list for ($l = $exit; $l >= $entry; $l--) { $point_name = self::cleanName($airways[$name][$l]->name); $allpoints[$point_name] = $airways[$name][$l]; } } elseif ($entry == $exit) { $point_name = self::cleanName($airways[$name][$l]->name); $allpoints[$point_name] = $airways[$name][$entry]; } # Now add the exit point, and increment the main counter by one if ($exit > -1) { $allpoints[$exit_name] = $airways[$name][$exit]; } continue; } else { /* This nav point already exists in the list, don't add it again */ if (isset($allpoints[$navpoints[$i]])) { continue; } /* Means it is a track, so go into processing it See if it's something like XXXX/YYYY */ if (substr_count($navpoints[$i], '/') > 0) { $name = $navpoints[$i]; $point_name = explode('/', $name); preg_match(self::$nat_pattern, $point_name[0], $matches); $coord = $matches[1]; $lat = $matches[2] . $coord[0] . $coord[1] . '.' . $coord[2] . $coord[3]; /* Match the second set of coordinates */ # Read the second set preg_match(self::$nat_pattern, $point_name[1], $matches); if ($matches == 0) { continue; } $coord = $matches[1]; $lng = $matches[2] . $coord[0] . $coord[1] . $coord[2] . '.' . $coord[3]; /* Now convert into decimal coordinates */ $coords = $lat . ' ' . $lng; $coords = Util::get_coordinates($coords); if (empty($coords['lat']) || empty($coords['lng'])) { unset($allpoints[$navpoints[$i]]); continue; } $tmp = new stdClass(); $tmp->id = 0; $tmp->type = NAV_TRACK; $tmp->name = $name; $tmp->title = $name; $tmp->lat = $coords['lat']; $tmp->lng = $coords['lng']; $tmp->airway = ''; $tmp->sequence = 0; $tmp->freq = ''; $allpoints[$navpoints[$i]] = $tmp; unset($point_name); unset($matches); unset($tmp); } else { $allpoints[$navpoints[$i]] = $navpoints[$i]; $navpoint_list[] = $navpoints[$i]; } } } $navpoint_list_details = self::getNavDetails($navpoint_list); foreach ($navpoint_list_details as $point => $list) { $allpoints[$point] = $list; } unset($navpoint_list_details); /* How will this work - loop through each point, and decide which one we'll use, determined by the one which is the shortest distance from the previous Go in the order of the ones passed in. */ foreach ($allpoints as $point_name => $point_details) { if (is_string($point_details)) { unset($allpoints[$point_name]); continue; } if (!is_array($point_details)) { continue; } $results_count = count($point_details); if ($results_count == 1) { $allpoints[$point_name] = $point_details[0]; } elseif ($results_count > 1) { /* There is more than one, so find the one with the shortest distance from the previous point out of all the ones */ $index = 0; $dist = 0; /* Set the inital settings */ $lowest_index = 0; $lowest = $point_details[$lowest_index]; $lowest_dist = SchedulesData::distanceBetweenPoints($fromlat, $fromlng, $lowest->lat, $lowest->lng); foreach ($point_details as $p) { $dist = SchedulesData::distanceBetweenPoints($fromlat, $fromlng, $p->lat, $p->lng); if ($dist < $lowest_dist) { $lowest_index = $index; $lowest_dist = $dist; } $index++; } $allpoints[$point_name] = $point_details[$lowest_index]; } $fromlat = $allpoints[$point_name]->lat; $fromlng = $allpoints[$point_name]->lng; } return $allpoints; }
/** * Get the distance between two airports * * @param mixed $depicao ICAO or object of the departure airport * @param mixed $arricao ICAO or object of the destination airport * @return int The distance * */ public static function getAirportDistance($depicao, $arricao) { if (!is_object($depicao)) { $depicao = self::getAirportInfo($depicao); } if (!is_object($arricao)) { $arricao = self::getAirportInfo($arricao); } return SchedulesData::distanceBetweenPoints($depicao->lat, $depicao->lng, $arricao->lat, $arricao->lng); }
$alt = $matches[1]; // Get our speed preg_match("/\\/IAS.(.*)\\//", $data, $matches); $gs = $matches[1]; // Get the OUT time preg_match("/OUT.(.*) \\/ZFW/", $data, $matches); $deptime = $matches[1]; /* We don't need to update every field, just a few of them */ $fields = array('lat' => $coords['lat'], 'lng' => $coords['lng'], 'heading' => $heading, 'alt' => $alt, 'gs' => $gs, 'phasedetail' => 'Enroute'); } else { return; } # Get the distance remaining $depapt = OperationsData::GetAirportInfo($depicao); $dist_remain = SchedulesData::distanceBetweenPoints($coords->lat, $coords->lng, $depapt->lat, $depapt->lng); # Estimate the time remaining if ($gs > 0) { $time_remain = $dist_remain / $gs; } else { $time_remain = '00:00'; } ob_start(); $fields['distremain'] = $dist_remain; $fields['timeremaining'] = $time_remain; Debug::log(print_r($fields, true), 'xacars'); ACARSData::UpdateFlightData($pilotid, $fields); echo '1|' . $outstring; break; case 'pirep': $data = explode('~', $_REQUEST['DATA2']);
</ul> <br /> <form action="<?php echo url('/FBSV11/jumpseat'); ?> " method="get"> <table> <tr> <td>select airport to transfer : </td> <td > <select name="depicao" onchange="listSel(this,'cost')"> <option value="">--Select--</option> <?php foreach ($airports as $airport) { $distance = round(SchedulesData::distanceBetweenPoints($last_name->lat, $last_name->lng, $airport->lat, $airport->lng), 0); $permile = Config::Get('JUMPSEAT_COST'); $cost = $permile * $distance; $check = PIREPData::getLastReports(Auth::$userinfo->pilotid, 1, 1); if ($cost >= Auth::$userinfo->totalpay) { continue; } elseif ($check->accepted == PIREP_ACCEPTED || !$check) { echo "<option name='{$cost}' value='{$airport->icao}'>{$airport->icao} - {$airport->name} /Cost - <font color='#66FF00'>\$ {$cost}</font></option>"; } ?> <hr> <?php } ?>