protected function add_schedule_post() { if ($this->post->code == '' || $this->post->flightnum == '' || $this->post->deptime == '' || $this->post->arrtime == '' || $this->post->depicao == '' || $this->post->arricao == '') { $this->set('message', 'All of the fields must be filled out'); $this->render('core_error.tpl'); return; } # Check if the schedule exists $sched = SchedulesData::getScheduleByFlight($this->post->code, $this->post->flightnum); if (is_object($sched)) { $this->set('message', 'This schedule already exists!'); $this->render('core_error.tpl'); return; } $enabled = $this->post->enabled == 'on' ? true : false; # Check the distance if ($this->post->distance == '' || $this->post->distance == 0) { $this->post->distance = OperationsData::getAirportDistance($this->post->depicao, $this->post->arricao); } # Format the flight level $this->post->flightlevel = str_replace(',', '', $this->post->flightlevel); $this->post->flightlevel = str_replace(' ', '', $this->post->flightlevel); $this->post->route = strtoupper($this->post->route); $this->post->route = str_replace($this->post->depicao, '', $this->post->route); $this->post->route = str_replace($this->post->arricao, '', $this->post->route); $this->post->route = str_replace('SID', '', $this->post->route); $this->post->route = str_replace('STAR', '', $this->post->route); $data = array('code' => $this->post->code, 'flightnum' => $this->post->flightnum, 'depicao' => $this->post->depicao, 'arricao' => $this->post->arricao, 'route' => $this->post->route, 'aircraft' => $this->post->aircraft, 'flightlevel' => $this->post->flightlevel, 'distance' => $this->post->distance, 'deptime' => $this->post->deptime, 'arrtime' => $this->post->arrtime, 'flighttime' => $this->post->flighttime, 'daysofweek' => implode('', $_POST['daysofweek']), 'price' => $this->post->price, 'flighttype' => $this->post->flighttype, 'notes' => $this->post->notes, 'enabled' => $enabled); # Add it in $ret = SchedulesData::AddSchedule($data); if (DB::errno() != 0 && $ret == false) { $this->set('message', 'There was an error adding the schedule, already exists DB error: ' . DB::error()); $this->render('core_error.tpl'); return; } $this->set('message', 'The schedule "' . $this->post->code . $this->post->flightnum . '" has been added'); $this->render('core_success.tpl'); LogData::addLog(Auth::$userinfo->pilotid, 'Added schedule "' . $this->post->code . $this->post->flightnum . '"'); }
/** * Populate the PIREP with the fianancial info needed * * @param mixed $pirep Either a PIREP ID or the row * @param bool $reset_fuel Reset the fuel costs or not? * @return */ 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; } } /* Set the pilotpay here - if it was a per-schedule payment, then set the pilot pay to that, otherwise, set it to the total amount paid... */ # Handle pilot pay if (!empty($sched->payforflight)) { $pilot->payrate = $sched->payforflight; $payment_type = PILOT_PAY_SCHEDULE; } else { $payment_type = PILOT_PAY_HOURLY; } $data = array('price' => $sched->price, 'load' => $pirep->load, 'fuelprice' => $pirep->fuelprice, 'expenses' => $total_ex, 'pilotpay' => $pilot->payrate, 'flighttime' => $pirep->flighttime); $revenue = self::getPIREPRevenue($data, $payment_type); /* 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, 'paytype' => $payment_type, 'revenue' => $revenue); if (isset($data['load']) && $data['load'] != '') { $fields['load'] = $data['load']; } return self::editPIREPFields($pirepid, $fields); }
public function processimport() { echo '<h3>Processing Import</h3>'; if (!file_exists($_FILES['uploadedfile']['tmp_name'])) { $this->set('message', 'File upload failed!'); $this->render('core_error.tpl'); return; } echo '<p><strong>DO NOT REFRESH OR STOP THIS PAGE</strong></p>'; set_time_limit(270); $errs = array(); $skip = false; # Fix for bug VMS-325 $temp_name = $_FILES['uploadedfile']['tmp_name']; $new_name = CACHE_PATH . $_FILES['uploadedfile']['name']; move_uploaded_file($temp_name, $new_name); $fp = fopen($new_name, 'r'); if (isset($_POST['header'])) { $skip = true; } /* Delete all schedules before doing an import */ if (isset($_POST['erase_routes'])) { SchedulesData::deleteAllSchedules(); } $added = 0; $updated = 0; $total = 0; echo '<div style="overflow: auto; height: 400px; border: 1px solid #666; margin-bottom: 20px; padding: 5px; padding-top: 0px; padding-bottom: 20px;">'; while ($fields = fgetcsv($fp, 1000, ',')) { // Skip the first line if ($skip == true) { $skip = false; continue; } // list fields: $code = $fields[0]; $flightnum = $fields[1]; $depicao = $fields[2]; $arricao = $fields[3]; $route = $fields[4]; $aircraft = $fields[5]; $flightlevel = $fields[6]; $distance = $fields[7]; $deptime = $fields[8]; $arrtime = $fields[9]; $flighttime = $fields[10]; $notes = $fields[11]; $price = $fields[12]; $flighttype = $fields[13]; $daysofweek = $fields[14]; $enabled = $fields[15]; $week1 = $fields[16]; $week2 = $fields[17]; $week3 = $fields[18]; $week4 = $fields[19]; if ($code == '') { continue; } // Check the code: if (!OperationsData::GetAirlineByCode($code)) { echo "Airline with code {$code} does not exist! Skipping...<br />"; continue; } // Make sure airports exist: if (!($depapt = OperationsData::GetAirportInfo($depicao))) { $this->get_airport_info($depicao); } if (!($arrapt = OperationsData::GetAirportInfo($arricao))) { $this->get_airport_info($arricao); } # Check the aircraft $aircraft = trim($aircraft); $ac_info = OperationsData::GetAircraftByReg($aircraft); # If the aircraft doesn't exist, skip it if (!$ac_info) { echo 'Aircraft "' . $aircraft . '" does not exist! Skipping<br />'; continue; } $ac = $ac_info->id; if ($flighttype == '') { $flighttype = 'P'; } if ($daysofweek == '') { $daysofweek = '0123456'; } // Replace a 7 (Sunday) with 0 (since PHP thinks 0 is Sunday) $daysofweek = str_replace('7', '0', $daysofweek); # Check the distance if ($distance == 0 || $distance == '') { $distance = OperationsData::getAirportDistance($depicao, $arricao); } $flighttype = strtoupper($flighttype); if ($enabled == '0') { $enabled = false; } else { $enabled = true; } # This is our 'struct' we're passing into the schedule function # to add or edit it $data = array('code' => $code, 'flightnum' => $flightnum, 'depicao' => $depicao, 'arricao' => $arricao, 'route' => $route, 'aircraft' => $ac, 'flightlevel' => $flightlevel, 'distance' => $distance, 'deptime' => $deptime, 'arrtime' => $arrtime, 'flighttime' => $flighttime, 'daysofweek' => $daysofweek, 'notes' => $notes, 'enabled' => $enabled, 'price' => $price, 'flighttype' => $flighttype, 'week1' => $week1, 'week2' => $week2, 'week3' => $week3, 'week4' => $week4); # Check if the schedule exists: if ($schedinfo = SchedulesData::getScheduleByFlight($code, $flightnum)) { # Update the schedule instead $val = SchedulesData::updateScheduleFields($schedinfo->id, $data); $updated++; } else { # Add it $val = SchedulesData::addSchedule($data); $added++; } if ($val === false) { if (DB::errno() == 1216) { echo "Error adding {$code}{$flightnum}: The airline code, airports, or aircraft does not exist"; } else { $error = DB::error() != '' ? DB::error() : 'Route already exists'; echo "{$code}{$flightnum} was not added, reason: {$error}<br />"; } echo '<br />'; } else { $total++; echo "Imported {$code}{$flightnum} ({$depicao} to {$arricao})<br />"; } } CentralData::send_schedules(); echo "The import process is complete, added {$added} schedules, updated {$updated}, for a total of {$total}<br />"; foreach ($errs as $error) { echo ' ' . $error . '<br />'; } echo '</div>'; unlink($new_name); }
/** * PIREPS::SubmitPIREP() * * @return */ protected function SubmitPIREP() { $pilotid = Auth::$pilot->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; }