Example #1
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');
 }
Example #2
0
 protected function edit_pirep_post()
 {
     if ($this->post->code == '' || $this->post->flightnum == '' || $this->post->depicao == '' || $this->post->arricao == '' || $this->post->aircraft == '' || $this->post->flighttime == '') {
         $this->set('message', 'You must fill out all of the required fields!');
         $this->render('core_error.tpl');
         return false;
     }
     $pirepInfo = PIREPData::getReportDetails($this->post_action->pirepid);
     if (!$pirepInfo) {
         $this->set('message', 'Invalid PIREP!');
         $this->render('core_error.tpl');
         return false;
     }
     $this->post->fuelused = str_replace(' ', '', $this->post->fuelused);
     $this->post->fuelused = str_replace(',', '', $this->post->fuelused);
     $fuelcost = $this->post->fuelused * $this->post->fuelunitcost;
     # form the fields to submit
     $data = array('pirepid' => $this->post->pirepid, 'code' => $this->post->code, 'flightnum' => $this->post->flightnum, 'leg' => $this->post->leg, 'depicao' => $this->post->depicao, 'arricao' => $this->post->arricao, 'aircraft' => $this->post->aircraft, 'flighttime' => $this->post->flighttime, 'load' => $this->post->load, 'price' => $this->post->price, 'pilotpay' => $this->post->pilotpay, 'fuelused' => $this->post->fuelused, 'fuelunitcost' => $this->post->fuelunitcost, 'fuelprice' => $fuelcost, 'expenses' => $this->post->expenses);
     if (!PIREPData::UpdateFlightReport($this->post->pirepid, $data)) {
         $this->set('message', 'There was an error editing your PIREP');
         $this->render('core_error.tpl');
         return false;
     }
     PIREPData::SaveFields($this->post->pirepid, $_POST);
     //Accept or reject?
     $this->post->id = $this->post->pirepid;
     $submit = strtolower($this->post->submit_pirep);
     // Add a comment
     if (trim($this->post->comment) != '' && $submit != 'reject pirep') {
         PIREPData::AddComment($this->post->pirepid, Auth::$userinfo->pilotid, $this->post->comment);
     }
     if ($submit == 'accept pirep') {
         $this->approve_pirep_post();
     } elseif ($submit == 'reject pirep') {
         $this->reject_pirep_post();
     }
     StatsData::UpdateTotalHours();
     # Update a pilot's stats
     PilotData::updatePilotStats($pirepInfo->pilotid);
     LogData::addLog(Auth::$userinfo->pilotid, 'Edited PIREP #' . $this->post->id);
     return true;
 }
 public static function send_pirep($pirep_id)
 {
     if (!self::central_enabled()) {
         return false;
     }
     if ($pirep_id == '') {
         return;
     }
     self::set_xml('add_pirep');
     $pirep = PIREPData::getReportDetails($pirep_id);
     PIREPData::setExportedStatus($pirep_id, false);
     if (!$pirep) {
         return false;
     }
     self::get_pirep_xml($pirep);
     CronData::set_lastupdate('add_pirep');
     $resp = self::send_xml();
     if ($resp === true) {
         PIREPData::setExportedStatus($pirep_id, true);
         return true;
     }
 }
Example #4
0
 /**
  * Change the status of a PIREP. For the status, use the constants:
  * PIREP_PENDING, PIREP_ACCEPTED, PIREP_REJECTED,PIREP_INPROGRESS
  * 
  * Also handle paying the pilot, and handle PIREP rejection, etc
  * 
  * @param int $pirepid The PIREP ID of status to change
  * @param int $status Use consts: PIREP_PENDING, PIREP_ACCEPTED, PIREP_REJECTED,PIREP_INPROGRESS
  * @return bool
  */
 public static function changePIREPStatus($pirepid, $status)
 {
     # Look up the status of the PIREP of previous
     $pirep_details = PIREPData::getReportDetails($pirepid);
     if (!$pirep_details) {
         return false;
     }
     if ($pirep_details->accepted == $status) {
         return true;
     }
     $ret = self::editPIREPFields($pirepid, array('accepted' => $status));
     # Do something if the PIREP was previously marked as pending
     if ($pirep_details->accepted == PIREP_PENDING) {
         if ($status == PIREP_ACCEPTED) {
             self::calculatePIREPPayment($pirepid);
             SchedulesData::changeFlownCount($pirep_details->code, $pirep_details->flightnum, '+1');
         } elseif ($status == PIREP_REJECTED) {
             // Do nothing, since nothing in the PIREP was actually counted
         }
     } elseif ($pirep_details->accepted == PIREP_ACCEPTED) {
         # If already accepted
         if ($status == PIREP_REJECTED) {
             LedgerData::deletePaymentByPIREP($pirep_details->pirepid);
             PilotData::resetPilotPay($pirep_details->pilotpay);
             SchedulesData::changeFlownCount($pirep_details->code, $pirep_details->flightnum, '-1');
         }
     }
     PilotData::updatePilotStats($pirep_details->pilotid);
     RanksData::calculateUpdatePilotRank($pirep_details->pilotid);
     PilotData::generateSignature($pirep_details->pilotid);
     StatsData::updateTotalHours();
     return $ret;
 }
