Esempio n. 1
0
 public function testExtractRoute()
 {
     $routes = array('VMA1234A', 'VMA324AB', 'VMS3030B');
     echo "<strong>Checking to see if flight numbers are parsed</strong><br />";
     # Check the first one
     $route = SchedulesData::getProperFlightNum($routes[0]);
     $this->assertEqual($route['code'], 'VMA');
     $this->assertEqual($route['flightnum'], '1234A');
     # Second
     $route = SchedulesData::getProperFlightNum($routes[1]);
     $this->assertEqual($route['code'], 'VMA');
     $this->assertEqual($route['flightnum'], '324AB');
     # Third
     $route = SchedulesData::getProperFlightNum($routes[2]);
     $this->assertEqual($route['code'], 'VMS');
     $this->assertEqual($route['flightnum'], '3030B');
     echo "<br />";
 }
Esempio n. 2
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;
         }
     }
 }
Esempio n. 3
0
    /**
     * This updates the ACARS live data for a pilot
     *
     * @param mixed $data This is the data structure with flight properties
     * @return mixed Nothing
     *
     */
    public static function updateFlightData($pilotid, $data)
    {
        if (!is_array($data)) {
            self::$lasterror = 'Data not array';
            return false;
        }
        if (isset($data['code']) && isset($data['flightnum'])) {
            $data['flightnum'] = $data['code'] . $data['flightnum'];
        }
        // Add pilot info
        $pilotinfo = PilotData::getPilotData($pilotid);
        $data['pilotid'] = $pilotid;
        $data['pilotname'] = $pilotinfo->firstname . ' ' . $pilotinfo->lastname;
        // Store for later
        if (isset($data['registration'])) {
            $ac_registration = $data['registration'];
            unset($data['registration']);
        }
        if (isset($data['depicao'])) {
            $dep_apt = OperationsData::GetAirportInfo($data['depicao']);
            $data['depapt'] = DB::escape($dep_apt->name);
        }
        if (isset($data['arricao'])) {
            $arr_apt = OperationsData::GetAirportInfo($data['arricao']);
            $data['arrapt'] = DB::escape($arr_apt->name);
        }
        if (isset($data['route']) && empty($data['route'])) {
            $flight_info = SchedulesData::getProperFlightNum($data['flightnum']);
            $params = array('s.code' => $flight_info['code'], 's.flightnum' => $flight_info['flightnum']);
            $schedule = SchedulesData::findSchedules($params);
            $schedule = $schedule[0];
            $data['route'] = $schedule->route;
            //$data['route_details'] = serialize(SchedulesData::getRouteDetails($schedule->id));
        } elseif (isset($data['route']) && !empty($data['route'])) {
            /*$tmp = new stdClass();
            		$tmp->deplat = $dep_apt->lat;
            		$tmp->deplng = $dep_apt->lng;
            		$tmp->route = $data['route'];
            		
            		$data['route_details'] = NavData::parseRoute($tmp);
            		$data['route_details'] = serialize($data['route_details']);
            		unset($tmp);*/
        }
        if (!empty($data['route_details'])) {
            $data['route_details'] = DB::escape($data['route_details']);
        }
        if (isset($dep_apt)) {
            unset($dep_apt);
        }
        if (isset($arr_apt)) {
            unset($arr_apt);
        }
        // Clean up times
        if (isset($data['deptime']) && !is_numeric($data['deptime'])) {
            $data['deptime'] = strtotime($data['deptime']);
        }
        if (isset($data['arrtime']) && !is_numeric($data['arrtime'])) {
            $data['arrtime'] = strtotime($data['arrtime']);
        }
        /* Check the heading for the flight
        			If none is specified, then point it straight to the arrival airport */
        if ($data['heading'] == '' || !isset($data['heading']) && isset($data['lat']) && isset($data['lng'])) {
            /* Calculate an angle based on current coords and the
            			destination coordinates */
            $data['heading'] = intval(atan2($data['lat'] - $arr_apt->lat, $data['lng'] - $arr_apt->lng) * 180 / 3.14);
            if ($data['lat'] - $data['lng'] < 0) {
                $data['heading'] += 180;
            }
            if ($data['heading'] < 0) {
                $data['heading'] += 360;
            }
        }
        // Manually add the last set
        $data['lastupdate'] = 'NOW()';
        // first see if we exist:
        $sql = 'SELECT `id`
				FROM ' . TABLE_PREFIX . "acarsdata \n\t\t\t\tWHERE `pilotid`={$pilotid}";
        $exist = DB::get_row($sql);
        $flight_id = '';
        if ($exist) {
            // update
            $upd = array();
            $flight_id = $exist->id;
            foreach ($data as $field => $value) {
                $value = DB::escape(trim($value));
                // Append the message log
                if ($field === 'messagelog') {
                    $upd[] = "`messagelog`=CONCAT(`messagelog`, '{$value}')";
                } elseif ($field === 'lastupdate') {
                    $upd[] = "`lastupdate`=NOW()";
                } elseif ($field === 'deptime' || $field === 'arrtime') {
                    /*	If undefined, set a default time to now (penalty for malformed data?)
                    			Won't be quite accurate.... */
                    if ($value == '') {
                        $value = time();
                    }
                    $upd[] = "`{$field}`=FROM_UNIXTIME({$value})";
                } else {
                    $upd[] = "`{$field}`='{$value}'";
                }
            }
            $upd = implode(',', $upd);
            $query = 'UPDATE ' . TABLE_PREFIX . "acarsdata \n\t\t\t\t\tSET {$upd} \n\t\t\t\t\tWHERE `id`='{$flight_id}'";
            DB::query($query);
        } else {
            // form array with $ins[column]=value and then
            //	give it to quick_insert to finish
            $ins = array();
            $vals = array();
            foreach ($data as $field => $value) {
                $ins[] = "`{$field}`";
                if ($field === 'deptime' || $field === 'arrtime') {
                    if (empty($value)) {
                        $value = time();
                    }
                    $vals[] = "FROM_UNIXTIME({$value})";
                } elseif ($field === 'lastupdate') {
                    $vals[] = 'NOW()';
                } else {
                    $value = DB::escape($value);
                    $vals[] = "'{$value}'";
                }
            }
            $ins = implode(',', $ins);
            $vals = implode(',', $vals);
            $query = 'INSERT INTO ' . TABLE_PREFIX . "acarsdata ({$ins}) \n\t\t\t\t\t\tVALUES ({$vals})";
            DB::query($query);
            $data['deptime'] = time();
            $flight_id = DB::$insert_id;
        }
        $flight_info = self::get_flight_by_id($flight_id);
        // Add this cuz we need it
        $data['code'] = $pilotinfo->code;
        $data['pilotid'] = $pilotid;
        $data['unique_id'] = $flight_id;
        $data['aircraft'] = $flight_info->aircraftname;
        $data['registration'] = $flight_info->registration;
        $res = CentralData::send_acars_data($data);
        return true;
    }
