Example #1
0
 public function acarsdata()
 {
     $output = '';
     CodonEvent::Dispatch('refresh_acars', 'XML');
     $flights = ACARSData::GetACARSData();
     $xml = new SimpleXMLElement('<livemap/>');
     if (!$flights) {
         $flights = array();
     }
     foreach ($flights as $flight) {
         $pilot = $xml->addChild('aircraft');
         $pilot->addAttribute('flightnum', $flight->flightnum);
         $pilot->addAttribute('lat', $flight->lat);
         $pilot->addAttribute('lng', $flight->lng);
         $pilot->addChild('pilotid', PilotData::GetPilotCode($flight->code, $flight->pilotid));
         $pilot->addChild('pilotname', $flight->firstname . ' ' . $flight->lastname);
         $pilot->addChild('flightnum', $flight->flightnum);
         $pilot->addChild('lat', $flight->lat);
         $pilot->addChild('lng', $flight->lng);
         $pilot->addChild('depicao', $flight->depicao);
         $pilot->addChild('arricao', $flight->arricao);
         $pilot->addChild('phase', $flight->phasedetail);
         $pilot->addChild('alt', $flight->alt);
         $pilot->addChild('gs', $flight->gs);
         $pilot->addChild('distremain', $flight->distremain);
         $pilot->addChild('timeremain', $flight->timeremain);
     }
     header('Content-type: text/xml');
     echo $xml->asXML();
 }
Example #2
0
 public function data()
 {
     $flights = ACARSData::GetACARSData();
     if (!$flights) {
         $flights = array();
     }
     $this->acarsflights = array();
     foreach ($flights as $flight) {
         if ($flight->route == '') {
             $flight->route_details = array();
         } else {
             #declare stClass (php 5.5)
             $params = new stdClass();
             # Jeff's fix for ACARS
             $params->deplat = $flight->deplat;
             $params->deplng = $flight->deplng;
             $params->route = $flight->route;
             $flight->route_details = NavData::parseRoute($params);
         }
         $c = (array) $flight;
         // Convert the object to an array
         $c['pilotid'] = PilotData::GetPilotCode($c['code'], $c['pilotid']);
         // Normalize the data
         if ($c['timeremaining'] == '') {
             $c['timeremaining'] == '-';
         }
         if (trim($c['phasedetail']) == '') {
             $c['phasedetail'] = 'Enroute';
         }
         /* If no heading was passed via ACARS app then calculate it
         			This should probably move to inside the ACARSData function, so then
         			 the heading is always there for no matter what the calcuation is
         			*/
         if ($flight->heading == '') {
             /* Calculate an angle based on current coords and the
             			destination coordinates */
             $flight->heading = intval(atan2($flight->lat - $flight->arrlat, $flight->lng - $flight->arrlng) * 180 / 3.14);
             //$flight->heading *= intval(180/3.14159);
             if ($flight->lng - $flight->arrlng < 0) {
                 $flight->heading += 180;
             }
             if ($flight->heading < 0) {
                 $flight->heading += 360;
             }
         }
         // Little one-off fixes to normalize data
         $c['distremaining'] = $c['distremain'];
         $c['pilotname'] = $c['firstname'] . ' ' . $c['lastname'];
         unset($c['messagelog']);
         $this->acarsflights[] = $c;
         continue;
     }
     CodonEvent::Dispatch('refresh_acars', 'ACARS');
     echo json_encode($this->acarsflights);
 }
Example #3
0
 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;
         }
     }
 }
Example #4
0
 /**
  * File a PIREP from an ACARS program
  *
  * @param mixed $pilotid The pilot ID of the pilot filing the PIREP
  * @param mixed $data This is the data structure with the PIREP info
  * @return bool true/false
  *
  */
 public static function FilePIREP($pilotid, $data)
 {
     if (!is_array($data)) {
         self::$lasterror = 'PIREP data must be array';
         return false;
     }
     # Call the pre-file event
     #
     if (CodonEvent::Dispatch('pirep_prefile', 'PIREPS', $_POST) == false) {
         return false;
     }
     # File the PIREP report
     #
     $ret = PIREPData::FileReport($data);
     # Set them as non-retired
     PilotData::setPilotRetired($pilotid, 0);
     if (!$ret) {
         return false;
     }
     self::$pirepid = DB::$insert_id;
     # Call the event
     #
     CodonEvent::Dispatch('pirep_filed', 'PIREPS', $_POST);
     # Close out a bid if it exists
     #
     $bidid = SchedulesData::GetBidWithRoute($pilotid, $data['code'], $data['flightnum']);
     if ($bidid) {
         SchedulesData::RemoveBid($bidid->bidid);
     }
     return true;
 }
