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; }
protected function SubmitPIREP() { $pilotid = Auth::$userinfo->pilotid; if ($pilotid == '' || Auth::LoggedIn() == false) { $this->set('message', 'You must be logged in to access this feature!!'); //$this->render('core_error.tpl'); return false; } 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!'); return false; } # Only allow for valid routes to be filed $sched_data = SchedulesData::GetScheduleByFlight($this->post->code, $this->post->flightnum); if (!$sched_data) { $this->set('message', 'The flight code and number you entered is not a valid route!'); return false; } # See if they entered more than 59 in the minutes part of the flight time $this->post->flighttime = str_replace(':', '.', $this->post->flighttime); $parts = explode('.', $this->post->flighttime); if ($parts[1] > 59) { $this->set('message', 'You entered more than 60 minutes in the minutes'); return false; } /* Check the schedule and see if it's been bidded on */ if (Config::Get('DISABLE_SCHED_ON_BID') == true) { $biddata = SchedulesData::GetBid($sched_data->bidid); if ($biddata) { if ($biddata->pilotid != $pilotid) { $this->set('message', 'You are not the bidding pilot'); //$this->render('core_error.tpl'); return false; } } } /* Removed this check since maybe it's a training flight or something, who knows if($this->post->depicao == $this->post->arricao) { $this->set('message', 'The departure airport is the same as the arrival airport!'); $this->render('core_error.tpl'); return false; }*/ $this->post->flighttime = str_replace(':', '.', $this->post->flighttime); if (!is_numeric($this->post->flighttime)) { $this->set('message', 'The flight time has to be a number!'); return false; } # form the fields to submit $this->pirepdata = array('pilotid' => $pilotid, 'code' => $this->post->code, 'flightnum' => $this->post->flightnum, 'depicao' => $this->post->depicao, 'arricao' => $this->post->arricao, 'aircraft' => $this->post->aircraft, 'flighttime' => $this->post->flighttime, 'route' => $this->post->route, 'submitdate' => 'NOW()', 'fuelused' => $this->post->fuelused, 'source' => 'manual', 'comment' => $this->post->comment); CodonEvent::Dispatch('pirep_prefile', 'PIREPS'); if (CodonEvent::hasStop('pirepfile')) { return false; } if (!PIREPData::FileReport($this->pirepdata)) { $this->set('message', 'There was an error adding your PIREP : ' . PIREPData::$lasterror); return false; } $pirepid = DB::$insert_id; PIREPData::SaveFields($pirepid, $_POST); # Remove the bid $bidid = SchedulesData::GetBidWithRoute($pilotid, $this->post->code, $this->post->flightnum); if ($bidid) { SchedulesData::RemoveBid($bidid->bidid); } # Call the event CodonEvent::Dispatch('pirep_filed', 'PIREPS'); # Set them as non-retired PilotData::setPilotRetired($pilotid, 0); # Delete the bid, if the value for it is set if ($this->post->bid != '') { SchedulesData::RemoveBid($this->post->bid); } return true; }