Jump to content

Alternative Airport (Schedules) Help me


bass

Recommended Posts

Help make sure to record the alternate airport in the database.

I added a column to the table SCHEDULES, then added a line in "ops_scheduleform"

I made changes to SchedulesData.klass file, but with the addition of the flight, an alternative airport is not recorded in the database (((, can you help?

2016-06-11_000331.jpg

2016-06-11_000813.jpg

2016-06-11_000545.jpg

Link to comment
Share on other sites

SchedulesData.class

<?php
/**
* phpVMS - Virtual Airline Administration Software
* Copyright (c) 2008 Nabeel Shahzad
* For more information, visit www.phpvms.net
* Forums: http://www.phpvms.net/forum
* Documentation: http://www.phpvms.net/docs
*
* phpVMS is licenced under the following license:
*   Creative Commons Attribution Non-commercial Share Alike (by-nc-sa)
*   View license.txt in the root, or visit http://creativecommons.org/licenses/by-nc-sa/3.0/
*
* @author Nabeel Shahzad
* @copyright Copyright (c) 2008, Nabeel Shahzad
* @link http://www.phpvms.net
* @license http://creativecommons.org/licenses/by-nc-sa/3.0/
*/

class SchedulesData extends CodonData
{
/**
 * A generic find function for schedules. As parameters, do:
 *
 * $params = array( 's.depicao' => 'value',
 *	 's.arricao' => array ('multiple', 'values'),
 * );
 *
 * Syntax is ('s.columnname' => 'value'), where value can be
 * an array is multiple values, or with a SQL wildcard (%)
 *  if that's what is desired.
 *
 * Columns from the schedules table should be prefixed by 's.',
 * the aircraft table as 'a.'
 *
 * You can also pass offsets ($start and $count) in order to
 * facilitate pagination
 *
 * @tutorial http://docs.phpvms.net/media/development/searching_and_retriving_schedules
 */
public static function findSchedules($params, $count = '', $start = '')
{
 $sql = 'SELECT s.*,
 a.id as aircraftid, a.name as aircraft, a.registration,
 a.minrank as aircraft_minrank, a.ranklevel as aircraftlevel,
 dep.name as depname, dep.lat AS deplat, dep.lng AS deplng,
 arr.name as arrname, arr.lat AS arrlat, arr.lng AS arrlng
   FROM '.TABLE_PREFIX.'schedules AS s
   LEFT JOIN '.TABLE_PREFIX.'airports AS dep ON dep.icao = s.depicao
   LEFT JOIN '.TABLE_PREFIX.'airports AS arr ON arr.icao = s.arricao
   LEFT JOIN '.TABLE_PREFIX.'aircraft AS a ON a.id = s.aircraft ';

 /* Build the select "WHERE" based on the columns passed, this is a generic function */
 $sql .= DB::build_where($params);

 // Order matters
 if(Config::Get('SCHEDULES_ORDER_BY') != '')
 {
  $sql .= ' ORDER BY '.Config::Get('SCHEDULES_ORDER_BY');
 }

 if(strlen($count) != 0)
 {
  $sql .= ' LIMIT '.$count;
 }

 if(strlen($start) != 0)
 {
  $sql .= ' OFFSET '. $start;
 }

 $ret = DB::get_results($sql);
 return $ret;
}


/**
 * Get the total number of schedules based on criterea
 *
 * @param array $params key => value list
 * @return int Returns the total number
 *
 */
public static function countSchedules($params)
{
 $sql = 'SELECT COUNT(s.id) as total
   FROM '.TABLE_PREFIX.'schedules AS s
   LEFT JOIN '.TABLE_PREFIX.'airports AS dep ON dep.icao = s.depicao
   LEFT JOIN '.TABLE_PREFIX.'airports AS arr ON arr.icao = s.arricao
   LEFT JOIN '.TABLE_PREFIX.'aircraft AS a ON a.id = s.aircraft ';

 $sql .= DB::build_where($params);
 $res = DB::get_row($sql);

 return $res->total;
}

/**
 * Return information about a schedule (pass the ID)
 */
public static function getSchedule($id)
{
 return self::getScheduleDetailed($id);
}


/**
 * Return a flight given the airline code and flight number
 *
 * @deprecated
 *
 * @param string $code Airline code
 * @param mixed $flightnum Flight number
 * @return array Returns a full flight
 *
 */
public static function getScheduleByFlight($code, $flightnum)
{
 $params = array(
  's.code' => strtoupper($code),
  's.flightnum' => strtoupper($flightnum),
 );

 $schedule = self::findSchedules($params);
 return $schedule[0];
}


/**
 * Find a flight on the flightnumber and departure airport
 *
 * @param string $flightnum Flight numbers
 * @param string $depicao Departure airport
 * @return array Returns one flight
 *
 */
public static function findFlight($flightnum, $depicao='')
{
 $params = array('s.flightnum' => strtoupper($flightnum));

 if($depicao != '')
 {
  $params['s.depicao'] = $depicao;
 }

 $schedule = self::findSchedules($params);
 return $schedule[0];
}

/**
 * Extract the code and flight number portions from the flight number
 * Ensures that the code and number are properly split
 */
public static function getProperFlightNum($flightnum)
{
 if($flightnum == '')
  return false;

 $ret = array();
 $flightnum = strtoupper($flightnum);
 $airlines = OperationsData::getAllAirlines(false);

 foreach($airlines as $a)
 {
  $a->code = strtoupper($a->code);

  if(strpos($flightnum, $a->code) === false)
  {
   continue;
  }

  $ret['code'] = $a->code;
  $ret['flightnum'] = str_ireplace($a->code, '', $flightnum);

  return $ret;
 }

 # Invalid flight number
 $ret['code'] = '';
 $ret['flightnum'] = $flightnum;
 return $ret;
}


/**
 * Increment the flown count for a schedule
 *
 * @param string $code Airline code
 * @param int $flightnum Flight number
 * @return bool
 *
 */
public static function IncrementFlownCount($code, $flightnum)
{
 $schedid = intval($schedid);

 $code = strtoupper($code);
 $flightnum = strtoupper($flightnum);

 $sql = 'UPDATE '.TABLE_PREFIX."schedules
 SET timesflown=timesflown+1
 WHERE code='{$code}' AND flightnum='{$flightnum}'";

 $res = DB::query($sql);

 if(DB::errno() != 0)
  return false;

 return true;
}


/**
 * Get detailed information about a schedule
 *
 * @param int $id ID of the schedule
 * @return array Schedule details
 *
 */
public static function getScheduleDetailed($id)
{
 $schedules = self::findSchedules(array('s.id' => $id));
 if(!$schedules)
  return false;

 $schedule =  $schedules[0];
 unset($schedules);

 /*$schedule->route_details = unserialize($schedule->route_details);
 if(!empty($schedule->route) && !$schedule->route_details)
 {
  $schedule->route_details = SchedulesData::getRouteDetails($schedule->id, $schedule->route);
 }*/

 if($schedule->route != '')
 {
  $schedule->route_details = NavData::parseRoute($schedule);
 }

 return $schedule;
}

/**
 * Return all the airports by depature, which have a schedule, for
 * a certain airline. If the airline
 * @return object_array
 */
public static function getDepartureAirports($airlinecode='', $onlyenabled=false)
{
 $airlinecode = DB::escape($airlinecode);

 if($onlyenabled)
  $enabled = 'AND s.enabled=1';
 else
  $enabled = '';

 $sql = 'SELECT DISTINCT s.depicao AS icao, a.name
   FROM '.TABLE_PREFIX.'schedules s, '.TABLE_PREFIX.'airports a
   WHERE s.depicao = a.icao '.$enabled;

 if($airlinecode != '')
  $sql .= " AND s.code='{$airlinecode}' ";

 $sql .= ' ORDER BY depicao ASC';

 return DB::get_results($sql);
}

/**
 * Get all of the airports which have a schedule, from
 * a certain airport, using the airline code. Code
 * is optional, otherwise it returns all of the airports.
 *
 * @return database object
 */
public static function getArrivalAiports($depicao, $airlinecode='', $onlyenabled=true)
{
 $depicao = strtoupper($depicao);
 $airlinecode = strtoupper($airlinecode);
 $depicao = DB::escape($depicao);

 if($onlyenabled)
  $enabled = 'AND s.enabled=1';
 else
  $enabled = '';

 $sql = 'SELECT DISTINCT s.arricao AS icao, a.name
   FROM '.TABLE_PREFIX.'schedules s, '.TABLE_PREFIX.'airports a
   WHERE s.arricao = a.icao '.$enabled;
 if($airlinecode != '')
  $sql .= " AND s.code='{$airlinecode}' ";

 $sql .= ' ORDER BY depicao ASC';

 return DB::get_results($sql);
}

/**
 * Get all the schedules, $limit is the number to return
 */
public static function getSchedules($onlyenabled=true, $limit='', $start='')
{
 $params = array();
 if($onlyenabled)
  $params['s.enabled'] = '1';

 return self::findSchedules($params, $limit, $start);
}

/**
 * This gets all of the schedules which are disabled
 */
/*public static function getInactiveSchedules($count='', $start='')
{
 $params = array('s.enabled'=>0);
 return self::findSchedules($params, $count, $start);
}*/


/**
 * Calculate the distance between two coordinates
 * Using a revised equation found on http://www.movable-type.co.uk/scripts/latlong.html
 *
 * Also converts to proper type based on UNIT setting
 *
 */
public static function distanceBetweenPoints($lat1, $lng1, $lat2, $lng2)
{
 /* Use a radius depending on the final units we want to be in
  New formula, from http://jan.ucc.nau.edu/~cvm/latlon_formula.html
  */
 if(strtolower(Config::Get('UNITS')) === 'mi') # miles
  $radius = 3963.192;
 elseif(strtolower(Config::Get('UNITS')) === 'km') # Convert to km
  $radius = 6378.14;
 else
  $radius = 3443.92;

 /*
 $distance = ($radius * 3.1415926 * sqrt(($lat2-$lat1) * ($lat2-$lat1)
 +cos($lat2/57.29578) * cos($lat1/57.29578) * ($lng2-$lng1) * ($lng2-$lng1))/180);

 return $distance;
 */
 $lat1 = deg2rad(floatval($lat1));
 $lat2 = deg2rad(floatval($lat2));
 $lng1 = deg2rad(floatval($lng1));
 $lng2 = deg2rad(floatval($lng2));

 $a = sin(($lat2 - $lat1)/2.0);
 $b = sin(($lng2 - $lng1)/2.0);
 $h = ($a*$a) + cos($lat1) * cos($lat2) * ($b*$;
 $theta = 2 * asin(sqrt($h)); # distance in radians

 $distance = $theta * $radius;

 return $distance;

 /* Convert all decimal degrees to radians */

 $dlat = $lat2 - $lat1;
 $dlng = $lng2 - $lng1;

 $a = sin($dlat / 2) * sin($dlat / 2) + cos($lat1) * cos($lat2) * sin($dlng / 2) * sin($dlng / 2);
 $c = 2 * atan2(sqrt($a), sqrt(1 - $a));
 $distance = $r * $c;

 return $distance;
 /*$distance = acos(cos($lat1)*cos($lng1)*cos($lat2)*cos($lng2)
   + cos($lat1)*sin($lng1)*cos($lat2)*sin($lng2)
   + sin($lat1)*sin($lat2)) * $r;
 return floatval(round($distance, 2));*/
}

/**
 * Update a distance
 *
 * @deprecated
 */
/*public static function UpdateDistance($scheduleid, $distance)
{
 $sql = 'UPDATE '.TABLE_PREFIX."schedules
   SET distance='{$distance}'
   WHERE id={$scheduleid}";

 $res = DB::query($sql);

 if(DB::errno() != 0)
  return false;

 return true;
}*/

/**
 * Add a schedule
 *
 * Pass in the following:
   $data = array( 'code'=>'',
  'flightnum'=''
  'depicao'=>'',
  'arricao'=>'',
  'alternativ'=>'',
  'route'=>'',
  'aircraft'=>'',
  'distance'=>'',
  'deptime'=>'',
  'arrtime'=>'',
  'flighttime'=>'',
  'notes'=>'',
  'enabled'=>'',
  'price'=>''
  'flighttype'=>'');
 */
public static function addSchedule($data)
{
 if(!is_array($data))
  return false;

 # Commented out to allow flights to/from the same airport
 #if($data['depicao'] == $data['arricao'])
 # return false;

 $data['code'] = strtoupper($data['code']);
 $data['flightnum'] = strtoupper($data['flightnum']);  
 $data['deptime'] = strtoupper($data['deptime']);
 $data['arrtime'] = strtoupper($data['arrtime']);
 $data['depicao'] = strtoupper($data['depicao']); 
 $data['arricao'] = strtoupper($data['arricao']);
 $data['alternativ'] = strtoupper($data['alternativ']);

 if($data['enabled'] == true)
  $data['enabled'] = 1;
 else
  $data['enabled'] = 0;

 # If they didn't specify
 $data['flighttype'] = strtoupper($data['flighttype']);
 if($data['flighttype'] == '')
  $data['flighttype'] = 'P';

 $data['flightlevel'] = str_replace(',', '', $data['flightlevel']);

 if(isset($fields['route']))
 {
  $fields['route'] = str_replace('SID', '', $fields['route']);
  $fields['route'] = str_replace('STAR', '', $fields['route']);
  $fields['route'] = trim($fields['route']);
  $fields['route_details'] = '';
 }

 foreach($data as $key=>$value)
 {
  $data[$key] = DB::escape($value);
 }

 $data['flighttime'] = str_replace(':', '.', $data['flighttime']);

 $sql = "INSERT INTO " . TABLE_PREFIX ."schedules
 (`code`, `flightnum`,
  `depicao`, `arricao`, `alternativ`,
  `route`, `route_details`,
  `aircraft`, `flightlevel`, `distance`,
  `deptime`, `arrtime`,
  `flighttime`, `daysofweek`, `price`,
  `flighttype`, `notes`, `enabled`)
   VALUES ('{$data['code']}',
  '{$data['flightnum']}',
  '{$data['depicao']}',
  '{$data['arricao']}',
  '{$data['alternativ']}',
  '{$data['route']}',
  '{$data['route_details']}',
  '{$data['aircraft']}',
  '{$data['flightlevel']}',
  '{$data['distance']}',
  '{$data['deptime']}',
  '{$data['arrtime']}',
  '{$data['flighttime']}',
  '{$data['daysofweek']}',
  '{$data['price']}',
  '{$data['flighttype']}',
  '{$data['notes']}',
  {$data['enabled']})";

 $res = DB::query($sql);

 if(!empty($data['route']))
 {
  self::getRouteDetails(DB::$insert_id, $data['route']);
 }

 if(DB::errno() != 0)
  return false;

 return true;
}
/**
 * Edit a schedule
 *  Pass in the columns - deprecated
 */

public static function editSchedule($data)
{
 if(!is_array($data))
  return false;

 $id = $data['id'];
 unset($data['id']);

 self::editScheduleFields($id, $data);
}

/**
 * Parse a schedule's route, and store it in the route_details
 * column for later on. It will store a serialized array of the
 * route's details.
 *
 * @param int $schedule_id ID of the schedule to parse
 * @param string $route Optional route to parse, otherwise it will look it up
 * @return array Returns the route's details
 *
 */
public static function getRouteDetails($schedule_id, $route = '')
{
 $schedule = self::findSchedules(array('s.id' => $schedule_id), 1);
 $schedule = $schedule[0];

 if(empty($schedule->route))
 {
  return;
 }

 $route_details = NavData::parseRoute($schedule);
 $store_details = DB::escape(serialize($route_details));

 $val = self::editScheduleFields($schedule_id, array('route_details' => $store_details));

 return $route_details;
}

/**
 * Update any fields in a schedule, other update functions come down to this
 *
 * @param int $scheduleid ID of the schedule to update
 * @param array $fields Array, column name as key, with values to update
 * @return bool
 *
 */
public static function updateScheduleFields($scheduleid, $fields)
{
 return self::editScheduleFields($scheduleid, $fields);
}

/**
 * Update any fields in a schedule, other update functions come down to this
 *
 * @param int $scheduleid ID of the schedule to update
 * @param array $fields Array, column name as key, with values to update
 * @return bool
 *
 */
public static function editScheduleFields($scheduleid, $fields)
{
 if(!is_array($fields))
 {
  return false;
 }

 if(isset($fields['depicao']) && isset($fields['arricao']))
 {
  if($fields['depicao'] == $fields['arricao'])
  {
   return false;
  }
 }

 /* Ensure data is ok and formatted properly */
 if(isset($fields['code']))
 {
  $fields['code'] = strtoupper($fields['code']);
 }

 if(isset($fields['flightnum']))
 {
  $fields['flightnum'] = strtoupper($fields['flightnum']);
 }

 if(isset($fields['depicao']))
 {
  $fields['depicao'] = strtoupper($fields['depicao']);
 }

 if(isset($fields['arricao']))
 {
  $fields['arricao'] = strtoupper($fields['arricao']);
 }

 if(isset($fields['deptime']))
 {
  $fields['deptime'] = strtoupper($fields['deptime']);
 }

 if(isset($fields['arrtime']))
 {
  $fields['arrtime'] = strtoupper($fields['arrtime']);
 }

 if(isset($fields['enabled']))
 {
  if($fields['enabled'] == true)
   $fields['enabled'] = 1;
  else
   $fields['enabled'] = 0;
 }

 # If they didn't specify a flight type, just default to pax
 if(isset($fields['flighttype']))
 {
  $fields['flighttype'] = strtoupper($fields['flighttype']);
  if($fields['flighttype'] == '')
  {
   $fields['flighttype'] = 'P';
  }
 }

 if(isset($fields['flightlevel']))
 {
  $fields['flightlevel'] = str_replace(',', '', $fields['flightlevel']);
 }

 if(isset($fields['flighttime']))
 {
  $fields['flighttime'] = str_replace(':', '.', $fields['flighttime']);
 }

 if(isset($fields['route']))
 {
  $fields['route'] = str_replace('SID', '', $fields['route']);
  $fields['route'] = str_replace('STAR', '', $fields['route']);
  $fields['route'] = trim($fields['route']);
 }

 foreach($fields as $key=>$value)
 {
  $fields[$key] = DB::escape($value);
 }

 $sql = "UPDATE `".TABLE_PREFIX."schedules` SET ";
 $sql .= DB::build_update($fields);
 $sql .= ' WHERE `id`='.$scheduleid;

 $res = DB::query($sql);

 if(DB::errno() != 0)
 {
  return false;
 }

 return true;
}
/**
 * Delete a schedule
 */
public static function deleteSchedule($scheduleid)
{
 $scheduleid = DB::escape($scheduleid);
 $sql = 'DELETE FROM ' .TABLE_PREFIX.'schedules
   WHERE id='.$scheduleid;
 $res = DB::query($sql);

 if(DB::errno() != 0)
  return false;

 return true;
}

public static function deleteAllSchedules()
{
 $sql = 'DELETE FROM ' .TABLE_PREFIX.'schedules';
 $res = DB::query($sql);

 if(DB::errno() != 0)
  return false;

 return true;
}

public static function deleteAllScheduleDetails()
{
 $sql = 'UPDATE '.TABLE_PREFIX."schedules
   SET `route_details` = ''";

  $res = DB::query($sql);

 if(DB::errno() != 0)
  return false;

 return true;
}

public static function getAllBids()
{
 $sql = 'SELECT  p.*, s.*,
  b.bidid as bidid, b.dateadded, a.name as aircraft, a.registration
   FROM '.TABLE_PREFIX.'schedules s,
  '.TABLE_PREFIX.'bids b,
  '.TABLE_PREFIX.'aircraft a,
  '.TABLE_PREFIX.'pilots p
   WHERE b.routeid = s.id AND s.aircraft=a.id AND p.pilotid = b.pilotid
   ORDER BY b.bidid DESC';

 return DB::get_results($sql);
}

/**
 * Get the latest bids
 */

public static function getLatestBids($limit=5)
{
 $sql = 'SELECT  p.*, s.*,
  b.bidid as bidid, a.name as aircraft, a.registration
   FROM '.TABLE_PREFIX.'schedules s,
  '.TABLE_PREFIX.'bids b,
  '.TABLE_PREFIX.'aircraft a,
  '.TABLE_PREFIX.'pilots p
   WHERE b.routeid = s.id AND s.aircraft=a.id AND p.pilotid = b.pilotid
   ORDER BY b.bidid DESC
   LIMIT '.$limit;

 return DB::get_results($sql);
}

public function getLatestBid($pilotid)
{
 $pilotid = DB::escape($pilotid);

 $sql = 'SELECT s.*, b.bidid, a.id as aircraftid, a.name as aircraft, a.registration, a.maxpax, a.maxcargo
   FROM '.TABLE_PREFIX.'schedules s,
  '.TABLE_PREFIX.'bids b,
  '.TABLE_PREFIX.'aircraft a
   WHERE b.routeid = s.id
 AND s.aircraft=a.id
 AND b.pilotid='.$pilotid.'
   ORDER BY b.bidid ASC LIMIT 1';

 return DB::get_row($sql);
}

/**
 * Get a specific bid with route information
 *
 * @param unknown_type $bidid
 * @return unknown
 */
public static function getBid($bidid)
{
 $bidid = DB::escape($bidid);

 $sql = 'SELECT s.*, b.bidid, b.pilotid, b.routeid,
  a.name as aircraft, a.registration
   FROM '.TABLE_PREFIX.'schedules s, '.TABLE_PREFIX.'bids b,
 '.TABLE_PREFIX.'aircraft a
   WHERE b.routeid = s.id
  AND s.aircraft=a.id
  AND b.bidid='.$bidid;

 return DB::get_row($sql);
}

/**
 * Get all of the bids for a pilot
 *
 * @param unknown_type $pilotid
 * @return unknown
 */
public static function getBids($pilotid)
{ 
 $pilotid = DB::escape($pilotid);
 $sql = 'SELECT s.*, b.bidid, a.name as aircraft, a.registration
   FROM '.TABLE_PREFIX.'schedules s, '.TABLE_PREFIX.'bids b,
 '.TABLE_PREFIX.'aircraft a
   WHERE b.routeid = s.id
 AND s.aircraft=a.id
 AND b.pilotid='.$pilotid;

 return DB::get_results($sql);
}

/**
 * Get find a bid for the pilot based on ID,
 * the airline code for the flight, and the flight number
 */
public static function getBidWithRoute($pilotid, $code, $flightnum)
{
 if($pilotid == '')
  return;

 $sql = 'SELECT b.bidid
   FROM '.TABLE_PREFIX.'bids b, '.TABLE_PREFIX.'schedules s
   WHERE b.pilotid='.$pilotid.'
 AND b.routeid=s.id
 AND s.code=\''.$code.'\'
 AND s.flightnum=\''.$flightnum.'\'';

 return DB::get_row($sql);
}

public static function setBidOnSchedule($scheduleid, $bidid)
{
 $scheduleid = intval($scheduleid);
 $bidid = intval($bidid);

 $sql = 'UPDATE '.TABLE_PREFIX.'schedules
   SET `bidid`='.$bidid.'
   WHERE `id`='.$scheduleid;

 DB::query($sql);

 if(DB::errno() != 0)
  return false;

 return true;
}

/**
 * Add a bid
 */ 
public static function addBid($pilotid, $routeid)
{
 $pilotid = DB::escape($pilotid);
 $routeid = DB::escape($routeid);

 if(DB::get_row('SELECT bidid FROM '.TABLE_PREFIX.'bids
  WHERE pilotid='.$pilotid.' AND routeid='.$routeid))
 {
  return false;
 }

 $pilotid = DB::escape($pilotid);
 $routeid = DB::escape($routeid);

 $sql = 'INSERT INTO '.TABLE_PREFIX.'bids (pilotid, routeid, dateadded)
   VALUES ('.$pilotid.', '.$routeid.', NOW())';

 DB::query($sql);

 self::setBidOnSchedule($routeid, DB::$insert_id);

 if(DB::errno() != 0)
  return false;

 return true;
}

public static function deleteExpiredBids()
{ 
 $cache_time = Config::Get('BID_EXPIRE_TIME');
 if($cache_time == '')
 {
  return;
 }

 $sql = 'DELETE FROM '.TABLE_PREFIX."bids
   WHERE `dateadded` + INTERVAL {$cache_time} HOUR < NOW()";

 DB::query($sql);

}
/**
 * Remove a bid, by passing it's bid id
 */
public static function deleteBid($bidid)
{
 self::removeBid($bidid);
}

/**
 * Remove a bid, by passing it's bid id
 */
public static function removeBid($bidid)
{
 $bidid = intval($bidid);
 $bid_info = self::getBid($bidid);

 $sql = 'DELETE FROM '.TABLE_PREFIX.'bids
   WHERE `bidid`='.$bidid;

 DB::query($sql);

 self::SetBidOnSchedule($bid_info->routeid, 0);

 if(DB::errno() != 0)
  return false;

 return true;
}


/**
 * @deprecated
 *
 */
public static function getScheduleFlownCounts($code, $flightnum, $days=7)
{
 $max = 0;


 $code = strtoupper($code);
 $flightnum = strtoupper($flightnum);

 $start = strtotime("- $days days");
 $end = time();
 $data = array();

 # Turn on caching: 
 DB::enableCache();

 do
 {
  $count = PIREPData::getReportCountForRoute($code, $flightnum, $start);
  $date = date('m-d', $start);

  $data[$date] = $count;  

  $start += SECONDS_PER_DAY;

 }  while ($start <= $end);

 DB::disableCache();

 return $data;
}

/**
 * Show the graph of the past week's reports. Outputs the
 * image unless $ret == true
 *
 * @deprecated
 */
public static function showReportCounts()
{
 // Recent PIREP #'s
 $max = 0;
 $data = array();
 $time_start = strtotime('-7 days');
 $time_end = time();

 // This is for the past 7 days
 do {
  $count = PIREPData::getReportCount($time_start);

  $data[] = $count;

  if($count > $max)
   $max = $count;

  $time_start += SECONDS_PER_DAY;
 } while ($time_start < $time_end);

 return $data;
}

/* Below here, these are all deprecated. In your code, you should use
 the query structure, defined within the functions

/**
 * @deprecated
 */
/*public static function getSchedulesWithCode($code, $onlyenabled=true, $limit='', $start='')
{
 $params = array('s.code' => strtoupper($code));
 if($onlyenabled)
  $params['s.enabled'] = '1';

 return self::findSchedules($params, $limit, $start);
}*/

/**
 * @deprecated
 */
/*public static function getSchedulesWithFlightNum($flightnum, $onlyenabled=true, $limit='', $start='')
{
 $params = array('s.flightnum' => $flightnum);
 if($onlyenabled)
  $params['s.enabled'] = '1';

 return self::findSchedules($params, $limit, $start);
}*/

/**
 * Return all of the routes give the departure airport
 *
 * @deprecated
 */
/*public static function getSchedulesWithDeparture($depicao, $onlyenabled = true, $limit = '', $start='')
{
 self::getRoutesWithDeparture($depicao, $onlyenabled, $limit);
}*/
/**
 * @deprecated
 */
/*public static function getRoutesWithDeparture($depicao, $onlyenabled=true, $limit='', $start='')
{
 $params = array('s.depicao' => strtoupper($depicao));
 if($onlyenabled)
  $params['s.enabled'] = '1';

 return self::findSchedules($params, $limit, $start);
}*/

/**
 * @deprecated
 */
/*public static function getRoutesWithArrival($arricao, $onlyenabled=true, $start='', $limit='')
{
 return self::getSchedulesWithArrival($arricao, $onlyenabled, $limit);
}*/

/**
 * @deprecated
 */
/*public static function getSchedulesWithArrival($arricao, $onlyenabled=true, $start='', $limit='')
{
 $params = array('s.arricao' => strtoupper($arricao));
 if($onlyenabled)
  $params['s.enabled'] = '1';

 return self::findSchedules($params, $limit, $start);
}*/

/**
 * @deprecated
 */
/*public static function getSchedulesByDistance($distance, $type, $onlyenabled=true, $start='', $limit='')
{
 if($type == '')
  $type = '>';

 $params = array('s.distance' => trim($type).' '.$distance);
 if($onlyenabled)
  $params['s.enabled'] = '1';

 return self::findSchedules($params, $limit, $start);
}*/

/**
 * Search schedules by the equipment type
 *
 * @deprecated
 */
/*public static function getSchedulesByEquip($ac, $onlyenabled = true, $start='', $limit='')
{
 $params = array('a.name' => $ac);
 if($onlyenabled)
  $params['s.enabled'] = '1';

 return self::findSchedules($params, $limit, $start);
}*/
}

Link to comment
Share on other sites

Of course, the $data parsed to the addSchedule function comes from admin/core/modules/Schedules/Schedules.php

Can you suggest how this code to register right?

This is my Schedules.php

<?php
/**
* phpVMS - Virtual Airline Administration Software
* Copyright (c) 2008 Nabeel Shahzad
* For more information, visit www.phpvms.net
* Forums: http://www.phpvms.net/forum
* Documentation: http://www.phpvms.net/docs
*
* phpVMS is licenced under the following license:
*   Creative Commons Attribution Non-commercial Share Alike (by-nc-sa)
*   View license.txt in the root, or visit http://creativecommons.org/licenses/by-nc-sa/3.0/
*
* @author Nabeel Shahzad
* @copyright Copyright (c) 2008, Nabeel Shahzad
* @link http://www.phpvms.net
* @license http://creativecommons.org/licenses/by-nc-sa/3.0/
*/

class Schedules extends CodonModule
{
public function index()
{
 $this->view();
}

public function view()
{
 if(isset($this->post->action) && $this->post->action == 'findflight')
 {
  $this->FindFlight();
  return;
 }

 $this->showSchedules();
}

public function detail($routeid='')
{
 $this->details($routeid);
}

public function details($routeid = '')
{
 //$routeid = $this->get->id;

 if(!is_numeric($routeid))
 {
  preg_match('/^([A-Za-z]{3})(\d*)/', $routeid, $matches);
  $code = $matches[1];
  $flightnum = $matches[2];

  $params = array('s.code'=>$code, 's.flightnum'=>$flightnum);
 }
 else
 {
  $params = array('s.id' => $routeid);
 }

 $schedule = SchedulesData::getScheduleDetailed($routeid);
 $this->set('schedule', $schedule);
 $this->render('schedule_details.tpl');
 $this->render('route_map.tpl');
}

public function brief($routeid = '')
{
 if($routeid == '')
 {
  $this->set('message', 'You must be logged in to access this feature!');
  $this->render('core_error.tpl');
  return;
 }

 $schedule = SchedulesData::getScheduleDetailed($routeid);
 $this->set('schedule', $schedule);
 $this->render('schedule_briefing.tpl');
}

public function boardingpass($routeid)
{
 if($routeid == '')
 {
  $this->set('message', 'You must be logged in to access this feature!');
  $this->render('core_error.tpl');
  return;
 }

 $schedule = SchedulesData::getScheduleDetailed($routeid);

 $this->set('schedule', $schedule);
 $this->render('schedule_boarding_pass.tpl');
}

public function bids()
{
 if(!Auth::LoggedIn()) return;

 $this->set('bids', SchedulesData::GetBids(Auth::$userinfo->pilotid));
 $this->render('schedule_bids.tpl');
}

public function addbid()
{
 if(!Auth::LoggedIn()) return;

 $routeid = $this->get->id;

 if($routeid == '')
 {
  echo 'No route passed';
  return;
 }

 // See if this is a valid route
 $route = SchedulesData::findSchedules(array('s.id' => $routeid));

 if(!is_array($route) && !isset($route[0]))
 {
  echo 'Invalid Route';
  return;
 }

 CodonEvent::Dispatch('bid_preadd', 'Schedules', $routeid);

 /* Block any other bids if they've already made a bid
  */
 if(Config::Get('DISABLE_BIDS_ON_BID') == true)
 {
  $bids = SchedulesData::getBids(Auth::$userinfo->pilotid);

  # They've got somethin goin on
  if(count($bids) > 0)
  {
   echo 'Bid exists!';
   return;
  }
 }

 $ret = SchedulesData::AddBid(Auth::$userinfo->pilotid, $routeid);
 CodonEvent::Dispatch('bid_added', 'Schedules', $routeid);

 if($ret == true)
 {
  echo 'Bid added';
 }
 else
 {
  echo 'Already in bids!';
 }
}

public function removebid()
{
 if(!Auth::LoggedIn()) return;

 SchedulesData::RemoveBid($this->post->id);
}
public function showSchedules()
{
 $depapts = OperationsData::GetAllAirports();
 $equip = OperationsData::GetAllAircraftSearchList(true);

 $this->set('depairports', $depapts);
 $this->set('equipment', $equip);

 $this->render('schedule_searchform.tpl');

 # Show the routes. Remote this to not show them.
 $this->set('allroutes', SchedulesData::GetSchedules());

 $this->render('schedule_list.tpl');
}

public function findFlight()
{

 if($this->post->depicao != '')
 {
  $params = array('s.depicao' => $this->post->depicao);
 }

 if($this->post->arricao != '')
 {
  $params = array('s.arricao' => $this->post->arricao);
 }

 if($this->post->equipment != '')
 {
  $params = array('a.name' => $this->post->equipment);
 }

 if($this->post->distance != '')
 {
  if($this->post->type == 'greater')
   $value = '> ';
  else
   $value = '< ';

  $value .= $this->post->distance;

  $params = array('s.distance' => $value);
 }

 $params['s.enabled'] = 1;
 $this->set('allroutes', SchedulesData::findSchedules($params));
 $this->render('schedule_results.tpl');
}

public function statsdaysdata($routeid)
{
 $routeinfo = SchedulesData::findSchedules(array('s.id'=>$routeid));
 $routeinfo = $routeinfo[0];

 // Last 30 days stats
 $data = PIREPData::getIntervalDataByDays(
  array(
   'p.code' => $routeinfo->code,
   'p.flightnum' => $routeinfo->flightnum,
  ), 30);

 $this->create_line_graph('Schedule Flown Counts', $data);
}

protected function create_line_graph($title, $data)
{
 if(!$data)
 {
  $data = array();
 }

 $titles = array();
 $bar_titles = array();
 foreach($data as $val)
 {
  $titles[] = $val->ym;
  $values[] = floatval($val->total);
 }

 OFCharts::add_data_set($titles, $values);
 echo OFCharts::create_line_graph($title);
}
}

Link to comment
Share on other sites

This is not admin/core/modules/Schedules/Schedules.php although you will have to find the function for the addschedule and editschedule and store the posted value of the new input field into the data array.

admin/core/modules/Schedules

I have generally no such folder in this directory

2016-06-11_005610.jpg

Edited by bass
Link to comment
Share on other sites

This?

phpVMS 5.5.x https://github.com/DavidJClark/phpvms_5.5.x

/**
 * Operations::add_schedule_post()
 *
 * @return
 */
protected function add_schedule_post() {
 $this->checkPermission(EDIT_SCHEDULES);

 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.php');
	 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.php');
	 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);
 if(is_array($_POST['daysofweek'])) {
	 $daysofweek = implode('', $_POST['daysofweek']);
 } else {
	 $daysofweek = '0123456'; # default activate for all days
 }

 if (is_array($_POST['week1'])) {
	 $week1 = implode('', $_POST['week1']);
 } else {
	 $week1 = '';
 }
 if (is_array($_POST['week2'])) {
	 $week2 = implode('', $_POST['week2']);
 } else {
	 $week2 = '';
 }
 if (is_array($_POST['week3'])) {
	 $week3 = implode('', $_POST['week3']);
 } else {
	 $week3 = '';
 }
 if (is_array($_POST['week4'])) {
	 $week4 = implode('', $_POST['week4']);
 } else {
	 $week4 = '';
 }

 $this->post->alternativ = strtoupper($this->post->alternativ);

 $data = array(
	 'code' => $this->post->code,
	 'flightnum' => $this->post->flightnum,
	 'depicao' => $this->post->depicao,
	 'arricao' => $this->post->arricao,
	 'alternativ' => $this->post->alternative,
	 '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' => $daysofweek,
	 'week1' => $week1, 'week2' => $week2, 'week3' => $week3, 'week4' => $week4,
	 'price' => $this->post->price,
	 'payforflight' => $this->post->payforflight,
	 '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.php');
	 return;
 }
 $this->set('message', 'The schedule "' . $this->post->code . $this->post->flightnum .
	 '" has been added');
 $this->render('core_success.php');
 LogData::addLog(Auth::$userinfo->pilotid, 'Added schedule "' . $this->post->code .
	 $this->post->flightnum . '"');
}
/**
 * Operations::edit_schedule_post()
 *
 * @return
 */
protected function edit_schedule_post() {
 $this->checkPermission(EDIT_SCHEDULES);
 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.php');
	 return;
 }
 $enabled = ($this->post->enabled == 'on') ? true : false;
 $this->post->route = strtoupper($this->post->route);
 # Format the flight level
 $this->post->flightlevel = str_replace(',', '', $this->post->flightlevel);
 $this->post->flightlevel = str_replace(' ', '', $this->post->flightlevel);
 # Clear anything invalid out of the route
 $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);
 if(is_array($_POST['daysofweek'])) {
	 $daysofweek = implode('', $_POST['daysofweek']);
 } else {
	 $daysofweek = '0123456'; # default activate for all days
 }
 #var_dump($_POST);
 if (is_array($_POST['week1'])) {
	 $week1 = implode('', $_POST['week1']);
 } else {
	 $week1 = '';
 }
 if (is_array($_POST['week2'])) {
	 $week2 = implode('', $_POST['week2']);
 } else {
	 $week2 = '';
 }
 if (is_array($_POST['week3'])) {
	 $week3 = implode('', $_POST['week3']);
 } else {
	 $week3 = '';
 }
 if (is_array($_POST['week4'])) {
	 $week4 = implode('', $_POST['week4']);
 } else {
	 $week4 = '';
 }

 $this->post->alternativ = strtoupper($this->post->alternativ);
 $data = array(
	 'code' => $this->post->code,
	 'flightnum' => $this->post->flightnum,
	 'depicao' => $this->post->depicao,
	 'arricao' => $this->post->arricao,
	 'alternativ' => $this->post->alternative,
	 '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' => $daysofweek,
	 'week1' => $week1, 'week2' => $week2, 'week3' => $week3, 'week4' => $week4,
	 'price' => $this->post->price, 'payforflight' => $this->post->payforflight,
	 'flighttype' => $this->post->flighttype, 'notes' => $this->post->notes,
	 'enabled' => $enabled
 );
 $val = SchedulesData::editScheduleFields($this->post->id, $data);
 if (!$val) {
	 $this->set('message', 'There was an error editing the schedule: ' . DB::error());
	 $this->render('core_error.php');
	 return;
 }
 # Parse the route:
 SchedulesData::getRouteDetails($this->post->id, $this->post->route);
 $this->set('message', 'The schedule "' . $this->post->code . $this->post->flightnum .
	 '" has been edited');
 $this->render('core_success.php');
 LogData::addLog(Auth::$userinfo->pilotid, 'Edited schedule "' . $this->post->code .
	 $this->post->flightnum . '"');
}

Edited by web541
Link to comment
Share on other sites

yep, you can make adjustments accordingly, it's in admin/modules/Operations/Operations.php

Error

Fatal error: Call to undefined method Operations::checkPermission() in/home/u173934115/public_html/admin/modules/Operations/Operations.php on line 979

Link to comment
Share on other sites

try this one for your version

phpVMS 2.1.936 https://github.com/nabeelio/phpVMS

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);

 $this->post->alternativ = strtoupper($this->post->alternativ);

$data = array( 'code'=>$this->post->code,
 'flightnum'=>$this->post->flightnum,
 'depicao'=>$this->post->depicao,
 'arricao'=>$this->post->arricao,
				 'alternativ'=>$this->post->alternativ,
 '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.'"');
}
protected function edit_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;
}

