-
Notifications
You must be signed in to change notification settings - Fork 161
/
Copy pathsearch-gpx.php
121 lines (114 loc) · 6.13 KB
/
search-gpx.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
require_once('require/class.Connection.php');
require_once('require/class.Spotter.php');
require_once('require/class.Language.php');
$Spotter = new Spotter();
if (isset($_GET['start_date'])) {
//for the date manipulation into the query
if($_GET['start_date'] != "" && $_GET['end_date'] != ""){
$start_date = $_GET['start_date'].":00";
$end_date = $_GET['end_date'].":00";
$sql_date = $start_date.",".$end_date;
} else if($_GET['start_date'] != ""){
$start_date = $_GET['start_date'].":00";
$sql_date = $start_date;
} else if($_GET['start_date'] == "" && $_GET['end_date'] != ""){
$end_date = date("Y-m-d H:i:s", strtotime("2014-04-12")).",".$_GET['end_date'].":00";
$sql_date = $end_date;
} else $sql_date = '';
} else $sql_date = '';
if (isset($_GET['highest_altitude'])) {
//for altitude manipulation
if($_GET['highest_altitude'] != "" && $_GET['lowest_altitude'] != ""){
$end_altitude = filter_input(INPUT_GET,'highest_altitude',FILTER_SANITIZE_NUMBER_INT);
$start_altitude = filter_input(INPUT_GET,'lowest_altitude',FILTER_SANITIZE_NUMBER_INT);
$sql_altitude = $start_altitude.",".$end_altitude;
} else if($_GET['highest_altitude'] != ""){
$end_altitude = filter_input(INPUT_GET,'highest_altitude',FILTER_SANITIZE_NUMBER_INT);
$sql_altitude = $end_altitude;
} else if($_GET['highest_altitude'] == "" && $_GET['lowest_altitude'] != ""){
$start_altitude = filter_input(INPUT_GET,'lowest_altitude',FILTER_SANITIZE_NUMBER_INT).",60000";
$sql_altitude = $start_altitude;
} else $sql_altitude = '';
} else $sql_altitude = '';
//calculuation for the pagination
if(!isset($_GET['limit']))
{
if (!isset($_GET['number_results'])) {
$limit_start = 0;
$limit_end = 25;
$absolute_difference = 25;
} else {
if ($_GET['number_results'] > 1000){
$_GET['number_results'] = 1000;
}
$limit_start = 0;
$limit_end = filter_input(INPUT_GET,'number_results',FILTER_SANITIZE_NUMBER_INT);
$absolute_difference = filter_input(INPUT_GET,'number_results',FILTER_SANITIZE_NUMBER_INT);
}
} else {
$limit_explode = explode(",", $_GET['limit']);
$limit_start = filter_var($limit_explode[0],FILTER_SANITIZE_NUMBER_INT);
$limit_end = filter_var($limit_explode[1],FILTER_SANITIZE_NUMBER_INT);
}
$absolute_difference = abs($limit_start - $limit_end);
$limit_next = $limit_end + $absolute_difference;
$limit_previous_1 = $limit_start - $absolute_difference;
$limit_previous_2 = $limit_end - $absolute_difference;
if ($_GET['download'] == "true")
{
header('Content-disposition: attachment; filename="flightairmap.gpx"');
}
header('Content-Type: text/xml');
if (isset($_GET['sort'])) $sort = $_GET['sort'];
else $sort = '';
$q = filter_input(INPUT_GET,'q',FILTER_SANITIZE_STRING);
$registration = filter_input(INPUT_GET,'registratrion',FILTER_SANITIZE_STRING);
$aircraft = filter_input(INPUT_GET,'aircraft',FILTER_SANITIZE_STRING);
$manufacturer = filter_input(INPUT_GET,'manufacturer',FILTER_SANITIZE_STRING);
$highlights = filter_input(INPUT_GET,'highlights',FILTER_SANITIZE_STRING);
$airline = filter_input(INPUT_GET,'airline',FILTER_SANITIZE_STRING);
$airline_country = filter_input(INPUT_GET,'airline_country',FILTER_SANITIZE_STRING);
$airline_type = filter_input(INPUT_GET,'airline_type',FILTER_SANITIZE_STRING);
$airport = filter_input(INPUT_GET,'airport',FILTER_SANITIZE_STRING);
$airport_country = filter_input(INPUT_GET,'airport_country',FILTER_SANITIZE_STRING);
$callsign = filter_input(INPUT_GET,'callsign',FILTER_SANITIZE_STRING);
$owner = filter_input(INPUT_GET,'owner',FILTER_SANITIZE_STRING);
$pilot_id = filter_input(INPUT_GET,'pilot_id',FILTER_SANITIZE_STRING);
$pilot_name = filter_input(INPUT_GET,'pilot_name',FILTER_SANITIZE_STRING);
$departure_airport_route = filter_input(INPUT_GET,'departure_airport_route',FILTER_SANITIZE_STRING);
$arrival_airport_route = filter_input(INPUT_GET,'arrival_airport_route',FILTER_SANITIZE_STRING);
$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,'');
$output = '<?xml version="1.0" encoding="UTF-8"?>';
$output .= '<gpx version="1.0">';
$output .= '<name>FlightAirMap GPX Feed</name>';
if (!empty($spotter_array))
{
foreach($spotter_array as $spotter_item)
{
$altitude = $spotter_item['altitude'].'00';
//waypoint plotting
$output .= '<trk>';
$output .= '<name>'.$spotter_item['ident'].' '.$spotter_item['airline_name'].' | '.$spotter_item['registration'].' '.$spotter_item['aircraft_name'].' ('.$spotter_item['aircraft_type'].') | '.$spotter_item['departure_airport'].' - '.$spotter_item['arrival_airport'].'</name>';
$output .= '<number>1</number>';
if ($spotter_item['waypoints'] != '') {
$output .= '<trkseg>';
$waypoint_pieces = explode(' ', $spotter_item['waypoints']);
$waypoint_pieces = array_chunk($waypoint_pieces, 2);
foreach ($waypoint_pieces as $waypoint_coordinate)
{
$output .= '<trkpt lat="'.$waypoint_coordinate[0].'" lon="'.$waypoint_coordinate[1].'"><ele>'.$altitude.'</ele><time>'.date("c", strtotime($spotter_item['date_iso_8601'])).'</time></trkpt>';
}
$output .= '</trkseg>';
}
$output .= '</trk>';
//location of aircraft
$output .= '<wpt lat="'.$spotter_item['latitude'].'" lon="'.$spotter_item['longitude'].'">';
$output .= '<ele>'.$altitude.'</ele>';
$output .= '<name>Ident: '.$spotter_item['ident'].' | Registration: '.$spotter_item['registration'].' | Aircraft: '.$spotter_item['aircraft_name'].' ('.$spotter_item['aircraft_type'].') | Airline: '.$spotter_item['airline_name'].' | Route: '.$spotter_item['departure_airport_city'].', '.$spotter_item['departure_airport_name'].', '.$spotter_item['departure_airport_country'].' ('.$spotter_item['departure_airport'].') - '.$spotter_item['arrival_airport_city'].', '.$spotter_item['arrival_airport_name'].', '.$spotter_item['arrival_airport_country'].' ('.$spotter_item['arrival_airport'].') | Date: '.date("D M j, Y, g:i a T", strtotime($spotter_item['date_iso_8601'])).'</name>';
$output .= '</wpt>';
}
}
$output .= '</gpx>';
print $output;
?>