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