1
|
|
|
<?php |
2
|
|
|
//$global_query = "SELECT spotter_live.* FROM spotter_live"; |
3
|
|
|
|
4
|
|
|
class SpotterLive { |
5
|
|
|
public $db; |
6
|
|
|
static $global_query = "SELECT spotter_live.* FROM spotter_live"; |
7
|
|
|
|
8
|
|
|
public function __construct($dbc = null) { |
9
|
|
|
$Connection = new Connection($dbc); |
10
|
|
|
$this->db = $Connection->db(); |
11
|
|
|
if ($this->db === null) die('Error: No DB connection. (SpotterLive)'); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Get SQL query part for filter used |
17
|
|
|
* @param array $filter the filter |
18
|
|
|
* @return string the SQL part |
19
|
|
|
*/ |
20
|
|
|
public function getFilter($filter = array(),$where = false,$and = false) { |
21
|
|
|
global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver; |
22
|
|
|
$filters = array(); |
23
|
|
|
if (is_array($globalStatsFilters) && isset($globalStatsFilters[$globalFilterName])) { |
24
|
|
|
if (isset($globalStatsFilters[$globalFilterName][0]['source'])) { |
25
|
|
|
$filters = $globalStatsFilters[$globalFilterName]; |
26
|
|
|
} else { |
27
|
|
|
$filter = array_merge($filter,$globalStatsFilters[$globalFilterName]); |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
if (isset($filter[0]['source'])) { |
31
|
|
|
$filters = array_merge($filters,$filter); |
32
|
|
|
} |
33
|
|
|
if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter); |
34
|
|
|
$filter_query_join = ''; |
35
|
|
|
$filter_query_where = ''; |
36
|
|
|
foreach($filters as $flt) { |
37
|
|
|
if (isset($flt['airlines']) && !empty($flt['airlines'])) { |
38
|
|
|
if ($flt['airlines'][0] != '' && $flt['airlines'][0] != 'all') { |
39
|
|
|
if (isset($flt['source'])) { |
40
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$flt['airlines'])."') AND spotter_output.format_source IN ('".implode("','",$flt['source'])."')) saf ON saf.flightaware_id = spotter_live.flightaware_id"; |
41
|
|
|
} else { |
42
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$flt['airlines'])."')) saf ON saf.flightaware_id = spotter_live.flightaware_id"; |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
if (isset($flt['pilots_id']) && !empty($flt['pilots_id'])) { |
47
|
|
|
if (isset($flt['source'])) { |
48
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.pilot_id IN ('".implode("','",$flt['pilots_id'])."') AND spotter_output.format_source IN ('".implode("','",$flt['source'])."')) spi ON spi.flightaware_id = spotter_live.flightaware_id"; |
49
|
|
|
} else { |
50
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.pilot_id IN ('".implode("','",$flt['pilots_id'])."')) spi ON spi.flightaware_id = spotter_live.flightaware_id"; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
if (isset($flt['idents']) && !empty($flt['idents'])) { |
54
|
|
|
if (isset($flt['source'])) { |
55
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.ident IN ('".implode("','",$flt['idents'])."') AND spotter_output.format_source IN ('".implode("','",$flt['source'])."')) spid ON spid.flightaware_id = spotter_live.flightaware_id"; |
56
|
|
|
} else { |
57
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.ident IN ('".implode("','",$flt['idents'])."')) spid ON spid.flightaware_id = spotter_live.flightaware_id"; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
if (isset($flt['registrations']) && !empty($flt['registrations'])) { |
61
|
|
|
if (isset($flt['source'])) { |
62
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.registration IN ('".implode("','",$flt['registrations'])."') AND spotter_output.format_source IN ('".implode("','",$flt['source'])."')) sre ON sre.flightaware_id = spotter_live.flightaware_id"; |
63
|
|
|
} else { |
64
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.registration IN ('".implode("','",$flt['registrations'])."')) sre ON sre.flightaware_id = spotter_live.flightaware_id"; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
if ((isset($flt['airlines']) && empty($flt['airlines']) && isset($flt['pilots_id']) && empty($flt['pilots_id']) && isset($flt['idents']) && empty($flt['idents'])) || (!isset($flt['airlines']) && !isset($flt['pilots_id']) && !isset($flt['idents']) && !isset($flt['registrations']))) { |
68
|
|
|
if (isset($flt['source'])) { |
69
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.format_source IN ('".implode("','",$flt['source'])."')) ssf ON ssf.flightaware_id = spotter_live.flightaware_id"; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
if (isset($filter['airlines']) && !empty($filter['airlines'])) { |
74
|
|
|
if ($filter['airlines'][0] != '' && $filter['airlines'][0] != 'all') { |
75
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) sai ON sai.flightaware_id = spotter_live.flightaware_id"; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
if (isset($filter['alliance']) && !empty($filter['alliance'])) { |
79
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN (SELECT icao FROM airlines WHERE alliance = '".$filter['alliance']."')) sal ON sal.flightaware_id = spotter_live.flightaware_id "; |
80
|
|
|
} |
81
|
|
|
if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) { |
82
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_live.flightaware_id "; |
83
|
|
|
} |
84
|
|
|
if (isset($filter['pilots_id']) && !empty($filter['pilots_id'])) { |
85
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.pilot_id IN ('".implode("','",$filter['pilots_id'])."')) sp ON sp.flightaware_id = spotter_live.flightaware_id"; |
86
|
|
|
} |
87
|
|
|
if (isset($filter['blocked']) && $filter['blocked'] == true) { |
88
|
|
|
$filter_query_join .= " INNER JOIN (SELECT callsign FROM aircraft_block) cblk ON cblk.callsign = spotter_live.ident"; |
89
|
|
|
} |
90
|
|
|
if (isset($filter['source']) && !empty($filter['source'])) { |
91
|
|
|
if (count($filter['source']) == 1) { |
92
|
|
|
$filter_query_where .= " AND format_source = '".$filter['source'][0]."'"; |
93
|
|
|
} else { |
94
|
|
|
$filter_query_where .= " AND format_source IN ('".implode("','",$filter['source'])."')"; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
if (isset($filter['ident']) && !empty($filter['ident'])) { |
98
|
|
|
$filter_query_where .= " AND ident = '".$filter['ident']."'"; |
99
|
|
|
} |
100
|
|
|
if (isset($filter['id']) && !empty($filter['id'])) { |
101
|
|
|
$filter_query_where .= " AND flightaware_id = '".$filter['id']."'"; |
102
|
|
|
} |
103
|
|
|
if ((isset($filter['year']) && $filter['year'] != '') || (isset($filter['month']) && $filter['month'] != '') || (isset($filter['day']) && $filter['day'] != '')) { |
104
|
|
|
$filter_query_date = ''; |
105
|
|
|
|
106
|
|
|
if (isset($filter['year']) && $filter['year'] != '') { |
107
|
|
|
if ($globalDBdriver == 'mysql') { |
108
|
|
|
$filter_query_date .= " AND YEAR(spotter_output.date) = '".$filter['year']."'"; |
109
|
|
|
} else { |
110
|
|
|
$filter_query_date .= " AND EXTRACT(YEAR FROM spotter_output.date) = '".$filter['year']."'"; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
if (isset($filter['month']) && $filter['month'] != '') { |
114
|
|
|
if ($globalDBdriver == 'mysql') { |
115
|
|
|
$filter_query_date .= " AND MONTH(spotter_output.date) = '".$filter['month']."'"; |
116
|
|
|
} else { |
117
|
|
|
$filter_query_date .= " AND EXTRACT(MONTH FROM spotter_output.date) = '".$filter['month']."'"; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
if (isset($filter['day']) && $filter['day'] != '') { |
121
|
|
|
if ($globalDBdriver == 'mysql') { |
122
|
|
|
$filter_query_date .= " AND DAY(spotter_output.date) = '".$filter['day']."'"; |
123
|
|
|
} else { |
124
|
|
|
$filter_query_date .= " AND EXTRACT(DAY FROM spotter_output.date) = '".$filter['day']."'"; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
$filter_query_join .= " INNER JOIN (SELECT flightaware_id FROM spotter_output".preg_replace('/^ AND/',' WHERE',$filter_query_date).") sd ON sd.flightaware_id = spotter_live.flightaware_id"; |
128
|
|
|
} |
129
|
|
|
if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) { |
130
|
|
|
$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
131
|
|
|
} |
132
|
|
|
if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE'; |
133
|
|
|
elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND'; |
134
|
|
|
if ($filter_query_where != '') { |
135
|
|
|
$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where); |
136
|
|
|
} |
137
|
|
|
$filter_query = $filter_query_join.$filter_query_where; |
138
|
|
|
return $filter_query; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Gets all the spotter information based on the latest data entry |
143
|
|
|
* |
144
|
|
|
* @param string $limit |
145
|
|
|
* @param string $sort |
146
|
|
|
* @param array $filter |
147
|
|
|
* @return array the spotter information |
148
|
|
|
*/ |
149
|
|
|
public function getLiveSpotterData($limit = '', $sort = '', $filter = array()) |
150
|
|
|
{ |
151
|
|
|
global $globalDBdriver, $globalLiveInterval; |
152
|
|
|
$Spotter = new Spotter($this->db); |
153
|
|
|
date_default_timezone_set('UTC'); |
154
|
|
|
|
155
|
|
|
$filter_query = $this->getFilter($filter); |
156
|
|
|
$limit_query = ''; |
157
|
|
|
if ($limit != '') |
158
|
|
|
{ |
159
|
|
|
$limit_array = explode(',', $limit); |
160
|
|
|
$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
161
|
|
|
$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
162
|
|
|
if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
163
|
|
|
{ |
164
|
|
|
$limit_query = ' LIMIT '.$limit_array[1].' OFFSET '.$limit_array[0]; |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
$orderby_query = ''; |
168
|
|
|
if ($sort != '') |
169
|
|
|
{ |
170
|
|
|
$search_orderby_array = $this->getOrderBy(); |
171
|
|
|
if (isset($search_orderby_array[$sort]['sql'])) |
172
|
|
|
{ |
173
|
|
|
$orderby_query = ' '.$search_orderby_array[$sort]['sql']; |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
if ($orderby_query == '') $orderby_query = ' ORDER BY date DESC'; |
177
|
|
|
|
178
|
|
|
if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
179
|
|
|
if ($globalDBdriver == 'mysql') { |
180
|
|
|
//$query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate"; |
181
|
|
|
$query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query.$orderby_query; |
182
|
|
|
} else { |
183
|
|
|
$query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate".$filter_query.$orderby_query; |
184
|
|
|
} |
185
|
|
|
$spotter_array = $Spotter->getDataFromDB($query.$limit_query,array(),'',true); |
186
|
|
|
|
187
|
|
|
return $spotter_array; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Gets Minimal Live Spotter data |
192
|
|
|
* |
193
|
|
|
* @param int $limit |
194
|
|
|
* @param array $filter |
195
|
|
|
* @return array the spotter information |
196
|
|
|
*/ |
197
|
|
|
public function getMinLiveSpotterData($limit = 0,$filter = array()) |
198
|
|
|
{ |
199
|
|
|
global $globalDBdriver, $globalLiveInterval, $globalArchive, $globalMap2DAircraftsLimit; |
200
|
|
|
date_default_timezone_set('UTC'); |
201
|
|
|
$filter_query = $this->getFilter($filter,true,true); |
202
|
|
|
if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
203
|
|
|
if ($globalDBdriver == 'mysql') { |
204
|
|
|
if (isset($globalArchive) && $globalArchive === TRUE) { |
205
|
|
|
// $query = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
206
|
|
|
// FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= spotter_live.date AND'." spotter_live.latitude <> 0 AND spotter_live.longitude <> 0 ORDER BY date DESC"; |
207
|
|
|
$query = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
208
|
|
|
FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= spotter_live.date AND'." spotter_live.latitude <> 0 AND spotter_live.longitude <> 0"; |
209
|
|
|
} else { |
210
|
|
|
// $query = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
211
|
|
|
// FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query." spotter_live.latitude <> 0 AND spotter_live.longitude <> 0 ORDER BY date DESC"; |
212
|
|
|
$query = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
213
|
|
|
FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query." spotter_live.latitude <> 0 AND spotter_live.longitude <> 0"; |
214
|
|
|
} |
215
|
|
|
} else { |
216
|
|
|
if (isset($globalArchive) && $globalArchive === TRUE) { |
217
|
|
|
// $query = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
218
|
|
|
// FROM spotter_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' ORDER BY date DESC"; |
219
|
|
|
$query = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
220
|
|
|
FROM spotter_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0'"; |
221
|
|
|
} else { |
222
|
|
|
// $query = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
223
|
|
|
// FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate".$filter_query." spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' ORDER BY date DESC"; |
224
|
|
|
$query = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
225
|
|
|
FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate".$filter_query." spotter_live.latitude <> '0' AND spotter_live.longitude <> '0'"; |
226
|
|
|
} |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
if ($limit == 0 && isset($globalMap2DAircraftsLimit) && $globalMap2DAircraftsLimit != '') { |
230
|
|
|
$limit = $globalMap2DAircraftsLimit; |
231
|
|
|
} |
232
|
|
|
if ($limit != 0 && filter_var($limit,FILTER_VALIDATE_INT)) { |
233
|
|
|
$query .= ' LIMIT '.$limit; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
try { |
237
|
|
|
$sth = $this->db->prepare($query); |
238
|
|
|
$sth->execute(); |
239
|
|
|
} catch(PDOException $e) { |
240
|
|
|
echo $e->getMessage(); |
241
|
|
|
die; |
242
|
|
|
} |
243
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
244
|
|
|
return $spotter_array; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* Gets Minimal Live Spotter data since xx seconds |
249
|
|
|
* |
250
|
|
|
* @param array $coord |
251
|
|
|
* @param array $filter |
252
|
|
|
* @param int $limit |
253
|
|
|
* @param string $id |
254
|
|
|
* @return array the spotter information |
255
|
|
|
*/ |
256
|
|
|
public function getMinLastLiveSpotterData($coord = array(),$filter = array(), $limit = 0, $id = '') |
257
|
|
|
{ |
258
|
|
|
global $globalDBdriver, $globalLiveInterval, $globalArchive, $globalMap3DAircraftsLimit; |
259
|
|
|
date_default_timezone_set('UTC'); |
260
|
|
|
$usecoord = false; |
261
|
|
|
if (is_array($coord) && !empty($coord)) { |
262
|
|
|
$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
263
|
|
|
$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
264
|
|
|
$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
265
|
|
|
$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
266
|
|
|
if ($minlong != '' && $minlat != '' && $maxlong != '' && $maxlat != '') $usecoord = true; |
267
|
|
|
} |
268
|
|
|
$id = filter_var($id,FILTER_SANITIZE_STRING); |
269
|
|
|
$filter_query = $this->getFilter($filter,true,true); |
270
|
|
|
|
271
|
|
|
if (!isset($globalLiveInterval) || $globalLiveInterval == '') $globalLiveInterval = '200'; |
272
|
|
|
if (!isset($globalMap3DAircraftsLimit) || $globalMap3DAircraftsLimit == '') $globalMap3DAircraftsLimit = '300'; |
273
|
|
|
if ($limit == 0 || $limit == '') $limit = $globalMap3DAircraftsLimit; |
274
|
|
|
if ($globalDBdriver == 'mysql') { |
275
|
|
|
if (isset($globalArchive) && $globalArchive === TRUE) { |
276
|
|
|
/* |
277
|
|
|
$query = 'SELECT spotter_archive.ident, spotter_archive.flightaware_id, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, spotter_archive.date, spotter_archive.format_source |
278
|
|
|
FROM spotter_archive INNER JOIN (SELECT flightaware_id FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= spotter_live.date) l ON l.flightaware_id = spotter_archive.flightaware_id |
279
|
|
|
WHERE spotter_archive.latitude <> '0' AND spotter_archive.longitude <> '0' |
280
|
|
|
ORDER BY spotter_archive.flightaware_id, spotter_archive.date"; |
281
|
|
|
*/ |
282
|
|
|
$query = 'SELECT * FROM (SELECT spotter_archive.ident, spotter_archive.flightaware_id, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, spotter_archive.date, spotter_archive.format_source, spotter_archive.registration |
283
|
|
|
FROM spotter_archive INNER JOIN (SELECT flightaware_id FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= spotter_live.date"; |
284
|
|
|
//if ($limit > 0) $query .= " LIMIT ".$limit; |
285
|
|
|
$query .= ") l ON l.flightaware_id = spotter_archive.flightaware_id "; |
286
|
|
|
if ($usecoord) $query .= "AND (spotter_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_archive.longitude BETWEEN ".$minlong." AND ".$maxlong.") "; |
|
|
|
|
287
|
|
|
if ($id != '') $query .= "OR spotter_archive.flightaware_id = :id "; |
288
|
|
|
$query .= "UNION |
289
|
|
|
SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
290
|
|
|
FROM spotter_live".$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= spotter_live.date"; |
291
|
|
|
if ($usecoord) $query .= " AND (spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.")"; |
292
|
|
|
if ($id != '') $query .= " OR spotter_live.flightaware_id = :id"; |
293
|
|
|
//if ($limit > 0) $query .= " LIMIT ".$limit; |
294
|
|
|
$query .= ") AS spotter |
295
|
|
|
WHERE latitude <> '0' AND longitude <> '0' |
296
|
|
|
ORDER BY flightaware_id, date"; |
297
|
|
|
if ($limit > 0) $query .= " LIMIT ".$limit; |
298
|
|
|
} else { |
299
|
|
|
$query = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
300
|
|
|
FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= spotter_live.date "; |
301
|
|
|
if ($usecoord) $query .= "AND (spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.") "; |
302
|
|
|
if ($id != '') $query .= "OR spotter_live.flightaware_id = :id "; |
303
|
|
|
$query .= "AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' |
304
|
|
|
ORDER BY spotter_live.flightaware_id, spotter_live.date"; |
305
|
|
|
if ($limit > 0) $query .= " LIMIT ".$limit; |
306
|
|
|
} |
307
|
|
|
} else { |
308
|
|
|
if (isset($globalArchive) && $globalArchive === TRUE) { |
309
|
|
|
/* |
310
|
|
|
$query = "SELECT spotter_archive.ident, spotter_archive.flightaware_id, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, spotter_archive.date, spotter_archive.format_source |
311
|
|
|
FROM spotter_archive INNER JOIN (SELECT flightaware_id FROM spotter_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date) l ON l.flightaware_id = spotter_archive.flightaware_id |
312
|
|
|
WHERE spotter_archive.latitude <> '0' AND spotter_archive.longitude <> '0' |
313
|
|
|
ORDER BY spotter_archive.flightaware_id, spotter_archive.date"; |
314
|
|
|
*/ |
315
|
|
|
$query = "SELECT * FROM ( |
316
|
|
|
SELECT spotter_archive.ident, spotter_archive.flightaware_id, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, spotter_archive.date, spotter_archive.format_source, spotter_archive.registration |
317
|
|
|
FROM spotter_archive |
318
|
|
|
INNER JOIN ( |
319
|
|
|
SELECT flightaware_id |
320
|
|
|
FROM spotter_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date"; |
321
|
|
|
//if ($limit > 0) $query .= " ORDER BY spotter_live.date ASC LIMIT ".$limit; |
322
|
|
|
$query .= ") l ON l.flightaware_id = spotter_archive.flightaware_id "; |
323
|
|
|
if ($usecoord) $query .= "AND (spotter_archive.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_archive.longitude BETWEEN ".$minlong." AND ".$maxlong.") "; |
324
|
|
|
if ($id != '') $query .= "OR spotter_archive.flightaware_id = :id "; |
325
|
|
|
$query .= "UNION |
326
|
|
|
SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
327
|
|
|
FROM spotter_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date"; |
328
|
|
|
if ($usecoord) $query .= " AND (spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.")"; |
329
|
|
|
if ($id != '') $query .= " OR spotter_live.flightaware_id = :id"; |
330
|
|
|
//if ($limit > 0) $query .= " ORDER BY date ASC LIMIT ".$limit; |
331
|
|
|
$query .= ") AS spotter WHERE latitude <> '0' AND longitude <> '0' "; |
332
|
|
|
$query .= "ORDER BY flightaware_id, date"; |
333
|
|
|
if ($limit > 0) $query .= " LIMIT ".$limit; |
334
|
|
|
} else { |
335
|
|
|
$query = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
336
|
|
|
FROM spotter_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date "; |
337
|
|
|
if ($usecoord) $query .= "AND (spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.") "; |
338
|
|
|
if ($id != '') $query .= "OR spotter_live.flightaware_id = :id "; |
339
|
|
|
$query .= "AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' |
340
|
|
|
ORDER BY spotter_live.flightaware_id, spotter_live.date"; |
341
|
|
|
if ($limit > 0) $query .= " LIMIT ".$limit; |
342
|
|
|
} |
343
|
|
|
} |
344
|
|
|
$query_values = array(); |
345
|
|
|
if ($id != '') $query_values = array(':id' => $id); |
346
|
|
|
try { |
347
|
|
|
$sth = $this->db->prepare($query); |
348
|
|
|
$sth->execute($query_values); |
349
|
|
|
} catch(PDOException $e) { |
350
|
|
|
echo $e->getMessage(); |
351
|
|
|
die; |
352
|
|
|
} |
353
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
354
|
|
|
return $spotter_array; |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* Gets Minimal Live Spotter data since xx seconds |
359
|
|
|
* |
360
|
|
|
* @param string $id |
361
|
|
|
* @param array $filter |
362
|
|
|
* @param int $limit |
363
|
|
|
* @return array the spotter information |
364
|
|
|
*/ |
365
|
|
|
public function getMinLastLiveSpotterDataByID($id = '',$filter = array(), $limit = 0) |
366
|
|
|
{ |
367
|
|
|
global $globalDBdriver, $globalLiveInterval, $globalArchive, $globalMap3DAircraftsLimit; |
368
|
|
|
date_default_timezone_set('UTC'); |
369
|
|
|
$id = filter_var($id,FILTER_SANITIZE_STRING); |
370
|
|
|
$filter_query = $this->getFilter($filter,true,true); |
371
|
|
|
|
372
|
|
|
if (!isset($globalLiveInterval) || $globalLiveInterval == '') $globalLiveInterval = '200'; |
373
|
|
|
if (!isset($globalMap3DAircraftsLimit) || $globalMap3DAircraftsLimit == '') $globalMap3DAircraftsLimit = '300'; |
374
|
|
|
if ($limit == 0 || $limit == '') $limit = $globalMap3DAircraftsLimit; |
375
|
|
|
if ($globalDBdriver == 'mysql') { |
376
|
|
|
if (isset($globalArchive) && $globalArchive === TRUE) { |
377
|
|
|
$query = 'SELECT * FROM (SELECT spotter_archive.ident, spotter_archive.flightaware_id, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, spotter_archive.date, spotter_archive.format_source, spotter_archive.registration |
378
|
|
|
FROM spotter_archive INNER JOIN (SELECT flightaware_id FROM spotter_live'.$filter_query.' spotter_live.flightaware_id = :id) l ON l.flightaware_id = spotter_archive.flightaware_id '; |
379
|
|
|
$query .= "UNION |
380
|
|
|
SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
381
|
|
|
FROM spotter_live".$filter_query.' spotter_live.flightaware_id = :id'; |
382
|
|
|
$query .= ") AS spotter |
383
|
|
|
WHERE latitude <> '0' AND longitude <> '0' |
384
|
|
|
ORDER BY flightaware_id, date"; |
385
|
|
|
if ($limit > 0) $query .= " LIMIT ".$limit; |
386
|
|
|
} else { |
387
|
|
|
$query = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
388
|
|
|
FROM spotter_live'.$filter_query.' spotter_live.flightaware_id = :id '; |
389
|
|
|
$query .= "AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' |
390
|
|
|
ORDER BY spotter_live.flightaware_id, spotter_live.date"; |
391
|
|
|
if ($limit > 0) $query .= " LIMIT ".$limit; |
392
|
|
|
} |
393
|
|
|
} else { |
394
|
|
|
if (isset($globalArchive) && $globalArchive === TRUE) { |
395
|
|
|
$query = "SELECT * FROM ( |
396
|
|
|
SELECT spotter_archive.ident, spotter_archive.flightaware_id, spotter_archive.aircraft_icao, spotter_archive.departure_airport_icao as departure_airport, spotter_archive.arrival_airport_icao as arrival_airport, spotter_archive.latitude, spotter_archive.longitude, spotter_archive.altitude, spotter_archive.heading, spotter_archive.ground_speed, spotter_archive.squawk, spotter_archive.date, spotter_archive.format_source, spotter_archive.registration |
397
|
|
|
FROM spotter_archive |
398
|
|
|
INNER JOIN ( |
399
|
|
|
SELECT flightaware_id |
400
|
|
|
FROM spotter_live".$filter_query." spotter_live.flightaware_id = :id"; |
401
|
|
|
$query.= ") l ON l.flightaware_id = spotter_archive.flightaware_id "; |
402
|
|
|
$query .= "UNION |
403
|
|
|
SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
404
|
|
|
FROM spotter_live".$filter_query." spotter_live.flightaware_id = :id"; |
405
|
|
|
$query .= ") AS spotter WHERE latitude <> '0' AND longitude <> '0' "; |
406
|
|
|
$query .= "ORDER BY flightaware_id, date"; |
407
|
|
|
if ($limit > 0) $query .= " LIMIT ".$limit; |
408
|
|
|
} else { |
409
|
|
|
$query = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
410
|
|
|
FROM spotter_live".$filter_query." spotter_live.flightaware_id = :id "; |
411
|
|
|
$query .= "AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' |
412
|
|
|
ORDER BY spotter_live.flightaware_id, spotter_live.date"; |
413
|
|
|
if ($limit > 0) $query .= " LIMIT ".$limit; |
414
|
|
|
} |
415
|
|
|
} |
416
|
|
|
$query_values = array(':id' => $id); |
417
|
|
|
try { |
418
|
|
|
$sth = $this->db->prepare($query); |
419
|
|
|
$sth->execute($query_values); |
420
|
|
|
} catch(PDOException $e) { |
421
|
|
|
echo $e->getMessage(); |
422
|
|
|
die; |
423
|
|
|
} |
424
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
425
|
|
|
return $spotter_array; |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
/** |
429
|
|
|
* Gets number of latest data entry |
430
|
|
|
* |
431
|
|
|
* @param array $filter |
432
|
|
|
* @return String number of entry |
433
|
|
|
*/ |
434
|
|
|
public function getLiveSpotterCount($filter = array()) |
435
|
|
|
{ |
436
|
|
|
global $globalDBdriver, $globalLiveInterval; |
437
|
|
|
$filter_query = $this->getFilter($filter,true,true); |
438
|
|
|
|
439
|
|
|
if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
440
|
|
|
if ($globalDBdriver == 'mysql') { |
441
|
|
|
//$query = 'SELECT COUNT(*) as nb FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query; |
442
|
|
|
$query = 'SELECT COUNT(DISTINCT spotter_live.flightaware_id) as nb FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date'; |
443
|
|
|
} else { |
444
|
|
|
//$query = "SELECT COUNT(*) as nb FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() AT TIME ZONE 'UTC' - '".$globalLiveInterval." SECONDS'->INTERVAL <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate".$filter_query; |
445
|
|
|
$query = "SELECT COUNT(DISTINCT spotter_live.flightaware_id) as nb FROM spotter_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date"; |
446
|
|
|
} |
447
|
|
|
try { |
448
|
|
|
$sth = $this->db->prepare($query); |
449
|
|
|
$sth->execute(); |
450
|
|
|
} catch(PDOException $e) { |
451
|
|
|
echo $e->getMessage(); |
452
|
|
|
die; |
453
|
|
|
} |
454
|
|
|
$result = $sth->fetch(PDO::FETCH_ASSOC); |
455
|
|
|
$sth->closeCursor(); |
456
|
|
|
return $result['nb']; |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
/** |
460
|
|
|
* Gets all the spotter information based on the latest data entry and coord |
461
|
|
|
* |
462
|
|
|
* @param $coord |
463
|
|
|
* @param array $filter |
464
|
|
|
* @return array the spotter information |
465
|
|
|
*/ |
466
|
|
|
public function getLiveSpotterDatabyCoord($coord, $filter = array()) |
467
|
|
|
{ |
468
|
|
|
global $globalDBdriver, $globalLiveInterval,$globalMap2DAircraftsLimit; |
469
|
|
|
$Spotter = new Spotter($this->db); |
470
|
|
|
if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
471
|
|
|
$filter_query = $this->getFilter($filter); |
472
|
|
|
|
473
|
|
|
if (is_array($coord)) { |
474
|
|
|
$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
475
|
|
|
$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
476
|
|
|
$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
477
|
|
|
$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
478
|
|
|
} else return array(); |
479
|
|
|
if ($globalDBdriver == 'mysql') { |
480
|
|
|
$query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND spotter_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND spotter_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.' GROUP BY spotter_live.flightaware_id'.$filter_query; |
481
|
|
|
} else { |
482
|
|
|
$query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() at time zone 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong." GROUP BY spotter_live.flightaware_id".$filter_query; |
483
|
|
|
} |
484
|
|
|
if (isset($globalMap2DAircraftsLimit) && $globalMap2DAircraftsLimit != '') { |
485
|
|
|
$query .= ' LIMIT '.$globalMap2DAircraftsLimit; |
486
|
|
|
} |
487
|
|
|
|
488
|
|
|
$spotter_array = $Spotter->getDataFromDB($query); |
489
|
|
|
return $spotter_array; |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
/** |
493
|
|
|
* Gets all the spotter information based on the latest data entry and coord |
494
|
|
|
* |
495
|
|
|
* @param $coord |
496
|
|
|
* @param int $limit |
497
|
|
|
* @param array $filter |
498
|
|
|
* @return array the spotter information |
499
|
|
|
*/ |
500
|
|
|
public function getMinLiveSpotterDatabyCoord($coord,$limit = 0, $filter = array()) |
501
|
|
|
{ |
502
|
|
|
global $globalDBdriver, $globalLiveInterval, $globalArchive,$globalMap2DAircraftsLimit; |
503
|
|
|
if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
504
|
|
|
$filter_query = $this->getFilter($filter,true,true); |
505
|
|
|
|
506
|
|
|
if (is_array($coord)) { |
507
|
|
|
$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
508
|
|
|
$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
509
|
|
|
$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
510
|
|
|
$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
511
|
|
|
} else return array(); |
512
|
|
|
if ($globalDBdriver == 'mysql') { |
513
|
|
|
if (isset($globalArchive) && $globalArchive === TRUE) { |
514
|
|
|
$query = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
515
|
|
|
FROM spotter_live |
516
|
|
|
'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= spotter_live.date |
517
|
|
|
AND spotter_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND spotter_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.' |
518
|
|
|
AND spotter_live.latitude <> 0 AND spotter_live.longitude <> 0 ORDER BY date DESC'; |
519
|
|
|
} else { |
520
|
|
|
$query = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
521
|
|
|
FROM spotter_live |
522
|
|
|
INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate |
523
|
|
|
FROM spotter_live l |
524
|
|
|
WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date |
525
|
|
|
AND l.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND l.longitude BETWEEN '.$minlong.' AND '.$maxlong.' |
526
|
|
|
GROUP BY l.flightaware_id |
527
|
|
|
) s on spotter_live.flightaware_id = s.flightaware_id |
528
|
|
|
AND spotter_live.date = s.maxdate'.$filter_query.' spotter_live.latitude <> 0 AND spotter_live.longitude <> 0 ORDER BY date DESC'; |
529
|
|
|
} |
530
|
|
|
} else { |
531
|
|
|
if (isset($globalArchive) && $globalArchive === TRUE) { |
532
|
|
|
/* |
533
|
|
|
$query = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
534
|
|
|
FROM spotter_live |
535
|
|
|
".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date |
536
|
|
|
AND spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." |
537
|
|
|
AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong." |
538
|
|
|
AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' ORDER BY date DESC"; |
539
|
|
|
*/ |
540
|
|
|
$query = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
541
|
|
|
FROM spotter_live |
542
|
|
|
".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date |
543
|
|
|
AND spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." |
544
|
|
|
AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong." |
545
|
|
|
AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0'"; |
546
|
|
|
} else { |
547
|
|
|
/* |
548
|
|
|
$query = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
549
|
|
|
FROM spotter_live |
550
|
|
|
INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate |
551
|
|
|
FROM spotter_live l |
552
|
|
|
WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date |
553
|
|
|
AND l.latitude BETWEEN ".$minlat." AND ".$maxlat." |
554
|
|
|
AND l.longitude BETWEEN ".$minlong." AND ".$maxlong." |
555
|
|
|
GROUP BY l.flightaware_id |
556
|
|
|
) s on spotter_live.flightaware_id = s.flightaware_id |
557
|
|
|
AND spotter_live.date = s.maxdate".$filter_query." spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' ORDER BY date DESC"; |
558
|
|
|
*/ |
559
|
|
|
$query = "SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.real_altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source, spotter_live.registration |
560
|
|
|
FROM spotter_live |
561
|
|
|
INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate |
562
|
|
|
FROM spotter_live l |
563
|
|
|
WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date |
564
|
|
|
AND l.latitude BETWEEN ".$minlat." AND ".$maxlat." |
565
|
|
|
AND l.longitude BETWEEN ".$minlong." AND ".$maxlong." |
566
|
|
|
GROUP BY l.flightaware_id |
567
|
|
|
) s on spotter_live.flightaware_id = s.flightaware_id |
568
|
|
|
AND spotter_live.date = s.maxdate".$filter_query." spotter_live.latitude <> '0' AND spotter_live.longitude <> '0'"; |
569
|
|
|
} |
570
|
|
|
} |
571
|
|
|
if ($limit == 0 && isset($globalMap2DAircraftsLimit) && $globalMap2DAircraftsLimit != '') { |
572
|
|
|
$limit = $globalMap2DAircraftsLimit; |
573
|
|
|
} |
574
|
|
|
if ($limit != 0 && filter_var($limit,FILTER_VALIDATE_INT)) { |
575
|
|
|
$query .= ' LIMIT '.$limit; |
576
|
|
|
} |
577
|
|
|
try { |
578
|
|
|
$sth = $this->db->prepare($query); |
579
|
|
|
$sth->execute(); |
580
|
|
|
} catch(PDOException $e) { |
581
|
|
|
echo $e->getMessage(); |
582
|
|
|
die; |
583
|
|
|
} |
584
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
585
|
|
|
return $spotter_array; |
586
|
|
|
} |
587
|
|
|
|
588
|
|
|
/** |
589
|
|
|
* Gets all the spotter information based on a user's latitude and longitude |
590
|
|
|
* |
591
|
|
|
* @param $lat |
592
|
|
|
* @param $lng |
593
|
|
|
* @param $radius |
594
|
|
|
* @param $interval |
595
|
|
|
* @return array the spotter information |
596
|
|
|
*/ |
597
|
|
|
public function getLatestSpotterForLayar($lat, $lng, $radius, $interval) |
598
|
|
|
{ |
599
|
|
|
$Spotter = new Spotter($this->db); |
600
|
|
|
date_default_timezone_set('UTC'); |
601
|
|
|
if ($lat != '') { |
602
|
|
|
if (!is_numeric($lat)) { |
603
|
|
|
return array(); |
604
|
|
|
} |
605
|
|
|
} |
606
|
|
|
if ($lng != '') |
607
|
|
|
{ |
608
|
|
|
if (!is_numeric($lng)) |
609
|
|
|
{ |
610
|
|
|
return array(); |
611
|
|
|
} |
612
|
|
|
} |
613
|
|
|
if ($radius != '') |
614
|
|
|
{ |
615
|
|
|
if (!is_numeric($radius)) |
616
|
|
|
{ |
617
|
|
|
return array(); |
618
|
|
|
} |
619
|
|
|
} |
620
|
|
|
$additional_query = ''; |
621
|
|
|
if ($interval != '') |
622
|
|
|
{ |
623
|
|
|
if (!is_string($interval)) |
624
|
|
|
{ |
625
|
|
|
return array(); |
626
|
|
|
} else { |
627
|
|
|
if ($interval == '1m') |
628
|
|
|
{ |
629
|
|
|
$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date '; |
630
|
|
|
} else if ($interval == '15m'){ |
631
|
|
|
$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= spotter_live.date '; |
632
|
|
|
} |
633
|
|
|
} |
634
|
|
|
} else { |
635
|
|
|
$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date '; |
636
|
|
|
} |
637
|
|
|
$query = "SELECT spotter_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM spotter_live |
638
|
|
|
WHERE spotter_live.latitude <> '' |
639
|
|
|
AND spotter_live.longitude <> '' |
640
|
|
|
".$additional_query." |
641
|
|
|
HAVING distance < :radius |
642
|
|
|
ORDER BY distance"; |
643
|
|
|
|
644
|
|
|
$spotter_array = $Spotter->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius)); |
645
|
|
|
return $spotter_array; |
646
|
|
|
} |
647
|
|
|
|
648
|
|
|
|
649
|
|
|
/** |
650
|
|
|
* Gets all the spotter information based on a particular callsign |
651
|
|
|
* |
652
|
|
|
* @param $ident |
653
|
|
|
* @return array the spotter information |
654
|
|
|
*/ |
655
|
|
|
public function getLastLiveSpotterDataByIdent($ident) |
656
|
|
|
{ |
657
|
|
|
$Spotter = new Spotter($this->db); |
658
|
|
|
date_default_timezone_set('UTC'); |
659
|
|
|
|
660
|
|
|
$ident = filter_var($ident, FILTER_SANITIZE_STRING); |
661
|
|
|
$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 GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC'; |
662
|
|
|
|
663
|
|
|
$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident),'',true); |
664
|
|
|
|
665
|
|
|
return $spotter_array; |
666
|
|
|
} |
667
|
|
|
|
668
|
|
|
/** |
669
|
|
|
* Gets all the spotter information based on a particular callsign |
670
|
|
|
* |
671
|
|
|
* @param $ident |
672
|
|
|
* @param $date |
673
|
|
|
* @return array the spotter information |
674
|
|
|
*/ |
675
|
|
|
public function getDateLiveSpotterDataByIdent($ident,$date) |
676
|
|
|
{ |
677
|
|
|
$Spotter = new Spotter($this->db); |
678
|
|
|
date_default_timezone_set('UTC'); |
679
|
|
|
|
680
|
|
|
$ident = filter_var($ident, FILTER_SANITIZE_STRING); |
681
|
|
|
$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.date <= :date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC'; |
682
|
|
|
|
683
|
|
|
$date = date('c',$date); |
684
|
|
|
$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident,':date' => $date)); |
685
|
|
|
|
686
|
|
|
return $spotter_array; |
687
|
|
|
} |
688
|
|
|
|
689
|
|
|
/** |
690
|
|
|
* Gets last spotter information based on a particular callsign |
691
|
|
|
* |
692
|
|
|
* @param $id |
693
|
|
|
* @return array the spotter information |
694
|
|
|
*/ |
695
|
|
|
public function getLastLiveSpotterDataById($id) |
696
|
|
|
{ |
697
|
|
|
$Spotter = new Spotter($this->db); |
698
|
|
|
date_default_timezone_set('UTC'); |
699
|
|
|
$id = filter_var($id, FILTER_SANITIZE_STRING); |
700
|
|
|
$query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.flightaware_id = :id GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC'; |
701
|
|
|
$spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id),'',true); |
702
|
|
|
return $spotter_array; |
703
|
|
|
} |
704
|
|
|
|
705
|
|
|
/** |
706
|
|
|
* Gets last spotter information based on a particular callsign |
707
|
|
|
* |
708
|
|
|
* @param $id |
709
|
|
|
* @param $date |
710
|
|
|
* @return array the spotter information |
711
|
|
|
*/ |
712
|
|
|
public function getDateLiveSpotterDataById($id,$date) |
713
|
|
|
{ |
714
|
|
|
$Spotter = new Spotter($this->db); |
715
|
|
|
date_default_timezone_set('UTC'); |
716
|
|
|
|
717
|
|
|
$id = filter_var($id, FILTER_SANITIZE_STRING); |
718
|
|
|
$query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.flightaware_id = :id AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC'; |
719
|
|
|
$date = date('c',$date); |
720
|
|
|
$spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id,':date' => $date),'',true); |
721
|
|
|
return $spotter_array; |
722
|
|
|
} |
723
|
|
|
|
724
|
|
|
/** |
725
|
|
|
* Gets altitude information based on a particular callsign |
726
|
|
|
* |
727
|
|
|
* @param $ident |
728
|
|
|
* @return array the spotter information |
729
|
|
|
*/ |
730
|
|
|
public function getAltitudeLiveSpotterDataByIdent($ident) |
731
|
|
|
{ |
732
|
|
|
|
733
|
|
|
date_default_timezone_set('UTC'); |
734
|
|
|
|
735
|
|
|
$ident = filter_var($ident, FILTER_SANITIZE_STRING); |
736
|
|
|
$query = 'SELECT spotter_live.altitude, spotter_live.date FROM spotter_live WHERE spotter_live.ident = :ident'; |
737
|
|
|
|
738
|
|
|
try { |
739
|
|
|
|
740
|
|
|
$sth = $this->db->prepare($query); |
741
|
|
|
$sth->execute(array(':ident' => $ident)); |
742
|
|
|
} catch(PDOException $e) { |
743
|
|
|
echo $e->getMessage(); |
744
|
|
|
die; |
745
|
|
|
} |
746
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
747
|
|
|
|
748
|
|
|
return $spotter_array; |
749
|
|
|
} |
750
|
|
|
|
751
|
|
|
/** |
752
|
|
|
* Gets all the spotter information based on a particular id |
753
|
|
|
* |
754
|
|
|
* @param $id |
755
|
|
|
* @param bool $liveinterval |
756
|
|
|
* @return array the spotter information |
757
|
|
|
*/ |
758
|
|
|
public function getAllLiveSpotterDataById($id,$liveinterval = false) |
759
|
|
|
{ |
760
|
|
|
global $globalDBdriver, $globalLiveInterval; |
761
|
|
|
date_default_timezone_set('UTC'); |
762
|
|
|
$id = filter_var($id, FILTER_SANITIZE_STRING); |
763
|
|
|
//$query = self::$global_query.' WHERE spotter_live.flightaware_id = :id ORDER BY date'; |
764
|
|
|
if ($globalDBdriver == 'mysql') { |
765
|
|
|
$query = 'SELECT spotter_live.* FROM spotter_live WHERE spotter_live.flightaware_id = :id'; |
766
|
|
|
if ($liveinterval) $query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date'; |
767
|
|
|
$query .= ' ORDER BY date'; |
768
|
|
|
} else { |
769
|
|
|
$query = 'SELECT spotter_live.* FROM spotter_live WHERE spotter_live.flightaware_id = :id'; |
770
|
|
|
if ($liveinterval) $query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date"; |
771
|
|
|
$query .= ' ORDER BY date'; |
772
|
|
|
} |
773
|
|
|
|
774
|
|
|
try { |
775
|
|
|
$sth = $this->db->prepare($query); |
776
|
|
|
$sth->execute(array(':id' => $id)); |
777
|
|
|
} catch(PDOException $e) { |
778
|
|
|
echo $e->getMessage(); |
779
|
|
|
die; |
780
|
|
|
} |
781
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
782
|
|
|
return $spotter_array; |
783
|
|
|
} |
784
|
|
|
|
785
|
|
|
/** |
786
|
|
|
* Gets all the spotter information based on a particular ident |
787
|
|
|
* |
788
|
|
|
* @param $ident |
789
|
|
|
* @return array the spotter information |
790
|
|
|
*/ |
791
|
|
|
public function getAllLiveSpotterDataByIdent($ident) |
792
|
|
|
{ |
793
|
|
|
date_default_timezone_set('UTC'); |
794
|
|
|
$ident = filter_var($ident, FILTER_SANITIZE_STRING); |
795
|
|
|
$query = self::$global_query.' WHERE spotter_live.ident = :ident'; |
796
|
|
|
try { |
797
|
|
|
|
798
|
|
|
$sth = $this->db->prepare($query); |
799
|
|
|
$sth->execute(array(':ident' => $ident)); |
800
|
|
|
} catch(PDOException $e) { |
801
|
|
|
echo $e->getMessage(); |
802
|
|
|
die; |
803
|
|
|
} |
804
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
805
|
|
|
return $spotter_array; |
806
|
|
|
} |
807
|
|
|
|
808
|
|
|
|
809
|
|
|
/** |
810
|
|
|
* Deletes all info in the table |
811
|
|
|
* |
812
|
|
|
* @return String success or false |
813
|
|
|
* |
814
|
|
|
*/ |
815
|
|
|
public function deleteLiveSpotterData() |
816
|
|
|
{ |
817
|
|
|
global $globalDBdriver; |
818
|
|
|
if ($globalDBdriver == 'mysql') { |
819
|
|
|
//$query = "DELETE FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE) >= spotter_live.date"; |
820
|
|
|
$query = 'DELETE FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 9 HOUR) >= spotter_live.date'; |
821
|
|
|
//$query = "DELETE FROM spotter_live WHERE spotter_live.id IN (SELECT spotter_live.id FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= spotter_live.date)"; |
822
|
|
|
} else { |
823
|
|
|
$query = "DELETE FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= spotter_live.date"; |
824
|
|
|
} |
825
|
|
|
|
826
|
|
|
try { |
827
|
|
|
|
828
|
|
|
$sth = $this->db->prepare($query); |
829
|
|
|
$sth->execute(); |
830
|
|
|
} catch(PDOException $e) { |
831
|
|
|
return "error"; |
832
|
|
|
} |
833
|
|
|
|
834
|
|
|
return "success"; |
835
|
|
|
} |
836
|
|
|
|
837
|
|
|
/** |
838
|
|
|
* Deletes all info in the table for aircraft not seen since 2 HOUR |
839
|
|
|
* |
840
|
|
|
* @return String success or false |
841
|
|
|
* |
842
|
|
|
*/ |
843
|
|
|
public function deleteLiveSpotterDataNotUpdated() |
844
|
|
|
{ |
845
|
|
|
global $globalDBdriver, $globalDebug; |
846
|
|
|
if ($globalDBdriver == 'mysql') { |
847
|
|
|
//$query = 'SELECT flightaware_id FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) >= spotter_live.date AND spotter_live.flightaware_id NOT IN (SELECT flightaware_id FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) < spotter_live.date) LIMIT 800 OFFSET 0'; |
848
|
|
|
$query = "SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 2000 OFFSET 0"; |
849
|
|
|
try { |
850
|
|
|
|
851
|
|
|
$sth = $this->db->prepare($query); |
852
|
|
|
$sth->execute(); |
853
|
|
|
} catch(PDOException $e) { |
854
|
|
|
return "error"; |
855
|
|
|
} |
856
|
|
|
$query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN ('; |
857
|
|
|
$i = 0; |
858
|
|
|
$j =0; |
859
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
860
|
|
|
foreach($all as $row) |
861
|
|
|
{ |
862
|
|
|
$i++; |
863
|
|
|
$j++; |
864
|
|
|
if ($j == 30) { |
865
|
|
|
if ($globalDebug) echo "."; |
866
|
|
|
try { |
867
|
|
|
|
868
|
|
|
$sth = $this->db->prepare(substr($query_delete,0,-1).")"); |
869
|
|
|
$sth->execute(); |
870
|
|
|
} catch(PDOException $e) { |
871
|
|
|
return "error"; |
872
|
|
|
} |
873
|
|
|
$query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN ('; |
874
|
|
|
$j = 0; |
875
|
|
|
} |
876
|
|
|
$query_delete .= "'".$row['flightaware_id']."',"; |
877
|
|
|
} |
878
|
|
|
if ($i > 0) { |
879
|
|
|
try { |
880
|
|
|
|
881
|
|
|
$sth = $this->db->prepare(substr($query_delete,0,-1).")"); |
882
|
|
|
$sth->execute(); |
883
|
|
|
} catch(PDOException $e) { |
884
|
|
|
return "error"; |
885
|
|
|
} |
886
|
|
|
} |
887
|
|
|
return "success"; |
888
|
|
|
} elseif ($globalDBdriver == 'pgsql') { |
889
|
|
|
//$query = "SELECT flightaware_id FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= spotter_live.date AND spotter_live.flightaware_id NOT IN (SELECT flightaware_id FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' < spotter_live.date) LIMIT 800 OFFSET 0"; |
890
|
|
|
//$query = "SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0"; |
891
|
|
|
$query = "DELETE FROM spotter_live WHERE flightaware_id IN (SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 2000 OFFSET 0)"; |
892
|
|
|
try { |
893
|
|
|
|
894
|
|
|
$sth = $this->db->prepare($query); |
895
|
|
|
$sth->execute(); |
896
|
|
|
} catch(PDOException $e) { |
897
|
|
|
return "error"; |
898
|
|
|
} |
899
|
|
|
/* $query_delete = "DELETE FROM spotter_live WHERE flightaware_id IN ("; |
900
|
|
|
$i = 0; |
901
|
|
|
$j =0; |
902
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
903
|
|
|
foreach($all as $row) |
904
|
|
|
{ |
905
|
|
|
$i++; |
906
|
|
|
$j++; |
907
|
|
|
if ($j == 100) { |
908
|
|
|
if ($globalDebug) echo "."; |
909
|
|
|
try { |
910
|
|
|
|
911
|
|
|
$sth = $this->db->query(substr($query_delete,0,-1).")"); |
912
|
|
|
//$sth->execute(); |
913
|
|
|
} catch(PDOException $e) { |
914
|
|
|
return "error"; |
915
|
|
|
} |
916
|
|
|
$query_delete = "DELETE FROM spotter_live WHERE flightaware_id IN ("; |
917
|
|
|
$j = 0; |
918
|
|
|
} |
919
|
|
|
$query_delete .= "'".$row['flightaware_id']."',"; |
920
|
|
|
} |
921
|
|
|
if ($i > 0) { |
922
|
|
|
try { |
923
|
|
|
|
924
|
|
|
$sth = $this->db->query(substr($query_delete,0,-1).")"); |
925
|
|
|
//$sth->execute(); |
926
|
|
|
} catch(PDOException $e) { |
927
|
|
|
return "error"; |
928
|
|
|
} |
929
|
|
|
} |
930
|
|
|
*/ |
931
|
|
|
return "success"; |
932
|
|
|
} |
933
|
|
|
} |
934
|
|
|
|
935
|
|
|
/** |
936
|
|
|
* Deletes all info in the table for an ident |
937
|
|
|
* |
938
|
|
|
* @param $ident |
939
|
|
|
* @return String success or false |
940
|
|
|
*/ |
941
|
|
|
public function deleteLiveSpotterDataByIdent($ident) |
942
|
|
|
{ |
943
|
|
|
$ident = filter_var($ident, FILTER_SANITIZE_STRING); |
944
|
|
|
$query = 'DELETE FROM spotter_live WHERE ident = :ident'; |
945
|
|
|
|
946
|
|
|
try { |
947
|
|
|
|
948
|
|
|
$sth = $this->db->prepare($query); |
949
|
|
|
$sth->execute(array(':ident' => $ident)); |
950
|
|
|
} catch(PDOException $e) { |
951
|
|
|
return "error"; |
952
|
|
|
} |
953
|
|
|
|
954
|
|
|
return "success"; |
955
|
|
|
} |
956
|
|
|
|
957
|
|
|
/** |
958
|
|
|
* Deletes all info in the table for an id |
959
|
|
|
* |
960
|
|
|
* @param $id |
961
|
|
|
* @return String success or false |
962
|
|
|
*/ |
963
|
|
|
public function deleteLiveSpotterDataById($id) |
964
|
|
|
{ |
965
|
|
|
$id = filter_var($id, FILTER_SANITIZE_STRING); |
966
|
|
|
$query = 'DELETE FROM spotter_live WHERE flightaware_id = :id'; |
967
|
|
|
|
968
|
|
|
try { |
969
|
|
|
|
970
|
|
|
$sth = $this->db->prepare($query); |
971
|
|
|
$sth->execute(array(':id' => $id)); |
972
|
|
|
} catch(PDOException $e) { |
973
|
|
|
return "error"; |
974
|
|
|
} |
975
|
|
|
|
976
|
|
|
return "success"; |
977
|
|
|
} |
978
|
|
|
|
979
|
|
|
|
980
|
|
|
/** |
981
|
|
|
* Gets the aircraft ident within the last hour |
982
|
|
|
* |
983
|
|
|
* @param $ident |
984
|
|
|
* @return String the ident |
985
|
|
|
*/ |
986
|
|
|
public function getIdentFromLastHour($ident) |
987
|
|
|
{ |
988
|
|
|
global $globalDBdriver, $globalTimezone; |
989
|
|
|
if ($globalDBdriver == 'mysql') { |
990
|
|
|
$query = 'SELECT spotter_live.ident FROM spotter_live |
991
|
|
|
WHERE spotter_live.ident = :ident |
992
|
|
|
AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) |
993
|
|
|
AND spotter_live.date < UTC_TIMESTAMP()'; |
994
|
|
|
$query_data = array(':ident' => $ident); |
995
|
|
|
} else { |
996
|
|
|
$query = "SELECT spotter_live.ident FROM spotter_live |
997
|
|
|
WHERE spotter_live.ident = :ident |
998
|
|
|
AND spotter_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS' |
999
|
|
|
AND spotter_live.date < now() AT TIME ZONE 'UTC'"; |
1000
|
|
|
$query_data = array(':ident' => $ident); |
1001
|
|
|
} |
1002
|
|
|
|
1003
|
|
|
$sth = $this->db->prepare($query); |
1004
|
|
|
$sth->execute($query_data); |
1005
|
|
|
$ident_result=''; |
1006
|
|
|
while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
1007
|
|
|
{ |
1008
|
|
|
$ident_result = $row['ident']; |
1009
|
|
|
} |
1010
|
|
|
return $ident_result; |
1011
|
|
|
} |
1012
|
|
|
|
1013
|
|
|
/** |
1014
|
|
|
* Check recent aircraft |
1015
|
|
|
* |
1016
|
|
|
* @param $ident |
1017
|
|
|
* @return String the ident |
1018
|
|
|
*/ |
1019
|
|
|
public function checkIdentRecent($ident) |
1020
|
|
|
{ |
1021
|
|
|
global $globalDBdriver, $globalTimezone; |
1022
|
|
|
if ($globalDBdriver == 'mysql') { |
1023
|
|
|
$query = 'SELECT spotter_live.ident, spotter_live.flightaware_id FROM spotter_live |
1024
|
|
|
WHERE spotter_live.ident = :ident |
1025
|
|
|
AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 20 MINUTE)'; |
1026
|
|
|
// AND spotter_live.date < UTC_TIMESTAMP()"; |
1027
|
|
|
$query_data = array(':ident' => $ident); |
1028
|
|
|
} else { |
1029
|
|
|
$query = "SELECT spotter_live.ident, spotter_live.flightaware_id FROM spotter_live |
1030
|
|
|
WHERE spotter_live.ident = :ident |
1031
|
|
|
AND spotter_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '20 MINUTES'"; |
1032
|
|
|
// AND spotter_live.date < now() AT TIME ZONE 'UTC'"; |
1033
|
|
|
$query_data = array(':ident' => $ident); |
1034
|
|
|
} |
1035
|
|
|
|
1036
|
|
|
$sth = $this->db->prepare($query); |
1037
|
|
|
$sth->execute($query_data); |
1038
|
|
|
$ident_result=''; |
1039
|
|
|
while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
1040
|
|
|
{ |
1041
|
|
|
$ident_result = $row['flightaware_id']; |
1042
|
|
|
} |
1043
|
|
|
return $ident_result; |
1044
|
|
|
} |
1045
|
|
|
|
1046
|
|
|
/** |
1047
|
|
|
* Check recent aircraft by id |
1048
|
|
|
* |
1049
|
|
|
* @param $id |
1050
|
|
|
* @return String the ident |
1051
|
|
|
*/ |
1052
|
|
|
public function checkIdRecent($id) |
1053
|
|
|
{ |
1054
|
|
|
global $globalDBdriver, $globalTimezone; |
1055
|
|
|
if ($globalDBdriver == 'mysql') { |
1056
|
|
|
$query = 'SELECT spotter_live.ident, spotter_live.flightaware_id FROM spotter_live |
1057
|
|
|
WHERE spotter_live.flightaware_id = :id |
1058
|
|
|
AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 10 HOUR)'; |
1059
|
|
|
// AND spotter_live.date < UTC_TIMESTAMP()"; |
1060
|
|
|
$query_data = array(':id' => $id); |
1061
|
|
|
} else { |
1062
|
|
|
$query = "SELECT spotter_live.ident, spotter_live.flightaware_id FROM spotter_live |
1063
|
|
|
WHERE spotter_live.flightaware_id = :id |
1064
|
|
|
AND spotter_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '10 HOUR'"; |
1065
|
|
|
// AND spotter_live.date < now() AT TIME ZONE 'UTC'"; |
1066
|
|
|
$query_data = array(':id' => $id); |
1067
|
|
|
} |
1068
|
|
|
|
1069
|
|
|
$sth = $this->db->prepare($query); |
1070
|
|
|
$sth->execute($query_data); |
1071
|
|
|
$ident_result=''; |
1072
|
|
|
while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
1073
|
|
|
{ |
1074
|
|
|
$ident_result = $row['flightaware_id']; |
1075
|
|
|
} |
1076
|
|
|
return $ident_result; |
1077
|
|
|
} |
1078
|
|
|
|
1079
|
|
|
/** |
1080
|
|
|
* Check recent aircraft by ModeS |
1081
|
|
|
* |
1082
|
|
|
* @param $modes |
1083
|
|
|
* @return String the ModeS |
1084
|
|
|
*/ |
1085
|
|
|
public function checkModeSRecent($modes) |
1086
|
|
|
{ |
1087
|
|
|
global $globalDBdriver, $globalTimezone; |
1088
|
|
|
if ($globalDBdriver == 'mysql') { |
1089
|
|
|
$query = 'SELECT spotter_live.ModeS, spotter_live.flightaware_id FROM spotter_live |
1090
|
|
|
WHERE spotter_live.ModeS = :modes |
1091
|
|
|
AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 20 MINUTE)'; |
1092
|
|
|
// AND spotter_live.date < UTC_TIMESTAMP()"; |
1093
|
|
|
$query_data = array(':modes' => $modes); |
1094
|
|
|
} else { |
1095
|
|
|
$query = "SELECT spotter_live.ModeS, spotter_live.flightaware_id FROM spotter_live |
1096
|
|
|
WHERE spotter_live.ModeS = :modes |
1097
|
|
|
AND spotter_live.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '20 MINUTE'"; |
1098
|
|
|
// // AND spotter_live.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'"; |
1099
|
|
|
$query_data = array(':modes' => $modes); |
1100
|
|
|
} |
1101
|
|
|
|
1102
|
|
|
$sth = $this->db->prepare($query); |
1103
|
|
|
$sth->execute($query_data); |
1104
|
|
|
$ident_result=''; |
1105
|
|
|
while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
1106
|
|
|
{ |
1107
|
|
|
//$ident_result = $row['spotter_live_id']; |
1108
|
|
|
$ident_result = $row['flightaware_id']; |
1109
|
|
|
} |
1110
|
|
|
return $ident_result; |
1111
|
|
|
} |
1112
|
|
|
|
1113
|
|
|
/** |
1114
|
|
|
* Gets the aircraft data from the last 20 seconds |
1115
|
|
|
* |
1116
|
|
|
* @param string $q |
1117
|
|
|
* @return array the spotter data |
1118
|
|
|
*/ |
1119
|
|
|
public function getRealTimeData($q = '') |
1120
|
|
|
{ |
1121
|
|
|
global $globalDBdriver; |
1122
|
|
|
$additional_query = ''; |
1123
|
|
|
if ($q != "") |
1124
|
|
|
{ |
1125
|
|
|
if (!is_string($q)) |
1126
|
|
|
{ |
1127
|
|
|
return array(); |
1128
|
|
|
} else { |
1129
|
|
|
$q_array = explode(" ", $q); |
1130
|
|
|
foreach ($q_array as $q_item){ |
1131
|
|
|
$q_item = filter_var($q_item,FILTER_SANITIZE_STRING); |
1132
|
|
|
$additional_query .= " AND ("; |
1133
|
|
|
$additional_query .= "(spotter_live.aircraft_icao like '%".$q_item."%') OR "; |
1134
|
|
|
$additional_query .= "(spotter_live.aircraft_name like '%".$q_item."%') OR "; |
1135
|
|
|
$additional_query .= "(spotter_live.aircraft_manufacturer like '%".$q_item."%') OR "; |
1136
|
|
|
$additional_query .= "(spotter_live.airline_icao like '%".$q_item."%') OR "; |
1137
|
|
|
$additional_query .= "(spotter_live.departure_airport_icao like '%".$q_item."%') OR "; |
1138
|
|
|
$additional_query .= "(spotter_live.arrival_airport_icao like '%".$q_item."%') OR "; |
1139
|
|
|
$additional_query .= "(spotter_live.registration like '%".$q_item."%') OR "; |
1140
|
|
|
$additional_query .= "(spotter_live.ident like '%".$q_item."%')"; |
1141
|
|
|
$additional_query .= ")"; |
1142
|
|
|
} |
1143
|
|
|
} |
1144
|
|
|
} |
1145
|
|
|
if ($globalDBdriver == 'mysql') { |
1146
|
|
|
$query = "SELECT spotter_live.* FROM spotter_live |
1147
|
|
|
WHERE spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 20 SECOND) ".$additional_query." |
1148
|
|
|
AND spotter_live.date < UTC_TIMESTAMP()"; |
1149
|
|
|
} else { |
1150
|
|
|
$query = "SELECT spotter_live.* FROM spotter_live |
1151
|
|
|
WHERE spotter_live.date::timestamp >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '20 SECONDS' ".$additional_query." |
1152
|
|
|
AND spotter_live.date::timestamp < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'"; |
1153
|
|
|
} |
1154
|
|
|
$Spotter = new Spotter(); |
1155
|
|
|
$spotter_array = $Spotter->getDataFromDB($query, array()); |
1156
|
|
|
return $spotter_array; |
1157
|
|
|
} |
1158
|
|
|
|
1159
|
|
|
/** |
1160
|
|
|
* Adds a new spotter data |
1161
|
|
|
* |
1162
|
|
|
* @param String $flightaware_id the ID from flightaware |
1163
|
|
|
* @param String $ident the flight ident |
1164
|
|
|
* @param String $aircraft_icao the aircraft type |
1165
|
|
|
* @param String $departure_airport_icao the departure airport |
1166
|
|
|
* @param String $arrival_airport_icao the arrival airport |
1167
|
|
|
* @param string $latitude |
1168
|
|
|
* @param string $longitude |
1169
|
|
|
* @param string $waypoints |
1170
|
|
|
* @param string $altitude |
1171
|
|
|
* @param string $altitude_real |
1172
|
|
|
* @param string $heading |
1173
|
|
|
* @param string $groundspeed |
1174
|
|
|
* @param string $date |
1175
|
|
|
* @param string $departure_airport_time |
1176
|
|
|
* @param string $arrival_airport_time |
1177
|
|
|
* @param string $squawk |
1178
|
|
|
* @param string $route_stop |
1179
|
|
|
* @param string $ModeS |
1180
|
|
|
* @param bool $putinarchive |
1181
|
|
|
* @param string $registration |
1182
|
|
|
* @param string $pilot_id |
1183
|
|
|
* @param string $pilot_name |
1184
|
|
|
* @param string $verticalrate |
1185
|
|
|
* @param bool $noarchive |
1186
|
|
|
* @param bool $ground |
1187
|
|
|
* @param string $format_source |
1188
|
|
|
* @param string $source_name |
1189
|
|
|
* @param string $over_country |
1190
|
|
|
* @return String success or false |
1191
|
|
|
*/ |
1192
|
|
|
public function addLiveSpotterData($flightaware_id = '', $ident = '', $aircraft_icao = '', $departure_airport_icao = '', $arrival_airport_icao = '', $latitude = '', $longitude = '', $waypoints = '', $altitude = '', $altitude_real = '',$heading = '', $groundspeed = '', $date = '',$departure_airport_time = '', $arrival_airport_time = '', $squawk = '', $route_stop = '', $ModeS = '', $putinarchive = false,$registration = '',$pilot_id = '', $pilot_name = '', $verticalrate = '', $noarchive = false, $ground = false,$format_source = '', $source_name = '', $over_country = '') |
1193
|
|
|
{ |
1194
|
|
|
global $globalURL, $globalArchive, $globalDebug; |
1195
|
|
|
$Common = new Common(); |
1196
|
|
|
date_default_timezone_set('UTC'); |
1197
|
|
|
|
1198
|
|
|
//getting the airline information |
1199
|
|
|
if ($ident != '') |
1200
|
|
|
{ |
1201
|
|
|
if (!is_string($ident)) |
1202
|
|
|
{ |
1203
|
|
|
return false; |
1204
|
|
|
} |
1205
|
|
|
} |
1206
|
|
|
|
1207
|
|
|
//getting the aircraft information |
1208
|
|
|
if ($aircraft_icao != '') |
1209
|
|
|
{ |
1210
|
|
|
if (!is_string($aircraft_icao)) |
1211
|
|
|
{ |
1212
|
|
|
return false; |
1213
|
|
|
} |
1214
|
|
|
} |
1215
|
|
|
//getting the departure airport information |
1216
|
|
|
if ($departure_airport_icao != '') |
1217
|
|
|
{ |
1218
|
|
|
if (!is_string($departure_airport_icao)) |
1219
|
|
|
{ |
1220
|
|
|
return false; |
1221
|
|
|
} |
1222
|
|
|
} |
1223
|
|
|
|
1224
|
|
|
//getting the arrival airport information |
1225
|
|
|
if ($arrival_airport_icao != '') |
1226
|
|
|
{ |
1227
|
|
|
if (!is_string($arrival_airport_icao)) |
1228
|
|
|
{ |
1229
|
|
|
return false; |
1230
|
|
|
} |
1231
|
|
|
} |
1232
|
|
|
|
1233
|
|
|
|
1234
|
|
|
if ($latitude != '') |
1235
|
|
|
{ |
1236
|
|
|
if (!is_numeric($latitude)) |
1237
|
|
|
{ |
1238
|
|
|
return false; |
1239
|
|
|
} |
1240
|
|
|
} else return ''; |
1241
|
|
|
|
1242
|
|
|
if ($longitude != '') |
1243
|
|
|
{ |
1244
|
|
|
if (!is_numeric($longitude)) |
1245
|
|
|
{ |
1246
|
|
|
return false; |
1247
|
|
|
} |
1248
|
|
|
} else return ''; |
1249
|
|
|
|
1250
|
|
|
if ($waypoints != '') |
1251
|
|
|
{ |
1252
|
|
|
if (!is_string($waypoints)) |
1253
|
|
|
{ |
1254
|
|
|
return false; |
1255
|
|
|
} |
1256
|
|
|
} |
1257
|
|
|
|
1258
|
|
|
if ($altitude != '') |
1259
|
|
|
{ |
1260
|
|
|
if (!is_numeric($altitude)) |
1261
|
|
|
{ |
1262
|
|
|
return false; |
1263
|
|
|
} |
1264
|
|
|
} else $altitude = 0; |
1265
|
|
|
if ($altitude_real != '') |
1266
|
|
|
{ |
1267
|
|
|
if (!is_numeric($altitude_real)) |
1268
|
|
|
{ |
1269
|
|
|
return false; |
1270
|
|
|
} |
1271
|
|
|
} else $altitude_real = 0; |
1272
|
|
|
|
1273
|
|
|
if ($heading != '') |
1274
|
|
|
{ |
1275
|
|
|
if (!is_numeric($heading)) |
1276
|
|
|
{ |
1277
|
|
|
return false; |
1278
|
|
|
} |
1279
|
|
|
} else $heading = 0; |
1280
|
|
|
|
1281
|
|
|
if ($groundspeed != '') |
1282
|
|
|
{ |
1283
|
|
|
if (!is_numeric($groundspeed)) |
1284
|
|
|
{ |
1285
|
|
|
return false; |
1286
|
|
|
} |
1287
|
|
|
} else $groundspeed = 0; |
1288
|
|
|
date_default_timezone_set('UTC'); |
1289
|
|
|
if ($date == '') $date = date("Y-m-d H:i:s", time()); |
1290
|
|
|
|
1291
|
|
|
|
1292
|
|
|
$flightaware_id = filter_var($flightaware_id,FILTER_SANITIZE_STRING); |
1293
|
|
|
$ident = filter_var($ident,FILTER_SANITIZE_STRING); |
1294
|
|
|
$aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
1295
|
|
|
$departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING); |
1296
|
|
|
$arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING); |
1297
|
|
|
$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
1298
|
|
|
$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
1299
|
|
|
$waypoints = filter_var($waypoints,FILTER_SANITIZE_STRING); |
1300
|
|
|
$altitude = filter_var($altitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
1301
|
|
|
$altitude_real = filter_var($altitude_real,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
1302
|
|
|
$heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT); |
1303
|
|
|
$groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
1304
|
|
|
$squawk = filter_var($squawk,FILTER_SANITIZE_NUMBER_INT); |
1305
|
|
|
$route_stop = filter_var($route_stop,FILTER_SANITIZE_STRING); |
1306
|
|
|
$ModeS = filter_var($ModeS,FILTER_SANITIZE_STRING); |
1307
|
|
|
$pilot_id = filter_var($pilot_id,FILTER_SANITIZE_STRING); |
1308
|
|
|
$pilot_name = filter_var($pilot_name,FILTER_SANITIZE_STRING); |
1309
|
|
|
$format_source = filter_var($format_source,FILTER_SANITIZE_STRING); |
1310
|
|
|
$source_name = filter_var($source_name,FILTER_SANITIZE_STRING); |
1311
|
|
|
$over_country = filter_var($over_country,FILTER_SANITIZE_STRING); |
1312
|
|
|
$verticalrate = filter_var($verticalrate,FILTER_SANITIZE_NUMBER_INT); |
1313
|
|
|
|
1314
|
|
|
$airline_name = ''; |
1315
|
|
|
$airline_icao = ''; |
1316
|
|
|
$airline_country = ''; |
1317
|
|
|
$airline_type = ''; |
1318
|
|
|
$aircraft_shadow = ''; |
1319
|
|
|
$aircraft_type = ''; |
1320
|
|
|
$aircraft_manufacturer = ''; |
1321
|
|
|
|
1322
|
|
|
|
1323
|
|
|
|
1324
|
|
|
$aircraft_name = ''; |
1325
|
|
|
$departure_airport_name = ''; |
1326
|
|
|
$departure_airport_city = ''; |
1327
|
|
|
$departure_airport_country = ''; |
1328
|
|
|
|
1329
|
|
|
$arrival_airport_name = ''; |
1330
|
|
|
$arrival_airport_city = ''; |
1331
|
|
|
$arrival_airport_country = ''; |
1332
|
|
|
|
1333
|
|
|
|
1334
|
|
|
if ($squawk == '' || $Common->isInteger($squawk) === false ) $squawk = NULL; |
1335
|
|
|
if ($verticalrate == '' || $Common->isInteger($verticalrate) === false ) $verticalrate = NULL; |
1336
|
|
|
if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0; |
1337
|
|
|
if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0; |
1338
|
|
|
|
1339
|
|
|
$query = ''; |
1340
|
|
|
if ($globalArchive) { |
1341
|
|
|
if ($globalDebug) echo '-- Delete previous data -- '; |
1342
|
|
|
$query .= 'DELETE FROM spotter_live WHERE flightaware_id = :flightaware_id;'; |
1343
|
|
|
} |
1344
|
|
|
|
1345
|
|
|
$query .= 'INSERT INTO spotter_live (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, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, latitude, longitude, waypoints, altitude, heading, ground_speed, date, departure_airport_time, arrival_airport_time, squawk, route_stop, ModeS, pilot_id, pilot_name, verticalrate, ground, format_source, source_name, over_country, real_altitude) |
1346
|
|
|
VALUES (:flightaware_id,:ident,:registration,:airline_name,:airline_icao,:airline_country,:airline_type,:aircraft_icao,:aircraft_shadow,:aircraft_type,:aircraft_manufacturer,:departure_airport_icao,:departure_airport_name, :departure_airport_city, :departure_airport_country, :arrival_airport_icao, :arrival_airport_name, :arrival_airport_city, :arrival_airport_country, :latitude,:longitude,:waypoints,:altitude,:heading,:groundspeed,:date,:departure_airport_time,:arrival_airport_time,:squawk,:route_stop,:ModeS, :pilot_id, :pilot_name, :verticalrate, :ground, :format_source, :source_name, :over_country, :real_altitude)'; |
1347
|
|
|
|
1348
|
|
|
$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_type' => $aircraft_type,':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,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_name' => $arrival_airport_name,':arrival_airport_city' => $arrival_airport_city,':arrival_airport_country' => $arrival_airport_country,':latitude' => $latitude,':longitude' => $longitude, ':waypoints' => $waypoints,':altitude' => $altitude,':heading' => $heading,':groundspeed' => $groundspeed,':date' => $date, ':departure_airport_time' => $departure_airport_time,':arrival_airport_time' => $arrival_airport_time, ':squawk' => $squawk,':route_stop' => $route_stop,':ModeS' => $ModeS, ':pilot_id' => $pilot_id, ':pilot_name' => $pilot_name, ':verticalrate' => $verticalrate, ':format_source' => $format_source,':ground' => $ground, ':source_name' => $source_name, ':over_country' => $over_country,':real_altitude' => $altitude_real); |
1349
|
|
|
try { |
1350
|
|
|
|
1351
|
|
|
$sth = $this->db->prepare($query); |
1352
|
|
|
$sth->execute($query_values); |
1353
|
|
|
$sth->closeCursor(); |
1354
|
|
|
} catch(PDOException $e) { |
1355
|
|
|
return "error : ".$e->getMessage(); |
1356
|
|
|
} |
1357
|
|
|
if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) { |
1358
|
|
|
if ($globalDebug) echo '(Add to Spotter archive : '; |
1359
|
|
|
$SpotterArchive = new SpotterArchive($this->db); |
1360
|
|
|
$result = $SpotterArchive->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, $altitude_real,$heading, $groundspeed, $squawk, $ModeS, $pilot_id, $pilot_name,$verticalrate,$format_source,$source_name, $over_country); |
1361
|
|
|
if ($globalDebug) echo $result.')'; |
1362
|
|
|
} elseif ($globalDebug && $putinarchive !== true) { |
1363
|
|
|
echo '(Not adding to archive)'; |
1364
|
|
|
} elseif ($globalDebug && $noarchive === true) { |
1365
|
|
|
echo '(No archive)'; |
1366
|
|
|
} |
1367
|
|
|
return "success"; |
1368
|
|
|
|
1369
|
|
|
} |
1370
|
|
|
|
1371
|
|
|
public function getOrderBy() |
1372
|
|
|
{ |
1373
|
|
|
$orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY spotter_live.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY spotter_live.aircraft_icao DESC"),"manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY spotter_live.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY spotter_live.aircraft_manufacturer DESC"),"airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY spotter_live.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY spotter_live.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY spotter_live.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY spotter_live.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY spotter_live.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY spotter_live.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY spotter_live.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY spotter_live.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY spotter_live.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY spotter_live.date DESC")); |
1374
|
|
|
return $orderby; |
1375
|
|
|
} |
1376
|
|
|
|
1377
|
|
|
} |
1378
|
|
|
|
1379
|
|
|
|
1380
|
|
|
?> |
1381
|
|
|
|
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: