|
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
|
|
|
* @return array the spotter information |
|
283
|
|
|
* |
|
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, $globalLiveInterval; |
|
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, $globalLiveInterval; |
|
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
|
|
|
} |
|
964
|
|
|
|
|
965
|
|
|
/** |
|
966
|
|
|
* Gets all the spotter information based on the callsign |
|
967
|
|
|
* |
|
968
|
|
|
* @param string $ident |
|
969
|
|
|
* @param string $limit |
|
970
|
|
|
* @param string $sort |
|
971
|
|
|
* @return array the spotter information |
|
972
|
|
|
*/ |
|
973
|
|
|
public function getMarineDataByIdent($ident = '', $limit = '', $sort = '') |
|
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
|
|
|
|
|
984
|
|
|
if ($ident != "") |
|
985
|
|
|
{ |
|
986
|
|
|
if (!is_string($ident)) |
|
987
|
|
|
{ |
|
988
|
|
|
return false; |
|
989
|
|
|
} else { |
|
990
|
|
|
$additional_query = " AND (marine_archive_output.ident = :ident)"; |
|
991
|
|
|
$query_values = array(':ident' => $ident); |
|
992
|
|
|
} |
|
993
|
|
|
} |
|
994
|
|
|
|
|
995
|
|
|
if ($limit != "") |
|
996
|
|
|
{ |
|
997
|
|
|
$limit_array = explode(",", $limit); |
|
998
|
|
|
|
|
999
|
|
|
$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
|
1000
|
|
|
$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
|
1001
|
|
|
|
|
1002
|
|
|
if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
|
1003
|
|
|
{ |
|
1004
|
|
|
//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
|
1005
|
|
|
$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
|
1006
|
|
|
} |
|
1007
|
|
|
} |
|
1008
|
|
|
|
|
1009
|
|
|
if ($sort != "") |
|
1010
|
|
|
{ |
|
1011
|
|
|
$search_orderby_array = $Marine->getOrderBy(); |
|
1012
|
|
|
$orderby_query = $search_orderby_array[$sort]['sql']; |
|
1013
|
|
|
} else { |
|
1014
|
|
|
$orderby_query = " ORDER BY marine_archive_output.date DESC"; |
|
1015
|
|
|
} |
|
1016
|
|
|
|
|
1017
|
|
|
$query = $global_query." WHERE marine_archive_output.ident <> '' ".$additional_query." ".$orderby_query; |
|
1018
|
|
|
|
|
1019
|
|
|
$spotter_array = $Marine->getDataFromDB($query, $query_values, $limit_query); |
|
1020
|
|
|
|
|
1021
|
|
|
return $spotter_array; |
|
1022
|
|
|
} |
|
1023
|
|
|
|
|
1024
|
|
|
|
|
1025
|
|
|
/** |
|
1026
|
|
|
* Gets all the spotter information based on the owner |
|
1027
|
|
|
* |
|
1028
|
|
|
* @param string $owner |
|
1029
|
|
|
* @param string $limit |
|
1030
|
|
|
* @param string $sort |
|
1031
|
|
|
* @param array $filter |
|
1032
|
|
|
* @return array the spotter information |
|
1033
|
|
|
*/ |
|
1034
|
|
|
public function getMarineDataByOwner($owner = '', $limit = '', $sort = '', $filter = array()) |
|
1035
|
|
|
{ |
|
1036
|
|
|
$global_query = "SELECT marine_archive_output.* FROM marine_archive_output"; |
|
1037
|
|
|
|
|
1038
|
|
|
date_default_timezone_set('UTC'); |
|
1039
|
|
|
$Marine = new Marine($this->db); |
|
1040
|
|
|
|
|
1041
|
|
|
$query_values = array(); |
|
1042
|
|
|
$limit_query = ''; |
|
1043
|
|
|
$additional_query = ''; |
|
1044
|
|
|
$filter_query = $this->getFilter($filter,true,true); |
|
1045
|
|
|
|
|
1046
|
|
|
if ($owner != "") |
|
1047
|
|
|
{ |
|
1048
|
|
|
if (!is_string($owner)) |
|
1049
|
|
|
{ |
|
1050
|
|
|
return array(); |
|
1051
|
|
|
} else { |
|
1052
|
|
|
$additional_query = " AND (marine_archive_output.owner_name = :owner)"; |
|
1053
|
|
|
$query_values = array(':owner' => $owner); |
|
1054
|
|
|
} |
|
1055
|
|
|
} |
|
1056
|
|
|
|
|
1057
|
|
|
if ($limit != "") |
|
1058
|
|
|
{ |
|
1059
|
|
|
$limit_array = explode(",", $limit); |
|
1060
|
|
|
|
|
1061
|
|
|
$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
|
1062
|
|
|
$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
|
1063
|
|
|
|
|
1064
|
|
|
if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
|
1065
|
|
|
{ |
|
1066
|
|
|
//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
|
1067
|
|
|
$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
|
1068
|
|
|
} |
|
1069
|
|
|
} |
|
1070
|
|
|
|
|
1071
|
|
|
if ($sort != "") |
|
1072
|
|
|
{ |
|
1073
|
|
|
$search_orderby_array = $Marine->getOrderBy(); |
|
1074
|
|
|
$orderby_query = $search_orderby_array[$sort]['sql']; |
|
1075
|
|
|
} else { |
|
1076
|
|
|
$orderby_query = " ORDER BY marine_archive_output.date DESC"; |
|
1077
|
|
|
} |
|
1078
|
|
|
|
|
1079
|
|
|
$query = $global_query.$filter_query." marine_archive_output.owner_name <> '' ".$additional_query." ".$orderby_query; |
|
1080
|
|
|
|
|
1081
|
|
|
$spotter_array = $Marine->getDataFromDB($query, $query_values, $limit_query); |
|
1082
|
|
|
|
|
1083
|
|
|
return $spotter_array; |
|
1084
|
|
|
} |
|
1085
|
|
|
|
|
1086
|
|
|
/** |
|
1087
|
|
|
* Gets all the spotter information based on the pilot |
|
1088
|
|
|
* |
|
1089
|
|
|
* @param string $pilot |
|
1090
|
|
|
* @param string $limit |
|
1091
|
|
|
* @param string $sort |
|
1092
|
|
|
* @param array $filter |
|
1093
|
|
|
* @return array the spotter information |
|
1094
|
|
|
*/ |
|
1095
|
|
|
public function getMarineDataByPilot($pilot = '', $limit = '', $sort = '', $filter = array()) |
|
1096
|
|
|
{ |
|
1097
|
|
|
$global_query = "SELECT marine_archive_output.* FROM marine_archive_output"; |
|
1098
|
|
|
|
|
1099
|
|
|
date_default_timezone_set('UTC'); |
|
1100
|
|
|
$Marine = new Marine($this->db); |
|
1101
|
|
|
|
|
1102
|
|
|
$query_values = array(); |
|
1103
|
|
|
$limit_query = ''; |
|
1104
|
|
|
$additional_query = ''; |
|
1105
|
|
|
$filter_query = $this->getFilter($filter,true,true); |
|
1106
|
|
|
|
|
1107
|
|
|
if ($pilot != "") |
|
1108
|
|
|
{ |
|
1109
|
|
|
$additional_query = " AND (marine_archive_output.pilot_id = :pilot OR marine_archive_output.pilot_name = :pilot)"; |
|
1110
|
|
|
$query_values = array(':pilot' => $pilot); |
|
1111
|
|
|
} |
|
1112
|
|
|
|
|
1113
|
|
|
if ($limit != "") |
|
1114
|
|
|
{ |
|
1115
|
|
|
$limit_array = explode(",", $limit); |
|
1116
|
|
|
|
|
1117
|
|
|
$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
|
1118
|
|
|
$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
|
1119
|
|
|
|
|
1120
|
|
|
if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
|
1121
|
|
|
{ |
|
1122
|
|
|
//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
|
1123
|
|
|
$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
|
1124
|
|
|
} |
|
1125
|
|
|
} |
|
1126
|
|
|
|
|
1127
|
|
|
if ($sort != "") |
|
1128
|
|
|
{ |
|
1129
|
|
|
$search_orderby_array = $Marine->getOrderBy(); |
|
1130
|
|
|
$orderby_query = $search_orderby_array[$sort]['sql']; |
|
1131
|
|
|
} else { |
|
1132
|
|
|
$orderby_query = " ORDER BY marine_archive_output.date DESC"; |
|
1133
|
|
|
} |
|
1134
|
|
|
|
|
1135
|
|
|
$query = $global_query.$filter_query." marine_archive_output.pilot_name <> '' ".$additional_query." ".$orderby_query; |
|
1136
|
|
|
|
|
1137
|
|
|
$spotter_array = $Marine->getDataFromDB($query, $query_values, $limit_query); |
|
1138
|
|
|
|
|
1139
|
|
|
return $spotter_array; |
|
1140
|
|
|
} |
|
1141
|
|
|
|
|
1142
|
|
|
/** |
|
1143
|
|
|
* Gets all number of flight over countries |
|
1144
|
|
|
* |
|
1145
|
|
|
* @param bool $limit |
|
1146
|
|
|
* @param int $olderthanmonths |
|
1147
|
|
|
* @param string $sincedate |
|
1148
|
|
|
* @return array the airline country list |
|
1149
|
|
|
*/ |
|
1150
|
|
|
public function countAllFlightOverCountries($limit = true,$olderthanmonths = 0,$sincedate = '') |
|
1151
|
|
|
{ |
|
1152
|
|
|
global $globalDBdriver; |
|
1153
|
|
|
/* |
|
1154
|
|
|
$query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb |
|
1155
|
|
|
FROM countries c, marine_archive s |
|
1156
|
|
|
WHERE Within(GeomFromText(CONCAT('POINT(',s.longitude,' ',s.latitude,')')), ogc_geom) "; |
|
1157
|
|
|
*/ |
|
1158
|
|
|
$query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb |
|
1159
|
|
|
FROM countries c, marine_archive s |
|
1160
|
|
|
WHERE c.iso2 = s.over_country "; |
|
1161
|
|
|
if ($olderthanmonths > 0) { |
|
1162
|
|
|
if ($globalDBdriver == 'mysql') { |
|
1163
|
|
|
$query .= 'AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) '; |
|
1164
|
|
|
} else { |
|
1165
|
|
|
$query .= "AND date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
|
1166
|
|
|
} |
|
1167
|
|
|
} |
|
1168
|
|
|
if ($sincedate != '') $query .= "AND date > '".$sincedate."' "; |
|
1169
|
|
|
$query .= "GROUP BY c.name, c.iso3, c.iso2 ORDER BY nb DESC"; |
|
1170
|
|
|
if ($limit) $query .= " LIMIT 0,10"; |
|
1171
|
|
|
|
|
1172
|
|
|
|
|
1173
|
|
|
$sth = $this->db->prepare($query); |
|
1174
|
|
|
$sth->execute(); |
|
1175
|
|
|
|
|
1176
|
|
|
$flight_array = array(); |
|
1177
|
|
|
$temp_array = array(); |
|
1178
|
|
|
|
|
1179
|
|
|
while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
|
1180
|
|
|
{ |
|
1181
|
|
|
$temp_array['flight_count'] = $row['nb']; |
|
1182
|
|
|
$temp_array['flight_country'] = $row['name']; |
|
1183
|
|
|
$temp_array['flight_country_iso3'] = $row['iso3']; |
|
1184
|
|
|
$temp_array['flight_country_iso2'] = $row['iso2']; |
|
1185
|
|
|
$flight_array[] = $temp_array; |
|
1186
|
|
|
} |
|
1187
|
|
|
return $flight_array; |
|
1188
|
|
|
} |
|
1189
|
|
|
|
|
1190
|
|
|
/** |
|
1191
|
|
|
* Gets all number of flight over countries |
|
1192
|
|
|
* |
|
1193
|
|
|
* @param bool $limit |
|
1194
|
|
|
* @param int $olderthanmonths |
|
1195
|
|
|
* @param string $sincedate |
|
1196
|
|
|
* @return array the airline country list |
|
1197
|
|
|
*/ |
|
1198
|
|
|
public function countAllFlightOverCountriesByAirlines($limit = true,$olderthanmonths = 0,$sincedate = '') |
|
1199
|
|
|
{ |
|
1200
|
|
|
global $globalDBdriver; |
|
1201
|
|
|
/* |
|
1202
|
|
|
$query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb |
|
1203
|
|
|
FROM countries c, marine_archive s |
|
1204
|
|
|
WHERE Within(GeomFromText(CONCAT('POINT(',s.longitude,' ',s.latitude,')')), ogc_geom) "; |
|
1205
|
|
|
*/ |
|
1206
|
|
|
$query = "SELECT o.airline_icao,c.name, c.iso3, c.iso2, count(c.name) as nb |
|
1207
|
|
|
FROM countries c, marine_archive s, spotter_output o |
|
1208
|
|
|
WHERE c.iso2 = s.over_country AND o.airline_icao <> '' AND o.fammarine_id = s.fammarine_id "; |
|
1209
|
|
|
if ($olderthanmonths > 0) { |
|
1210
|
|
|
if ($globalDBdriver == 'mysql') { |
|
1211
|
|
|
$query .= 'AND s.date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) '; |
|
1212
|
|
|
} else { |
|
1213
|
|
|
$query .= "AND s.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
|
1214
|
|
|
} |
|
1215
|
|
|
} |
|
1216
|
|
|
if ($sincedate != '') $query .= "AND s.date > '".$sincedate."' "; |
|
1217
|
|
|
$query .= "GROUP BY o.airline_icao,c.name, c.iso3, c.iso2 ORDER BY nb DESC"; |
|
1218
|
|
|
if ($limit) $query .= " LIMIT 0,10"; |
|
1219
|
|
|
|
|
1220
|
|
|
|
|
1221
|
|
|
$sth = $this->db->prepare($query); |
|
1222
|
|
|
$sth->execute(); |
|
1223
|
|
|
|
|
1224
|
|
|
$flight_array = array(); |
|
1225
|
|
|
$temp_array = array(); |
|
1226
|
|
|
|
|
1227
|
|
|
while($row = $sth->fetch(PDO::FETCH_ASSOC)) |
|
1228
|
|
|
{ |
|
1229
|
|
|
$temp_array['airline_icao'] = $row['airline_icao']; |
|
1230
|
|
|
$temp_array['flight_count'] = $row['nb']; |
|
1231
|
|
|
$temp_array['flight_country'] = $row['name']; |
|
1232
|
|
|
$temp_array['flight_country_iso3'] = $row['iso3']; |
|
1233
|
|
|
$temp_array['flight_country_iso2'] = $row['iso2']; |
|
1234
|
|
|
$flight_array[] = $temp_array; |
|
1235
|
|
|
} |
|
1236
|
|
|
return $flight_array; |
|
1237
|
|
|
} |
|
1238
|
|
|
|
|
1239
|
|
|
/** |
|
1240
|
|
|
* Gets last spotter information based on a particular callsign |
|
1241
|
|
|
* |
|
1242
|
|
|
* @param $id |
|
1243
|
|
|
* @param $date |
|
1244
|
|
|
* @return array the spotter information |
|
1245
|
|
|
*/ |
|
1246
|
|
|
public function getDateArchiveMarineDataById($id,$date) |
|
1247
|
|
|
{ |
|
1248
|
|
|
$Marine = new Marine($this->db); |
|
1249
|
|
|
date_default_timezone_set('UTC'); |
|
1250
|
|
|
$id = filter_var($id, FILTER_SANITIZE_STRING); |
|
1251
|
|
|
$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'; |
|
1252
|
|
|
$date = date('c',$date); |
|
1253
|
|
|
$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id,':date' => $date)); |
|
1254
|
|
|
return $spotter_array; |
|
1255
|
|
|
} |
|
1256
|
|
|
|
|
1257
|
|
|
/** |
|
1258
|
|
|
* Gets all the spotter information based on a particular callsign |
|
1259
|
|
|
* |
|
1260
|
|
|
* @param $ident |
|
1261
|
|
|
* @param $date |
|
1262
|
|
|
* @return array the spotter information |
|
1263
|
|
|
*/ |
|
1264
|
|
|
public function getDateArchiveMarineDataByIdent($ident,$date) |
|
1265
|
|
|
{ |
|
1266
|
|
|
$Marine = new Marine($this->db); |
|
1267
|
|
|
date_default_timezone_set('UTC'); |
|
1268
|
|
|
$ident = filter_var($ident, FILTER_SANITIZE_STRING); |
|
1269
|
|
|
$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'; |
|
1270
|
|
|
$date = date('c',$date); |
|
1271
|
|
|
$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident,':date' => $date)); |
|
1272
|
|
|
return $spotter_array; |
|
1273
|
|
|
} |
|
1274
|
|
|
|
|
1275
|
|
|
/** |
|
1276
|
|
|
* Gets all the spotter information based on the airport |
|
1277
|
|
|
* |
|
1278
|
|
|
* @param string $airport |
|
1279
|
|
|
* @param string $limit |
|
1280
|
|
|
* @param string $sort |
|
1281
|
|
|
* @param array $filters |
|
1282
|
|
|
* @return array the spotter information |
|
1283
|
|
|
*/ |
|
1284
|
|
|
public function getMarineDataByAirport($airport = '', $limit = '', $sort = '',$filters = array()) |
|
1285
|
|
|
{ |
|
1286
|
|
|
global $global_query; |
|
1287
|
|
|
$Marine = new Marine($this->db); |
|
1288
|
|
|
date_default_timezone_set('UTC'); |
|
1289
|
|
|
$query_values = array(); |
|
1290
|
|
|
$limit_query = ''; |
|
1291
|
|
|
$additional_query = ''; |
|
1292
|
|
|
$filter_query = $this->getFilter($filters,true,true); |
|
1293
|
|
|
|
|
1294
|
|
|
if ($airport != "") |
|
1295
|
|
|
{ |
|
1296
|
|
|
if (!is_string($airport)) |
|
1297
|
|
|
{ |
|
1298
|
|
|
return array(); |
|
1299
|
|
|
} else { |
|
1300
|
|
|
$additional_query .= " AND ((marine_archive_output.departure_airport_icao = :airport) OR (marine_archive_output.arrival_airport_icao = :airport))"; |
|
1301
|
|
|
$query_values = array(':airport' => $airport); |
|
1302
|
|
|
} |
|
1303
|
|
|
} |
|
1304
|
|
|
|
|
1305
|
|
|
if ($limit != "") |
|
1306
|
|
|
{ |
|
1307
|
|
|
$limit_array = explode(",", $limit); |
|
1308
|
|
|
|
|
1309
|
|
|
$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
|
1310
|
|
|
$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
|
1311
|
|
|
|
|
1312
|
|
|
if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
|
1313
|
|
|
{ |
|
1314
|
|
|
//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
|
1315
|
|
|
$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
|
1316
|
|
|
} |
|
1317
|
|
|
} |
|
1318
|
|
|
|
|
1319
|
|
|
if ($sort != "") |
|
1320
|
|
|
{ |
|
1321
|
|
|
$search_orderby_array = $Marine->getOrderBy(); |
|
1322
|
|
|
$orderby_query = $search_orderby_array[$sort]['sql']; |
|
1323
|
|
|
} else { |
|
1324
|
|
|
$orderby_query = " ORDER BY marine_archive_output.date DESC"; |
|
1325
|
|
|
} |
|
1326
|
|
|
|
|
1327
|
|
|
$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; |
|
1328
|
|
|
|
|
1329
|
|
|
$spotter_array = $Marine->getDataFromDB($query, $query_values, $limit_query); |
|
1330
|
|
|
|
|
1331
|
|
|
return $spotter_array; |
|
1332
|
|
|
} |
|
1333
|
|
|
} |
|
1334
|
|
|
?> |