1
|
|
|
<?php |
2
|
|
|
class SpotterArchive { |
3
|
|
|
public $global_query = "SELECT spotter_archive.* FROM spotter_archive"; |
4
|
|
|
public $db; |
5
|
|
|
|
6
|
|
|
public function __construct($dbc = null) { |
7
|
|
|
$Connection = new Connection($dbc); |
8
|
|
|
$this->db = $Connection->db; |
9
|
|
|
if ($this->db === null) die('Error: No DB connection. (SpotterArchive)'); |
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Get SQL query part for filter used |
14
|
|
|
* @param Array $filter the filter |
15
|
|
|
* @return Array the SQL part |
16
|
|
|
*/ |
17
|
|
|
public function getFilter($filter = array(),$where = false,$and = false) { |
18
|
|
|
global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver; |
19
|
|
|
$filters = array(); |
20
|
|
|
if (is_array($globalStatsFilters) && isset($globalStatsFilters[$globalFilterName])) { |
21
|
|
|
if (isset($globalStatsFilters[$globalFilterName][0]['source'])) { |
22
|
|
|
$filters = $globalStatsFilters[$globalFilterName]; |
23
|
|
|
} else { |
24
|
|
|
$filter = array_merge($filter,$globalStatsFilters[$globalFilterName]); |
25
|
|
|
} |
26
|
|
|
} |
27
|
|
|
if (isset($filter[0]['source'])) { |
28
|
|
|
$filters = array_merge($filters,$filter); |
29
|
|
|
} |
30
|
|
|
if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter); |
31
|
|
|
$filter_query_join = ''; |
32
|
|
|
$filter_query_where = ''; |
33
|
|
|
foreach($filters as $flt) { |
34
|
|
|
if (isset($flt['airlines']) && !empty($flt['airlines'])) { |
35
|
|
|
if ($flt['airlines'][0] != '' && $flt['airlines'][0] != 'all') { |
36
|
|
|
if (isset($flt['source'])) { |
37
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_icao IN ('".implode("','",$flt['airlines'])."') AND spotter_archive_output.format_source IN ('".implode("','",$flt['source'])."')) saff ON saff.flightaware_id = spotter_archive_output.flightaware_id"; |
38
|
|
|
} else { |
39
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_icao IN ('".implode("','",$flt['airlines'])."')) saff ON saff.flightaware_id = spotter_archive_output.flightaware_id"; |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
if (isset($flt['pilots_id']) && !empty($flt['pilots_id'])) { |
44
|
|
|
if (isset($flt['source'])) { |
45
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.pilot_id IN ('".implode("','",$flt['pilots_id'])."') AND spotter_archive_output.format_source IN ('".implode("','",$flt['source'])."')) sp ON sp.flightaware_id = spotter_archive_output.flightaware_id"; |
46
|
|
|
} else { |
47
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.pilot_id IN ('".implode("','",$flt['pilots_id'])."')) sp ON sp.flightaware_id = spotter_archive_output.flightaware_id"; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
if (isset($flt['idents']) && !empty($flt['idents'])) { |
51
|
|
|
if (isset($flt['source'])) { |
52
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.ident IN ('".implode("','",$flt['idents'])."') AND spotter_archive_output.format_source IN ('".implode("','",$flt['source'])."')) spi ON spi.flightaware_id = spotter_archive_output.flightaware_id"; |
53
|
|
|
} else { |
54
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.ident IN ('".implode("','",$flt['idents'])."')) spi ON spi.flightaware_id = spotter_archive_output.flightaware_id"; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
if (isset($flt['registrations']) && !empty($flt['registrations'])) { |
58
|
|
|
if (isset($flt['source'])) { |
59
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.registration IN ('".implode("','",$flt['registrations'])."') AND spotter_archive_output.format_source IN ('".implode("','",$flt['source'])."')) sre ON sre.flightaware_id = spotter_archive_output.flightaware_id"; |
60
|
|
|
} else { |
61
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.registration IN ('".implode("','",$flt['registrations'])."')) sre ON sre.flightaware_id = spotter_archive_output.flightaware_id"; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
if ((isset($flt['airlines']) && empty($flt['airlines']) && isset($flt['pilots_id']) && empty($flt['pilots_id']) && isset($flt['idents']) && empty($flt['idents']) && isset($flt['registrations']) && empty($flt['registrations'])) || (!isset($flt['airlines']) && !isset($flt['pilots_id']) && !isset($flt['idents']) && !isset($flt['registrations']))) { |
65
|
|
|
if (isset($flt['source'])) { |
66
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_output.format_source IN ('".implode("','",$flt['source'])."')) saa ON saa.flightaware_id = spotter_archive_output.flightaware_id"; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
if (isset($filter['airlines']) && !empty($filter['airlines'])) { |
71
|
|
|
if ($filter['airlines'][0] != '' && $filter['airlines'][0] != 'all') { |
72
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) saf ON saf.flightaware_id = spotter_archive_output.flightaware_id"; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) { |
76
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_archive_output.flightaware_id "; |
77
|
|
|
} |
78
|
|
|
if (isset($filter['pilots_id']) && !empty($filter['pilots_id'])) { |
79
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.pilot_id IN ('".implode("','",$filter['pilots_id'])."')) spi ON spi.flightaware_id = spotter_archive_output.flightaware_id"; |
80
|
|
|
} |
81
|
|
|
if (isset($filter['source']) && !empty($filter['source'])) { |
82
|
|
|
if (count($filter['source']) == 1) { |
83
|
|
|
$filter_query_where .= " AND format_source = '".$filter['source'][0]."'"; |
84
|
|
|
} else { |
85
|
|
|
$filter_query_where .= " AND format_source IN ('".implode("','",$filter['source'])."')"; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
if (isset($filter['ident']) && !empty($filter['ident'])) { |
89
|
|
|
$filter_query_where .= " AND ident = '".$filter['ident']."'"; |
90
|
|
|
} |
91
|
|
|
if (isset($filter['id']) && !empty($filter['id'])) { |
92
|
|
|
$filter_query_where .= " AND flightaware_id = '".$filter['id']."'"; |
93
|
|
|
} |
94
|
|
|
if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) { |
95
|
|
|
$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
96
|
|
|
} |
97
|
|
|
if ((isset($filter['year']) && $filter['year'] != '') || (isset($filter['month']) && $filter['month'] != '') || (isset($filter['day']) && $filter['day'] != '')) { |
98
|
|
|
$filter_query_date = ''; |
99
|
|
|
if (isset($filter['year']) && $filter['year'] != '') { |
100
|
|
|
if ($globalDBdriver == 'mysql') { |
101
|
|
|
$filter_query_date .= " AND YEAR(spotter_archive_output.date) = '".$filter['year']."'"; |
102
|
|
|
} else { |
103
|
|
|
$filter_query_date .= " AND EXTRACT(YEAR FROM spotter_archive_output.date) = '".$filter['year']."'"; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
if (isset($filter['month']) && $filter['month'] != '') { |
107
|
|
|
if ($globalDBdriver == 'mysql') { |
108
|
|
|
$filter_query_date .= " AND MONTH(spotter_archive_output.date) = '".$filter['month']."'"; |
109
|
|
|
} else { |
110
|
|
|
$filter_query_date .= " AND EXTRACT(MONTH FROM spotter_archive_output.date) = '".$filter['month']."'"; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
if (isset($filter['day']) && $filter['day'] != '') { |
114
|
|
|
if ($globalDBdriver == 'mysql') { |
115
|
|
|
$filter_query_date .= " AND DAY(spotter_archive_output.date) = '".$filter['day']."'"; |
116
|
|
|
} else { |
117
|
|
|
$filter_query_date .= " AND EXTRACT(DAY FROM spotter_archive_output.date) = '".$filter['day']."'"; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output".preg_replace('/^ AND/',' WHERE',$filter_query_date).") sd ON sd.flightaware_id = spotter_archive_output.flightaware_id"; |
121
|
|
|
} |
122
|
|
|
if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE'; |
123
|
|
|
elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND'; |
124
|
|
|
if ($filter_query_where != '') { |
125
|
|
|
$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where); |
126
|
|
|
} |
127
|
|
|
$filter_query = $filter_query_join.$filter_query_where; |
128
|
|
|
return $filter_query; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
// Spotter_archive |
132
|
|
|
public function 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 = '', $real_altitude = '',$heading = '', $ground_speed = '', $squawk = '', $ModeS = '', $pilot_id = '', $pilot_name = '',$verticalrate = '',$format_source = '', $source_name = '', $over_country = '') { |
133
|
|
|
require_once(dirname(__FILE__).'/class.Spotter.php'); |
134
|
|
|
if ($over_country == '') { |
135
|
|
|
$Spotter = new Spotter($this->db); |
136
|
|
|
$data_country = $Spotter->getCountryFromLatitudeLongitude($latitude,$longitude); |
137
|
|
|
if (!empty($data_country)) $country = $data_country['iso2']; |
138
|
|
|
else $country = ''; |
139
|
|
|
} else $country = $over_country; |
140
|
|
|
if ($airline_type === NULL) $airline_type =''; |
141
|
|
|
|
142
|
|
|
//if ($country == '') echo "\n".'************ UNKNOW COUNTRY ****************'."\n"; |
143
|
|
|
//else echo "\n".'*/*/*/*/*/*/*/ Country : '.$country.' */*/*/*/*/*/*/*/*/'."\n"; |
144
|
|
|
|
145
|
|
|
// Route is not added in spotter_archive |
146
|
|
|
$query = "INSERT INTO spotter_archive (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, ground_speed, squawk, ModeS, pilot_id, pilot_name, verticalrate,format_source,over_country,source_name,real_altitude) |
147
|
|
|
VALUES (: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, :ground_speed, :squawk, :ModeS, :pilot_id, :pilot_name, :verticalrate, :format_source, :over_country, :source_name,:real_altitude)"; |
148
|
|
|
|
149
|
|
|
$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_name' => $aircraft_name, ':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, ':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_name' => $arrival_airport_name, ':arrival_airport_city' => $arrival_airport_city, ':arrival_airport_country' => $arrival_airport_country, ':arrival_airport_time' => $arrival_airport_time, ':route_stop' => $route_stop, ':date' => $date,':latitude' => $latitude, ':longitude' => $longitude, ':waypoints' => $waypoints, ':altitude' => $altitude, ':heading' => $heading, ':ground_speed' => $ground_speed, ':squawk' => $squawk, ':ModeS' => $ModeS, ':pilot_id' => $pilot_id, ':pilot_name' => $pilot_name, ':verticalrate' => $verticalrate, ':format_source' => $format_source, ':over_country' => $country, ':source_name' => $source_name,':real_altitude' => $real_altitude); |
150
|
|
|
try { |
151
|
|
|
$sth = $this->db->prepare($query); |
152
|
|
|
$sth->execute($query_values); |
153
|
|
|
$sth->closeCursor(); |
154
|
|
|
} catch(PDOException $e) { |
155
|
|
|
return "error : ".$e->getMessage(); |
156
|
|
|
} |
157
|
|
|
return "success"; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Gets all the spotter information based on a particular callsign |
163
|
|
|
* |
164
|
|
|
* @return Array the spotter information |
165
|
|
|
* |
166
|
|
|
*/ |
167
|
|
|
public function getLastArchiveSpotterDataByIdent($ident) { |
168
|
|
|
$Spotter = new Spotter($this->db); |
169
|
|
|
date_default_timezone_set('UTC'); |
170
|
|
|
|
171
|
|
|
$ident = filter_var($ident, FILTER_SANITIZE_STRING); |
172
|
|
|
//$query = "SELECT spotter_archive.* FROM spotter_archive INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_archive l WHERE l.ident = :ident GROUP BY l.flightaware_id) s on spotter_archive.flightaware_id = s.flightaware_id AND spotter_archive.date = s.maxdate LIMIT 1"; |
173
|
|
|
$query = "SELECT spotter_archive.* FROM spotter_archive WHERE ident = :ident ORDER BY date DESC LIMIT 1"; |
174
|
|
|
|
175
|
|
|
$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident)); |
176
|
|
|
|
177
|
|
|
return $spotter_array; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Gets last the spotter information based on a particular id |
183
|
|
|
* |
184
|
|
|
* @return Array the spotter information |
185
|
|
|
* |
186
|
|
|
*/ |
187
|
|
|
public function getLastArchiveSpotterDataById($id) { |
188
|
|
|
$Spotter = new Spotter($this->db); |
189
|
|
|
date_default_timezone_set('UTC'); |
190
|
|
|
$id = filter_var($id, FILTER_SANITIZE_STRING); |
191
|
|
|
//$query = SpotterArchive->$global_query." WHERE spotter_archive.flightaware_id = :id"; |
192
|
|
|
//$query = "SELECT spotter_archive.* FROM spotter_archive INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_archive l WHERE l.flightaware_id = :id GROUP BY l.flightaware_id) s on spotter_archive.flightaware_id = s.flightaware_id AND spotter_archive.date = s.maxdate LIMIT 1"; |
193
|
|
|
$query = "SELECT * FROM spotter_archive WHERE flightaware_id = :id ORDER BY date DESC LIMIT 1"; |
194
|
|
|
|
195
|
|
|
// $spotter_array = Spotter->getDataFromDB($query,array(':id' => $id)); |
196
|
|
|
/* |
197
|
|
|
try { |
198
|
|
|
$Connection = new Connection(); |
199
|
|
|
$sth = Connection->$db->prepare($query); |
200
|
|
|
$sth->execute(array(':id' => $id)); |
201
|
|
|
} catch(PDOException $e) { |
202
|
|
|
return "error"; |
203
|
|
|
} |
204
|
|
|
$spotter_array = $sth->fetchAll(PDO->FETCH_ASSOC); |
205
|
|
|
*/ |
206
|
|
|
$spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id)); |
207
|
|
|
|
208
|
|
|
return $spotter_array; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Gets all the spotter information based on a particular id |
213
|
|
|
* |
214
|
|
|
* @return Array the spotter information |
215
|
|
|
* |
216
|
|
|
*/ |
217
|
|
|
public function getAllArchiveSpotterDataById($id) { |
218
|
|
|
date_default_timezone_set('UTC'); |
219
|
|
|
$id = filter_var($id, FILTER_SANITIZE_STRING); |
220
|
|
|
$query = $this->global_query." WHERE spotter_archive.flightaware_id = :id ORDER BY date"; |
221
|
|
|
|
222
|
|
|
// $spotter_array = Spotter->getDataFromDB($query,array(':id' => $id)); |
223
|
|
|
|
224
|
|
|
try { |
225
|
|
|
$sth = $this->db->prepare($query); |
226
|
|
|
$sth->execute(array(':id' => $id)); |
227
|
|
|
} catch(PDOException $e) { |
228
|
|
|
echo $e->getMessage(); |
229
|
|
|
die; |
230
|
|
|
} |
231
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
232
|
|
|
|
233
|
|
|
return $spotter_array; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Gets coordinate & time spotter information based on a particular id |
238
|
|
|
* |
239
|
|
|
* @return Array the spotter information |
240
|
|
|
* |
241
|
|
|
*/ |
242
|
|
|
public function getCoordArchiveSpotterDataById($id) { |
243
|
|
|
date_default_timezone_set('UTC'); |
244
|
|
|
$id = filter_var($id, FILTER_SANITIZE_STRING); |
245
|
|
|
$query = "SELECT spotter_archive.latitude, spotter_archive.longitude, spotter_archive.date FROM spotter_archive WHERE spotter_archive.flightaware_id = :id ORDER by spotter_archive.date ASC"; |
246
|
|
|
try { |
247
|
|
|
$sth = $this->db->prepare($query); |
248
|
|
|
$sth->execute(array(':id' => $id)); |
249
|
|
|
} catch(PDOException $e) { |
250
|
|
|
echo $e->getMessage(); |
251
|
|
|
die; |
252
|
|
|
} |
253
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
254
|
|
|
return $spotter_array; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* Gets altitude information based on a particular callsign |
260
|
|
|
* |
261
|
|
|
* @return Array the spotter information |
262
|
|
|
* |
263
|
|
|
*/ |
264
|
|
|
public function getAltitudeArchiveSpotterDataByIdent($ident) { |
265
|
|
|
|
266
|
|
|
date_default_timezone_set('UTC'); |
267
|
|
|
|
268
|
|
|
$ident = filter_var($ident, FILTER_SANITIZE_STRING); |
269
|
|
|
$query = "SELECT spotter_archive.altitude, spotter_archive.date FROM spotter_archive WHERE spotter_archive.ident = :ident AND spotter_archive.latitude <> 0 AND spotter_archive.longitude <> 0 ORDER BY date"; |
270
|
|
|
|
271
|
|
|
try { |
272
|
|
|
$sth = $this->db->prepare($query); |
273
|
|
|
$sth->execute(array(':ident' => $ident)); |
274
|
|
|
} catch(PDOException $e) { |
275
|
|
|
echo $e->getMessage(); |
276
|
|
|
die; |
277
|
|
|
} |
278
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
279
|
|
|
|
280
|
|
|
return $spotter_array; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* Gets altitude information based on a particular id |
285
|
|
|
* |
286
|
|
|
* @return Array the spotter information |
287
|
|
|
* |
288
|
|
|
*/ |
289
|
|
|
public function getAltitudeArchiveSpotterDataById($id) { |
290
|
|
|
|
291
|
|
|
date_default_timezone_set('UTC'); |
292
|
|
|
|
293
|
|
|
$id = filter_var($id, FILTER_SANITIZE_STRING); |
294
|
|
|
$query = "SELECT spotter_archive.altitude, spotter_archive.date FROM spotter_archive WHERE spotter_archive.flightaware_id = :id AND spotter_archive.latitude <> 0 AND spotter_archive.longitude <> 0 ORDER BY date"; |
295
|
|
|
|
296
|
|
|
try { |
297
|
|
|
$sth = $this->db->prepare($query); |
298
|
|
|
$sth->execute(array(':id' => $id)); |
299
|
|
|
} catch(PDOException $e) { |
300
|
|
|
echo $e->getMessage(); |
301
|
|
|
die; |
302
|
|
|
} |
303
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
304
|
|
|
|
305
|
|
|
return $spotter_array; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* Gets altitude & speed information based on a particular id |
310
|
|
|
* |
311
|
|
|
* @return Array the spotter information |
312
|
|
|
* |
313
|
|
|
*/ |
314
|
|
|
public function getAltitudeSpeedArchiveSpotterDataById($id) { |
315
|
|
|
date_default_timezone_set('UTC'); |
316
|
|
|
$id = filter_var($id, FILTER_SANITIZE_STRING); |
317
|
|
|
$query = "SELECT spotter_archive.altitude, spotter_archive.real_altitude,spotter_archive.ground_speed, spotter_archive.date FROM spotter_archive WHERE spotter_archive.flightaware_id = :id ORDER BY date"; |
318
|
|
|
try { |
319
|
|
|
$sth = $this->db->prepare($query); |
320
|
|
|
$sth->execute(array(':id' => $id)); |
321
|
|
|
} catch(PDOException $e) { |
322
|
|
|
echo $e->getMessage(); |
323
|
|
|
die; |
324
|
|
|
} |
325
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
326
|
|
|
return $spotter_array; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* Gets altitude information based on a particular callsign |
331
|
|
|
* |
332
|
|
|
* @return Array the spotter information |
333
|
|
|
* |
334
|
|
|
*/ |
335
|
|
|
public function getLastAltitudeArchiveSpotterDataByIdent($ident) { |
336
|
|
|
date_default_timezone_set('UTC'); |
337
|
|
|
$ident = filter_var($ident, FILTER_SANITIZE_STRING); |
338
|
|
|
$query = "SELECT spotter_archive.altitude, spotter_archive.date FROM spotter_archive INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_archive l WHERE l.ident = :ident GROUP BY l.flightaware_id) s on spotter_archive.flightaware_id = s.flightaware_id AND spotter_archive.date = s.maxdate LIMIT 1"; |
339
|
|
|
// $query = "SELECT spotter_archive.altitude, spotter_archive.date FROM spotter_archive WHERE spotter_archive.ident = :ident"; |
340
|
|
|
try { |
341
|
|
|
$sth = $this->db->prepare($query); |
342
|
|
|
$sth->execute(array(':ident' => $ident)); |
343
|
|
|
} catch(PDOException $e) { |
344
|
|
|
echo $e->getMessage(); |
345
|
|
|
die; |
346
|
|
|
} |
347
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
348
|
|
|
return $spotter_array; |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
|
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
* Gets all the archive spotter information |
355
|
|
|
* |
356
|
|
|
* @return Array the spotter information |
357
|
|
|
* |
358
|
|
|
*/ |
359
|
|
|
public function getSpotterArchiveData($ident,$flightaware_id,$date) { |
360
|
|
|
$Spotter = new Spotter($this->db); |
361
|
|
|
$ident = filter_var($ident, FILTER_SANITIZE_STRING); |
362
|
|
|
$query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident AND l.flightaware_id = :flightaware_id AND l.date LIKE :date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate"; |
363
|
|
|
$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident,':flightaware_id' => $flightaware_id,':date' => $date.'%')); |
364
|
|
|
return $spotter_array; |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
public function deleteSpotterArchiveTrackData() { |
368
|
|
|
global $globalArchiveKeepTrackMonths, $globalDBdriver; |
369
|
|
|
if ($globalDBdriver == 'mysql') { |
370
|
|
|
$query = 'DELETE FROM spotter_archive WHERE spotter_archive.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$globalArchiveKeepTrackMonths.' MONTH) LIMIT 10000'; |
371
|
|
|
} else { |
372
|
|
|
$query = "DELETE FROM spotter_archive WHERE spotter_archive_id IN (SELECT spotter_archive_id FROM spotter_archive WHERE spotter_archive.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveKeepTrackMonths." MONTH' LIMIT 10000)"; |
373
|
|
|
} |
374
|
|
|
try { |
375
|
|
|
$sth = $this->db->prepare($query); |
376
|
|
|
$sth->execute(); |
377
|
|
|
} catch(PDOException $e) { |
378
|
|
|
echo $e->getMessage(); |
379
|
|
|
die; |
380
|
|
|
} |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* Gets Minimal Live Spotter data |
385
|
|
|
* |
386
|
|
|
* @return Array the spotter information |
387
|
|
|
* |
388
|
|
|
*/ |
389
|
|
|
public function getMinLiveSpotterData($begindate,$enddate,$filter = array()) { |
390
|
|
|
global $globalDBdriver, $globalLiveInterval; |
391
|
|
|
date_default_timezone_set('UTC'); |
392
|
|
|
|
393
|
|
|
$filter_query = ''; |
394
|
|
|
if (isset($filter['source']) && !empty($filter['source'])) { |
395
|
|
|
$filter_query .= " AND format_source IN ('".implode("','",$filter['source'])."') "; |
396
|
|
|
} |
397
|
|
|
// Use spotter_output also ? |
398
|
|
|
if (isset($filter['airlines']) && !empty($filter['airlines'])) { |
399
|
|
|
$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.flightaware_id = spotter_archive.flightaware_id "; |
400
|
|
|
} |
401
|
|
|
if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) { |
402
|
|
|
$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_archive.flightaware_id "; |
403
|
|
|
} |
404
|
|
|
if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) { |
405
|
|
|
$filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
//if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
409
|
|
|
if ($globalDBdriver == 'mysql') { |
410
|
|
|
$query = 'SELECT spotter_archive.date,spotter_archive.flightaware_id, spotter_archive.ident, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, a.aircraft_shadow,a.engine_type, a.engine_count, a.wake_category |
411
|
|
|
FROM spotter_archive |
412
|
|
|
INNER JOIN (SELECT * FROM aircraft) a on spotter_archive.aircraft_icao = a.icao |
413
|
|
|
WHERE spotter_archive.date BETWEEN '."'".$begindate."'".' AND '."'".$begindate."'".' |
414
|
|
|
'.$filter_query.' ORDER BY flightaware_id'; |
415
|
|
|
} else { |
416
|
|
|
$query = 'SELECT spotter_archive.flightaware_id, spotter_archive.date, spotter_archive.ident, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, a.aircraft_shadow,a.engine_type, a.engine_count, a.wake_category |
417
|
|
|
FROM spotter_archive |
418
|
|
|
INNER JOIN (SELECT * FROM aircraft) a on spotter_archive.aircraft_icao = a.icao |
419
|
|
|
WHERE spotter_archive.date BETWEEN '."'".$begindate."'".' AND '."'".$enddate."'".' |
420
|
|
|
'.$filter_query.' ORDER BY flightaware_id'; |
421
|
|
|
} |
422
|
|
|
//echo $query; |
423
|
|
|
try { |
424
|
|
|
$sth = $this->db->prepare($query); |
425
|
|
|
$sth->execute(); |
426
|
|
|
} catch(PDOException $e) { |
427
|
|
|
echo $e->getMessage(); |
428
|
|
|
die; |
429
|
|
|
} |
430
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
431
|
|
|
|
432
|
|
|
return $spotter_array; |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
/** |
436
|
|
|
* Gets Minimal Live Spotter data |
437
|
|
|
* |
438
|
|
|
* @return Array the spotter information |
439
|
|
|
* |
440
|
|
|
*/ |
441
|
|
|
public function getMinLiveSpotterDataPlayback($begindate,$enddate,$filter = array()) { |
442
|
|
|
global $globalDBdriver, $globalLiveInterval; |
443
|
|
|
date_default_timezone_set('UTC'); |
444
|
|
|
|
445
|
|
|
$filter_query = ''; |
446
|
|
|
if (isset($filter['source']) && !empty($filter['source'])) { |
447
|
|
|
$filter_query .= " AND format_source IN ('".implode("','",$filter['source'])."') "; |
448
|
|
|
} |
449
|
|
|
// Should use spotter_output also ? |
450
|
|
|
if (isset($filter['airlines']) && !empty($filter['airlines'])) { |
451
|
|
|
$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.flightaware_id = spotter_archive.flightaware_id "; |
452
|
|
|
} |
453
|
|
|
if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) { |
454
|
|
|
$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_archive.flightaware_id "; |
455
|
|
|
} |
456
|
|
|
if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) { |
457
|
|
|
$filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
//if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
461
|
|
|
if ($globalDBdriver == 'mysql') { |
462
|
|
|
/* |
463
|
|
|
$query = 'SELECT a.aircraft_shadow, spotter_archive.ident, spotter_archive.flightaware_id, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk |
464
|
|
|
FROM spotter_archive |
465
|
|
|
INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_archive l WHERE (l.date BETWEEN '."'".$begindate."'".' AND '."'".$enddate."'".') GROUP BY l.flightaware_id) s on spotter_archive.flightaware_id = s.flightaware_id AND spotter_archive.date = s.maxdate '.$filter_query.'LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_archive.aircraft_icao = a.icao'; |
466
|
|
|
*/ |
467
|
|
|
$query = 'SELECT a.aircraft_shadow, spotter_archive_output.ident, spotter_archive_output.flightaware_id, spotter_archive_output.aircraft_icao, spotter_archive_output.departure_airport_icao as departure_airport, spotter_archive_output.arrival_airport_icao as arrival_airport, spotter_archive_output.latitude, spotter_archive_output.longitude, spotter_archive_output.altitude, spotter_archive_output.heading, spotter_archive_output.ground_speed, spotter_archive_output.squawk |
468
|
|
|
FROM spotter_archive_output |
469
|
|
|
LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_archive_output.aircraft_icao = a.icao |
470
|
|
|
WHERE (spotter_archive_output.date BETWEEN '."'".$begindate."'".' AND '."'".$enddate."'".') |
471
|
|
|
'.$filter_query.' GROUP BY spotter_archive_output.flightaware_id, spotter_archive_output.ident, spotter_archive_output.aircraft_icao, spotter_archive_output.departure_airport_icao, spotter_archive_output.arrival_airport_icao, spotter_archive_output.latitude, spotter_archive_output.longitude, spotter_archive_output.altitude, spotter_archive_output.heading, spotter_archive_output.ground_speed, spotter_archive_output.squawk, a.aircraft_shadow'; |
472
|
|
|
|
473
|
|
|
} else { |
474
|
|
|
//$query = 'SELECT spotter_archive_output.ident, spotter_archive_output.flightaware_id, spotter_archive_output.aircraft_icao, spotter_archive_output.departure_airport_icao as departure_airport, spotter_archive_output.arrival_airport_icao as arrival_airport, spotter_archive_output.latitude, spotter_archive_output.longitude, spotter_archive_output.altitude, spotter_archive_output.heading, spotter_archive_output.ground_speed, spotter_archive_output.squawk, a.aircraft_shadow FROM spotter_archive_output INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_archive_output l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_archive_output.flightaware_id = s.flightaware_id AND spotter_archive_output.date = s.maxdate '.$filter_query.'INNER JOIN (SELECT * FROM aircraft) a on spotter_archive_output.aircraft_icao = a.icao'; |
475
|
|
|
/* |
476
|
|
|
$query = 'SELECT spotter_archive_output.ident, spotter_archive_output.flightaware_id, spotter_archive_output.aircraft_icao, spotter_archive_output.departure_airport_icao as departure_airport, spotter_archive_output.arrival_airport_icao as arrival_airport, spotter_archive_output.latitude, spotter_archive_output.longitude, spotter_archive_output.altitude, spotter_archive_output.heading, spotter_archive_output.ground_speed, spotter_archive_output.squawk, a.aircraft_shadow |
477
|
|
|
FROM spotter_archive_output |
478
|
|
|
INNER JOIN (SELECT * FROM aircraft) a on spotter_archive_output.aircraft_icao = a.icao |
479
|
|
|
WHERE spotter_archive_output.date >= '."'".$begindate."'".' AND spotter_archive_output.date <= '."'".$enddate."'".' |
480
|
|
|
'.$filter_query.' GROUP BY spotter_archive_output.flightaware_id, spotter_archive_output.ident, spotter_archive_output.aircraft_icao, spotter_archive_output.departure_airport_icao, spotter_archive_output.arrival_airport_icao, spotter_archive_output.latitude, spotter_archive_output.longitude, spotter_archive_output.altitude, spotter_archive_output.heading, spotter_archive_output.ground_speed, spotter_archive_output.squawk, a.aircraft_shadow'; |
481
|
|
|
*/ |
482
|
|
|
$query = 'SELECT DISTINCT spotter_archive_output.flightaware_id, spotter_archive_output.ident, spotter_archive_output.aircraft_icao, spotter_archive_output.departure_airport_icao as departure_airport, spotter_archive_output.arrival_airport_icao as arrival_airport, spotter_archive_output.latitude, spotter_archive_output.longitude, spotter_archive_output.altitude, spotter_archive_output.heading, spotter_archive_output.ground_speed, spotter_archive_output.squawk, a.aircraft_shadow |
483
|
|
|
FROM spotter_archive_output |
484
|
|
|
INNER JOIN (SELECT * FROM aircraft) a on spotter_archive_output.aircraft_icao = a.icao |
485
|
|
|
WHERE spotter_archive_output.date >= '."'".$begindate."'".' AND spotter_archive_output.date <= '."'".$enddate."'".' |
486
|
|
|
'.$filter_query.' LIMIT 200 OFFSET 0'; |
487
|
|
|
// .' GROUP BY spotter_output.flightaware_id, spotter_output.ident, spotter_output.aircraft_icao, spotter_output.departure_airport_icao, spotter_output.arrival_airport_icao, spotter_output.latitude, spotter_output.longitude, spotter_output.altitude, spotter_output.heading, spotter_output.ground_speed, spotter_output.squawk, a.aircraft_shadow'; |
488
|
|
|
|
489
|
|
|
} |
490
|
|
|
//echo $query; |
491
|
|
|
try { |
492
|
|
|
$sth = $this->db->prepare($query); |
493
|
|
|
$sth->execute(); |
494
|
|
|
} catch(PDOException $e) { |
495
|
|
|
echo $e->getMessage(); |
496
|
|
|
die; |
497
|
|
|
} |
498
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
499
|
|
|
|
500
|
|
|
return $spotter_array; |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
/** |
504
|
|
|
* Gets count Live Spotter data |
505
|
|
|
* |
506
|
|
|
* @return Array the spotter information |
507
|
|
|
* |
508
|
|
|
*/ |
509
|
|
|
public function getLiveSpotterCount($begindate,$enddate,$filter = array()) { |
510
|
|
|
global $globalDBdriver, $globalLiveInterval; |
511
|
|
|
date_default_timezone_set('UTC'); |
512
|
|
|
|
513
|
|
|
$filter_query = ''; |
514
|
|
|
if (isset($filter['source']) && !empty($filter['source'])) { |
515
|
|
|
$filter_query .= " AND format_source IN ('".implode("','",$filter['source'])."') "; |
516
|
|
|
} |
517
|
|
|
if (isset($filter['airlines']) && !empty($filter['airlines'])) { |
518
|
|
|
$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.flightaware_id = spotter_archive.flightaware_id "; |
519
|
|
|
} |
520
|
|
|
if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) { |
521
|
|
|
$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_archive.flightaware_id "; |
522
|
|
|
} |
523
|
|
|
if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) { |
524
|
|
|
$filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
525
|
|
|
} |
526
|
|
|
|
527
|
|
|
//if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
528
|
|
|
if ($globalDBdriver == 'mysql') { |
529
|
|
|
$query = 'SELECT COUNT(DISTINCT flightaware_id) as nb |
530
|
|
|
FROM spotter_archive l |
531
|
|
|
WHERE (l.date BETWEEN DATE_SUB('."'".$begindate."'".',INTERVAL '.$globalLiveInterval.' SECOND) AND '."'".$begindate."'".')'.$filter_query; |
532
|
|
|
} else { |
533
|
|
|
$query = 'SELECT COUNT(DISTINCT flightaware_id) as nb FROM spotter_archive l WHERE (l.date BETWEEN '."'".$begindate."' - INTERVAL '".$globalLiveInterval." SECONDS' AND "."'".$enddate."'".')'.$filter_query; |
534
|
|
|
} |
535
|
|
|
//echo $query; |
536
|
|
|
try { |
537
|
|
|
$sth = $this->db->prepare($query); |
538
|
|
|
$sth->execute(); |
539
|
|
|
} catch(PDOException $e) { |
540
|
|
|
echo $e->getMessage(); |
541
|
|
|
die; |
542
|
|
|
} |
543
|
|
|
$result = $sth->fetch(PDO::FETCH_ASSOC); |
544
|
|
|
$sth->closeCursor(); |
545
|
|
|
return $result['nb']; |
546
|
|
|
|
547
|
|
|
} |
548
|
|
|
|
549
|
|
|
|
550
|
|
|
|
551
|
|
|
// Spotter_Archive_output |
552
|
|
|
|
553
|
|
|
/** |
554
|
|
|
* Gets all the spotter information |
555
|
|
|
* |
556
|
|
|
* @return Array the spotter information |
557
|
|
|
* |
558
|
|
|
*/ |
559
|
|
|
public function searchSpotterData($q = '', $registration = '', $aircraft_icao = '', $aircraft_manufacturer = '', $highlights = '', $airline_icao = '', $airline_country = '', $airline_type = '', $airport = '', $airport_country = '', $callsign = '', $departure_airport_route = '', $arrival_airport_route = '', $owner = '',$pilot_id = '',$pilot_name = '',$altitude = '', $date_posted = '', $limit = '', $sort = '', $includegeodata = '',$origLat = '',$origLon = '',$dist = '', $filters=array()) { |
560
|
|
|
global $globalTimezone, $globalDBdriver; |
561
|
|
|
require_once(dirname(__FILE__).'/class.Translation.php'); |
562
|
|
|
$Translation = new Translation($this->db); |
563
|
|
|
$Spotter = new Spotter($this->db); |
564
|
|
|
|
565
|
|
|
date_default_timezone_set('UTC'); |
566
|
|
|
|
567
|
|
|
$query_values = array(); |
568
|
|
|
$additional_query = ''; |
569
|
|
|
$limit_query = ''; |
570
|
|
|
$filter_query = $this->getFilter($filters); |
571
|
|
|
if ($q != "") { |
572
|
|
|
if (!is_string($q)) { |
573
|
|
|
return false; |
|
|
|
|
574
|
|
|
} else { |
575
|
|
|
|
576
|
|
|
$q_array = explode(" ", $q); |
577
|
|
|
|
578
|
|
|
foreach ($q_array as $q_item) { |
579
|
|
|
$additional_query .= " AND ("; |
580
|
|
|
$additional_query .= "(spotter_archive_output.spotter_id like '%".$q_item."%') OR "; |
581
|
|
|
$additional_query .= "(spotter_archive_output.aircraft_icao like '%".$q_item."%') OR "; |
582
|
|
|
$additional_query .= "(spotter_archive_output.aircraft_name like '%".$q_item."%') OR "; |
583
|
|
|
$additional_query .= "(spotter_archive_output.aircraft_manufacturer like '%".$q_item."%') OR "; |
584
|
|
|
$additional_query .= "(spotter_archive_output.airline_icao like '%".$q_item."%') OR "; |
585
|
|
|
$additional_query .= "(spotter_archive_output.airline_name like '%".$q_item."%') OR "; |
586
|
|
|
$additional_query .= "(spotter_archive_output.airline_country like '%".$q_item."%') OR "; |
587
|
|
|
$additional_query .= "(spotter_archive_output.departure_airport_icao like '%".$q_item."%') OR "; |
588
|
|
|
$additional_query .= "(spotter_archive_output.departure_airport_name like '%".$q_item."%') OR "; |
589
|
|
|
$additional_query .= "(spotter_archive_output.departure_airport_city like '%".$q_item."%') OR "; |
590
|
|
|
$additional_query .= "(spotter_archive_output.departure_airport_country like '%".$q_item."%') OR "; |
591
|
|
|
$additional_query .= "(spotter_archive_output.arrival_airport_icao like '%".$q_item."%') OR "; |
592
|
|
|
$additional_query .= "(spotter_archive_output.arrival_airport_name like '%".$q_item."%') OR "; |
593
|
|
|
$additional_query .= "(spotter_archive_output.arrival_airport_city like '%".$q_item."%') OR "; |
594
|
|
|
$additional_query .= "(spotter_archive_output.arrival_airport_country like '%".$q_item."%') OR "; |
595
|
|
|
$additional_query .= "(spotter_archive_output.registration like '%".$q_item."%') OR "; |
596
|
|
|
$additional_query .= "(spotter_archive_output.owner_name like '%".$q_item."%') OR "; |
597
|
|
|
$additional_query .= "(spotter_archive_output.pilot_id like '%".$q_item."%') OR "; |
598
|
|
|
$additional_query .= "(spotter_archive_output.pilot_name like '%".$q_item."%') OR "; |
599
|
|
|
$additional_query .= "(spotter_archive_output.ident like '%".$q_item."%') OR "; |
600
|
|
|
$translate = $Translation->ident2icao($q_item); |
601
|
|
|
if ($translate != $q_item) $additional_query .= "(spotter_archive_output.ident like '%".$translate."%') OR "; |
602
|
|
|
$additional_query .= "(spotter_archive_output.highlight like '%".$q_item."%')"; |
603
|
|
|
$additional_query .= ")"; |
604
|
|
|
} |
605
|
|
|
} |
606
|
|
|
} |
607
|
|
|
|
608
|
|
|
if ($registration != "") { |
609
|
|
|
$registration = filter_var($registration,FILTER_SANITIZE_STRING); |
610
|
|
|
if (!is_string($registration)) { |
611
|
|
|
return false; |
|
|
|
|
612
|
|
|
} else { |
613
|
|
|
$additional_query .= " AND (spotter_archive_output.registration = '".$registration."')"; |
614
|
|
|
} |
615
|
|
|
} |
616
|
|
|
|
617
|
|
|
if ($aircraft_icao != "") { |
618
|
|
|
$aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
619
|
|
|
if (!is_string($aircraft_icao)) { |
620
|
|
|
return false; |
|
|
|
|
621
|
|
|
} else { |
622
|
|
|
$additional_query .= " AND (spotter_archive_output.aircraft_icao = '".$aircraft_icao."')"; |
623
|
|
|
} |
624
|
|
|
} |
625
|
|
|
|
626
|
|
|
if ($aircraft_manufacturer != "") { |
627
|
|
|
$aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
628
|
|
|
if (!is_string($aircraft_manufacturer)) { |
629
|
|
|
return false; |
|
|
|
|
630
|
|
|
} else { |
631
|
|
|
$additional_query .= " AND (spotter_archive_output.aircraft_manufacturer = '".$aircraft_manufacturer."')"; |
632
|
|
|
} |
633
|
|
|
} |
634
|
|
|
|
635
|
|
|
if ($highlights == "true") { |
636
|
|
|
if (!is_string($highlights)) { |
637
|
|
|
return false; |
|
|
|
|
638
|
|
|
} else { |
639
|
|
|
$additional_query .= " AND (spotter_archive_output.highlight <> '')"; |
640
|
|
|
} |
641
|
|
|
} |
642
|
|
|
|
643
|
|
|
if ($airline_icao != "") { |
644
|
|
|
$airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
645
|
|
|
if (!is_string($airline_icao)) { |
646
|
|
|
return false; |
|
|
|
|
647
|
|
|
} else { |
648
|
|
|
$additional_query .= " AND (spotter_archive_output.airline_icao = '".$airline_icao."')"; |
649
|
|
|
} |
650
|
|
|
} |
651
|
|
|
|
652
|
|
|
if ($airline_country != "") { |
653
|
|
|
$airline_country = filter_var($airline_country,FILTER_SANITIZE_STRING); |
654
|
|
|
if (!is_string($airline_country)) { |
655
|
|
|
return false; |
|
|
|
|
656
|
|
|
} else { |
657
|
|
|
$additional_query .= " AND (spotter_archive_output.airline_country = '".$airline_country."')"; |
658
|
|
|
} |
659
|
|
|
} |
660
|
|
|
|
661
|
|
|
if ($airline_type != "") { |
662
|
|
|
$airline_type = filter_var($airline_type,FILTER_SANITIZE_STRING); |
663
|
|
|
if (!is_string($airline_type)) { |
664
|
|
|
return false; |
|
|
|
|
665
|
|
|
} else { |
666
|
|
|
if ($airline_type == "passenger") { |
667
|
|
|
$additional_query .= " AND (spotter_archive_output.airline_type = 'passenger')"; |
668
|
|
|
} |
669
|
|
|
if ($airline_type == "cargo") { |
670
|
|
|
$additional_query .= " AND (spotter_archive_output.airline_type = 'cargo')"; |
671
|
|
|
} |
672
|
|
|
if ($airline_type == "military") { |
673
|
|
|
$additional_query .= " AND (spotter_archive_output.airline_type = 'military')"; |
674
|
|
|
} |
675
|
|
|
} |
676
|
|
|
} |
677
|
|
|
|
678
|
|
|
if ($airport != "") { |
679
|
|
|
$airport = filter_var($airport,FILTER_SANITIZE_STRING); |
680
|
|
|
if (!is_string($airport)) { |
681
|
|
|
return false; |
|
|
|
|
682
|
|
|
} else { |
683
|
|
|
$additional_query .= " AND ((spotter_archive_output.departure_airport_icao = '".$airport."') OR (spotter_archive_output.arrival_airport_icao = '".$airport."'))"; |
684
|
|
|
} |
685
|
|
|
} |
686
|
|
|
|
687
|
|
|
if ($airport_country != "") { |
688
|
|
|
$airport_country = filter_var($airport_country,FILTER_SANITIZE_STRING); |
689
|
|
|
if (!is_string($airport_country)) { |
690
|
|
|
return false; |
|
|
|
|
691
|
|
|
} else { |
692
|
|
|
$additional_query .= " AND ((spotter_archive_output.departure_airport_country = '".$airport_country."') OR (spotter_archive_output.arrival_airport_country = '".$airport_country."'))"; |
693
|
|
|
} |
694
|
|
|
} |
695
|
|
|
|
696
|
|
|
if ($callsign != "") { |
697
|
|
|
$callsign = filter_var($callsign,FILTER_SANITIZE_STRING); |
698
|
|
|
if (!is_string($callsign)) { |
699
|
|
|
return false; |
|
|
|
|
700
|
|
|
} else { |
701
|
|
|
$translate = $Translation->ident2icao($callsign); |
702
|
|
|
if ($translate != $callsign) { |
703
|
|
|
$additional_query .= " AND (spotter_archive_output.ident = :callsign OR spotter_archive_output.ident = :translate)"; |
704
|
|
|
$query_values = array_merge($query_values,array(':callsign' => $callsign,':translate' => $translate)); |
705
|
|
|
} else { |
706
|
|
|
$additional_query .= " AND (spotter_archive_output.ident = '".$callsign."')"; |
707
|
|
|
} |
708
|
|
|
} |
709
|
|
|
} |
710
|
|
|
|
711
|
|
|
if ($owner != "") { |
712
|
|
|
$owner = filter_var($owner,FILTER_SANITIZE_STRING); |
713
|
|
|
if (!is_string($owner)) { |
714
|
|
|
return false; |
|
|
|
|
715
|
|
|
} else { |
716
|
|
|
$additional_query .= " AND (spotter_archive_output.owner_name = '".$owner."')"; |
717
|
|
|
} |
718
|
|
|
} |
719
|
|
|
|
720
|
|
|
if ($pilot_name != "") { |
721
|
|
|
$pilot_name = filter_var($pilot_name,FILTER_SANITIZE_STRING); |
722
|
|
|
if (!is_string($pilot_name)) { |
723
|
|
|
return false; |
|
|
|
|
724
|
|
|
} else { |
725
|
|
|
$additional_query .= " AND (spotter_archive_output.pilot_name = '".$pilot_name."')"; |
726
|
|
|
} |
727
|
|
|
} |
728
|
|
|
|
729
|
|
|
if ($pilot_id != "") { |
730
|
|
|
$pilot_id = filter_var($pilot_id,FILTER_SANITIZE_NUMBER_INT); |
731
|
|
|
if (!is_string($pilot_id)) { |
732
|
|
|
return false; |
|
|
|
|
733
|
|
|
} else { |
734
|
|
|
$additional_query .= " AND (spotter_archive_output.pilot_id = '".$pilot_id."')"; |
735
|
|
|
} |
736
|
|
|
} |
737
|
|
|
|
738
|
|
|
if ($departure_airport_route != "") { |
739
|
|
|
$departure_airport_route = filter_var($departure_airport_route,FILTER_SANITIZE_STRING); |
740
|
|
|
if (!is_string($departure_airport_route)) { |
741
|
|
|
return false; |
|
|
|
|
742
|
|
|
} else { |
743
|
|
|
$additional_query .= " AND (spotter_archive_output.departure_airport_icao = '".$departure_airport_route."')"; |
744
|
|
|
} |
745
|
|
|
} |
746
|
|
|
|
747
|
|
|
if ($arrival_airport_route != "") { |
748
|
|
|
$arrival_airport_route = filter_var($arrival_airport_route,FILTER_SANITIZE_STRING); |
749
|
|
|
if (!is_string($arrival_airport_route)) { |
750
|
|
|
return false; |
|
|
|
|
751
|
|
|
} else { |
752
|
|
|
$additional_query .= " AND (spotter_archive_output.arrival_airport_icao = '".$arrival_airport_route."')"; |
753
|
|
|
} |
754
|
|
|
} |
755
|
|
|
|
756
|
|
|
if ($altitude != "") { |
757
|
|
|
$altitude_array = explode(",", $altitude); |
758
|
|
|
|
759
|
|
|
$altitude_array[0] = filter_var($altitude_array[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
760
|
|
|
$altitude_array[1] = filter_var($altitude_array[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
761
|
|
|
|
762
|
|
|
|
763
|
|
|
if ($altitude_array[1] != "") { |
764
|
|
|
$altitude_array[0] = substr($altitude_array[0], 0, -2); |
765
|
|
|
$altitude_array[1] = substr($altitude_array[1], 0, -2); |
766
|
|
|
$additional_query .= " AND altitude BETWEEN '".$altitude_array[0]."' AND '".$altitude_array[1]."' "; |
767
|
|
|
} else { |
768
|
|
|
$altitude_array[0] = substr($altitude_array[0], 0, -2); |
769
|
|
|
$additional_query .= " AND altitude <= '".$altitude_array[0]."' "; |
770
|
|
|
} |
771
|
|
|
} |
772
|
|
|
|
773
|
|
|
if ($date_posted != "") { |
774
|
|
|
$date_array = explode(",", $date_posted); |
775
|
|
|
$date_array[0] = filter_var($date_array[0],FILTER_SANITIZE_STRING); |
776
|
|
|
$date_array[1] = filter_var($date_array[1],FILTER_SANITIZE_STRING); |
777
|
|
|
if ($globalTimezone != '') { |
778
|
|
|
date_default_timezone_set($globalTimezone); |
779
|
|
|
$datetime = new DateTime(); |
780
|
|
|
$offset = $datetime->format('P'); |
781
|
|
|
} else $offset = '+00:00'; |
782
|
|
|
if ($date_array[1] != "") { |
783
|
|
|
$date_array[0] = date("Y-m-d H:i:s", strtotime($date_array[0])); |
784
|
|
|
$date_array[1] = date("Y-m-d H:i:s", strtotime($date_array[1])); |
785
|
|
|
if ($globalDBdriver == 'mysql') { |
786
|
|
|
$additional_query .= " AND TIMESTAMP(CONVERT_TZ(spotter_archive_output.date,'+00:00', '".$offset."')) >= '".$date_array[0]."' AND TIMESTAMP(CONVERT_TZ(spotter_archive_output.date,'+00:00', '".$offset."')) <= '".$date_array[1]."' "; |
787
|
|
|
} else { |
788
|
|
|
$additional_query .= " AND spotter_archive_output.date::timestamp AT TIME ZONE INTERVAL ".$offset." >= CAST('".$date_array[0]."' AS TIMESTAMP) AND spotter_archive_output.date::timestamp AT TIME ZONE INTERVAL ".$offset." <= CAST('".$date_array[1]."' AS TIMESTAMP) "; |
789
|
|
|
} |
790
|
|
|
} else { |
791
|
|
|
$date_array[0] = date("Y-m-d H:i:s", strtotime($date_array[0])); |
792
|
|
|
if ($globalDBdriver == 'mysql') { |
793
|
|
|
$additional_query .= " AND TIMESTAMP(CONVERT_TZ(spotter_archive_output.date,'+00:00', '".$offset."')) >= '".$date_array[0]."' "; |
794
|
|
|
} else { |
795
|
|
|
$additional_query .= " AND spotter_archive_output.date::timestamp AT TIME ZONE INTERVAL ".$offset." >= CAST('".$date_array[0]."' AS TIMESTAMP) "; |
796
|
|
|
} |
797
|
|
|
} |
798
|
|
|
} |
799
|
|
|
if ($limit != "") { |
800
|
|
|
$limit_array = explode(",", $limit); |
801
|
|
|
$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
802
|
|
|
$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
803
|
|
|
if ($limit_array[0] >= 0 && $limit_array[1] >= 0) { |
804
|
|
|
//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
805
|
|
|
$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
806
|
|
|
} |
807
|
|
|
} |
808
|
|
|
if ($origLat != "" && $origLon != "" && $dist != "") { |
809
|
|
|
$dist = number_format($dist*0.621371,2,'.',''); |
810
|
|
|
$query="SELECT spotter_archive_output.*, 3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - ABS(CAST(spotter_archive.latitude as double precision)))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(ABS(CAST(spotter_archive.latitude as double precision))*pi()/180)*POWER(SIN(($origLon-CAST(spotter_archive.longitude as double precision))*pi()/180/2),2))) as distance |
811
|
|
|
FROM spotter_archive_output, spotter_archive WHERE spotter_output_archive.flightaware_id = spotter_archive.flightaware_id AND spotter_output.ident <> '' ".$additional_query."AND CAST(spotter_archive.longitude as double precision) between ($origLon-$dist/ABS(cos(radians($origLat))*69)) and ($origLon+$dist/ABS(cos(radians($origLat))*69)) and CAST(spotter_archive.latitude as double precision) between ($origLat-($dist/69)) and ($origLat+($dist/69)) |
812
|
|
|
AND (3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - ABS(CAST(spotter_archive.latitude as double precision)))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(ABS(CAST(spotter_archive.latitude as double precision))*pi()/180)*POWER(SIN(($origLon-CAST(spotter_archive.longitude as double precision))*pi()/180/2),2)))) < $dist".$filter_query." ORDER BY distance"; |
813
|
|
|
} else { |
814
|
|
|
if ($sort != "") { |
815
|
|
|
$search_orderby_array = $Spotter->getOrderBy(); |
816
|
|
|
$orderby_query = $search_orderby_array[$sort]['sql']; |
817
|
|
|
} else { |
818
|
|
|
$orderby_query = " ORDER BY spotter_archive_output.date DESC"; |
819
|
|
|
} |
820
|
|
|
if ($includegeodata == "true") { |
821
|
|
|
$additional_query .= " AND (spotter_archive_output.waypoints <> '')"; |
822
|
|
|
} |
823
|
|
|
|
824
|
|
|
$query = "SELECT spotter_archive_output.* FROM spotter_archive_output |
825
|
|
|
WHERE spotter_archive_output.ident <> '' |
826
|
|
|
".$additional_query." |
827
|
|
|
".$filter_query.$orderby_query; |
828
|
|
|
} |
829
|
|
|
$spotter_array = $Spotter->getDataFromDB($query, $query_values,$limit_query); |
830
|
|
|
return $spotter_array; |
831
|
|
|
} |
832
|
|
|
|
833
|
|
|
public function deleteSpotterArchiveData() { |
834
|
|
|
global $globalArchiveKeepMonths, $globalDBdriver; |
835
|
|
|
date_default_timezone_set('UTC'); |
836
|
|
|
if ($globalDBdriver == 'mysql') { |
837
|
|
|
$query = 'DELETE FROM spotter_archive_output WHERE spotter_archive_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$globalArchiveKeepMonths.' MONTH) LIMIT 10000'; |
838
|
|
|
} else { |
839
|
|
|
$query = "DELETE FROM spotter_archive_output WHERE spotter_archive_id IN (SELECT spotter_archive_id FROM spotter_archive_output WHERE spotter_archive_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveKeepMonths." MONTH' LIMIT 10000)"; |
840
|
|
|
} |
841
|
|
|
try { |
842
|
|
|
$sth = $this->db->prepare($query); |
843
|
|
|
$sth->execute(); |
844
|
|
|
} catch(PDOException $e) { |
845
|
|
|
return "error"; |
846
|
|
|
} |
847
|
|
|
} |
848
|
|
|
|
849
|
|
|
/** |
850
|
|
|
* Gets all the spotter information based on the callsign |
851
|
|
|
* |
852
|
|
|
* @return Array the spotter information |
853
|
|
|
* |
854
|
|
|
*/ |
855
|
|
|
public function getSpotterDataByIdent($ident = '', $limit = '', $sort = '') { |
856
|
|
|
$global_query = "SELECT spotter_archive_output.* FROM spotter_archive_output"; |
857
|
|
|
|
858
|
|
|
date_default_timezone_set('UTC'); |
859
|
|
|
$Spotter = new Spotter($this->db); |
860
|
|
|
|
861
|
|
|
$query_values = array(); |
862
|
|
|
$limit_query = ''; |
863
|
|
|
$additional_query = ''; |
864
|
|
|
|
865
|
|
|
if ($ident != "") { |
866
|
|
|
if (!is_string($ident)) { |
867
|
|
|
return false; |
|
|
|
|
868
|
|
|
} else { |
869
|
|
|
$additional_query = " AND spotter_archive_output.ident = :ident"; |
870
|
|
|
$query_values = array(':ident' => $ident); |
871
|
|
|
} |
872
|
|
|
} |
873
|
|
|
|
874
|
|
|
if ($limit != "") { |
875
|
|
|
$limit_array = explode(",", $limit); |
876
|
|
|
|
877
|
|
|
$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
878
|
|
|
$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
879
|
|
|
|
880
|
|
|
if ($limit_array[0] >= 0 && $limit_array[1] >= 0) { |
881
|
|
|
//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
882
|
|
|
$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
883
|
|
|
} |
884
|
|
|
} |
885
|
|
|
|
886
|
|
|
if ($sort != "") { |
887
|
|
|
$search_orderby_array = $Spotter->getOrderBy(); |
888
|
|
|
$orderby_query = $search_orderby_array[$sort]['sql']; |
889
|
|
|
} else { |
890
|
|
|
$orderby_query = " ORDER BY spotter_archive_output.date DESC"; |
891
|
|
|
} |
892
|
|
|
|
893
|
|
|
$query = $global_query." WHERE spotter_archive_output.ident <> '' ".$additional_query." ".$orderby_query; |
894
|
|
|
|
895
|
|
|
$spotter_array = $Spotter->getDataFromDB($query, $query_values, $limit_query); |
896
|
|
|
|
897
|
|
|
return $spotter_array; |
898
|
|
|
} |
899
|
|
|
|
900
|
|
|
|
901
|
|
|
/** |
902
|
|
|
* Gets all the spotter information based on the owner |
903
|
|
|
* |
904
|
|
|
* @return Array the spotter information |
905
|
|
|
* |
906
|
|
|
*/ |
907
|
|
|
public function getSpotterDataByOwner($owner = '', $limit = '', $sort = '', $filter = array()) { |
908
|
|
|
$global_query = "SELECT spotter_archive_output.* FROM spotter_archive_output"; |
909
|
|
|
|
910
|
|
|
date_default_timezone_set('UTC'); |
911
|
|
|
$Spotter = new Spotter($this->db); |
912
|
|
|
|
913
|
|
|
$query_values = array(); |
914
|
|
|
$limit_query = ''; |
915
|
|
|
$additional_query = ''; |
916
|
|
|
$filter_query = $this->getFilter($filter,true,true); |
917
|
|
|
|
918
|
|
|
if ($owner != "") { |
919
|
|
|
if (!is_string($owner)) { |
920
|
|
|
return false; |
|
|
|
|
921
|
|
|
} else { |
922
|
|
|
$additional_query = " AND (spotter_archive_output.owner_name = :owner)"; |
923
|
|
|
$query_values = array(':owner' => $owner); |
924
|
|
|
} |
925
|
|
|
} |
926
|
|
|
|
927
|
|
|
if ($limit != "") { |
928
|
|
|
$limit_array = explode(",", $limit); |
929
|
|
|
|
930
|
|
|
$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
931
|
|
|
$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
932
|
|
|
|
933
|
|
|
if ($limit_array[0] >= 0 && $limit_array[1] >= 0) { |
934
|
|
|
//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
935
|
|
|
$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
936
|
|
|
} |
937
|
|
|
} |
938
|
|
|
|
939
|
|
|
if ($sort != "") { |
940
|
|
|
$search_orderby_array = $Spotter->getOrderBy(); |
941
|
|
|
$orderby_query = $search_orderby_array[$sort]['sql']; |
942
|
|
|
} else { |
943
|
|
|
$orderby_query = " ORDER BY spotter_archive_output.date DESC"; |
944
|
|
|
} |
945
|
|
|
|
946
|
|
|
$query = $global_query.$filter_query." spotter_archive_output.owner_name <> '' ".$additional_query." ".$orderby_query; |
947
|
|
|
|
948
|
|
|
$spotter_array = $Spotter->getDataFromDB($query, $query_values, $limit_query); |
949
|
|
|
|
950
|
|
|
return $spotter_array; |
951
|
|
|
} |
952
|
|
|
|
953
|
|
|
/** |
954
|
|
|
* Gets all the spotter information based on the pilot |
955
|
|
|
* |
956
|
|
|
* @return Array the spotter information |
957
|
|
|
* |
958
|
|
|
*/ |
959
|
|
|
public function getSpotterDataByPilot($pilot = '', $limit = '', $sort = '', $filter = array()) { |
960
|
|
|
$global_query = "SELECT spotter_archive_output.* FROM spotter_archive_output"; |
961
|
|
|
|
962
|
|
|
date_default_timezone_set('UTC'); |
963
|
|
|
$Spotter = new Spotter($this->db); |
964
|
|
|
|
965
|
|
|
$query_values = array(); |
966
|
|
|
$limit_query = ''; |
967
|
|
|
$additional_query = ''; |
968
|
|
|
$filter_query = $this->getFilter($filter,true,true); |
969
|
|
|
|
970
|
|
|
if ($pilot != "") { |
971
|
|
|
$additional_query = " AND (spotter_archive_output.pilot_id = :pilot OR spotter_archive_output.pilot_name = :pilot)"; |
972
|
|
|
$query_values = array(':pilot' => $pilot); |
973
|
|
|
} |
974
|
|
|
|
975
|
|
|
if ($limit != "") { |
976
|
|
|
$limit_array = explode(",", $limit); |
977
|
|
|
|
978
|
|
|
$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
979
|
|
|
$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
980
|
|
|
|
981
|
|
|
if ($limit_array[0] >= 0 && $limit_array[1] >= 0) { |
982
|
|
|
//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
983
|
|
|
$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
984
|
|
|
} |
985
|
|
|
} |
986
|
|
|
|
987
|
|
|
if ($sort != "") { |
988
|
|
|
$search_orderby_array = $Spotter->getOrderBy(); |
989
|
|
|
$orderby_query = $search_orderby_array[$sort]['sql']; |
990
|
|
|
} else { |
991
|
|
|
$orderby_query = " ORDER BY spotter_archive_output.date DESC"; |
992
|
|
|
} |
993
|
|
|
|
994
|
|
|
$query = $global_query.$filter_query." spotter_archive_output.pilot_name <> '' ".$additional_query." ".$orderby_query; |
995
|
|
|
|
996
|
|
|
$spotter_array = $Spotter->getDataFromDB($query, $query_values, $limit_query); |
997
|
|
|
|
998
|
|
|
return $spotter_array; |
999
|
|
|
} |
1000
|
|
|
|
1001
|
|
|
/** |
1002
|
|
|
* Gets all number of flight over countries |
1003
|
|
|
* |
1004
|
|
|
* @return Array the airline country list |
1005
|
|
|
* |
1006
|
|
|
*/ |
1007
|
|
|
public function countAllFlightOverCountries($limit = true,$olderthanmonths = 0,$sincedate = '') { |
1008
|
|
|
global $globalDBdriver; |
1009
|
|
|
/* |
1010
|
|
|
$query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb |
1011
|
|
|
FROM countries c, spotter_archive s |
1012
|
|
|
WHERE Within(GeomFromText(CONCAT('POINT(',s.longitude,' ',s.latitude,')')), ogc_geom) "; |
1013
|
|
|
*/ |
1014
|
|
|
$query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb |
1015
|
|
|
FROM countries c, spotter_archive s |
1016
|
|
|
WHERE c.iso2 = s.over_country "; |
1017
|
|
|
if ($olderthanmonths > 0) { |
1018
|
|
|
if ($globalDBdriver == 'mysql') { |
1019
|
|
|
$query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) '; |
1020
|
|
|
} else { |
1021
|
|
|
$query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
1022
|
|
|
} |
1023
|
|
|
} |
1024
|
|
|
if ($sincedate != '') $query .= "AND date > '".$sincedate."' "; |
1025
|
|
|
$query .= "GROUP BY c.name, c.iso3, c.iso2 ORDER BY nb DESC"; |
1026
|
|
|
if ($limit) $query .= " LIMIT 0,10"; |
1027
|
|
|
|
1028
|
|
|
|
1029
|
|
|
$sth = $this->db->prepare($query); |
1030
|
|
|
$sth->execute(); |
1031
|
|
|
|
1032
|
|
|
$flight_array = array(); |
1033
|
|
|
$temp_array = array(); |
1034
|
|
|
|
1035
|
|
|
while($row = $sth->fetch(PDO::FETCH_ASSOC)) { |
1036
|
|
|
$temp_array['flight_count'] = $row['nb']; |
1037
|
|
|
$temp_array['flight_country'] = $row['name']; |
1038
|
|
|
$temp_array['flight_country_iso3'] = $row['iso3']; |
1039
|
|
|
$temp_array['flight_country_iso2'] = $row['iso2']; |
1040
|
|
|
$flight_array[] = $temp_array; |
1041
|
|
|
} |
1042
|
|
|
return $flight_array; |
1043
|
|
|
} |
1044
|
|
|
|
1045
|
|
|
/** |
1046
|
|
|
* Gets all number of flight over countries |
1047
|
|
|
* |
1048
|
|
|
* @return Array the airline country list |
1049
|
|
|
* |
1050
|
|
|
*/ |
1051
|
|
|
public function countAllFlightOverCountriesByAirlines($limit = true,$olderthanmonths = 0,$sincedate = '') { |
1052
|
|
|
global $globalDBdriver; |
1053
|
|
|
/* |
1054
|
|
|
$query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb |
1055
|
|
|
FROM countries c, spotter_archive s |
1056
|
|
|
WHERE Within(GeomFromText(CONCAT('POINT(',s.longitude,' ',s.latitude,')')), ogc_geom) "; |
1057
|
|
|
*/ |
1058
|
|
|
$query = "SELECT o.airline_icao,c.name, c.iso3, c.iso2, count(c.name) as nb |
1059
|
|
|
FROM countries c, spotter_archive s, spotter_output o |
1060
|
|
|
WHERE c.iso2 = s.over_country AND o.airline_icao <> '' AND o.flightaware_id = s.flightaware_id "; |
1061
|
|
|
if ($olderthanmonths > 0) { |
1062
|
|
|
if ($globalDBdriver == 'mysql') { |
1063
|
|
|
$query .= 'AND s.date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) '; |
1064
|
|
|
} else { |
1065
|
|
|
$query .= "AND s.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
1066
|
|
|
} |
1067
|
|
|
} |
1068
|
|
|
if ($sincedate != '') $query .= "AND s.date > '".$sincedate."' "; |
1069
|
|
|
$query .= "GROUP BY o.airline_icao,c.name, c.iso3, c.iso2 ORDER BY nb DESC"; |
1070
|
|
|
if ($limit) $query .= " LIMIT 0,10"; |
1071
|
|
|
|
1072
|
|
|
|
1073
|
|
|
$sth = $this->db->prepare($query); |
1074
|
|
|
$sth->execute(); |
1075
|
|
|
|
1076
|
|
|
$flight_array = array(); |
1077
|
|
|
$temp_array = array(); |
1078
|
|
|
|
1079
|
|
|
while($row = $sth->fetch(PDO::FETCH_ASSOC)) { |
1080
|
|
|
$temp_array['airline_icao'] = $row['airline_icao']; |
1081
|
|
|
$temp_array['flight_count'] = $row['nb']; |
1082
|
|
|
$temp_array['flight_country'] = $row['name']; |
1083
|
|
|
$temp_array['flight_country_iso3'] = $row['iso3']; |
1084
|
|
|
$temp_array['flight_country_iso2'] = $row['iso2']; |
1085
|
|
|
$flight_array[] = $temp_array; |
1086
|
|
|
} |
1087
|
|
|
return $flight_array; |
1088
|
|
|
} |
1089
|
|
|
|
1090
|
|
|
/** |
1091
|
|
|
* Gets last spotter information based on a particular callsign |
1092
|
|
|
* |
1093
|
|
|
* @return Array the spotter information |
1094
|
|
|
* |
1095
|
|
|
*/ |
1096
|
|
|
public function getDateArchiveSpotterDataById($id,$date) { |
1097
|
|
|
$Spotter = new Spotter($this->db); |
1098
|
|
|
date_default_timezone_set('UTC'); |
1099
|
|
|
$id = filter_var($id, FILTER_SANITIZE_STRING); |
1100
|
|
|
$query = 'SELECT spotter_archive.* FROM spotter_archive INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_archive l WHERE l.flightaware_id = :id AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_archive.flightaware_id = s.flightaware_id AND spotter_archive.date = s.maxdate ORDER BY spotter_archive.date DESC'; |
1101
|
|
|
$date = date('c',$date); |
1102
|
|
|
$spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id,':date' => $date)); |
1103
|
|
|
return $spotter_array; |
1104
|
|
|
} |
1105
|
|
|
|
1106
|
|
|
/** |
1107
|
|
|
* Gets all the spotter information based on a particular callsign |
1108
|
|
|
* |
1109
|
|
|
* @return Array the spotter information |
1110
|
|
|
* |
1111
|
|
|
*/ |
1112
|
|
|
public function getDateArchiveSpotterDataByIdent($ident,$date) { |
1113
|
|
|
$Spotter = new Spotter($this->db); |
1114
|
|
|
date_default_timezone_set('UTC'); |
1115
|
|
|
$ident = filter_var($ident, FILTER_SANITIZE_STRING); |
1116
|
|
|
$query = 'SELECT spotter_archive.* FROM spotter_archive INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_archive l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_archive.flightaware_id = s.flightaware_id AND spotter_archive.date = s.maxdate ORDER BY spotter_archive.date DESC'; |
1117
|
|
|
$date = date('c',$date); |
1118
|
|
|
$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident,':date' => $date)); |
1119
|
|
|
return $spotter_array; |
1120
|
|
|
} |
1121
|
|
|
|
1122
|
|
|
/** |
1123
|
|
|
* Gets all the spotter information based on the airport |
1124
|
|
|
* |
1125
|
|
|
* @return Array the spotter information |
1126
|
|
|
* |
1127
|
|
|
*/ |
1128
|
|
|
public function getSpotterDataByAirport($airport = '', $limit = '', $sort = '',$filters = array()) { |
1129
|
|
|
global $global_query; |
1130
|
|
|
$Spotter = new Spotter($this->db); |
1131
|
|
|
date_default_timezone_set('UTC'); |
1132
|
|
|
$query_values = array(); |
1133
|
|
|
$limit_query = ''; |
1134
|
|
|
$additional_query = ''; |
1135
|
|
|
$filter_query = $this->getFilter($filters,true,true); |
1136
|
|
|
|
1137
|
|
|
if ($airport != "") { |
1138
|
|
|
if (!is_string($airport)) { |
1139
|
|
|
return false; |
|
|
|
|
1140
|
|
|
} else { |
1141
|
|
|
$additional_query .= " AND ((spotter_archive_output.departure_airport_icao = :airport) OR (spotter_archive_output.arrival_airport_icao = :airport))"; |
1142
|
|
|
$query_values = array(':airport' => $airport); |
1143
|
|
|
} |
1144
|
|
|
} |
1145
|
|
|
|
1146
|
|
|
if ($limit != "") { |
1147
|
|
|
$limit_array = explode(",", $limit); |
1148
|
|
|
|
1149
|
|
|
$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
1150
|
|
|
$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
1151
|
|
|
|
1152
|
|
|
if ($limit_array[0] >= 0 && $limit_array[1] >= 0) { |
1153
|
|
|
//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
1154
|
|
|
$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
1155
|
|
|
} |
1156
|
|
|
} |
1157
|
|
|
|
1158
|
|
|
if ($sort != "") { |
1159
|
|
|
$search_orderby_array = $Spotter->getOrderBy(); |
1160
|
|
|
$orderby_query = $search_orderby_array[$sort]['sql']; |
1161
|
|
|
} else { |
1162
|
|
|
$orderby_query = " ORDER BY spotter_archive_output.date DESC"; |
1163
|
|
|
} |
1164
|
|
|
|
1165
|
|
|
$query = $global_query.$filter_query." spotter_archive_output.ident <> '' ".$additional_query." AND ((spotter_archive_output.departure_airport_icao <> 'NA') AND (spotter_archive_output.arrival_airport_icao <> 'NA')) ".$orderby_query; |
1166
|
|
|
|
1167
|
|
|
$spotter_array = $Spotter->getDataFromDB($query, $query_values, $limit_query); |
1168
|
|
|
|
1169
|
|
|
return $spotter_array; |
1170
|
|
|
} |
1171
|
|
|
} |
1172
|
|
|
?> |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.