Пример #1
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);
 }
Пример #2
0
 public function viewmap()
 {
     if ($this->get->type === 'pirep') {
         $data = PIREPData::getReportDetails($this->get->id);
     } elseif ($this->get->type === 'schedule') {
         $data = SchedulesData::getScheduleDetailed($this->get->id);
     } elseif ($this->get->type === 'preview') {
         $data = new stdClass();
         $depicao = OperationsData::getAirportInfo($this->get->depicao);
         $arricao = OperationsData::getAirportInfo($this->get->arricao);
         $data->deplat = $depicao->lat;
         $data->deplng = $depicao->lng;
         $data->depname = $depicao->name;
         $data->arrlat = $arricao->lat;
         $data->arrlng = $arricao->lng;
         $data->arrname = $arricao->name;
         $data->route = $this->get->route;
         unset($depicao);
         unset($arricao);
         $data->route_details = NavData::parseRoute($data);
     }
     $this->set('mapdata', $data);
     $this->render('route_map.tpl');
 }
Пример #3
0
 /**
  * Parse a schedule's route, and store it in the route_details
  * column for later on. It will store a serialized array of the
  * route's details. 
  *
  * @param int $schedule_id ID of the schedule to parse
  * @param string $route Optional route to parse, otherwise it will look it up
  * @return array Returns the route's details
  *
  */
 public static function getRouteDetails($schedule_id, $route = '')
 {
     $schedule = self::findSchedules(array('s.id' => $schedule_id), 1);
     $schedule = $schedule[0];
     if (empty($schedule->route)) {
         return;
     }
     $route_details = NavData::parseRoute($schedule);
     $store_details = DB::escape(serialize($route_details));
     $val = self::editScheduleFields($schedule_id, array('route_details' => $store_details));
     return $route_details;
 }
