/**
  * Adds a new spotter data
  *
  * @param String $flightaware_id the ID from flightaware
  * @param String $ident the flight ident
  * @param String $aircraft_icao the aircraft type
  * @param String $departure_airport_icao the departure airport
  * @param String $arrival_airport_icao the arrival airport
  * @return String success or false
  *
  */
 public static function addLiveSpotterData($flightaware_id = '', $ident = '', $aircraft_icao = '', $departure_airport_icao = '', $arrival_airport_icao = '', $latitude = '', $longitude = '', $waypoints = '', $altitude = '', $heading = '', $groundspeed = '', $departure_airport_time = '', $arrival_airport_time = '', $squawk = '', $route_stop = '', $ModeS = '', $putinarchive = false, $registration = '', $pilot_id = '', $pilot_name = '', $verticalrate = '')
 {
     global $globalURL, $globalArchive, $globalDebug;
     date_default_timezone_set('UTC');
     $registration = '';
     //getting the registration
     //		if ($ModeS != '') $registration = Spotter::getAircraftRegistrationBymodeS($ModeS);
     //getting the airline information
     if ($ident != "") {
         if (!is_string($ident)) {
             return false;
         }
         /*
         	else {
         		//if (!is_numeric(substr($ident, -1, 1)))
         		if (!is_numeric(substr($ident, 0, 3)))
         		{
         			if (is_numeric(substr(substr($ident, 0, 3), -1, 1))) {
         				$airline_array = Spotter::getAllAirlineInfo(substr($ident, 0, 2));
         			} elseif (is_numeric(substr(substr($ident, 0, 4), -1, 1))) {
         				$airline_array = Spotter::getAllAirlineInfo(substr($ident, 0, 3));
         			} else {
         				$airline_array = Spotter::getAllAirlineInfo("NA");
         			}
         			//print_r($airline_array);
         			if (count($airline_array) == 0) {
         			    $airline_array = Spotter::getAllAirlineInfo("NA");
         			} elseif ($airline_array[0]['icao'] == ""){
         			    $airline_array = Spotter::getAllAirlineInfo("NA");
         			}
         
         		} else {
         			//echo "\n arg numeric : ".substr($ident, -1, 1)." - ".substr($ident, 0, 3)."\n";
         			$airline_array = Spotter::getAllAirlineInfo("NA");
         		}
         	}
         */
     }
     //getting the aircraft information
     if ($aircraft_icao != "") {
         if (!is_string($aircraft_icao)) {
             return false;
         }
         /*
         else {
         	if ($aircraft_icao == "" || $aircraft_icao == "XXXX")
         	{
         		$aircraft_array = Spotter::getAllAircraftInfo("NA");
         	} else {
         		$aircraft_array = Spotter::getAllAircraftInfo($aircraft_icao);
         	}
         }
         */
     }
     //getting the departure airport information
     if ($departure_airport_icao != "") {
         if (!is_string($departure_airport_icao)) {
             return false;
         }
         /*
         else {
         	$departure_airport_array = Spotter::getAllAirportInfo($departure_airport_icao);
         }
         */
     }
     //getting the arrival airport information
     if ($arrival_airport_icao != "") {
         if (!is_string($arrival_airport_icao)) {
             return false;
         }
         /*
         
          else {
         	$arrival_airport_array = Spotter::getAllAirportInfo($arrival_airport_icao);
         }
         */
     }
     if ($latitude != "") {
         if (!is_numeric($latitude)) {
             return false;
         }
     }
     if ($longitude != "") {
         if (!is_numeric($longitude)) {
             return false;
         }
     }
     if ($waypoints != "") {
         if (!is_string($waypoints)) {
             return false;
         }
     }
     if ($altitude != "") {
         if (!is_numeric($altitude)) {
             return false;
         }
     }
     if ($heading != "") {
         if (!is_numeric($heading)) {
             return false;
         }
     }
     if ($groundspeed != "") {
         if (!is_numeric($groundspeed)) {
             return false;
         }
     }
     date_default_timezone_set('UTC');
     $date = date("Y-m-d H:i:s", time());
     /*
     		//getting the aircraft image
     		if ($registration != "")
     		{
     			$image_array = Image::getSpotterImage($registration);
     			if (!isset($image_array[0]['registration']))
     			{
     				Image::addSpotterImage($registration);
     			}
     		}
     */
     $flightaware_id = filter_var($flightaware_id, FILTER_SANITIZE_STRING);
     $ident = filter_var($ident, FILTER_SANITIZE_STRING);
     $aircraft_icao = filter_var($aircraft_icao, FILTER_SANITIZE_STRING);
     $departure_airport_icao = filter_var($departure_airport_icao, FILTER_SANITIZE_STRING);
     $arrival_airport_icao = filter_var($arrival_airport_icao, FILTER_SANITIZE_STRING);
     $latitude = filter_var($latitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
     $longitude = filter_var($longitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
     $waypoints = filter_var($waypoints, FILTER_SANITIZE_STRING);
     $altitude = filter_var($altitude, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
     $heading = filter_var($heading, FILTER_SANITIZE_NUMBER_INT);
     $groundspeed = filter_var($groundspeed, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
     $squawk = filter_var($squawk, FILTER_SANITIZE_NUMBER_INT);
     $route_stop = filter_var($route_stop, FILTER_SANITIZE_STRING);
     $ModeS = filter_var($ModeS, FILTER_SANITIZE_STRING);
     $pilot_id = filter_var($pilot_id, FILTER_SANITIZE_STRING);
     $pilot_name = filter_var($pilot_name, FILTER_SANITIZE_STRING);
     $verticalrate = filter_var($verticalrate, FILTER_SANITIZE_NUMBER_INT);
     /*
     		if (!isset($airline_array) || count($airline_array) == 0) {
     			$airline_array = Spotter::getAllAirlineInfo('NA');
     		}
     		if (!isset($aircraft_array) || count($aircraft_array) == 0) {
     			$aircraft_array = Spotter::getAllAircraftInfo('NA');
                 	}
                 	if ($registration == '') $registration = 'NA';
     		$airline_name = $airline_array[0]['name'];
     		$airline_icao = $airline_array[0]['icao'];
     		$airline_country = $airline_array[0]['country'];
     		$airline_type = $airline_array[0]['type'];
     		$aircraft_shadow = $aircraft_array[0]['aircraft_shadow'];
     		$aircraft_type = $aircraft_array[0]['type'];
     		$aircraft_manufacturer = $aircraft_array[0]['manufacturer'];
     */
     $airline_name = '';
     $airline_icao = '';
     $airline_country = '';
     $airline_type = '';
     $aircraft_shadow = '';
     $aircraft_type = '';
     $aircraft_manufacturer = '';
     $aircraft_name = '';
     if (isset($departure_airport_array[0])) {
         $departure_airport_name = $departure_airport_array[0]['name'];
         $departure_airport_city = $departure_airport_array[0]['city'];
         $departure_airport_country = $departure_airport_array[0]['country'];
     } else {
         $departure_airport_name = '';
         $departure_airport_city = '';
         $departure_airport_country = '';
     }
     if (isset($arrival_airport_array[0])) {
         $arrival_airport_name = $arrival_airport_array[0]['name'];
         $arrival_airport_city = $arrival_airport_array[0]['city'];
         $arrival_airport_country = $arrival_airport_array[0]['country'];
     } else {
         $arrival_airport_name = '';
         $arrival_airport_city = '';
         $arrival_airport_country = '';
     }
     $query = "INSERT INTO spotter_live (flightaware_id, ident, registration, airline_name, airline_icao, airline_country, airline_type, aircraft_icao, aircraft_shadow, aircraft_name, aircraft_manufacturer, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, latitude, longitude, waypoints, altitude, heading, ground_speed, date, departure_airport_time, arrival_airport_time, squawk, route_stop, ModeS, pilot_id, pilot_name, verticalrate) \n\t\tVALUES (:flightaware_id,:ident,:registration,:airline_name,:airline_icao,:airline_country,:airline_type,:aircraft_icao,:aircraft_shadow,:aircraft_type,:aircraft_manufacturer,:departure_airport_icao,:departure_airport_name, :departure_airport_city, :departure_airport_country, :arrival_airport_icao, :arrival_airport_name, :arrival_airport_city, :arrival_airport_country, :latitude,:longitude,:waypoints,:altitude,:heading,:groundspeed,:date,:departure_airport_time,:arrival_airport_time,:squawk,:route_stop,:ModeS, :pilot_id, :pilot_name, :verticalrate)";
     $query_values = array(':flightaware_id' => $flightaware_id, ':ident' => $ident, ':registration' => $registration, ':airline_name' => $airline_name, ':airline_icao' => $airline_icao, ':airline_country' => $airline_country, ':airline_type' => $airline_type, ':aircraft_icao' => $aircraft_icao, ':aircraft_shadow' => $aircraft_shadow, ':aircraft_type' => $aircraft_type, ':aircraft_manufacturer' => $aircraft_manufacturer, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_name' => $departure_airport_name, ':departure_airport_city' => $departure_airport_city, ':departure_airport_country' => $departure_airport_country, ':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_name' => $arrival_airport_name, ':arrival_airport_city' => $arrival_airport_city, ':arrival_airport_country' => $arrival_airport_country, ':latitude' => $latitude, ':longitude' => $longitude, ':waypoints' => $waypoints, ':altitude' => $altitude, ':heading' => $heading, ':groundspeed' => $groundspeed, ':date' => $date, ':departure_airport_time' => $departure_airport_time, ':arrival_airport_time' => $arrival_airport_time, ':squawk' => $squawk, ':route_stop' => $route_stop, ':ModeS' => $ModeS, ':pilot_id' => $pilot_id, ':pilot_name' => $pilot_name, ':verticalrate' => $verticalrate);
     //$query_values = array(':flightaware_id' => $flightaware_id,':ident' => $ident, ':registration' => $registration,':airline_name' => $airline_array[0]['name'],':airline_icao' => $airline_array[0]['icao'],':airline_country' => $airline_array[0]['country'],':airline_type' => $airline_array[0]['type'],':aircraft_icao' => $aircraft_icao,':aircraft_type' => $aircraft_array[0]['type'],':aircraft_manufacturer' => $aircraft_array[0]['manufacturer'],':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':latitude' => $latitude,':longitude' => $longitude, ':waypoints' => $waypoints,':altitude' => $altitude,':heading' => $heading,':groundspeed' => $groundspeed,':date' => $date);
     try {
         $Connection = new Connection();
         $sth = Connection::$db->prepare($query);
         $sth->execute($query_values);
         //			Connection::$db = null;
     } catch (PDOException $e) {
         return "error : " . $e->getMessage();
     }
     if (isset($globalArchive) && $globalArchive && $putinarchive) {
         if ($globalDebug) {
             echo "(Add to SBS archive : ";
         }
         $result = SpotterArchive::addSpotterArchiveData($flightaware_id, $ident, $registration, $airline_name, $airline_icao, $airline_country, $airline_type, $aircraft_icao, $aircraft_shadow, $aircraft_name, $aircraft_manufacturer, $departure_airport_icao, $departure_airport_name, $departure_airport_city, $departure_airport_country, $departure_airport_time, $arrival_airport_icao, $arrival_airport_name, $arrival_airport_city, $arrival_airport_country, $arrival_airport_time, $route_stop, $date, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed, $squawk, $ModeS, $pilot_id, $pilot_name);
         if ($globalDebug) {
             echo $result . ')';
         }
     }
     return "success";
 }