Example #5
0
 /**
  * Populate the PIREP with the fianancial info needed
  *  Pass the PIREPID or the PIREP row
  */
 public static function populatePIREPFinance($pirep, $reset_fuel = false)
 {
     if (!is_object($pirep) && is_numeric($pirep)) {
         $pirep = PIREPData::getReportDetails($pirep);
         if (!$pirep) {
             self::$lasterror = 'PIREP does not exist';
             return false;
         }
     }
     # Set the PIREP ID
     $pirepid = $pirep->pirepid;
     $sched = SchedulesData::getScheduleByFlight($pirep->code, $pirep->flightnum, '');
     if (!$sched) {
         self::$lasterror = 'Schedule does not exist. Please update this manually.';
         return false;
     }
     $pilot = PilotData::getPilotData($pirep->pilotid);
     # Get the load factor for this flight
     if ($pirep->load == '' || $pirep->load == 0) {
         $pirep->load = FinanceData::getLoadCount($pirep->aircraft, $sched->flighttype);
     }
     // Fix for bug #62, check the airport fuel price as 0 for live
     //$depapt = OperationsData::getAirportInfo($pirep->depicao);
     if ($pirep->fuelunitcost == '' || $pirep->fuelunitcost == 0 || $reset_fuel == true) {
         $pirep->fuelunitcost = FuelData::getFuelPrice($pirep->depicao);
     }
     # Check the fuel
     if ($pirep->fuelprice != '' || $reset_fuel == true) {
         $pirep->fuelprice = FinanceData::getFuelPrice($pirep->fuelused, $pirep->depicao);
     }
     # Get the expenses for a flight
     $total_ex = 0;
     $expense_list = '';
     /* Account for any fixed-cost percentages */
     $allexpenses = FinanceData::getFlightExpenses();
     if (is_array($allexpenses)) {
         foreach ($allexpenses as $ex) {
             $total_ex += $ex->cost;
         }
     }
     /* Account for any per-flight %age expenses */
     $all_percent_expenses = FinanceData::getFlightPercentExpenses();
     $gross = floatval($sched->price) * floatval($pirep->load);
     if (is_array($all_percent_expenses)) {
         foreach ($all_percent_expenses as $ex) {
             $cost = str_replace('%', '', $ex->cost);
             $percent = $cost / 100;
             $total = $gross * $percent;
             $total_ex += $total;
         }
     }
     $data = array('price' => $sched->price, 'load' => $pirep->load, 'fuelprice' => $pirep->fuelprice, 'expenses' => $total_ex, 'pilotpay' => $pilot->payrate, 'flighttime' => $pirep->flighttime);
     $revenue = self::getPIREPRevenue($data);
     /* Now update the PIREP */
     $fields = array('price' => $sched->price, 'load' => $pirep->load, 'gross' => $gross, 'fuelprice' => $pirep->fuelprice, 'fuelunitcost' => $pirep->fuelunitcost, 'expenses' => $total_ex, 'pilotpay' => $pilot->payrate, 'revenue' => $revenue);
     if (isset($data['load']) && $data['load'] != '') {
         $fields['load'] = $data['load'];
     }
     return self::editPIREPFields($pirepid, $fields);
 }
