Esempio n. 1
0
} elseif (isset($spotter_item['wikipedia_link']) && $spotter_item['wikipedia_link'] != '') {
    print '<div><span>Links</span>';
    print '<a href="' . $spotter_item['wikipedia_link'] . '">Wikipedia</a>';
    print '</div>';
}
print '</div>';
if (isset($metar_parse)) {
    print '<div class="waypoints">';
    print '<div><span>METAR</span>';
    print '<i>' . $metar_info[0]['metar'] . '</i><br />';
    print '<b>' . $metar_info[0]['metar_date'] . '</b><br />';
    //    print_r($metar_parse);
    if (isset($metar_parse['wind'])) {
        print 'Wind : ';
        if (isset($metar_parse['wind']['direction'])) {
            $direction = $Spotter->parseDirection($metar_parse['wind']['direction']);
            print $direction[0]['direction_fullname'];
            print ' (' . $metar_parse['wind']['direction'] . '°) ';
        }
        if (isset($metar_parse['wind']['speed'])) {
            print $metar_parse['wind']['speed'] . ' m/s';
        }
        print '<br/>';
    }
    if (isset($metar_parse['visibility'])) {
        print 'Visibility : ' . $metar_parse['visibility'] . ' m' . "<br/>";
    }
    if (isset($metar_parse['weather'])) {
        print 'Weather : ' . $metar_parse['weather'] . "<br/>";
    }
    if (isset($metar_parse['temperature'])) {
Esempio n. 2
0
 /**
  * Executes the SQL statements to get the spotter information
  *
  * @param String $query the SQL query
  * @param String $limit the limit query
  * @return Array the spotter information
  *
  */
 public static function getDataFromDB($query, $params = array(), $limitQuery = '')
 {
     global $globalSquawkCountry, $globalIVAO;
     if (!isset($globalIVAO)) {
         $globalIVAO = FALSE;
     }
     date_default_timezone_set('UTC');
     if (!is_string($query)) {
         return false;
     }
     if ($limitQuery != "") {
         if (!is_string($limitQuery)) {
             return false;
         }
     }
     $Connection = new Connection();
     try {
         $sth = Connection::$db->prepare($query . $limitQuery);
         $sth->execute($params);
     } catch (PDOException $e) {
         printf("Invalid query : %s\nWhole query: %s\n", $e->getMessage(), $query . $limitQuery);
         exit;
     }
     //	$num_rows = count($sth->fetchAll());
     $num_rows = 0;
     $spotter_array = array();
     $temp_array = array();
     while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
         $num_rows++;
         $temp_array = array();
         if (isset($row['spotter_live_id'])) {
             $temp_array['spotter_id'] = $row['spotter_live_id'];
         } elseif (isset($row['spotter_archive_id'])) {
             $temp_array['spotter_id'] = $row['spotter_archive_id'];
         } else {
             $temp_array['spotter_id'] = $row['spotter_id'];
         }
         $temp_array['flightaware_id'] = $row['flightaware_id'];
         if (isset($row['modes'])) {
             $temp_array['modes'] = $row['modes'];
         }
         $temp_array['ident'] = $row['ident'];
         if (isset($row['registration']) && $row['registration'] != '') {
             $temp_array['registration'] = $row['registration'];
         } elseif (isset($temp_array['modes'])) {
             $temp_array['registration'] = Spotter::getAircraftRegistrationBymodeS($temp_array['modes']);
         } else {
             $temp_array['registration'] = '';
         }
         $temp_array['aircraft_type'] = $row['aircraft_icao'];
         $temp_array['departure_airport'] = $row['departure_airport_icao'];
         $temp_array['arrival_airport'] = $row['arrival_airport_icao'];
         $temp_array['latitude'] = $row['latitude'];
         $temp_array['longitude'] = $row['longitude'];
         if (Connection::tableExists('countries')) {
             $country_info = Spotter::getCountryFromLatitudeLongitude($temp_array['latitude'], $temp_array['longitude']);
             if (is_array($country_info) && isset($country_info['name']) && isset($country_info['iso2'])) {
                 $temp_array['country'] = $country_info['name'];
                 $temp_array['country_iso2'] = $country_info['iso2'];
             }
         }
         $temp_array['waypoints'] = $row['waypoints'];
         if (isset($row['route_stop'])) {
             $temp_array['route_stop'] = $row['route_stop'];
             if ($row['route_stop'] != '') {
                 $allroute = explode(' ', $row['route_stop']);
                 foreach ($allroute as $route) {
                     $route_airport_array = Spotter::getAllAirportInfo($route);
                     if (isset($route_airport_array[0]['name'])) {
                         $route_stop_details['airport_name'] = $route_airport_array[0]['name'];
                         $route_stop_details['airport_city'] = $route_airport_array[0]['city'];
                         $route_stop_details['airport_country'] = $route_airport_array[0]['country'];
                         $route_stop_details['airport_icao'] = $route_airport_array[0]['icao'];
                         $temp_array['route_stop_details'][] = $route_stop_details;
                     }
                 }
             }
         }
         $temp_array['altitude'] = $row['altitude'];
         $temp_array['heading'] = $row['heading'];
         $heading_direction = Spotter::parseDirection($row['heading']);
         if (isset($heading_direction[0]['direction_fullname'])) {
             $temp_array['heading_name'] = $heading_direction[0]['direction_fullname'];
         }
         $temp_array['ground_speed'] = $row['ground_speed'];
         $temp_array['image'] = "";
         $temp_array['image_thumbnail'] = "";
         $temp_array['image_source'] = "";
         $temp_array['image_copyright'] = "";
         if (isset($row['highlight'])) {
             $temp_array['highlight'] = $row['highlight'];
         } else {
             $temp_array['highlight'] = '';
         }
         $dateArray = Spotter::parseDateString($row['date']);
         if ($dateArray['seconds'] < 10) {
             $temp_array['date'] = "a few seconds ago";
         } elseif ($dateArray['seconds'] >= 5 && $dateArray['seconds'] < 30) {
             $temp_array['date'] = "half a minute ago";
         } elseif ($dateArray['seconds'] >= 30 && $dateArray['seconds'] < 60) {
             $temp_array['date'] = "about a minute ago";
         } elseif ($dateArray['minutes'] < 5) {
             $temp_array['date'] = "a few minutes ago";
         } elseif ($dateArray['minutes'] >= 5 && $dateArray['minutes'] < 60) {
             $temp_array['date'] = "about " . $dateArray['minutes'] . " minutes ago";
         } elseif ($dateArray['hours'] < 2) {
             $temp_array['date'] = "about an hour ago";
         } elseif ($dateArray['hours'] >= 2 && $dateArray['hours'] < 24) {
             $temp_array['date'] = "about " . $dateArray['hours'] . " hours ago";
         } else {
             $temp_array['date'] = date("M j Y, g:i a", strtotime($row['date'] . " UTC"));
         }
         $temp_array['date_minutes_past'] = $dateArray['minutes'];
         $temp_array['date_iso_8601'] = date("c", strtotime($row['date'] . " UTC"));
         $temp_array['date_rfc_2822'] = date("r", strtotime($row['date'] . " UTC"));
         $temp_array['date_unix'] = strtotime($row['date'] . " UTC");
         if (isset($row['aircraft_name']) && $row['aircraft_name'] != '' && isset($row['aircraft_shadow']) && $row['aircraft_shadow'] != '') {
             $temp_array['aircraft_name'] = $row['aircraft_name'];
             $temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer'];
             if (isset($row['aircraft_shadow'])) {
                 $temp_array['aircraft_shadow'] = $row['aircraft_shadow'];
             }
         } else {
             $aircraft_array = Spotter::getAllAircraftInfo($row['aircraft_icao']);
             if (count($aircraft_array) > 0) {
                 $temp_array['aircraft_name'] = $aircraft_array[0]['type'];
                 $temp_array['aircraft_manufacturer'] = $aircraft_array[0]['manufacturer'];
                 if ($aircraft_array[0]['aircraft_shadow'] != NULL) {
                     $temp_array['aircraft_shadow'] = $aircraft_array[0]['aircraft_shadow'];
                 } else {
                     $temp_array['aircraft_shadow'] = 'default.png';
                 }
             } else {
                 $temp_array['aircraft_shadow'] = 'default.png';
                 $temp_array['aircraft_name'] = 'N/A';
             }
         }
         $airline_array = array();
         if (!is_numeric(substr($row['ident'], 0, 3))) {
             if (is_numeric(substr(substr($row['ident'], 0, 3), -1, 1))) {
                 $airline_array = Spotter::getAllAirlineInfo(substr($row['ident'], 0, 2));
             } elseif (is_numeric(substr(substr($row['ident'], 0, 4), -1, 1))) {
                 $airline_array = Spotter::getAllAirlineInfo(substr($row['ident'], 0, 3));
             } else {
                 $airline_array = Spotter::getAllAirlineInfo('NA');
             }
         } else {
             $airline_array = Spotter::getAllAirlineInfo('NA');
         }
         if (count($airline_array) > 0) {
             $temp_array['airline_icao'] = $airline_array[0]['icao'];
             $temp_array['airline_iata'] = $airline_array[0]['iata'];
             $temp_array['airline_name'] = $airline_array[0]['name'];
             $temp_array['airline_country'] = $airline_array[0]['country'];
             $temp_array['airline_callsign'] = $airline_array[0]['callsign'];
             $temp_array['airline_type'] = $airline_array[0]['type'];
         }
         if (isset($temp_array['airline_iata'])) {
             $acars_array = ACARS::getLiveAcarsData($temp_array['airline_iata'] . substr($temp_array['ident'], 3));
             //$acars_array = ACARS::getLiveAcarsData('BA40YL');
             if (count($acars_array) > 0) {
                 $temp_array['acars'] = $acars_array;
                 //print_r($acars_array);
             }
         }
         if ($temp_array['registration'] != "" || $globalIVAO && $temp_array['aircraft_type'] != '') {
             if ($globalIVAO) {
                 if (isset($temp_array['airline_icao'])) {
                     $image_array = Image::getSpotterImage('', $temp_array['aircraft_type'], $temp_array['airline_icao']);
                 } else {
                     $image_array = Image::getSpotterImage('', $temp_array['aircraft_type']);
                 }
             } else {
                 $image_array = Image::getSpotterImage($temp_array['registration']);
             }
             if (count($image_array) > 0) {
                 $temp_array['image'] = $image_array[0]['image'];
                 $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail'];
                 $temp_array['image_source'] = $image_array[0]['image_source'];
                 $temp_array['image_source_website'] = $image_array[0]['image_source_website'];
                 if ($temp_array['image_source_website'] == '' && $temp_array['image_source'] == 'planespotters') {
                     $planespotter_url_array = explode("_", $temp_array['image']);
                     $planespotter_id = str_replace(".jpg", "", $planespotter_url_array[1]);
                     $temp_array['image_source_website'] = 'http://www.planespotters.net/Aviation_Photos/photo.show?id=' . $planespotter_id;
                 }
                 $temp_array['image_copyright'] = $image_array[0]['image_copyright'];
             }
         }
         if (!isset($globalIVAO) || !$globalIVAO) {
             $schedule_array = Schedule::getSchedule($temp_array['ident']);
             //print_r($schedule_array);
             if (count($schedule_array) > 0) {
                 if ($schedule_array['departure_airport_icao'] != '') {
                     $row['departure_airport_icao'] = $schedule_array['departure_airport_icao'];
                     $temp_array['departure_airport'] = $row['departure_airport_icao'];
                 }
                 if ($schedule_array['arrival_airport_icao'] != '') {
                     $row['arrival_airport_icao'] = $schedule_array['arrival_airport_icao'];
                     $temp_array['arrival_airport'] = $row['arrival_airport_icao'];
                 }
                 $temp_array['departure_airport_time'] = $schedule_array['departure_airport_time'];
                 $temp_array['arrival_airport_time'] = $schedule_array['arrival_airport_time'];
             }
         }
         if ($row['departure_airport_icao'] != '') {
             $departure_airport_array = Spotter::getAllAirportInfo($row['departure_airport_icao']);
             if (!isset($departure_airport_array[0]['name'])) {
                 $departure_airport_array = Spotter::getAllAirportInfo('NA');
             }
         } else {
             $departure_airport_array = Spotter::getAllAirportInfo('NA');
         }
         if (isset($departure_airport_array[0]['name'])) {
             $temp_array['departure_airport_name'] = $departure_airport_array[0]['name'];
             $temp_array['departure_airport_city'] = $departure_airport_array[0]['city'];
             $temp_array['departure_airport_country'] = $departure_airport_array[0]['country'];
             $temp_array['departure_airport_iata'] = $departure_airport_array[0]['iata'];
             $temp_array['departure_airport_icao'] = $departure_airport_array[0]['icao'];
             $temp_array['departure_airport_latitude'] = $departure_airport_array[0]['latitude'];
             $temp_array['departure_airport_longitude'] = $departure_airport_array[0]['longitude'];
             $temp_array['departure_airport_altitude'] = $departure_airport_array[0]['altitude'];
         }
         /*
         if (isset($row['departure_airport_time'])) {
         	$temp_array['departure_airport_time'] = $row['departure_airport_time'];
         }
         */
         if ($row['arrival_airport_icao'] != '') {
             $arrival_airport_array = Spotter::getAllAirportInfo($row['arrival_airport_icao']);
             if (count($arrival_airport_array) == 0) {
                 $arrival_airport_array = Spotter::getAllAirportInfo('NA');
             }
         } else {
             $arrival_airport_array = Spotter::getAllAirportInfo('NA');
         }
         if (count($arrival_airport_array) > 0) {
             $temp_array['arrival_airport_name'] = $arrival_airport_array[0]['name'];
             $temp_array['arrival_airport_city'] = $arrival_airport_array[0]['city'];
             $temp_array['arrival_airport_country'] = $arrival_airport_array[0]['country'];
             $temp_array['arrival_airport_iata'] = $arrival_airport_array[0]['iata'];
             $temp_array['arrival_airport_icao'] = $arrival_airport_array[0]['icao'];
             $temp_array['arrival_airport_latitude'] = $arrival_airport_array[0]['latitude'];
             $temp_array['arrival_airport_longitude'] = $arrival_airport_array[0]['longitude'];
             $temp_array['arrival_airport_altitude'] = $arrival_airport_array[0]['altitude'];
         }
         /*
         if (isset($row['arrival_airport_time'])) {
         	$temp_array['arrival_airport_time'] = $row['arrival_airport_time'];
         }
         */
         if (isset($row['pilot_id']) && $row['pilot_id'] != '') {
             $temp_array['pilot_id'] = $row['pilot_id'];
         }
         if (isset($row['pilot_name']) && $row['pilot_name'] != '') {
             $temp_array['pilot_name'] = $row['pilot_name'];
         }
         if (isset($row['squawk'])) {
             $temp_array['squawk'] = $row['squawk'];
             if ($row['squawk'] != '' && isset($temp_array['country_iso2'])) {
                 $temp_array['squawk_usage'] = Spotter::getSquawkUsage($row['squawk'], $temp_array['country_iso2']);
                 if ($temp_array['squawk_usage'] == '' && isset($globalSquawkCountry)) {
                     $temp_array['squawk_usage'] = Spotter::getSquawkUsage($row['squawk'], $globalSquawkCountry);
                 }
             } elseif ($row['squawk'] != '' && isset($globalSquawkCountry)) {
                 $temp_array['squawk_usage'] = Spotter::getSquawkUsage($row['squawk'], $globalSquawkCountry);
             }
         }
         $temp_array['query_number_rows'] = $num_rows;
         $spotter_array[] = $temp_array;
     }
     if ($num_rows == 0) {
         return array();
     }
     $spotter_array[0]['query_number_rows'] = $num_rows;
     return $spotter_array;
 }