+++ /dev/null
-<?php
-include_once($_SERVER['DOCUMENT_ROOT'].'/wp-config.php' );
- class glm_flight {
- /**
- * toolbox
- *
- * @var mixed
- * @access public
- */
- public $toolbox;
- /**
- * DB
- *
- * @var mixed
- * @access public
- */
- public $DB;
- /**
- * arr_data
- *
- * @var mixed
- * @access public
- */
- public $arr_data;
- /**
- * dep_data
- *
- * @var mixed
- * @access public
- */
- public $dep_data;
- /**
- * airports
- *
- * @var mixed
- * @access public
- */
- public $airports;
- /**
- * time_codes
- *
- * @var mixed
- * @access public
- */
- public $time_codes;
- /**
- * last_updated
- *
- * @var mixed
- * @access public
- */
- public $last_updated;
- /**
- * glm_flight
- *
- * @param mixed $toolbox
- * @access public
- * @return string
- */
- function glm_flight()
- {
-// $this->toolbox = &$toolbox;
-// $this->DB =& $toolbox->DB;
- $this->airports = array('DTW'=>'Detroit Metro','PLN'=>'Pellston');
- $this->time_codes = array('A'=>'Actual','E'=>'Estimated','D'=>'Descision','S'=>'Scheduled','R'=>'In-range');
- }
-
- function get_airports( $code )
- { global $wpdb;
- $return = false;
- $query = "select * from glm_airport where code = '$code'";
- if( $data = $wpdb->get_results( $query, ARRAY_A ) )
- {
- $return = array(
- 'city'=>$data[0]['city'],
- 'state'=>$data[0]['state'],
- 'name'=>$data[0]['name']
- );
- }
- return( $return );
- }
- /**
- * get_flight_data
- *
- * @access public
- * @return string
- */
- function get_flight_data()
- {
- global $wpdb;
- $this->get_arr_flight_data();
- $this->get_dep_flight_data();
-
- if ( isset( $this->arr_data ) && is_array( $this->arr_data ) ) {
- foreach( $this->arr_data as $key=>$value )
- {
- $update_times[] = strtotime($value['msg_dtm']);
- if ($row['name'] == "EXPRESS AIRLINES 1, INC.") $this->arr_data[$key]['name'] = 'Delta Airlines';
- if ($row['airline'] == "EXPRESS AIRLINES 1, INC.") $this->arr_data[$key]['airline'] = 'Delta Airlines';
- }
- }
- if ( isset( $this->dep_data ) && is_array( $this->dep_data ) ) {
- foreach( $this->dep_data as $key=>$value)
- {
- $update_times[] = strtotime($value['msg_dtm']);
- if ($row['name'] == "EXPRESS AIRLINES 1, INC.") $this->dep_data[$key]['name'] = '<nobr>Delta Airlines</nobr>';
- if ($row['airline'] == "EXPRESS AIRLINES 1, INC.") $this->dep_data[$key]['airline'] = '<nobr>Delta Airlines</nobr>';
- }
- }
- rsort($update_times);
- // get UTC offset for current date/time
- $TimeDiff = 4+date("I");
- $this->last_updated = '<div id="last-update"><p> </p><p><b>Last updated:</b> '.date("n/j/Y g:i a",$update_times[0]-($TimeDiff*60*60)).'</p></div>';
- // $query = "SELECT msg_dtm FROM glm_flight
- // ORDER BY msg_dtm DESC
- // LIMIT 1;";
- // $results = $wpdb->get_results($query, ARRAY_A);
- // foreach($results as $key=>$value){
- // $lastUpdated = date("n/j/Y g:i a", strtotime($value['msg_dtm']) - ($TimeDiff*60*60));
- // }
- // $this->last_updated = '<div id="last-update"><p> </p><p><b>Last updated:</b> '. $lastUpdated . '</p></div>';
- //echo '<!--<pre>';
- //print_r( $update_times );
- //echo '</pre>-->';
- }
-
- /**
- * get_arr_flight_data
- *
- * @access public
- * @return string
- */
- function get_arr_flight_data()
- {
- global $wpdb;
- $query = "select *, name AS airline from glm_flight, glm_airlines where flt_orig_date = current_date and flt_leg_dest = 'PLN' and glm_airlines.code = flt_airline order by cur_in_time;";
-
- if( $data = $wpdb->get_results( $query, ARRAY_A ) )
- {
- $this->arr_data = $data;
- }
- }
-
- /**
- * get_dep_flight_data
- *
- * @access public
- * @return string
- */
- function get_dep_flight_data()
- {
- global $wpdb;
- $query = "select *, name AS airline from glm_flight, glm_airlines where flt_orig_date = current_date and flt_leg_orig = 'PLN' and glm_airlines.code = flt_airline order by cur_dep_time;";
- if( $data = $wpdb->get_results( $query, ARRAY_A ) )
- {
- $this->dep_data = $data;
- }
- }
-
- /**
- * format_time
- *
- * @param mixed $time
- * @access public
- * @return string
- */
- function format_time( $time )
- {
- $timestamp = strtotime( 'now '.$time );
- $newtime = date('g:i A',$timestamp);
- return( $newtime );
- }
-
- /**
- * build_arrivals
- *
- * @access public
- * @return string
- */
- function build_arrivals()
- {
- if( is_array( $this->arr_data ) )
- {
- $out = '
- <table class="footable arrival" id="flight-arrivals">';
- $out .= '
- <thead>
- <tr>
- <th>From</th>
- <th>Flight</th>
- <th>Time</th>
- <th>Status</th>
- </tr>
- </thead>
- ';
- foreach( $this->arr_data as $row )
- {
- $airport = $this->get_airports( $row["flt_leg_orig"] );
- $airport_text = $airport["name"].' '.$airport["city"];
- $airport_text .= ( $airport["state"] ) ? ','.$airport["state"]:'';
- $out .= '
- <tr>
- <td>'.$airport_text.'</td>
- <td>'.$row["airline"].' '.$row["flt_numb"].'</td>
- <td>'.$this->format_time( $row["cur_in_time"] ).' '.$this->time_codes[$row["cur_in_time_code"]].'</td>
- <td><nobr>'.$row["remarks"].'</nobr></td>
- </tr>
- ';
- }
- $out .= '</table>
- ';
- }
- return( $out );
- }
-
- /**
- * build_departures
- *
- * @access public
- * @return string
- */
- function build_departures()
- {
-
- if( is_array( $this->dep_data ) )
- {
- $out = '
- <table class="footable departure id="flight-departures">';
- $out .= '
- <thead>
- <tr>
- <th>Destination</th>
- <th>Flight</th>
- <th>Time</th>
- <th>Status</th>
- </tr>
- </thead>
- ';
- foreach( $this->dep_data as $row )
- {
- $airport = $this->get_airports( $row["flt_leg_dest"] );
- $airport_text = $airport["name"].' '.$airport["city"];
- $airport_text .= ( $airport["state"] ) ? ','.$airport["state"]:'';
- $out .= '
- <tr>
- <td>'.$airport_text.'</td>
- <td>'.$row["airline"].'<br>'.$row["flt_numb"].'</td>
- <td>'.$this->format_time( $row["cur_dep_time"] ).' '.$this->time_codes[$row["cur_dep_time_code"]].'</td>
- <td><nobr>'.$row["remarks"].'</nobr></td>
- </tr>
- ';
- }
- $out .= '</table>
- ';
- }
- return( $out );
- }
- }
-?>
+++ /dev/null
-CREATE TABLE glm_28_airport
- (
- id SERIAL,
- code text null,
- name text null,
- city text null,
- state text null
- );
-REVOKE ALL ON glm_airport FROM PUBLIC;
-GRANT ALL ON glm_airport TO nobody;
-REVOKE ALL ON airport_id_seq FROM PUBLIC;
-GRANT ALL ON airport_id_seq TO nobody;
-CREATE INDEX airport_code_index ON glm_airport(code);
-
-CREATE TABLE glm_28_flight
- (
- id SERIAL,
- msg_dtm timestamp null,
- msg_seq_id text null,
- flt_orig_date date null,
- flt_airline text null,
- flt_numb text null,
- flt_leg_orig text null,
- flt_leg_dest text null,
- flt_leg_vers int null,
- sch_leg_orig text null,
- sch_leg_dest text null,
- sch_dep_time time null,
- sch_off_time time null,
- sch_on_time time null,
- sch_in_time time null,
- cur_dep_time time null,
- cur_dep_time_code text null,
- cur_off_time time null,
- cur_off_time_code text null,
- cur_on_time time null,
- cur_on_time_code text null,
- cur_in_time time null,
- cur_in_time_code text null,
- delay_code text null,
- depart_gate text null,
- arriv_gate text null,
- radio_code text null,
- aircraft text null,
- reg_numb text null,
- remarks text null,
- food_code text null,
- flight_type text null,
- downline_leg bool null,
- overfly bool null,
- canceled bool null,
- dep_ontime bool null,
- arriv_ontime bool null
- );
-
-REVOKE ALL ON glm_flight FROM PUBLIC;
-GRANT ALL ON glm_flight TO nobody;
-REVOKE ALL ON flight_id_seq FROM PUBLIC;
-GRANT ALL ON flight_id_seq TO nobody;
-CREATE INDEX flight_orig_date_index ON glm_flight(flt_orig_date);
-CREATE INDEX flight_numb_index ON glm_flight(flt_numb);