Jump to content

eliezerazevedo

Members
  • Posts

    60
  • Joined

  • Last visited

Posts posted by eliezerazevedo

  1. Hello,

    My country (Brazil) offers repetitive flight plans (RPL) of all domestic airlines to public consultation. The format and "TXT" would like to import that content to facilitate the registration of routes, does anyone have any idea how this could be done?

    File you want to import the information: http://www.cgna.gov..../Cia_GLO_CS.txt

    Source: http://www.cgna.gov.br/

    Source: http://www.cgna.gov.br/?page_id=148

  2. I did not work, I believe the code is not compatible with the version of PHPVMS I'm used.

    The message he gave me was is!

    Currently you have no flight booked!

    My SchedulesData.class.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 SchedulesData extends CodonData
    { [/background][/size][/font][/color][/b]
    [b][color=#58666E][font="Open Sans", sans-serif][size=3][background=rgb(245, 245, 245)]/**
     * 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;[/background][/size][/font][/color][/b]
    [b][color=#58666E][font="Open Sans", sans-serif][size=3][background=rgb(245, 245, 245)]  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;[/background][/size][/font][/color][/b]
    [b][color=#58666E][font="Open Sans", sans-serif][size=3][background=rgb(245, 245, 245)]  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'=>'',
      'alticao'=>'',
      'route'=>'',
      'aircraft'=>'',
      'distance'=>'',
      'deptime'=>'',
      'arrtime'=>'',
      'flighttime'=>'',
      'EQPT'=>'',
      'PBN'=>'',
      'EET'=>'',
      'PER'=>'',
      'RALT'=>'',
      'RMK'=>'',
      'OPR'=>'',
      '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['alticao'] = strtoupper($data['alticao']);
    
     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`, `alticao`,
      `route`, `route_details`,
      `aircraft`, `flightlevel`, `distance`,
      `deptime`, `arrtime`,
      `flighttime`, `daysofweek`, `price`,
      `flighttype`, `EQPT`, `PBN`, `EET`, `PER`, `RALT`, `RMK`, `OPR`, `notes`, `enabled`)
       VALUES ('{$data['code']}',
      '{$data['flightnum']}',
      '{$data['depicao']}',
      '{$data['arricao']}',
      '{$data['alticao']}',
      '{$data['route']}',
      '{$data['route_details']}',
      '{$data['aircraft']}',
      '{$data['flightlevel']}',
      '{$data['distance']}',
      '{$data['deptime']}',
      '{$data['arrtime']}',
      '{$data['flighttime']}',
      '{$data['daysofweek']}',
      '{$data['price']}',
      '{$data['flighttype']}',
      '{$data['EQPT']}',
      '{$data['PBN']}',
      '{$data['EET']}',
      '{$data['PER']}',
      '{$data['RALT']}',
      '{$data['RMK']}',
      '{$data['OPR']}',
      '{$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;
    }[/background][/size][/font][/color][/b]
    [b][color=#58666E][font="Open Sans", sans-serif][size=3][background=rgb(245, 245, 245)]/**
     * 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);
    }[/background][/size][/font][/color][/b]
    
    [b][color=#58666E][font="Open Sans", sans-serif][size=3][background=rgb(245, 245, 245)]/**
     * 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']);
     }[/background][/size][/font][/color][/b]
    [b][color=#58666E][font="Open Sans", sans-serif][size=3][background=rgb(245, 245, 245)] 
     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;
    }[/background][/size][/font][/color][/b]
    [b][color=#58666E][font="Open Sans", sans-serif][size=3][background=rgb(245, 245, 245)]/**
     * Delete a schedule
     */
    public static function deleteSchedule($scheduleid)
    {
     $scheduleid = DB::escape($scheduleid);
     $sql = 'DELETE FROM ' .TABLE_PREFIX.'schedules
       WHERE id='.$scheduleid;[/background][/size][/font][/color][/b]
    [b][color=#58666E][font="Open Sans", sans-serif][size=3][background=rgb(245, 245, 245)]  $res = DB::query($sql);
    
     if(DB::errno() != 0)
      return false;
    
     return true;
    }
    
    public static function deleteAllSchedules()
    {
     $sql = 'DELETE FROM ' .TABLE_PREFIX.'schedules';[/background][/size][/font][/color][/b]
    [b][color=#58666E][font="Open Sans", sans-serif][size=3][background=rgb(245, 245, 245)]  $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();[/background][/size][/font][/color][/b]
    [b][color=#58666E][font="Open Sans", sans-serif][size=3][background=rgb(245, 245, 245)]  $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);
    }*/[/background][/size][/font][/color][/b]
    [b][color=#58666E][font="Open Sans", sans-serif][size=3][background=rgb(245, 245, 245)]/**
     * @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);
    }*/
    }
    
  3. Did not work :(

    If the pilot land at JFK, the next flight that will be shown in the table will be from JFK to XXX.

    I am currently using a scale system that generates 25 flights.

    schedule_bids.tpl

     <!-- Start Page Header -->
    <div class="row presentation">
       <div class="col-lg-8 col-md-6 titles">
      <span class="icon color14-bg"><i class="fa fa-plane"></i></span>
      <h1>Minha Escala</h1>
      <h4 class="active label label-danger" style="color:#FFFFFF">Atenção ao dia de operação do vôo! Vôos realizados em dias divergente do adquirido, serão rejeitados automaticamente.</h4>
       </div>
    </div>
     <!-- End Page Header -->
     <?php
    if(!$bids)
    {
    echo '<div id="error">Currently you have no flight booked!</div>';
    return;
    }
    ?>
    </p>
    <table class="table table-bordered table-striped" align="center">
    
     <tr>
    <td align="center"><strong>Vôo</strong></td>
    <td align="center"><strong>DEP / ARR</strong></td>
    <td align="center"><strong>Aeronave</strong></td>
    <td align="center"><strong>Plano de Vôo</strong></td>
    <td align="center"><strong>Navegação SITA</strong></td>
       <td align="center"><strong>FOQA</strong></td>
    <td align="center"><strong>Dia de Operação</strong></td>
    </tr>
    <?php
    foreach($bids as $bid)
    {
    ?>
    <tr id="bid<?php echo $bid->bidid ?>">
    <td align="center"><?php echo $bid->code . $bid->flightnum; ?></td>
    <td align="center"><?php echo $bid->depicao; ?> / <?php echo $bid->arricao; ?></td>
    <td align="center"><a href="<?php echo ('https://www.flightradar24.com/data/aircraft/'.$bid->registration);?>" target="_blank"><?php echo $bid->aircraft; ?> (<?php echo $bid->registration?>)</a></td>
    <td align="center"><a href="<?php echo actionurl('/IVAOFlightPlan/download_ivao/'.$bid->id);?>">Baixar Plano de Vôo</a></td>
    <td align="center"><a href="<?php echo actionurl('/schedules/brief/'.$bid->id);?>" target="_blank">Navegação S.I.T.A</a></td>
       <td align="center"><a href="#" onclick="javascript: window.open('<?php echo SITE_URL ?>/FOQA/<?php echo $bid->aircraft; ?>.php', '', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=660,height=850,left = 240,top = 20'); return false"><font color="#CC6600">Limites Operacionais</font></a>
    </td>
    <td align="center"><?php echo Util::GetDaysCompact($bid->daysofweek); ?></td>
    </tr>
    <?php
    }
    ?>
    </table>
    <hr>
    <a href="<?php echo url('/profile'); ?>" class="btn btn-square fa fa-chevron-left"> Voltar</a>
    <p> </p>
    

  4. Not valid my PIREP. :(

    I use CAVACARS

    PIREPData.class.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 PIREPData extends CodonData
    {
    public static $lasterror;
    public static $pirepid;
    
    
    /**
     * 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 findPIREPS($params,  $count = '', $start = '')
    {
     $sql = 'SELECT p.*, UNIX_TIMESTAMP(p.submitdate) as submitdate,
     u.pilotid, u.firstname, u.lastname, u.email, u.rank,
     a.id AS aircraftid, a.name as aircraft, a.registration,
     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.'pireps p
       LEFT JOIN '.TABLE_PREFIX.'aircraft a ON a.id = p.aircraft
       LEFT JOIN '.TABLE_PREFIX.'airports AS dep ON dep.icao = p.depicao
       LEFT JOIN '.TABLE_PREFIX.'airports AS arr ON arr.icao = p.arricao
       LEFT JOIN '.TABLE_PREFIX.'pilots u ON u.pilotid = p.pilotid ';
    
     /* Build the select "WHERE" based on the columns passed */ 
     $sql .= DB::build_where($params);
    
     if(Config::Get('PIREPS_ORDER_BY') != '')
     {
      $sql .= ' ORDER BY '.Config::Get('PIREPS_ORDER_BY');
     }
    
     if(strlen($count) != 0)
     {
      $sql .= ' LIMIT '.$count;
     }
    
     if(strlen($start) != 0)
     {
      $sql .= ' OFFSET '. $start;
     }
    
     $ret = DB::get_results($sql);
     return $ret;
    }/**
     * Get internal data for the past $interval months, including the
     * total number of PIREPS and revenue
     *
     * @param array $where_params Any specific conditions to search on
     * @param int $interval The interval, in months
     * @return mixed This is the return value description
     *
     */
    public static function getIntervalDataByMonth($where_params, $interval='6')
    {
     $date_clause = "DATE_SUB(NOW(), INTERVAL {$interval} MONTH) <= p.submitdate";
    
     /* See if this array already exists */
     if(!is_array($where_params))
     {
      $where_params=array($date_clause);
     }
     else
     {
      $where_params[] = $date_clause;
     }
    
     $data = self::getIntervalData($where_params);
    
     if(!$data)
     {
      return array();
     }
    
     foreach($data as $month)
     {
      $month = FinanceData::calculateFinances($month);
     }
    
     return $data;
    }
    
    /**
     * Get internal data for the past $interval days, including the
     * total number of PIREPS and revenue
     *
     * @param array $where_params Any specific conditions to search on
     * @param int $interval The interval, in days
     * @return mixed This is the return value description
     *
     */
    public static function getIntervalDataByDays($where_params, $interval='7')
    {
     $date_clause = "DATE_SUB(CURDATE(), INTERVAL {$interval} DAY)  <= p.submitdate";
    
     /* See if this array already exists */
     if(!is_array($where_params))
     {
      $where_params=array($date_clause);
     }
     else
     {
      $where_params[] = $date_clause;
     }
    
     return self::getIntervalData($where_params, 'D');
    }
    
    
    /**
     * Get interval financial data, with the date clause
     * passed in as a WHERE:
     *
     * "DATE_SUB(CURDATE(), INTERVAL {$interval} DAY)  <= p.submitdate";
     *
     * Or some form of a date limitation, but has to be within the
     * where clause
     *
     * @param array $where_params Any WHERE parameters
     * @param char $grouping How to group data - Y for yearly, M for monthly, D for daily
     * @return array Returns finance data according to the above grouping
     *
     */
    public static function getIntervalData($where_params, $grouping='M')
    {
     $grouping = strtolower($grouping);
    
     if($grouping == 'y')
     {
      $format = '%Y';
     }
     elseif($grouping == 'm')
     {
      $format = '%Y-%m';
     }
     elseif($grouping == 'd') /* go by day */
     {
      $format = '%Y-%m-%d';
     }
    
     $sql = "SELECT DATE_FORMAT(p.submitdate, '{$format}') AS ym,
     UNIX_TIMESTAMP(p.submitdate) AS timestamp,
     COUNT(p.pirepid) AS total,
     SUM(p.revenue) as revenue,
     SUM(p.gross) as gross,
     SUM(p.fuelprice) as fuelprice,
     SUM(p.price) as price,
     SUM(p.expenses) as expenses,
     SUM((TIME_TO_SEC(flighttime_stamp)/60) * (pilotpay/60)) as pilotpay
       FROM ".TABLE_PREFIX."pireps p";
    
     $sql .= DB::build_where($where_params);
     $sql .= ' GROUP BY `ym` ORDER BY `timestamp` ASC';
    
     $results = DB::get_results($sql);
    
     return $results;
    }
    
    /**
     * Return all of the pilot reports. Can pass a start and
     * count for pagination. Returns 20 rows by default. If you
     * only want to return the latest n number of reports, use
     * getRecentReportsByCount()
     *
     */
    public static function getAllReports($count = '', $start = 0)
    {
     return self::findPIREPS(array(), $count, $start);
    }
    
    /**
     * Get all of the reports by the accepted status. Use the
     * constants:
     * PIREP_PENDING, PIREP_ACCEPTED, PIREP_REJECTED,PIREP_INPROGRESS
     */
    public static function getAllReportsByAccept($accepted = 0)
    {
     $params = array(
      'p.accepted'=>$accept
     );
    
     return self::findPIREPS($params);
    }
    
    public static function getAllReportsFromHub($accepted = 0, $hub)
    {
     $params = array(
      'p.accepted' => $accepted,
      'u.hub' => $hub
     );
    
     return self::findPIREPS($params);
    }
    /**
     * Get the latest reports that have been submitted,
     * return the last 10 by default
     */
    public static function getRecentReportsByCount($count = 10)
    {
     if($count == '') $count = 10;
    
     return self::findPIREPS('', $count);
    }/**
     * Get the latest reports by n number of days
     */
    public static function getRecentReports($days=2)
    {
     # No => assumes just to plop in the entire expression "raw"
     $params = array(
      'DATE_SUB(CURDATE(), INTERVAL '.$days.' DAY) <= p.submitdate'
     );
    
     return self::findPIREPS($params);
    }
    
    /**
     * Get all of the reports by the exported status (true or false)
     */
    public static function getReportsByExportStatus($status)
    {
     if($status === true)
      $status = 1;
     else
      $status = 0;
    
     return self::findPIREPS(array('p.exported'=>$status));
    }
    /**
     * Get the number of reports on a certain date
     *  Pass unix timestamp for the date
     */
    public static function getReportCount($date)
    {
     $sql = 'SELECT COUNT(*) AS count
       FROM '.TABLE_PREFIX.'pireps
       WHERE DATE(submitdate)=DATE(FROM_UNIXTIME('.$date.'))';  $row = DB::get_row($sql);
     if(!$row)
      return 0;
    
     return ($row->count=='') ? 0 : $row->count;
    }
    
    /**
     * Get the number of reports on a certain date, for a certain route
     *
     * @param string $code Airline code
     * @param string $flightnum Flight number
     * @param timestamp $date UNIX timestamp
     */
    public static function getReportCountForRoute($code, $flightnum, $date)
    {
     $MonthYear = date('mY', $date);
     $sql = "SELECT COUNT(*) AS count
       FROM ".TABLE_PREFIX."pireps
       WHERE DATE_FORMAT(submitdate, '%c%Y') = '$MonthYear'
     AND code='$code' AND flightnum='$flightnum'";
     $row = DB::get_row($sql);
     return $row->count;
    }/**
     * Get the number of reports for the last x  number of days
     * Returns 1 row for every day, with the total number of
     * reports per day
     */
    public static function getCountsForDays($days = 7)
    {
     $sql = 'SELECT DISTINCT(DATE(submitdate)) AS submitdate,
     (SELECT COUNT(*) FROM '.TABLE_PREFIX.'pireps WHERE DATE(submitdate)=DATE(p.submitdate)) AS count
       FROM '.TABLE_PREFIX.'pireps p WHERE DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= p.submitdate';
     return DB::get_results($sql);
    }/**
     * Get all of the details for a PIREP, including lat/long of the airports
     */
    public static function getReportDetails($pirepid)
    {
     $sql = 'SELECT p.*, s.*, s.id AS scheduleid, p.route, p.route_details,
     u.pilotid, u.firstname, u.lastname, u.email, u.rank,
     dep.name as depname, dep.lat AS deplat, dep.lng AS deplng,
     arr.name as arrname, arr.lat AS arrlat, arr.lng AS arrlng,
        p.code, p.flightnum, p.depicao, p.arricao,  p.price AS price,
        a.id as aircraftid, a.name as aircraft, a.registration, p.flighttime,
        p.distance, UNIX_TIMESTAMP(p.submitdate) as submitdate, p.accepted, p.log
       FROM '.TABLE_PREFIX.'pilots u, '.TABLE_PREFIX.'pireps p
     LEFT JOIN '.TABLE_PREFIX.'airports AS dep ON dep.icao = p.depicao
     LEFT JOIN '.TABLE_PREFIX.'airports AS arr ON arr.icao = p.arricao
     LEFT JOIN '.TABLE_PREFIX.'aircraft a ON a.id = p.aircraft
     LEFT JOIN '.TABLE_PREFIX.'schedules s ON s.code = p.code AND s.flightnum = p.flightnum
       WHERE p.pilotid=u.pilotid AND p.pirepid='.$pirepid;
     $row = DB::get_row($sql);
     $row->rawdata = unserialize($row->rawdata);
    
     /* Do any specific replacements here */
     if($row)
     {
      /* If it's FSFlightKeeper, process the `rawdata` column, which contains
       array()'d copied of extra data that was sent by the ACARS. Run that
       through some templates which we've got. This can probably be generic-ized
       but it's fine now for FSFK. This can probably move through an outside
       function, but seems OK to stay in getReportDetails() for now, since this
       is semi-intensive code here (the most expensive is populating the templates,
       and I wouldn't want to run it for EVERY PIREP which is called by the system.
      */
      if($row->source == 'fsfk')
      {
       /* Do data stuff in the logs */
       $data = $row->rawdata;
    
       /* Process flight data */
       if(isset($data['FLIGHTDATA']))
       {
     Template::Set('data', $data['FLIGHTDATA']);
     $flightdata = Template::Get('fsfk_log_flightdata.tpl', true, true, true);
     $row->log.=$flightdata;
     unset($flightdata);
       }
    
       /* Process the flightplan */
       if(isset($data['FLIGHTPLAN']))
       {
     $value = trim($data['FLIGHTPLAN']);
     $lines = explode("\n", $value);
    
     Template::Set('lines', $lines);
     $flightplan = Template::Get('fsfk_log_flightplan.tpl', true, true, true);
    
     $row->log.=$flightplan;
     unset($flightplan);
       }
    
       /* Process flight critique data */
       if(isset($data['FLIGHTCRITIQUE']))
       {
     $value = $data['FLIGHTCRITIQUE'];
     $value = trim($value);
     preg_match_all("/(.*) \| (.*)\n/", $value, $matches);
    
     # Get these from a template
     Template::Set('matches', $matches);
     $critique = Template::Get('fsfk_log_flightcritique.tpl', true, true, true);
    
     $row->log.=$critique;
     unset($critique);
       }
    
       /* Process the flight images, last */
       if(isset($data['FLIGHTMAPS']))
       {
     Template::Set('images', $data['FLIGHTMAPS']);
     $flightimages = Template::Get('fsfk_log_flightimages.tpl', true, true, true);
     $row->log.=$flightimages;
     unset($flightimages);
       }
      } /* End "if FSFK" */
    
    
      if($row->route_details != '')
      {
       $row->route_details = unserialize($row->route_details);
      }
      else
      {
       $row->route_details = NavData::parseRoute($row);
    
       # Save it for future?
       //PIREPData::updatePIREPFields($row->pirepid, array('route_details'=>serialize($row->route_details)));
      }
    
     } /* End "if $row" */
    
     return $row;
    }/**
     * Get the latest reports for a pilot
     */
    public static function getLastReports($pilotid, $count = 1, $status='')
    {
     $sql = 'SELECT * FROM '.TABLE_PREFIX.'pireps
     WHERE pilotid='.intval($pilotid);
    
     # Check it via the status
     if($status != '')
     {
      $sql .= ' AND accepted='.$status;
     }
    
     $sql .=' ORDER BY submitdate DESC
     LIMIT '.intval($count);
     if($count == 1)
      return DB::get_row($sql);
     else
      return DB::get_results($sql);
    }/**
     * Get a pilot's reports by the status.  Use the
     * constants:
     * PIREP_PENDING, PIREP_ACCEPTED, PIREP_REJECTED, PIREP_INPROGRESS
     */
    public static function getReportsByAcceptStatus($pilotid, $accept=0)
    {
     $sql = 'SELECT *
     FROM '.TABLE_PREFIX.'pireps
     WHERE pilotid='.intval($pilotid).'
      AND accepted='.intval($accept);
     return DB::get_results($sql);
    }
    
    /**
     * Get the count of comments
     */
    
    public static function getCommentCount($pirepid)
    {
     $sql = 'SELECT COUNT(*) AS total FROM '.TABLE_PREFIX.'pirepcomments
     WHERE pirepid='.$pirepid.'
     GROUP BY pirepid';
    
     $total = DB::get_row($sql);
    
     if($total == '')
      return 0;
    
     return $total->total;
    }
    
    public static function setAllExportStatus($status)
    {
     if($status === true)
      $status = 1;
     else
      $status = 0;
    
     $sql = 'UPDATE '.TABLE_PREFIX.'pireps
       SET `exported`='.$status;
    
     $res = DB::query($sql);
    
     if(DB::errno() != 0)
     {
      return false;
     }
    
     return true;
    }
    
    public static function setExportedStatus($pirepid, $status)
    {
     if($status === true)
      $status = 1;
     else
      $status = 0;
    
     return self::editPIREPFields($pirepid, array('exported' => $status));
    }/**
     * Get all of the comments for a pilot report
     */
    public static function getComments($pirepid)
    {
     $sql = 'SELECT c.*, UNIX_TIMESTAMP(c.postdate) as postdate,
      p.firstname, p.lastname
     FROM '.TABLE_PREFIX.'pirepcomments c, '.TABLE_PREFIX.'pilots p
     WHERE p.pilotid=c.pilotid AND c.pirepid='.$pirepid.'
     ORDER BY postdate ASC';
     return DB::get_results($sql);
    }
    
    public static function deleteComment($comment_id)
    {
     $sql = 'DELETE FROM '.TABLE_PREFIX.'pirepcomments WHERE `id`='.$comment_id;
     $res = DB::query($sql);
    
     if(DB::errno() != 0)
     {
      return false;
     }
    
     return true;
    }
    
    /**
     * File a PIREP
     */
    public static function newPIREP($pirepdata)
    {
     self::fileReport($pirepdata);
    }
    
    public static function filePIREP($pirepdata)
    {
     self::fileReport($pirepdata);
    }
    
    public static function fileReport($pirepdata)
    {
    
     /*$pirepdata = array('pilotid'=>'',
       'code'=>'',
       'flightnum'=>'',
       'depicao'=>'',
       'arricao'=>'',
       'aircraft'=>'',
       'flighttime'=>'',
       'submitdate'=>'',
       'comment'=>'',
       'fuelused'=>'',
       'source'=>''
       'log'=>'');*/
    
     if(!is_array($pirepdata))
      return false;
    
     $pirepdata['code'] = strtoupper($pirepdata['code']);
     $pirepdata['flightnum'] = strtoupper($pirepdata['flightnum']);
     $pirepdata['depicao'] = strtoupper($pirepdata['depicao']);
     $pirepdata['arricao'] = strtoupper($pirepdata['arricao']);
    
     /* Check if this PIREP was just submitted, check the last 10 minutes
     */
     if(Config::Get('PIREP_CHECK_DUPLICATE') == true)
     {
      $time_limit = Config::Get('PIREP_TIME_CHECK');
      if(empty($time_limit))
      {
       $time_limit = 1;
      }
    
      $sql = "SELECT `pirepid` FROM ".TABLE_PREFIX."pireps
     WHERE `pilotid`={$pirepdata['pilotid']}
      AND `code`='{$pirepdata['code']}'
      AND `flightnum`='{$pirepdata['flightnum']}'
      AND DATE_SUB(NOW(), INTERVAL {$time_limit} MINUTE) <= `submitdate`";
    
      $res = DB::get_row($sql);
    
      if($res)
      {
       self::$lasterror = 'This PIREP was just submitted!';
       return;
      }
     }
    
     if(isset($pirepdata['log']))
     {
      $pirepdata['log'] = DB::escape($pirepdata['log']);
     }
     else
     {
      $pirepdata['log'] = '';
     }
    
     if($pirepdata['depicao'] == '' || $pirepdata['arricao'] == '')
     {
      self::$lasterror = 'The departure or arrival airports are blank';
      return false;
     }
    
     # Check the aircraft
     if(!is_numeric($pirepdata['aircraft']))
     {
      // Check by registration
      $ac = OperationsData::getAircraftByReg($pirepdata['aircraft']);
      if($ac)
      {
       $pirepdata['aircraft'] = $ac->id;
      }
      else
      {
       // Check by name
       $ac = OperationsData::getAircraftByName($pirepdata['aircraft']);
       if($ac)
       {
     $pirepdata['aircraft'] = $ac->id;
       }
      }
     }
    
     # Check the airports, add to database if they don't exist
     $depapt = OperationsData::getAirportInfo($pirepdata['depicao']);
     if(!$depapt)
     {	 
      $depapt = OperationsData::RetrieveAirportInfo($pirepdata['depicao']);
     }
    
     $arrapt = OperationsData::getAirportInfo($pirepdata['arricao']);
     if(!$arrapt)
     {
      $arrapt = OperationsData::RetrieveAirportInfo($pirepdata['arricao']);	 
     }  # Look up the schedule
     $sched = SchedulesData::getScheduleByFlight($pirepdata['code'], $pirepdata['flightnum']);
    
     /* Get route information, and also the detailed layout of the route
      Store it cached, in case the schedule changes later, then the route
      information remains intact. Also, if the nav data changes, then
      the route is saved as it was
      */
    
     if(!empty($pirepdata['route']))
     {
      /* They supplied some route information, so build up the data
       based on that. It needs a certain structure passed, so build that */
    
      $pirepdata['route'] = str_replace('SID', '', $pirepdata['route']);
      $pirepdata['route'] = str_replace('STAR', '', $pirepdata['route']);
      $pirepdata['route'] = trim($pirepdata['route']);
    
      $tmp = new stdClass();
      $tmp->deplat = $depapt->lat;
      $tmp->deplng = $depapt->lng;
      $tmp->route = $pirepdata['route'];
    
      $pirepdata['route_details'] = NavData::parseRoute($tmp);
      $pirepdata['route_details'] = serialize($pirepdata['route_details']);
      unset($tmp);
     }
    
     if(empty($pirepdata['route']) && !empty($sched->route))
     {
      $pirepdata['route'] = $sched->route;
      $pirepdata['route'] = str_replace('SID', '', $pirepdata['route']);
      $pirepdata['route'] = str_replace('STAR', '', $pirepdata['route']);
      $pirepdata['route'] = trim($pirepdata['route']);
    
      /* The schedule doesn't have any route_details, so let's populate
       the schedule while we're here. Then we'll use that same info
       to populate our details information
       */
      if(empty($sched->route_details))
      {
       $pirepdata['route_details'] = serialize(SchedulesData::getRouteDetails($sched->id));
      }
      else
      {
       /* The schedule does have route information, and it's already been cached */
       $pirepdata['route_details'] = $sched->route_details;
      }
     }
    
     $pirepdata['route'] = DB::escape($pirepdata['route']);
    
     if(!empty($pirepdata['route_details']))
     {
      $pirepdata['route_details'] = DB::escape($pirepdata['route_details']);
     }
    
     /* This setting forces the next code to automatically
      calculate a load value for this current PIREP */
     if(Config::Get('PIREP_OVERRIDE_LOAD') == true)
     {
      $pirepdata['load'] == '';
     }
    
     # Check the load, if it's blank then look it up
     # Based on the aircraft that was flown
     if(!isset($pirepdata['load']) || empty($pirepdata['load']))
     {
      $pirepdata['load'] = FinanceData::getLoadCount($pirepdata['aircraft'], $sched->flighttype);
     }
    
     /* If the distance isn't supplied, then calculate it */
     if(!isset($pirepdata['distance']) || empty($pirepdata['distance']))
     {
      $pirepdata['distance'] = OperationsData::getAirportDistance($depapt, $arrapt);
     }
    
     /* See if there's a landing rate */
     if(!isset($pirepdata['landingrate']) || empty($pirepdata['landingrate']))
     {
      $pirepdata['landingrate'] = 0;
     }
    
     /* Any "raw" parameterized data which needs to be added */
     if(isset($pirepdata['rawdata']))
     {
      $pirepdata['rawdata'] = DB::escape(serialize($pirepdata['rawdata']));
     }
     else
     {
      $pirepdata['rawdata'] = '';
     }
    
     /* Escape the comment field */
     $pirepdata['log'] = DB::escape($pirepdata['log']);
     $comment = DB::escape($pirepdata['comment']);
    
     /* Proper timestamp */
     $flighttime_stamp = str_replace('.', ':', $pirepdata['flighttime']).':00';
     $pirepdata['flighttime'] = str_replace(':', '.', $pirepdata['flighttime']);
    
     /* Export status as 0 */
     $pirepdata['exported'] = 0;
    
     $sql = "INSERT INTO ".TABLE_PREFIX."pireps(
       `pilotid`,
       `code`,
       `flightnum`,
       `depicao`,
       `arricao`,
       `route`,
       `route_details`,
       `distance`,
       `aircraft`,
       `flighttime`,
       `flighttime_stamp`,
       `landingrate`,
       `submitdate`,
       `accepted`,
       `log`,
       `load`,
       `fuelused`,
       `expenselist`,
       `source`,
       `exported`,
       `rawdata`)
     VALUES ( {$pirepdata['pilotid']},
       '{$pirepdata['code']}',
       '{$pirepdata['flightnum']}',
       '{$pirepdata['depicao']}',
       '{$pirepdata['arricao']}',
       '{$pirepdata['route']}',
       '{$pirepdata['route_details']}',
       '{$pirepdata['distance']}',
       '{$pirepdata['aircraft']}',
       '{$pirepdata['flighttime']}',
       '{$flighttime_stamp}',
       '{$pirepdata['landingrate']}',
       NOW(),
       ".PIREP_PENDING.",
       '{$pirepdata['log']}',
       '{$pirepdata['load']}',
       '{$pirepdata['fuelused']}',
       '0',
       '{$pirepdata['source']}',
       {$pirepdata['exported']},
       '{$pirepdata['rawdata']}')";
     $ret = DB::query($sql);
     $pirepid = DB::$insert_id;
    
     // Add the comment if its not blank
     if($comment != '')
     {
      self::addComment($pirepid, $pirepdata['pilotid'], $pirepdata['comment']);
     }
    
     # Update the financial information for the PIREP, true to refresh fuel
     self::PopulatePIREPFinance($pirepid, true);
    
     # Do other assorted tasks that are along with a PIREP filing
     # Update the flown count for that route
     self::UpdatePIREPFeed();
    
     # Update any pilot's information
     $pilotinfo = PilotData::getPilotData($pirepdata['pilotid']);
     $pilotcode = PilotData::getPilotCode($pilotinfo->code, $pilotinfo->pilotid);
     PilotData::UpdateLastPIREPDate($pilotinfo->pilotid);
     PirepAcData::search($pirepid);
    
     # Send an email to the admin that a PIREP was submitted
     $sub = "A PIREP has been submitted by {$pilotcode} ({$pirepdata['depicao']} - {$pirepdata['arricao']})";
     $message="A PIREP has been submitted by {$pilotcode} ({$pilotinfo->firstname} {$pilotinfo->lastname})\n\n"
       ."{$pirepdata['code']}{$pirepdata['flightnum']}: {$pirepdata['depicao']} to {$pirepdata['arricao']}\n"
       ."Aircraft: {$pirepdata['aircraft']}\n"
       ."Flight Time: {$pirepdata['flighttime']}\n"
       ."Filed using: {$pirepdata['source']}\n\n"
       ."Comment: {$pirepdata['comment']}";
    
     $email = Config::Get('EMAIL_NEW_PIREP');
     if(empty($email))
     {
      $email = ADMIN_EMAIL;
     }
    
     Util::SendEmail($email, $sub, $message);
    
     CentralData::send_pirep($pirepid);
    
     // Reset this ID back
     DB::$insert_id = $pirepid;
     self::$pirepid = $pirepid;
     return true;
    }
    
    public static function updateReport($pirepid, $pirepdata)
    {
     self::updateFlightReport($pirepid, $pirepdata);
    }
    
    public static function updatePIREP($pirepid, $pirepdata)
    {
     self::updateFlightReport($pirepid, $pirepdata);
    }
    
    public static function updateFlightReport($pirepid, $pirepdata)
    { 
     /*$pirepdata = 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(!is_array($pirepdata))
     {
      return false;
     }
    
     if($pirepdata['depicao'] == '' || $pirepdata['arricao'] == '')
     {
      return false;
     }
    
     $pirepinfo = self::getReportDetails($pirepid);
    
     $pirepdata['fuelprice'] = $pirepdata['fuelused'] * $pirepdata['fuelunitcost'];
    
     $flighttime_stamp = str_replace('.', ':', $pirepdata['flighttime']).':00';
     $pirepdata['flighttime'] = str_replace(':', ',', $pirepdata['flighttime']);
    
     $data = array(
      'price' => $pirepdata['price'],
      'load' => $pirepdata['load'],
      'expenses' => $pirepdata['expenses'],
      'fuelprice' => $pirepdata['fuelprice'],
      'pilotpay' => $pirepdata['pilotpay'],
      'flighttime' => $pirepdata['flighttime'],
     );
    
     $gross = floatval($pirepdata['load']) * floatval($pirepdata['price']);
     $revenue = self::getPIREPRevenue($data);
    
     $fields = array(
      'code' => $pirepdata['code'],
      'flightnum' => $pirepdata['flightnum'],
      'depicao' => $pirepdata['depicao'],
      'arricao' => $pirepdata['arricao'],
      'aircraft' => $pirepdata['aircraft'],
      'flighttime' => $pirepdata['flighttime'],
      'flighttime_stamp' => $flighttime_stamp,
      'load' => $pirepdata['load'],
      'price' => $pirepdata['price'],
      'gross' => $gross,
      'pilotpay' => $pirepdata['pilotpay'],
      'fuelused' => $pirepdata['fuelused'],
      'fuelunitcost' => $pirepdata['fuelunitcost'],
      'fuelprice' => $pirepdata['fuelprice'],
      'expenses' => $pirepdata['expenses'],
      'revenue' => $revenue,
     );
    
     return self::editPIREPFields($pirepid, $fields);
    }
    
    /**
     * Update any fields in a PIREP, other update functions come down to this
     *
     * @param int $pirepid ID of the PIREP to update
     * @param array $fields Array, column name as key, with values to update
     * @return bool
     *
     */
    public static function updatePIREPFields($pirepid, $fields)
    {
     return self::editPIREPFields($pirepid, $fields);
    }
    
    /**
     * Update any fields in a PIREP, other update functions come down to this
     *
     * @param int $pirepid ID of the PIREP to update
     * @param array $fields Array, column name as key, with values to update
     * @return bool
     *
     */
    public static function editPIREPFields($pirepid, $fields)
    {
     if(!is_array($fields))
     {
      return false;
     }
    
     $sql = "UPDATE `".TABLE_PREFIX."pireps` SET ";
     $sql .= DB::build_update($fields);
     $sql .= ' WHERE `pirepid`='.$pirepid;
    
     $res = DB::query($sql);
    
     if(DB::errno() != 0)
     {
      return false;
     }
    
     return true;
    }
    
    /**
     *
     * Populate PIREPS which have 0 values for the load/price, etc
     */
    
    public static function populateEmptyPIREPS()
    { 
     $sql = 'SELECT *
       FROM '.TABLE_PREFIX.'pireps ';
    
     $results = DB::get_results($sql);
    
     if(!$results)
     {
      return true;
     }
    
     foreach($results as $row)
     {
      self::PopulatePIREPFinance($row, true);
     }
    
     return true; 
    }
    
    /**
     * Populate the PIREP with the fianancial info needed
     *  Pass the PIREPID or the PIREP row
     */
    
    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;
      }
     }
    
     $data = array(
      'price' => $sched->price,
      'load' => $pirep->load,
      'fuelprice' => $pirep->fuelprice,
      'expenses' => $total_ex,
      'pilotpay' => $pilot->payrate,
      'flighttime' => $pirep->flighttime,
     );
    
     $revenue = self::getPIREPRevenue($data);
    
     /* 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,
      'revenue' => $revenue
     );
    
     if(isset($data['load']) && $data['load'] != '')
      $fields['load'] = $data['load'];
    
     return self::editPIREPFields($pirepid, $fields);
    }
    
    public static function getPIREPRevenue($data)
    {
     $gross = $data['price'] * $data['load'];
     $pilotpay = $data['pilotpay'] * $data['flighttime'];
    
     if($data['expenses'] == '')
      $data['expenses'] = 0;
    
     $revenue = $gross - $data['expenses'] - $data['fuelprice'] - $pilotpay;
    
     return $revenue;
    
    }
    
    /**
     * Delete a flight report and all of its associated data
     */
    public static function deletePIREP($pirepid)
    {
     self::deleteFlightReport($pirepid);
    }
    
    public static function deleteFlightReport($pirepid)
    {
     $pirepid = intval($pirepid);
     $pirep_details = self::getReportDetails($pirepid);
    
     $sql = 'DELETE FROM '. TABLE_PREFIX.'pireps
     WHERE pirepid='.$pirepid;
    
     DB::query($sql);
    
     # Delete any comments and fields
     $sql = 'DELETE FROM '. TABLE_PREFIX.'pirepcomments
     WHERE pirepid='.$pirepid;
    
     DB::query($sql);
    
     # Delete any custom field data
     $sql = 'DELETE FROM '. TABLE_PREFIX.'pirepvalues
     WHERE pirepid='.$pirepid;
    
     DB::query($sql);
    
     # Check if this was accepted report
     # If it was, remove it from that pilot's stats
     if($pirep_details->accepted == PIREP_ACCEPTED)
     {
      PilotData::UpdateFlightData($pirep_details->pilotid, ($pirep_details->flighttime) * -1, -1);
     }
    
     self::UpdatePIREPFeed();
    }
    
    public static function deleteAllRouteDetails()
    {
     $sql = "UPDATE ".TABLE_PREFIX."pireps
       SET `route_details` = ''";
    
     $row = DB::get_row($sql);
    
     if(!$row)
     {
      return false;
     }
    
     return true;
    }
    
    public static function UpdatePIREPFeed()
    {
     # Load PIREP into RSS feed
     $reports = PIREPData::findPIREPS(array(), 10);
     $rss = new RSSFeed('Latest Pilot Reports', SITE_URL, 'The latest pilot reports');
    
     # Empty the rss file if there are no pireps
     if(!$reports)
     {
      //file_put_contents(LIB_PATH.'/rss/latestpireps.rss', '');
      $reports = array();
      return;
     }
    
     foreach($reports as $report)
     {
      $rss->AddItem('Report #'.$report->pirepid.' - '.$report->depicao.' to '.$report->arricao,
       SITE_URL.'/admin/index.php?admin=viewpending','',
       'Filed by '.PilotData::getPilotCode($report->code, $report->pilotid)
       . " ($report->firstname $report->lastname)");
     }
    
     $rss->BuildFeed(LIB_PATH.'/rss/latestpireps.rss');
    }
    
    
    /**
     * Return true if a PIREP if under $age_hours old
     *
     * @param int $pirepid PIREP ID
     * @param int $age_hours The age in hours to see if a PIREP is under
     * @return bool True/false
     *
     */
    public static function PIREPUnderAge($pirepid, $age_hours)
    {
     $pirepid = intval($pirepid);
    
     $sql = "SELECT pirepid
       FROM ".TABLE_PREFIX."pireps
       WHERE DATE_SUB(CURDATE(), INTERVAL {$age_hours} HOUR) <= submitdate
     AND pirepid={$pirepid}";  $row = DB::get_row($sql);
    
     if(!$row)
     {
      return false;
     }
    
     return true;
    }
    
    /**
     * Append to a flight report's log
     */
    
    public static function appendToLog($pirepid, $log)
    {
     $sql = 'UPDATE '.TABLE_PREFIX.'pireps
     SET `log` = CONCAT(`log`, \''.$log.'\')
     WHERE `pirepid`='.$pirepid;
    
     $res = DB::query($sql);
    
     if(DB::errno() != 0)
      return false;
    
     return true; 
    }
    
    /**
     * Get all of the reports for a pilot. Pass the pilot id
     * The ID is their database ID number, not their airline ID number
     *
     * @deprecated Use findPIREPS() instead
     */
    public static function getAllReportsForPilot($pilotid)
    {
     return self::findPIREPS(array('p.pilotid'=>$pilotid));
    }
    
    /**
     * Change the status of a PIREP. For the status, use the
     * constants:
     * PIREP_PENDING, PIREP_ACCEPTED, PIREP_REJECTED,PIREP_INPROGRESS
     *
     * @deprecated Use editPIREPFields instead
     */
    public static function ChangePIREPStatus($pirepid, $status)
    {
     return self::editPIREPFields($pirepid, array('accepted' => $status));
    }
    /**
     * Add a comment to the flight report
     */
    public static function addComment($pirepid, $pilotid, $comment)
    {
     $comment = DB::escape($comment);
     $sql = "INSERT INTO ".TABLE_PREFIX."pirepcomments (`pirepid`, `pilotid`, `comment`, `postdate`)
     VALUES ($pirepid, $pilotid, '$comment', NOW())";  $res = DB::query($sql);
    
     if(DB::errno() != 0)
      return false;
    
     return true;
    }
    
    
    public static function getAllFields()
    {
     return DB::get_results('SELECT * FROM '.TABLE_PREFIX.'pirepfields');
    }
    
    /**
     * Get all of the "cusom fields" for a pirep
     */
    public static function getFieldData($pirepid)
    {
     $sql = 'SELECT f.title, f.name, v.value
     FROM '.TABLE_PREFIX.'pirepfields f
     LEFT JOIN '.TABLE_PREFIX.'pirepvalues v
      ON f.fieldid=v.fieldid
       AND v.pirepid='.intval($pirepid);
    
     return DB::get_results($sql);
    }
    
    public static function getFieldInfo($id)
    {
     $sql = 'SELECT * FROM '.TABLE_PREFIX.'pirepfields
     WHERE fieldid='.$id;
    
     return DB::get_row($sql);
    }
    
    public static function getFieldValue($fieldid, $pirepid)
    {
     $sql = 'SELECT * FROM '.TABLE_PREFIX.'pirepvalues
     WHERE fieldid='.$fieldid.' AND pirepid='.$pirepid;
    
     $ret = DB::get_row($sql);
     return $ret->value;
    }
    /**
     * Add a custom field to be used in a PIREP
     */
    public static function AddField($title, $type='', $values='')
    {
     $fieldname = strtoupper(str_replace(' ', '_', $title));
     //$values = DB::escape($values);
    
     if($type == '')
      $type = 'text';
    
     $sql = "INSERT INTO " . TABLE_PREFIX ."pirepfields (title, name, type, options)
     VALUES ('$title', '$fieldname', '$type', '$values')";
    
     $res = DB::query($sql);
    
     if(DB::errno() != 0)
      return false;
    
     return true;
    }
    
    /**
     * Edit the field
     */
    public static function EditField($id, $title, $type, $values='')
    {
     $fieldname = strtoupper(str_replace(' ', '_', $title));
    
     $sql = "UPDATE ".TABLE_PREFIX."pirepfields
     SET title='$title',name='$fieldname', type='$type', options='$values'
     WHERE fieldid=$id";
    
     $res = DB::query($sql);
    
     if(DB::errno() != 0)
      return false;
    
     return true;
    }
    
    /**
     * Save PIREP fields
     */
    public static function SaveFields($pirepid, $list)
    {
     if(!is_array($list) || $pirepid == '')
      return false;
    
     $allfields = self::getAllFields();
    
     if(!$allfields) return true;
    
     foreach($allfields as $field)
     {
      // See if that value already exists
      $sql = 'SELECT id FROM '.TABLE_PREFIX.'pirepvalues
      WHERE fieldid='.$field->fieldid.' AND pirepid='.$pirepid;
      $res = DB::get_row($sql);
      $fieldname =str_replace(' ', '_', $field->name);
      $value = $list[$fieldname];
    
      if($res)
      {
       $sql = 'UPDATE '.TABLE_PREFIX."pirepvalues
       SET value='$value'
       WHERE fieldid=$field->fieldid
        AND pirepid=$pirepid";
      }
      else
      { 
       $sql = "INSERT INTO ".TABLE_PREFIX."pirepvalues
      (fieldid, pirepid, value)
      VALUES ($field->fieldid, $pirepid, '$value')";
      }
    
      DB::query($sql);
     }
    
     return true;
    }
    
    public static function DeleteField($id)
    {
     $sql = 'DELETE FROM '.TABLE_PREFIX.'pirepfields WHERE fieldid='.$id;  $res = DB::query($sql);
    
     if(DB::errno() != 0)
      return false;
    
     return true;
     //TODO: delete all of the field values!
     //$sql = 'DELETE FROM '.TABLE_PREFIX.'
    }
    /**
     * Show the graph of the past week's reports. Outputs the
     * image unless $ret == true
     *
     * @deprecated
     */
    public static function ShowReportCounts($ret=false)
    {
     // Recent PIREP #'s
     $max = 0;
     $data = array();
    
     # Get the past 7 days
     $time_start = strtotime('-7 days');
     $time_end = date('Ymd');
    
     do {
      $count = PIREPData::getReportCount($time_start);
      $data[date('m/d', $time_start)] = $count;
    
      $time_start += SECONDS_PER_DAY;
      $check = date('Ymd', $time_start);
     } while ($check <= $time_end);
    
     return $data;
    }
    }
    

  5. The code would almost it!

    Only instead to add the values, I want an average.

    Ex:

    Starts counting at 100%

    Value 0 (Approval Pending): Does not diminish the count.

    Value 1 (Approval Accepted): Increase count 1% up to the maximum value of 100%

    Value 2 (Approval Rejected): Decrease the count in 5%

    <?PHP	 $somar = mysql_query("SELECT SUM(accepted) as accepted FROM `phpvms_pireps` WHERE pilotid=$userinfo->pilotid");
    						 $total = mysql_fetch_array($somar);
    						 $v_total = $total['accepted'];
    						 $linha = mysql_query("SELECT * FROM `phpvms_pireps` WHERE pilotid=$userinfo->pilotid");
    						 $taxa = mysql_num_rows($linha);
    						 $v_taxa = $taxa;
    						 ?>
    						 <?php echo $taxa."%"; ?>
    

    This item will be shown in profile main.tpl

  6. How to make a FOQA system, eg if the pilot makes 10 legs and 5 is regeitada, so it will have a score of 50%.

    Based on this code:

    <? Php
    
    $ Add = mysql_query ("SELECT SUM (landingrate) the landingrate FROM` phpvms_pireps` WHERE pilotid = $ userinfo-> pilotid ");
    $ Total = mysql_fetch_array ($ total);
    $ V_total = Total $ [ 'landingrate'];
    $ Line = mysql_query ("SELECT * FROM` phpvms_pireps` WHERE pilotid = $ userinfo-> pilotid ");
    $ Rate = mysql_num_rows ($ line);
    $ V_taxa = $ rate;
    if ($ v_taxa <= 0)
    {$ V_media = 0; } Else {$ media = $ v_total / $ v_taxa; $ V_media = number_format ($ average, 0, '' '.'); }
    ?>
    <? Php echo $ v_media "%"?.; ?>
    

  7. Here's the problem: use the tool

    random flights until there all ok. after the pilot generate the scale, how to restrict flights by day operation.

    Example: The only pilot will be able to fly the leg that is in scale if it operate in espesifico day.

    I think I should make an alteration within the module Acars

    <?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 Jeffrey Kobus
    * @copyright Copyright (c) 2010, Jeffrey Kobus
    * @link http://www.fs-products.net
    * @license http://creativecommons.org/licenses/by-nc-sa/3.0/
    * @ v1.0.1.1
    */
    
    class kACARS_Free extends CodonModule
    {
    
    public function index()
    {
    if($_SERVER['REQUEST_METHOD'] === 'POST')
    {
    
    // Site Settings
    $logTime = 0;	 // kACARS_Free FlightLog Timesatmp 0=System Time or 1=FS Time
    $logPause = 0; // kACARS_Free Pause Log 0=Log Pauses or 1=Do NOT Log Pauses
    $version = '1.0.1.1'; // kACARS_Free Version
    $forceOut = 1;		 // Force disconnect is wrong version 0=no 1=yes
    $charter = 1; // Allow Charter flights to be flown (Includes abilty to change aircraft) 0=no 1=yes
    
    
    $postText = file_get_contents('php://input');
    $encoding = mb_detect_encoding($postText);
    $rec_xml = trim(iconv($encoding, "UTF-8", $postText));
    $xml = simplexml_load_string($rec_xml);
    
    if(!$xml)
    {
    #$this->log("Invalid XML Sent: \n".$rec_xml, 'kacars');
    echo "not xml";
    return;
    }
    
    #$this->log(print_r($xml->asXML(), true), 'kacars');
    
    $case = strtolower($xml->switch->data);
    switch($case)
    {
    case 'verify':
     $results = Auth::ProcessLogin($xml->verify->pilotID, $xml->verify->password);
     if ($results)
     {	
     $params = array('loginStatus' => '1');
     }
     else
     {
     $params = array('loginStatus' => '0');
     }
    
     // Send Site Settings
     $params['logTimeSetting'] = $logTime;
     $params['logPauseSetting'] = $logPause;
     $params['version'] = $version;
     $params['forceOut'] = $forceOut;
     $params['charter'] = $charter;
    
     $send = self::sendXML($params);
    
     break;
    
    case 'getbid':	
    
     $pilotid = PilotData::parsePilotID($xml->verify->pilotID);
     $pilotinfo = PilotData::getPilotData($pilotid);
     $biddata = SchedulesData::getLatestBid($pilotid);
    [b]	 $data = SchedulesData::getScheduleFlownCounts($xml->verify->$bid->daysofweek);	[/b]
     $aircraftinfo = OperationsData::getAircraftByReg($biddata->registration);
    
     if(count($biddata) == 1)
     {
     if($aircraftinfo->enabled == 1)
     {
     $params = array(
     'flightStatus'	 => '1',
     'flightNumber'	 => $biddata->code.$biddata->flightnum,
     'aircraftReg'	 => $biddata->registration,
     'aircraftICAO'	 => $aircraftinfo->icao,
     'aircraftFullName' => $aircraftinfo->fullname,
     'flightLevel'	 => $biddata->flightlevel,
     'aircraftMaxPax' => $aircraftinfo->maxpax,
     'aircraftCargo' => $aircraftinfo->maxcargo,
     'depICAO'		 => $biddata->depicao,
     'arrICAO'		 => $biddata->arricao,
     'route'		 => $biddata->route,
     'depTime'		 => $biddata->deptime,
     'arrTime'		 => $biddata->arrtime,
     'flightTime'	 => $biddata->flighttime,
     'flightType'	 => $biddata->flighttype,
     'aircraftName'	 => $aircraftinfo->name,
     'aircraftRange' => $aircraftinfo->range,
     'aircraftWeight' => $aircraftinfo->weight,
     'aircraftCruise' => $aircraftinfo->cruise
     );	
     }
     else
     {
     $params = array(
     'flightStatus'	 => '3'); // Aircraft Out of Service.	
     }
     }
     else
     {
     $params = array('flightStatus' => '2'); // You have no bids!	
     }
    
     $send = $this->sendXML($params);
    
     break;
    
    case 'getflight':
    
     $flightinfo = SchedulesData::getProperFlightNum($xml->pirep->flightNumber);
    
     $params = array(
     's.code' => $flightinfo['code'],
     's.flightnum' => $flightinfo['flightnum'],
     's.enabled' => 1,
     );
    
     $biddata = SchedulesData::findSchedules($params, 1);
     $aircraftinfo = OperationsData::getAircraftByReg($biddata[0]->registration);
    
     if(count($biddata) == 1)
     {
     $params = array(
     'flightStatus'	 => '1',
     'flightNumber'	 => $biddata[0]->code.$biddata[0]->flightnum,
     'aircraftReg'	 => $biddata[0]->registration,
     'aircraftICAO'	 => $aircraftinfo->icao,
     'aircraftFullName' => $aircraftinfo->fullname,
     'flightLevel'	 => $biddata[0]->flightlevel,
     'aircraftMaxPax' => $aircraftinfo->maxpax,
     'aircraftCargo' => $aircraftinfo->maxcargo,
     'depICAO'		 => $biddata[0]->depicao,
     'arrICAO'		 => $biddata[0]->arricao,
     'route'		 => $biddata[0]->route,
     'depTime'		 => $biddata[0]->deptime,
     'arrTime'		 => $biddata[0]->arrtime,
     'flightTime'	 => $biddata[0]->flighttime,
     'flightType'	 => $biddata[0]->flighttype,
     'aircraftName'	 => $aircraftinfo->name,
     'aircraftRange' => $aircraftinfo->range,
     'aircraftWeight' => $aircraftinfo->weight,
     'aircraftCruise' => $aircraftinfo->cruise
     );
     }
     else
     {
     $params = array('flightStatus'	 => '2');	
     }
    
     $send = $this->sendXML($params);
     break;
    
    case 'liveupdate':
    
     $pilotid = PilotData::parsePilotID($xml->verify->pilotID);
     $lat = str_replace(",", ".", $xml->liveupdate->latitude);
     $lon = str_replace(",", ".", $xml->liveupdate->longitude);
    
     # Get the distance remaining
     $depapt = OperationsData::GetAirportInfo($xml->liveupdate->depICAO);
     $arrapt = OperationsData::GetAirportInfo($xml->liveupdate->arrICAO);
     $dist_remain = round(SchedulesData::distanceBetweenPoints(
     $lat, $lon, $arrapt->lat, $arrapt->lng));
    
     # Estimate the time remaining
     if($xml->liveupdate->groundSpeed > 0)
     {
     $Minutes = round($dist_remain / $xml->liveupdate->groundSpeed * 60);
     $time_remain = self::ConvertMinutes2Hours($Minutes);
     }
     else
     {
     $time_remain = '00:00';
     }	
    
     $fields = array(
     'pilotid'	 =>$pilotid,
     'flightnum'	 =>$xml->liveupdate->flightNumber,
     'pilotname'	 =>'',
     'aircraft'	 =>$xml->liveupdate->registration,
     'lat'		 =>$lat,
     'lng'		 =>$lon,
     'heading'	 =>$xml->liveupdate->heading,
     'alt'		 =>$xml->liveupdate->altitude,
     'gs'			 =>$xml->liveupdate->groundSpeed,
     'depicao'	 =>$xml->liveupdate->depICAO,
     'arricao'	 =>$xml->liveupdate->arrICAO,
     'deptime'	 =>$xml->liveupdate->depTime,
     'arrtime'	 =>'',
     'route'		 =>$xml->liveupdate->route,
     'distremain'	 =>$dist_remain,
     'timeremaining' =>$time_remain,
     'phasedetail' =>$xml->liveupdate->status,
     'online'		 =>'',
     'client'		 =>'kACARS',
     );
    
     #$this->log("UpdateFlightData: \n".print_r($fields, true), 'kacars');
     ACARSData::UpdateFlightData($pilotid, $fields);
    
     break;
    
    case 'pirep':	
    
     $flightinfo = SchedulesData::getProperFlightNum($xml->pirep->flightNumber);
     $code = $flightinfo['code'];
     $flightnum = $flightinfo['flightnum'];
    
     $pilotid = PilotData::parsePilotID($xml->verify->pilotID);
    
     # Make sure airports exist:
     # If not, add them.
    
     if(!OperationsData::GetAirportInfo($xml->pirep->depICAO))
     {
     OperationsData::RetrieveAirportInfo($xml->pirep->depICAO);
     }
    
     if(!OperationsData::GetAirportInfo($xml->pirep->arrICAO))
     {
     OperationsData::RetrieveAirportInfo($xml->pirep->arrICAO);
     }
    
     # Get aircraft information
     $reg = trim($xml->pirep->registration);
     $ac = OperationsData::GetAircraftByReg($reg);
    
     # Load info
     /* If no passengers set, then set it to the cargo */
     $load = $xml->pirep->pax;
     if(empty($load))
     $load = $xml->pirep->cargo;	
    
     /* Fuel conversion - kAcars only reports in lbs */
     $fuelused = $xml->pirep->fuelUsed;
     if(Config::Get('LiquidUnit') == '0')
     {
     # Convert to KGs, divide by density since d = mass * volume
     $fuelused = ($fuelused * .45359237) / .8075;
     }
     # Convert lbs to gallons
     elseif(Config::Get('LiquidUnit') == '1')
     {
     $fuelused = $fuelused / 6.84;
     }
     # Convert lbs to kgs
     elseif(Config::Get('LiquidUnit') == '2')
     {
     $fuelused = $fuelused * .45359237;
     }	
    
     $data = array(
     'pilotid' =>$pilotid,
     'code' =>$code,
     'flightnum' =>$flightnum,
     'depicao' =>$xml->pirep->depICAO,
     'arricao' =>$xml->pirep->arrICAO,
     'aircraft' =>$ac->id,
     'flighttime' =>$xml->pirep->flightTime,
     'flighttype' =>$xml->pirep->flightType,
     'submitdate' =>'UTC_TIMESTAMP()',
     'comment' =>$xml->pirep->comments,
     'fuelused' =>$fuelused,
     'route'		 =>$xml->liveupdate->route,
     'source' =>'kACARS',
     'load' =>$load,
     'landingrate' =>$xml->pirep->landing,
     'log' =>$xml->pirep->log
     );
    
     #$this->log("File PIREP: \n".print_r($data, true), 'kacars');
     $ret = ACARSData::FilePIREP($pilotid, $data);
    
     if ($ret)
     {
     $params = array(
     'pirepStatus'	 => '1'); // Pirep Filed!	
     }
     else
     {
     $params = array(
     'pirepStatus'	 => '2'); // Please Try Again!	
    
     }
     $send = $this->sendXML($params);	
    
     break;
    
    case 'aircraft':
    
     $this->getAllAircraft();
     break;
    
    case 'aircraftinfo':
    
     $aircraftinfo = OperationsData::getAircraftByReg($xml->pirep->registration);
    
    
     $params = array(	
     'aircraftReg'	 => $aircraftinfo->registration,
     'aircraftICAO'	 => $aircraftinfo->icao,
     'aircraftFullName' => $aircraftinfo->fullname,	
     'aircraftMaxPax' => $aircraftinfo->maxpax,
     'aircraftCargo' => $aircraftinfo->maxcargo,	
     'aircraftName'	 => $aircraftinfo->name,
     'aircraftRange' => $aircraftinfo->range,
     'aircraftWeight' => $aircraftinfo->weight,
     'aircraftCruise' => $aircraftinfo->cruise
     );
    
     $send = $this->sendXML($params);
     break;
    }
    
    }
    }
    
    public function ConvertMinutes2Hours($Minutes)
    {
    if ($Minutes < 0)
    {
    $Min = Abs($Minutes);
    }
    else
    {
    $Min = $Minutes;
    }
    $iHours = Floor($Min / 60);
    $Minutes = ($Min - ($iHours * 60)) / 100;
    $tHours = $iHours + $Minutes;
    if ($Minutes < 0)
    {
    $tHours = $tHours * (-1);
    }
    $aHours = explode(".", $tHours);
    $iHours = $aHours[0];
    if (empty($aHours[1]))
    {
    $aHours[1] = "00";
    }
    $Minutes = $aHours[1];
    if (strlen($Minutes) < 2)
    {
    $Minutes = $Minutes ."0";
    }
    $tHours = $iHours .":". $Minutes;
    return $tHours;
    }
    
    public function sendXML($params)
    {
    $xml = new SimpleXMLElement("<sitedata />");
    
    $info_xml = $xml->addChild('info');
    foreach($params as $name => $value)
    {
    $info_xml->addChild($name, $value);
    }
    
    header('Content-type: text/xml');
    $xml_string = $xml->asXML();
    echo $xml_string;
    
    # For debug
    #$this->log("Sending: \n".print_r($xml_string, true), 'kacars');
    
    return;
    }
    
    public function getAllAircraft()
    {
    $results = OperationsData::getAllAircraft(true);
    
    $xml = new SimpleXMLElement("<aircraftdata />");
    
    $info_xml = $xml->addChild('info');
    
    foreach($results as $row)
    {
    $info_xml->addChild('aircraftICAO', $row->icao);
    $info_xml->addChild('aircraftReg', $row->registration);
    }
    
    # For debug
    #$this->log("Sending: \n".print_r($xml_string, true), 'kacars');
    
    header('Content-type: text/xml');
    echo $xml->asXML();
    }
    }
    

    This is my "kACARS_Free.php" The part in bold and the issue I'm trying to do!

    $data = SchedulesData::getScheduleFlownCounts($xml->verify->$bid->daysofweek);

  8. You can run the script: https://github.com/nabeelio/phpvms_navdata

    And simple just follow the tutorial:

    Running the script

    ----------------

    On the command line, to set the permissions:

    chmod +x ./importdata

    Then run it:

    ./importdata

    That will write the temporary nav to the phpvms_navdata table, and then

    create a dump of the navdata.sql file as well. You should be set then

    However, this procedure should be done in linux terminal, used the ubunutu 16.04 ... And the file "db.php" must properly connected to your database.

    Forgiveness for my bad English.

  9. The function is working, however is showing the following error: Fatal error: Call to undefined method TemplateSet::render() in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\dov\lib\skins\EXC\layout.php on line 5

    This is the code:

    <?php

    if(!Auth::LoggedIn())

    {

    $this->set('message', 'You must be logged in to access this feature!');

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

    return;

    }

    ?>

    <!DOCTYPE html>

    <html lang="en">

    <head>

    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">

    <meta name="description" content="">

    <meta name="author" content="Mosaddek">

    <meta name="keyword" content="slick, flat, dashboard, bootstrap, admin, template, theme, responsive, fluid, retina">

    <link rel="shortcut icon" href="javascript:;" type="image/png">

    <title><?php echo $page_title; ?></title>

    <?php echo $page_htmlhead; ?>

    <link href="<?php echo SITE_URL?>/lib/skins/EXC/css/slidebars.css" rel="stylesheet">

    <link href="<?php echo SITE_URL?>/lib/skins/EXC/js/switchery/switchery.min.css" rel="stylesheet" type="text/css" media="screen" />

    <link href="<?php echo SITE_URL?>/lib/skins/EXC/css/style.css" rel="stylesheet">

    <link href="<?php echo SITE_URL?>/lib/skins/EXC/css/style-responsive.css" rel="stylesheet">

    <script src="<?php echo SITE_URL?>/lib/skins/EXC/js/html5shiv.js"></script>

    <script src="<?php echo SITE_URL?>/lib/skins/EXC/js/respond.min.js"></script>

    </head>

    <?php echo $page_htmlreq; ?>

    <body class="sticky-header">

    <section>

    <div class="sidebar-left">

    <div class="logo dark-logo-bg visible-xs-* visible-sm-*">

    <a href="<?php echo SITE_URL?>/lib/skins/EXC/index.html">

    <img src="<?php echo SITE_URL?>/lib/skins/EXC/img/logo-icon.png" alt="">

    <span class="brand-name">SlickLab</span>

    </a>

    </div>

    <div class="sidebar-left-info">

    <div class=" search-field"> </div>

    <ul class="nav nav-pills nav-stacked side-navigation">

    <li>

    <h3 class="navigation-title">Navigation</h3>

    </li>

    <li><a href="<?php echo url('/profile'); ?>"><i class="fa fa-home"></i> <span>Home</span></a></li>

    <li class="menu-list">

    <a href="<?php echo SITE_URL?>/lib/skins/EXC/"><i class="fa fa-laptop"></i> <span>Layouts</span></a>

    <ul class="child-list">

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/boxed-layout.html"> Boxed Page</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/collapsed-menu.html"> Sidebar Collapsed</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/blank-page.html"> Blank page</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/different-theme-layouts.html"> Different Theme Layouts</a></li>

    </ul>

    </li>

    <li class="menu-list"><a href="<?php echo SITE_URL?>/lib/skins/EXC/"><i class="fa fa-book"></i> <span>UI Elements</span></a>

    <ul class="child-list">

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/general.html"> BS Elements</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/buttons.html"> Buttons</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/toastr.html"> Toaster Notification</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/widgets.html"> Widgets</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/ion-slider.html"> Ion Slider</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/tree.html"> Tree View</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/nestable.html"> Nestable</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/fontawesome.html"> Fontawesome</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/line-icon.html"> Line Icon</a></li>

    </ul>

    </li>

    <li>

    <h3 class="navigation-title">Components</h3>

    </li>

    <li class="menu-list nav-active"><a href="<?php echo SITE_URL?>/lib/skins/EXC/"><i class="fa fa-cogs"></i> <span>Components <span class="badge noti-arrow bg-success pull-right">3</span> </span></a>

    <ul class="child-list">

    <li class="active"><a href="<?php echo SITE_URL?>/lib/skins/EXC/grid.html"> Grids</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/calendar.html"> Calendar</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/timeline.html"> Timeline </a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/gallery.html"> Gallery </a></li>

    </ul>

    </li>

    <li class="menu-list"><a href="javascript:;"><i class="fa fa-th-list"></i> <span>Data Tables</span></a>

    <ul class="child-list">

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/table-static.html"> Basic Table</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/table-dynamic.html"> Advanced Table</a></li>

    </ul>

    </li>

    <li class="menu-list"><a href="<?php echo SITE_URL?>/lib/skins/EXC/"><i class="fa fa-tasks"></i> <span>Forms</span></a>

    <ul class="child-list">

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/form-layout.html"> Form Layouts</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/advanced-components.html"> Advanced Components</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/form-wizard.html"> Form Wizards</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/form-validation.html"> Form Validation</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/form-editor.html"> Editors</a></li>

    </ul>

    </li>

    <li class="menu-list"><a href="<?php echo SITE_URL?>/lib/skins/EXC/"><i class="fa fa-bar-chart-o"></i> <span>Charts </span></a>

    <ul class="child-list">

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/flot-chart.html"> Flot Charts</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/morris-chart.html"> Morris Charts</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/chartjs.html"> Chartjs</a></li>

    </ul>

    </li>

    <li>

    <h3 class="navigation-title">Extra</h3>

    </li>

    <li class="menu-list"><a href="javascript:;"><i class="fa fa-envelope-o"></i> <span>Email <span class="label noti-arrow bg-danger pull-right">4 Unread</span> </span></a>

    <ul class="child-list">

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/inbox.html"> Inbox</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/inbox-details.html"> View Mail</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/inbox-compose.html"> Compose Mail</a></li>

    </ul>

    </li>

    <li class="menu-list"><a href="javascript:;"><i class="fa fa-map-marker"></i> <span>Maps</span></a>

    <ul class="child-list">

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/google-map.html"> Google Map</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/vector-map.html"> Vector Map</a></li>

    </ul>

    </li>

    <li class="menu-list"><a href="<?php echo SITE_URL?>/lib/skins/EXC/"><i class="fa fa-file-text"></i> <span>Extra Pages</span></a>

    <ul class="child-list">

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/profile.html"> Profile</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/invoice.html"> Invoice</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/login.html"> Login </a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/registration.html"> Registration </a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/lock.html"> Lock Screen </a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/404.html"> 404 Error</a></li>

    <li><a href="<?php echo SITE_URL?>/lib/skins/EXC/500.html"> 500 Error</a></li>

    </ul>

    </li>

    </ul>

    </div>

    </div>

    <div class="body-content" style="min-height: 1100px;">

    <div class="header-section">

    <div class="logo dark-logo-bg hidden-xs hidden-sm">

    <a href="<?php echo SITE_URL?>/lib/skins/EXC/index.html">

    <img src="<?php echo SITE_URL?>/lib/skins/EXC/img/logo-icon.png" alt="">

    <span class="brand-name">SlickLab</span>

    </a>

    </div>

    <div class="icon-logo dark-logo-bg hidden-xs hidden-sm">

    <a href="<?php echo SITE_URL?>/lib/skins/EXC/index.html">

    <img src="<?php echo SITE_URL?>/lib/skins/EXC/img/logo-icon.png" alt="">

    </a>

    </div>

    <a class="toggle-btn"><i class="fa fa-outdent"></i></a>

    <div id="navbar-collapse-1" class="navbar-collapse collapse yamm mega-menu">

    <ul class="nav navbar-nav">

    <li class="dropdown"><a href="javascript:;" data-toggle="dropdown" class="dropdown-toggle"> Português <b

    class=" fa fa-angle-down"></b></a>

    <ul role="menu" class="dropdown-menu language-switch">

    <li>

    <a tabindex="-1" href="javascript:;"><span> English </span><img src="<?php echo SITE_URL?>/lib/skins/EXC/img/flags/usa_flag.jpg" alt=""/></a>

    </li>

    <li>

    <a tabindex="-1" href="javascript:;"><span> Espanhol </span> <img src="<?php echo SITE_URL?>/lib/skins/EXC/img/flags/spain_flag.jpg" alt=""/></a>

    </li>

    </ul>

    </li>

    </ul>

    </div>

    <div class="notification-wrap">

    <div class="left-notification">

    <ul class="notification-menu">

    <li>

    <a href="javascript:;" class="btn btn-default dropdown-toggle info-number" data-toggle="dropdown">

    <i class="fa fa-bell-o"></i>

    <span class="badge bg-warning">4</span>

    </a>

    <div class="dropdown-menu dropdown-title ">

    <div class="title-row">

    <h5 class="title yellow">

    You have 4 New Notification

    </h5>

    <a href="javascript:;" class="btn-warning btn-view-all">View all</a>

    </div>

    <div class="notification-list-scroll sidebar">

    <div class="notification-list mail-list not-list">

    <a href="javascript:;" class="single-mail">

    <span class="icon bg-primary">

    <i class="fa fa-envelope-o"></i>

    </span>

    <strong>New User Registration</strong>

    <p>

    <small>Just Now</small>

    </p>

    <span class="un-read tooltips" data-original-title="Mark as Read" data-toggle="tooltip" data-placement="left">

    <i class="fa fa-circle"></i>

    </span>

    </a>

    <a href="javascript:;" class="single-mail">

    <span class="icon bg-success">

    <i class="fa fa-comments-o"></i>

    </span>

    <strong> Private message Send</strong>

    <p>

    <small>30 Mins Ago</small>

    </p>

    <span class="un-read tooltips" data-original-title="Mark as Read" data-toggle="tooltip" data-placement="left">

    <i class="fa fa-circle"></i>

    </span>

    </a>

    <a href="javascript:;" class="single-mail">

    <span class="icon bg-warning">

    <i class="fa fa-warning"></i>

    </span> Application Error

    <p>

    <small> 2 Days Ago</small>

    </p>

    <span class="read tooltips" data-original-title="Mark as Unread" data-toggle="tooltip" data-placement="left">

    <i class="fa fa-circle-o"></i>

    </span>

    </a>

    <a href="javascript:;" class="single-mail">

    <span class="icon bg-dark">

    <i class="fa fa-database"></i>

    </span> Database Overloaded 24%

    <p>

    <small>1 Week Ago</small>

    </p>

    <span class="read tooltips" data-original-title="Mark as Unread" data-toggle="tooltip" data-placement="left">

    <i class="fa fa-circle-o"></i>

    </span>

    </a>

    <a href="javascript:;" class="single-mail">

    <span class="icon bg-danger">

    <i class="fa fa-warning"></i>

    </span>

    <strong>Server Failed Notification</strong>

    <p>

    <small>10 Days Ago</small>

    </p>

    <span class="un-read tooltips" data-original-title="Mark as Read" data-toggle="tooltip" data-placement="left">

    <i class="fa fa-circle"></i>

    </span>

    </a>

    </div>

    </div>

    </div>

    </li>

    </ul>

    </div>

    <div class="right-notification">

    <ul class="notification-menu">

    <li>

    <a href="javascript:;" class="btn btn-default dropdown-toggle" data-toggle="dropdown">

    <img src="<?php echo PilotData::getPilotAvatar($pilotid);?>" alt=""><?php echo $pilot->firstname . ' ' . $pilot->lastname; ?>

    <span class=" fa fa-angle-down"></span>

    </a>

    <ul class="dropdown-menu dropdown-usermenu purple pull-right">

    <li><a href="<?php echo url('/profile'); ?>"> Perfil</a></li>

    <li>

    <a href="<?php echo url('/profile/editprofile'); ?>">

    <span> Configuração</span>

    </a>

    </li>

    <li>

    <a href="<?php echo url('/profile/changepassword'); ?>">

    <span> Mudar Senha</span>

    </a>

    </li>

    <li>

    <a href="#">

    <span class="label bg-info pull-right"> New</span> Regulamento</a>

    </li>

    <li><a href="<?php echo url('/logout'); ?>"><i class="fa fa-sign-out pull-right"></i> Sair</a></li>

    </ul>

    </li>

    </ul>

    </div>

    </div>

    </div>

    <div class="page-head">

    <h3>

    <?php echo $page_title; ?>

    </h3>

    </div>

    <div class="wrapper">

    <div class="row">

    <div class="col-lg-12">

    <section class="panel">

    <div class="panel-body"><?php echo $page_content;?></div>

    </section>

    </div>

    </div>

    </div>

    <footer>

    2016 © <a href="http://www.phpvms.net" target="_blank">powered by phpVMS</a>

    </footer>

    </div>

    </section>

    <script src="<?php echo SITE_URL?>/lib/skins/EXC/js/jquery-1.10.2.min.js"></script>

    <script src="<?php echo SITE_URL?>/lib/skins/EXC/js/jquery-migrate.js"></script>

    <script src="<?php echo SITE_URL?>/lib/skins/EXC/js/bootstrap.min.js"></script>

    <script src="<?php echo SITE_URL?>/lib/skins/EXC/js/modernizr.min.js"></script>

    <script src="<?php echo SITE_URL?>/lib/skins/EXC/js/jquery.nicescroll.js" type="text/javascript"></script>

    <script src="<?php echo SITE_URL?>/lib/skins/EXC/js/slidebars.min.js"></script>

    <script src="<?php echo SITE_URL?>/lib/skins/EXC/js/switchery/switchery.min.js"></script>

    <script src="<?php echo SITE_URL?>/lib/skins/EXC/js/switchery/switchery-init.js"></script>

    <script src="<?php echo SITE_URL?>/lib/skins/EXC/js/sparkline/jquery.sparkline.js"></script>

    <script src="<?php echo SITE_URL?>/lib/skins/EXC/js/sparkline/sparkline-init.js"></script>

    <script src="<?php echo SITE_URL?>/lib/skins/EXC/js/scripts.js"></script>

    </body>

    </html>

  10. Estou com uma duvida e nao sei oque fazer.

    Eis a questao:

    Na pasta "A": Fica o "PHPVMS" e o tema principal do site.

    Na pasta "B": Uma réplica do "PHPVMS" sem a parte "ADMIN" que se conecta na mesma "DB" da pasta "A"

    a pasta "A" fica o tema do despacho operacional.

    Como fazer para restringir o acesso da pasta "B" para apenas pilotos cadastrados.

    I have a doubt and do not know what to do.

    That is the question:

    In the "A" folder: It is the "PHPVMS" and the main theme of the site.

    In the "B" folder: A replica of the "PHPVMS" no part "ADMIN" that plugs into the same "DB" of the "A" folder

    the folder "A" is the theme of the operational order.

    How to restrict access to the "B" folder to only registered pilots.

    Exemplo/Example:

    http://sulcargovirtual.net/

    http://sulcargovirtual.net/index.php/login?p=login

  11. good job, a question where is the login folder is placed? Thanks for your attention

    Where does the login folder go?

    BR

    Caros amigos, a pasta de login deve ser colocado dentro da pasta raiz do phpvms, ou seja na pasta principal onde fica localizado os aquivos action.php, index.php, entre outras.

    Exemplo: O diretório ficara "WWW/phpvms/login".

    ATENÇÃO: ANTES DE FAZER ESTA OPERAÇÃO TIRE COPIA DE SUA PASTA RAIZ PARA EVITAR EVENTUAIS PERDAS.

    EN

    Dear friends, the login folder should be placed in the root folder of phpvms, that is the main folder where is located the action.php files on it, index.php, among others.

    Example: The directory had been "WWW / phpvms / login".

    WARNING: BEFORE MAKING THIS COPY OF YOUR TAKE ROOT FOLDER OPERATION TO AVOID ANY LOSS.

×
×
  • Create New...