Example #6
0
 public function viewreport($pirepid = '')
 {
     if ($pirepid == '') {
         $this->set('message', 'No report ID specified!');
         $this->render('core_error.tpl');
         return;
     }
     $pirep = PIREPData::getReportDetails($pirepid);
     if (!$pirep) {
         $this->set('message', 'This PIREP does not exist!');
         $this->render('core_error.tpl');
         return;
     }
     $this->set('pirep', $pirep);
     $this->set('fields', PIREPData::GetFieldData($pirepid));
     $this->set('comments', PIREPData::GetComments($pirepid));
     $this->render('pirep_viewreport.tpl');
     $this->render('route_map.tpl');
 }
Example #7
0
 /**
  * PIREPS::addcomment()
  * 
  * @return
  */
 public function addcomment()
 {
     if (!Auth::LoggedIn()) {
         $this->set('message', 'You must be logged in to access this feature!');
         $this->render('core_error.tpl');
         return;
     }
     if (!isset($this->get->id)) {
         $this->set('message', 'No PIREP specified');
         $this->render('core_error.tpl');
         return;
     }
     $pirep = PIREPData::getReportDetails($this->get->id);
     if (!$pirep) {
         $this->set('message', 'Invalid PIREP');
         $this->render('core_error.tpl');
         return;
     }
     # Make sure pilot ID's match
     if ($pirep->pilotid != Auth::$pilot->pilotid) {
         $this->set('message', 'You cannot add a comment to a PIREP that is not yours!');
         $this->render('core_error.tpl');
         return;
     }
     # Show the comment form
     $this->set('pirep', $pirep);
     $this->render('pireps_addcomment.tpl');
 }
Example #8
0
 /**
  * Change the status of a PIREP. For the status, use the constants:
  * PIREP_PENDING, PIREP_ACCEPTED, PIREP_REJECTED,PIREP_INPROGRESS
  * 
  * Also handle paying the pilot, and handle PIREP rejection, etc
  * 
  * @deprecated Use editPIREPFields instead
  */
 public static function changePIREPStatus($pirepid, $status)
 {
     # Look up the status of the PIREP of previous
     $pirep_details = PIREPData::getReportDetails($pirepid);
     if (!$pirep_details) {
         return false;
     }
     if ($pirep_details->accepted == $status) {
         return true;
     }
     $ret = self::editPIREPFields($pirepid, array('accepted' => $status));
     # Do something if the PIREP was previously marked as pending
     if ($pirep_details->accepted == PIREP_PENDING) {
         if ($status == PIREP_ACCEPTED) {
             # Pay per-schedule
             if (!empty($pirep_details->payforflight)) {
                 $sql = 'UPDATE ' . TABLE_PREFIX . "pilots \n            \t\t\t\tSET totalpay=totalpay+{$pirep_details->payforflight} \n            \t\t\t\tWHERE pilotid={$pirep_details->pilotid}";
                 DB::query($sql);
             } else {
                 # Pay by hour
                 PilotData::updatePilotPay($pirep_details->pilotid, $pirep_details->flighttime, true);
             }
             SchedulesData::changeFlownCount($pirep_details->code, $pirep_details->flightnum, '+1');
         } elseif ($status == PIREP_REJECTED) {
             // Do nothing, since nothing in the PIREP was actually counted
         }
     } elseif ($pirep_details->accepted == PIREP_ACCEPTED) {
         # If already accepted
         if ($status == PIREP_REJECTED) {
             # Subtract their pay for the rejected flight
             if (!empty($pirep_details->payforflight)) {
                 $sql = 'UPDATE ' . TABLE_PREFIX . "pilots \n            \t\t\t\tSET totalpay=totalpay-{$pirep_details->payforflight} \n            \t\t\t\tWHERE pilotid={$pirep_details->pilotid}";
                 DB::query($sql);
             } else {
                 PilotData::updatePilotPay($pirep_details->pilotid, $pirep_details->flighttime, false);
             }
             SchedulesData::changeFlownCount($pirep_details->code, $pirep_details->flightnum, '-1');
         }
     }
     PilotData::updatePilotStats($pirep_details->pilotid);
     RanksData::calculateUpdatePilotRank($pirep_details->pilotid);
     PilotData::generateSignature($pirep_details->pilotid);
     StatsData::updateTotalHours();
     return $ret;
 }