Пример #4
0
 /**
  * PIREPData::fileReport()
  * 
  * @param mixed $pirepdata
  * @return
  */
 public static function fileReport($pirepdata)
 {
     /*$pirepdata = array('pilotid'=>'',
       'code'=>'',
       'flightnum'=>'',
       'depicao'=>'',
       'arricao'=>'',
       'aircraft'=>'',
       'flighttime'=>'',
       'submitdate'=>'',
       'comment'=>'',
       'fuelused'=>'',
       'source'=>''
       'log'=>''
       );*/
     if (!is_array($pirepdata)) {
         return false;
     }
     $pirepdata['code'] = strtoupper($pirepdata['code']);
     $pirepdata['flightnum'] = strtoupper($pirepdata['flightnum']);
     $pirepdata['depicao'] = strtoupper($pirepdata['depicao']);
     $pirepdata['arricao'] = strtoupper($pirepdata['arricao']);
     /* Check if this PIREP was just submitted, check the last 10 minutes
      */
     if (Config::Get('PIREP_CHECK_DUPLICATE') == true) {
         $time_limit = Config::Get('PIREP_TIME_CHECK');
         if (empty($time_limit)) {
             $time_limit = 1;
         }
         $sql = "SELECT `pirepid` FROM " . TABLE_PREFIX . "pireps\n\t\t\t\t\tWHERE `pilotid` = {$pirepdata['pilotid']} \n\t\t\t\t\t\tAND `code` = '{$pirepdata['code']}'\n\t\t\t\t\t\tAND `flightnum` = '{$pirepdata['flightnum']}' \n\t\t\t\t\t\tAND DATE_SUB(NOW(), INTERVAL {$time_limit} MINUTE) <= `submitdate`";
         $res = DB::get_row($sql);
         if ($res) {
             self::$lasterror = 'This PIREP was just submitted!';
             return $res->pirepid;
         }
     }
     if ($pirepdata['depicao'] == '' || $pirepdata['arricao'] == '') {
         self::$lasterror = 'The departure or arrival airports are blank';
         return false;
     }
     # Check the aircraft
     if (!is_numeric($pirepdata['aircraft'])) {
         // Check by registration
         $ac = OperationsData::getAircraftByReg($pirepdata['aircraft']);
         if ($ac) {
             $pirepdata['aircraft'] = $ac->id;
         } else {
             // Check by name
             $ac = OperationsData::getAircraftByName($pirepdata['aircraft']);
             if ($ac) {
                 $pirepdata['aircraft'] = $ac->id;
             } else {
                 $pirepdata['aircraft'] = '0';
             }
         }
     }
     # Check the airports, add to database if they don't exist
     $depapt = OperationsData::getAirportInfo($pirepdata['depicao']);
     if (!$depapt) {
         $depapt = OperationsData::RetrieveAirportInfo($pirepdata['depicao']);
     }
     $arrapt = OperationsData::getAirportInfo($pirepdata['arricao']);
     if (!$arrapt) {
         $arrapt = OperationsData::RetrieveAirportInfo($pirepdata['arricao']);
     }
     # Look up the schedule
     $sched = SchedulesData::getScheduleByFlight($pirepdata['code'], $pirepdata['flightnum']);
     /*	Get route information, and also the detailed layout of the route
        Store it cached, in case the schedule changes later, then the route
        information remains intact. Also, if the nav data changes, then 
        the route is saved as it was 
        */
     if (!empty($pirepdata['route'])) {
         /*	They supplied some route information, so build up the data
            based on that. It needs a certain structure passed, so build that */
         $pirepdata['route'] = str_replace('SID', '', $pirepdata['route']);
         $pirepdata['route'] = str_replace('STAR', '', $pirepdata['route']);
         $pirepdata['route'] = str_replace('DCT', '', $pirepdata['route']);
         $pirepdata['route'] = trim($pirepdata['route']);
         $tmp = new stdClass();
         $tmp->deplat = $depapt->lat;
         $tmp->deplng = $depapt->lng;
         $tmp->route = $pirepdata['route'];
         $pirepdata['route_details'] = NavData::parseRoute($tmp);
         $pirepdata['route_details'] = serialize($pirepdata['route_details']);
         unset($tmp);
     }
     if (empty($pirepdata['route']) && !empty($sched->route)) {
         $pirepdata['route'] = $sched->route;
         $pirepdata['route'] = str_replace('SID', '', $pirepdata['route']);
         $pirepdata['route'] = str_replace('STAR', '', $pirepdata['route']);
         $pirepdata['route'] = str_replace('DCT', '', $pirepdata['route']);
         $pirepdata['route'] = trim($pirepdata['route']);
         /*	The schedule doesn't have any route_details, so let's populate
               the schedule while we're here. Then we'll use that same info
               to populate our details information 
            */
         if (empty($sched->route_details)) {
             $pirepdata['route_details'] = serialize(SchedulesData::getRouteDetails($sched->id));
         } else {
             /*	The schedule does have route information, and it's already been cached */
             $pirepdata['route_details'] = $sched->route_details;
         }
     }
     /*	This setting forces the next code to automatically
        calculate a load value for this current PIREP */
     if (Config::Get('PIREP_OVERRIDE_LOAD') == true) {
         $pirepdata['load'] == '';
     }
     # Check the load, if it's blank then look it up
     #	Based on the aircraft that was flown
     if (!isset($pirepdata['load']) || empty($pirepdata['load'])) {
         $pirepdata['load'] = FinanceData::getLoadCount($pirepdata['aircraft'], $sched->flighttype);
     }
     /* If the distance isn't supplied, then calculate it */
     if (!isset($pirepdata['distance']) || empty($pirepdata['distance'])) {
         $pirepdata['distance'] = OperationsData::getAirportDistance($depapt, $arrapt);
     }
     /* See if there's a landing rate */
     if (!isset($pirepdata['landingrate']) || empty($pirepdata['landingrate'])) {
         $pirepdata['landingrate'] = 0;
     }
     /* Any "raw" parameterized data which needs to be added */
     if (isset($pirepdata['rawdata'])) {
         $pirepdata['rawdata'] = serialize($pirepdata['rawdata']);
     } else {
         $pirepdata['rawdata'] = '';
     }
     /* Escape the comment field */
     //$pirepdata['log'] = DB::escape($pirepdata['log']);
     if (isset($pirepdata['comment'])) {
         $comment = DB::escape($pirepdata['comment']);
         unset($pirepdata['comment']);
     }
     /* Proper timestamp */
     $pirepdata['flighttime'] = str_replace(':', '.', $pirepdata['flighttime']);
     $pirepdata['flighttime_stamp'] = str_replace('.', ':', $pirepdata['flighttime']) . ':00';
     /* Export status as 0 */
     $pirepdata['exported'] = 0;
     $pirepdata['submitdate'] = 'NOW()';
     $pirepdata['modifieddate'] = 'NOW()';
     $pirepdata['accepted'] = PIREP_PENDING;
     $pirepdata['expenselist'] = '0';
     $pirepdata['flighttype'] = $sched->flighttype;
     # Do the insert based on the columns here
     $cols = array();
     $col_values = array();
     foreach ($pirepdata as $key => $value) {
         if ($key == 'submitdate') {
             $value = 'NOW()';
         } elseif ($key == 'comment') {
             continue;
         } else {
             $value = "'" . DB::escape($value) . "'";
         }
         $cols[] = "`{$key}`";
         $col_values[] = $value;
     }
     $cols = implode(', ', $cols);
     $col_values = implode(', ', $col_values);
     $sql = 'INSERT INTO ' . TABLE_PREFIX . "pireps ({$cols}) VALUES ({$col_values});";
     DB::query($sql);
     $pirepid = DB::$insert_id;
     // Add the comment if its not blank
     if ($comment != '') {
         self::addComment($pirepid, $pirepdata['pilotid'], $comment);
     }
     # Update the financial information for the PIREP, true to refresh fuel
     self::PopulatePIREPFinance($pirepid, true);
     # Do other assorted tasks that are along with a PIREP filing
     # Update the flown count for that route
     self::UpdatePIREPFeed();
     # Update any pilot's information
     $pilotinfo = PilotData::getPilotData($pirepdata['pilotid']);
     $pilotcode = PilotData::getPilotCode($pilotinfo->code, $pilotinfo->pilotid);
     PilotData::UpdateLastPIREPDate($pilotinfo->pilotid);
     if (Config::Get('EMAIL_SEND_PIREP') === true) {
         # Send an email to the admin that a PIREP was submitted
         $sub = "A PIREP has been submitted by {$pilotcode} ({$pirepdata['depicao']} - {$pirepdata['arricao']})";
         $message = "A PIREP has been submitted by {$pilotcode} " . "({$pilotinfo->firstname} {$pilotinfo->lastname})\n\n" . "{$pirepdata['code']}{$pirepdata['flightnum']}: {$pirepdata['depicao']} to {$pirepdata['arricao']}\n" . "Aircraft: {$pirepdata['aircraft']}\n" . "Flight Time: {$pirepdata['flighttime']}\n" . "Landing Rate: {$pirepdata['landingrate']}\n" . "Filed using: {$pirepdata['source']}\n\n" . "Comment: {$comment}\n\n" . "Click to approve this pirep (admin must be signed in):\n" . adminurl('/pirepadmin/approvepirep/' . $pirepid);
         $email = Config::Get('EMAIL_NEW_PIREP');
         if (empty($email)) {
             $email = ADMIN_EMAIL;
         }
         Util::SendEmail($email, $sub, $message);
     }
     /* Add this into the activity feed */
     $message = Lang::get('activity.new.pirep');
     foreach ($pirepdata as $key => $value) {
         $message = str_replace('$' . $key, $value, $message);
     }
     # Add it to the activity feed
     ActivityData::addActivity(array('pilotid' => $pirepdata['pilotid'], 'type' => ACTIVITY_NEW_PIREP, 'refid' => $pirepid, 'message' => htmlentities($message)));
     /* Now send data to vaCentral */
     CentralData::send_pirep($pirepid);
     // Reset this ID back
     DB::$insert_id = $pirepid;
     self::$pirepid = $pirepid;
     return $pirepid;
 }
Пример #5
0
if (!$depicao) {
    $depicao = OperationsData::RetrieveAirportInfo($_GET['depicao']);
}
$arricao = OperationsData::getAirportInfo($_GET['arricao']);
if (!$arricao) {
    $arricao = OperationsData::RetrieveAirportInfo($_GET['arricao']);
}
$data->deplat = $depicao->lat;
$data->deplng = $depicao->lng;
$data->depname = $depicao->name;
$data->arrlat = $arricao->lat;
$data->arrlng = $arricao->lng;
$data->arrname = $arricao->name;
unset($depicao);
unset($arricao);
$data->route_details = NavData::parseRoute($data);
print_r($data->route_details);
$mapdata = $data;
?>
</pre>
<h4>Route Map</h4>
<div class="mapcenter" align="center">
	<div id="routemap" style="width:600px; height: 480px"></div>
</div>
<p><strong>Route: </strong><?php 
echo $mapdata->route;
?>
</p>
<h4>Debugging Info</h4>
<pre>
<?php