Example #5
0
 /**
  * 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|';
 }
 public static function send_all_acars()
 {
     if (!self::central_enabled()) {
         return false;
     }
     $acars_flights = ACARSData::GetAllFlights();
     if (!$acars_flights) {
         return false;
     }
     self::set_xml('update_acars');
     foreach ($acars_flights as $flight) {
         self::create_acars_flight($flight);
     }
     CronData::set_lastupdate('update_acars');
     return self::send_xml();
 }
Example #7
0
        $_GET['dest'] = DB::escape($_GET['dest']);
        # Get schedule info, using minimal information
        #	Check if they forgot the flight code
        if ($code == '') {
            # Find a flight using just the flight code
            $sched = SchedulesData::FindFlight($flightnum);
            # Can't do it. They completely f****d this up
            if (!$sched) {
                return;
            }
            $code = $sched->code;
            $flightnum = $sched->flightnum;
            if ($_GET['origin'] != $sched->depicao || $_GET['dest'] != $sched->arricao) {
                $comment = 'phpVMS Message: Arrival or Departure does not match schedule';
            }
        }
        # Make sure airports exist:
        #  If not, add them.
        if (!OperationsData::GetAirportInfo($_GET['origin'])) {
            OperationsData::RetrieveAirportInfo($_GET['origin']);
        }
        if (!OperationsData::GetAirportInfo($_GET['dest'])) {
            OperationsData::RetrieveAirportInfo($_GET['dest']);
        }
        # Convert the time to xx.xx
        $flighttime = number_format(floatval(str_replace(':', '.', $_GET['duration'])), 2);
        $data = array('pilotid' => $pilotid, 'code' => $code, 'flightnum' => $flightnum, 'depicao' => $_GET['origin'], 'arricao' => $_GET['dest'], 'aircraft' => $ac->id, 'flighttime' => $flighttime, 'landingrate' => $landingrate, 'submitdate' => 'NOW()', 'comment' => $comment, 'fuelused' => $_GET['fuel'], 'source' => 'fsacars', 'route' => $route, 'load' => $load, 'rawdata' => $log, 'log' => $_GET['log']);
        $ret = ACARSData::FilePIREP($pilotid, $data);
        echo 'OK';
        break;
}
Example #8
0
 /**
  * Maintenance::resetacars()
  * 
  * @return
  */
 public function resetacars()
 {
     CodonModule::checkPermission(MAINTENANCE);
     echo '<h3>ACARS Reset</h3>';
     ACARSData::resetFlights();
 }
Example #9
0
        $resp = CentralData::send_schedules();
        break;
    case 'sendpilots':
        $resp = CentralData::send_pilots();
        break;
    case 'sendallpireps':
        $resp = CentralData::send_all_pireps();
        break;
    case 'sendpirep':
        $pirep = PIREPData::findPIREPS(array(), 20);
        $num = rand(0, count($pirep) - 1);
        $resp = CentralData::send_pirep($pirep[$num]->pirepid);
        break;
    case 'sendacars':
        # Send a random flight
        $flights = ACARSData::GetAllFlights();
        $total = count($flights);
        $resp = CentralData::send_acars_data($flights[rand(0, $total - 1)]);
        break;
    case 'sendallacars':
        $resp = CentralData::send_all_acars();
        break;
}
?>
<h3>Response:</h3>
<pre><?php 
$response = CentralData::$xml_response;
echo htmlentities(formatXmlString($response));
?>
</pre>
Example #10
0
 public function resetacars()
 {
     echo '<h3>ACARS Reset</h3>';
     ACARSData::resetFlights();
 }