@@ -12,10 +12,10 @@ discard block |
||
12 | 12 | |
13 | 13 | |
14 | 14 | /** |
15 | - * Get SQL query part for filter used |
|
16 | - * @param Array $filter the filter |
|
17 | - * @return Array the SQL part |
|
18 | - */ |
|
15 | + * Get SQL query part for filter used |
|
16 | + * @param Array $filter the filter |
|
17 | + * @return Array the SQL part |
|
18 | + */ |
|
19 | 19 | public function getFilter($filter = array(),$where = false,$and = false) { |
20 | 20 | global $globalFilter, $globalStatsFilters, $globalFilterName; |
21 | 21 | $filters = array(); |
@@ -83,11 +83,11 @@ discard block |
||
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
86 | - * Gets all the spotter information based on the latest data entry |
|
87 | - * |
|
88 | - * @return Array the spotter information |
|
89 | - * |
|
90 | - */ |
|
86 | + * Gets all the spotter information based on the latest data entry |
|
87 | + * |
|
88 | + * @return Array the spotter information |
|
89 | + * |
|
90 | + */ |
|
91 | 91 | public function getLiveSpotterData($limit = '', $sort = '', $filter = array()) |
92 | 92 | { |
93 | 93 | global $globalDBdriver, $globalLiveInterval; |
@@ -126,11 +126,11 @@ discard block |
||
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
129 | - * Gets Minimal Live Spotter data |
|
130 | - * |
|
131 | - * @return Array the spotter information |
|
132 | - * |
|
133 | - */ |
|
129 | + * Gets Minimal Live Spotter data |
|
130 | + * |
|
131 | + * @return Array the spotter information |
|
132 | + * |
|
133 | + */ |
|
134 | 134 | public function getMinLiveSpotterData($filter = array()) |
135 | 135 | { |
136 | 136 | global $globalDBdriver, $globalLiveInterval; |
@@ -181,11 +181,11 @@ discard block |
||
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
184 | - * Gets Minimal Live Spotter data since xx seconds |
|
185 | - * |
|
186 | - * @return Array the spotter information |
|
187 | - * |
|
188 | - */ |
|
184 | + * Gets Minimal Live Spotter data since xx seconds |
|
185 | + * |
|
186 | + * @return Array the spotter information |
|
187 | + * |
|
188 | + */ |
|
189 | 189 | public function getMinLastLiveSpotterData($filter = array()) |
190 | 190 | { |
191 | 191 | global $globalDBdriver, $globalLiveInterval; |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | $query = 'SELECT a.aircraft_shadow, a.engine_type, a.engine_count, a.wake_category, spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source |
200 | 200 | FROM spotter_live LEFT JOIN (SELECT aircraft_shadow,engine_type, engine_count, wake_category,icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= spotter_live.date AND spotter_live.latitude <> '0' AND spotter_live.longitude <> '0' |
201 | 201 | ORDER BY spotter_live.flightaware_id, spotter_live.date"; |
202 | - } else { |
|
202 | + } else { |
|
203 | 203 | /* |
204 | 204 | $query = "SELECT a.aircraft_shadow, spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source |
205 | 205 | FROM spotter_live WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | // echo $query; |
212 | 212 | } |
213 | 213 | |
214 | - try { |
|
214 | + try { |
|
215 | 215 | $sth = $this->db->prepare($query); |
216 | 216 | $sth->execute(); |
217 | 217 | } catch(PDOException $e) { |
@@ -223,11 +223,11 @@ discard block |
||
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
226 | - * Gets number of latest data entry |
|
227 | - * |
|
228 | - * @return String number of entry |
|
229 | - * |
|
230 | - */ |
|
226 | + * Gets number of latest data entry |
|
227 | + * |
|
228 | + * @return String number of entry |
|
229 | + * |
|
230 | + */ |
|
231 | 231 | public function getLiveSpotterCount($filter = array()) |
232 | 232 | { |
233 | 233 | global $globalDBdriver, $globalLiveInterval; |
@@ -254,11 +254,11 @@ discard block |
||
254 | 254 | } |
255 | 255 | |
256 | 256 | /** |
257 | - * Gets all the spotter information based on the latest data entry and coord |
|
258 | - * |
|
259 | - * @return Array the spotter information |
|
260 | - * |
|
261 | - */ |
|
257 | + * Gets all the spotter information based on the latest data entry and coord |
|
258 | + * |
|
259 | + * @return Array the spotter information |
|
260 | + * |
|
261 | + */ |
|
262 | 262 | public function getLiveSpotterDatabyCoord($coord, $filter = array()) |
263 | 263 | { |
264 | 264 | global $globalDBdriver, $globalLiveInterval; |
@@ -283,11 +283,11 @@ discard block |
||
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
286 | - * Gets all the spotter information based on a user's latitude and longitude |
|
287 | - * |
|
288 | - * @return Array the spotter information |
|
289 | - * |
|
290 | - */ |
|
286 | + * Gets all the spotter information based on a user's latitude and longitude |
|
287 | + * |
|
288 | + * @return Array the spotter information |
|
289 | + * |
|
290 | + */ |
|
291 | 291 | public function getLatestSpotterForLayar($lat, $lng, $radius, $interval) |
292 | 292 | { |
293 | 293 | $Spotter = new Spotter($this->db); |
@@ -297,145 +297,145 @@ discard block |
||
297 | 297 | return false; |
298 | 298 | } |
299 | 299 | } |
300 | - if ($lng != '') |
|
301 | - { |
|
302 | - if (!is_numeric($lng)) |
|
303 | - { |
|
304 | - return false; |
|
305 | - } |
|
306 | - } |
|
307 | - |
|
308 | - if ($radius != '') |
|
309 | - { |
|
310 | - if (!is_numeric($radius)) |
|
311 | - { |
|
312 | - return false; |
|
313 | - } |
|
314 | - } |
|
300 | + if ($lng != '') |
|
301 | + { |
|
302 | + if (!is_numeric($lng)) |
|
303 | + { |
|
304 | + return false; |
|
305 | + } |
|
306 | + } |
|
307 | + |
|
308 | + if ($radius != '') |
|
309 | + { |
|
310 | + if (!is_numeric($radius)) |
|
311 | + { |
|
312 | + return false; |
|
313 | + } |
|
314 | + } |
|
315 | 315 | $additional_query = ''; |
316 | - if ($interval != '') |
|
317 | - { |
|
318 | - if (!is_string($interval)) |
|
319 | - { |
|
320 | - //$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date '; |
|
321 | - return false; |
|
322 | - } else { |
|
323 | - if ($interval == '1m') |
|
324 | - { |
|
325 | - $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date '; |
|
326 | - } else if ($interval == '15m'){ |
|
327 | - $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= spotter_live.date '; |
|
328 | - } |
|
329 | - } |
|
330 | - } else { |
|
331 | - $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date '; |
|
332 | - } |
|
333 | - |
|
334 | - $query = "SELECT spotter_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM spotter_live |
|
316 | + if ($interval != '') |
|
317 | + { |
|
318 | + if (!is_string($interval)) |
|
319 | + { |
|
320 | + //$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date '; |
|
321 | + return false; |
|
322 | + } else { |
|
323 | + if ($interval == '1m') |
|
324 | + { |
|
325 | + $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date '; |
|
326 | + } else if ($interval == '15m'){ |
|
327 | + $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= spotter_live.date '; |
|
328 | + } |
|
329 | + } |
|
330 | + } else { |
|
331 | + $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date '; |
|
332 | + } |
|
333 | + |
|
334 | + $query = "SELECT spotter_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM spotter_live |
|
335 | 335 | WHERE spotter_live.latitude <> '' |
336 | 336 | AND spotter_live.longitude <> '' |
337 | 337 | ".$additional_query." |
338 | 338 | HAVING distance < :radius |
339 | 339 | ORDER BY distance"; |
340 | 340 | |
341 | - $spotter_array = $Spotter->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius)); |
|
341 | + $spotter_array = $Spotter->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius)); |
|
342 | 342 | |
343 | - return $spotter_array; |
|
344 | - } |
|
343 | + return $spotter_array; |
|
344 | + } |
|
345 | 345 | |
346 | 346 | |
347 | - /** |
|
348 | - * Gets all the spotter information based on a particular callsign |
|
349 | - * |
|
350 | - * @return Array the spotter information |
|
351 | - * |
|
352 | - */ |
|
347 | + /** |
|
348 | + * Gets all the spotter information based on a particular callsign |
|
349 | + * |
|
350 | + * @return Array the spotter information |
|
351 | + * |
|
352 | + */ |
|
353 | 353 | public function getLastLiveSpotterDataByIdent($ident) |
354 | 354 | { |
355 | 355 | $Spotter = new Spotter($this->db); |
356 | 356 | date_default_timezone_set('UTC'); |
357 | 357 | |
358 | 358 | $ident = filter_var($ident, FILTER_SANITIZE_STRING); |
359 | - $query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC'; |
|
359 | + $query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC'; |
|
360 | 360 | |
361 | 361 | $spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident),'',true); |
362 | 362 | |
363 | 363 | return $spotter_array; |
364 | 364 | } |
365 | 365 | |
366 | - /** |
|
367 | - * Gets all the spotter information based on a particular callsign |
|
368 | - * |
|
369 | - * @return Array the spotter information |
|
370 | - * |
|
371 | - */ |
|
366 | + /** |
|
367 | + * Gets all the spotter information based on a particular callsign |
|
368 | + * |
|
369 | + * @return Array the spotter information |
|
370 | + * |
|
371 | + */ |
|
372 | 372 | public function getDateLiveSpotterDataByIdent($ident,$date) |
373 | 373 | { |
374 | 374 | $Spotter = new Spotter($this->db); |
375 | 375 | date_default_timezone_set('UTC'); |
376 | 376 | |
377 | 377 | $ident = filter_var($ident, FILTER_SANITIZE_STRING); |
378 | - $query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC'; |
|
378 | + $query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC'; |
|
379 | 379 | |
380 | - $date = date('c',$date); |
|
380 | + $date = date('c',$date); |
|
381 | 381 | $spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident,':date' => $date)); |
382 | 382 | |
383 | 383 | return $spotter_array; |
384 | 384 | } |
385 | 385 | |
386 | - /** |
|
387 | - * Gets last spotter information based on a particular callsign |
|
388 | - * |
|
389 | - * @return Array the spotter information |
|
390 | - * |
|
391 | - */ |
|
386 | + /** |
|
387 | + * Gets last spotter information based on a particular callsign |
|
388 | + * |
|
389 | + * @return Array the spotter information |
|
390 | + * |
|
391 | + */ |
|
392 | 392 | public function getLastLiveSpotterDataById($id) |
393 | 393 | { |
394 | 394 | $Spotter = new Spotter($this->db); |
395 | 395 | date_default_timezone_set('UTC'); |
396 | 396 | |
397 | 397 | $id = filter_var($id, FILTER_SANITIZE_STRING); |
398 | - $query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.flightaware_id = :id GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC'; |
|
398 | + $query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.flightaware_id = :id GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC'; |
|
399 | 399 | |
400 | 400 | $spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id),'',true); |
401 | 401 | |
402 | 402 | return $spotter_array; |
403 | 403 | } |
404 | 404 | |
405 | - /** |
|
406 | - * Gets last spotter information based on a particular callsign |
|
407 | - * |
|
408 | - * @return Array the spotter information |
|
409 | - * |
|
410 | - */ |
|
405 | + /** |
|
406 | + * Gets last spotter information based on a particular callsign |
|
407 | + * |
|
408 | + * @return Array the spotter information |
|
409 | + * |
|
410 | + */ |
|
411 | 411 | public function getDateLiveSpotterDataById($id,$date) |
412 | 412 | { |
413 | 413 | $Spotter = new Spotter($this->db); |
414 | 414 | date_default_timezone_set('UTC'); |
415 | 415 | |
416 | 416 | $id = filter_var($id, FILTER_SANITIZE_STRING); |
417 | - $query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.flightaware_id = :id AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC'; |
|
418 | - $date = date('c',$date); |
|
417 | + $query = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.flightaware_id = :id AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC'; |
|
418 | + $date = date('c',$date); |
|
419 | 419 | $spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id,':date' => $date),'',true); |
420 | 420 | |
421 | 421 | return $spotter_array; |
422 | 422 | } |
423 | 423 | |
424 | - /** |
|
425 | - * Gets altitude information based on a particular callsign |
|
426 | - * |
|
427 | - * @return Array the spotter information |
|
428 | - * |
|
429 | - */ |
|
424 | + /** |
|
425 | + * Gets altitude information based on a particular callsign |
|
426 | + * |
|
427 | + * @return Array the spotter information |
|
428 | + * |
|
429 | + */ |
|
430 | 430 | public function getAltitudeLiveSpotterDataByIdent($ident) |
431 | 431 | { |
432 | 432 | |
433 | 433 | date_default_timezone_set('UTC'); |
434 | 434 | |
435 | 435 | $ident = filter_var($ident, FILTER_SANITIZE_STRING); |
436 | - $query = 'SELECT spotter_live.altitude, spotter_live.date FROM spotter_live WHERE spotter_live.ident = :ident'; |
|
436 | + $query = 'SELECT spotter_live.altitude, spotter_live.date FROM spotter_live WHERE spotter_live.ident = :ident'; |
|
437 | 437 | |
438 | - try { |
|
438 | + try { |
|
439 | 439 | |
440 | 440 | $sth = $this->db->prepare($query); |
441 | 441 | $sth->execute(array(':ident' => $ident)); |
@@ -448,12 +448,12 @@ discard block |
||
448 | 448 | return $spotter_array; |
449 | 449 | } |
450 | 450 | |
451 | - /** |
|
452 | - * Gets all the spotter information based on a particular id |
|
453 | - * |
|
454 | - * @return Array the spotter information |
|
455 | - * |
|
456 | - */ |
|
451 | + /** |
|
452 | + * Gets all the spotter information based on a particular id |
|
453 | + * |
|
454 | + * @return Array the spotter information |
|
455 | + * |
|
456 | + */ |
|
457 | 457 | public function getAllLiveSpotterDataById($id,$liveinterval = false) |
458 | 458 | { |
459 | 459 | global $globalDBdriver, $globalLiveInterval; |
@@ -481,18 +481,18 @@ discard block |
||
481 | 481 | return $spotter_array; |
482 | 482 | } |
483 | 483 | |
484 | - /** |
|
485 | - * Gets all the spotter information based on a particular ident |
|
486 | - * |
|
487 | - * @return Array the spotter information |
|
488 | - * |
|
489 | - */ |
|
484 | + /** |
|
485 | + * Gets all the spotter information based on a particular ident |
|
486 | + * |
|
487 | + * @return Array the spotter information |
|
488 | + * |
|
489 | + */ |
|
490 | 490 | public function getAllLiveSpotterDataByIdent($ident) |
491 | 491 | { |
492 | 492 | date_default_timezone_set('UTC'); |
493 | 493 | $ident = filter_var($ident, FILTER_SANITIZE_STRING); |
494 | 494 | $query = self::$global_query.' WHERE spotter_live.ident = :ident'; |
495 | - try { |
|
495 | + try { |
|
496 | 496 | |
497 | 497 | $sth = $this->db->prepare($query); |
498 | 498 | $sth->execute(array(':ident' => $ident)); |
@@ -506,23 +506,23 @@ discard block |
||
506 | 506 | |
507 | 507 | |
508 | 508 | /** |
509 | - * Deletes all info in the table |
|
510 | - * |
|
511 | - * @return String success or false |
|
512 | - * |
|
513 | - */ |
|
509 | + * Deletes all info in the table |
|
510 | + * |
|
511 | + * @return String success or false |
|
512 | + * |
|
513 | + */ |
|
514 | 514 | public function deleteLiveSpotterData() |
515 | 515 | { |
516 | 516 | global $globalDBdriver; |
517 | 517 | if ($globalDBdriver == 'mysql') { |
518 | 518 | //$query = "DELETE FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE) >= spotter_live.date"; |
519 | 519 | $query = 'DELETE FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 9 HOUR) >= spotter_live.date'; |
520 | - //$query = "DELETE FROM spotter_live WHERE spotter_live.id IN (SELECT spotter_live.id FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= spotter_live.date)"; |
|
520 | + //$query = "DELETE FROM spotter_live WHERE spotter_live.id IN (SELECT spotter_live.id FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= spotter_live.date)"; |
|
521 | 521 | } else { |
522 | 522 | $query = "DELETE FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= spotter_live.date"; |
523 | 523 | } |
524 | 524 | |
525 | - try { |
|
525 | + try { |
|
526 | 526 | |
527 | 527 | $sth = $this->db->prepare($query); |
528 | 528 | $sth->execute(); |
@@ -534,18 +534,18 @@ discard block |
||
534 | 534 | } |
535 | 535 | |
536 | 536 | /** |
537 | - * Deletes all info in the table for aircraft not seen since 2 HOUR |
|
538 | - * |
|
539 | - * @return String success or false |
|
540 | - * |
|
541 | - */ |
|
537 | + * Deletes all info in the table for aircraft not seen since 2 HOUR |
|
538 | + * |
|
539 | + * @return String success or false |
|
540 | + * |
|
541 | + */ |
|
542 | 542 | public function deleteLiveSpotterDataNotUpdated() |
543 | 543 | { |
544 | 544 | global $globalDBdriver, $globalDebug; |
545 | 545 | if ($globalDBdriver == 'mysql') { |
546 | 546 | //$query = 'SELECT flightaware_id FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) >= spotter_live.date AND spotter_live.flightaware_id NOT IN (SELECT flightaware_id FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) < spotter_live.date) LIMIT 800 OFFSET 0'; |
547 | - $query = "SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 1200 OFFSET 0"; |
|
548 | - try { |
|
547 | + $query = "SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 1200 OFFSET 0"; |
|
548 | + try { |
|
549 | 549 | |
550 | 550 | $sth = $this->db->prepare($query); |
551 | 551 | $sth->execute(); |
@@ -553,8 +553,8 @@ discard block |
||
553 | 553 | return "error"; |
554 | 554 | } |
555 | 555 | $query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN ('; |
556 | - $i = 0; |
|
557 | - $j =0; |
|
556 | + $i = 0; |
|
557 | + $j =0; |
|
558 | 558 | $all = $sth->fetchAll(PDO::FETCH_ASSOC); |
559 | 559 | foreach($all as $row) |
560 | 560 | { |
@@ -562,20 +562,20 @@ discard block |
||
562 | 562 | $j++; |
563 | 563 | if ($j == 30) { |
564 | 564 | if ($globalDebug) echo "."; |
565 | - try { |
|
565 | + try { |
|
566 | 566 | |
567 | 567 | $sth = $this->db->prepare(substr($query_delete,0,-1).")"); |
568 | 568 | $sth->execute(); |
569 | 569 | } catch(PDOException $e) { |
570 | 570 | return "error"; |
571 | 571 | } |
572 | - $query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN ('; |
|
573 | - $j = 0; |
|
572 | + $query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN ('; |
|
573 | + $j = 0; |
|
574 | 574 | } |
575 | 575 | $query_delete .= "'".$row['flightaware_id']."',"; |
576 | 576 | } |
577 | 577 | if ($i > 0) { |
578 | - try { |
|
578 | + try { |
|
579 | 579 | |
580 | 580 | $sth = $this->db->prepare(substr($query_delete,0,-1).")"); |
581 | 581 | $sth->execute(); |
@@ -586,9 +586,9 @@ discard block |
||
586 | 586 | return "success"; |
587 | 587 | } elseif ($globalDBdriver == 'pgsql') { |
588 | 588 | //$query = "SELECT flightaware_id FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= spotter_live.date AND spotter_live.flightaware_id NOT IN (SELECT flightaware_id FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' < spotter_live.date) LIMIT 800 OFFSET 0"; |
589 | - //$query = "SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0"; |
|
590 | - $query = "DELETE FROM spotter_live WHERE flightaware_id IN (SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0)"; |
|
591 | - try { |
|
589 | + //$query = "SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0"; |
|
590 | + $query = "DELETE FROM spotter_live WHERE flightaware_id IN (SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0)"; |
|
591 | + try { |
|
592 | 592 | |
593 | 593 | $sth = $this->db->prepare($query); |
594 | 594 | $sth->execute(); |
@@ -632,17 +632,17 @@ discard block |
||
632 | 632 | } |
633 | 633 | |
634 | 634 | /** |
635 | - * Deletes all info in the table for an ident |
|
636 | - * |
|
637 | - * @return String success or false |
|
638 | - * |
|
639 | - */ |
|
635 | + * Deletes all info in the table for an ident |
|
636 | + * |
|
637 | + * @return String success or false |
|
638 | + * |
|
639 | + */ |
|
640 | 640 | public function deleteLiveSpotterDataByIdent($ident) |
641 | 641 | { |
642 | 642 | $ident = filter_var($ident, FILTER_SANITIZE_STRING); |
643 | 643 | $query = 'DELETE FROM spotter_live WHERE ident = :ident'; |
644 | 644 | |
645 | - try { |
|
645 | + try { |
|
646 | 646 | |
647 | 647 | $sth = $this->db->prepare($query); |
648 | 648 | $sth->execute(array(':ident' => $ident)); |
@@ -654,17 +654,17 @@ discard block |
||
654 | 654 | } |
655 | 655 | |
656 | 656 | /** |
657 | - * Deletes all info in the table for an id |
|
658 | - * |
|
659 | - * @return String success or false |
|
660 | - * |
|
661 | - */ |
|
657 | + * Deletes all info in the table for an id |
|
658 | + * |
|
659 | + * @return String success or false |
|
660 | + * |
|
661 | + */ |
|
662 | 662 | public function deleteLiveSpotterDataById($id) |
663 | 663 | { |
664 | 664 | $id = filter_var($id, FILTER_SANITIZE_STRING); |
665 | 665 | $query = 'DELETE FROM spotter_live WHERE flightaware_id = :id'; |
666 | 666 | |
667 | - try { |
|
667 | + try { |
|
668 | 668 | |
669 | 669 | $sth = $this->db->prepare($query); |
670 | 670 | $sth->execute(array(':id' => $id)); |
@@ -677,11 +677,11 @@ discard block |
||
677 | 677 | |
678 | 678 | |
679 | 679 | /** |
680 | - * Gets the aircraft ident within the last hour |
|
681 | - * |
|
682 | - * @return String the ident |
|
683 | - * |
|
684 | - */ |
|
680 | + * Gets the aircraft ident within the last hour |
|
681 | + * |
|
682 | + * @return String the ident |
|
683 | + * |
|
684 | + */ |
|
685 | 685 | public function getIdentFromLastHour($ident) |
686 | 686 | { |
687 | 687 | global $globalDBdriver, $globalTimezone; |
@@ -707,14 +707,14 @@ discard block |
||
707 | 707 | $ident_result = $row['ident']; |
708 | 708 | } |
709 | 709 | return $ident_result; |
710 | - } |
|
710 | + } |
|
711 | 711 | |
712 | 712 | /** |
713 | - * Check recent aircraft |
|
714 | - * |
|
715 | - * @return String the ident |
|
716 | - * |
|
717 | - */ |
|
713 | + * Check recent aircraft |
|
714 | + * |
|
715 | + * @return String the ident |
|
716 | + * |
|
717 | + */ |
|
718 | 718 | public function checkIdentRecent($ident) |
719 | 719 | { |
720 | 720 | global $globalDBdriver, $globalTimezone; |
@@ -740,14 +740,14 @@ discard block |
||
740 | 740 | $ident_result = $row['flightaware_id']; |
741 | 741 | } |
742 | 742 | return $ident_result; |
743 | - } |
|
743 | + } |
|
744 | 744 | |
745 | 745 | /** |
746 | - * Check recent aircraft by id |
|
747 | - * |
|
748 | - * @return String the ident |
|
749 | - * |
|
750 | - */ |
|
746 | + * Check recent aircraft by id |
|
747 | + * |
|
748 | + * @return String the ident |
|
749 | + * |
|
750 | + */ |
|
751 | 751 | public function checkIdRecent($id) |
752 | 752 | { |
753 | 753 | global $globalDBdriver, $globalTimezone; |
@@ -773,14 +773,14 @@ discard block |
||
773 | 773 | $ident_result = $row['flightaware_id']; |
774 | 774 | } |
775 | 775 | return $ident_result; |
776 | - } |
|
776 | + } |
|
777 | 777 | |
778 | 778 | /** |
779 | - * Check recent aircraft by ModeS |
|
780 | - * |
|
781 | - * @return String the ModeS |
|
782 | - * |
|
783 | - */ |
|
779 | + * Check recent aircraft by ModeS |
|
780 | + * |
|
781 | + * @return String the ModeS |
|
782 | + * |
|
783 | + */ |
|
784 | 784 | public function checkModeSRecent($modes) |
785 | 785 | { |
786 | 786 | global $globalDBdriver, $globalTimezone; |
@@ -807,19 +807,19 @@ discard block |
||
807 | 807 | $ident_result = $row['flightaware_id']; |
808 | 808 | } |
809 | 809 | return $ident_result; |
810 | - } |
|
810 | + } |
|
811 | 811 | |
812 | 812 | /** |
813 | - * Adds a new spotter data |
|
814 | - * |
|
815 | - * @param String $flightaware_id the ID from flightaware |
|
816 | - * @param String $ident the flight ident |
|
817 | - * @param String $aircraft_icao the aircraft type |
|
818 | - * @param String $departure_airport_icao the departure airport |
|
819 | - * @param String $arrival_airport_icao the arrival airport |
|
820 | - * @return String success or false |
|
821 | - * |
|
822 | - */ |
|
813 | + * Adds a new spotter data |
|
814 | + * |
|
815 | + * @param String $flightaware_id the ID from flightaware |
|
816 | + * @param String $ident the flight ident |
|
817 | + * @param String $aircraft_icao the aircraft type |
|
818 | + * @param String $departure_airport_icao the departure airport |
|
819 | + * @param String $arrival_airport_icao the arrival airport |
|
820 | + * @return String success or false |
|
821 | + * |
|
822 | + */ |
|
823 | 823 | public function addLiveSpotterData($flightaware_id = '', $ident = '', $aircraft_icao = '', $departure_airport_icao = '', $arrival_airport_icao = '', $latitude = '', $longitude = '', $waypoints = '', $altitude = '', $heading = '', $groundspeed = '', $date = '',$departure_airport_time = '', $arrival_airport_time = '', $squawk = '', $route_stop = '', $ModeS = '', $putinarchive = false,$registration = '',$pilot_id = '', $pilot_name = '', $verticalrate = '', $noarchive = false, $ground = false,$format_source = '', $source_name = '', $over_country = '') |
824 | 824 | { |
825 | 825 | global $globalURL, $globalArchive, $globalDebug; |
@@ -954,10 +954,10 @@ discard block |
||
954 | 954 | $arrival_airport_country = ''; |
955 | 955 | |
956 | 956 | |
957 | - if ($squawk == '' || $Common->isInteger($squawk) === false ) $squawk = NULL; |
|
958 | - if ($verticalrate == '' || $Common->isInteger($verticalrate) === false ) $verticalrate = NULL; |
|
959 | - if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0; |
|
960 | - if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0; |
|
957 | + if ($squawk == '' || $Common->isInteger($squawk) === false ) $squawk = NULL; |
|
958 | + if ($verticalrate == '' || $Common->isInteger($verticalrate) === false ) $verticalrate = NULL; |
|
959 | + if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0; |
|
960 | + if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0; |
|
961 | 961 | |
962 | 962 | $query = 'INSERT INTO spotter_live (flightaware_id, ident, registration, airline_name, airline_icao, airline_country, airline_type, aircraft_icao, aircraft_shadow, aircraft_name, aircraft_manufacturer, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, latitude, longitude, waypoints, altitude, heading, ground_speed, date, departure_airport_time, arrival_airport_time, squawk, route_stop, ModeS, pilot_id, pilot_name, verticalrate, ground, format_source, source_name, over_country) |
963 | 963 | VALUES (:flightaware_id,:ident,:registration,:airline_name,:airline_icao,:airline_country,:airline_type,:aircraft_icao,:aircraft_shadow,:aircraft_type,:aircraft_manufacturer,:departure_airport_icao,:departure_airport_name, :departure_airport_city, :departure_airport_country, :arrival_airport_icao, :arrival_airport_name, :arrival_airport_city, :arrival_airport_country, :latitude,:longitude,:waypoints,:altitude,:heading,:groundspeed,:date,:departure_airport_time,:arrival_airport_time,:squawk,:route_stop,:ModeS, :pilot_id, :pilot_name, :verticalrate, :ground, :format_source, :source_name, :over_country)'; |
@@ -967,14 +967,14 @@ discard block |
||
967 | 967 | |
968 | 968 | $sth = $this->db->prepare($query); |
969 | 969 | $sth->execute($query_values); |
970 | - } catch(PDOException $e) { |
|
971 | - return "error : ".$e->getMessage(); |
|
972 | - } |
|
970 | + } catch(PDOException $e) { |
|
971 | + return "error : ".$e->getMessage(); |
|
972 | + } |
|
973 | 973 | if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) { |
974 | - if ($globalDebug) echo '(Add to SBS archive : '; |
|
975 | - $SpotterArchive = new SpotterArchive($this->db); |
|
976 | - $result = $SpotterArchive->addSpotterArchiveData($flightaware_id, $ident, $registration, $airline_name, $airline_icao, $airline_country, $airline_type, $aircraft_icao, $aircraft_shadow, $aircraft_name, $aircraft_manufacturer, $departure_airport_icao, $departure_airport_name, $departure_airport_city, $departure_airport_country, $departure_airport_time,$arrival_airport_icao, $arrival_airport_name, $arrival_airport_city, $arrival_airport_country, $arrival_airport_time, $route_stop, $date,$latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed, $squawk, $ModeS, $pilot_id, $pilot_name,$verticalrate,$format_source,$source_name, $over_country); |
|
977 | - if ($globalDebug) echo $result.')'; |
|
974 | + if ($globalDebug) echo '(Add to SBS archive : '; |
|
975 | + $SpotterArchive = new SpotterArchive($this->db); |
|
976 | + $result = $SpotterArchive->addSpotterArchiveData($flightaware_id, $ident, $registration, $airline_name, $airline_icao, $airline_country, $airline_type, $aircraft_icao, $aircraft_shadow, $aircraft_name, $aircraft_manufacturer, $departure_airport_icao, $departure_airport_name, $departure_airport_city, $departure_airport_country, $departure_airport_time,$arrival_airport_icao, $arrival_airport_name, $arrival_airport_city, $arrival_airport_country, $arrival_airport_time, $route_stop, $date,$latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed, $squawk, $ModeS, $pilot_id, $pilot_name,$verticalrate,$format_source,$source_name, $over_country); |
|
977 | + if ($globalDebug) echo $result.')'; |
|
978 | 978 | } |
979 | 979 | return "success"; |
980 | 980 |