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