1
|
|
|
<?php |
2
|
|
|
class SpotterArchive { |
3
|
|
|
public $global_query = "SELECT spotter_archive.* FROM spotter_archive"; |
4
|
|
|
public $db; |
5
|
|
|
|
6
|
|
|
public function __construct($dbc = null) { |
7
|
|
|
$Connection = new Connection($dbc); |
8
|
|
|
$this->db = $Connection->db; |
9
|
|
|
if ($this->db === null) die('Error: No DB connection. (SpotterArchive)'); |
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Get SQL query part for filter used |
14
|
|
|
* @param array $filter the filter |
15
|
|
|
* @param bool $where |
16
|
|
|
* @param bool $and |
17
|
|
|
* @return string the SQL part |
18
|
|
|
*/ |
19
|
|
|
public function getFilter($filter = array(),$where = false,$and = false) { |
20
|
|
|
global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver; |
21
|
|
|
$filters = array(); |
22
|
|
|
if (is_array($globalStatsFilters) && isset($globalStatsFilters[$globalFilterName])) { |
23
|
|
|
if (isset($globalStatsFilters[$globalFilterName][0]['source'])) { |
24
|
|
|
$filters = $globalStatsFilters[$globalFilterName]; |
25
|
|
|
} else { |
26
|
|
|
$filter = array_merge($filter,$globalStatsFilters[$globalFilterName]); |
27
|
|
|
} |
28
|
|
|
} |
29
|
|
|
if (isset($filter[0]['source'])) { |
30
|
|
|
$filters = array_merge($filters,$filter); |
31
|
|
|
} |
32
|
|
|
if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter); |
33
|
|
|
$filter_query_join = ''; |
34
|
|
|
$filter_query_where = ''; |
35
|
|
|
foreach($filters as $flt) { |
36
|
|
|
if (isset($flt['airlines']) && !empty($flt['airlines'])) { |
37
|
|
|
if ($flt['airlines'][0] != '' && $flt['airlines'][0] != 'all') { |
38
|
|
|
if (isset($flt['source'])) { |
39
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_icao IN ('".implode("','",$flt['airlines'])."') AND spotter_archive_output.format_source IN ('".implode("','",$flt['source'])."')) saff ON saff.flightaware_id = spotter_archive_output.flightaware_id"; |
40
|
|
|
} else { |
41
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_icao IN ('".implode("','",$flt['airlines'])."')) saff ON saff.flightaware_id = spotter_archive_output.flightaware_id"; |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
if (isset($flt['pilots_id']) && !empty($flt['pilots_id'])) { |
46
|
|
|
if (isset($flt['source'])) { |
47
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.pilot_id IN ('".implode("','",$flt['pilots_id'])."') AND spotter_archive_output.format_source IN ('".implode("','",$flt['source'])."')) sp ON sp.flightaware_id = spotter_archive_output.flightaware_id"; |
48
|
|
|
} else { |
49
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.pilot_id IN ('".implode("','",$flt['pilots_id'])."')) sp ON sp.flightaware_id = spotter_archive_output.flightaware_id"; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
if (isset($flt['idents']) && !empty($flt['idents'])) { |
53
|
|
|
if (isset($flt['source'])) { |
54
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.ident IN ('".implode("','",$flt['idents'])."') AND spotter_archive_output.format_source IN ('".implode("','",$flt['source'])."')) spi ON spi.flightaware_id = spotter_archive_output.flightaware_id"; |
55
|
|
|
} else { |
56
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.ident IN ('".implode("','",$flt['idents'])."')) spi ON spi.flightaware_id = spotter_archive_output.flightaware_id"; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
if (isset($flt['registrations']) && !empty($flt['registrations'])) { |
60
|
|
|
if (isset($flt['source'])) { |
61
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.registration IN ('".implode("','",$flt['registrations'])."') AND spotter_archive_output.format_source IN ('".implode("','",$flt['source'])."')) sre ON sre.flightaware_id = spotter_archive_output.flightaware_id"; |
62
|
|
|
} else { |
63
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.registration IN ('".implode("','",$flt['registrations'])."')) sre ON sre.flightaware_id = spotter_archive_output.flightaware_id"; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
if ((isset($flt['airlines']) && empty($flt['airlines']) && isset($flt['pilots_id']) && empty($flt['pilots_id']) && isset($flt['idents']) && empty($flt['idents']) && isset($flt['registrations']) && empty($flt['registrations'])) || (!isset($flt['airlines']) && !isset($flt['pilots_id']) && !isset($flt['idents']) && !isset($flt['registrations']))) { |
67
|
|
|
if (isset($flt['source'])) { |
68
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_output.format_source IN ('".implode("','",$flt['source'])."')) saa ON saa.flightaware_id = spotter_archive_output.flightaware_id"; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
if (isset($filter['airlines']) && !empty($filter['airlines'])) { |
73
|
|
|
if ($filter['airlines'][0] != '' && $filter['airlines'][0] != 'all') { |
74
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) saf ON saf.flightaware_id = spotter_archive_output.flightaware_id"; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) { |
78
|
|
|
$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 "; |
79
|
|
|
} |
80
|
|
|
if (isset($filter['pilots_id']) && !empty($filter['pilots_id'])) { |
81
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output WHERE spotter_archive_output.pilot_id IN ('".implode("','",$filter['pilots_id'])."')) spi ON spi.flightaware_id = spotter_archive_output.flightaware_id"; |
82
|
|
|
} |
83
|
|
|
if (isset($filter['source']) && !empty($filter['source'])) { |
84
|
|
|
if (count($filter['source']) == 1) { |
85
|
|
|
$filter_query_where .= " AND format_source = '".$filter['source'][0]."'"; |
86
|
|
|
} else { |
87
|
|
|
$filter_query_where .= " AND format_source IN ('".implode("','",$filter['source'])."')"; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
if (isset($filter['ident']) && !empty($filter['ident'])) { |
91
|
|
|
$filter_query_where .= " AND ident = '".$filter['ident']."'"; |
92
|
|
|
} |
93
|
|
|
if (isset($filter['id']) && !empty($filter['id'])) { |
94
|
|
|
$filter_query_where .= " AND flightaware_id = '".$filter['id']."'"; |
95
|
|
|
} |
96
|
|
|
if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) { |
97
|
|
|
$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
98
|
|
|
} |
99
|
|
|
if ((isset($filter['year']) && $filter['year'] != '') || (isset($filter['month']) && $filter['month'] != '') || (isset($filter['day']) && $filter['day'] != '')) { |
100
|
|
|
$filter_query_date = ''; |
101
|
|
|
if (isset($filter['year']) && $filter['year'] != '') { |
102
|
|
|
if ($globalDBdriver == 'mysql') { |
103
|
|
|
$filter_query_date .= " AND YEAR(spotter_archive_output.date) = '".$filter['year']."'"; |
104
|
|
|
} else { |
105
|
|
|
$filter_query_date .= " AND EXTRACT(YEAR FROM spotter_archive_output.date) = '".$filter['year']."'"; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
if (isset($filter['month']) && $filter['month'] != '') { |
109
|
|
|
if ($globalDBdriver == 'mysql') { |
110
|
|
|
$filter_query_date .= " AND MONTH(spotter_archive_output.date) = '".$filter['month']."'"; |
111
|
|
|
} else { |
112
|
|
|
$filter_query_date .= " AND EXTRACT(MONTH FROM spotter_archive_output.date) = '".$filter['month']."'"; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
if (isset($filter['day']) && $filter['day'] != '') { |
116
|
|
|
if ($globalDBdriver == 'mysql') { |
117
|
|
|
$filter_query_date .= " AND DAY(spotter_archive_output.date) = '".$filter['day']."'"; |
118
|
|
|
} else { |
119
|
|
|
$filter_query_date .= " AND EXTRACT(DAY FROM spotter_archive_output.date) = '".$filter['day']."'"; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_archive_output".preg_replace('/^ AND/',' WHERE',$filter_query_date).") sd ON sd.flightaware_id = spotter_archive_output.flightaware_id"; |
123
|
|
|
} |
124
|
|
|
if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE'; |
125
|
|
|
elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND'; |
126
|
|
|
if ($filter_query_where != '') { |
127
|
|
|
$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where); |
128
|
|
|
} |
129
|
|
|
$filter_query = $filter_query_join.$filter_query_where; |
130
|
|
|
return $filter_query; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
// Spotter_archive |
134
|
|
|
public function addSpotterArchiveData($flightaware_id = '', $ident = '', $registration = '', $airline_name = '', $airline_icao = '', $airline_country = '', $airline_type = '', $aircraft_icao = '', $aircraft_shadow = '', $aircraft_name = '', $aircraft_manufacturer = '', $departure_airport_icao = '', $departure_airport_name = '', $departure_airport_city = '', $departure_airport_country = '', $departure_airport_time = '',$arrival_airport_icao = '', $arrival_airport_name = '', $arrival_airport_city ='', $arrival_airport_country = '', $arrival_airport_time = '', $route_stop = '', $date = '',$latitude = '', $longitude = '', $waypoints = '', $altitude = '', $real_altitude = '',$heading = '', $ground_speed = '', $squawk = '', $ModeS = '', $pilot_id = '', $pilot_name = '',$verticalrate = '',$format_source = '', $source_name = '', $over_country = '') { |
135
|
|
|
require_once(dirname(__FILE__).'/class.Spotter.php'); |
136
|
|
|
if ($over_country == '') { |
137
|
|
|
$Spotter = new Spotter($this->db); |
138
|
|
|
$data_country = $Spotter->getCountryFromLatitudeLongitude($latitude,$longitude); |
139
|
|
|
if (!empty($data_country)) $country = $data_country['iso2']; |
140
|
|
|
else $country = ''; |
141
|
|
|
} else $country = $over_country; |
142
|
|
|
if ($airline_type === NULL) $airline_type =''; |
143
|
|
|
|
144
|
|
|
//if ($country == '') echo "\n".'************ UNKNOW COUNTRY ****************'."\n"; |
145
|
|
|
//else echo "\n".'*/*/*/*/*/*/*/ Country : '.$country.' */*/*/*/*/*/*/*/*/'."\n"; |
146
|
|
|
|
147
|
|
|
// Route is not added in spotter_archive |
148
|
|
|
$query = "INSERT INTO spotter_archive (flightaware_id, ident, registration, airline_name, airline_icao, airline_country, airline_type, aircraft_icao, aircraft_shadow, aircraft_name, aircraft_manufacturer, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, departure_airport_time,arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, arrival_airport_time, route_stop, date,latitude, longitude, waypoints, altitude, heading, ground_speed, squawk, ModeS, pilot_id, pilot_name, verticalrate,format_source,over_country,source_name,real_altitude) |
149
|
|
|
VALUES (:flightaware_id, :ident, :registration, :airline_name, :airline_icao, :airline_country, :airline_type, :aircraft_icao, :aircraft_shadow, :aircraft_name, :aircraft_manufacturer, :departure_airport_icao, :departure_airport_name, :departure_airport_city, :departure_airport_country, :departure_airport_time,:arrival_airport_icao, :arrival_airport_name, :arrival_airport_city, :arrival_airport_country, :arrival_airport_time, :route_stop, :date,:latitude, :longitude, :waypoints, :altitude, :heading, :ground_speed, :squawk, :ModeS, :pilot_id, :pilot_name, :verticalrate, :format_source, :over_country, :source_name,:real_altitude)"; |
150
|
|
|
|
151
|
|
|
$query_values = array(':flightaware_id' => $flightaware_id, ':ident' => $ident, ':registration' => $registration, ':airline_name' => $airline_name, ':airline_icao' => $airline_icao, ':airline_country' => $airline_country, ':airline_type' => $airline_type, ':aircraft_icao' => $aircraft_icao, ':aircraft_shadow' => $aircraft_shadow, ':aircraft_name' => $aircraft_name, ':aircraft_manufacturer' => $aircraft_manufacturer, ':departure_airport_icao' => $departure_airport_icao, ':departure_airport_name' => $departure_airport_name, ':departure_airport_city' => $departure_airport_city, ':departure_airport_country' => $departure_airport_country, ':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao, ':arrival_airport_name' => $arrival_airport_name, ':arrival_airport_city' => $arrival_airport_city, ':arrival_airport_country' => $arrival_airport_country, ':arrival_airport_time' => $arrival_airport_time, ':route_stop' => $route_stop, ':date' => $date,':latitude' => $latitude, ':longitude' => $longitude, ':waypoints' => $waypoints, ':altitude' => $altitude, ':heading' => $heading, ':ground_speed' => $ground_speed, ':squawk' => $squawk, ':ModeS' => $ModeS, ':pilot_id' => $pilot_id, ':pilot_name' => $pilot_name, ':verticalrate' => $verticalrate, ':format_source' => $format_source, ':over_country' => $country, ':source_name' => $source_name,':real_altitude' => $real_altitude); |
152
|
|
|
try { |
153
|
|
|
$sth = $this->db->prepare($query); |
154
|
|
|
$sth->execute($query_values); |
155
|
|
|
$sth->closeCursor(); |
156
|
|
|
} catch(PDOException $e) { |
157
|
|
|
return "error : ".$e->getMessage(); |
158
|
|
|
} |
159
|
|
|
return "success"; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Gets all the spotter information based on a particular callsign |
165
|
|
|
* |
166
|
|
|
* @param $ident |
167
|
|
|
* @return array the spotter information |
168
|
|
|
*/ |
169
|
|
|
public function getLastArchiveSpotterDataByIdent($ident) { |
170
|
|
|
$Spotter = new Spotter($this->db); |
171
|
|
|
date_default_timezone_set('UTC'); |
172
|
|
|
|
173
|
|
|
$ident = filter_var($ident, FILTER_SANITIZE_STRING); |
174
|
|
|
//$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"; |
175
|
|
|
$query = "SELECT spotter_archive.* FROM spotter_archive WHERE ident = :ident ORDER BY date DESC LIMIT 1"; |
176
|
|
|
|
177
|
|
|
$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident)); |
178
|
|
|
|
179
|
|
|
return $spotter_array; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Gets last the spotter information based on a particular id |
185
|
|
|
* |
186
|
|
|
* @param $id |
187
|
|
|
* @return array the spotter information |
188
|
|
|
*/ |
189
|
|
|
public function getLastArchiveSpotterDataById($id) { |
190
|
|
|
$Spotter = new Spotter($this->db); |
191
|
|
|
date_default_timezone_set('UTC'); |
192
|
|
|
$id = filter_var($id, FILTER_SANITIZE_STRING); |
193
|
|
|
//$query = SpotterArchive->$global_query." WHERE spotter_archive.flightaware_id = :id"; |
194
|
|
|
//$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"; |
195
|
|
|
$query = "SELECT * FROM spotter_archive WHERE flightaware_id = :id ORDER BY date DESC LIMIT 1"; |
196
|
|
|
|
197
|
|
|
// $spotter_array = Spotter->getDataFromDB($query,array(':id' => $id)); |
198
|
|
|
/* |
199
|
|
|
try { |
200
|
|
|
$Connection = new Connection(); |
201
|
|
|
$sth = Connection->$db->prepare($query); |
202
|
|
|
$sth->execute(array(':id' => $id)); |
203
|
|
|
} catch(PDOException $e) { |
204
|
|
|
return "error"; |
205
|
|
|
} |
206
|
|
|
$spotter_array = $sth->fetchAll(PDO->FETCH_ASSOC); |
207
|
|
|
*/ |
208
|
|
|
$spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id)); |
209
|
|
|
|
210
|
|
|
return $spotter_array; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Gets all the spotter information based on a particular id |
215
|
|
|
* |
216
|
|
|
* @param $id |
217
|
|
|
* @return array the spotter information |
218
|
|
|
*/ |
219
|
|
|
public function getAllArchiveSpotterDataById($id) { |
220
|
|
|
date_default_timezone_set('UTC'); |
221
|
|
|
$id = filter_var($id, FILTER_SANITIZE_STRING); |
222
|
|
|
$query = $this->global_query." WHERE spotter_archive.flightaware_id = :id ORDER BY date"; |
223
|
|
|
|
224
|
|
|
// $spotter_array = Spotter->getDataFromDB($query,array(':id' => $id)); |
225
|
|
|
|
226
|
|
|
try { |
227
|
|
|
$sth = $this->db->prepare($query); |
228
|
|
|
$sth->execute(array(':id' => $id)); |
229
|
|
|
} catch(PDOException $e) { |
230
|
|
|
echo $e->getMessage(); |
231
|
|
|
die; |
232
|
|
|
} |
233
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
234
|
|
|
|
235
|
|
|
return $spotter_array; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Gets coordinate & time spotter information based on a particular id |
240
|
|
|
* |
241
|
|
|
* @param $id |
242
|
|
|
* @return array the spotter information |
243
|
|
|
*/ |
244
|
|
|
public function getCoordArchiveSpotterDataById($id) { |
245
|
|
|
date_default_timezone_set('UTC'); |
246
|
|
|
$id = filter_var($id, FILTER_SANITIZE_STRING); |
247
|
|
|
$query = "SELECT spotter_archive.latitude, spotter_archive.longitude, spotter_archive.date FROM spotter_archive WHERE spotter_archive.flightaware_id = :id ORDER by spotter_archive.date ASC"; |
248
|
|
|
try { |
249
|
|
|
$sth = $this->db->prepare($query); |
250
|
|
|
$sth->execute(array(':id' => $id)); |
251
|
|
|
} catch(PDOException $e) { |
252
|
|
|
echo $e->getMessage(); |
253
|
|
|
die; |
254
|
|
|
} |
255
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
256
|
|
|
return $spotter_array; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* Gets coordinate & time spotter information based on a particular id |
261
|
|
|
* |
262
|
|
|
* @param $id |
263
|
|
|
* @param $begindate |
264
|
|
|
* @param $enddate |
265
|
|
|
* @return array the spotter information |
266
|
|
|
*/ |
267
|
|
|
public function getCoordArchiveSpotterDataByIdDate($id,$begindate,$enddate) { |
268
|
|
|
date_default_timezone_set('UTC'); |
269
|
|
|
$id = filter_var($id, FILTER_SANITIZE_STRING); |
270
|
|
|
$query = "SELECT spotter_archive.latitude, spotter_archive.longitude, spotter_archive.date FROM spotter_archive WHERE spotter_archive.flightaware_id = :id AND spotter_archive.date BETWEEN :begindate AND :enddate ORDER by spotter_archive.date ASC"; |
271
|
|
|
try { |
272
|
|
|
$sth = $this->db->prepare($query); |
273
|
|
|
$sth->execute(array(':id' => $id,':begindate' => $begindate,':enddate' => $enddate)); |
274
|
|
|
} catch(PDOException $e) { |
275
|
|
|
echo $e->getMessage(); |
276
|
|
|
die; |
277
|
|
|
} |
278
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
279
|
|
|
return $spotter_array; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* Gets altitude information based on a particular callsign |
285
|
|
|
* |
286
|
|
|
* @param $ident |
287
|
|
|
* @return array the spotter information |
288
|
|
|
*/ |
289
|
|
|
public function getAltitudeArchiveSpotterDataByIdent($ident) { |
290
|
|
|
|
291
|
|
|
date_default_timezone_set('UTC'); |
292
|
|
|
|
293
|
|
|
$ident = filter_var($ident, FILTER_SANITIZE_STRING); |
294
|
|
|
$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"; |
295
|
|
|
|
296
|
|
|
try { |
297
|
|
|
$sth = $this->db->prepare($query); |
298
|
|
|
$sth->execute(array(':ident' => $ident)); |
299
|
|
|
} catch(PDOException $e) { |
300
|
|
|
echo $e->getMessage(); |
301
|
|
|
die; |
302
|
|
|
} |
303
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
304
|
|
|
|
305
|
|
|
return $spotter_array; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* Gets altitude information based on a particular id |
310
|
|
|
* |
311
|
|
|
* @param $id |
312
|
|
|
* @return array the spotter information |
313
|
|
|
*/ |
314
|
|
|
public function getAltitudeArchiveSpotterDataById($id) { |
315
|
|
|
|
316
|
|
|
date_default_timezone_set('UTC'); |
317
|
|
|
|
318
|
|
|
$id = filter_var($id, FILTER_SANITIZE_STRING); |
319
|
|
|
$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"; |
320
|
|
|
|
321
|
|
|
try { |
322
|
|
|
$sth = $this->db->prepare($query); |
323
|
|
|
$sth->execute(array(':id' => $id)); |
324
|
|
|
} catch(PDOException $e) { |
325
|
|
|
echo $e->getMessage(); |
326
|
|
|
die; |
327
|
|
|
} |
328
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
329
|
|
|
|
330
|
|
|
return $spotter_array; |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* Gets altitude & speed information based on a particular id |
335
|
|
|
* |
336
|
|
|
* @param $id |
337
|
|
|
* @return array the spotter information |
338
|
|
|
*/ |
339
|
|
|
public function getAltitudeSpeedArchiveSpotterDataById($id) { |
340
|
|
|
date_default_timezone_set('UTC'); |
341
|
|
|
$id = filter_var($id, FILTER_SANITIZE_STRING); |
342
|
|
|
$query = "SELECT spotter_archive.altitude, spotter_archive.real_altitude,spotter_archive.ground_speed, spotter_archive.date FROM spotter_archive WHERE spotter_archive.flightaware_id = :id ORDER BY date"; |
343
|
|
|
try { |
344
|
|
|
$sth = $this->db->prepare($query); |
345
|
|
|
$sth->execute(array(':id' => $id)); |
346
|
|
|
} catch(PDOException $e) { |
347
|
|
|
echo $e->getMessage(); |
348
|
|
|
die; |
349
|
|
|
} |
350
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
351
|
|
|
return $spotter_array; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* Gets altitude information based on a particular callsign |
356
|
|
|
* |
357
|
|
|
* @param $ident |
358
|
|
|
* @return array the spotter information |
359
|
|
|
*/ |
360
|
|
|
public function getLastAltitudeArchiveSpotterDataByIdent($ident) { |
361
|
|
|
date_default_timezone_set('UTC'); |
362
|
|
|
$ident = filter_var($ident, FILTER_SANITIZE_STRING); |
363
|
|
|
$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"; |
364
|
|
|
// $query = "SELECT spotter_archive.altitude, spotter_archive.date FROM spotter_archive WHERE spotter_archive.ident = :ident"; |
365
|
|
|
try { |
366
|
|
|
$sth = $this->db->prepare($query); |
367
|
|
|
$sth->execute(array(':ident' => $ident)); |
368
|
|
|
} catch(PDOException $e) { |
369
|
|
|
echo $e->getMessage(); |
370
|
|
|
die; |
371
|
|
|
} |
372
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
373
|
|
|
return $spotter_array; |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* Gets all the archive spotter information |
379
|
|
|
* |
380
|
|
|
* @param $ident |
381
|
|
|
* @param $flightaware_id |
382
|
|
|
* @param $date |
383
|
|
|
* @return array the spotter information |
384
|
|
|
*/ |
385
|
|
|
public function getSpotterArchiveData($ident,$flightaware_id,$date) { |
386
|
|
|
$Spotter = new Spotter($this->db); |
387
|
|
|
$ident = filter_var($ident, FILTER_SANITIZE_STRING); |
388
|
|
|
$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"; |
389
|
|
|
$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident,':flightaware_id' => $flightaware_id,':date' => $date.'%')); |
390
|
|
|
return $spotter_array; |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
public function deleteSpotterArchiveTrackData() { |
394
|
|
|
global $globalArchiveKeepTrackMonths, $globalDBdriver; |
395
|
|
|
if ($globalDBdriver == 'mysql') { |
396
|
|
|
$query = 'DELETE FROM spotter_archive WHERE spotter_archive.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$globalArchiveKeepTrackMonths.' MONTH) LIMIT 10000'; |
397
|
|
|
} else { |
398
|
|
|
$query = "DELETE FROM spotter_archive WHERE spotter_archive_id IN (SELECT spotter_archive_id FROM spotter_archive WHERE spotter_archive.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveKeepTrackMonths." MONTH' LIMIT 10000)"; |
399
|
|
|
} |
400
|
|
|
try { |
401
|
|
|
$sth = $this->db->prepare($query); |
402
|
|
|
$sth->execute(); |
403
|
|
|
} catch(PDOException $e) { |
404
|
|
|
echo $e->getMessage(); |
405
|
|
|
die; |
406
|
|
|
} |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
/** |
410
|
|
|
* Delete row in spotter_archive table based on flightaware_id |
411
|
|
|
* @param $id flightaware_id |
412
|
|
|
*/ |
413
|
|
|
public function deleteSpotterArchiveTrackDataByID($id) { |
414
|
|
|
global $globalArchiveKeepTrackMonths, $globalDBdriver; |
415
|
|
|
$query = 'DELETE FROM spotter_archive WHERE spotter_archive.flightaware_id = :id'; |
416
|
|
|
try { |
417
|
|
|
$sth = $this->db->prepare($query); |
418
|
|
|
$sth->execute(array(':id' => $id)); |
419
|
|
|
} catch(PDOException $e) { |
420
|
|
|
echo $e->getMessage(); |
421
|
|
|
die; |
422
|
|
|
} |
423
|
|
|
} |
424
|
|
|
|
425
|
|
|
/** |
426
|
|
|
* Gets Minimal Live Spotter data |
427
|
|
|
* |
428
|
|
|
* @param $begindate |
429
|
|
|
* @param $enddate |
430
|
|
|
* @param array $filter |
431
|
|
|
* @param int $part |
432
|
|
|
* @return array the spotter information |
433
|
|
|
*/ |
434
|
|
|
public function getMinLiveSpotterData($begindate,$enddate,$filter = array(),$part = 0) { |
435
|
|
|
global $globalDBdriver; |
436
|
|
|
date_default_timezone_set('UTC'); |
437
|
|
|
//$filter_query = $this->getFilter($filter,true,true); |
438
|
|
|
|
439
|
|
|
$filter_query = ''; |
440
|
|
|
if (isset($filter['source']) && !empty($filter['source'])) { |
441
|
|
|
$filter_query .= " AND format_source IN ('".implode("','",$filter['source'])."') "; |
442
|
|
|
} |
443
|
|
|
// Use spotter_output also ? |
444
|
|
|
if (isset($filter['airlines']) && !empty($filter['airlines'])) { |
445
|
|
|
$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 "; |
446
|
|
|
} |
447
|
|
|
if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) { |
448
|
|
|
$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 "; |
449
|
|
|
} |
450
|
|
|
if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) { |
451
|
|
|
$filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
$limit = ''; |
455
|
|
|
if ($part != 0) { |
456
|
|
|
$limit = ' LIMIT 100 OFFSET '.($part-1)*100; |
457
|
|
|
} |
458
|
|
|
if ($globalDBdriver == 'mysql') { |
459
|
|
|
$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 |
460
|
|
|
FROM spotter_archive |
461
|
|
|
INNER JOIN aircraft a on spotter_archive.aircraft_icao = a.icao |
462
|
|
|
WHERE spotter_archive.date BETWEEN '."'".$begindate."'".' AND '."'".$enddate."'".' |
463
|
|
|
'.$filter_query.' ORDER BY flightaware_id'.$limit; |
464
|
|
|
} else { |
465
|
|
|
|
466
|
|
|
$query = 'SELECT spotter_archive.flightaware_id, spotter_archive.date, spotter_archive.ident, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, a.aircraft_shadow,a.engine_type, a.engine_count, a.wake_category |
467
|
|
|
FROM spotter_archive |
468
|
|
|
INNER JOIN aircraft a on spotter_archive.aircraft_icao = a.icao |
469
|
|
|
WHERE spotter_archive.date BETWEEN '."'".$begindate."'".' AND '."'".$enddate."'".' |
470
|
|
|
'.$filter_query.' ORDER BY flightaware_id'.$limit; |
471
|
|
|
} |
472
|
|
|
|
473
|
|
|
try { |
474
|
|
|
$sth = $this->db->prepare($query); |
475
|
|
|
$sth->execute(); |
476
|
|
|
} catch(PDOException $e) { |
477
|
|
|
echo $e->getMessage(); |
478
|
|
|
die; |
479
|
|
|
} |
480
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
481
|
|
|
return $spotter_array; |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
/** |
485
|
|
|
* Gets Minimal Live Spotter data |
486
|
|
|
* |
487
|
|
|
* @param $begindate |
488
|
|
|
* @param $enddate |
489
|
|
|
* @param array $filter |
490
|
|
|
* @return array the spotter information |
491
|
|
|
*/ |
492
|
|
|
public function getMinLiveSpotterDataPlayback($begindate,$enddate,$filter = array()) { |
493
|
|
|
global $globalDBdriver; |
494
|
|
|
date_default_timezone_set('UTC'); |
495
|
|
|
|
496
|
|
|
//$filter_query = $this->getFilter($filter,true,true); |
497
|
|
|
|
498
|
|
|
$filter_query = ''; |
499
|
|
|
if (isset($filter['source']) && !empty($filter['source'])) { |
500
|
|
|
$filter_query .= " AND format_source IN ('".implode("','",$filter['source'])."') "; |
501
|
|
|
} |
502
|
|
|
// Use spotter_output also ? |
503
|
|
|
if (isset($filter['airlines']) && !empty($filter['airlines'])) { |
504
|
|
|
$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 "; |
505
|
|
|
} |
506
|
|
|
if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) { |
507
|
|
|
$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 "; |
508
|
|
|
} |
509
|
|
|
if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) { |
510
|
|
|
$filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
|
514
|
|
|
//if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
515
|
|
|
if ($globalDBdriver == 'mysql') { |
516
|
|
|
/* |
517
|
|
|
$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 |
518
|
|
|
FROM spotter_archive |
519
|
|
|
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'; |
520
|
|
|
*/ |
521
|
|
|
$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 |
522
|
|
|
FROM spotter_archive_output |
523
|
|
|
LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_archive_output.aircraft_icao = a.icao |
524
|
|
|
WHERE (spotter_archive_output.date BETWEEN '."'".$begindate."'".' AND '."'".$enddate."'".') |
525
|
|
|
'.$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'; |
526
|
|
|
|
527
|
|
|
} else { |
528
|
|
|
//$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'; |
529
|
|
|
/* |
530
|
|
|
$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 |
531
|
|
|
FROM spotter_archive_output |
532
|
|
|
INNER JOIN (SELECT * FROM aircraft) a on spotter_archive_output.aircraft_icao = a.icao |
533
|
|
|
WHERE spotter_archive_output.date >= '."'".$begindate."'".' AND spotter_archive_output.date <= '."'".$enddate."'".' |
534
|
|
|
'.$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'; |
535
|
|
|
*/ |
536
|
|
|
$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 |
537
|
|
|
FROM spotter_archive_output |
538
|
|
|
INNER JOIN (SELECT * FROM aircraft) a on spotter_archive_output.aircraft_icao = a.icao |
539
|
|
|
WHERE spotter_archive_output.date >= '."'".$begindate."'".' AND spotter_archive_output.date <= '."'".$enddate."'".' |
540
|
|
|
'.$filter_query.' LIMIT 200 OFFSET 0'; |
541
|
|
|
// .' 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'; |
542
|
|
|
|
543
|
|
|
} |
544
|
|
|
//echo $query; |
545
|
|
|
try { |
546
|
|
|
$sth = $this->db->prepare($query); |
547
|
|
|
$sth->execute(); |
548
|
|
|
} catch(PDOException $e) { |
549
|
|
|
echo $e->getMessage(); |
550
|
|
|
die; |
551
|
|
|
} |
552
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
553
|
|
|
|
554
|
|
|
return $spotter_array; |
555
|
|
|
} |
556
|
|
|
|
557
|
|
|
/** |
558
|
|
|
* Gets count Live Spotter data |
559
|
|
|
* |
560
|
|
|
* @param $begindate |
561
|
|
|
* @param $enddate |
562
|
|
|
* @param array $filter |
563
|
|
|
* @return array the spotter information |
564
|
|
|
*/ |
565
|
|
|
public function getLiveSpotterCount($begindate,$enddate,$filter = array()) { |
566
|
|
|
global $globalDBdriver, $globalLiveInterval; |
567
|
|
|
date_default_timezone_set('UTC'); |
568
|
|
|
|
569
|
|
|
$filter_query = ''; |
570
|
|
|
if (isset($filter['source']) && !empty($filter['source'])) { |
571
|
|
|
$filter_query .= " AND format_source IN ('".implode("','",$filter['source'])."') "; |
572
|
|
|
} |
573
|
|
|
if (isset($filter['airlines']) && !empty($filter['airlines'])) { |
574
|
|
|
$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 "; |
575
|
|
|
} |
576
|
|
|
if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) { |
577
|
|
|
$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 "; |
578
|
|
|
} |
579
|
|
|
if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) { |
580
|
|
|
$filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
581
|
|
|
} |
582
|
|
|
|
583
|
|
|
//if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
584
|
|
|
if ($globalDBdriver == 'mysql') { |
585
|
|
|
$query = 'SELECT COUNT(DISTINCT flightaware_id) as nb |
586
|
|
|
FROM spotter_archive l |
587
|
|
|
WHERE (l.date BETWEEN DATE_SUB('."'".$begindate."'".',INTERVAL '.$globalLiveInterval.' SECOND) AND '."'".$begindate."'".')'.$filter_query; |
588
|
|
|
} else { |
589
|
|
|
$query = 'SELECT COUNT(DISTINCT flightaware_id) as nb FROM spotter_archive l WHERE (l.date BETWEEN '."'".$begindate."' - INTERVAL '".$globalLiveInterval." SECONDS' AND "."'".$enddate."'".')'.$filter_query; |
590
|
|
|
} |
591
|
|
|
//echo $query; |
592
|
|
|
try { |
593
|
|
|
$sth = $this->db->prepare($query); |
594
|
|
|
$sth->execute(); |
595
|
|
|
} catch(PDOException $e) { |
596
|
|
|
echo $e->getMessage(); |
597
|
|
|
die; |
598
|
|
|
} |
599
|
|
|
$result = $sth->fetch(PDO::FETCH_ASSOC); |
600
|
|
|
$sth->closeCursor(); |
601
|
|
|
return $result['nb']; |
602
|
|
|
|
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
|
606
|
|
|
|
607
|
|
|
// Spotter_Archive_output |
608
|
|
|
|
609
|
|
|
/** |
610
|
|
|
* Gets all the spotter information |
611
|
|
|
* |
612
|
|
|
* @param string $q |
613
|
|
|
* @param string $registration |
614
|
|
|
* @param string $aircraft_icao |
615
|
|
|
* @param string $aircraft_manufacturer |
616
|
|
|
* @param string $highlights |
617
|
|
|
* @param string $airline_icao |
618
|
|
|
* @param string $airline_country |
619
|
|
|
* @param string $airline_type |
620
|
|
|
* @param string $airport |
621
|
|
|
* @param string $airport_country |
622
|
|
|
* @param string $callsign |
623
|
|
|
* @param string $departure_airport_route |
624
|
|
|
* @param string $arrival_airport_route |
625
|
|
|
* @param string $owner |
626
|
|
|
* @param string $pilot_id |
627
|
|
|
* @param string $pilot_name |
628
|
|
|
* @param string $altitude |
629
|
|
|
* @param string $date_posted |
630
|
|
|
* @param string $limit |
631
|
|
|
* @param string $sort |
632
|
|
|
* @param string $includegeodata |
633
|
|
|
* @param string $origLat |
634
|
|
|
* @param string $origLon |
635
|
|
|
* @param string $dist |
636
|
|
|
* @param array $filters |
637
|
|
|
* @return array the spotter information |
638
|
|
|
*/ |
639
|
|
|
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()) { |
640
|
|
|
global $globalTimezone, $globalDBdriver; |
641
|
|
|
require_once(dirname(__FILE__).'/class.Translation.php'); |
642
|
|
|
$Translation = new Translation($this->db); |
643
|
|
|
$Spotter = new Spotter($this->db); |
644
|
|
|
|
645
|
|
|
date_default_timezone_set('UTC'); |
646
|
|
|
|
647
|
|
|
$query_values = array(); |
648
|
|
|
$additional_query = ''; |
649
|
|
|
$limit_query = ''; |
650
|
|
|
$filter_query = $this->getFilter($filters); |
651
|
|
|
if ($q != "") { |
652
|
|
|
if (!is_string($q)) { |
653
|
|
|
return array(); |
654
|
|
|
} else { |
655
|
|
|
|
656
|
|
|
$q_array = explode(" ", $q); |
657
|
|
|
|
658
|
|
|
foreach ($q_array as $q_item) { |
659
|
|
|
$additional_query .= " AND ("; |
660
|
|
|
$additional_query .= "(spotter_archive_output.spotter_id like '%".$q_item."%') OR "; |
661
|
|
|
$additional_query .= "(spotter_archive_output.aircraft_icao like '%".$q_item."%') OR "; |
662
|
|
|
$additional_query .= "(spotter_archive_output.aircraft_name like '%".$q_item."%') OR "; |
663
|
|
|
$additional_query .= "(spotter_archive_output.aircraft_manufacturer like '%".$q_item."%') OR "; |
664
|
|
|
$additional_query .= "(spotter_archive_output.airline_icao like '%".$q_item."%') OR "; |
665
|
|
|
$additional_query .= "(spotter_archive_output.airline_name like '%".$q_item."%') OR "; |
666
|
|
|
$additional_query .= "(spotter_archive_output.airline_country like '%".$q_item."%') OR "; |
667
|
|
|
$additional_query .= "(spotter_archive_output.departure_airport_icao like '%".$q_item."%') OR "; |
668
|
|
|
$additional_query .= "(spotter_archive_output.departure_airport_name like '%".$q_item."%') OR "; |
669
|
|
|
$additional_query .= "(spotter_archive_output.departure_airport_city like '%".$q_item."%') OR "; |
670
|
|
|
$additional_query .= "(spotter_archive_output.departure_airport_country like '%".$q_item."%') OR "; |
671
|
|
|
$additional_query .= "(spotter_archive_output.arrival_airport_icao like '%".$q_item."%') OR "; |
672
|
|
|
$additional_query .= "(spotter_archive_output.arrival_airport_name like '%".$q_item."%') OR "; |
673
|
|
|
$additional_query .= "(spotter_archive_output.arrival_airport_city like '%".$q_item."%') OR "; |
674
|
|
|
$additional_query .= "(spotter_archive_output.arrival_airport_country like '%".$q_item."%') OR "; |
675
|
|
|
$additional_query .= "(spotter_archive_output.registration like '%".$q_item."%') OR "; |
676
|
|
|
$additional_query .= "(spotter_archive_output.owner_name like '%".$q_item."%') OR "; |
677
|
|
|
$additional_query .= "(spotter_archive_output.pilot_id like '%".$q_item."%') OR "; |
678
|
|
|
$additional_query .= "(spotter_archive_output.pilot_name like '%".$q_item."%') OR "; |
679
|
|
|
$additional_query .= "(spotter_archive_output.ident like '%".$q_item."%') OR "; |
680
|
|
|
$translate = $Translation->ident2icao($q_item); |
681
|
|
|
if ($translate != $q_item) $additional_query .= "(spotter_archive_output.ident like '%".$translate."%') OR "; |
682
|
|
|
$additional_query .= "(spotter_archive_output.highlight like '%".$q_item."%')"; |
683
|
|
|
$additional_query .= ")"; |
684
|
|
|
} |
685
|
|
|
} |
686
|
|
|
} |
687
|
|
|
|
688
|
|
|
if ($registration != "") { |
689
|
|
|
$registration = filter_var($registration,FILTER_SANITIZE_STRING); |
690
|
|
|
if (!is_string($registration)) { |
691
|
|
|
return array(); |
692
|
|
|
} else { |
693
|
|
|
$additional_query .= " AND (spotter_archive_output.registration = '".$registration."')"; |
694
|
|
|
} |
695
|
|
|
} |
696
|
|
|
|
697
|
|
|
if ($aircraft_icao != "") { |
698
|
|
|
$aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
699
|
|
|
if (!is_string($aircraft_icao)) { |
700
|
|
|
return array(); |
701
|
|
|
} else { |
702
|
|
|
$additional_query .= " AND (spotter_archive_output.aircraft_icao = '".$aircraft_icao."')"; |
703
|
|
|
} |
704
|
|
|
} |
705
|
|
|
|
706
|
|
|
if ($aircraft_manufacturer != "") { |
707
|
|
|
$aircraft_manufacturer = filter_var($aircraft_manufacturer,FILTER_SANITIZE_STRING); |
708
|
|
|
if (!is_string($aircraft_manufacturer)) { |
709
|
|
|
return array(); |
710
|
|
|
} else { |
711
|
|
|
$additional_query .= " AND (spotter_archive_output.aircraft_manufacturer = '".$aircraft_manufacturer."')"; |
712
|
|
|
} |
713
|
|
|
} |
714
|
|
|
|
715
|
|
|
if ($highlights == "true") { |
716
|
|
|
if (!is_string($highlights)) { |
717
|
|
|
return array(); |
718
|
|
|
} else { |
719
|
|
|
$additional_query .= " AND (spotter_archive_output.highlight <> '')"; |
720
|
|
|
} |
721
|
|
|
} |
722
|
|
|
|
723
|
|
|
if ($airline_icao != "") { |
724
|
|
|
$airline_icao = filter_var($airline_icao,FILTER_SANITIZE_STRING); |
725
|
|
|
if (!is_string($airline_icao)) { |
726
|
|
|
return array(); |
727
|
|
|
} else { |
728
|
|
|
$additional_query .= " AND (spotter_archive_output.airline_icao = '".$airline_icao."')"; |
729
|
|
|
} |
730
|
|
|
} |
731
|
|
|
|
732
|
|
|
if ($airline_country != "") { |
733
|
|
|
$airline_country = filter_var($airline_country,FILTER_SANITIZE_STRING); |
734
|
|
|
if (!is_string($airline_country)) { |
735
|
|
|
return array(); |
736
|
|
|
} else { |
737
|
|
|
$additional_query .= " AND (spotter_archive_output.airline_country = '".$airline_country."')"; |
738
|
|
|
} |
739
|
|
|
} |
740
|
|
|
|
741
|
|
|
if ($airline_type != "") { |
742
|
|
|
$airline_type = filter_var($airline_type,FILTER_SANITIZE_STRING); |
743
|
|
|
if (!is_string($airline_type)) { |
744
|
|
|
return array(); |
745
|
|
|
} else { |
746
|
|
|
if ($airline_type == "passenger") { |
747
|
|
|
$additional_query .= " AND (spotter_archive_output.airline_type = 'passenger')"; |
748
|
|
|
} |
749
|
|
|
if ($airline_type == "cargo") { |
750
|
|
|
$additional_query .= " AND (spotter_archive_output.airline_type = 'cargo')"; |
751
|
|
|
} |
752
|
|
|
if ($airline_type == "military") { |
753
|
|
|
$additional_query .= " AND (spotter_archive_output.airline_type = 'military')"; |
754
|
|
|
} |
755
|
|
|
} |
756
|
|
|
} |
757
|
|
|
|
758
|
|
|
if ($airport != "") { |
759
|
|
|
$airport = filter_var($airport,FILTER_SANITIZE_STRING); |
760
|
|
|
if (!is_string($airport)) { |
761
|
|
|
return array(); |
762
|
|
|
} else { |
763
|
|
|
$additional_query .= " AND ((spotter_archive_output.departure_airport_icao = '".$airport."') OR (spotter_archive_output.arrival_airport_icao = '".$airport."'))"; |
764
|
|
|
} |
765
|
|
|
} |
766
|
|
|
|
767
|
|
|
if ($airport_country != "") { |
768
|
|
|
$airport_country = filter_var($airport_country,FILTER_SANITIZE_STRING); |
769
|
|
|
if (!is_string($airport_country)) { |
770
|
|
|
return array(); |
771
|
|
|
} else { |
772
|
|
|
$additional_query .= " AND ((spotter_archive_output.departure_airport_country = '".$airport_country."') OR (spotter_archive_output.arrival_airport_country = '".$airport_country."'))"; |
773
|
|
|
} |
774
|
|
|
} |
775
|
|
|
|
776
|
|
|
if ($callsign != "") { |
777
|
|
|
$callsign = filter_var($callsign,FILTER_SANITIZE_STRING); |
778
|
|
|
if (!is_string($callsign)) { |
779
|
|
|
return array(); |
780
|
|
|
} else { |
781
|
|
|
$translate = $Translation->ident2icao($callsign); |
782
|
|
|
if ($translate != $callsign) { |
783
|
|
|
$additional_query .= " AND (spotter_archive_output.ident = :callsign OR spotter_archive_output.ident = :translate)"; |
784
|
|
|
$query_values = array_merge($query_values,array(':callsign' => $callsign,':translate' => $translate)); |
785
|
|
|
} else { |
786
|
|
|
$additional_query .= " AND (spotter_archive_output.ident = '".$callsign."')"; |
787
|
|
|
} |
788
|
|
|
} |
789
|
|
|
} |
790
|
|
|
|
791
|
|
|
if ($owner != "") { |
792
|
|
|
$owner = filter_var($owner,FILTER_SANITIZE_STRING); |
793
|
|
|
if (!is_string($owner)) { |
794
|
|
|
return array(); |
795
|
|
|
} else { |
796
|
|
|
$additional_query .= " AND (spotter_archive_output.owner_name = '".$owner."')"; |
797
|
|
|
} |
798
|
|
|
} |
799
|
|
|
|
800
|
|
|
if ($pilot_name != "") { |
801
|
|
|
$pilot_name = filter_var($pilot_name,FILTER_SANITIZE_STRING); |
802
|
|
|
if (!is_string($pilot_name)) { |
803
|
|
|
return array(); |
804
|
|
|
} else { |
805
|
|
|
$additional_query .= " AND (spotter_archive_output.pilot_name = '".$pilot_name."')"; |
806
|
|
|
} |
807
|
|
|
} |
808
|
|
|
|
809
|
|
|
if ($pilot_id != "") { |
810
|
|
|
$pilot_id = filter_var($pilot_id,FILTER_SANITIZE_NUMBER_INT); |
811
|
|
|
if (!is_string($pilot_id)) { |
812
|
|
|
return array(); |
813
|
|
|
} else { |
814
|
|
|
$additional_query .= " AND (spotter_archive_output.pilot_id = '".$pilot_id."')"; |
815
|
|
|
} |
816
|
|
|
} |
817
|
|
|
|
818
|
|
|
if ($departure_airport_route != "") { |
819
|
|
|
$departure_airport_route = filter_var($departure_airport_route,FILTER_SANITIZE_STRING); |
820
|
|
|
if (!is_string($departure_airport_route)) { |
821
|
|
|
return array(); |
822
|
|
|
} else { |
823
|
|
|
$additional_query .= " AND (spotter_archive_output.departure_airport_icao = '".$departure_airport_route."')"; |
824
|
|
|
} |
825
|
|
|
} |
826
|
|
|
|
827
|
|
|
if ($arrival_airport_route != "") { |
828
|
|
|
$arrival_airport_route = filter_var($arrival_airport_route,FILTER_SANITIZE_STRING); |
829
|
|
|
if (!is_string($arrival_airport_route)) { |
830
|
|
|
return array(); |
831
|
|
|
} else { |
832
|
|
|
$additional_query .= " AND (spotter_archive_output.arrival_airport_icao = '".$arrival_airport_route."')"; |
833
|
|
|
} |
834
|
|
|
} |
835
|
|
|
|
836
|
|
|
if ($altitude != "") { |
837
|
|
|
$altitude_array = explode(",", $altitude); |
838
|
|
|
|
839
|
|
|
$altitude_array[0] = filter_var($altitude_array[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
840
|
|
|
$altitude_array[1] = filter_var($altitude_array[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
841
|
|
|
|
842
|
|
|
|
843
|
|
|
if ($altitude_array[1] != "") { |
844
|
|
|
$altitude_array[0] = substr($altitude_array[0], 0, -2); |
845
|
|
|
$altitude_array[1] = substr($altitude_array[1], 0, -2); |
846
|
|
|
$additional_query .= " AND altitude BETWEEN '".$altitude_array[0]."' AND '".$altitude_array[1]."' "; |
847
|
|
|
} else { |
848
|
|
|
$altitude_array[0] = substr($altitude_array[0], 0, -2); |
849
|
|
|
$additional_query .= " AND altitude <= '".$altitude_array[0]."' "; |
850
|
|
|
} |
851
|
|
|
} |
852
|
|
|
|
853
|
|
|
if ($date_posted != "") { |
854
|
|
|
$date_array = explode(",", $date_posted); |
855
|
|
|
$date_array[0] = filter_var($date_array[0],FILTER_SANITIZE_STRING); |
856
|
|
|
$date_array[1] = filter_var($date_array[1],FILTER_SANITIZE_STRING); |
857
|
|
|
if ($globalTimezone != '') { |
858
|
|
|
date_default_timezone_set($globalTimezone); |
859
|
|
|
$datetime = new DateTime(); |
860
|
|
|
$offset = $datetime->format('P'); |
861
|
|
|
} else $offset = '+00:00'; |
862
|
|
|
if ($date_array[1] != "") { |
863
|
|
|
$date_array[0] = date("Y-m-d H:i:s", strtotime($date_array[0])); |
864
|
|
|
$date_array[1] = date("Y-m-d H:i:s", strtotime($date_array[1])); |
865
|
|
|
if ($globalDBdriver == 'mysql') { |
866
|
|
|
$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]."' "; |
867
|
|
|
} else { |
868
|
|
|
$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) "; |
869
|
|
|
} |
870
|
|
|
} else { |
871
|
|
|
$date_array[0] = date("Y-m-d H:i:s", strtotime($date_array[0])); |
872
|
|
|
if ($globalDBdriver == 'mysql') { |
873
|
|
|
$additional_query .= " AND TIMESTAMP(CONVERT_TZ(spotter_archive_output.date,'+00:00', '".$offset."')) >= '".$date_array[0]."' "; |
874
|
|
|
} else { |
875
|
|
|
$additional_query .= " AND spotter_archive_output.date::timestamp AT TIME ZONE INTERVAL ".$offset." >= CAST('".$date_array[0]."' AS TIMESTAMP) "; |
876
|
|
|
} |
877
|
|
|
} |
878
|
|
|
} |
879
|
|
|
if ($limit != "") { |
880
|
|
|
$limit_array = explode(",", $limit); |
881
|
|
|
$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
882
|
|
|
$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
883
|
|
|
if ($limit_array[0] >= 0 && $limit_array[1] >= 0) { |
884
|
|
|
//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
885
|
|
|
$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
886
|
|
|
} |
887
|
|
|
} |
888
|
|
|
if ($origLat != "" && $origLon != "" && $dist != "") { |
889
|
|
|
$dist = number_format($dist*0.621371,2,'.',''); |
890
|
|
|
$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 |
891
|
|
|
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)) |
892
|
|
|
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"; |
893
|
|
|
} else { |
894
|
|
|
if ($sort != "") { |
895
|
|
|
$search_orderby_array = $Spotter->getOrderBy(); |
896
|
|
|
$orderby_query = $search_orderby_array[$sort]['sql']; |
897
|
|
|
} else { |
898
|
|
|
$orderby_query = " ORDER BY spotter_archive_output.date DESC"; |
899
|
|
|
} |
900
|
|
|
if ($includegeodata == "true") { |
901
|
|
|
$additional_query .= " AND (spotter_archive_output.waypoints <> '')"; |
902
|
|
|
} |
903
|
|
|
|
904
|
|
|
$query = "SELECT spotter_archive_output.* FROM spotter_archive_output |
905
|
|
|
WHERE spotter_archive_output.ident <> '' |
906
|
|
|
".$additional_query." |
907
|
|
|
".$filter_query.$orderby_query; |
908
|
|
|
} |
909
|
|
|
$spotter_array = $Spotter->getDataFromDB($query, $query_values,$limit_query); |
910
|
|
|
return $spotter_array; |
911
|
|
|
} |
912
|
|
|
|
913
|
|
|
public function deleteSpotterArchiveData() { |
914
|
|
|
global $globalArchiveKeepMonths, $globalDBdriver; |
915
|
|
|
date_default_timezone_set('UTC'); |
916
|
|
|
if ($globalDBdriver == 'mysql') { |
917
|
|
|
$query = 'DELETE FROM spotter_archive_output WHERE spotter_archive_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$globalArchiveKeepMonths.' MONTH) LIMIT 10000'; |
918
|
|
|
} else { |
919
|
|
|
$query = "DELETE FROM spotter_archive_output WHERE spotter_archive_id IN (SELECT spotter_archive_id FROM spotter_archive_output WHERE spotter_archive_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveKeepMonths." MONTH' LIMIT 10000)"; |
920
|
|
|
} |
921
|
|
|
try { |
922
|
|
|
$sth = $this->db->prepare($query); |
923
|
|
|
$sth->execute(); |
924
|
|
|
return ''; |
925
|
|
|
} catch(PDOException $e) { |
926
|
|
|
return "error"; |
927
|
|
|
} |
928
|
|
|
} |
929
|
|
|
|
930
|
|
|
/** |
931
|
|
|
* Gets all the spotter information based on the callsign |
932
|
|
|
* |
933
|
|
|
* @param string $ident |
934
|
|
|
* @param string $limit |
935
|
|
|
* @param string $sort |
936
|
|
|
* @return array the spotter information |
937
|
|
|
*/ |
938
|
|
|
public function getSpotterDataByIdent($ident = '', $limit = '', $sort = '') { |
939
|
|
|
$global_query = "SELECT spotter_archive_output.* FROM spotter_archive_output"; |
940
|
|
|
|
941
|
|
|
date_default_timezone_set('UTC'); |
942
|
|
|
$Spotter = new Spotter($this->db); |
943
|
|
|
|
944
|
|
|
$query_values = array(); |
945
|
|
|
$limit_query = ''; |
946
|
|
|
$additional_query = ''; |
947
|
|
|
|
948
|
|
|
if ($ident != "") { |
949
|
|
|
if (!is_string($ident)) { |
950
|
|
|
return array(); |
951
|
|
|
} else { |
952
|
|
|
$additional_query = " AND spotter_archive_output.ident = :ident"; |
953
|
|
|
$query_values = array(':ident' => $ident); |
954
|
|
|
} |
955
|
|
|
} |
956
|
|
|
|
957
|
|
|
if ($limit != "") { |
958
|
|
|
$limit_array = explode(",", $limit); |
959
|
|
|
|
960
|
|
|
$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
961
|
|
|
$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
962
|
|
|
|
963
|
|
|
if ($limit_array[0] >= 0 && $limit_array[1] >= 0) { |
964
|
|
|
//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
965
|
|
|
$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
966
|
|
|
} |
967
|
|
|
} |
968
|
|
|
|
969
|
|
|
if ($sort != "") { |
970
|
|
|
$search_orderby_array = $Spotter->getOrderBy(); |
971
|
|
|
$orderby_query = $search_orderby_array[$sort]['sql']; |
972
|
|
|
} else { |
973
|
|
|
$orderby_query = " ORDER BY spotter_archive_output.date DESC"; |
974
|
|
|
} |
975
|
|
|
|
976
|
|
|
$query = $global_query." WHERE spotter_archive_output.ident <> '' ".$additional_query." ".$orderby_query; |
977
|
|
|
|
978
|
|
|
$spotter_array = $Spotter->getDataFromDB($query, $query_values, $limit_query); |
979
|
|
|
|
980
|
|
|
return $spotter_array; |
981
|
|
|
} |
982
|
|
|
|
983
|
|
|
|
984
|
|
|
/** |
985
|
|
|
* Gets all the spotter information based on the owner |
986
|
|
|
* |
987
|
|
|
* @param string $owner |
988
|
|
|
* @param string $limit |
989
|
|
|
* @param string $sort |
990
|
|
|
* @param array $filter |
991
|
|
|
* @return array the spotter information |
992
|
|
|
*/ |
993
|
|
|
public function getSpotterDataByOwner($owner = '', $limit = '', $sort = '', $filter = array()) { |
994
|
|
|
$global_query = "SELECT spotter_archive_output.* FROM spotter_archive_output"; |
995
|
|
|
|
996
|
|
|
date_default_timezone_set('UTC'); |
997
|
|
|
$Spotter = new Spotter($this->db); |
998
|
|
|
|
999
|
|
|
$query_values = array(); |
1000
|
|
|
$limit_query = ''; |
1001
|
|
|
$additional_query = ''; |
1002
|
|
|
$filter_query = $this->getFilter($filter,true,true); |
1003
|
|
|
|
1004
|
|
|
if ($owner != "") { |
1005
|
|
|
if (!is_string($owner)) { |
1006
|
|
|
return array(); |
1007
|
|
|
} else { |
1008
|
|
|
$additional_query = " AND (spotter_archive_output.owner_name = :owner)"; |
1009
|
|
|
$query_values = array(':owner' => $owner); |
1010
|
|
|
} |
1011
|
|
|
} |
1012
|
|
|
|
1013
|
|
|
if ($limit != "") { |
1014
|
|
|
$limit_array = explode(",", $limit); |
1015
|
|
|
|
1016
|
|
|
$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
1017
|
|
|
$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
1018
|
|
|
|
1019
|
|
|
if ($limit_array[0] >= 0 && $limit_array[1] >= 0 && $limit_array[0] != '' && $limit_array[1] != '') { |
1020
|
|
|
//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
1021
|
|
|
$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
1022
|
|
|
} |
1023
|
|
|
} |
1024
|
|
|
|
1025
|
|
|
if ($sort != "") { |
1026
|
|
|
$search_orderby_array = $Spotter->getOrderBy(); |
1027
|
|
|
$orderby_query = $search_orderby_array[$sort]['sql']; |
1028
|
|
|
} else { |
1029
|
|
|
$orderby_query = " ORDER BY spotter_archive_output.date DESC"; |
1030
|
|
|
} |
1031
|
|
|
|
1032
|
|
|
$query = $global_query.$filter_query." spotter_archive_output.owner_name <> '' ".$additional_query." ".$orderby_query; |
1033
|
|
|
|
1034
|
|
|
$spotter_array = $Spotter->getDataFromDB($query, $query_values, $limit_query); |
1035
|
|
|
|
1036
|
|
|
return $spotter_array; |
1037
|
|
|
} |
1038
|
|
|
|
1039
|
|
|
/** |
1040
|
|
|
* Gets all the spotter information based on the pilot |
1041
|
|
|
* |
1042
|
|
|
* @param string $pilot |
1043
|
|
|
* @param string $limit |
1044
|
|
|
* @param string $sort |
1045
|
|
|
* @param array $filter |
1046
|
|
|
* @return array the spotter information |
1047
|
|
|
*/ |
1048
|
|
|
public function getSpotterDataByPilot($pilot = '', $limit = '', $sort = '', $filter = array()) { |
1049
|
|
|
$global_query = "SELECT spotter_archive_output.* FROM spotter_archive_output"; |
1050
|
|
|
|
1051
|
|
|
date_default_timezone_set('UTC'); |
1052
|
|
|
$Spotter = new Spotter($this->db); |
1053
|
|
|
|
1054
|
|
|
$query_values = array(); |
1055
|
|
|
$limit_query = ''; |
1056
|
|
|
$additional_query = ''; |
1057
|
|
|
$filter_query = $this->getFilter($filter,true,true); |
1058
|
|
|
|
1059
|
|
|
if ($pilot != "") { |
1060
|
|
|
$additional_query = " AND (spotter_archive_output.pilot_id = :pilot OR spotter_archive_output.pilot_name = :pilot)"; |
1061
|
|
|
$query_values = array(':pilot' => $pilot); |
1062
|
|
|
} |
1063
|
|
|
|
1064
|
|
|
if ($limit != "") { |
1065
|
|
|
$limit_array = explode(",", $limit); |
1066
|
|
|
|
1067
|
|
|
$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
1068
|
|
|
$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
1069
|
|
|
|
1070
|
|
|
if ($limit_array[0] >= 0 && $limit_array[1] >= 0) { |
1071
|
|
|
//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
1072
|
|
|
$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
1073
|
|
|
} |
1074
|
|
|
} |
1075
|
|
|
|
1076
|
|
|
if ($sort != "") { |
1077
|
|
|
$search_orderby_array = $Spotter->getOrderBy(); |
1078
|
|
|
$orderby_query = $search_orderby_array[$sort]['sql']; |
1079
|
|
|
} else { |
1080
|
|
|
$orderby_query = " ORDER BY spotter_archive_output.date DESC"; |
1081
|
|
|
} |
1082
|
|
|
|
1083
|
|
|
$query = $global_query.$filter_query." spotter_archive_output.pilot_name <> '' ".$additional_query." ".$orderby_query; |
1084
|
|
|
|
1085
|
|
|
$spotter_array = $Spotter->getDataFromDB($query, $query_values, $limit_query); |
1086
|
|
|
|
1087
|
|
|
return $spotter_array; |
1088
|
|
|
} |
1089
|
|
|
|
1090
|
|
|
/** |
1091
|
|
|
* Gets all number of flight over countries |
1092
|
|
|
* |
1093
|
|
|
* @param bool $limit |
1094
|
|
|
* @param int $olderthanmonths |
1095
|
|
|
* @param string $sincedate |
1096
|
|
|
* @return array the airline country list |
1097
|
|
|
*/ |
1098
|
|
|
public function countAllFlightOverCountries($limit = true,$olderthanmonths = 0,$sincedate = '') { |
1099
|
|
|
global $globalDBdriver; |
1100
|
|
|
/* |
1101
|
|
|
$query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb |
1102
|
|
|
FROM countries c, spotter_archive s |
1103
|
|
|
WHERE Within(GeomFromText(CONCAT('POINT(',s.longitude,' ',s.latitude,')')), ogc_geom) "; |
1104
|
|
|
*/ |
1105
|
|
|
$query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb |
1106
|
|
|
FROM countries c, spotter_archive s |
1107
|
|
|
WHERE c.iso2 = s.over_country "; |
1108
|
|
|
if ($olderthanmonths > 0) { |
1109
|
|
|
if ($globalDBdriver == 'mysql') { |
1110
|
|
|
$query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) '; |
1111
|
|
|
} else { |
1112
|
|
|
$query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
1113
|
|
|
} |
1114
|
|
|
} |
1115
|
|
|
if ($sincedate != '') $query .= "AND date > '".$sincedate."' "; |
1116
|
|
|
$query .= "GROUP BY c.name, c.iso3, c.iso2 ORDER BY nb DESC"; |
1117
|
|
|
if ($limit) $query .= " LIMIT 0,10"; |
1118
|
|
|
|
1119
|
|
|
|
1120
|
|
|
$sth = $this->db->prepare($query); |
1121
|
|
|
$sth->execute(); |
1122
|
|
|
|
1123
|
|
|
$flight_array = array(); |
1124
|
|
|
$temp_array = array(); |
1125
|
|
|
|
1126
|
|
|
while($row = $sth->fetch(PDO::FETCH_ASSOC)) { |
1127
|
|
|
$temp_array['flight_count'] = $row['nb']; |
1128
|
|
|
$temp_array['flight_country'] = $row['name']; |
1129
|
|
|
$temp_array['flight_country_iso3'] = $row['iso3']; |
1130
|
|
|
$temp_array['flight_country_iso2'] = $row['iso2']; |
1131
|
|
|
$flight_array[] = $temp_array; |
1132
|
|
|
} |
1133
|
|
|
return $flight_array; |
1134
|
|
|
} |
1135
|
|
|
|
1136
|
|
|
/** |
1137
|
|
|
* Gets all number of flight over countries |
1138
|
|
|
* |
1139
|
|
|
* @param bool $limit |
1140
|
|
|
* @param int $olderthanmonths |
1141
|
|
|
* @param string $sincedate |
1142
|
|
|
* @return array the airline country list |
1143
|
|
|
*/ |
1144
|
|
|
public function countAllFlightOverCountriesByAirlines($limit = true,$olderthanmonths = 0,$sincedate = '') { |
1145
|
|
|
global $globalDBdriver; |
1146
|
|
|
/* |
1147
|
|
|
$query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb |
1148
|
|
|
FROM countries c, spotter_archive s |
1149
|
|
|
WHERE Within(GeomFromText(CONCAT('POINT(',s.longitude,' ',s.latitude,')')), ogc_geom) "; |
1150
|
|
|
*/ |
1151
|
|
|
$query = "SELECT o.airline_icao,c.name, c.iso3, c.iso2, count(c.name) as nb |
1152
|
|
|
FROM countries c, spotter_archive s, spotter_output o |
1153
|
|
|
WHERE c.iso2 = s.over_country AND o.airline_icao <> '' AND o.flightaware_id = s.flightaware_id "; |
1154
|
|
|
if ($olderthanmonths > 0) { |
1155
|
|
|
if ($globalDBdriver == 'mysql') { |
1156
|
|
|
$query .= 'AND s.date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) '; |
1157
|
|
|
} else { |
1158
|
|
|
$query .= "AND s.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
1159
|
|
|
} |
1160
|
|
|
} |
1161
|
|
|
if ($sincedate != '') $query .= "AND s.date > '".$sincedate."' "; |
1162
|
|
|
$query .= "GROUP BY o.airline_icao,c.name, c.iso3, c.iso2 ORDER BY nb DESC"; |
1163
|
|
|
if ($limit) $query .= " LIMIT 0,10"; |
1164
|
|
|
|
1165
|
|
|
|
1166
|
|
|
$sth = $this->db->prepare($query); |
1167
|
|
|
$sth->execute(); |
1168
|
|
|
|
1169
|
|
|
$flight_array = array(); |
1170
|
|
|
$temp_array = array(); |
1171
|
|
|
|
1172
|
|
|
while($row = $sth->fetch(PDO::FETCH_ASSOC)) { |
1173
|
|
|
$temp_array['airline_icao'] = $row['airline_icao']; |
1174
|
|
|
$temp_array['flight_count'] = $row['nb']; |
1175
|
|
|
$temp_array['flight_country'] = $row['name']; |
1176
|
|
|
$temp_array['flight_country_iso3'] = $row['iso3']; |
1177
|
|
|
$temp_array['flight_country_iso2'] = $row['iso2']; |
1178
|
|
|
$flight_array[] = $temp_array; |
1179
|
|
|
} |
1180
|
|
|
return $flight_array; |
1181
|
|
|
} |
1182
|
|
|
|
1183
|
|
|
/** |
1184
|
|
|
* Gets all aircraft types that have flown over by owner |
1185
|
|
|
* |
1186
|
|
|
* @param $owner |
1187
|
|
|
* @param array $filters |
1188
|
|
|
* @return array the aircraft list |
1189
|
|
|
*/ |
1190
|
|
|
public function countAllAircraftTypesByOwner($owner,$filters = array()) |
1191
|
|
|
{ |
1192
|
|
|
$filter_query = $this->getFilter($filters,true,true); |
1193
|
|
|
$owner = filter_var($owner,FILTER_SANITIZE_STRING); |
1194
|
|
|
$query = "SELECT DISTINCT spotter_archive_output.aircraft_icao, COUNT(spotter_archive_output.aircraft_icao) AS aircraft_icao_count, spotter_archive_output.aircraft_name, spotter_archive_output.aircraft_manufacturer |
1195
|
|
|
FROM spotter_archive_output".$filter_query." spotter_archive_output.owner_name = :owner"; |
1196
|
|
|
$query_values = array(); |
1197
|
|
|
$query .= " GROUP BY spotter_archive_output.aircraft_name, spotter_archive_output.aircraft_manufacturer, spotter_archive_output.aircraft_icao |
1198
|
|
|
ORDER BY aircraft_icao_count DESC"; |
1199
|
|
|
$query_values = array_merge($query_values,array(':owner' => $owner)); |
1200
|
|
|
$sth = $this->db->prepare($query); |
1201
|
|
|
$sth->execute($query_values); |
1202
|
|
|
return $sth->fetchAll(PDO::FETCH_ASSOC); |
1203
|
|
|
} |
1204
|
|
|
|
1205
|
|
|
/** |
1206
|
|
|
* Gets all airlines by owner |
1207
|
|
|
* |
1208
|
|
|
* @param $owner |
1209
|
|
|
* @param array $filters |
1210
|
|
|
* @return array the airline list |
1211
|
|
|
*/ |
1212
|
|
|
public function countAllAirlinesByOwner($owner,$filters = array()) |
1213
|
|
|
{ |
1214
|
|
|
$owner = filter_var($owner,FILTER_SANITIZE_STRING); |
1215
|
|
|
$filter_query = $this->getFilter($filters,true,true); |
1216
|
|
|
$query = "SELECT DISTINCT spotter_archive_output.airline_name, spotter_archive_output.airline_icao, spotter_archive_output.airline_country, COUNT(spotter_archive_output.airline_name) AS airline_count |
1217
|
|
|
FROM spotter_archive_output".$filter_query." spotter_archive_output.owner_name = :owner |
1218
|
|
|
GROUP BY spotter_archive_output.airline_icao, spotter_archive_output.airline_name, spotter_archive_output.airline_country |
1219
|
|
|
ORDER BY airline_count DESC"; |
1220
|
|
|
|
1221
|
|
|
$sth = $this->db->prepare($query); |
1222
|
|
|
$sth->execute(array(':owner' => $owner)); |
1223
|
|
|
return $sth->fetchAll(PDO::FETCH_ASSOC); |
1224
|
|
|
} |
1225
|
|
|
|
1226
|
|
|
/** |
1227
|
|
|
* Gets all arrival airports by country of the airplanes that have flown over based on a owner |
1228
|
|
|
* |
1229
|
|
|
* @param $owner |
1230
|
|
|
* @param array $filters |
1231
|
|
|
* @return array the airport list |
1232
|
|
|
*/ |
1233
|
|
|
public function countAllArrivalAirportCountriesByOwner($owner, $filters = array()) |
1234
|
|
|
{ |
1235
|
|
|
$filter_query = $this->getFilter($filters,true,true); |
1236
|
|
|
$owner = filter_var($owner,FILTER_SANITIZE_STRING); |
1237
|
|
|
$query = "SELECT DISTINCT spotter_archive_output.arrival_airport_country, COUNT(spotter_archive_output.arrival_airport_country) AS airport_arrival_country_count, countries.iso3 AS airport_arrival_country_iso3 |
1238
|
|
|
FROM countries, spotter_archive_output".$filter_query." spotter_archive_output.arrival_airport_country <> '' AND spotter_archive_output.owner_name = :owner AND countries.name = spotter_archive_output.arrival_airport_country |
1239
|
|
|
GROUP BY spotter_archive_output.arrival_airport_country, countries.iso3 |
1240
|
|
|
ORDER BY airport_arrival_country_count DESC"; |
1241
|
|
|
$sth = $this->db->prepare($query); |
1242
|
|
|
$sth->execute(array(':owner' => $owner)); |
1243
|
|
|
return $sth->fetchAll(PDO::FETCH_ASSOC); |
1244
|
|
|
} |
1245
|
|
|
|
1246
|
|
|
/** |
1247
|
|
|
* Gets all arrival airports of the airplanes that have flown over based on a owner |
1248
|
|
|
* |
1249
|
|
|
* @param $owner |
1250
|
|
|
* @param array $filters |
1251
|
|
|
* @return array the airport list |
1252
|
|
|
*/ |
1253
|
|
|
public function countAllArrivalAirportsByOwner($owner,$filters = array()) |
1254
|
|
|
{ |
1255
|
|
|
$filter_query = $this->getFilter($filters,true,true); |
1256
|
|
|
$owner = filter_var($owner,FILTER_SANITIZE_STRING); |
1257
|
|
|
$query = "SELECT DISTINCT spotter_archive_output.arrival_airport_icao, COUNT(spotter_archive_output.arrival_airport_icao) AS airport_arrival_icao_count, spotter_archive_output.arrival_airport_name, spotter_archive_output.arrival_airport_city, spotter_archive_output.arrival_airport_country |
1258
|
|
|
FROM spotter_archive_output".$filter_query." spotter_archive_output.arrival_airport_name <> '' AND spotter_archive_output.arrival_airport_icao <> 'NA' AND spotter_archive_output.arrival_airport_icao <> '' AND spotter_archive_output.owner_name = :owner |
1259
|
|
|
GROUP BY spotter_archive_output.arrival_airport_icao, spotter_archive_output.arrival_airport_name, spotter_archive_output.arrival_airport_city, spotter_archive_output.arrival_airport_country |
1260
|
|
|
ORDER BY airport_arrival_icao_count DESC"; |
1261
|
|
|
$sth = $this->db->prepare($query); |
1262
|
|
|
$sth->execute(array(':owner' => $owner)); |
1263
|
|
|
$airport_array = array(); |
1264
|
|
|
$temp_array = array(); |
1265
|
|
|
while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
1266
|
|
|
{ |
1267
|
|
|
$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
1268
|
|
|
$temp_array['airport_arrival_icao_count'] = $row['airport_arrival_icao_count']; |
1269
|
|
|
$temp_array['airport_arrival_name'] = $row['arrival_airport_name']; |
1270
|
|
|
$temp_array['airport_arrival_city'] = $row['arrival_airport_city']; |
1271
|
|
|
$temp_array['airport_arrival_country'] = $row['arrival_airport_country']; |
1272
|
|
|
$airport_array[] = $temp_array; |
1273
|
|
|
} |
1274
|
|
|
return $airport_array; |
1275
|
|
|
} |
1276
|
|
|
|
1277
|
|
|
/** |
1278
|
|
|
* Gets all departure airports by country of the airplanes that have flown over based on owner |
1279
|
|
|
* |
1280
|
|
|
* @param $owner |
1281
|
|
|
* @param array $filters |
1282
|
|
|
* @return array the airport list |
1283
|
|
|
*/ |
1284
|
|
|
public function countAllDepartureAirportCountriesByOwner($owner,$filters = array()) |
1285
|
|
|
{ |
1286
|
|
|
$filter_query = $this->getFilter($filters,true,true); |
1287
|
|
|
$owner = filter_var($owner,FILTER_SANITIZE_STRING); |
1288
|
|
|
$query = "SELECT DISTINCT spotter_archive_output.departure_airport_country, COUNT(spotter_archive_output.departure_airport_country) AS airport_departure_country_count, countries.iso3 AS airport_departure_country_iso3 |
1289
|
|
|
FROM spotter_archive_output,countries".$filter_query." spotter_archive_output.departure_airport_country <> '' AND spotter_archive_output.owner_name = :owner AND countries.name = spotter_archive_output.departure_airport_country |
1290
|
|
|
GROUP BY spotter_archive_output.departure_airport_country, countries.iso3 |
1291
|
|
|
ORDER BY airport_departure_country_count DESC"; |
1292
|
|
|
$sth = $this->db->prepare($query); |
1293
|
|
|
$sth->execute(array(':owner' => $owner)); |
1294
|
|
|
return $sth->fetchAll(PDO::FETCH_ASSOC); |
1295
|
|
|
} |
1296
|
|
|
|
1297
|
|
|
/** |
1298
|
|
|
* Gets all departure airports of the airplanes that have flown over based on a owner |
1299
|
|
|
* |
1300
|
|
|
* @param $owner |
1301
|
|
|
* @param array $filters |
1302
|
|
|
* @return array the airport list |
1303
|
|
|
*/ |
1304
|
|
|
public function countAllDepartureAirportsByOwner($owner,$filters = array()) |
1305
|
|
|
{ |
1306
|
|
|
$filter_query = $this->getFilter($filters,true,true); |
1307
|
|
|
$owner = filter_var($owner,FILTER_SANITIZE_STRING); |
1308
|
|
|
$query = "SELECT DISTINCT spotter_archive_output.departure_airport_icao, COUNT(spotter_archive_output.departure_airport_icao) AS airport_departure_icao_count, spotter_archive_output.departure_airport_name, spotter_archive_output.departure_airport_city, spotter_archive_output.departure_airport_country, airport.latitude, airport.longitude |
1309
|
|
|
FROM spotter_archive_output,airport".$filter_query." spotter_archive_output.departure_airport_name <> '' AND spotter_archive_output.departure_airport_icao <> 'NA' AND spotter_archive_output.departure_airport_icao <> '' AND spotter_archive_output.owner_name = :owner AND airport.icao = spotter_archive_output.departure_airport_icao |
1310
|
|
|
GROUP BY spotter_archive_output.departure_airport_icao, spotter_archive_output.departure_airport_name, spotter_archive_output.departure_airport_city, spotter_archive_output.departure_airport_country, airport.latitude, airport.longitude |
1311
|
|
|
ORDER BY airport_departure_icao_count DESC"; |
1312
|
|
|
$sth = $this->db->prepare($query); |
1313
|
|
|
$sth->execute(array(':owner' => $owner)); |
1314
|
|
|
$airport_array = array(); |
1315
|
|
|
$temp_array = array(); |
1316
|
|
|
while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
1317
|
|
|
{ |
1318
|
|
|
$temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
1319
|
|
|
$temp_array['airport_departure_icao_count'] = $row['airport_departure_icao_count']; |
1320
|
|
|
$temp_array['airport_departure_name'] = $row['departure_airport_name']; |
1321
|
|
|
$temp_array['airport_departure_city'] = $row['departure_airport_city']; |
1322
|
|
|
$temp_array['airport_departure_country'] = $row['departure_airport_country']; |
1323
|
|
|
$temp_array['airport_departure_latitude'] = $row['latitude']; |
1324
|
|
|
$temp_array['airport_departure_longitude'] = $row['longitude']; |
1325
|
|
|
$airport_array[] = $temp_array; |
1326
|
|
|
} |
1327
|
|
|
return $airport_array; |
1328
|
|
|
} |
1329
|
|
|
|
1330
|
|
|
/** |
1331
|
|
|
* Gets all aircraft manufacturer that have flown over by owner |
1332
|
|
|
* |
1333
|
|
|
* @param $owner |
1334
|
|
|
* @param array $filters |
1335
|
|
|
* @return array the aircraft manufacturer list |
1336
|
|
|
*/ |
1337
|
|
|
public function countAllAircraftManufacturerByOwner($owner,$filters = array()) |
1338
|
|
|
{ |
1339
|
|
|
$filter_query = $this->getFilter($filters,true,true); |
1340
|
|
|
$owner = filter_var($owner,FILTER_SANITIZE_STRING); |
1341
|
|
|
$query = "SELECT DISTINCT spotter_archive_output.aircraft_manufacturer, COUNT(spotter_archive_output.aircraft_manufacturer) AS aircraft_manufacturer_count |
1342
|
|
|
FROM spotter_archive_output".$filter_query." spotter_archive_output.aircraft_manufacturer <> '' AND spotter_archive_output.owner_name = :owner"; |
1343
|
|
|
$query_values = array(); |
1344
|
|
|
$query_values = array_merge($query_values,array(':owner' => $owner)); |
1345
|
|
|
$query .= " GROUP BY spotter_archive_output.aircraft_manufacturer |
1346
|
|
|
ORDER BY aircraft_manufacturer_count DESC"; |
1347
|
|
|
$sth = $this->db->prepare($query); |
1348
|
|
|
$sth->execute($query_values); |
1349
|
|
|
return $sth->fetchAll(PDO::FETCH_ASSOC); |
1350
|
|
|
} |
1351
|
|
|
|
1352
|
|
|
/** |
1353
|
|
|
* Gets all aircraft registration that have flown over by owner |
1354
|
|
|
* |
1355
|
|
|
* @param $owner |
1356
|
|
|
* @param array $filters |
1357
|
|
|
* @return array the aircraft list |
1358
|
|
|
*/ |
1359
|
|
|
public function countAllAircraftRegistrationByOwner($owner,$filters = array()) |
1360
|
|
|
{ |
1361
|
|
|
$filter_query = $this->getFilter($filters,true,true); |
1362
|
|
|
$Image = new Image($this->db); |
1363
|
|
|
$owner = filter_var($owner,FILTER_SANITIZE_STRING); |
1364
|
|
|
$query = "SELECT DISTINCT spotter_archive_output.aircraft_icao, COUNT(spotter_archive_output.registration) AS registration_count, spotter_archive_output.aircraft_name, spotter_archive_output.aircraft_manufacturer, spotter_archive_output.registration, spotter_archive_output.airline_name |
1365
|
|
|
FROM spotter_archive_output".$filter_query." spotter_archive_output.registration <> '' AND spotter_archive_output.owner_name = :owner"; |
1366
|
|
|
$query_values = array(); |
1367
|
|
|
$query_values = array_merge($query_values,array(':owner' => $owner)); |
1368
|
|
|
$query .= " GROUP BY spotter_archive_output.registration,spotter_archive_output.aircraft_icao, spotter_archive_output.aircraft_name, spotter_archive_output.aircraft_manufacturer, spotter_archive_output.airline_name |
1369
|
|
|
ORDER BY registration_count DESC"; |
1370
|
|
|
$sth = $this->db->prepare($query); |
1371
|
|
|
$sth->execute($query_values); |
1372
|
|
|
$aircraft_array = array(); |
1373
|
|
|
$temp_array = array(); |
1374
|
|
|
while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
1375
|
|
|
{ |
1376
|
|
|
$temp_array['aircraft_icao'] = $row['aircraft_icao']; |
1377
|
|
|
$temp_array['aircraft_name'] = $row['aircraft_name']; |
1378
|
|
|
$temp_array['aircraft_manufacturer'] = $row['aircraft_manufacturer']; |
1379
|
|
|
$temp_array['registration'] = $row['registration']; |
1380
|
|
|
$temp_array['airline_name'] = $row['airline_name']; |
1381
|
|
|
$temp_array['image_thumbnail'] = ""; |
1382
|
|
|
if($row['registration'] != "") |
1383
|
|
|
{ |
1384
|
|
|
$image_array = $Image->getSpotterImage($row['registration']); |
1385
|
|
|
if (isset($image_array[0]['image_thumbnail'])) $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; |
1386
|
|
|
else $temp_array['image_thumbnail'] = ''; |
1387
|
|
|
} |
1388
|
|
|
$temp_array['registration_count'] = $row['registration_count']; |
1389
|
|
|
$aircraft_array[] = $temp_array; |
1390
|
|
|
} |
1391
|
|
|
return $aircraft_array; |
1392
|
|
|
} |
1393
|
|
|
|
1394
|
|
|
/** |
1395
|
|
|
* Gets all route combinations based on an owner |
1396
|
|
|
* |
1397
|
|
|
* @param $owner |
1398
|
|
|
* @param array $filters |
1399
|
|
|
* @return array the route list |
1400
|
|
|
*/ |
1401
|
|
|
public function countAllRoutesByOwner($owner,$filters = array()) |
1402
|
|
|
{ |
1403
|
|
|
$filter_query = $this->getFilter($filters,true,true); |
1404
|
|
|
$owner = filter_var($owner,FILTER_SANITIZE_STRING); |
1405
|
|
|
$query = "SELECT DISTINCT concat(spotter_archive_output.departure_airport_icao, ' - ', spotter_archive_output.arrival_airport_icao) AS route, count(concat(spotter_archive_output.departure_airport_icao, ' - ', spotter_archive_output.arrival_airport_icao)) AS route_count, spotter_archive_output.departure_airport_icao, spotter_archive_output.departure_airport_name AS airport_departure_name, spotter_archive_output.departure_airport_city AS airport_departure_city, spotter_archive_output.departure_airport_country AS airport_departure_country, spotter_archive_output.arrival_airport_icao, spotter_archive_output.arrival_airport_name AS airport_arrival_name, spotter_archive_output.arrival_airport_city AS airport_arrival_city, spotter_archive_output.arrival_airport_country AS airport_arrival_country |
1406
|
|
|
FROM spotter_archive_output".$filter_query." spotter_archive_output.ident <> '' AND spotter_archive_output.owner_name = :owner |
1407
|
|
|
GROUP BY route, spotter_archive_output.departure_airport_icao, spotter_archive_output.departure_airport_name, spotter_archive_output.departure_airport_city, spotter_archive_output.departure_airport_country, spotter_archive_output.arrival_airport_icao, spotter_archive_output.arrival_airport_name, spotter_archive_output.arrival_airport_city, spotter_archive_output.arrival_airport_country |
1408
|
|
|
ORDER BY route_count DESC"; |
1409
|
|
|
$sth = $this->db->prepare($query); |
1410
|
|
|
$sth->execute(array(':owner' => $owner)); |
1411
|
|
|
$routes_array = array(); |
1412
|
|
|
$temp_array = array(); |
1413
|
|
|
while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
1414
|
|
|
{ |
1415
|
|
|
$temp_array['route_count'] = $row['route_count']; |
1416
|
|
|
$temp_array['airport_departure_icao'] = $row['departure_airport_icao']; |
1417
|
|
|
$temp_array['airport_departure_name'] = $row['airport_departure_name']; |
1418
|
|
|
$temp_array['airport_departure_city'] = $row['airport_departure_city']; |
1419
|
|
|
$temp_array['airport_departure_country'] = $row['airport_departure_country']; |
1420
|
|
|
$temp_array['airport_arrival_icao'] = $row['arrival_airport_icao']; |
1421
|
|
|
$temp_array['airport_arrival_name'] = $row['airport_arrival_name']; |
1422
|
|
|
$temp_array['airport_arrival_city'] = $row['airport_arrival_city']; |
1423
|
|
|
$temp_array['airport_arrival_country'] = $row['airport_arrival_country']; |
1424
|
|
|
$routes_array[] = $temp_array; |
1425
|
|
|
} |
1426
|
|
|
return $routes_array; |
1427
|
|
|
} |
1428
|
|
|
|
1429
|
|
|
/** |
1430
|
|
|
* Counts all hours by a owner |
1431
|
|
|
* |
1432
|
|
|
* @param $owner |
1433
|
|
|
* @param array $filters |
1434
|
|
|
* @return array the hour list |
1435
|
|
|
*/ |
1436
|
|
|
public function countAllHoursByOwner($owner, $filters = array()) |
1437
|
|
|
{ |
1438
|
|
|
global $globalTimezone, $globalDBdriver; |
1439
|
|
|
$filter_query = $this->getFilter($filters,true,true); |
1440
|
|
|
$owner = filter_var($owner,FILTER_SANITIZE_STRING); |
1441
|
|
|
if ($globalTimezone != '') { |
1442
|
|
|
date_default_timezone_set($globalTimezone); |
1443
|
|
|
$datetime = new DateTime(); |
1444
|
|
|
$offset = $datetime->format('P'); |
1445
|
|
|
} else $offset = '+00:00'; |
1446
|
|
|
if ($globalDBdriver == 'mysql') { |
1447
|
|
|
$query = "SELECT HOUR(CONVERT_TZ(spotter_archive_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
1448
|
|
|
FROM spotter_archive_output".$filter_query." spotter_archive_output.owner_name = :owner |
1449
|
|
|
GROUP BY hour_name |
1450
|
|
|
ORDER BY hour_name ASC"; |
1451
|
|
|
} else { |
1452
|
|
|
$query = "SELECT EXTRACT(HOUR FROM spotter_archive_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count |
1453
|
|
|
FROM spotter_archive_output".$filter_query." spotter_archive_output.owner_name = :owner |
1454
|
|
|
GROUP BY hour_name |
1455
|
|
|
ORDER BY hour_name ASC"; |
1456
|
|
|
} |
1457
|
|
|
$sth = $this->db->prepare($query); |
1458
|
|
|
$sth->execute(array(':owner' => $owner,':offset' => $offset)); |
1459
|
|
|
$hour_array = array(); |
1460
|
|
|
$temp_array = array(); |
1461
|
|
|
while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
1462
|
|
|
{ |
1463
|
|
|
$temp_array['hour_name'] = $row['hour_name']; |
1464
|
|
|
$temp_array['hour_count'] = $row['hour_count']; |
1465
|
|
|
$hour_array[] = $temp_array; |
1466
|
|
|
} |
1467
|
|
|
return $hour_array; |
1468
|
|
|
} |
1469
|
|
|
|
1470
|
|
|
/** |
1471
|
|
|
* Gets last spotter information based on a particular callsign |
1472
|
|
|
* |
1473
|
|
|
* @param $id |
1474
|
|
|
* @param $date |
1475
|
|
|
* @return array the spotter information |
1476
|
|
|
*/ |
1477
|
|
|
public function getDateArchiveSpotterDataById($id,$date) { |
1478
|
|
|
$Spotter = new Spotter($this->db); |
1479
|
|
|
date_default_timezone_set('UTC'); |
1480
|
|
|
$id = filter_var($id, FILTER_SANITIZE_STRING); |
1481
|
|
|
$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'; |
1482
|
|
|
$date = date('c',$date); |
1483
|
|
|
$spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id,':date' => $date)); |
1484
|
|
|
return $spotter_array; |
1485
|
|
|
} |
1486
|
|
|
|
1487
|
|
|
/** |
1488
|
|
|
* Gets all the spotter information based on a particular callsign |
1489
|
|
|
* |
1490
|
|
|
* @param $ident |
1491
|
|
|
* @param $date |
1492
|
|
|
* @return array the spotter information |
1493
|
|
|
*/ |
1494
|
|
|
public function getDateArchiveSpotterDataByIdent($ident,$date) { |
1495
|
|
|
$Spotter = new Spotter($this->db); |
1496
|
|
|
date_default_timezone_set('UTC'); |
1497
|
|
|
$ident = filter_var($ident, FILTER_SANITIZE_STRING); |
1498
|
|
|
$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'; |
1499
|
|
|
$date = date('c',$date); |
1500
|
|
|
$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident,':date' => $date)); |
1501
|
|
|
return $spotter_array; |
1502
|
|
|
} |
1503
|
|
|
|
1504
|
|
|
/** |
1505
|
|
|
* Gets all the spotter information based on the airport |
1506
|
|
|
* |
1507
|
|
|
* @param string $airport |
1508
|
|
|
* @param string $limit |
1509
|
|
|
* @param string $sort |
1510
|
|
|
* @param array $filters |
1511
|
|
|
* @return array the spotter information |
1512
|
|
|
*/ |
1513
|
|
|
public function getSpotterDataByAirport($airport = '', $limit = '', $sort = '',$filters = array()) { |
1514
|
|
|
global $global_query; |
1515
|
|
|
$Spotter = new Spotter($this->db); |
1516
|
|
|
date_default_timezone_set('UTC'); |
1517
|
|
|
$query_values = array(); |
1518
|
|
|
$limit_query = ''; |
1519
|
|
|
$additional_query = ''; |
1520
|
|
|
$filter_query = $this->getFilter($filters,true,true); |
1521
|
|
|
|
1522
|
|
|
if ($airport != "") { |
1523
|
|
|
if (!is_string($airport)) { |
1524
|
|
|
return array(); |
1525
|
|
|
} else { |
1526
|
|
|
$additional_query .= " AND ((spotter_archive_output.departure_airport_icao = :airport) OR (spotter_archive_output.arrival_airport_icao = :airport))"; |
1527
|
|
|
$query_values = array(':airport' => $airport); |
1528
|
|
|
} |
1529
|
|
|
} |
1530
|
|
|
|
1531
|
|
|
if ($limit != "") { |
1532
|
|
|
$limit_array = explode(",", $limit); |
1533
|
|
|
|
1534
|
|
|
$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
1535
|
|
|
$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
1536
|
|
|
|
1537
|
|
|
if ($limit_array[0] >= 0 && $limit_array[1] >= 0) { |
1538
|
|
|
//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
1539
|
|
|
$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
1540
|
|
|
} |
1541
|
|
|
} |
1542
|
|
|
|
1543
|
|
|
if ($sort != "") { |
1544
|
|
|
$search_orderby_array = $Spotter->getOrderBy(); |
1545
|
|
|
$orderby_query = $search_orderby_array[$sort]['sql']; |
1546
|
|
|
} else { |
1547
|
|
|
$orderby_query = " ORDER BY spotter_archive_output.date DESC"; |
1548
|
|
|
} |
1549
|
|
|
|
1550
|
|
|
$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; |
1551
|
|
|
|
1552
|
|
|
$spotter_array = $Spotter->getDataFromDB($query, $query_values, $limit_query); |
1553
|
|
|
|
1554
|
|
|
return $spotter_array; |
1555
|
|
|
} |
1556
|
|
|
} |
1557
|
|
|
?> |