コード例 #1
0
ファイル: Dashboard.php プロジェクト: phpmods/phpvms_5.5.x
 public function index()
 {
     /* Dashboard.tpl calls the functions below
      */
     $this->CheckForUpdates();
     CentralData::send_vastats();
     $this->set('unexported_count', count(PIREPData::getReportsByExportStatus(false)));
     $this->render('dashboard.php');
 }
コード例 #2
0
ファイル: VACentral.php プロジェクト: deanstalker/phpVMS
 public function sendpireps()
 {
     echo '<h3>Sending all PIREPS</h3>';
     $within_timelimit = CronData::check_hoursdiff('update_pireps', CentralData::$limits['update_pireps']);
     if ($within_timelimit == true) {
         echo '<p>You can only export PIREPs every ' . CentralData::$limits['update_pireps'] . ' hours</p>';
         return false;
     }
     $ret = CentralData::send_all_pireps();
     $this->parse_response($ret);
     LogData::addLog(Auth::$userinfo->pilotid, 'vaCentral - PIREPS sent');
 }
コード例 #3
0
    /**
     * This updates the ACARS live data for a pilot
     *
     * @param mixed $data This is the data structure with flight properties
     * @return mixed Nothing
     *
     */
    public static function updateFlightData($pilotid, $data)
    {
        if (!is_array($data)) {
            self::$lasterror = 'Data not array';
            return false;
        }
        if (isset($data['code']) && isset($data['flightnum'])) {
            $data['flightnum'] = $data['code'] . $data['flightnum'];
        }
        // Add pilot info
        $pilotinfo = PilotData::getPilotData($pilotid);
        $data['pilotid'] = $pilotid;
        $data['pilotname'] = $pilotinfo->firstname . ' ' . $pilotinfo->lastname;
        // Store for later
        if (isset($data['registration'])) {
            $ac_registration = $data['registration'];
            unset($data['registration']);
        }
        if (isset($data['depicao'])) {
            $dep_apt = OperationsData::GetAirportInfo($data['depicao']);
            $data['depapt'] = DB::escape($dep_apt->name);
        }
        if (isset($data['arricao'])) {
            $arr_apt = OperationsData::GetAirportInfo($data['arricao']);
            $data['arrapt'] = DB::escape($arr_apt->name);
        }
        if (isset($data['route']) && empty($data['route'])) {
            $flight_info = SchedulesData::getProperFlightNum($data['flightnum']);
            $params = array('s.code' => $flight_info['code'], 's.flightnum' => $flight_info['flightnum']);
            $schedule = SchedulesData::findSchedules($params);
            $schedule = $schedule[0];
            $data['route'] = $schedule->route;
            //$data['route_details'] = serialize(SchedulesData::getRouteDetails($schedule->id));
        } elseif (isset($data['route']) && !empty($data['route'])) {
            /*$tmp = new stdClass();
            		$tmp->deplat = $dep_apt->lat;
            		$tmp->deplng = $dep_apt->lng;
            		$tmp->route = $data['route'];
            		
            		$data['route_details'] = NavData::parseRoute($tmp);
            		$data['route_details'] = serialize($data['route_details']);
            		unset($tmp);*/
        }
        if (!empty($data['route_details'])) {
            $data['route_details'] = DB::escape($data['route_details']);
        }
        if (isset($dep_apt)) {
            unset($dep_apt);
        }
        if (isset($arr_apt)) {
            unset($arr_apt);
        }
        // Clean up times
        if (isset($data['deptime']) && !is_numeric($data['deptime'])) {
            $data['deptime'] = strtotime($data['deptime']);
        }
        if (isset($data['arrtime']) && !is_numeric($data['arrtime'])) {
            $data['arrtime'] = strtotime($data['arrtime']);
        }
        /* Check the heading for the flight
        			If none is specified, then point it straight to the arrival airport */
        if ($data['heading'] == '' || !isset($data['heading']) && isset($data['lat']) && isset($data['lng'])) {
            /* Calculate an angle based on current coords and the
            			destination coordinates */
            $data['heading'] = intval(atan2($data['lat'] - $arr_apt->lat, $data['lng'] - $arr_apt->lng) * 180 / 3.14);
            if ($data['lat'] - $data['lng'] < 0) {
                $data['heading'] += 180;
            }
            if ($data['heading'] < 0) {
                $data['heading'] += 360;
            }
        }
        // Manually add the last set
        $data['lastupdate'] = 'NOW()';
        // first see if we exist:
        $sql = 'SELECT `id`
				FROM ' . TABLE_PREFIX . "acarsdata \n\t\t\t\tWHERE `pilotid`={$pilotid}";
        $exist = DB::get_row($sql);
        $flight_id = '';
        if ($exist) {
            // update
            $upd = array();
            $flight_id = $exist->id;
            foreach ($data as $field => $value) {
                $value = DB::escape(trim($value));
                // Append the message log
                if ($field === 'messagelog') {
                    $upd[] = "`messagelog`=CONCAT(`messagelog`, '{$value}')";
                } elseif ($field === 'lastupdate') {
                    $upd[] = "`lastupdate`=NOW()";
                } elseif ($field === 'deptime' || $field === 'arrtime') {
                    /*	If undefined, set a default time to now (penalty for malformed data?)
                    			Won't be quite accurate.... */
                    if ($value == '') {
                        $value = time();
                    }
                    $upd[] = "`{$field}`=FROM_UNIXTIME({$value})";
                } else {
                    $upd[] = "`{$field}`='{$value}'";
                }
            }
            $upd = implode(',', $upd);
            $query = 'UPDATE ' . TABLE_PREFIX . "acarsdata \n\t\t\t\t\tSET {$upd} \n\t\t\t\t\tWHERE `id`='{$flight_id}'";
            DB::query($query);
        } else {
            // form array with $ins[column]=value and then
            //	give it to quick_insert to finish
            $ins = array();
            $vals = array();
            foreach ($data as $field => $value) {
                $ins[] = "`{$field}`";
                if ($field === 'deptime' || $field === 'arrtime') {
                    if (empty($value)) {
                        $value = time();
                    }
                    $vals[] = "FROM_UNIXTIME({$value})";
                } elseif ($field === 'lastupdate') {
                    $vals[] = 'NOW()';
                } else {
                    $value = DB::escape($value);
                    $vals[] = "'{$value}'";
                }
            }
            $ins = implode(',', $ins);
            $vals = implode(',', $vals);
            $query = 'INSERT INTO ' . TABLE_PREFIX . "acarsdata ({$ins}) \n\t\t\t\t\t\tVALUES ({$vals})";
            DB::query($query);
            $data['deptime'] = time();
            $flight_id = DB::$insert_id;
        }
        $flight_info = self::get_flight_by_id($flight_id);
        // Add this cuz we need it
        $data['code'] = $pilotinfo->code;
        $data['pilotid'] = $pilotid;
        $data['unique_id'] = $flight_id;
        $data['aircraft'] = $flight_info->aircraftname;
        $data['registration'] = $flight_info->registration;
        $res = CentralData::send_acars_data($data);
        return true;
    }
