예제 #1
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;
 }