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
|
|
|
} |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Get SQL query part for filter used |
16
|
|
|
* @param Array $filter the filter |
17
|
|
|
* @return Array 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] != '') { |
38
|
|
|
if (isset($flt['source'])) { |
39
|
|
|
$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"; |
40
|
|
|
} else { |
41
|
|
|
$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"; |
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_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"; |
48
|
|
|
} else { |
49
|
|
|
$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"; |
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_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"; |
55
|
|
|
} else { |
56
|
|
|
$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"; |
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_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"; |
62
|
|
|
} else { |
63
|
|
|
$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"; |
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['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_output WHERE spotter_output.format_source IN ('".implode("','",$flt['source'])."')) ssf ON ssf.flightaware_id = spotter_live.flightaware_id"; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
if (isset($filter['airlines']) && !empty($filter['airlines'])) { |
73
|
|
|
if ($filter['airlines'][0] != '') { |
74
|
|
|
$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"; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
if (isset($filter['alliance']) && !empty($filter['alliance'])) { |
78
|
|
|
$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 "; |
79
|
|
|
} |
80
|
|
|
if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) { |
81
|
|
|
$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 "; |
82
|
|
|
} |
83
|
|
|
if (isset($filter['pilots_id']) && !empty($filter['pilots_id'])) { |
84
|
|
|
$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"; |
85
|
|
|
} |
86
|
|
|
if (isset($filter['source']) && !empty($filter['source'])) { |
87
|
|
|
$filter_query_where .= " AND format_source IN ('".implode("','",$filter['source'])."')"; |
88
|
|
|
} |
89
|
|
|
if (isset($filter['ident']) && !empty($filter['ident'])) { |
90
|
|
|
$filter_query_where .= " AND ident = '".$filter['ident']."'"; |
91
|
|
|
} |
92
|
|
|
if ((isset($filter['year']) && $filter['year'] != '') || (isset($filter['month']) && $filter['month'] != '') || (isset($filter['day']) && $filter['day'] != '')) { |
93
|
|
|
$filter_query_date = ''; |
94
|
|
|
|
95
|
|
|
if (isset($filter['year']) && $filter['year'] != '') { |
96
|
|
|
if ($globalDBdriver == 'mysql') { |
97
|
|
|
$filter_query_date .= " AND YEAR(spotter_output.date) = '".$filter['year']."'"; |
98
|
|
|
} else { |
99
|
|
|
$filter_query_date .= " AND EXTRACT(YEAR FROM spotter_output.date) = '".$filter['year']."'"; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
if (isset($filter['month']) && $filter['month'] != '') { |
103
|
|
|
if ($globalDBdriver == 'mysql') { |
104
|
|
|
$filter_query_date .= " AND MONTH(spotter_output.date) = '".$filter['month']."'"; |
105
|
|
|
} else { |
106
|
|
|
$filter_query_date .= " AND EXTRACT(MONTH FROM spotter_output.date) = '".$filter['month']."'"; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
if (isset($filter['day']) && $filter['day'] != '') { |
110
|
|
|
if ($globalDBdriver == 'mysql') { |
111
|
|
|
$filter_query_date .= " AND DAY(spotter_output.date) = '".$filter['day']."'"; |
112
|
|
|
} else { |
113
|
|
|
$filter_query_date .= " AND EXTRACT(DAY FROM spotter_output.date) = '".$filter['day']."'"; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
$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"; |
117
|
|
|
} |
118
|
|
|
if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) { |
119
|
|
|
$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
120
|
|
|
} |
121
|
|
|
if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE'; |
122
|
|
|
elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND'; |
123
|
|
|
if ($filter_query_where != '') { |
124
|
|
|
$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where); |
125
|
|
|
} |
126
|
|
|
$filter_query = $filter_query_join.$filter_query_where; |
127
|
|
|
return $filter_query; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Gets all the spotter information based on the latest data entry |
132
|
|
|
* |
133
|
|
|
* @return Array the spotter information |
134
|
|
|
* |
135
|
|
|
*/ |
136
|
|
|
public function getLiveSpotterData($limit = '', $sort = '', $filter = array()) |
137
|
|
|
{ |
138
|
|
|
global $globalDBdriver, $globalLiveInterval; |
139
|
|
|
$Spotter = new Spotter($this->db); |
140
|
|
|
date_default_timezone_set('UTC'); |
141
|
|
|
|
142
|
|
|
$filter_query = $this->getFilter($filter); |
143
|
|
|
$limit_query = ''; |
144
|
|
|
if ($limit != '') |
145
|
|
|
{ |
146
|
|
|
$limit_array = explode(',', $limit); |
147
|
|
|
$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
148
|
|
|
$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
149
|
|
|
if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
150
|
|
|
{ |
151
|
|
|
$limit_query = ' LIMIT '.$limit_array[1].' OFFSET '.$limit_array[0]; |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
$orderby_query = ''; |
155
|
|
|
if ($sort != '') |
156
|
|
|
{ |
157
|
|
|
$search_orderby_array = $this->getOrderBy(); |
158
|
|
|
if (isset($search_orderby_array[$sort]['sql'])) |
159
|
|
|
{ |
160
|
|
|
$orderby_query = ' '.$search_orderby_array[$sort]['sql']; |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
165
|
|
|
if ($globalDBdriver == 'mysql') { |
166
|
|
|
//$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"; |
167
|
|
|
$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; |
168
|
|
|
} else { |
169
|
|
|
$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; |
170
|
|
|
} |
171
|
|
|
$spotter_array = $Spotter->getDataFromDB($query.$limit_query,array(),'',true); |
172
|
|
|
|
173
|
|
|
return $spotter_array; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Gets Minimal Live Spotter data |
178
|
|
|
* |
179
|
|
|
* @return Array the spotter information |
180
|
|
|
* |
181
|
|
|
*/ |
182
|
|
|
public function getMinLiveSpotterData($filter = array()) |
183
|
|
|
{ |
184
|
|
|
global $globalDBdriver, $globalLiveInterval; |
185
|
|
|
date_default_timezone_set('UTC'); |
186
|
|
|
|
187
|
|
|
$filter_query = $this->getFilter($filter,true,true); |
188
|
|
|
|
189
|
|
|
if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
190
|
|
|
if ($globalDBdriver == 'mysql') { |
191
|
|
|
// $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$orderby_query"; |
192
|
|
|
// $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, a.aircraft_shadow 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 INNER JOIN (SELECT * FROM aircraft) a on spotter_live.aircraft_icao = a.icao'; |
193
|
|
|
// $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 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; |
194
|
|
|
/* |
195
|
|
|
$query = 'SELECT a.aircraft_shadow, 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 |
196
|
|
|
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 LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao'.$filter_query." spotter_live.latitude <> 0 AND spotter_live.longitude <> 0"; |
197
|
|
|
*/ |
198
|
|
|
$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 |
199
|
|
|
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"; |
200
|
|
|
|
201
|
|
|
// $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 FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= spotter_live.date ORDER BY spotter_live.date GROUP BY spotter_live.flightaware_id'.$filter_query; |
202
|
|
|
|
203
|
|
|
//$query = 'SELECT a.aircraft_shadow, 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 FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date '.$filter_query.'LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao'; |
204
|
|
|
} else { |
205
|
|
|
//$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' - '30 SECONDS'->INTERVAL <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate"; |
206
|
|
|
//$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' - '".$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$orderby_query"; |
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.heading, spotter_live.ground_speed, spotter_live.squawk, a.aircraft_shadow 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.'INNER JOIN (SELECT * FROM aircraft) a on spotter_live.aircraft_icao = a.icao'; |
208
|
|
|
/* |
209
|
|
|
$query = "SELECT a.aircraft_shadow, 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 |
210
|
|
|
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 LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao".$filter_query." spotter_live.latitude <> '0' AND spotter_live.longitude <> '0'"; |
211
|
|
|
*/ |
212
|
|
|
|
213
|
|
|
$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 |
214
|
|
|
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'"; |
215
|
|
|
|
216
|
|
|
|
217
|
|
|
} |
218
|
|
|
// $spotter_array = Spotter->getDataFromDB($query.$limit_query); |
219
|
|
|
// echo $query; |
220
|
|
|
|
221
|
|
|
try { |
222
|
|
|
$sth = $this->db->prepare($query); |
223
|
|
|
$sth->execute(); |
224
|
|
|
} catch(PDOException $e) { |
225
|
|
|
echo $e->getMessage(); |
226
|
|
|
die; |
227
|
|
|
} |
228
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
229
|
|
|
|
230
|
|
|
return $spotter_array; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Gets Minimal Live Spotter data since xx seconds |
235
|
|
|
* |
236
|
|
|
* @return Array the spotter information |
237
|
|
|
* |
238
|
|
|
*/ |
239
|
|
|
public function getMinLastLiveSpotterData($filter = array()) |
240
|
|
|
{ |
241
|
|
|
global $globalDBdriver, $globalLiveInterval; |
242
|
|
|
date_default_timezone_set('UTC'); |
243
|
|
|
|
244
|
|
|
$filter_query = $this->getFilter($filter,true,true); |
245
|
|
|
|
246
|
|
|
if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
247
|
|
|
if ($globalDBdriver == 'mysql') { |
248
|
|
|
/* |
249
|
|
|
$query = 'SELECT a.aircraft_shadow, a.engine_type, a.engine_count, a.wake_category, 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 |
250
|
|
|
FROM spotter_live LEFT JOIN (SELECT aircraft_shadow,engine_type, engine_count, wake_category,icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= spotter_live.date AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' |
251
|
|
|
ORDER BY spotter_live.flightaware_id, spotter_live.date"; |
252
|
|
|
*/ |
253
|
|
|
$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 |
254
|
|
|
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' |
255
|
|
|
ORDER BY spotter_live.flightaware_id, spotter_live.date"; |
256
|
|
|
} else { |
257
|
|
|
/* |
258
|
|
|
$query = "SELECT a.aircraft_shadow, a.engine_type, a.engine_count, a.wake_category, 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 |
259
|
|
|
FROM spotter_live LEFT JOIN (SELECT aircraft_shadow,engine_type, engine_count, wake_category, icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' |
260
|
|
|
ORDER BY spotter_live.flightaware_id, spotter_live.date"; |
261
|
|
|
*/ |
262
|
|
|
$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 |
263
|
|
|
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' |
264
|
|
|
ORDER BY spotter_live.flightaware_id, spotter_live.date"; |
265
|
|
|
// echo $query; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
try { |
269
|
|
|
$sth = $this->db->prepare($query); |
270
|
|
|
$sth->execute(); |
271
|
|
|
} catch(PDOException $e) { |
272
|
|
|
echo $e->getMessage(); |
273
|
|
|
die; |
274
|
|
|
} |
275
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
276
|
|
|
return $spotter_array; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* Gets number of latest data entry |
281
|
|
|
* |
282
|
|
|
* @return String number of entry |
283
|
|
|
* |
284
|
|
|
*/ |
285
|
|
|
public function getLiveSpotterCount($filter = array()) |
286
|
|
|
{ |
287
|
|
|
global $globalDBdriver, $globalLiveInterval; |
288
|
|
|
$filter_query = $this->getFilter($filter,true,true); |
289
|
|
|
|
290
|
|
|
if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
291
|
|
|
if ($globalDBdriver == 'mysql') { |
292
|
|
|
//$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; |
293
|
|
|
$query = 'SELECT COUNT(DISTINCT spotter_live.flightaware_id) as nb FROM spotter_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date'; |
294
|
|
|
} else { |
295
|
|
|
//$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; |
296
|
|
|
$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"; |
297
|
|
|
} |
298
|
|
|
try { |
299
|
|
|
$sth = $this->db->prepare($query); |
300
|
|
|
$sth->execute(); |
301
|
|
|
} catch(PDOException $e) { |
302
|
|
|
echo $e->getMessage(); |
303
|
|
|
die; |
304
|
|
|
} |
305
|
|
|
$result = $sth->fetch(PDO::FETCH_ASSOC); |
306
|
|
|
$sth->closeCursor(); |
307
|
|
|
return $result['nb']; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* Gets all the spotter information based on the latest data entry and coord |
312
|
|
|
* |
313
|
|
|
* @return Array the spotter information |
314
|
|
|
* |
315
|
|
|
*/ |
316
|
|
|
public function getLiveSpotterDatabyCoord($coord, $filter = array()) |
317
|
|
|
{ |
318
|
|
|
global $globalDBdriver, $globalLiveInterval; |
319
|
|
|
$Spotter = new Spotter($this->db); |
320
|
|
|
if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
321
|
|
|
$filter_query = $this->getFilter($filter); |
322
|
|
|
|
323
|
|
|
if (is_array($coord)) { |
324
|
|
|
$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
325
|
|
|
$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
326
|
|
|
$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
327
|
|
|
$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
328
|
|
|
} else return array(); |
329
|
|
|
if ($globalDBdriver == 'mysql') { |
330
|
|
|
$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; |
331
|
|
|
} else { |
332
|
|
|
$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; |
333
|
|
|
|
334
|
|
|
} |
335
|
|
|
$spotter_array = $Spotter->getDataFromDB($query); |
336
|
|
|
return $spotter_array; |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
/** |
340
|
|
|
* Gets all the spotter information based on the latest data entry and coord |
341
|
|
|
* |
342
|
|
|
* @return Array the spotter information |
343
|
|
|
* |
344
|
|
|
*/ |
345
|
|
|
public function getMinLiveSpotterDatabyCoord($coord, $filter = array()) |
346
|
|
|
{ |
347
|
|
|
global $globalDBdriver, $globalLiveInterval; |
348
|
|
|
$Spotter = new Spotter($this->db); |
|
|
|
|
349
|
|
|
if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
350
|
|
|
$filter_query = $this->getFilter($filter,true,true); |
351
|
|
|
|
352
|
|
|
if (is_array($coord)) { |
353
|
|
|
$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
354
|
|
|
$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
355
|
|
|
$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
356
|
|
|
$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
357
|
|
|
} else return array(); |
358
|
|
|
if ($globalDBdriver == 'mysql') { |
359
|
|
|
$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 |
360
|
|
|
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 AND spotter_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND spotter_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.''; |
361
|
|
|
} else { |
362
|
|
|
$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 |
363
|
|
|
FROM spotter_live |
364
|
|
|
INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate |
365
|
|
|
FROM spotter_live l |
366
|
|
|
WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date |
367
|
|
|
AND l.latitude BETWEEN ".$minlat." AND ".$maxlat." |
368
|
|
|
AND l.longitude BETWEEN ".$minlong." AND ".$maxlong." |
369
|
|
|
GROUP BY l.flightaware_id |
370
|
|
|
) s on spotter_live.flightaware_id = s.flightaware_id |
371
|
|
|
AND spotter_live.date = s.maxdate".$filter_query." spotter_live.latitude <> '0' AND spotter_live.longitude <> '0'"; |
372
|
|
|
} |
373
|
|
|
try { |
374
|
|
|
$sth = $this->db->prepare($query); |
375
|
|
|
$sth->execute(); |
376
|
|
|
} catch(PDOException $e) { |
377
|
|
|
echo $e->getMessage(); |
378
|
|
|
die; |
379
|
|
|
} |
380
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
381
|
|
|
return $spotter_array; |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
/** |
385
|
|
|
* Gets all the spotter information based on a user's latitude and longitude |
386
|
|
|
* |
387
|
|
|
* @return Array the spotter information |
388
|
|
|
* |
389
|
|
|
*/ |
390
|
|
|
public function getLatestSpotterForLayar($lat, $lng, $radius, $interval) |
391
|
|
|
{ |
392
|
|
|
$Spotter = new Spotter($this->db); |
393
|
|
|
date_default_timezone_set('UTC'); |
394
|
|
|
if ($lat != '') { |
395
|
|
|
if (!is_numeric($lat)) { |
396
|
|
|
return false; |
|
|
|
|
397
|
|
|
} |
398
|
|
|
} |
399
|
|
|
if ($lng != '') |
400
|
|
|
{ |
401
|
|
|
if (!is_numeric($lng)) |
402
|
|
|
{ |
403
|
|
|
return false; |
|
|
|
|
404
|
|
|
} |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
if ($radius != '') |
408
|
|
|
{ |
409
|
|
|
if (!is_numeric($radius)) |
410
|
|
|
{ |
411
|
|
|
return false; |
|
|
|
|
412
|
|
|
} |
413
|
|
|
} |
414
|
|
|
$additional_query = ''; |
415
|
|
|
if ($interval != '') |
416
|
|
|
{ |
417
|
|
|
if (!is_string($interval)) |
418
|
|
|
{ |
419
|
|
|
//$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date '; |
420
|
|
|
return false; |
|
|
|
|
421
|
|
|
} else { |
422
|
|
|
if ($interval == '1m') |
423
|
|
|
{ |
424
|
|
|
$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date '; |
425
|
|
|
} else if ($interval == '15m'){ |
426
|
|
|
$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= spotter_live.date '; |
427
|
|
|
} |
428
|
|
|
} |
429
|
|
|
} else { |
430
|
|
|
$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date '; |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
$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 |
434
|
|
|
WHERE spotter_live.latitude <> '' |
435
|
|
|
AND spotter_live.longitude <> '' |
436
|
|
|
".$additional_query." |
437
|
|
|
HAVING distance < :radius |
438
|
|
|
ORDER BY distance"; |
439
|
|
|
|
440
|
|
|
$spotter_array = $Spotter->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius)); |
441
|
|
|
|
442
|
|
|
return $spotter_array; |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
|
446
|
|
|
/** |
447
|
|
|
* Gets all the spotter information based on a particular callsign |
448
|
|
|
* |
449
|
|
|
* @return Array the spotter information |
450
|
|
|
* |
451
|
|
|
*/ |
452
|
|
|
public function getLastLiveSpotterDataByIdent($ident) |
453
|
|
|
{ |
454
|
|
|
$Spotter = new Spotter($this->db); |
455
|
|
|
date_default_timezone_set('UTC'); |
456
|
|
|
|
457
|
|
|
$ident = filter_var($ident, FILTER_SANITIZE_STRING); |
458
|
|
|
$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'; |
459
|
|
|
|
460
|
|
|
$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident),'',true); |
461
|
|
|
|
462
|
|
|
return $spotter_array; |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
/** |
466
|
|
|
* Gets all the spotter information based on a particular callsign |
467
|
|
|
* |
468
|
|
|
* @return Array the spotter information |
469
|
|
|
* |
470
|
|
|
*/ |
471
|
|
|
public function getDateLiveSpotterDataByIdent($ident,$date) |
472
|
|
|
{ |
473
|
|
|
$Spotter = new Spotter($this->db); |
474
|
|
|
date_default_timezone_set('UTC'); |
475
|
|
|
|
476
|
|
|
$ident = filter_var($ident, FILTER_SANITIZE_STRING); |
477
|
|
|
$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'; |
478
|
|
|
|
479
|
|
|
$date = date('c',$date); |
480
|
|
|
$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident,':date' => $date)); |
481
|
|
|
|
482
|
|
|
return $spotter_array; |
483
|
|
|
} |
484
|
|
|
|
485
|
|
|
/** |
486
|
|
|
* Gets last spotter information based on a particular callsign |
487
|
|
|
* |
488
|
|
|
* @return Array the spotter information |
489
|
|
|
* |
490
|
|
|
*/ |
491
|
|
|
public function getLastLiveSpotterDataById($id) |
492
|
|
|
{ |
493
|
|
|
$Spotter = new Spotter($this->db); |
494
|
|
|
date_default_timezone_set('UTC'); |
495
|
|
|
|
496
|
|
|
$id = filter_var($id, FILTER_SANITIZE_STRING); |
497
|
|
|
$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'; |
498
|
|
|
|
499
|
|
|
$spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id),'',true); |
500
|
|
|
|
501
|
|
|
return $spotter_array; |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
/** |
505
|
|
|
* Gets last spotter information based on a particular callsign |
506
|
|
|
* |
507
|
|
|
* @return Array the spotter information |
508
|
|
|
* |
509
|
|
|
*/ |
510
|
|
|
public function getDateLiveSpotterDataById($id,$date) |
511
|
|
|
{ |
512
|
|
|
$Spotter = new Spotter($this->db); |
513
|
|
|
date_default_timezone_set('UTC'); |
514
|
|
|
|
515
|
|
|
$id = filter_var($id, FILTER_SANITIZE_STRING); |
516
|
|
|
$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'; |
517
|
|
|
$date = date('c',$date); |
518
|
|
|
$spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id,':date' => $date),'',true); |
519
|
|
|
|
520
|
|
|
return $spotter_array; |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
/** |
524
|
|
|
* Gets altitude information based on a particular callsign |
525
|
|
|
* |
526
|
|
|
* @return Array the spotter information |
527
|
|
|
* |
528
|
|
|
*/ |
529
|
|
|
public function getAltitudeLiveSpotterDataByIdent($ident) |
530
|
|
|
{ |
531
|
|
|
|
532
|
|
|
date_default_timezone_set('UTC'); |
533
|
|
|
|
534
|
|
|
$ident = filter_var($ident, FILTER_SANITIZE_STRING); |
535
|
|
|
$query = 'SELECT spotter_live.altitude, spotter_live.date FROM spotter_live WHERE spotter_live.ident = :ident'; |
536
|
|
|
|
537
|
|
|
try { |
538
|
|
|
|
539
|
|
|
$sth = $this->db->prepare($query); |
540
|
|
|
$sth->execute(array(':ident' => $ident)); |
541
|
|
|
} catch(PDOException $e) { |
542
|
|
|
echo $e->getMessage(); |
543
|
|
|
die; |
544
|
|
|
} |
545
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
546
|
|
|
|
547
|
|
|
return $spotter_array; |
548
|
|
|
} |
549
|
|
|
|
550
|
|
|
/** |
551
|
|
|
* Gets all the spotter information based on a particular id |
552
|
|
|
* |
553
|
|
|
* @return Array the spotter information |
554
|
|
|
* |
555
|
|
|
*/ |
556
|
|
|
public function getAllLiveSpotterDataById($id,$liveinterval = false) |
557
|
|
|
{ |
558
|
|
|
global $globalDBdriver, $globalLiveInterval; |
559
|
|
|
date_default_timezone_set('UTC'); |
560
|
|
|
$id = filter_var($id, FILTER_SANITIZE_STRING); |
561
|
|
|
//$query = self::$global_query.' WHERE spotter_live.flightaware_id = :id ORDER BY date'; |
562
|
|
|
if ($globalDBdriver == 'mysql') { |
563
|
|
|
$query = 'SELECT spotter_live.* FROM spotter_live WHERE spotter_live.flightaware_id = :id'; |
564
|
|
|
if ($liveinterval) $query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date'; |
565
|
|
|
$query .= ' ORDER BY date'; |
566
|
|
|
} else { |
567
|
|
|
$query = 'SELECT spotter_live.* FROM spotter_live WHERE spotter_live.flightaware_id = :id'; |
568
|
|
|
if ($liveinterval) $query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date"; |
569
|
|
|
$query .= ' ORDER BY date'; |
570
|
|
|
} |
571
|
|
|
|
572
|
|
|
try { |
573
|
|
|
$sth = $this->db->prepare($query); |
574
|
|
|
$sth->execute(array(':id' => $id)); |
575
|
|
|
} catch(PDOException $e) { |
576
|
|
|
echo $e->getMessage(); |
577
|
|
|
die; |
578
|
|
|
} |
579
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
580
|
|
|
return $spotter_array; |
581
|
|
|
} |
582
|
|
|
|
583
|
|
|
/** |
584
|
|
|
* Gets all the spotter information based on a particular ident |
585
|
|
|
* |
586
|
|
|
* @return Array the spotter information |
587
|
|
|
* |
588
|
|
|
*/ |
589
|
|
|
public function getAllLiveSpotterDataByIdent($ident) |
590
|
|
|
{ |
591
|
|
|
date_default_timezone_set('UTC'); |
592
|
|
|
$ident = filter_var($ident, FILTER_SANITIZE_STRING); |
593
|
|
|
$query = self::$global_query.' WHERE spotter_live.ident = :ident'; |
594
|
|
|
try { |
595
|
|
|
|
596
|
|
|
$sth = $this->db->prepare($query); |
597
|
|
|
$sth->execute(array(':ident' => $ident)); |
598
|
|
|
} catch(PDOException $e) { |
599
|
|
|
echo $e->getMessage(); |
600
|
|
|
die; |
601
|
|
|
} |
602
|
|
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
603
|
|
|
return $spotter_array; |
604
|
|
|
} |
605
|
|
|
|
606
|
|
|
|
607
|
|
|
/** |
608
|
|
|
* Deletes all info in the table |
609
|
|
|
* |
610
|
|
|
* @return String success or false |
611
|
|
|
* |
612
|
|
|
*/ |
613
|
|
|
public function deleteLiveSpotterData() |
614
|
|
|
{ |
615
|
|
|
global $globalDBdriver; |
616
|
|
|
if ($globalDBdriver == 'mysql') { |
617
|
|
|
//$query = "DELETE FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE) >= spotter_live.date"; |
618
|
|
|
$query = 'DELETE FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 9 HOUR) >= spotter_live.date'; |
619
|
|
|
//$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)"; |
620
|
|
|
} else { |
621
|
|
|
$query = "DELETE FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= spotter_live.date"; |
622
|
|
|
} |
623
|
|
|
|
624
|
|
|
try { |
625
|
|
|
|
626
|
|
|
$sth = $this->db->prepare($query); |
627
|
|
|
$sth->execute(); |
628
|
|
|
} catch(PDOException $e) { |
629
|
|
|
return "error"; |
630
|
|
|
} |
631
|
|
|
|
632
|
|
|
return "success"; |
633
|
|
|
} |
634
|
|
|
|
635
|
|
|
/** |
636
|
|
|
* Deletes all info in the table for aircraft not seen since 2 HOUR |
637
|
|
|
* |
638
|
|
|
* @return String success or false |
639
|
|
|
* |
640
|
|
|
*/ |
641
|
|
|
public function deleteLiveSpotterDataNotUpdated() |
642
|
|
|
{ |
643
|
|
|
global $globalDBdriver, $globalDebug; |
644
|
|
|
if ($globalDBdriver == 'mysql') { |
645
|
|
|
//$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'; |
646
|
|
|
$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 1200 OFFSET 0"; |
647
|
|
|
try { |
648
|
|
|
|
649
|
|
|
$sth = $this->db->prepare($query); |
650
|
|
|
$sth->execute(); |
651
|
|
|
} catch(PDOException $e) { |
652
|
|
|
return "error"; |
653
|
|
|
} |
654
|
|
|
$query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN ('; |
655
|
|
|
$i = 0; |
656
|
|
|
$j =0; |
657
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
658
|
|
|
foreach($all as $row) |
659
|
|
|
{ |
660
|
|
|
$i++; |
661
|
|
|
$j++; |
662
|
|
|
if ($j == 30) { |
663
|
|
|
if ($globalDebug) echo "."; |
664
|
|
|
try { |
665
|
|
|
|
666
|
|
|
$sth = $this->db->prepare(substr($query_delete,0,-1).")"); |
667
|
|
|
$sth->execute(); |
668
|
|
|
} catch(PDOException $e) { |
669
|
|
|
return "error"; |
670
|
|
|
} |
671
|
|
|
$query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN ('; |
672
|
|
|
$j = 0; |
673
|
|
|
} |
674
|
|
|
$query_delete .= "'".$row['flightaware_id']."',"; |
675
|
|
|
} |
676
|
|
|
if ($i > 0) { |
677
|
|
|
try { |
678
|
|
|
|
679
|
|
|
$sth = $this->db->prepare(substr($query_delete,0,-1).")"); |
680
|
|
|
$sth->execute(); |
681
|
|
|
} catch(PDOException $e) { |
682
|
|
|
return "error"; |
683
|
|
|
} |
684
|
|
|
} |
685
|
|
|
return "success"; |
686
|
|
|
} elseif ($globalDBdriver == 'pgsql') { |
687
|
|
|
//$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"; |
688
|
|
|
//$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"; |
689
|
|
|
$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 800 OFFSET 0)"; |
690
|
|
|
try { |
691
|
|
|
|
692
|
|
|
$sth = $this->db->prepare($query); |
693
|
|
|
$sth->execute(); |
694
|
|
|
} catch(PDOException $e) { |
695
|
|
|
return "error"; |
696
|
|
|
} |
697
|
|
|
/* $query_delete = "DELETE FROM spotter_live WHERE flightaware_id IN ("; |
698
|
|
|
$i = 0; |
699
|
|
|
$j =0; |
700
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
701
|
|
|
foreach($all as $row) |
702
|
|
|
{ |
703
|
|
|
$i++; |
704
|
|
|
$j++; |
705
|
|
|
if ($j == 100) { |
706
|
|
|
if ($globalDebug) echo "."; |
707
|
|
|
try { |
708
|
|
|
|
709
|
|
|
$sth = $this->db->query(substr($query_delete,0,-1).")"); |
710
|
|
|
//$sth->execute(); |
711
|
|
|
} catch(PDOException $e) { |
712
|
|
|
return "error"; |
713
|
|
|
} |
714
|
|
|
$query_delete = "DELETE FROM spotter_live WHERE flightaware_id IN ("; |
715
|
|
|
$j = 0; |
716
|
|
|
} |
717
|
|
|
$query_delete .= "'".$row['flightaware_id']."',"; |
718
|
|
|
} |
719
|
|
|
if ($i > 0) { |
720
|
|
|
try { |
721
|
|
|
|
722
|
|
|
$sth = $this->db->query(substr($query_delete,0,-1).")"); |
723
|
|
|
//$sth->execute(); |
724
|
|
|
} catch(PDOException $e) { |
725
|
|
|
return "error"; |
726
|
|
|
} |
727
|
|
|
} |
728
|
|
|
*/ |
729
|
|
|
return "success"; |
730
|
|
|
} |
731
|
|
|
} |
732
|
|
|
|
733
|
|
|
/** |
734
|
|
|
* Deletes all info in the table for an ident |
735
|
|
|
* |
736
|
|
|
* @return String success or false |
737
|
|
|
* |
738
|
|
|
*/ |
739
|
|
|
public function deleteLiveSpotterDataByIdent($ident) |
740
|
|
|
{ |
741
|
|
|
$ident = filter_var($ident, FILTER_SANITIZE_STRING); |
742
|
|
|
$query = 'DELETE FROM spotter_live WHERE ident = :ident'; |
743
|
|
|
|
744
|
|
|
try { |
745
|
|
|
|
746
|
|
|
$sth = $this->db->prepare($query); |
747
|
|
|
$sth->execute(array(':ident' => $ident)); |
748
|
|
|
} catch(PDOException $e) { |
749
|
|
|
return "error"; |
750
|
|
|
} |
751
|
|
|
|
752
|
|
|
return "success"; |
753
|
|
|
} |
754
|
|
|
|
755
|
|
|
/** |
756
|
|
|
* Deletes all info in the table for an id |
757
|
|
|
* |
758
|
|
|
* @return String success or false |
759
|
|
|
* |
760
|
|
|
*/ |
761
|
|
|
public function deleteLiveSpotterDataById($id) |
762
|
|
|
{ |
763
|
|
|
$id = filter_var($id, FILTER_SANITIZE_STRING); |
764
|
|
|
$query = 'DELETE FROM spotter_live WHERE flightaware_id = :id'; |
765
|
|
|
|
766
|
|
|
try { |
767
|
|
|
|
768
|
|
|
$sth = $this->db->prepare($query); |
769
|
|
|
$sth->execute(array(':id' => $id)); |
770
|
|
|
} catch(PDOException $e) { |
771
|
|
|
return "error"; |
772
|
|
|
} |
773
|
|
|
|
774
|
|
|
return "success"; |
775
|
|
|
} |
776
|
|
|
|
777
|
|
|
|
778
|
|
|
/** |
779
|
|
|
* Gets the aircraft ident within the last hour |
780
|
|
|
* |
781
|
|
|
* @return String the ident |
782
|
|
|
* |
783
|
|
|
*/ |
784
|
|
|
public function getIdentFromLastHour($ident) |
785
|
|
|
{ |
786
|
|
|
global $globalDBdriver, $globalTimezone; |
787
|
|
|
if ($globalDBdriver == 'mysql') { |
788
|
|
|
$query = 'SELECT spotter_live.ident FROM spotter_live |
789
|
|
|
WHERE spotter_live.ident = :ident |
790
|
|
|
AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) |
791
|
|
|
AND spotter_live.date < UTC_TIMESTAMP()'; |
792
|
|
|
$query_data = array(':ident' => $ident); |
793
|
|
|
} else { |
794
|
|
|
$query = "SELECT spotter_live.ident FROM spotter_live |
795
|
|
|
WHERE spotter_live.ident = :ident |
796
|
|
|
AND spotter_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS' |
797
|
|
|
AND spotter_live.date < now() AT TIME ZONE 'UTC'"; |
798
|
|
|
$query_data = array(':ident' => $ident); |
799
|
|
|
} |
800
|
|
|
|
801
|
|
|
$sth = $this->db->prepare($query); |
802
|
|
|
$sth->execute($query_data); |
803
|
|
|
$ident_result=''; |
804
|
|
|
while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
805
|
|
|
{ |
806
|
|
|
$ident_result = $row['ident']; |
807
|
|
|
} |
808
|
|
|
return $ident_result; |
809
|
|
|
} |
810
|
|
|
|
811
|
|
|
/** |
812
|
|
|
* Check recent aircraft |
813
|
|
|
* |
814
|
|
|
* @return String the ident |
815
|
|
|
* |
816
|
|
|
*/ |
817
|
|
|
public function checkIdentRecent($ident) |
818
|
|
|
{ |
819
|
|
|
global $globalDBdriver, $globalTimezone; |
820
|
|
|
if ($globalDBdriver == 'mysql') { |
821
|
|
|
$query = 'SELECT spotter_live.ident, spotter_live.flightaware_id FROM spotter_live |
822
|
|
|
WHERE spotter_live.ident = :ident |
823
|
|
|
AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE)'; |
824
|
|
|
// AND spotter_live.date < UTC_TIMESTAMP()"; |
825
|
|
|
$query_data = array(':ident' => $ident); |
826
|
|
|
} else { |
827
|
|
|
$query = "SELECT spotter_live.ident, spotter_live.flightaware_id FROM spotter_live |
828
|
|
|
WHERE spotter_live.ident = :ident |
829
|
|
|
AND spotter_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '30 MINUTES'"; |
830
|
|
|
// AND spotter_live.date < now() AT TIME ZONE 'UTC'"; |
831
|
|
|
$query_data = array(':ident' => $ident); |
832
|
|
|
} |
833
|
|
|
|
834
|
|
|
$sth = $this->db->prepare($query); |
835
|
|
|
$sth->execute($query_data); |
836
|
|
|
$ident_result=''; |
837
|
|
|
while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
838
|
|
|
{ |
839
|
|
|
$ident_result = $row['flightaware_id']; |
840
|
|
|
} |
841
|
|
|
return $ident_result; |
842
|
|
|
} |
843
|
|
|
|
844
|
|
|
/** |
845
|
|
|
* Check recent aircraft by id |
846
|
|
|
* |
847
|
|
|
* @return String the ident |
848
|
|
|
* |
849
|
|
|
*/ |
850
|
|
|
public function checkIdRecent($id) |
851
|
|
|
{ |
852
|
|
|
global $globalDBdriver, $globalTimezone; |
853
|
|
|
if ($globalDBdriver == 'mysql') { |
854
|
|
|
$query = 'SELECT spotter_live.ident, spotter_live.flightaware_id FROM spotter_live |
855
|
|
|
WHERE spotter_live.flightaware_id = :id |
856
|
|
|
AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 10 HOUR)'; |
857
|
|
|
// AND spotter_live.date < UTC_TIMESTAMP()"; |
858
|
|
|
$query_data = array(':id' => $id); |
859
|
|
|
} else { |
860
|
|
|
$query = "SELECT spotter_live.ident, spotter_live.flightaware_id FROM spotter_live |
861
|
|
|
WHERE spotter_live.flightaware_id = :id |
862
|
|
|
AND spotter_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '10 HOUR'"; |
863
|
|
|
// AND spotter_live.date < now() AT TIME ZONE 'UTC'"; |
864
|
|
|
$query_data = array(':id' => $id); |
865
|
|
|
} |
866
|
|
|
|
867
|
|
|
$sth = $this->db->prepare($query); |
868
|
|
|
$sth->execute($query_data); |
869
|
|
|
$ident_result=''; |
870
|
|
|
while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
871
|
|
|
{ |
872
|
|
|
$ident_result = $row['flightaware_id']; |
873
|
|
|
} |
874
|
|
|
return $ident_result; |
875
|
|
|
} |
876
|
|
|
|
877
|
|
|
/** |
878
|
|
|
* Check recent aircraft by ModeS |
879
|
|
|
* |
880
|
|
|
* @return String the ModeS |
881
|
|
|
* |
882
|
|
|
*/ |
883
|
|
|
public function checkModeSRecent($modes) |
884
|
|
|
{ |
885
|
|
|
global $globalDBdriver, $globalTimezone; |
886
|
|
|
if ($globalDBdriver == 'mysql') { |
887
|
|
|
$query = 'SELECT spotter_live.ModeS, spotter_live.flightaware_id FROM spotter_live |
888
|
|
|
WHERE spotter_live.ModeS = :modes |
889
|
|
|
AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE)'; |
890
|
|
|
// AND spotter_live.date < UTC_TIMESTAMP()"; |
891
|
|
|
$query_data = array(':modes' => $modes); |
892
|
|
|
} else { |
893
|
|
|
$query = "SELECT spotter_live.ModeS, spotter_live.flightaware_id FROM spotter_live |
894
|
|
|
WHERE spotter_live.ModeS = :modes |
895
|
|
|
AND spotter_live.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '30 MINUTE'"; |
896
|
|
|
// // AND spotter_live.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'"; |
897
|
|
|
$query_data = array(':modes' => $modes); |
898
|
|
|
} |
899
|
|
|
|
900
|
|
|
$sth = $this->db->prepare($query); |
901
|
|
|
$sth->execute($query_data); |
902
|
|
|
$ident_result=''; |
903
|
|
|
while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
904
|
|
|
{ |
905
|
|
|
//$ident_result = $row['spotter_live_id']; |
906
|
|
|
$ident_result = $row['flightaware_id']; |
907
|
|
|
} |
908
|
|
|
return $ident_result; |
909
|
|
|
} |
910
|
|
|
|
911
|
|
|
/** |
912
|
|
|
* Adds a new spotter data |
913
|
|
|
* |
914
|
|
|
* @param String $flightaware_id the ID from flightaware |
915
|
|
|
* @param String $ident the flight ident |
916
|
|
|
* @param String $aircraft_icao the aircraft type |
917
|
|
|
* @param String $departure_airport_icao the departure airport |
918
|
|
|
* @param String $arrival_airport_icao the arrival airport |
919
|
|
|
* @return String success or false |
920
|
|
|
* |
921
|
|
|
*/ |
922
|
|
|
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 = '') |
|
|
|
|
923
|
|
|
{ |
924
|
|
|
global $globalURL, $globalArchive, $globalDebug; |
925
|
|
|
$Common = new Common(); |
926
|
|
|
date_default_timezone_set('UTC'); |
927
|
|
|
|
928
|
|
|
//getting the airline information |
929
|
|
|
if ($ident != '') |
930
|
|
|
{ |
931
|
|
|
if (!is_string($ident)) |
932
|
|
|
{ |
933
|
|
|
return false; |
934
|
|
|
} |
935
|
|
|
} |
936
|
|
|
|
937
|
|
|
//getting the aircraft information |
938
|
|
|
if ($aircraft_icao != '') |
939
|
|
|
{ |
940
|
|
|
if (!is_string($aircraft_icao)) |
941
|
|
|
{ |
942
|
|
|
return false; |
943
|
|
|
} |
944
|
|
|
} |
945
|
|
|
//getting the departure airport information |
946
|
|
|
if ($departure_airport_icao != '') |
947
|
|
|
{ |
948
|
|
|
if (!is_string($departure_airport_icao)) |
949
|
|
|
{ |
950
|
|
|
return false; |
951
|
|
|
} |
952
|
|
|
} |
953
|
|
|
|
954
|
|
|
//getting the arrival airport information |
955
|
|
|
if ($arrival_airport_icao != '') |
956
|
|
|
{ |
957
|
|
|
if (!is_string($arrival_airport_icao)) |
958
|
|
|
{ |
959
|
|
|
return false; |
960
|
|
|
} |
961
|
|
|
} |
962
|
|
|
|
963
|
|
|
|
964
|
|
|
if ($latitude != '') |
965
|
|
|
{ |
966
|
|
|
if (!is_numeric($latitude)) |
967
|
|
|
{ |
968
|
|
|
return false; |
969
|
|
|
} |
970
|
|
|
} else return ''; |
971
|
|
|
|
972
|
|
|
if ($longitude != '') |
973
|
|
|
{ |
974
|
|
|
if (!is_numeric($longitude)) |
975
|
|
|
{ |
976
|
|
|
return false; |
977
|
|
|
} |
978
|
|
|
} else return ''; |
979
|
|
|
|
980
|
|
|
if ($waypoints != '') |
981
|
|
|
{ |
982
|
|
|
if (!is_string($waypoints)) |
983
|
|
|
{ |
984
|
|
|
return false; |
985
|
|
|
} |
986
|
|
|
} |
987
|
|
|
|
988
|
|
|
if ($altitude != '') |
989
|
|
|
{ |
990
|
|
|
if (!is_numeric($altitude)) |
991
|
|
|
{ |
992
|
|
|
return false; |
993
|
|
|
} |
994
|
|
|
} else $altitude = 0; |
995
|
|
|
|
996
|
|
|
if ($heading != '') |
997
|
|
|
{ |
998
|
|
|
if (!is_numeric($heading)) |
999
|
|
|
{ |
1000
|
|
|
return false; |
1001
|
|
|
} |
1002
|
|
|
} else $heading = 0; |
1003
|
|
|
|
1004
|
|
|
if ($groundspeed != '') |
1005
|
|
|
{ |
1006
|
|
|
if (!is_numeric($groundspeed)) |
1007
|
|
|
{ |
1008
|
|
|
return false; |
1009
|
|
|
} |
1010
|
|
|
} else $groundspeed = 0; |
1011
|
|
|
date_default_timezone_set('UTC'); |
1012
|
|
|
if ($date == '') $date = date("Y-m-d H:i:s", time()); |
1013
|
|
|
|
1014
|
|
|
|
1015
|
|
|
$flightaware_id = filter_var($flightaware_id,FILTER_SANITIZE_STRING); |
1016
|
|
|
$ident = filter_var($ident,FILTER_SANITIZE_STRING); |
1017
|
|
|
$aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING); |
1018
|
|
|
$departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING); |
1019
|
|
|
$arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING); |
1020
|
|
|
$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
1021
|
|
|
$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
1022
|
|
|
$waypoints = filter_var($waypoints,FILTER_SANITIZE_STRING); |
1023
|
|
|
$altitude = filter_var($altitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
1024
|
|
|
$heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT); |
1025
|
|
|
$groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
1026
|
|
|
$squawk = filter_var($squawk,FILTER_SANITIZE_NUMBER_INT); |
1027
|
|
|
$route_stop = filter_var($route_stop,FILTER_SANITIZE_STRING); |
1028
|
|
|
$ModeS = filter_var($ModeS,FILTER_SANITIZE_STRING); |
1029
|
|
|
$pilot_id = filter_var($pilot_id,FILTER_SANITIZE_STRING); |
1030
|
|
|
$pilot_name = filter_var($pilot_name,FILTER_SANITIZE_STRING); |
1031
|
|
|
$format_source = filter_var($format_source,FILTER_SANITIZE_STRING); |
1032
|
|
|
$source_name = filter_var($source_name,FILTER_SANITIZE_STRING); |
1033
|
|
|
$over_country = filter_var($over_country,FILTER_SANITIZE_STRING); |
1034
|
|
|
$verticalrate = filter_var($verticalrate,FILTER_SANITIZE_NUMBER_INT); |
1035
|
|
|
|
1036
|
|
|
$airline_name = ''; |
1037
|
|
|
$airline_icao = ''; |
1038
|
|
|
$airline_country = ''; |
1039
|
|
|
$airline_type = ''; |
1040
|
|
|
$aircraft_shadow = ''; |
1041
|
|
|
$aircraft_type = ''; |
1042
|
|
|
$aircraft_manufacturer = ''; |
1043
|
|
|
|
1044
|
|
|
|
1045
|
|
|
|
1046
|
|
|
$aircraft_name = ''; |
1047
|
|
|
$departure_airport_name = ''; |
1048
|
|
|
$departure_airport_city = ''; |
1049
|
|
|
$departure_airport_country = ''; |
1050
|
|
|
|
1051
|
|
|
$arrival_airport_name = ''; |
1052
|
|
|
$arrival_airport_city = ''; |
1053
|
|
|
$arrival_airport_country = ''; |
1054
|
|
|
|
1055
|
|
|
|
1056
|
|
|
if ($squawk == '' || $Common->isInteger($squawk) === false ) $squawk = NULL; |
1057
|
|
|
if ($verticalrate == '' || $Common->isInteger($verticalrate) === false ) $verticalrate = NULL; |
1058
|
|
|
if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0; |
1059
|
|
|
if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0; |
1060
|
|
|
|
1061
|
|
|
$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) |
1062
|
|
|
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)'; |
1063
|
|
|
|
1064
|
|
|
$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); |
1065
|
|
|
try { |
1066
|
|
|
|
1067
|
|
|
$sth = $this->db->prepare($query); |
1068
|
|
|
$sth->execute($query_values); |
1069
|
|
|
} catch(PDOException $e) { |
1070
|
|
|
return "error : ".$e->getMessage(); |
1071
|
|
|
} |
1072
|
|
|
if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) { |
1073
|
|
|
if ($globalDebug) echo '(Add to SBS archive : '; |
1074
|
|
|
$SpotterArchive = new SpotterArchive($this->db); |
1075
|
|
|
$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, $heading, $groundspeed, $squawk, $ModeS, $pilot_id, $pilot_name,$verticalrate,$format_source,$source_name, $over_country); |
1076
|
|
|
if ($globalDebug) echo $result.')'; |
1077
|
|
|
} |
1078
|
|
|
return "success"; |
1079
|
|
|
|
1080
|
|
|
} |
1081
|
|
|
|
1082
|
|
|
public function getOrderBy() |
1083
|
|
|
{ |
1084
|
|
|
$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")); |
1085
|
|
|
return $orderby; |
1086
|
|
|
} |
1087
|
|
|
|
1088
|
|
|
} |
1089
|
|
|
|
1090
|
|
|
|
1091
|
|
|
?> |
1092
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.