コード例 #4
0
 public static function set_xml($method)
 {
     self::$xml = new SimpleXMLElement('<vacentral/>');
     $api_key = Config::Get('VACENTRAL_API_KEY');
     if ($api_key == '') {
         $api_key = Config::Get('PHPVMS_API_KEY');
     }
     self::$xml->addChild('siteurl', SITE_URL);
     self::$xml->addChild('apikey', $api_key);
     self::$xml->addChild('version', PHPVMS_VERSION);
     if (Config::Get('VACENTRAL_DEBUG_MODE') == true) {
         self::$xml->addChild('debug', true);
     }
     self::$method = $method;
     self::$xml->addChild('method', $method);
 }
コード例 #5
0
 /**
  * CentralData::startBody()
  * 
  * @param mixed $method
  * @return void
  */
 protected static function startBody($method)
 {
     $api_key = Config::Get('VACENTRAL_API_KEY');
     # Determine the type
     self::$type = strtolower(trim(Config::Get('VACENTRAL_DATA_FORMAT')));
     if (self::$type !== 'xml' && self::$type !== 'json') {
         self::$type = 'xml';
     }
     if (self::$type == 'xml') {
         self::$xml = new SimpleXMLElement('<vacentral/>');
     } elseif (self::$type == 'json') {
         self::$json = array();
     }
     self::$method = $method;
     self::addElement(null, 'siteurl', SITE_URL);
     self::addElement(null, 'apikey', $api_key);
     self::addElement(null, 'version', PHPVMS_VERSION);
     self::addElement(null, 'method', $method);
     if (Config::Get('VACENTRAL_DEBUG_MODE') == true) {
         self::addElement(null, 'debug', true);
     }
 }