$enabled = ($this->post->enabled == 'on') ? true : false;
$this->post->route = strtoupper($this->post->route);

# Format the flight level
$this->post->flightlevel = str_replace(',', '', $this->post->flightlevel);
$this->post->flightlevel = str_replace(' ', '', $this->post->flightlevel);

# Clear anything invalid out of the route
$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);

 $this->post->alternativ = strtoupper($this->post->alternativ);

$data = array( 'code'=>$this->post->code,
 'flightnum'=>$this->post->flightnum,
 'depicao'=>$this->post->depicao,
 'arricao'=>$this->post->arricao,
				 'alternativ'=>$this->post->alternativ,
 '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);

$val = SchedulesData::editScheduleFields($this->post->id, $data);
if(!$val)
{
$this->set('message', 'There was an error editing the schedule: '.DB::error());
$this->render('core_error.tpl');
return;
}

# Parse the route:
SchedulesData::getRouteDetails($this->post->id, $this->post->route);

$this->set('message', 'The schedule "'.$this->post->code.$this->post->flightnum.'" has been edited');
$this->render('core_success.tpl');

LogData::addLog(Auth::$userinfo->pilotid, 'Edited schedule "'.$this->post->code.$this->post->flightnum.'"');
}

Edited by web541
  • Like 1
