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