Esempio n. 4
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|';
 }
Esempio n. 5
0
         PIREPData::editPIREPFields($report->pirepid, array('landingrate' => $matches[2]));
     }
     PIREPData::AppendToLog($report->pirepid, $_GET['log']);
     echo 'OK';
     return;
 }
 # Full PIREP, run with it
 preg_match('/^([A-Za-z]*)(\\d*)/', $_GET['pilot'], $matches);
 $code = $matches[1];
 $log = explode('*', $_GET['log']);
 # Find where flight IATA is
 # And extract the code and flight number
 $pos = find_in_fsacars_log('Flight IATA', $log);
 $flightnum = str_replace('Flight IATA:', '', $log[$pos]);
 //preg_match('/^([A-Za-z]*)(\d*)/', $flightnum, $matches);
 $flightinfo = SchedulesData::getProperFlightNum($flightnum);
 $code = $flightinfo['code'];
 $flightnum = $flightinfo['flightnum'];
 # Get the passenger count:
 # Find where flight IATA is
 $pos = find_in_fsacars_log('PAX', $log);
 $load = str_replace('PAX:', '', $log[$pos]);
 $pos = find_in_fsacars_log('TouchDown:Rate', $log);
 $landingrate = str_replace('TouchDown:Rate', '', $log[$pos]);
 $pos = find_in_fsacars_log('Route', $log);
 $route = str_replace('Route:', '', $log[$pos]);
 $count = preg_match('/([0-9]*:[0-9]*).*([-+]\\d*).*/i', $landingrate, $matches);
 if ($count > 0) {
     $landingrate = $matches[2];
 } else {
     $landingrate = 0;
Esempio n. 6
0
     # 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']);
     $flightinfo = SchedulesData::getProperFlightNum($data[2]);
     $code = $flightinfo['code'];
     $flightnum = $flightinfo['flightnum'];
     /*if(!is_numeric($data[0]))
     		{
     			# see if they are a valid pilot:
     			preg_match('/^([A-Za-z]*)(\d*)/', $data[0], $matches);
     			$pilot_code = $matches[1];
     			$pilotid = intval($matches[2]) - Config::Get('PILOTID_OFFSET');
     		}
     		else
     		{
     			$pilotid = $data[0];
     		}*/
     $pilotid = PilotData::parsePilotID($data[0]);
     # Make sure airports exist:
Esempio n. 7
0
 /*if(is_numeric($_POST['UserName']))
 	{
 		$pilotid = intval(intval(trim( $_POST['UserName']))) - Config::Get('PILOTID_OFFSET');
 	}
 	else
 	{
 		if(preg_match('/^([A-Za-z]*)(\d*)/', $_POST['UserName'], $matches) == 0)
 		{
 			echo "#Answer# Error: Pilot doesn't exist ;";
 			return;
 		}
 		
 		$pilotid = intval(intval(trim($matches[2]))) - Config::Get('PILOTID_OFFSET');
 	}*/
 # Get the flight ID
 $flightinfo = SchedulesData::getProperFlightNum($_POST['FlightId']);
 $code = $flightinfo['code'];
 $flightnum = $flightinfo['flightnum'];
 /*if(preg_match('/^([A-Za-z]*)(\d*)/', $_POST['FlightId'], $matches) == 0)
 	{
 		echo "#Answer# Error - Invalid flight ID;";
 		return;
 	}*/
 preg_match('/^([A-Za-z]*) - .*/', $_POST['DepartureIcaoName'], $aptinfo);
 $depicao = $aptinfo[1];
 # Make sure it exists
 if (!OperationsData::GetAirportInfo($depicao)) {
     OperationsData::RetrieveAirportInfo($depicao);
 }
 preg_match('/^([A-Za-z]*) - .*/', $_POST['ArrivalIcaoName'], $aptinfo);
 $arricao = $aptinfo[1];