Esempio n. 1
0
 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 . '"');
 }