Esempio n. 1
0
 /**
  * File PIREP
  *
  */
 public function pirep()
 {
     $data = "<?xml version=\"1.0\" encoding='UTF-8'?>" . trim(utf8_encode($_REQUEST['DATA2']));
     $xml = simplexml_load_string($data);
     $this->log($data, 'fsfk');
     $this->log(print_r($xml, true), 'fsfk');
     #$this->log(serialize($xml), 'fsfk');
     $pilotid = PilotData::parsePilotID($xml->PilotID);
     $flightinfo = SchedulesData::getProperFlightNum($xml->FlightNumber);
     $code = $flightinfo['code'];
     $flightnum = $flightinfo['flightnum'];
     # Extract the ICAO of the airport
     $depicao = strtoupper(substr($xml->OriginICAO, 0, 4));
     $arricao = strtoupper(substr($xml->DestinationICAO, 0, 4));
     if (!OperationsData::GetAirportInfo($depicao)) {
         OperationsData::RetrieveAirportInfo($depicao);
     }
     if (!OperationsData::GetAirportInfo($arricao)) {
         OperationsData::RetrieveAirportInfo($arricao);
     }
     $load = (string) $xml->Passenger;
     if ($load == '' || $load == 0) {
         $load = (string) $xml->Cargo;
     }
     $flighttime = str_replace(':', '.', (string) $xml->BlockTime);
     # Get the proper aircraft
     $ac = OperationsData::GetAircraftByReg((string) $xml->AircraftTailNumber);
     if (!$ac) {
         $aircraft = 0;
     } else {
         $aircraft = $ac->id;
         unset($ac);
     }
     /* Process the report, to put into the log */
     $log = '';
     $images = '';
     $rawdata = array();
     # Setup the base things
     $rawdata['FLIGHTMAPS'] = array();
     $rawdata['FLIGHTDATA'] = array();
     foreach ($xml as $key => $value) {
         /* Add the map images in */
         if ($key == 'FLIGHTMAPS') {
             $img = (string) $xml->FLIGHTMAPS->FlightMapWeatherJPG;
             if ($img) {
                 $rawdata['FLIGHTMAPS']['FlightMapWeather'] = $img;
             }
             $img = (string) $xml->FLIGHTMAPS->FlightMapLandingProfileJPG;
             if ($img) {
                 $rawdata['FLIGHTMAPS']['FlightMapLandingProfile'] = $img;
             }
             $img = (string) $xml->FLIGHTMAPS->FlightMapTaxiInJPG;
             if ($img) {
                 $rawdata['FLIGHTMAPS']['FlightMapTaxiIn'] = $img;
             }
             $img = (string) $xml->FLIGHTMAPS->FlightMapTaxiOutJPG;
             if ($img) {
                 $rawdata['FLIGHTMAPS']['FlightMapTaxiOut'] = $img;
             }
             $img = (string) $xml->FLIGHTMAPS->FlightMapVerticalProfileJPG;
             if ($img) {
                 $rawdata['FLIGHTMAPS']['FlightMapVerticalProfile'] = $img;
             }
             $img = (string) $xml->FLIGHTMAPS->FlightMapJPG;
             if ($img) {
                 $rawdata['FLIGHTMAPS']['FlightMap'] = $img;
             }
             continue;
         } elseif ($key == 'FLIGHTPLAN') {
             $rawdata['FLIGHTPLAN'] = (string) $value;
             continue;
         } elseif ($key == 'FLIGHTCRITIQUE') {
             $value = trim((string) $value);
             $rawdata['FLIGHTCRITIQUE'] = $value;
             continue;
         } else {
             $key = trim($key);
             $value = (string) $value;
             $value = str_replace('��', '', $value);
             $rawdata['FLIGHTDATA'][$key] = $value;
         }
     }
     /* Fuel conversion - kAcars only reports in lbs */
     $fuelused = (string) $xml->BlockFuel;
     if (intval(Config::Get('LiquidUnit')) == 0) {
         # Convert to KGs, divide by density since d = mass * volume
         $fuelused = $fuelused * 0.45359237 / 0.8075;
     } elseif (intval(Config::Get('LiquidUnit')) == 1) {
         # Convert lbs to gallons
         $fuelused = $fuelused * 6.84;
     } elseif (intval(Config::Get('LiquidUnit')) == 2) {
         # Convert lbs to kgs
         $fuelused = $fuelused * 0.45359237;
     }
     /* Our data to send to the submit PIREP function */
     $data = array('pilotid' => $pilotid, 'code' => $code, 'flightnum' => $flightnum, 'depicao' => $depicao, 'arricao' => $arricao, 'aircraft' => $aircraft, 'registration' => (string) $xml->AircraftTailNumber, 'flighttime' => $flighttime, 'landingrate' => (string) $xml->ONVS, 'submitdate' => 'NOW()', 'comment' => trim((string) $xml->COMMENT), 'fuelused' => $fuelused, 'source' => 'fsfk', 'load' => $load, 'log' => $log, 'rawdata' => $rawdata);
     $this->log(print_r($data, true), 'fsfk');
     $ret = ACARSData::filePIREP($pilotid, $data);
     if (!$ret) {
         echo PIREPData::$lasterror;
     } else {
         echo '<script type="text/javascript">window.location="' . url('/pireps/view/' . ACARSData::$pirepid) . '";</script>';
     }
 }