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