Merge pull request #456 from Struart88/patch-2
[FlightAirMap.git] / search-xml.php
blob2ae8b77652b42d9f0d02a536a68c2e566a785f73
1 <?php
2 require_once('require/class.Connection.php');
3 require_once('require/class.Spotter.php');
4 require_once('require/class.Language.php');
5 $Spotter = new Spotter();
6 if (isset($_GET['start_date'])) {
7 //for the date manipulation into the query
8 if($_GET['start_date'] != "" && $_GET['end_date'] != ""){
9 $start_date = date("Y-m-d",strtotime($_GET['start_date']))." 00:00:00";
10 $end_date = date("Y-m-d",strtotime($_GET['end_date']))." 00:00:00";
11 $sql_date = $start_date.",".$end_date;
12 } else if($_GET['start_date'] != ""){
13 $start_date = date("Y-m-d",strtotime($_GET['start_date']))." 00:00:00";
14 $sql_date = $start_date;
15 } else if($_GET['start_date'] == "" && $_GET['end_date'] != ""){
16 $end_date = date("Y-m-d H:i:s", strtotime("2014-04-12")).",".date("Y-m-d",strtotime($_GET['end_date']))." 00:00:00";
17 $sql_date = $end_date;
18 } else $sql_date = '';
19 } else $sql_date = '';
21 if (isset($_GET['highest_altitude'])) {
22 //for altitude manipulation
23 if($_GET['highest_altitude'] != "" && $_GET['lowest_altitude'] != ""){
24 $end_altitude = filter_input(INPUT_GET,'highest_altitude',FILTER_SANITIZE_NUMBER_INT);
25 $start_altitude = filter_input(INPUT_GET,'lowest_altitude',FILTER_SANITIZE_NUMBER_INT);
26 $sql_altitude = $start_altitude.",".$end_altitude;
27 } else if($_GET['highest_altitude'] != ""){
28 $end_altitude = filter_input(INPUT_GET,'highest_altitude',FILTER_SANITIZE_NUMBER_INT);
29 $sql_altitude = $end_altitude;
30 } else if($_GET['highest_altitude'] == "" && $_GET['lowest_altitude'] != ""){
31 $start_altitude = filter_input(INPUT_GET,'lowest_altitude',FILTER_SANITIZE_NUMBER_INT).",60000";
32 $sql_altitude = $start_altitude;
33 } else $sql_altitude = '';
34 } else $sql_altitude = '';
36 //calculuation for the pagination
37 if(!isset($_GET['limit'])) {
38 if (!isset($_GET['number_results'])) {
39 $limit_start = 0;
40 $limit_end = 25;
41 $absolute_difference = 25;
42 } else {
43 if ($_GET['number_results'] > 1000){
44 $_GET['number_results'] = 1000;
46 $limit_start = 0;
47 $limit_end = filter_input(INPUT_GET,'number_results',FILTER_SANITIZE_NUMBER_INT);
48 $absolute_difference = filter_input(INPUT_GET,'number_results',FILTER_SANITIZE_NUMBER_INT);
50 } else {
51 $limit_explode = explode(",", $_GET['limit']);
52 $limit_start = filter_var($limit_explode[0],FILTER_SANITIZE_NUMBER_INT);
53 $limit_end = filter_var($limit_explode[1],FILTER_SANITIZE_NUMBER_INT);
56 $absolute_difference = abs($limit_start - $limit_end);
57 $limit_next = $limit_end + $absolute_difference;
58 $limit_previous_1 = $limit_start - $absolute_difference;
59 $limit_previous_2 = $limit_end - $absolute_difference;
61 if ($_GET['download'] == "true")
63 header('Content-disposition: attachment; filename="flightairmap.xml"');
66 header('Content-Type: application/xml');
68 if (isset($_GET['sort'])) $sort = $_GET['sort'];
69 else $sort = '';
70 $q = filter_input(INPUT_GET,'q',FILTER_SANITIZE_STRING);
71 $id = filter_input(INPUT_GET,'id',FILTER_SANITIZE_NUMBER_INT);
72 $registration = filter_input(INPUT_GET,'registratrion',FILTER_SANITIZE_STRING);
73 $aircraft = filter_input(INPUT_GET,'aircraft',FILTER_SANITIZE_STRING);
74 $manufacturer = filter_input(INPUT_GET,'manufacturer',FILTER_SANITIZE_STRING);
75 $highlights = filter_input(INPUT_GET,'highlights',FILTER_SANITIZE_STRING);
76 $airline = filter_input(INPUT_GET,'airline',FILTER_SANITIZE_STRING);
77 $airline_country = filter_input(INPUT_GET,'airline_country',FILTER_SANITIZE_STRING);
78 $airline_type = filter_input(INPUT_GET,'airline_type',FILTER_SANITIZE_STRING);
79 $airport = filter_input(INPUT_GET,'airport',FILTER_SANITIZE_STRING);
80 $airport_country = filter_input(INPUT_GET,'airport_country',FILTER_SANITIZE_STRING);
81 $callsign = filter_input(INPUT_GET,'callsign',FILTER_SANITIZE_STRING);
82 $owner = filter_input(INPUT_GET,'owner',FILTER_SANITIZE_STRING);
83 $pilot_id = filter_input(INPUT_GET,'pilot_id',FILTER_SANITIZE_STRING);
84 $pilot_name = filter_input(INPUT_GET,'pilot_name',FILTER_SANITIZE_STRING);
85 $departure_airport_route = filter_input(INPUT_GET,'departure_airport_route',FILTER_SANITIZE_STRING);
86 $arrival_airport_route = filter_input(INPUT_GET,'arrival_airport_route',FILTER_SANITIZE_STRING);
87 if ($id != '') {
88 $spotter_array = $Spotter->getSpotterDataByID($id);
89 } else {
90 $spotter_array = $Spotter->searchSpotterData($q,$registration,$aircraft,strtolower(str_replace("-", " ", $manufacturer)),$highlights,$airline,$airline_country,$airline_type,$airport,$airport_country,$callsign,$departure_airport_route,$arrival_airport_route,$owner,$pilot_id,$pilot_name,$sql_altitude,$sql_date,$limit_start.",".$absolute_difference,$sort,'');
92 $output = '<?xml version="1.0" encoding="UTF-8" ?>';
93 $output .= '<flightairmap>';
94 $output .= '<title>'.$globalName.' XML Feed</title>';
95 $output .= '<link>http://'.$_SERVER['HTTP_HOST'].$globalURL.'</link>';
96 $output .= '<aircrafts>';
97 if (!empty($spotter_array)) {
98 foreach($spotter_array as $spotter_item) {
99 $output .= '<aircraft>';
100 $output .= '<id>'.$spotter_item['spotter_id'].'</id>';
101 $output .= '<ident>'.$spotter_item['ident'].'</ident>';
102 $output .= '<registration>'.$spotter_item['registration'].'</registration>';
103 $output .= '<aircraft_icao>'.$spotter_item['aircraft_type'].'</aircraft_icao>';
104 $output .= '<aircraft_name>'.$spotter_item['aircraft_name'].'</aircraft_name>';
105 $output .= '<aircraft_manufacturer>'.$spotter_item['aircraft_manufacturer'].'</aircraft_manufacturer>';
106 $output .= '<airline_name>'.$spotter_item['airline_name'].'</airline_name>';
107 $output .= '<airline_icao>'.$spotter_item['airline_icao'].'</airline_icao>';
108 if (isset($spotter_item['airline_iata'])) {
109 $output .= '<airline_iata>'.$spotter_item['airline_iata'].'</airline_iata>';
111 $output .= '<airline_country>'.$spotter_item['airline_country'].'</airline_country>';
112 if (isset($spotter_item['airline_callsign'])) {
113 $output .= '<airline_callsign>'.$spotter_item['airline_callsign'].'</airline_callsign>';
115 $output .= '<airline_type>'.$spotter_item['airline_type'].'</airline_type>';
116 $output .= '<departure_airport_city>'.$spotter_item['departure_airport_city'].'</departure_airport_city>';
117 $output .= '<departure_airport_country>'.$spotter_item['departure_airport_country'].'</departure_airport_country>';
118 $output .= '<departure_airport_iata>'.$spotter_item['departure_airport_iata'].'</departure_airport_iata>';
119 $output .= '<departure_airport_icao>'.$spotter_item['departure_airport_icao'].'</departure_airport_icao>';
120 $output .= '<departure_airport_latitude>'.$spotter_item['departure_airport_latitude'].'</departure_airport_latitude>';
121 $output .= '<departure_airport_longitude>'.$spotter_item['departure_airport_longitude'].'</departure_airport_longitude>';
122 $output .= '<departure_airport_altitude>'.$spotter_item['departure_airport_altitude'].'</departure_airport_altitude>';
123 $output .= '<arrival_airport_city>'.$spotter_item['arrival_airport_city'].'</arrival_airport_city>';
124 $output .= '<arrival_airport_country>'.$spotter_item['arrival_airport_country'].'</arrival_airport_country>';
125 $output .= '<arrival_airport_iata>'.$spotter_item['arrival_airport_iata'].'</arrival_airport_iata>';
126 $output .= '<arrival_airport_icao>'.$spotter_item['arrival_airport_icao'].'</arrival_airport_icao>';
127 $output .= '<arrival_airport_latitude>'.$spotter_item['arrival_airport_latitude'].'</arrival_airport_latitude>';
128 $output .= '<arrival_airport_longitude>'.$spotter_item['arrival_airport_longitude'].'</arrival_airport_longitude>';
129 $output .= '<arrival_airport_altitude>'.$spotter_item['arrival_airport_altitude'].'</arrival_airport_altitude>';
130 $output .= '<latitude>'.$spotter_item['latitude'].'</latitude>';
131 $output .= '<longitude>'.$spotter_item['longitude'].'</longitude>';
132 $output .= '<altitude>'.$spotter_item['altitude'].'</altitude>';
133 $output .= '<ground_speed>'.$spotter_item['ground_speed'].'</ground_speed>';
134 $output .= '<heading>'.$spotter_item['heading'].'</heading>';
135 $output .= '<heading_name>'.$spotter_item['heading_name'].'</heading_name>';
136 $output .= '<waypoints>'.$spotter_item['waypoints'].'</waypoints>';
137 $output .= '<date>'.date("c", strtotime($spotter_item['date_iso_8601'])).'</date>';
138 $output .= '</aircraft>';
141 $output .= '</aircrafts>';
142 $output .= '</flightairmap>';
143 print $output;