Link to comment
Share on other sites

try this one for your version

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);

 $this->post->alternativ = strtoupper($this->post->alternativ);

$data = array( 'code'=>$this->post->code,
 'flightnum'=>$this->post->flightnum,
 'depicao'=>$this->post->depicao,
 'arricao'=>$this->post->arricao,
				 'alternativ'=>$this->post->alternativ,
 '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.'"');
}
protected function edit_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;
}

$enabled = ($this->post->enabled == 'on') ? true : false;
$this->post->route = strtoupper($this->post->route);

# Format the flight level
$this->post->flightlevel = str_replace(',', '', $this->post->flightlevel);
$this->post->flightlevel = str_replace(' ', '', $this->post->flightlevel);

# Clear anything invalid out of the route
$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);

 $this->post->alternativ = strtoupper($this->post->alternativ);

$data = array( 'code'=>$this->post->code,
 'flightnum'=>$this->post->flightnum,
 'depicao'=>$this->post->depicao,
 'arricao'=>$this->post->arricao,
				 'alternativ'=>$this->post->alternativ,
 '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);

$val = SchedulesData::editScheduleFields($this->post->id, $data);
if(!$val)
{
$this->set('message', 'There was an error editing the schedule: '.DB::error());
$this->render('core_error.tpl');
return;
}

# Parse the route:
SchedulesData::getRouteDetails($this->post->id, $this->post->route);

$this->set('message', 'The schedule "'.$this->post->code.$this->post->flightnum.'" has been edited');
$this->render('core_success.tpl');

LogData::addLog(Auth::$userinfo->pilotid, 'Edited schedule "'.$this->post->code.$this->post->flightnum.'"');
}

WORKING!!!

Thank you very much for your help!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...