コード例 #6
0
ファイル: Import.php プロジェクト: rallin/phpVMS
 public function processimport()
 {
     echo '<h3>Processing Import</h3>';
     if (!file_exists($_FILES['uploadedfile']['tmp_name'])) {
         $this->set('message', 'File upload failed!');
         $this->render('core_error.tpl');
         return;
     }
     echo '<p><strong>DO NOT REFRESH OR STOP THIS PAGE</strong></p>';
     set_time_limit(270);
     $errs = array();
     $skip = false;
     # Fix for bug VMS-325
     $temp_name = $_FILES['uploadedfile']['tmp_name'];
     $new_name = CACHE_PATH . $_FILES['uploadedfile']['name'];
     move_uploaded_file($temp_name, $new_name);
     $fp = fopen($new_name, 'r');
     if (isset($_POST['header'])) {
         $skip = true;
     }
     /* Delete all schedules before doing an import */
     if (isset($_POST['erase_routes'])) {
         SchedulesData::deleteAllSchedules();
     }
     $added = 0;
     $updated = 0;
     $total = 0;
     echo '<div style="overflow: auto; height: 400px; border: 1px solid #666; margin-bottom: 20px; padding: 5px; padding-top: 0px; padding-bottom: 20px;">';
     while ($fields = fgetcsv($fp, 1000, ',')) {
         // Skip the first line
         if ($skip == true) {
             $skip = false;
             continue;
         }
         // list fields:
         $code = $fields[0];
         $flightnum = $fields[1];
         $depicao = $fields[2];
         $arricao = $fields[3];
         $route = $fields[4];
         $aircraft = $fields[5];
         $flightlevel = $fields[6];
         $distance = $fields[7];
         $deptime = $fields[8];
         $arrtime = $fields[9];
         $flighttime = $fields[10];
         $notes = $fields[11];
         $price = $fields[12];
         $flighttype = $fields[13];
         $daysofweek = $fields[14];
         $enabled = $fields[15];
         $week1 = $fields[16];
         $week2 = $fields[17];
         $week3 = $fields[18];
         $week4 = $fields[19];
         if ($code == '') {
             continue;
         }
         // Check the code:
         if (!OperationsData::GetAirlineByCode($code)) {
             echo "Airline with code {$code} does not exist! Skipping...<br />";
             continue;
         }
         // Make sure airports exist:
         if (!($depapt = OperationsData::GetAirportInfo($depicao))) {
             $this->get_airport_info($depicao);
         }
         if (!($arrapt = OperationsData::GetAirportInfo($arricao))) {
             $this->get_airport_info($arricao);
         }
         # Check the aircraft
         $aircraft = trim($aircraft);
         $ac_info = OperationsData::GetAircraftByReg($aircraft);
         # If the aircraft doesn't exist, skip it
         if (!$ac_info) {
             echo 'Aircraft "' . $aircraft . '" does not exist! Skipping<br />';
             continue;
         }
         $ac = $ac_info->id;
         if ($flighttype == '') {
             $flighttype = 'P';
         }
         if ($daysofweek == '') {
             $daysofweek = '0123456';
         }
         // Replace a 7 (Sunday) with 0 (since PHP thinks 0 is Sunday)
         $daysofweek = str_replace('7', '0', $daysofweek);
         # Check the distance
         if ($distance == 0 || $distance == '') {
             $distance = OperationsData::getAirportDistance($depicao, $arricao);
         }
         $flighttype = strtoupper($flighttype);
         if ($enabled == '0') {
             $enabled = false;
         } else {
             $enabled = true;
         }
         # This is our 'struct' we're passing into the schedule function
         #	to add or edit it
         $data = array('code' => $code, 'flightnum' => $flightnum, 'depicao' => $depicao, 'arricao' => $arricao, 'route' => $route, 'aircraft' => $ac, 'flightlevel' => $flightlevel, 'distance' => $distance, 'deptime' => $deptime, 'arrtime' => $arrtime, 'flighttime' => $flighttime, 'daysofweek' => $daysofweek, 'notes' => $notes, 'enabled' => $enabled, 'price' => $price, 'flighttype' => $flighttype, 'week1' => $week1, 'week2' => $week2, 'week3' => $week3, 'week4' => $week4);
         # Check if the schedule exists:
         if ($schedinfo = SchedulesData::getScheduleByFlight($code, $flightnum)) {
             # Update the schedule instead
             $val = SchedulesData::updateScheduleFields($schedinfo->id, $data);
             $updated++;
         } else {
             # Add it
             $val = SchedulesData::addSchedule($data);
             $added++;
         }
         if ($val === false) {
             if (DB::errno() == 1216) {
                 echo "Error adding {$code}{$flightnum}: The airline code, airports, or aircraft does not exist";
             } else {
                 $error = DB::error() != '' ? DB::error() : 'Route already exists';
                 echo "{$code}{$flightnum} was not added, reason: {$error}<br />";
             }
             echo '<br />';
         } else {
             $total++;
             echo "Imported {$code}{$flightnum} ({$depicao} to {$arricao})<br />";
         }
     }
     CentralData::send_schedules();
     echo "The import process is complete, added {$added} schedules, updated {$updated}, for a total of {$total}<br />";
     foreach ($errs as $error) {
         echo '&nbsp;&nbsp;&nbsp;&nbsp;' . $error . '<br />';
     }
     echo '</div>';
     unlink($new_name);
 }
