Merge pull request #456 from Struart88/patch-2
[FlightAirMap.git] / search-ajax.php
blob750e53f8433274c612d33af08c29c493f51ba627
1 <?php
2 require_once('require/class.Connection.php');
3 require_once('require/class.Spotter.php');
4 require_once('require/class.Stats.php');
5 require_once('require/class.Language.php');
6 $Stats = new Stats();
7 $Spotter = new Spotter();
8 $orderby = $Spotter->getOrderBy();
10 $ask = filter_input(INPUT_GET,'ask',FILTER_SANITIZE_STRING);
11 if ($ask == 'aircraftsdetected') {
12 require_once('require/class.SpotterLive.php');
13 $SpotterLive = new SpotterLive();
14 $flightcnt = $SpotterLive->getLiveSpotterCount();
15 echo json_encode($flightcnt);
16 } elseif ($ask == 'trackersdetected') {
17 require_once('require/class.TrackerLive.php');
18 $TrackerLive = new TrackerLive();
19 $trackercnt = $TrackerLive->getLiveTrackerCount();
20 echo json_encode($trackercnt);
21 } elseif ($ask == 'marinesdetected') {
22 require_once('require/class.MarineLive.php');
23 $MarineLive = new MarineLive();
24 $marinecnt = $MarineLive->getLiveMarineCount();
25 echo json_encode($marinecnt);
26 } elseif ($ask == 'manufacturer') {
27 $manufacturers = $Stats->getAllManufacturers();
28 if (empty($manufacturers)) $manufacturers = $Spotter->getAllManufacturers();
29 $all_manufacturers = array();
30 foreach($manufacturers as $manufacturer)
32 $all_manufacturers[] = array('value' => $manufacturer['aircraft_manufacturer'], 'id' => strtolower(str_replace(' ','-',$manufacturer['aircraft_manufacturer'])));
34 echo json_encode($all_manufacturers);
35 } elseif ($ask == 'aircrafttypes') {
36 $aircraft_types = $Stats->getAllAircraftTypes();
37 if (empty($aircraft_types)) $aircraft_types = $Spotter->getAllAircraftTypes();
38 $all_aircraft_types = array();
39 foreach($aircraft_types as $aircraft_type)
41 $all_aircraft_types[] = array('id' => $aircraft_type['aircraft_icao'], 'value' => $aircraft_type['aircraft_name'].' ('.$aircraft_type['aircraft_icao'].')');
43 echo json_encode($all_aircraft_types);
44 } elseif ($ask == 'airlinenames') {
45 $airline_names = $Stats->getAllAirlineNames();
46 $all_airline_names = array();
47 foreach($airline_names as $airline_name)
49 $all_airline_names[] = array('id' => $airline_name['airline_icao'], 'value' => $airline_name['airline_name'].' ('.$airline_name['airline_icao'].')');
51 echo json_encode($all_airline_names);
52 } elseif ($ask == 'airlinecountries') {
53 $airline_countries = $Spotter->getAllAirlineCountries();
54 $all_airline_countries = array();
55 foreach($airline_countries as $airline_country)
57 $all_airline_countries[] = array('id' => $airline_country['airline_country'], 'value' => $airline_country['airline_country']);
59 echo json_encode($all_airline_countries);
60 } elseif ($ask == 'airportnames' || $ask == 'departureairportnames' || $ask == 'arrivalairportnames') {
61 $airport_names = $Stats->getAllAirportNames();
62 if (empty($airport_names)) $airport_names = $Spotter->getAllAirportNames();
63 ksort($airport_names);
64 $all_airport_names = array();
65 foreach($airport_names as $airport_name)
67 $all_airport_names[] = array('id' => $airport_name['airport_icao'], 'value' => $airport_name['airport_city'].', '.$airport_name['airport_name'].', '.$airport_name['airport_country'].' ('.$airport_name['airport_icao'].')');
69 echo json_encode($all_airport_names);
70 } elseif ($ask == 'airportcountries') {
71 $airport_countries = $Spotter->getAllAirportCountries();
72 $all_airport_countries = array();
73 foreach($airport_countries as $airport_country)
75 $all_airport_countries[] = array('id' => $airport_country['airport_country'], 'value' => $airport_country['airport_country']);
77 echo json_encode($all_airport_countries);