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