コード例 #7
0
ファイル: vac_diag.php プロジェクト: Galihom/phpVMS
    case 'sendallpireps':
        $resp = CentralData::send_all_pireps();
        break;
    case 'sendpirep':
        $pirep = PIREPData::findPIREPS(array(), 20);
        $num = rand(0, count($pirep) - 1);
        $resp = CentralData::send_pirep($pirep[$num]->pirepid);
        break;
    case 'sendacars':
        # Send a random flight
        $flights = ACARSData::GetAllFlights();
        $total = count($flights);
        $resp = CentralData::send_acars_data($flights[rand(0, $total - 1)]);
        break;
    case 'sendallacars':
        $resp = CentralData::send_all_acars();
        break;
}
?>
<h3>Response:</h3>
<pre><?php 
$response = CentralData::$xml_response;
echo htmlentities(formatXmlString($response));
?>
</pre>

<h3>Sent Data</h3>
<pre><?php 
if (CentralData::$type == 'xml') {
    $xml = CentralData::$xml->asXML();
    echo htmlentities(formatXmlString($xml));
コード例 #8
0
ファイル: PIREPData.class.php プロジェクト: Galihom/phpVMS
 /**
  * PIREPData::fileReport()
  * 
  * @param mixed $pirepdata
  * @return
  */
 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\n\t\t\t\t\tWHERE `pilotid` = {$pirepdata['pilotid']} \n\t\t\t\t\t\tAND `code` = '{$pirepdata['code']}'\n\t\t\t\t\t\tAND `flightnum` = '{$pirepdata['flightnum']}' \n\t\t\t\t\t\tAND DATE_SUB(NOW(), INTERVAL {$time_limit} MINUTE) <= `submitdate`";
         $res = DB::get_row($sql);
         if ($res) {
             self::$lasterror = 'This PIREP was just submitted!';
             return $res->pirepid;
         }
     }
     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;
             } else {
                 $pirepdata['aircraft'] = '0';
             }
         }
     }
     # 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'] = str_replace('DCT', '', $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'] = str_replace('DCT', '', $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;
         }
     }
     /*	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'] = serialize($pirepdata['rawdata']);
     } else {
         $pirepdata['rawdata'] = '';
     }
     /* Escape the comment field */
     //$pirepdata['log'] = DB::escape($pirepdata['log']);
     if (isset($pirepdata['comment'])) {
         $comment = DB::escape($pirepdata['comment']);
         unset($pirepdata['comment']);
     }
     /* Proper timestamp */
     $pirepdata['flighttime'] = str_replace(':', '.', $pirepdata['flighttime']);
     $pirepdata['flighttime_stamp'] = str_replace('.', ':', $pirepdata['flighttime']) . ':00';
     /* Export status as 0 */
     $pirepdata['exported'] = 0;
     $pirepdata['submitdate'] = 'NOW()';
     $pirepdata['modifieddate'] = 'NOW()';
     $pirepdata['accepted'] = PIREP_PENDING;
     $pirepdata['expenselist'] = '0';
     $pirepdata['flighttype'] = $sched->flighttype;
     # Do the insert based on the columns here
     $cols = array();
     $col_values = array();
     foreach ($pirepdata as $key => $value) {
         if ($key == 'submitdate') {
             $value = 'NOW()';
         } elseif ($key == 'comment') {
             continue;
         } else {
             $value = "'" . DB::escape($value) . "'";
         }
         $cols[] = "`{$key}`";
         $col_values[] = $value;
     }
     $cols = implode(', ', $cols);
     $col_values = implode(', ', $col_values);
     $sql = 'INSERT INTO ' . TABLE_PREFIX . "pireps ({$cols}) VALUES ({$col_values});";
     DB::query($sql);
     $pirepid = DB::$insert_id;
     // Add the comment if its not blank
     if ($comment != '') {
         self::addComment($pirepid, $pirepdata['pilotid'], $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);
     if (Config::Get('EMAIL_SEND_PIREP') === true) {
         # 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" . "Landing Rate: {$pirepdata['landingrate']}\n" . "Filed using: {$pirepdata['source']}\n\n" . "Comment: {$comment}\n\n" . "Click to approve this pirep (admin must be signed in):\n" . adminurl('/pirepadmin/approvepirep/' . $pirepid);
         $email = Config::Get('EMAIL_NEW_PIREP');
         if (empty($email)) {
             $email = ADMIN_EMAIL;
         }
         Util::SendEmail($email, $sub, $message);
     }
     /* Add this into the activity feed */
     $message = Lang::get('activity.new.pirep');
     foreach ($pirepdata as $key => $value) {
         $message = str_replace('$' . $key, $value, $message);
     }
     # Add it to the activity feed
     ActivityData::addActivity(array('pilotid' => $pirepdata['pilotid'], 'type' => ACTIVITY_NEW_PIREP, 'refid' => $pirepid, 'message' => htmlentities($message)));
     /* Now send data to vaCentral */
     CentralData::send_pirep($pirepid);
     // Reset this ID back
     DB::$insert_id = $pirepid;
     self::$pirepid = $pirepid;
     return $pirepid;
 }