@@ -258,7 +258,9 @@ discard block |
||
258 | 258 | // Update table countries |
259 | 259 | if ($Connection->tableExists('airspace')) { |
260 | 260 | $error .= update_db::update_countries(); |
261 | - if ($error != '') return $error; |
|
261 | + if ($error != '') { |
|
262 | + return $error; |
|
263 | + } |
|
262 | 264 | } |
263 | 265 | // Update schema_version to 7 |
264 | 266 | $query = "UPDATE `config` SET `value` = '7' WHERE `name` = 'schema_version'"; |
@@ -314,7 +316,9 @@ discard block |
||
314 | 316 | $error = ''; |
315 | 317 | // Update table aircraft |
316 | 318 | $error .= create_db::import_file('../db/source_location.sql'); |
317 | - if ($error != '') return $error; |
|
319 | + if ($error != '') { |
|
320 | + return $error; |
|
321 | + } |
|
318 | 322 | // Update schema_version to 6 |
319 | 323 | $query = "UPDATE `config` SET `value` = '8' WHERE `name` = 'schema_version'"; |
320 | 324 | try { |
@@ -331,7 +335,9 @@ discard block |
||
331 | 335 | $error = ''; |
332 | 336 | // Update table aircraft |
333 | 337 | $error .= create_db::import_file('../db/notam.sql'); |
334 | - if ($error != '') return $error; |
|
338 | + if ($error != '') { |
|
339 | + return $error; |
|
340 | + } |
|
335 | 341 | $query = "DELETE FROM config WHERE name = 'last_update_db'; |
336 | 342 | INSERT INTO config (name,value) VALUES ('last_update_db',NOW()); |
337 | 343 | DELETE FROM config WHERE name = 'last_update_notam_db'; |
@@ -365,7 +371,9 @@ discard block |
||
365 | 371 | $error = ''; |
366 | 372 | // Update table atc |
367 | 373 | $error .= create_db::import_file('../db/atc.sql'); |
368 | - if ($error != '') return $error; |
|
374 | + if ($error != '') { |
|
375 | + return $error; |
|
376 | + } |
|
369 | 377 | |
370 | 378 | $query = "UPDATE `config` SET `value` = '10' WHERE `name` = 'schema_version'"; |
371 | 379 | try { |
@@ -389,13 +397,21 @@ discard block |
||
389 | 397 | $error = ''; |
390 | 398 | // Add tables |
391 | 399 | $error .= create_db::import_file('../db/aircraft_owner.sql'); |
392 | - if ($error != '') return $error; |
|
400 | + if ($error != '') { |
|
401 | + return $error; |
|
402 | + } |
|
393 | 403 | $error .= create_db::import_file('../db/metar.sql'); |
394 | - if ($error != '') return $error; |
|
404 | + if ($error != '') { |
|
405 | + return $error; |
|
406 | + } |
|
395 | 407 | $error .= create_db::import_file('../db/taf.sql'); |
396 | - if ($error != '') return $error; |
|
408 | + if ($error != '') { |
|
409 | + return $error; |
|
410 | + } |
|
397 | 411 | $error .= create_db::import_file('../db/airport.sql'); |
398 | - if ($error != '') return $error; |
|
412 | + if ($error != '') { |
|
413 | + return $error; |
|
414 | + } |
|
399 | 415 | |
400 | 416 | $query = "UPDATE `config` SET `value` = '11' WHERE `name` = 'schema_version'"; |
401 | 417 | try { |
@@ -469,19 +485,33 @@ discard block |
||
469 | 485 | $error = ''; |
470 | 486 | // Add tables |
471 | 487 | $error .= create_db::import_file('../db/stats.sql'); |
472 | - if ($error != '') return $error; |
|
488 | + if ($error != '') { |
|
489 | + return $error; |
|
490 | + } |
|
473 | 491 | $error .= create_db::import_file('../db/stats_aircraft.sql'); |
474 | - if ($error != '') return $error; |
|
492 | + if ($error != '') { |
|
493 | + return $error; |
|
494 | + } |
|
475 | 495 | $error .= create_db::import_file('../db/stats_airline.sql'); |
476 | - if ($error != '') return $error; |
|
496 | + if ($error != '') { |
|
497 | + return $error; |
|
498 | + } |
|
477 | 499 | $error .= create_db::import_file('../db/stats_airport.sql'); |
478 | - if ($error != '') return $error; |
|
500 | + if ($error != '') { |
|
501 | + return $error; |
|
502 | + } |
|
479 | 503 | $error .= create_db::import_file('../db/stats_owner.sql'); |
480 | - if ($error != '') return $error; |
|
504 | + if ($error != '') { |
|
505 | + return $error; |
|
506 | + } |
|
481 | 507 | $error .= create_db::import_file('../db/stats_pilot.sql'); |
482 | - if ($error != '') return $error; |
|
508 | + if ($error != '') { |
|
509 | + return $error; |
|
510 | + } |
|
483 | 511 | $error .= create_db::import_file('../db/spotter_archive_output.sql'); |
484 | - if ($error != '') return $error; |
|
512 | + if ($error != '') { |
|
513 | + return $error; |
|
514 | + } |
|
485 | 515 | |
486 | 516 | $query = "UPDATE `config` SET `value` = '13' WHERE `name` = 'schema_version'"; |
487 | 517 | try { |
@@ -521,7 +551,9 @@ discard block |
||
521 | 551 | // Add tables |
522 | 552 | if (!$Connection->tableExists('stats_flight')) { |
523 | 553 | $error .= create_db::import_file('../db/stats_flight.sql'); |
524 | - if ($error != '') return $error; |
|
554 | + if ($error != '') { |
|
555 | + return $error; |
|
556 | + } |
|
525 | 557 | } |
526 | 558 | $query = "UPDATE `config` SET `value` = '15' WHERE `name` = 'schema_version'"; |
527 | 559 | try { |
@@ -545,7 +577,9 @@ discard block |
||
545 | 577 | } catch(PDOException $e) { |
546 | 578 | return "error (update stats) : ".$e->getMessage()."\n"; |
547 | 579 | } |
548 | - if ($error != '') return $error; |
|
580 | + if ($error != '') { |
|
581 | + return $error; |
|
582 | + } |
|
549 | 583 | $query = "UPDATE `config` SET `value` = '16' WHERE `name` = 'schema_version'"; |
550 | 584 | try { |
551 | 585 | $sth = $Connection->db->prepare($query); |
@@ -566,7 +600,9 @@ discard block |
||
566 | 600 | if (!$Connection->tableExists('stats_callsign')) { |
567 | 601 | $error .= create_db::import_file('../db/stats_callsign.sql'); |
568 | 602 | } |
569 | - if ($error != '') return $error; |
|
603 | + if ($error != '') { |
|
604 | + return $error; |
|
605 | + } |
|
570 | 606 | $query = "UPDATE `config` SET `value` = '17' WHERE `name` = 'schema_version'"; |
571 | 607 | try { |
572 | 608 | $sth = $Connection->db->prepare($query); |
@@ -584,7 +620,9 @@ discard block |
||
584 | 620 | if (!$Connection->tableExists('stats_country')) { |
585 | 621 | $error .= create_db::import_file('../db/stats_country.sql'); |
586 | 622 | } |
587 | - if ($error != '') return $error; |
|
623 | + if ($error != '') { |
|
624 | + return $error; |
|
625 | + } |
|
588 | 626 | $query = "UPDATE `config` SET `value` = '18' WHERE `name` = 'schema_version'"; |
589 | 627 | try { |
590 | 628 | $sth = $Connection->db->prepare($query); |
@@ -607,7 +645,9 @@ discard block |
||
607 | 645 | return "error (update stats) : ".$e->getMessage()."\n"; |
608 | 646 | } |
609 | 647 | } |
610 | - if ($error != '') return $error; |
|
648 | + if ($error != '') { |
|
649 | + return $error; |
|
650 | + } |
|
611 | 651 | $query = "UPDATE `config` SET `value` = '19' WHERE `name` = 'schema_version'"; |
612 | 652 | try { |
613 | 653 | $sth = $Connection->db->prepare($query); |
@@ -623,7 +663,9 @@ discard block |
||
623 | 663 | $error = ''; |
624 | 664 | // Update airport table |
625 | 665 | $error .= create_db::import_file('../db/airport.sql'); |
626 | - if ($error != '') return 'Import airport.sql : '.$error; |
|
666 | + if ($error != '') { |
|
667 | + return 'Import airport.sql : '.$error; |
|
668 | + } |
|
627 | 669 | // Remove primary key on Spotter_Archive |
628 | 670 | $query = "alter table spotter_archive drop spotter_archive_id"; |
629 | 671 | try { |
@@ -699,7 +741,9 @@ discard block |
||
699 | 741 | return "error (add source_name column) : ".$e->getMessage()."\n"; |
700 | 742 | } |
701 | 743 | } |
702 | - if ($error != '') return $error; |
|
744 | + if ($error != '') { |
|
745 | + return $error; |
|
746 | + } |
|
703 | 747 | $query = "UPDATE `config` SET `value` = '20' WHERE `name` = 'schema_version'"; |
704 | 748 | try { |
705 | 749 | $sth = $Connection->db->prepare($query); |
@@ -717,7 +761,9 @@ discard block |
||
717 | 761 | // Update airline table |
718 | 762 | if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS) { |
719 | 763 | $error .= create_db::import_file('../db/airlines.sql'); |
720 | - if ($error != '') return 'Import airlines.sql : '.$error; |
|
764 | + if ($error != '') { |
|
765 | + return 'Import airlines.sql : '.$error; |
|
766 | + } |
|
721 | 767 | } |
722 | 768 | if (!$Connection->checkColumnName('aircraft_modes','type_flight')) { |
723 | 769 | // Add column over_country |
@@ -729,7 +775,9 @@ discard block |
||
729 | 775 | return "error (add over_country) : ".$e->getMessage()."\n"; |
730 | 776 | } |
731 | 777 | } |
732 | - if ($error != '') return $error; |
|
778 | + if ($error != '') { |
|
779 | + return $error; |
|
780 | + } |
|
733 | 781 | /* |
734 | 782 | if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS) { |
735 | 783 | // Force update ModeS (this will put type_flight data |
@@ -759,7 +807,9 @@ discard block |
||
759 | 807 | } catch(PDOException $e) { |
760 | 808 | return "error (rename type to stats_type on stats*) : ".$e->getMessage()."\n"; |
761 | 809 | } |
762 | - if ($error != '') return $error; |
|
810 | + if ($error != '') { |
|
811 | + return $error; |
|
812 | + } |
|
763 | 813 | } |
764 | 814 | $query = "UPDATE `config` SET `value` = '22' WHERE `name` = 'schema_version'"; |
765 | 815 | try { |
@@ -782,7 +832,9 @@ discard block |
||
782 | 832 | } else { |
783 | 833 | $error .= create_db::import_file('../db/pgsql/stats_source.sql'); |
784 | 834 | } |
785 | - if ($error != '') return $error; |
|
835 | + if ($error != '') { |
|
836 | + return $error; |
|
837 | + } |
|
786 | 838 | } |
787 | 839 | $query = "UPDATE config SET value = '23' WHERE name = 'schema_version'"; |
788 | 840 | try { |
@@ -804,12 +856,16 @@ discard block |
||
804 | 856 | if ($globalDBdriver == 'mysql') { |
805 | 857 | if (!$Connection->tableExists('tle')) { |
806 | 858 | $error .= create_db::import_file('../db/tle.sql'); |
807 | - if ($error != '') return $error; |
|
859 | + if ($error != '') { |
|
860 | + return $error; |
|
861 | + } |
|
808 | 862 | } |
809 | 863 | } else { |
810 | 864 | if (!$Connection->tableExists('tle')) { |
811 | 865 | $error .= create_db::import_file('../db/pgsql/tle.sql'); |
812 | - if ($error != '') return $error; |
|
866 | + if ($error != '') { |
|
867 | + return $error; |
|
868 | + } |
|
813 | 869 | } |
814 | 870 | $query = "create index flightaware_id_idx ON spotter_archive USING btree(flightaware_id)"; |
815 | 871 | try { |
@@ -849,7 +905,9 @@ discard block |
||
849 | 905 | } else { |
850 | 906 | $error .= create_db::import_file('../db/pgsql/airlines.sql'); |
851 | 907 | } |
852 | - if ($error != '') return 'Import airlines.sql : '.$error; |
|
908 | + if ($error != '') { |
|
909 | + return 'Import airlines.sql : '.$error; |
|
910 | + } |
|
853 | 911 | if (!$Connection->checkColumnName('airlines','forsource')) { |
854 | 912 | // Add forsource to airlines |
855 | 913 | $query = "ALTER TABLE airlines ADD forsource VARCHAR(255) NULL DEFAULT NULL"; |
@@ -1332,20 +1390,28 @@ discard block |
||
1332 | 1390 | } |
1333 | 1391 | if ($globalDBdriver == 'mysql') { |
1334 | 1392 | $error .= create_db::import_file('../db/airlines.sql'); |
1335 | - if ($error != '') return $error; |
|
1393 | + if ($error != '') { |
|
1394 | + return $error; |
|
1395 | + } |
|
1336 | 1396 | } else { |
1337 | 1397 | $error .= create_db::import_file('../db/pgsql/airlines.sql'); |
1338 | - if ($error != '') return $error; |
|
1398 | + if ($error != '') { |
|
1399 | + return $error; |
|
1400 | + } |
|
1339 | 1401 | } |
1340 | 1402 | if ((isset($globalVATSIM) && $globalVATSIM) || (isset($globalIVAO) && $globalIVAO)) { |
1341 | 1403 | include_once(dirname(__FILE__).'/class.update_db.php'); |
1342 | 1404 | if (isset($globalVATSIM) && $globalVATSIM) { |
1343 | 1405 | $error .= update_db::update_vatsim(); |
1344 | - if ($error != '') return $error; |
|
1406 | + if ($error != '') { |
|
1407 | + return $error; |
|
1408 | + } |
|
1345 | 1409 | } |
1346 | 1410 | if (isset($globalIVAO) && $globalIVAO && file_exists('tmp/ivae_feb2013.zip')) { |
1347 | 1411 | $error .= update_db::update_IVAO(); |
1348 | - if ($error != '') return $error; |
|
1412 | + if ($error != '') { |
|
1413 | + return $error; |
|
1414 | + } |
|
1349 | 1415 | } |
1350 | 1416 | } |
1351 | 1417 | |
@@ -1607,30 +1673,54 @@ discard block |
||
1607 | 1673 | */ |
1608 | 1674 | if ($globalDBdriver == 'mysql') { |
1609 | 1675 | $error .= create_db::import_file('../db/tracker_output.sql'); |
1610 | - if ($error != '') return $error; |
|
1676 | + if ($error != '') { |
|
1677 | + return $error; |
|
1678 | + } |
|
1611 | 1679 | $error .= create_db::import_file('../db/tracker_live.sql'); |
1612 | - if ($error != '') return $error; |
|
1680 | + if ($error != '') { |
|
1681 | + return $error; |
|
1682 | + } |
|
1613 | 1683 | $error .= create_db::import_file('../db/marine_output.sql'); |
1614 | - if ($error != '') return $error; |
|
1684 | + if ($error != '') { |
|
1685 | + return $error; |
|
1686 | + } |
|
1615 | 1687 | $error .= create_db::import_file('../db/marine_live.sql'); |
1616 | - if ($error != '') return $error; |
|
1688 | + if ($error != '') { |
|
1689 | + return $error; |
|
1690 | + } |
|
1617 | 1691 | $error .= create_db::import_file('../db/marine_identity.sql'); |
1618 | - if ($error != '') return $error; |
|
1692 | + if ($error != '') { |
|
1693 | + return $error; |
|
1694 | + } |
|
1619 | 1695 | $error .= create_db::import_file('../db/marine_mid.sql'); |
1620 | - if ($error != '') return $error; |
|
1696 | + if ($error != '') { |
|
1697 | + return $error; |
|
1698 | + } |
|
1621 | 1699 | } else { |
1622 | 1700 | $error .= create_db::import_file('../db/pgsql/tracker_output.sql'); |
1623 | - if ($error != '') return $error; |
|
1701 | + if ($error != '') { |
|
1702 | + return $error; |
|
1703 | + } |
|
1624 | 1704 | $error .= create_db::import_file('../db/pgsql/tracker_live.sql'); |
1625 | - if ($error != '') return $error; |
|
1705 | + if ($error != '') { |
|
1706 | + return $error; |
|
1707 | + } |
|
1626 | 1708 | $error .= create_db::import_file('../db/pgsql/marine_output.sql'); |
1627 | - if ($error != '') return $error; |
|
1709 | + if ($error != '') { |
|
1710 | + return $error; |
|
1711 | + } |
|
1628 | 1712 | $error .= create_db::import_file('../db/pgsql/marine_live.sql'); |
1629 | - if ($error != '') return $error; |
|
1713 | + if ($error != '') { |
|
1714 | + return $error; |
|
1715 | + } |
|
1630 | 1716 | $error .= create_db::import_file('../db/pgsql/marine_identity.sql'); |
1631 | - if ($error != '') return $error; |
|
1717 | + if ($error != '') { |
|
1718 | + return $error; |
|
1719 | + } |
|
1632 | 1720 | $error .= create_db::import_file('../db/pgsql/marine_mid.sql'); |
1633 | - if ($error != '') return $error; |
|
1721 | + if ($error != '') { |
|
1722 | + return $error; |
|
1723 | + } |
|
1634 | 1724 | } |
1635 | 1725 | $query = "UPDATE config SET value = '37' WHERE name = 'schema_version'"; |
1636 | 1726 | try { |
@@ -1650,8 +1740,11 @@ discard block |
||
1650 | 1740 | if ($Connection->tableExists('aircraft')) { |
1651 | 1741 | if (!$Connection->tableExists('config')) { |
1652 | 1742 | $version = '1'; |
1653 | - if ($update) return self::update_from_1(); |
|
1654 | - else return $version; |
|
1743 | + if ($update) { |
|
1744 | + return self::update_from_1(); |
|
1745 | + } else { |
|
1746 | + return $version; |
|
1747 | + } |
|
1655 | 1748 | } else { |
1656 | 1749 | $Connection = new Connection(); |
1657 | 1750 | $query = "SELECT value FROM config WHERE name = 'schema_version' LIMIT 1"; |
@@ -1665,150 +1758,260 @@ discard block |
||
1665 | 1758 | if ($update) { |
1666 | 1759 | if ($result['value'] == '2') { |
1667 | 1760 | $error = self::update_from_2(); |
1668 | - if ($error != '') return $error; |
|
1669 | - else return self::check_version(true); |
|
1761 | + if ($error != '') { |
|
1762 | + return $error; |
|
1763 | + } else { |
|
1764 | + return self::check_version(true); |
|
1765 | + } |
|
1670 | 1766 | } elseif ($result['value'] == '3') { |
1671 | 1767 | $error = self::update_from_3(); |
1672 | - if ($error != '') return $error; |
|
1673 | - else return self::check_version(true); |
|
1768 | + if ($error != '') { |
|
1769 | + return $error; |
|
1770 | + } else { |
|
1771 | + return self::check_version(true); |
|
1772 | + } |
|
1674 | 1773 | } elseif ($result['value'] == '4') { |
1675 | 1774 | $error = self::update_from_4(); |
1676 | - if ($error != '') return $error; |
|
1677 | - else return self::check_version(true); |
|
1775 | + if ($error != '') { |
|
1776 | + return $error; |
|
1777 | + } else { |
|
1778 | + return self::check_version(true); |
|
1779 | + } |
|
1678 | 1780 | } elseif ($result['value'] == '5') { |
1679 | 1781 | $error = self::update_from_5(); |
1680 | - if ($error != '') return $error; |
|
1681 | - else return self::check_version(true); |
|
1782 | + if ($error != '') { |
|
1783 | + return $error; |
|
1784 | + } else { |
|
1785 | + return self::check_version(true); |
|
1786 | + } |
|
1682 | 1787 | } elseif ($result['value'] == '6') { |
1683 | 1788 | $error = self::update_from_6(); |
1684 | - if ($error != '') return $error; |
|
1685 | - else return self::check_version(true); |
|
1789 | + if ($error != '') { |
|
1790 | + return $error; |
|
1791 | + } else { |
|
1792 | + return self::check_version(true); |
|
1793 | + } |
|
1686 | 1794 | } elseif ($result['value'] == '7') { |
1687 | 1795 | $error = self::update_from_7(); |
1688 | - if ($error != '') return $error; |
|
1689 | - else return self::check_version(true); |
|
1796 | + if ($error != '') { |
|
1797 | + return $error; |
|
1798 | + } else { |
|
1799 | + return self::check_version(true); |
|
1800 | + } |
|
1690 | 1801 | } elseif ($result['value'] == '8') { |
1691 | 1802 | $error = self::update_from_8(); |
1692 | - if ($error != '') return $error; |
|
1693 | - else return self::check_version(true); |
|
1803 | + if ($error != '') { |
|
1804 | + return $error; |
|
1805 | + } else { |
|
1806 | + return self::check_version(true); |
|
1807 | + } |
|
1694 | 1808 | } elseif ($result['value'] == '9') { |
1695 | 1809 | $error = self::update_from_9(); |
1696 | - if ($error != '') return $error; |
|
1697 | - else return self::check_version(true); |
|
1810 | + if ($error != '') { |
|
1811 | + return $error; |
|
1812 | + } else { |
|
1813 | + return self::check_version(true); |
|
1814 | + } |
|
1698 | 1815 | } elseif ($result['value'] == '10') { |
1699 | 1816 | $error = self::update_from_10(); |
1700 | - if ($error != '') return $error; |
|
1701 | - else return self::check_version(true); |
|
1817 | + if ($error != '') { |
|
1818 | + return $error; |
|
1819 | + } else { |
|
1820 | + return self::check_version(true); |
|
1821 | + } |
|
1702 | 1822 | } elseif ($result['value'] == '11') { |
1703 | 1823 | $error = self::update_from_11(); |
1704 | - if ($error != '') return $error; |
|
1705 | - else return self::check_version(true); |
|
1824 | + if ($error != '') { |
|
1825 | + return $error; |
|
1826 | + } else { |
|
1827 | + return self::check_version(true); |
|
1828 | + } |
|
1706 | 1829 | } elseif ($result['value'] == '12') { |
1707 | 1830 | $error = self::update_from_12(); |
1708 | - if ($error != '') return $error; |
|
1709 | - else return self::check_version(true); |
|
1831 | + if ($error != '') { |
|
1832 | + return $error; |
|
1833 | + } else { |
|
1834 | + return self::check_version(true); |
|
1835 | + } |
|
1710 | 1836 | } elseif ($result['value'] == '13') { |
1711 | 1837 | $error = self::update_from_13(); |
1712 | - if ($error != '') return $error; |
|
1713 | - else return self::check_version(true); |
|
1838 | + if ($error != '') { |
|
1839 | + return $error; |
|
1840 | + } else { |
|
1841 | + return self::check_version(true); |
|
1842 | + } |
|
1714 | 1843 | } elseif ($result['value'] == '14') { |
1715 | 1844 | $error = self::update_from_14(); |
1716 | - if ($error != '') return $error; |
|
1717 | - else return self::check_version(true); |
|
1845 | + if ($error != '') { |
|
1846 | + return $error; |
|
1847 | + } else { |
|
1848 | + return self::check_version(true); |
|
1849 | + } |
|
1718 | 1850 | } elseif ($result['value'] == '15') { |
1719 | 1851 | $error = self::update_from_15(); |
1720 | - if ($error != '') return $error; |
|
1721 | - else return self::check_version(true); |
|
1852 | + if ($error != '') { |
|
1853 | + return $error; |
|
1854 | + } else { |
|
1855 | + return self::check_version(true); |
|
1856 | + } |
|
1722 | 1857 | } elseif ($result['value'] == '16') { |
1723 | 1858 | $error = self::update_from_16(); |
1724 | - if ($error != '') return $error; |
|
1725 | - else return self::check_version(true); |
|
1859 | + if ($error != '') { |
|
1860 | + return $error; |
|
1861 | + } else { |
|
1862 | + return self::check_version(true); |
|
1863 | + } |
|
1726 | 1864 | } elseif ($result['value'] == '17') { |
1727 | 1865 | $error = self::update_from_17(); |
1728 | - if ($error != '') return $error; |
|
1729 | - else return self::check_version(true); |
|
1866 | + if ($error != '') { |
|
1867 | + return $error; |
|
1868 | + } else { |
|
1869 | + return self::check_version(true); |
|
1870 | + } |
|
1730 | 1871 | } elseif ($result['value'] == '18') { |
1731 | 1872 | $error = self::update_from_18(); |
1732 | - if ($error != '') return $error; |
|
1733 | - else return self::check_version(true); |
|
1873 | + if ($error != '') { |
|
1874 | + return $error; |
|
1875 | + } else { |
|
1876 | + return self::check_version(true); |
|
1877 | + } |
|
1734 | 1878 | } elseif ($result['value'] == '19') { |
1735 | 1879 | $error = self::update_from_19(); |
1736 | - if ($error != '') return $error; |
|
1737 | - else return self::check_version(true); |
|
1880 | + if ($error != '') { |
|
1881 | + return $error; |
|
1882 | + } else { |
|
1883 | + return self::check_version(true); |
|
1884 | + } |
|
1738 | 1885 | } elseif ($result['value'] == '20') { |
1739 | 1886 | $error = self::update_from_20(); |
1740 | - if ($error != '') return $error; |
|
1741 | - else return self::check_version(true); |
|
1887 | + if ($error != '') { |
|
1888 | + return $error; |
|
1889 | + } else { |
|
1890 | + return self::check_version(true); |
|
1891 | + } |
|
1742 | 1892 | } elseif ($result['value'] == '21') { |
1743 | 1893 | $error = self::update_from_21(); |
1744 | - if ($error != '') return $error; |
|
1745 | - else return self::check_version(true); |
|
1894 | + if ($error != '') { |
|
1895 | + return $error; |
|
1896 | + } else { |
|
1897 | + return self::check_version(true); |
|
1898 | + } |
|
1746 | 1899 | } elseif ($result['value'] == '22') { |
1747 | 1900 | $error = self::update_from_22(); |
1748 | - if ($error != '') return $error; |
|
1749 | - else return self::check_version(true); |
|
1901 | + if ($error != '') { |
|
1902 | + return $error; |
|
1903 | + } else { |
|
1904 | + return self::check_version(true); |
|
1905 | + } |
|
1750 | 1906 | } elseif ($result['value'] == '23') { |
1751 | 1907 | $error = self::update_from_23(); |
1752 | - if ($error != '') return $error; |
|
1753 | - else return self::check_version(true); |
|
1908 | + if ($error != '') { |
|
1909 | + return $error; |
|
1910 | + } else { |
|
1911 | + return self::check_version(true); |
|
1912 | + } |
|
1754 | 1913 | } elseif ($result['value'] == '24') { |
1755 | 1914 | $error = self::update_from_24(); |
1756 | - if ($error != '') return $error; |
|
1757 | - else return self::check_version(true); |
|
1915 | + if ($error != '') { |
|
1916 | + return $error; |
|
1917 | + } else { |
|
1918 | + return self::check_version(true); |
|
1919 | + } |
|
1758 | 1920 | } elseif ($result['value'] == '25') { |
1759 | 1921 | $error = self::update_from_25(); |
1760 | - if ($error != '') return $error; |
|
1761 | - else return self::check_version(true); |
|
1922 | + if ($error != '') { |
|
1923 | + return $error; |
|
1924 | + } else { |
|
1925 | + return self::check_version(true); |
|
1926 | + } |
|
1762 | 1927 | } elseif ($result['value'] == '26') { |
1763 | 1928 | $error = self::update_from_26(); |
1764 | - if ($error != '') return $error; |
|
1765 | - else return self::check_version(true); |
|
1929 | + if ($error != '') { |
|
1930 | + return $error; |
|
1931 | + } else { |
|
1932 | + return self::check_version(true); |
|
1933 | + } |
|
1766 | 1934 | } elseif ($result['value'] == '27') { |
1767 | 1935 | $error = self::update_from_27(); |
1768 | - if ($error != '') return $error; |
|
1769 | - else return self::check_version(true); |
|
1936 | + if ($error != '') { |
|
1937 | + return $error; |
|
1938 | + } else { |
|
1939 | + return self::check_version(true); |
|
1940 | + } |
|
1770 | 1941 | } elseif ($result['value'] == '28') { |
1771 | 1942 | $error = self::update_from_28(); |
1772 | - if ($error != '') return $error; |
|
1773 | - else return self::check_version(true); |
|
1943 | + if ($error != '') { |
|
1944 | + return $error; |
|
1945 | + } else { |
|
1946 | + return self::check_version(true); |
|
1947 | + } |
|
1774 | 1948 | } elseif ($result['value'] == '29') { |
1775 | 1949 | $error = self::update_from_29(); |
1776 | - if ($error != '') return $error; |
|
1777 | - else return self::check_version(true); |
|
1950 | + if ($error != '') { |
|
1951 | + return $error; |
|
1952 | + } else { |
|
1953 | + return self::check_version(true); |
|
1954 | + } |
|
1778 | 1955 | } elseif ($result['value'] == '30') { |
1779 | 1956 | $error = self::update_from_30(); |
1780 | - if ($error != '') return $error; |
|
1781 | - else return self::check_version(true); |
|
1957 | + if ($error != '') { |
|
1958 | + return $error; |
|
1959 | + } else { |
|
1960 | + return self::check_version(true); |
|
1961 | + } |
|
1782 | 1962 | } elseif ($result['value'] == '31') { |
1783 | 1963 | $error = self::update_from_31(); |
1784 | - if ($error != '') return $error; |
|
1785 | - else return self::check_version(true); |
|
1964 | + if ($error != '') { |
|
1965 | + return $error; |
|
1966 | + } else { |
|
1967 | + return self::check_version(true); |
|
1968 | + } |
|
1786 | 1969 | } elseif ($result['value'] == '32') { |
1787 | 1970 | $error = self::update_from_32(); |
1788 | - if ($error != '') return $error; |
|
1789 | - else return self::check_version(true); |
|
1971 | + if ($error != '') { |
|
1972 | + return $error; |
|
1973 | + } else { |
|
1974 | + return self::check_version(true); |
|
1975 | + } |
|
1790 | 1976 | } elseif ($result['value'] == '33') { |
1791 | 1977 | $error = self::update_from_33(); |
1792 | - if ($error != '') return $error; |
|
1793 | - else return self::check_version(true); |
|
1978 | + if ($error != '') { |
|
1979 | + return $error; |
|
1980 | + } else { |
|
1981 | + return self::check_version(true); |
|
1982 | + } |
|
1794 | 1983 | } elseif ($result['value'] == '34') { |
1795 | 1984 | $error = self::update_from_34(); |
1796 | - if ($error != '') return $error; |
|
1797 | - else return self::check_version(true); |
|
1985 | + if ($error != '') { |
|
1986 | + return $error; |
|
1987 | + } else { |
|
1988 | + return self::check_version(true); |
|
1989 | + } |
|
1798 | 1990 | } elseif ($result['value'] == '35') { |
1799 | 1991 | $error = self::update_from_35(); |
1800 | - if ($error != '') return $error; |
|
1801 | - else return self::check_version(true); |
|
1992 | + if ($error != '') { |
|
1993 | + return $error; |
|
1994 | + } else { |
|
1995 | + return self::check_version(true); |
|
1996 | + } |
|
1802 | 1997 | } elseif ($result['value'] == '36') { |
1803 | 1998 | $error = self::update_from_36(); |
1804 | - if ($error != '') return $error; |
|
1805 | - else return self::check_version(true); |
|
1806 | - } else return ''; |
|
1999 | + if ($error != '') { |
|
2000 | + return $error; |
|
2001 | + } else { |
|
2002 | + return self::check_version(true); |
|
2003 | + } |
|
2004 | + } else { |
|
2005 | + return ''; |
|
2006 | + } |
|
2007 | + } else { |
|
2008 | + return $result['value']; |
|
1807 | 2009 | } |
1808 | - else return $result['value']; |
|
1809 | 2010 | } |
1810 | 2011 | |
1811 | - } else return $version; |
|
2012 | + } else { |
|
2013 | + return $version; |
|
2014 | + } |
|
1812 | 2015 | } |
1813 | 2016 | |
1814 | 2017 | } |
@@ -29,7 +29,9 @@ discard block |
||
29 | 29 | if (isset($filter[0]['source'])) { |
30 | 30 | $filters = array_merge($filters,$filter); |
31 | 31 | } |
32 | - if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter); |
|
32 | + if (is_array($globalFilter)) { |
|
33 | + $filter = array_merge($filter,$globalFilter); |
|
34 | + } |
|
33 | 35 | $filter_query_join = ''; |
34 | 36 | $filter_query_where = ''; |
35 | 37 | foreach($filters as $flt) { |
@@ -76,8 +78,11 @@ discard block |
||
76 | 78 | if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) { |
77 | 79 | $filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
78 | 80 | } |
79 | - if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE'; |
|
80 | - elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND'; |
|
81 | + if ($filter_query_where == '' && $where) { |
|
82 | + $filter_query_where = ' WHERE'; |
|
83 | + } elseif ($filter_query_where != '' && $and) { |
|
84 | + $filter_query_where .= ' AND'; |
|
85 | + } |
|
81 | 86 | if ($filter_query_where != '') { |
82 | 87 | $filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where); |
83 | 88 | } |
@@ -119,7 +124,9 @@ discard block |
||
119 | 124 | } |
120 | 125 | } |
121 | 126 | |
122 | - if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
|
127 | + if (!isset($globalLiveInterval)) { |
|
128 | + $globalLiveInterval = '200'; |
|
129 | + } |
|
123 | 130 | if ($globalDBdriver == 'mysql') { |
124 | 131 | //$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"; |
125 | 132 | $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; |
@@ -144,7 +151,9 @@ discard block |
||
144 | 151 | |
145 | 152 | $filter_query = $this->getFilter($filter,true,true); |
146 | 153 | |
147 | - if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
|
154 | + if (!isset($globalLiveInterval)) { |
|
155 | + $globalLiveInterval = '200'; |
|
156 | + } |
|
148 | 157 | if ($globalDBdriver == 'mysql') { |
149 | 158 | $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 |
150 | 159 | 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"; |
@@ -178,7 +187,9 @@ discard block |
||
178 | 187 | |
179 | 188 | $filter_query = $this->getFilter($filter,true,true); |
180 | 189 | |
181 | - if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
|
190 | + if (!isset($globalLiveInterval)) { |
|
191 | + $globalLiveInterval = '200'; |
|
192 | + } |
|
182 | 193 | if ($globalDBdriver == 'mysql') { |
183 | 194 | $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 |
184 | 195 | 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' |
@@ -211,7 +222,9 @@ discard block |
||
211 | 222 | global $globalDBdriver, $globalLiveInterval; |
212 | 223 | $filter_query = $this->getFilter($filter,true,true); |
213 | 224 | |
214 | - if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
|
225 | + if (!isset($globalLiveInterval)) { |
|
226 | + $globalLiveInterval = '200'; |
|
227 | + } |
|
215 | 228 | if ($globalDBdriver == 'mysql') { |
216 | 229 | $query = 'SELECT COUNT(DISTINCT marine_live.fammarine_id) as nb FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date'; |
217 | 230 | } else { |
@@ -239,7 +252,9 @@ discard block |
||
239 | 252 | { |
240 | 253 | global $globalDBdriver, $globalLiveInterval; |
241 | 254 | $Spotter = new Spotter($this->db); |
242 | - if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
|
255 | + if (!isset($globalLiveInterval)) { |
|
256 | + $globalLiveInterval = '200'; |
|
257 | + } |
|
243 | 258 | $filter_query = $this->getFilter($filter); |
244 | 259 | |
245 | 260 | if (is_array($coord)) { |
@@ -247,7 +262,9 @@ discard block |
||
247 | 262 | $minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
248 | 263 | $maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
249 | 264 | $maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
250 | - } else return array(); |
|
265 | + } else { |
|
266 | + return array(); |
|
267 | + } |
|
251 | 268 | if ($globalDBdriver == 'mysql') { |
252 | 269 | $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'.$filter_query; |
253 | 270 | } else { |
@@ -411,11 +428,15 @@ discard block |
||
411 | 428 | //$query = self::$global_query.' WHERE marine_live.fammarine_id = :id ORDER BY date'; |
412 | 429 | if ($globalDBdriver == 'mysql') { |
413 | 430 | $query = 'SELECT marine_live.* FROM marine_live WHERE marine_live.fammarine_id = :id'; |
414 | - if ($liveinterval) $query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date'; |
|
431 | + if ($liveinterval) { |
|
432 | + $query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date'; |
|
433 | + } |
|
415 | 434 | $query .= ' ORDER BY date'; |
416 | 435 | } else { |
417 | 436 | $query = 'SELECT marine_live.* FROM marine_live WHERE marine_live.fammarine_id = :id'; |
418 | - if ($liveinterval) $query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date"; |
|
437 | + if ($liveinterval) { |
|
438 | + $query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date"; |
|
439 | + } |
|
419 | 440 | $query .= ' ORDER BY date'; |
420 | 441 | } |
421 | 442 | |
@@ -510,7 +531,9 @@ discard block |
||
510 | 531 | $i++; |
511 | 532 | $j++; |
512 | 533 | if ($j == 30) { |
513 | - if ($globalDebug) echo "."; |
|
534 | + if ($globalDebug) { |
|
535 | + echo "."; |
|
536 | + } |
|
514 | 537 | try { |
515 | 538 | |
516 | 539 | $sth = $this->db->prepare(substr($query_delete,0,-1).")"); |
@@ -790,7 +813,9 @@ discard block |
||
790 | 813 | { |
791 | 814 | return false; |
792 | 815 | } |
793 | - } else return ''; |
|
816 | + } else { |
|
817 | + return ''; |
|
818 | + } |
|
794 | 819 | |
795 | 820 | if ($longitude != '') |
796 | 821 | { |
@@ -798,7 +823,9 @@ discard block |
||
798 | 823 | { |
799 | 824 | return false; |
800 | 825 | } |
801 | - } else return ''; |
|
826 | + } else { |
|
827 | + return ''; |
|
828 | + } |
|
802 | 829 | |
803 | 830 | |
804 | 831 | if ($heading != '') |
@@ -807,7 +834,9 @@ discard block |
||
807 | 834 | { |
808 | 835 | return false; |
809 | 836 | } |
810 | - } else $heading = 0; |
|
837 | + } else { |
|
838 | + $heading = 0; |
|
839 | + } |
|
811 | 840 | |
812 | 841 | if ($groundspeed != '') |
813 | 842 | { |
@@ -815,9 +844,13 @@ discard block |
||
815 | 844 | { |
816 | 845 | return false; |
817 | 846 | } |
818 | - } else $groundspeed = 0; |
|
847 | + } else { |
|
848 | + $groundspeed = 0; |
|
849 | + } |
|
819 | 850 | date_default_timezone_set('UTC'); |
820 | - if ($date == '') $date = date("Y-m-d H:i:s", time()); |
|
851 | + if ($date == '') { |
|
852 | + $date = date("Y-m-d H:i:s", time()); |
|
853 | + } |
|
821 | 854 | |
822 | 855 | |
823 | 856 | $fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING); |
@@ -838,9 +871,15 @@ discard block |
||
838 | 871 | $arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING); |
839 | 872 | |
840 | 873 | |
841 | - if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0; |
|
842 | - if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0; |
|
843 | - if ($arrival_date == '') $arrival_date = NULL; |
|
874 | + if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) { |
|
875 | + $groundspeed = 0; |
|
876 | + } |
|
877 | + if ($heading == '' || $Common->isInteger($heading) === false ) { |
|
878 | + $heading = 0; |
|
879 | + } |
|
880 | + if ($arrival_date == '') { |
|
881 | + $arrival_date = NULL; |
|
882 | + } |
|
844 | 883 | $query = 'INSERT INTO marine_live (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, over_country, mmsi, type,status,imo,arrival_port_name,arrival_port_date) |
845 | 884 | VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:groundspeed,:date,:format_source, :source_name, :over_country,:mmsi,:type,:status,:imo,:arrival_port_name,:arrival_port_date)'; |
846 | 885 |
@@ -31,7 +31,9 @@ discard block |
||
31 | 31 | if (isset($filter[0]['source'])) { |
32 | 32 | $filters = array_merge($filters,$filter); |
33 | 33 | } |
34 | - if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter); |
|
34 | + if (is_array($globalFilter)) { |
|
35 | + $filter = array_merge($filter,$globalFilter); |
|
36 | + } |
|
35 | 37 | $filter_query_join = ''; |
36 | 38 | $filter_query_where = ''; |
37 | 39 | foreach($filters as $flt) { |
@@ -70,8 +72,11 @@ discard block |
||
70 | 72 | $filter_query_where .= " AND EXTRACT(DAY FROM marine_output.date) = '".$filter['day']."'"; |
71 | 73 | } |
72 | 74 | } |
73 | - if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE'; |
|
74 | - elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND'; |
|
75 | + if ($filter_query_where == '' && $where) { |
|
76 | + $filter_query_where = ' WHERE'; |
|
77 | + } elseif ($filter_query_where != '' && $and) { |
|
78 | + $filter_query_where .= ' AND'; |
|
79 | + } |
|
75 | 80 | if ($filter_query_where != '') { |
76 | 81 | $filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where); |
77 | 82 | } |
@@ -125,25 +130,40 @@ discard block |
||
125 | 130 | $temp_array['spotter_id'] = $row['spotter_archive_id']; |
126 | 131 | } elseif (isset($row['spotter_archive_output_id'])) { |
127 | 132 | $temp_array['spotter_id'] = $row['spotter_archive_output_id']; |
128 | - */} |
|
129 | - elseif (isset($row['marineid'])) { |
|
133 | + */} elseif (isset($row['marineid'])) { |
|
130 | 134 | $temp_array['marineid'] = $row['marineid']; |
131 | 135 | } else { |
132 | 136 | $temp_array['marineid'] = ''; |
133 | 137 | } |
134 | - if (isset($row['fammarine_id'])) $temp_array['fammarine_id'] = $row['fammarine_id']; |
|
135 | - if (isset($row['mmsi'])) $temp_array['mmsi'] = $row['mmsi']; |
|
136 | - if (isset($row['type'])) $temp_array['type'] = $row['type']; |
|
138 | + if (isset($row['fammarine_id'])) { |
|
139 | + $temp_array['fammarine_id'] = $row['fammarine_id']; |
|
140 | + } |
|
141 | + if (isset($row['mmsi'])) { |
|
142 | + $temp_array['mmsi'] = $row['mmsi']; |
|
143 | + } |
|
144 | + if (isset($row['type'])) { |
|
145 | + $temp_array['type'] = $row['type']; |
|
146 | + } |
|
137 | 147 | $temp_array['ident'] = $row['ident']; |
138 | - if (isset($row['latitude'])) $temp_array['latitude'] = $row['latitude']; |
|
139 | - if (isset($row['longitude'])) $temp_array['longitude'] = $row['longitude']; |
|
140 | - if (isset($row['format_source'])) $temp_array['format_source'] = $row['format_source']; |
|
148 | + if (isset($row['latitude'])) { |
|
149 | + $temp_array['latitude'] = $row['latitude']; |
|
150 | + } |
|
151 | + if (isset($row['longitude'])) { |
|
152 | + $temp_array['longitude'] = $row['longitude']; |
|
153 | + } |
|
154 | + if (isset($row['format_source'])) { |
|
155 | + $temp_array['format_source'] = $row['format_source']; |
|
156 | + } |
|
141 | 157 | if (isset($row['heading'])) { |
142 | 158 | $temp_array['heading'] = $row['heading']; |
143 | 159 | $heading_direction = $this->parseDirection($row['heading']); |
144 | - if (isset($heading_direction[0]['direction_fullname'])) $temp_array['heading_name'] = $heading_direction[0]['direction_fullname']; |
|
160 | + if (isset($heading_direction[0]['direction_fullname'])) { |
|
161 | + $temp_array['heading_name'] = $heading_direction[0]['direction_fullname']; |
|
162 | + } |
|
163 | + } |
|
164 | + if (isset($row['ground_speed'])) { |
|
165 | + $temp_array['ground_speed'] = $row['ground_speed']; |
|
145 | 166 | } |
146 | - if (isset($row['ground_speed'])) $temp_array['ground_speed'] = $row['ground_speed']; |
|
147 | 167 | |
148 | 168 | if (isset($row['date'])) { |
149 | 169 | $dateArray = $this->parseDateString($row['date']); |
@@ -186,13 +206,21 @@ discard block |
||
186 | 206 | } |
187 | 207 | |
188 | 208 | $fromsource = NULL; |
189 | - if (isset($row['source_name']) && $row['source_name'] != '') $temp_array['source_name'] = $row['source_name']; |
|
190 | - if (isset($row['over_country']) && $row['over_country'] != '') $temp_array['over_country'] = $row['over_country']; |
|
191 | - if (isset($row['distance']) && $row['distance'] != '') $temp_array['distance'] = $row['distance']; |
|
209 | + if (isset($row['source_name']) && $row['source_name'] != '') { |
|
210 | + $temp_array['source_name'] = $row['source_name']; |
|
211 | + } |
|
212 | + if (isset($row['over_country']) && $row['over_country'] != '') { |
|
213 | + $temp_array['over_country'] = $row['over_country']; |
|
214 | + } |
|
215 | + if (isset($row['distance']) && $row['distance'] != '') { |
|
216 | + $temp_array['distance'] = $row['distance']; |
|
217 | + } |
|
192 | 218 | $temp_array['query_number_rows'] = $num_rows; |
193 | 219 | $spotter_array[] = $temp_array; |
194 | 220 | } |
195 | - if ($num_rows == 0) return array(); |
|
221 | + if ($num_rows == 0) { |
|
222 | + return array(); |
|
223 | + } |
|
196 | 224 | $spotter_array[0]['query_number_rows'] = $num_rows; |
197 | 225 | return $spotter_array; |
198 | 226 | } |
@@ -223,8 +251,12 @@ discard block |
||
223 | 251 | { |
224 | 252 | //$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; |
225 | 253 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
226 | - } else $limit_query = ""; |
|
227 | - } else $limit_query = ""; |
|
254 | + } else { |
|
255 | + $limit_query = ""; |
|
256 | + } |
|
257 | + } else { |
|
258 | + $limit_query = ""; |
|
259 | + } |
|
228 | 260 | |
229 | 261 | if ($sort != "") |
230 | 262 | { |
@@ -252,7 +284,9 @@ discard block |
||
252 | 284 | global $global_query; |
253 | 285 | |
254 | 286 | date_default_timezone_set('UTC'); |
255 | - if ($id == '') return array(); |
|
287 | + if ($id == '') { |
|
288 | + return array(); |
|
289 | + } |
|
256 | 290 | $additional_query = "marine_output.fammarine_id = :id"; |
257 | 291 | $query_values = array(':id' => $id); |
258 | 292 | $query = $global_query." WHERE ".$additional_query." "; |
@@ -395,8 +429,11 @@ discard block |
||
395 | 429 | $query .= " ORDER BY marine_output.source_name ASC"; |
396 | 430 | |
397 | 431 | $sth = $this->db->prepare($query); |
398 | - if (!empty($query_values)) $sth->execute($query_values); |
|
399 | - else $sth->execute(); |
|
432 | + if (!empty($query_values)) { |
|
433 | + $sth->execute($query_values); |
|
434 | + } else { |
|
435 | + $sth->execute(); |
|
436 | + } |
|
400 | 437 | |
401 | 438 | $source_array = array(); |
402 | 439 | $temp_array = array(); |
@@ -451,8 +488,11 @@ discard block |
||
451 | 488 | $sth = $this->db->prepare($query); |
452 | 489 | $sth->execute(array(':mmsi' => $mmsi)); |
453 | 490 | $result = $sth->fetchAll(PDO::FETCH_ASSOC); |
454 | - if (isset($result[0])) return $result[0]; |
|
455 | - else return array(); |
|
491 | + if (isset($result[0])) { |
|
492 | + return $result[0]; |
|
493 | + } else { |
|
494 | + return array(); |
|
495 | + } |
|
456 | 496 | } |
457 | 497 | |
458 | 498 | /* |
@@ -468,7 +508,9 @@ discard block |
||
468 | 508 | date_default_timezone_set($globalTimezone); |
469 | 509 | $datetime = new DateTime(); |
470 | 510 | $offset = $datetime->format('P'); |
471 | - } else $offset = '+00:00'; |
|
511 | + } else { |
|
512 | + $offset = '+00:00'; |
|
513 | + } |
|
472 | 514 | |
473 | 515 | if ($globalDBdriver == 'mysql') { |
474 | 516 | $query = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date |
@@ -663,9 +705,15 @@ discard block |
||
663 | 705 | $latitude = 0; |
664 | 706 | $longitude = 0; |
665 | 707 | } |
666 | - if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0; |
|
667 | - if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0; |
|
668 | - if ($arrival_date == '') $arrival_date = NULL; |
|
708 | + if ($heading == '' || $Common->isInteger($heading) === false) { |
|
709 | + $heading = 0; |
|
710 | + } |
|
711 | + if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) { |
|
712 | + $groundspeed = 0; |
|
713 | + } |
|
714 | + if ($arrival_date == '') { |
|
715 | + $arrival_date = NULL; |
|
716 | + } |
|
669 | 717 | $query = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo,arrival_port_name,arrival_port_date) |
670 | 718 | VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:speed,:date,:format_source, :source_name,:mmsi,:type,:status,:imo,:arrival_port_name,:arrival_port_date)"; |
671 | 719 | |
@@ -829,12 +877,18 @@ discard block |
||
829 | 877 | $query = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count |
830 | 878 | FROM marine_output".$filter_query." marine_output.ident <> ''"; |
831 | 879 | if ($olderthanmonths > 0) { |
832 | - if ($globalDBdriver == 'mysql') $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)'; |
|
833 | - else $query .= " AND marine_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
|
880 | + if ($globalDBdriver == 'mysql') { |
|
881 | + $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)'; |
|
882 | + } else { |
|
883 | + $query .= " AND marine_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
|
884 | + } |
|
834 | 885 | } |
835 | 886 | if ($sincedate != '') { |
836 | - if ($globalDBdriver == 'mysql') $query .= " AND marine_output.date > '".$sincedate."'"; |
|
837 | - else $query .= " AND marine_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
|
887 | + if ($globalDBdriver == 'mysql') { |
|
888 | + $query .= " AND marine_output.date > '".$sincedate."'"; |
|
889 | + } else { |
|
890 | + $query .= " AND marine_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
|
891 | + } |
|
838 | 892 | } |
839 | 893 | $query_values = array(); |
840 | 894 | if ($year != '') { |
@@ -865,7 +919,9 @@ discard block |
||
865 | 919 | } |
866 | 920 | } |
867 | 921 | $query .= " GROUP BY marine_output.ident ORDER BY callsign_icao_count DESC"; |
868 | - if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
|
922 | + if ($limit) { |
|
923 | + $query .= " LIMIT 10 OFFSET 0"; |
|
924 | + } |
|
869 | 925 | |
870 | 926 | $sth = $this->db->prepare($query); |
871 | 927 | $sth->execute($query_values); |
@@ -900,7 +956,9 @@ discard block |
||
900 | 956 | date_default_timezone_set($globalTimezone); |
901 | 957 | $datetime = new DateTime(); |
902 | 958 | $offset = $datetime->format('P'); |
903 | - } else $offset = '+00:00'; |
|
959 | + } else { |
|
960 | + $offset = '+00:00'; |
|
961 | + } |
|
904 | 962 | |
905 | 963 | if ($globalDBdriver == 'mysql') { |
906 | 964 | $query = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count |
@@ -950,7 +1008,9 @@ discard block |
||
950 | 1008 | date_default_timezone_set($globalTimezone); |
951 | 1009 | $datetime = new DateTime(); |
952 | 1010 | $offset = $datetime->format('P'); |
953 | - } else $offset = '+00:00'; |
|
1011 | + } else { |
|
1012 | + $offset = '+00:00'; |
|
1013 | + } |
|
954 | 1014 | $filter_query = $this->getFilter($filters,true,true); |
955 | 1015 | if ($globalDBdriver == 'mysql') { |
956 | 1016 | $query = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count |
@@ -996,7 +1056,9 @@ discard block |
||
996 | 1056 | date_default_timezone_set($globalTimezone); |
997 | 1057 | $datetime = new DateTime(); |
998 | 1058 | $offset = $datetime->format('P'); |
999 | - } else $offset = '+00:00'; |
|
1059 | + } else { |
|
1060 | + $offset = '+00:00'; |
|
1061 | + } |
|
1000 | 1062 | $filter_query = $this->getFilter($filters,true,true); |
1001 | 1063 | if ($globalDBdriver == 'mysql') { |
1002 | 1064 | $query = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count |
@@ -1044,7 +1106,9 @@ discard block |
||
1044 | 1106 | date_default_timezone_set($globalTimezone); |
1045 | 1107 | $datetime = new DateTime(); |
1046 | 1108 | $offset = $datetime->format('P'); |
1047 | - } else $offset = '+00:00'; |
|
1109 | + } else { |
|
1110 | + $offset = '+00:00'; |
|
1111 | + } |
|
1048 | 1112 | |
1049 | 1113 | if ($globalDBdriver == 'mysql') { |
1050 | 1114 | $query = "SELECT YEAR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS month_name, count(*) as date_count |
@@ -1093,7 +1157,9 @@ discard block |
||
1093 | 1157 | date_default_timezone_set($globalTimezone); |
1094 | 1158 | $datetime = new DateTime(); |
1095 | 1159 | $offset = $datetime->format('P'); |
1096 | - } else $offset = '+00:00'; |
|
1160 | + } else { |
|
1161 | + $offset = '+00:00'; |
|
1162 | + } |
|
1097 | 1163 | $filter_query = $this->getFilter($filters,true,true); |
1098 | 1164 | if ($globalDBdriver == 'mysql') { |
1099 | 1165 | $query = "SELECT MONTH(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS month_name, YEAR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS year_name, count(*) as date_count |
@@ -1142,7 +1208,9 @@ discard block |
||
1142 | 1208 | date_default_timezone_set($globalTimezone); |
1143 | 1209 | $datetime = new DateTime(); |
1144 | 1210 | $offset = $datetime->format('P'); |
1145 | - } else $offset = '+00:00'; |
|
1211 | + } else { |
|
1212 | + $offset = '+00:00'; |
|
1213 | + } |
|
1146 | 1214 | |
1147 | 1215 | $orderby_sql = ''; |
1148 | 1216 | if ($orderby == "hour") |
@@ -1211,7 +1279,9 @@ discard block |
||
1211 | 1279 | date_default_timezone_set($globalTimezone); |
1212 | 1280 | $datetime = new DateTime($date); |
1213 | 1281 | $offset = $datetime->format('P'); |
1214 | - } else $offset = '+00:00'; |
|
1282 | + } else { |
|
1283 | + $offset = '+00:00'; |
|
1284 | + } |
|
1215 | 1285 | |
1216 | 1286 | if ($globalDBdriver == 'mysql') { |
1217 | 1287 | $query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
@@ -1259,7 +1329,9 @@ discard block |
||
1259 | 1329 | date_default_timezone_set($globalTimezone); |
1260 | 1330 | $datetime = new DateTime(); |
1261 | 1331 | $offset = $datetime->format('P'); |
1262 | - } else $offset = '+00:00'; |
|
1332 | + } else { |
|
1333 | + $offset = '+00:00'; |
|
1334 | + } |
|
1263 | 1335 | |
1264 | 1336 | if ($globalDBdriver == 'mysql') { |
1265 | 1337 | $query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
@@ -1323,8 +1395,11 @@ discard block |
||
1323 | 1395 | $query_values = array_merge($query_values,array(':month' => $month)); |
1324 | 1396 | } |
1325 | 1397 | } |
1326 | - if (empty($query_values)) $queryi .= $this->getFilter($filters); |
|
1327 | - else $queryi .= $this->getFilter($filters,true,true).substr($query,4); |
|
1398 | + if (empty($query_values)) { |
|
1399 | + $queryi .= $this->getFilter($filters); |
|
1400 | + } else { |
|
1401 | + $queryi .= $this->getFilter($filters,true,true).substr($query,4); |
|
1402 | + } |
|
1328 | 1403 | |
1329 | 1404 | $sth = $this->db->prepare($queryi); |
1330 | 1405 | $sth->execute($query_values); |
@@ -1346,7 +1421,9 @@ discard block |
||
1346 | 1421 | date_default_timezone_set($globalTimezone); |
1347 | 1422 | $datetime = new DateTime(); |
1348 | 1423 | $offset = $datetime->format('P'); |
1349 | - } else $offset = '+00:00'; |
|
1424 | + } else { |
|
1425 | + $offset = '+00:00'; |
|
1426 | + } |
|
1350 | 1427 | |
1351 | 1428 | if ($globalDBdriver == 'mysql') { |
1352 | 1429 | $query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
@@ -1450,7 +1527,9 @@ discard block |
||
1450 | 1527 | */ |
1451 | 1528 | public function parseDirection($direction = 0) |
1452 | 1529 | { |
1453 | - if ($direction == '') $direction = 0; |
|
1530 | + if ($direction == '') { |
|
1531 | + $direction = 0; |
|
1532 | + } |
|
1454 | 1533 | $direction_array = array(); |
1455 | 1534 | $temp_array = array(); |
1456 | 1535 | |
@@ -1539,7 +1618,9 @@ discard block |
||
1539 | 1618 | $longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
1540 | 1619 | |
1541 | 1620 | $Connection = new Connection($this->db); |
1542 | - if (!$Connection->tableExists('countries')) return ''; |
|
1621 | + if (!$Connection->tableExists('countries')) { |
|
1622 | + return ''; |
|
1623 | + } |
|
1543 | 1624 | |
1544 | 1625 | try { |
1545 | 1626 | /* |
@@ -1559,9 +1640,13 @@ discard block |
||
1559 | 1640 | $sth->closeCursor(); |
1560 | 1641 | if (count($row) > 0) { |
1561 | 1642 | return $row; |
1562 | - } else return ''; |
|
1643 | + } else { |
|
1644 | + return ''; |
|
1645 | + } |
|
1563 | 1646 | } catch (PDOException $e) { |
1564 | - if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n"; |
|
1647 | + if (isset($globalDebug) && $globalDebug) { |
|
1648 | + echo 'Error : '.$e->getMessage()."\n"; |
|
1649 | + } |
|
1565 | 1650 | return ''; |
1566 | 1651 | } |
1567 | 1652 | |
@@ -1579,7 +1664,9 @@ discard block |
||
1579 | 1664 | $iso2 = filter_var($iso2,FILTER_SANITIZE_STRING); |
1580 | 1665 | |
1581 | 1666 | $Connection = new Connection($this->db); |
1582 | - if (!$Connection->tableExists('countries')) return ''; |
|
1667 | + if (!$Connection->tableExists('countries')) { |
|
1668 | + return ''; |
|
1669 | + } |
|
1583 | 1670 | |
1584 | 1671 | try { |
1585 | 1672 | $query = "SELECT name,iso2,iso3 FROM countries WHERE iso2 = :iso2 LIMIT 1"; |
@@ -1591,9 +1678,13 @@ discard block |
||
1591 | 1678 | $sth->closeCursor(); |
1592 | 1679 | if (count($row) > 0) { |
1593 | 1680 | return $row; |
1594 | - } else return ''; |
|
1681 | + } else { |
|
1682 | + return ''; |
|
1683 | + } |
|
1595 | 1684 | } catch (PDOException $e) { |
1596 | - if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n"; |
|
1685 | + if (isset($globalDebug) && $globalDebug) { |
|
1686 | + echo 'Error : '.$e->getMessage()."\n"; |
|
1687 | + } |
|
1597 | 1688 | return ''; |
1598 | 1689 | } |
1599 | 1690 | |
@@ -1611,7 +1702,9 @@ discard block |
||
1611 | 1702 | { |
1612 | 1703 | global $globalBitlyAccessToken; |
1613 | 1704 | |
1614 | - if ($globalBitlyAccessToken == '') return $url; |
|
1705 | + if ($globalBitlyAccessToken == '') { |
|
1706 | + return $url; |
|
1707 | + } |
|
1615 | 1708 | |
1616 | 1709 | $google_url = 'https://api-ssl.bitly.com/v3/shorten?access_token='.$globalBitlyAccessToken.'&longUrl='.$url; |
1617 | 1710 |
@@ -45,7 +45,9 @@ discard block |
||
45 | 45 | |
46 | 46 | public function checkAll() { |
47 | 47 | global $globalDebug; |
48 | - if ($globalDebug) echo "Update last seen tracked data...\n"; |
|
48 | + if ($globalDebug) { |
|
49 | + echo "Update last seen tracked data...\n"; |
|
50 | + } |
|
49 | 51 | foreach ($this->all_tracked as $key => $flight) { |
50 | 52 | if (isset($this->all_tracked[$key]['id'])) { |
51 | 53 | //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].' '.$this->all_tracked[$key]['longitude']."\n"; |
@@ -58,12 +60,16 @@ discard block |
||
58 | 60 | public function del() { |
59 | 61 | global $globalDebug; |
60 | 62 | // Delete old infos |
61 | - if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
|
63 | + if ($globalDebug) { |
|
64 | + echo 'Delete old values and update latest data...'."\n"; |
|
65 | + } |
|
62 | 66 | foreach ($this->all_tracked as $key => $flight) { |
63 | 67 | if (isset($flight['lastupdate'])) { |
64 | 68 | if ($flight['lastupdate'] < (time()-3000)) { |
65 | 69 | if (isset($this->all_tracked[$key]['id'])) { |
66 | - if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
|
70 | + if ($globalDebug) { |
|
71 | + echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
|
72 | + } |
|
67 | 73 | /* |
68 | 74 | $MarineLive = new MarineLive(); |
69 | 75 | $MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']); |
@@ -73,7 +79,9 @@ discard block |
||
73 | 79 | $Marine = new Marine($this->db); |
74 | 80 | if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') { |
75 | 81 | $result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed']); |
76 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
82 | + if ($globalDebug && $result != 'success') { |
|
83 | + echo '!!! ERROR : '.$result."\n"; |
|
84 | + } |
|
77 | 85 | } |
78 | 86 | // Put in archive |
79 | 87 | // $Marine->db = null; |
@@ -86,7 +94,9 @@ discard block |
||
86 | 94 | |
87 | 95 | public function add($line) { |
88 | 96 | global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked; |
89 | - if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02'; |
|
97 | + if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') { |
|
98 | + $globalCoordMinChange = '0.02'; |
|
99 | + } |
|
90 | 100 | date_default_timezone_set('UTC'); |
91 | 101 | $dataFound = false; |
92 | 102 | $send = false; |
@@ -111,8 +121,11 @@ discard block |
||
111 | 121 | |
112 | 122 | $Common = new Common(); |
113 | 123 | $AIS = new AIS(); |
114 | - if (!isset($line['id'])) $id = trim($line['mmsi']); |
|
115 | - else $id = trim($line['id']); |
|
124 | + if (!isset($line['id'])) { |
|
125 | + $id = trim($line['mmsi']); |
|
126 | + } else { |
|
127 | + $id = trim($line['id']); |
|
128 | + } |
|
116 | 129 | |
117 | 130 | if (!isset($this->all_tracked[$id])) { |
118 | 131 | $this->all_tracked[$id] = array(); |
@@ -120,10 +133,16 @@ discard block |
||
120 | 133 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '')); |
121 | 134 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time())); |
122 | 135 | if (!isset($line['id'])) { |
123 | - if (!isset($globalDaemon)) $globalDaemon = TRUE; |
|
136 | + if (!isset($globalDaemon)) { |
|
137 | + $globalDaemon = TRUE; |
|
138 | + } |
|
124 | 139 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi'))); |
125 | - } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
126 | - if ($globalAllTracked !== FALSE) $dataFound = true; |
|
140 | + } else { |
|
141 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
142 | + } |
|
143 | + if ($globalAllTracked !== FALSE) { |
|
144 | + $dataFound = true; |
|
145 | + } |
|
127 | 146 | } |
128 | 147 | |
129 | 148 | if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) { |
@@ -166,11 +185,17 @@ discard block |
||
166 | 185 | $Marine = new Marine($this->db); |
167 | 186 | $fromsource = NULL; |
168 | 187 | $result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource); |
169 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
188 | + if ($globalDebug && $result != 'success') { |
|
189 | + echo '!!! ERROR : '.$result."\n"; |
|
190 | + } |
|
170 | 191 | $Marine->db = null; |
171 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
192 | + if ($globalDebugTimeElapsed) { |
|
193 | + echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
194 | + } |
|
195 | + } |
|
196 | + if (!isset($this->all_tracked[$id]['id'])) { |
|
197 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
172 | 198 | } |
173 | - if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
174 | 199 | } |
175 | 200 | |
176 | 201 | if (isset($line['speed']) && $line['speed'] != '') { |
@@ -181,14 +206,21 @@ discard block |
||
181 | 206 | if ($distance > 1000 && $distance < 10000) { |
182 | 207 | $speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']); |
183 | 208 | $speed = $speed*3.6; |
184 | - if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed))); |
|
185 | - if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
|
209 | + if ($speed < 1000) { |
|
210 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed))); |
|
211 | + } |
|
212 | + if ($globalDebug) { |
|
213 | + echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
|
214 | + } |
|
186 | 215 | } |
187 | 216 | } |
188 | 217 | |
189 | 218 | if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
190 | - if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
191 | - else unset($timediff); |
|
219 | + if (isset($this->all_tracked[$id]['time_last_coord'])) { |
|
220 | + $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
221 | + } else { |
|
222 | + unset($timediff); |
|
223 | + } |
|
192 | 224 | if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) { |
193 | 225 | if (isset($this->all_tracked[$id]['archive_latitude']) && isset($this->all_tracked[$id]['archive_longitude']) && isset($this->all_tracked[$id]['livedb_latitude']) && isset($this->all_tracked[$id]['livedb_longitude'])) { |
194 | 226 | if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) { |
@@ -196,20 +228,30 @@ discard block |
||
196 | 228 | $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
197 | 229 | $this->all_tracked[$id]['putinarchive'] = true; |
198 | 230 | |
199 | - if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
|
231 | + if ($globalDebug) { |
|
232 | + echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
|
233 | + } |
|
200 | 234 | $timeelapsed = microtime(true); |
201 | 235 | $Marine = new Marine($this->db); |
202 | 236 | $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
203 | - if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
|
237 | + if (!empty($all_country)) { |
|
238 | + $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
|
239 | + } |
|
204 | 240 | $Marine->db = null; |
205 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
241 | + if ($globalDebugTimeElapsed) { |
|
242 | + echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
243 | + } |
|
206 | 244 | $this->tmd = 0; |
207 | - if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n"; |
|
245 | + if ($globalDebug) { |
|
246 | + echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n"; |
|
247 | + } |
|
208 | 248 | } |
209 | 249 | } |
210 | 250 | |
211 | 251 | if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
212 | - if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
|
252 | + if (!isset($this->all_tracked[$id]['archive_latitude'])) { |
|
253 | + $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
|
254 | + } |
|
213 | 255 | if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') { |
214 | 256 | $this->all_tracked[$id]['livedb_latitude'] = $line['latitude']; |
215 | 257 | $dataFound = true; |
@@ -218,8 +260,12 @@ discard block |
||
218 | 260 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude'])); |
219 | 261 | } |
220 | 262 | if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { |
221 | - if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
222 | - if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
|
263 | + if ($line['longitude'] > 180) { |
|
264 | + $line['longitude'] = $line['longitude'] - 360; |
|
265 | + } |
|
266 | + if (!isset($this->all_tracked[$id]['archive_longitude'])) { |
|
267 | + $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
|
268 | + } |
|
223 | 269 | if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') { |
224 | 270 | $this->all_tracked[$id]['livedb_longitude'] = $line['longitude']; |
225 | 271 | $dataFound = true; |
@@ -237,7 +283,9 @@ discard block |
||
237 | 283 | } |
238 | 284 | } |
239 | 285 | if (isset($line['last_update']) && $line['last_update'] != '') { |
240 | - if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
286 | + if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) { |
|
287 | + $dataFound = true; |
|
288 | + } |
|
241 | 289 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update'])); |
242 | 290 | } |
243 | 291 | if (isset($line['format_source']) && $line['format_source'] != '') { |
@@ -255,15 +303,21 @@ discard block |
||
255 | 303 | } |
256 | 304 | |
257 | 305 | if (isset($line['heading']) && $line['heading'] != '') { |
258 | - if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
306 | + if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) { |
|
307 | + $this->all_tracked[$id]['putinarchive'] = true; |
|
308 | + } |
|
259 | 309 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading']))); |
260 | 310 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true)); |
261 | 311 | //$dataFound = true; |
262 | 312 | } elseif (!isset($this->all_tracked[$id]['heading_fromsrc']) && isset($this->all_tracked[$id]['archive_latitude']) && $this->all_tracked[$id]['archive_latitude'] != $this->all_tracked[$id]['latitude'] && isset($this->all_tracked[$id]['archive_longitude']) && $this->all_tracked[$id]['archive_longitude'] != $this->all_tracked[$id]['longitude']) { |
263 | 313 | $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']); |
264 | 314 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading))); |
265 | - if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
266 | - if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
|
315 | + if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) { |
|
316 | + $this->all_tracked[$id]['putinarchive'] = true; |
|
317 | + } |
|
318 | + if ($globalDebug) { |
|
319 | + echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
|
320 | + } |
|
267 | 321 | } |
268 | 322 | //if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
269 | 323 | |
@@ -271,8 +325,11 @@ discard block |
||
271 | 325 | if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) { |
272 | 326 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime'])); |
273 | 327 | } else { |
274 | - if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n"; |
|
275 | - elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
328 | + if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) { |
|
329 | + echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n"; |
|
330 | + } elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) { |
|
331 | + echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
332 | + } |
|
276 | 333 | return ''; |
277 | 334 | } |
278 | 335 | } else { |
@@ -286,22 +343,35 @@ discard block |
||
286 | 343 | if ($this->all_tracked[$id]['addedMarine'] == 0) { |
287 | 344 | if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == '' || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
288 | 345 | if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) { |
289 | - if ($globalDebug) echo "Check if aircraft is already in DB..."; |
|
346 | + if ($globalDebug) { |
|
347 | + echo "Check if aircraft is already in DB..."; |
|
348 | + } |
|
290 | 349 | $timeelapsed = microtime(true); |
291 | 350 | $MarineLive = new MarineLive($this->db); |
292 | 351 | if (isset($line['id'])) { |
293 | 352 | $recent_ident = $MarineLive->checkIdRecent($line['id']); |
294 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
353 | + if ($globalDebugTimeElapsed) { |
|
354 | + echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
355 | + } |
|
295 | 356 | } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') { |
296 | 357 | $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']); |
297 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
358 | + if ($globalDebugTimeElapsed) { |
|
359 | + echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
360 | + } |
|
298 | 361 | } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') { |
299 | 362 | $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']); |
300 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
301 | - } else $recent_ident = ''; |
|
363 | + if ($globalDebugTimeElapsed) { |
|
364 | + echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
365 | + } |
|
366 | + } else { |
|
367 | + $recent_ident = ''; |
|
368 | + } |
|
302 | 369 | $MarineLive->db=null; |
303 | - if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
|
304 | - elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
|
370 | + if ($globalDebug && $recent_ident == '') { |
|
371 | + echo " Not in DB.\n"; |
|
372 | + } elseif ($globalDebug && $recent_ident != '') { |
|
373 | + echo " Already in DB.\n"; |
|
374 | + } |
|
305 | 375 | } else { |
306 | 376 | $recent_ident = ''; |
307 | 377 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0)); |
@@ -309,16 +379,24 @@ discard block |
||
309 | 379 | //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
310 | 380 | if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') |
311 | 381 | { |
312 | - if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : "; |
|
382 | + if ($globalDebug) { |
|
383 | + echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : "; |
|
384 | + } |
|
313 | 385 | //adds the spotter data for the archive |
314 | 386 | $highlight = ''; |
315 | - if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi'))); |
|
387 | + if (!isset($this->all_tracked[$id]['id'])) { |
|
388 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi'))); |
|
389 | + } |
|
316 | 390 | $timeelapsed = microtime(true); |
317 | 391 | $Marine = new Marine($this->db); |
318 | 392 | $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']); |
319 | 393 | $Marine->db = null; |
320 | - if ($globalDebug && isset($result)) echo $result."\n"; |
|
321 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
394 | + if ($globalDebug && isset($result)) { |
|
395 | + echo $result."\n"; |
|
396 | + } |
|
397 | + if ($globalDebugTimeElapsed) { |
|
398 | + echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
399 | + } |
|
322 | 400 | |
323 | 401 | /* |
324 | 402 | // Add source stat in DB |
@@ -352,12 +430,16 @@ discard block |
||
352 | 430 | $this->all_tracked[$id]['addedMarine'] = 1; |
353 | 431 | //print_r($this->all_tracked[$id]); |
354 | 432 | if ($this->last_delete == 0 || time() - $this->last_delete > 1800) { |
355 | - if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours..."; |
|
433 | + if ($globalDebug) { |
|
434 | + echo "---- Deleting Live Marine data older than 9 hours..."; |
|
435 | + } |
|
356 | 436 | //MarineLive->deleteLiveMarineDataNotUpdated(); |
357 | 437 | $MarineLive = new MarineLive($this->db); |
358 | 438 | $MarineLive->deleteLiveMarineData(); |
359 | 439 | $MarineLive->db=null; |
360 | - if ($globalDebug) echo " Done\n"; |
|
440 | + if ($globalDebug) { |
|
441 | + echo " Done\n"; |
|
442 | + } |
|
361 | 443 | $this->last_delete = time(); |
362 | 444 | } |
363 | 445 | } elseif ($recent_ident != '') { |
@@ -380,13 +462,17 @@ discard block |
||
380 | 462 | |
381 | 463 | if (!$ignoreImport) { |
382 | 464 | if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
383 | - if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : "; |
|
465 | + if ($globalDebug) { |
|
466 | + echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : "; |
|
467 | + } |
|
384 | 468 | $timeelapsed = microtime(true); |
385 | 469 | $MarineLive = new MarineLive($this->db); |
386 | 470 | $result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']); |
387 | 471 | $MarineLive->db = null; |
388 | 472 | $this->all_tracked[$id]['putinarchive'] = false; |
389 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
473 | + if ($globalDebugTimeElapsed) { |
|
474 | + echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
475 | + } |
|
390 | 476 | |
391 | 477 | // Put statistics in $this->stats variable |
392 | 478 | /* |
@@ -443,19 +529,29 @@ discard block |
||
443 | 529 | */ |
444 | 530 | |
445 | 531 | $this->all_tracked[$id]['lastupdate'] = time(); |
446 | - if ($this->all_tracked[$id]['putinarchive']) $send = true; |
|
447 | - if ($globalDebug) echo $result."\n"; |
|
448 | - } elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
|
532 | + if ($this->all_tracked[$id]['putinarchive']) { |
|
533 | + $send = true; |
|
534 | + } |
|
535 | + if ($globalDebug) { |
|
536 | + echo $result."\n"; |
|
537 | + } |
|
538 | + } elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) { |
|
539 | + echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
|
540 | + } |
|
449 | 541 | //$this->del(); |
450 | 542 | |
451 | 543 | |
452 | 544 | if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) { |
453 | - if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour..."; |
|
545 | + if ($globalDebug) { |
|
546 | + echo "---- Deleting Live Marine data Not updated since 2 hour..."; |
|
547 | + } |
|
454 | 548 | $MarineLive = new MarineLive($this->db); |
455 | 549 | $MarineLive->deleteLiveMarineDataNotUpdated(); |
456 | 550 | $MarineLive->db = null; |
457 | 551 | //MarineLive->deleteLiveMarineData(); |
458 | - if ($globalDebug) echo " Done\n"; |
|
552 | + if ($globalDebug) { |
|
553 | + echo " Done\n"; |
|
554 | + } |
|
459 | 555 | $this->last_delete_hourly = time(); |
460 | 556 | } |
461 | 557 | |
@@ -463,7 +559,9 @@ discard block |
||
463 | 559 | //$ignoreImport = false; |
464 | 560 | } |
465 | 561 | //if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN); |
466 | - if ($send) return $this->all_tracked[$id]; |
|
562 | + if ($send) { |
|
563 | + return $this->all_tracked[$id]; |
|
564 | + } |
|
467 | 565 | } |
468 | 566 | } |
469 | 567 | } |
@@ -35,7 +35,9 @@ discard block |
||
35 | 35 | $temp += 1; |
36 | 36 | $flat = (float)($temp / (60.0 * 10000.0)); |
37 | 37 | $flat *= -1.0; |
38 | - } else $flat = (float)($temp / (60.0 * 10000.0)); |
|
38 | + } else { |
|
39 | + $flat = (float)($temp / (60.0 * 10000.0)); |
|
40 | + } |
|
39 | 41 | return $flat; // float |
40 | 42 | } |
41 | 43 | |
@@ -47,7 +49,9 @@ discard block |
||
47 | 49 | $temp += 1; |
48 | 50 | $flon = (float)($temp / (60.0 * 10000.0)); |
49 | 51 | $flon *= -1.0; |
50 | - } else $flon = (float)($temp / (60.0 * 10000.0)); |
|
52 | + } else { |
|
53 | + $flon = (float)($temp / (60.0 * 10000.0)); |
|
54 | + } |
|
51 | 55 | return $flon; |
52 | 56 | } |
53 | 57 | |
@@ -70,10 +74,8 @@ discard block |
||
70 | 74 | */ |
71 | 75 | private function asciidec_2_8bit($ascii) { |
72 | 76 | //only process in the following range: 48-87, 96-119 |
73 | - if ($ascii < 48) { } |
|
74 | - else { |
|
75 | - if($ascii>119) { } |
|
76 | - else { |
|
77 | + if ($ascii < 48) { } else { |
|
78 | + if($ascii>119) { } else { |
|
77 | 79 | if ($ascii>87 && $ascii<96) ; |
78 | 80 | else { |
79 | 81 | $ascii=$ascii+40; |
@@ -175,7 +177,9 @@ discard block |
||
175 | 177 | $ro->lon = $this->make_lonf(bindec(substr($_aisdata,57,28))); |
176 | 178 | $ro->lat = $this->make_latf(bindec(substr($_aisdata,85,27))); |
177 | 179 | $ro->heading = bindec(substr($_aisdata,124,9)); |
178 | - if ($ro->heading == 511) $ro->heading = ''; |
|
180 | + if ($ro->heading == 511) { |
|
181 | + $ro->heading = ''; |
|
182 | + } |
|
179 | 183 | $ro->cls = 2; // class B |
180 | 184 | } else if ($ro->id == 19) { |
181 | 185 | $ro->cog = bindec(substr($_aisdata,112,12))/10; |
@@ -185,7 +189,9 @@ discard block |
||
185 | 189 | $ro->name = $this->binchar($_aisdata,143,120); |
186 | 190 | $ro->cls = 2; // class B |
187 | 191 | $ro->heading = bindec(substr($_aisdata,124,9)); |
188 | - if ($ro->heading == 511) $ro->heading = ''; |
|
192 | + if ($ro->heading == 511) { |
|
193 | + $ro->heading = ''; |
|
194 | + } |
|
189 | 195 | $ro->typeid = bindec(substr($_aisdata,263,8)); |
190 | 196 | $ro->type = $this->getShipType($ro->typeid); |
191 | 197 | //$ro->to_bow = bindec(substr($_aisdata,271,9)); |
@@ -216,9 +222,13 @@ discard block |
||
216 | 222 | $ro->cls = 2; // class B |
217 | 223 | } else if ($ro->id == 27) { |
218 | 224 | $ro->cog = bindec(substr($_aisdata,85,9)); |
219 | - if ($ro->cog == 511) $ro->cog = 0.0; |
|
225 | + if ($ro->cog == 511) { |
|
226 | + $ro->cog = 0.0; |
|
227 | + } |
|
220 | 228 | $ro->sog = bindec(substr($_aisdata,79,6)); |
221 | - if ($ro->sog == 63) $ro->sog = 0.0; |
|
229 | + if ($ro->sog == 63) { |
|
230 | + $ro->sog = 0.0; |
|
231 | + } |
|
222 | 232 | $ro->lon = $this->make_lonf(bindec(substr($_aisdata,44,18))*10); |
223 | 233 | $ro->lat = $this->make_latf(bindec(substr($_aisdata,62,17))*10); |
224 | 234 | $ro->cls = 1; // class A |
@@ -267,88 +277,171 @@ discard block |
||
267 | 277 | } |
268 | 278 | |
269 | 279 | public function getShipType($code) { |
270 | - if ($code == 0) return 'Not available (default)'; |
|
271 | - elseif ($code >= 1 && $code <= 19) return 'Reserved for future use'; |
|
272 | - elseif ($code == 20) return 'Wing in ground (WIG), all ships of this type'; |
|
273 | - elseif ($code == 21) return 'Wing in ground (WIG), Hazardous category A'; |
|
274 | - elseif ($code == 22) return 'Wing in ground (WIG), Hazardous category B'; |
|
275 | - elseif ($code == 23) return 'Wing in ground (WIG), Hazardous category C'; |
|
276 | - elseif ($code == 24) return 'Wing in ground (WIG), Hazardous category D'; |
|
277 | - elseif ($code == 25) return 'Wing in ground (WIG), Reserved for future use'; |
|
278 | - elseif ($code == 26) return 'Wing in ground (WIG), Reserved for future use'; |
|
279 | - elseif ($code == 27) return 'Wing in ground (WIG), Reserved for future use'; |
|
280 | - elseif ($code == 28) return 'Wing in ground (WIG), Reserved for future use'; |
|
281 | - elseif ($code == 29) return 'Wing in ground (WIG), Reserved for future use'; |
|
282 | - elseif ($code == 30) return 'Fishing'; |
|
283 | - elseif ($code == 31) return 'Towing'; |
|
284 | - elseif ($code == 32) return 'Towing: length exceeds 200m or breadth exceeds 25m'; |
|
285 | - elseif ($code == 33) return 'Dredging or underwater ops'; |
|
286 | - elseif ($code == 34) return 'Diving ops'; |
|
287 | - elseif ($code == 35) return 'Military ops'; |
|
288 | - elseif ($code == 36) return 'Sailing'; |
|
289 | - elseif ($code == 37) return 'Pleasure Craft'; |
|
290 | - elseif ($code == 38) return 'Reserved'; |
|
291 | - elseif ($code == 39) return 'Reserved'; |
|
292 | - elseif ($code == 40) return 'High speed craft (HSC), all ships of this type'; |
|
293 | - elseif ($code == 41) return 'High speed craft (HSC), Hazardous category A'; |
|
294 | - elseif ($code == 42) return 'High speed craft (HSC), Hazardous category B'; |
|
295 | - elseif ($code == 43) return 'High speed craft (HSC), Hazardous category C'; |
|
296 | - elseif ($code == 44) return 'High speed craft (HSC), Hazardous category D'; |
|
297 | - elseif ($code == 45) return 'High speed craft (HSC), Reserved for future use'; |
|
298 | - elseif ($code == 46) return 'High speed craft (HSC), Reserved for future use'; |
|
299 | - elseif ($code == 47) return 'High speed craft (HSC), Reserved for future use'; |
|
300 | - elseif ($code == 48) return 'High speed craft (HSC), Reserved for future use'; |
|
301 | - elseif ($code == 49) return 'High speed craft (HSC), No additional information'; |
|
302 | - elseif ($code == 50) return 'Pilot Vessel'; |
|
303 | - elseif ($code == 51) return 'Search and Rescue vessel'; |
|
304 | - elseif ($code == 52) return 'Tug'; |
|
305 | - elseif ($code == 53) return 'Port Tender'; |
|
306 | - elseif ($code == 54) return 'Anti-pollution equipment'; |
|
307 | - elseif ($code == 55) return 'Law Enforcement'; |
|
308 | - elseif ($code == 56) return 'Spare - Local Vessel'; |
|
309 | - elseif ($code == 57) return 'Spare - Local Vessel'; |
|
310 | - elseif ($code == 58) return 'Medical Transport'; |
|
311 | - elseif ($code == 59) return 'Noncombatant ship according to RR Resolution No. 18'; |
|
312 | - elseif ($code == 60) return 'Passenger, all ships of this type'; |
|
313 | - elseif ($code == 61) return 'Passenger, Hazardous category A'; |
|
314 | - elseif ($code == 62) return 'Passenger, Hazardous category B'; |
|
315 | - elseif ($code == 63) return 'Passenger, Hazardous category C'; |
|
316 | - elseif ($code == 64) return 'Passenger, Hazardous category D'; |
|
317 | - elseif ($code == 65) return 'Passenger, Reserved for future use'; |
|
318 | - elseif ($code == 66) return 'Passenger, Reserved for future use'; |
|
319 | - elseif ($code == 67) return 'Passenger, Reserved for future use'; |
|
320 | - elseif ($code == 68) return 'Passenger, Reserved for future use'; |
|
321 | - elseif ($code == 69) return 'Passenger, No additional information'; |
|
322 | - elseif ($code == 70) return 'Cargo, all ships of this type'; |
|
323 | - elseif ($code == 71) return 'Cargo, Hazardous category A'; |
|
324 | - elseif ($code == 72) return 'Cargo, Hazardous category B'; |
|
325 | - elseif ($code == 73) return 'Cargo, Hazardous category C'; |
|
326 | - elseif ($code == 74) return 'Cargo, Hazardous category D'; |
|
327 | - elseif ($code == 75) return 'Cargo, Reserved for future use'; |
|
328 | - elseif ($code == 76) return 'Cargo, Reserved for future use'; |
|
329 | - elseif ($code == 77) return 'Cargo, Reserved for future use'; |
|
330 | - elseif ($code == 78) return 'Cargo, Reserved for future use'; |
|
331 | - elseif ($code == 79) return 'Cargo, No additional information'; |
|
332 | - elseif ($code == 80) return 'Tanker, all ships of this type'; |
|
333 | - elseif ($code == 81) return 'Tanker, Hazardous category A'; |
|
334 | - elseif ($code == 82) return 'Tanker, Hazardous category B'; |
|
335 | - elseif ($code == 83) return 'Tanker, Hazardous category C'; |
|
336 | - elseif ($code == 84) return 'Tanker, Hazardous category D'; |
|
337 | - elseif ($code == 85) return 'Tanker, Reserved for future use'; |
|
338 | - elseif ($code == 86) return 'Tanker, Reserved for future use'; |
|
339 | - elseif ($code == 87) return 'Tanker, Reserved for future use'; |
|
340 | - elseif ($code == 88) return 'Tanker, Reserved for future use'; |
|
341 | - elseif ($code == 89) return 'Tanker, No additional information'; |
|
342 | - elseif ($code == 90) return 'Other Type, all ships of this type'; |
|
343 | - elseif ($code == 91) return 'Other Type, Hazardous category A'; |
|
344 | - elseif ($code == 92) return 'Other Type, Hazardous category B'; |
|
345 | - elseif ($code == 93) return 'Other Type, Hazardous category C'; |
|
346 | - elseif ($code == 94) return 'Other Type, Hazardous category D'; |
|
347 | - elseif ($code == 95) return 'Other Type, Reserved for future use'; |
|
348 | - elseif ($code == 96) return 'Other Type, Reserved for future use'; |
|
349 | - elseif ($code == 97) return 'Other Type, Reserved for future use'; |
|
350 | - elseif ($code == 98) return 'Other Type, Reserved for future use'; |
|
351 | - elseif ($code == 99) return 'Other Type, no additional information'; |
|
280 | + if ($code == 0) { |
|
281 | + return 'Not available (default)'; |
|
282 | + } elseif ($code >= 1 && $code <= 19) { |
|
283 | + return 'Reserved for future use'; |
|
284 | + } elseif ($code == 20) { |
|
285 | + return 'Wing in ground (WIG), all ships of this type'; |
|
286 | + } elseif ($code == 21) { |
|
287 | + return 'Wing in ground (WIG), Hazardous category A'; |
|
288 | + } elseif ($code == 22) { |
|
289 | + return 'Wing in ground (WIG), Hazardous category B'; |
|
290 | + } elseif ($code == 23) { |
|
291 | + return 'Wing in ground (WIG), Hazardous category C'; |
|
292 | + } elseif ($code == 24) { |
|
293 | + return 'Wing in ground (WIG), Hazardous category D'; |
|
294 | + } elseif ($code == 25) { |
|
295 | + return 'Wing in ground (WIG), Reserved for future use'; |
|
296 | + } elseif ($code == 26) { |
|
297 | + return 'Wing in ground (WIG), Reserved for future use'; |
|
298 | + } elseif ($code == 27) { |
|
299 | + return 'Wing in ground (WIG), Reserved for future use'; |
|
300 | + } elseif ($code == 28) { |
|
301 | + return 'Wing in ground (WIG), Reserved for future use'; |
|
302 | + } elseif ($code == 29) { |
|
303 | + return 'Wing in ground (WIG), Reserved for future use'; |
|
304 | + } elseif ($code == 30) { |
|
305 | + return 'Fishing'; |
|
306 | + } elseif ($code == 31) { |
|
307 | + return 'Towing'; |
|
308 | + } elseif ($code == 32) { |
|
309 | + return 'Towing: length exceeds 200m or breadth exceeds 25m'; |
|
310 | + } elseif ($code == 33) { |
|
311 | + return 'Dredging or underwater ops'; |
|
312 | + } elseif ($code == 34) { |
|
313 | + return 'Diving ops'; |
|
314 | + } elseif ($code == 35) { |
|
315 | + return 'Military ops'; |
|
316 | + } elseif ($code == 36) { |
|
317 | + return 'Sailing'; |
|
318 | + } elseif ($code == 37) { |
|
319 | + return 'Pleasure Craft'; |
|
320 | + } elseif ($code == 38) { |
|
321 | + return 'Reserved'; |
|
322 | + } elseif ($code == 39) { |
|
323 | + return 'Reserved'; |
|
324 | + } elseif ($code == 40) { |
|
325 | + return 'High speed craft (HSC), all ships of this type'; |
|
326 | + } elseif ($code == 41) { |
|
327 | + return 'High speed craft (HSC), Hazardous category A'; |
|
328 | + } elseif ($code == 42) { |
|
329 | + return 'High speed craft (HSC), Hazardous category B'; |
|
330 | + } elseif ($code == 43) { |
|
331 | + return 'High speed craft (HSC), Hazardous category C'; |
|
332 | + } elseif ($code == 44) { |
|
333 | + return 'High speed craft (HSC), Hazardous category D'; |
|
334 | + } elseif ($code == 45) { |
|
335 | + return 'High speed craft (HSC), Reserved for future use'; |
|
336 | + } elseif ($code == 46) { |
|
337 | + return 'High speed craft (HSC), Reserved for future use'; |
|
338 | + } elseif ($code == 47) { |
|
339 | + return 'High speed craft (HSC), Reserved for future use'; |
|
340 | + } elseif ($code == 48) { |
|
341 | + return 'High speed craft (HSC), Reserved for future use'; |
|
342 | + } elseif ($code == 49) { |
|
343 | + return 'High speed craft (HSC), No additional information'; |
|
344 | + } elseif ($code == 50) { |
|
345 | + return 'Pilot Vessel'; |
|
346 | + } elseif ($code == 51) { |
|
347 | + return 'Search and Rescue vessel'; |
|
348 | + } elseif ($code == 52) { |
|
349 | + return 'Tug'; |
|
350 | + } elseif ($code == 53) { |
|
351 | + return 'Port Tender'; |
|
352 | + } elseif ($code == 54) { |
|
353 | + return 'Anti-pollution equipment'; |
|
354 | + } elseif ($code == 55) { |
|
355 | + return 'Law Enforcement'; |
|
356 | + } elseif ($code == 56) { |
|
357 | + return 'Spare - Local Vessel'; |
|
358 | + } elseif ($code == 57) { |
|
359 | + return 'Spare - Local Vessel'; |
|
360 | + } elseif ($code == 58) { |
|
361 | + return 'Medical Transport'; |
|
362 | + } elseif ($code == 59) { |
|
363 | + return 'Noncombatant ship according to RR Resolution No. 18'; |
|
364 | + } elseif ($code == 60) { |
|
365 | + return 'Passenger, all ships of this type'; |
|
366 | + } elseif ($code == 61) { |
|
367 | + return 'Passenger, Hazardous category A'; |
|
368 | + } elseif ($code == 62) { |
|
369 | + return 'Passenger, Hazardous category B'; |
|
370 | + } elseif ($code == 63) { |
|
371 | + return 'Passenger, Hazardous category C'; |
|
372 | + } elseif ($code == 64) { |
|
373 | + return 'Passenger, Hazardous category D'; |
|
374 | + } elseif ($code == 65) { |
|
375 | + return 'Passenger, Reserved for future use'; |
|
376 | + } elseif ($code == 66) { |
|
377 | + return 'Passenger, Reserved for future use'; |
|
378 | + } elseif ($code == 67) { |
|
379 | + return 'Passenger, Reserved for future use'; |
|
380 | + } elseif ($code == 68) { |
|
381 | + return 'Passenger, Reserved for future use'; |
|
382 | + } elseif ($code == 69) { |
|
383 | + return 'Passenger, No additional information'; |
|
384 | + } elseif ($code == 70) { |
|
385 | + return 'Cargo, all ships of this type'; |
|
386 | + } elseif ($code == 71) { |
|
387 | + return 'Cargo, Hazardous category A'; |
|
388 | + } elseif ($code == 72) { |
|
389 | + return 'Cargo, Hazardous category B'; |
|
390 | + } elseif ($code == 73) { |
|
391 | + return 'Cargo, Hazardous category C'; |
|
392 | + } elseif ($code == 74) { |
|
393 | + return 'Cargo, Hazardous category D'; |
|
394 | + } elseif ($code == 75) { |
|
395 | + return 'Cargo, Reserved for future use'; |
|
396 | + } elseif ($code == 76) { |
|
397 | + return 'Cargo, Reserved for future use'; |
|
398 | + } elseif ($code == 77) { |
|
399 | + return 'Cargo, Reserved for future use'; |
|
400 | + } elseif ($code == 78) { |
|
401 | + return 'Cargo, Reserved for future use'; |
|
402 | + } elseif ($code == 79) { |
|
403 | + return 'Cargo, No additional information'; |
|
404 | + } elseif ($code == 80) { |
|
405 | + return 'Tanker, all ships of this type'; |
|
406 | + } elseif ($code == 81) { |
|
407 | + return 'Tanker, Hazardous category A'; |
|
408 | + } elseif ($code == 82) { |
|
409 | + return 'Tanker, Hazardous category B'; |
|
410 | + } elseif ($code == 83) { |
|
411 | + return 'Tanker, Hazardous category C'; |
|
412 | + } elseif ($code == 84) { |
|
413 | + return 'Tanker, Hazardous category D'; |
|
414 | + } elseif ($code == 85) { |
|
415 | + return 'Tanker, Reserved for future use'; |
|
416 | + } elseif ($code == 86) { |
|
417 | + return 'Tanker, Reserved for future use'; |
|
418 | + } elseif ($code == 87) { |
|
419 | + return 'Tanker, Reserved for future use'; |
|
420 | + } elseif ($code == 88) { |
|
421 | + return 'Tanker, Reserved for future use'; |
|
422 | + } elseif ($code == 89) { |
|
423 | + return 'Tanker, No additional information'; |
|
424 | + } elseif ($code == 90) { |
|
425 | + return 'Other Type, all ships of this type'; |
|
426 | + } elseif ($code == 91) { |
|
427 | + return 'Other Type, Hazardous category A'; |
|
428 | + } elseif ($code == 92) { |
|
429 | + return 'Other Type, Hazardous category B'; |
|
430 | + } elseif ($code == 93) { |
|
431 | + return 'Other Type, Hazardous category C'; |
|
432 | + } elseif ($code == 94) { |
|
433 | + return 'Other Type, Hazardous category D'; |
|
434 | + } elseif ($code == 95) { |
|
435 | + return 'Other Type, Reserved for future use'; |
|
436 | + } elseif ($code == 96) { |
|
437 | + return 'Other Type, Reserved for future use'; |
|
438 | + } elseif ($code == 97) { |
|
439 | + return 'Other Type, Reserved for future use'; |
|
440 | + } elseif ($code == 98) { |
|
441 | + return 'Other Type, Reserved for future use'; |
|
442 | + } elseif ($code == 99) { |
|
443 | + return 'Other Type, no additional information'; |
|
444 | + } |
|
352 | 445 | } |
353 | 446 | |
354 | 447 | public function process_ais_itu($_itu, $_len, $_filler, $aux /*, $ais_ch*/) { |
@@ -386,19 +479,34 @@ discard block |
||
386 | 479 | // assume 1st ! is valid |
387 | 480 | // find * ensure that it is at correct position |
388 | 481 | $end = strrpos ( $rawdata , '*' ); |
389 | - if ($end === FALSE) return -1; // check for NULLS!!! |
|
482 | + if ($end === FALSE) { |
|
483 | + return -1; |
|
484 | + } |
|
485 | + // check for NULLS!!! |
|
390 | 486 | $cs = substr( $rawdata, $end + 1 ); |
391 | - if ( strlen($cs) != 2 ) return -1; // correct cs length |
|
487 | + if ( strlen($cs) != 2 ) { |
|
488 | + return -1; |
|
489 | + } |
|
490 | + // correct cs length |
|
392 | 491 | $dcs = (int)hexdec( $cs ); |
393 | - for ( $alias=1; $alias<$end; $alias++) $chksum ^= ord( $rawdata[$alias] ); // perform XOR for NMEA checksum |
|
492 | + for ( $alias=1; $alias<$end; $alias++) { |
|
493 | + $chksum ^= ord( $rawdata[$alias] ); |
|
494 | + } |
|
495 | + // perform XOR for NMEA checksum |
|
394 | 496 | if ( $chksum == $dcs ) { // NMEA checksum pass |
395 | 497 | $pcs = explode(',', $rawdata); |
396 | 498 | // !AI??? identifier |
397 | 499 | $num_seq = (int)$pcs[1]; // number of sequences |
398 | 500 | $seq = (int)$pcs[2]; // get sequence |
399 | 501 | // get msg sequence id |
400 | - if ($pcs[3] == '') $msg_sid = -1; // non-multipart message, set to -1 |
|
401 | - else $msg_sid = (int)$pcs[3]; // multipart message |
|
502 | + if ($pcs[3] == '') { |
|
503 | + $msg_sid = -1; |
|
504 | + } |
|
505 | + // non-multipart message, set to -1 |
|
506 | + else { |
|
507 | + $msg_sid = (int)$pcs[3]; |
|
508 | + } |
|
509 | + // multipart message |
|
402 | 510 | $ais_ch = $pcs[4]; // get AIS channel |
403 | 511 | // message sequence checking |
404 | 512 | if ($num_seq < 1 || $num_seq > 9) { |
@@ -459,10 +567,18 @@ discard block |
||
459 | 567 | //DEBUG echo "[$start $end $tst]\n"; |
460 | 568 | $result = $this->process_ais_raw( $tst, "" ); |
461 | 569 | $last_pos = $end + 1; |
462 | - } else break; |
|
570 | + } else { |
|
571 | + break; |
|
572 | + } |
|
573 | + } |
|
574 | + if ($last_pos > 0) { |
|
575 | + $cbuf = substr($cbuf, $last_pos); |
|
463 | 576 | } |
464 | - if ($last_pos > 0) $cbuf = substr($cbuf, $last_pos); // move... |
|
465 | - if (strlen($cbuf) > 1024) $cbuf = ""; // prevent overflow simple mode... |
|
577 | + // move... |
|
578 | + if (strlen($cbuf) > 1024) { |
|
579 | + $cbuf = ""; |
|
580 | + } |
|
581 | + // prevent overflow simple mode... |
|
466 | 582 | return $result; |
467 | 583 | } |
468 | 584 | |
@@ -482,7 +598,9 @@ discard block |
||
482 | 598 | if ($lat<0.0) { |
483 | 599 | $lat = -$lat; |
484 | 600 | $neg=true; |
485 | - } else $neg=false; |
|
601 | + } else { |
|
602 | + $neg=false; |
|
603 | + } |
|
486 | 604 | $latd = 0x00000000; |
487 | 605 | $latd = intval ($lat * 600000.0); |
488 | 606 | if ($neg==true) { |
@@ -498,7 +616,9 @@ discard block |
||
498 | 616 | if ($lon<0.0) { |
499 | 617 | $lon = -$lon; |
500 | 618 | $neg=true; |
501 | - } else $neg=false; |
|
619 | + } else { |
|
620 | + $neg=false; |
|
621 | + } |
|
502 | 622 | $lond = 0x00000000; |
503 | 623 | $lond = intval ($lon * 600000.0); |
504 | 624 | if ($neg==true) { |
@@ -511,9 +631,14 @@ discard block |
||
511 | 631 | |
512 | 632 | private function char2bin($name, $max_len) { |
513 | 633 | $len = strlen($name); |
514 | - if ($len > $max_len) $name = substr($name,0,$max_len); |
|
515 | - if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len) * 6); |
|
516 | - else $pad = ''; |
|
634 | + if ($len > $max_len) { |
|
635 | + $name = substr($name,0,$max_len); |
|
636 | + } |
|
637 | + if ($len < $max_len) { |
|
638 | + $pad = str_repeat('0', ($max_len - $len) * 6); |
|
639 | + } else { |
|
640 | + $pad = ''; |
|
641 | + } |
|
517 | 642 | $rv = ''; |
518 | 643 | $ais_chars = array( |
519 | 644 | '@'=>0, 'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 'I'=>9, |
@@ -526,9 +651,12 @@ discard block |
||
526 | 651 | ); |
527 | 652 | // " |
528 | 653 | $_a = str_split($name); |
529 | - if ($_a) foreach ($_a as $_1) { |
|
654 | + if ($_a) { |
|
655 | + foreach ($_a as $_1) { |
|
530 | 656 | if (isset($ais_chars[$_1])) $dec = $ais_chars[$_1]; |
531 | - else $dec = 0; |
|
657 | + } else { |
|
658 | + $dec = 0; |
|
659 | + } |
|
532 | 660 | $bin = str_pad(decbin( $dec ), 6, '0', STR_PAD_LEFT); |
533 | 661 | $rv .= $bin; |
534 | 662 | //echo "$_1 $dec ($bin)<br/>"; |
@@ -540,7 +668,9 @@ discard block |
||
540 | 668 | $len_bit = strlen($_enc); |
541 | 669 | $rem6 = $len_bit % 6; |
542 | 670 | $pad6_len = 0; |
543 | - if ($rem6) $pad6_len = 6 - $rem6; |
|
671 | + if ($rem6) { |
|
672 | + $pad6_len = 6 - $rem6; |
|
673 | + } |
|
544 | 674 | //echo $pad6_len.'<br>'; |
545 | 675 | $_enc .= str_repeat("0", $pad6_len); // pad the text... |
546 | 676 | $len_enc = strlen($_enc) / 6; |
@@ -549,8 +679,11 @@ discard block |
||
549 | 679 | for ($i=0; $i<$len_enc; $i++) { |
550 | 680 | $offset = $i * 6; |
551 | 681 | $dec = bindec(substr($_enc,$offset,6)); |
552 | - if ($dec < 40) $dec += 48; |
|
553 | - else $dec += 56; |
|
682 | + if ($dec < 40) { |
|
683 | + $dec += 48; |
|
684 | + } else { |
|
685 | + $dec += 56; |
|
686 | + } |
|
554 | 687 | //echo chr($dec)." $dec<br/>"; |
555 | 688 | $itu .= chr($dec); |
556 | 689 | } |
@@ -563,25 +696,41 @@ discard block |
||
563 | 696 | } |
564 | 697 | $hex_arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); |
565 | 698 | $lsb = $chksum & 0x0F; |
566 | - if ($lsb >=0 && $lsb <= 15 ) $lsbc = $hex_arr[$lsb]; |
|
567 | - else $lsbc = '0'; |
|
699 | + if ($lsb >=0 && $lsb <= 15 ) { |
|
700 | + $lsbc = $hex_arr[$lsb]; |
|
701 | + } else { |
|
702 | + $lsbc = '0'; |
|
703 | + } |
|
568 | 704 | $msb = (($chksum & 0xF0) >> 4) & 0x0F; |
569 | - if ($msb >=0 && $msb <= 15 ) $msbc = $hex_arr[$msb]; |
|
570 | - else $msbc = '0'; |
|
705 | + if ($msb >=0 && $msb <= 15 ) { |
|
706 | + $msbc = $hex_arr[$msb]; |
|
707 | + } else { |
|
708 | + $msbc = '0'; |
|
709 | + } |
|
571 | 710 | $itu = '!'.$itu."*{$msbc}{$lsbc}\r\n"; |
572 | 711 | return $itu; |
573 | 712 | } |
574 | 713 | |
575 | 714 | public function parse($buffer) { |
576 | 715 | $data = $this->process_ais_buf($buffer); |
577 | - if (!is_object($data)) return array(); |
|
578 | - if ($data->lon != 0) $result['longitude'] = $data->lon; |
|
579 | - if ($data->lat != 0) $result['latitude'] = $data->lat; |
|
716 | + if (!is_object($data)) { |
|
717 | + return array(); |
|
718 | + } |
|
719 | + if ($data->lon != 0) { |
|
720 | + $result['longitude'] = $data->lon; |
|
721 | + } |
|
722 | + if ($data->lat != 0) { |
|
723 | + $result['latitude'] = $data->lat; |
|
724 | + } |
|
580 | 725 | $result['ident'] = trim($data->name); |
581 | 726 | $result['timestamp'] = $data->ts; |
582 | 727 | $result['mmsi'] = $data->mmsi; |
583 | - if ($data->sog != -1.0) $result['speed'] = $data->sog; |
|
584 | - if ($data->cog != 0) $result['heading'] = $data->cog; |
|
728 | + if ($data->sog != -1.0) { |
|
729 | + $result['speed'] = $data->sog; |
|
730 | + } |
|
731 | + if ($data->cog != 0) { |
|
732 | + $result['heading'] = $data->cog; |
|
733 | + } |
|
585 | 734 | /* |
586 | 735 | $ro->cls = 0; // AIS class undefined, also indicate unparsed msg |
587 | 736 | $ro->id = bindec(substr($_aisdata,0,6)); |
@@ -591,15 +740,25 @@ discard block |
||
591 | 740 | |
592 | 741 | public function mmsitype($mmsi) { |
593 | 742 | if (strlen($mmsi) == 9) { |
594 | - if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS'; |
|
595 | - elseif (substr($mmsi,0,3) == '972') return 'MOB (Man Overboard) device'; |
|
596 | - elseif (substr($mmsi,0,3) == '970') return 'AIS SART (Search and Rescue Transmitter)'; |
|
597 | - elseif (substr($mmsi,0,3) == '111') return 'SAR (Search and Rescue) aircraft'; |
|
598 | - elseif (substr($mmsi,0,2) == '98') return 'Auxiliary craft associated with a parent ship'; |
|
599 | - elseif (substr($mmsi,0,2) == '99') return 'Aids to Navigation'; |
|
600 | - elseif (substr($mmsi,0,2) == '00') return 'Coastal stations'; |
|
601 | - elseif (substr($mmsi,0,1) == '0') return 'Group of ships'; |
|
602 | - else return 'Ship'; |
|
743 | + if (substr($mmsi,0,3) == '974') { |
|
744 | + return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS'; |
|
745 | + } elseif (substr($mmsi,0,3) == '972') { |
|
746 | + return 'MOB (Man Overboard) device'; |
|
747 | + } elseif (substr($mmsi,0,3) == '970') { |
|
748 | + return 'AIS SART (Search and Rescue Transmitter)'; |
|
749 | + } elseif (substr($mmsi,0,3) == '111') { |
|
750 | + return 'SAR (Search and Rescue) aircraft'; |
|
751 | + } elseif (substr($mmsi,0,2) == '98') { |
|
752 | + return 'Auxiliary craft associated with a parent ship'; |
|
753 | + } elseif (substr($mmsi,0,2) == '99') { |
|
754 | + return 'Aids to Navigation'; |
|
755 | + } elseif (substr($mmsi,0,2) == '00') { |
|
756 | + return 'Coastal stations'; |
|
757 | + } elseif (substr($mmsi,0,1) == '0') { |
|
758 | + return 'Group of ships'; |
|
759 | + } else { |
|
760 | + return 'Ship'; |
|
761 | + } |
|
603 | 762 | } |
604 | 763 | |
605 | 764 | |
@@ -616,25 +775,48 @@ discard block |
||
616 | 775 | //if ($globalDebug) echo '==== Line format not supported : '.$buffer."\n"; |
617 | 776 | return array(); |
618 | 777 | } |
619 | - if ($data->lon != 0) $result['longitude'] = $data->lon; |
|
620 | - if ($data->lat != 0) $result['latitude'] = $data->lat; |
|
778 | + if ($data->lon != 0) { |
|
779 | + $result['longitude'] = $data->lon; |
|
780 | + } |
|
781 | + if ($data->lat != 0) { |
|
782 | + $result['latitude'] = $data->lat; |
|
783 | + } |
|
621 | 784 | $result['ident'] = trim(str_replace('@','',$data->name)); |
622 | 785 | $result['timestamp'] = $data->ts; |
623 | 786 | $result['mmsi'] = $data->mmsi; |
624 | - if (strlen($result['mmsi']) == 8 && susbtr($result['mmsi'],0,3) == '669') $result['mmsi'] = '3'.$result['mmsi']; |
|
787 | + if (strlen($result['mmsi']) == 8 && susbtr($result['mmsi'],0,3) == '669') { |
|
788 | + $result['mmsi'] = '3'.$result['mmsi']; |
|
789 | + } |
|
625 | 790 | $result['mmsi_type'] = $this->mmsitype($result['mmsi']); |
626 | - if ($data->sog != -1.0) $result['speed'] = $data->sog; |
|
627 | - if ($data->heading != '') $result['heading'] = $data->heading; |
|
628 | - elseif ($data->cog != 0) $result['heading'] = $data->cog; |
|
629 | - if ($data->status != '') $result['status'] = $data->status; |
|
630 | - if ($data->type != '') $result['type'] = $data->type; |
|
631 | - if ($data->typeid != '') $result['typeid'] = $data->typeid; |
|
632 | - if ($data->imo != '') $result['imo'] = $data->imo; |
|
633 | - if ($data->callsign != '') $result['callsign'] = $data->callsign; |
|
791 | + if ($data->sog != -1.0) { |
|
792 | + $result['speed'] = $data->sog; |
|
793 | + } |
|
794 | + if ($data->heading != '') { |
|
795 | + $result['heading'] = $data->heading; |
|
796 | + } elseif ($data->cog != 0) { |
|
797 | + $result['heading'] = $data->cog; |
|
798 | + } |
|
799 | + if ($data->status != '') { |
|
800 | + $result['status'] = $data->status; |
|
801 | + } |
|
802 | + if ($data->type != '') { |
|
803 | + $result['type'] = $data->type; |
|
804 | + } |
|
805 | + if ($data->typeid != '') { |
|
806 | + $result['typeid'] = $data->typeid; |
|
807 | + } |
|
808 | + if ($data->imo != '') { |
|
809 | + $result['imo'] = $data->imo; |
|
810 | + } |
|
811 | + if ($data->callsign != '') { |
|
812 | + $result['callsign'] = $data->callsign; |
|
813 | + } |
|
634 | 814 | if ($data->eta_month != '' && $data->eta_day != '' && $data->eta_hour != '' && $data->eta_minute != '') { |
635 | 815 | $result['eta_ts'] = strtotime(date('Y').'-'.$data->eta_month.'-'.$data->eta_day.' '.$data->eta_hour.':'.$data->eta_minute.':00'); |
636 | 816 | } |
637 | - if ($data->destination != '') $result['destination'] = $data->destination; |
|
817 | + if ($data->destination != '') { |
|
818 | + $result['destination'] = $data->destination; |
|
819 | + } |
|
638 | 820 | $result['all'] = (array) $data; |
639 | 821 | /* |
640 | 822 | $ro->cls = 0; // AIS class undefined, also indicate unparsed msg |
@@ -37,8 +37,11 @@ discard block |
||
37 | 37 | } else { |
38 | 38 | curl_setopt($ch, CURLOPT_USERAGENT, $useragent); |
39 | 39 | } |
40 | - if ($timeout == '') curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
|
41 | - else curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
|
40 | + if ($timeout == '') { |
|
41 | + curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
|
42 | + } else { |
|
43 | + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
|
44 | + } |
|
42 | 45 | curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common',"curlResponseHeaderCallback")); |
43 | 46 | if ($type == 'post') { |
44 | 47 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
@@ -85,8 +88,9 @@ discard block |
||
85 | 88 | private function curlResponseHeaderCallback($ch, $headerLine) { |
86 | 89 | //global $cookies; |
87 | 90 | $cookies = array(); |
88 | - if (preg_match('/^Set-Cookie:\s*([^;]*)/mi', $headerLine, $cookie) == 1) |
|
89 | - $cookies[] = $cookie; |
|
91 | + if (preg_match('/^Set-Cookie:\s*([^;]*)/mi', $headerLine, $cookie) == 1) { |
|
92 | + $cookies[] = $cookie; |
|
93 | + } |
|
90 | 94 | return strlen($headerLine); // Needed by curl |
91 | 95 | } |
92 | 96 | |
@@ -97,11 +101,15 @@ discard block |
||
97 | 101 | curl_setopt($ch, CURLOPT_URL, $url); |
98 | 102 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
99 | 103 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
100 | - if ($referer != '') curl_setopt($ch, CURLOPT_REFERER, $referer); |
|
104 | + if ($referer != '') { |
|
105 | + curl_setopt($ch, CURLOPT_REFERER, $referer); |
|
106 | + } |
|
101 | 107 | curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5'); |
102 | 108 | curl_setopt($ch, CURLOPT_FILE, $fp); |
103 | 109 | curl_exec($ch); |
104 | - if (curl_errno($ch) && $globalDebug) echo 'Download error: '.curl_error($ch); |
|
110 | + if (curl_errno($ch) && $globalDebug) { |
|
111 | + echo 'Download error: '.curl_error($ch); |
|
112 | + } |
|
105 | 113 | curl_close($ch); |
106 | 114 | fclose($fp); |
107 | 115 | } |
@@ -112,10 +120,16 @@ discard block |
||
112 | 120 | * @return Array array of the tables in HTML page |
113 | 121 | */ |
114 | 122 | public function table2array($data) { |
115 | - if (!is_string($data)) return array(); |
|
116 | - if ($data == '') return array(); |
|
123 | + if (!is_string($data)) { |
|
124 | + return array(); |
|
125 | + } |
|
126 | + if ($data == '') { |
|
127 | + return array(); |
|
128 | + } |
|
117 | 129 | $html = str_get_html($data); |
118 | - if ($html === false) return array(); |
|
130 | + if ($html === false) { |
|
131 | + return array(); |
|
132 | + } |
|
119 | 133 | $tabledata=array(); |
120 | 134 | foreach($html->find('tr') as $element) |
121 | 135 | { |
@@ -150,7 +164,9 @@ discard block |
||
150 | 164 | */ |
151 | 165 | public function text2array($data) { |
152 | 166 | $html = str_get_html($data); |
153 | - if ($html === false) return array(); |
|
167 | + if ($html === false) { |
|
168 | + return array(); |
|
169 | + } |
|
154 | 170 | $tabledata=array(); |
155 | 171 | foreach($html->find('p') as $element) |
156 | 172 | { |
@@ -171,7 +187,9 @@ discard block |
||
171 | 187 | * @return Float Distance in $unit |
172 | 188 | */ |
173 | 189 | public function distance($lat, $lon, $latc, $lonc, $unit = 'km') { |
174 | - if ($lat == $latc && $lon == $lonc) return 0; |
|
190 | + if ($lat == $latc && $lon == $lonc) { |
|
191 | + return 0; |
|
192 | + } |
|
175 | 193 | $dist = rad2deg(acos(sin(deg2rad(floatval($lat)))*sin(deg2rad(floatval($latc)))+ cos(deg2rad(floatval($lat)))*cos(deg2rad(floatval($latc)))*cos(deg2rad(floatval($lon)-floatval($lonc)))))*60*1.1515; |
176 | 194 | if ($unit == "km") { |
177 | 195 | return round($dist * 1.609344); |
@@ -195,10 +213,16 @@ discard block |
||
195 | 213 | public function withinThreshold ($timeDifference, $distance) { |
196 | 214 | $x = abs($timeDifference); |
197 | 215 | $d = abs($distance); |
198 | - if ($x == 0 || $d == 0) return true; |
|
216 | + if ($x == 0 || $d == 0) { |
|
217 | + return true; |
|
218 | + } |
|
199 | 219 | // may be due to Internet jitter; distance is realistic |
200 | - if ($x < 0.7 && $d < 2000) return true; |
|
201 | - else return $d/$x < 1500*0.27778; // 1500 km/h max |
|
220 | + if ($x < 0.7 && $d < 2000) { |
|
221 | + return true; |
|
222 | + } else { |
|
223 | + return $d/$x < 1500*0.27778; |
|
224 | + } |
|
225 | + // 1500 km/h max |
|
202 | 226 | } |
203 | 227 | |
204 | 228 | |
@@ -226,11 +250,17 @@ discard block |
||
226 | 250 | |
227 | 251 | public function convertDM($coord,$latlong) { |
228 | 252 | if ($latlong == 'latitude') { |
229 | - if ($coord < 0) $NSEW = 'S'; |
|
230 | - else $NSEW = 'N'; |
|
253 | + if ($coord < 0) { |
|
254 | + $NSEW = 'S'; |
|
255 | + } else { |
|
256 | + $NSEW = 'N'; |
|
257 | + } |
|
231 | 258 | } elseif ($latlong == 'longitude') { |
232 | - if ($coord < 0) $NSEW = 'W'; |
|
233 | - else $NSEW = 'E'; |
|
259 | + if ($coord < 0) { |
|
260 | + $NSEW = 'W'; |
|
261 | + } else { |
|
262 | + $NSEW = 'E'; |
|
263 | + } |
|
234 | 264 | } |
235 | 265 | $coord = abs($coord); |
236 | 266 | $deg = floor($coord); |
@@ -273,7 +303,9 @@ discard block |
||
273 | 303 | public function hex2str($hex) { |
274 | 304 | $str = ''; |
275 | 305 | $hexln = strlen($hex); |
276 | - for($i=0;$i<$hexln;$i+=2) $str .= chr(hexdec(substr($hex,$i,2))); |
|
306 | + for($i=0;$i<$hexln;$i+=2) { |
|
307 | + $str .= chr(hexdec(substr($hex,$i,2))); |
|
308 | + } |
|
277 | 309 | return $str; |
278 | 310 | } |
279 | 311 | |
@@ -301,8 +333,11 @@ discard block |
||
301 | 333 | $b = $lat2 - $lat1; |
302 | 334 | $c = -($a*$lat1+$b*$lon1); |
303 | 335 | $d = $a*$lat3+$b*$lon3+$c; |
304 | - if ($d > -$approx && $d < $approx) return true; |
|
305 | - else return false; |
|
336 | + if ($d > -$approx && $d < $approx) { |
|
337 | + return true; |
|
338 | + } else { |
|
339 | + return false; |
|
340 | + } |
|
306 | 341 | } |
307 | 342 | |
308 | 343 | public function array_merge_noappend() { |
@@ -361,7 +396,9 @@ discard block |
||
361 | 396 | return $result; |
362 | 397 | } |
363 | 398 | $handle = @opendir('./locale'); |
364 | - if ($handle === false) return $result; |
|
399 | + if ($handle === false) { |
|
400 | + return $result; |
|
401 | + } |
|
365 | 402 | while (false !== ($file = readdir($handle))) { |
366 | 403 | $path = './locale'.'/'.$file.'/LC_MESSAGES/fam.mo'; |
367 | 404 | if ($file != "." && $file != ".." && @file_exists($path)) { |
@@ -428,8 +465,9 @@ discard block |
||
428 | 465 | $error = false; |
429 | 466 | if ($fp_out = gzopen($dest, $mode)) { |
430 | 467 | if ($fp_in = fopen($source,'rb')) { |
431 | - while (!feof($fp_in)) |
|
432 | - gzwrite($fp_out, fread($fp_in, 1024 * 512)); |
|
468 | + while (!feof($fp_in)) { |
|
469 | + gzwrite($fp_out, fread($fp_in, 1024 * 512)); |
|
470 | + } |
|
433 | 471 | fclose($fp_in); |
434 | 472 | } else { |
435 | 473 | $error = true; |
@@ -438,14 +476,17 @@ discard block |
||
438 | 476 | } else { |
439 | 477 | $error = true; |
440 | 478 | } |
441 | - if ($error) |
|
442 | - return false; |
|
443 | - else |
|
444 | - return $dest; |
|
479 | + if ($error) { |
|
480 | + return false; |
|
481 | + } else { |
|
482 | + return $dest; |
|
483 | + } |
|
445 | 484 | } |
446 | 485 | |
447 | 486 | public function remove_accents($string) { |
448 | - if ( !preg_match('/[\x80-\xff]/', $string) ) return $string; |
|
487 | + if ( !preg_match('/[\x80-\xff]/', $string) ) { |
|
488 | + return $string; |
|
489 | + } |
|
449 | 490 | $chars = array( |
450 | 491 | // Decompositions for Latin-1 Supplement |
451 | 492 | chr(195).chr(128) => 'A', chr(195).chr(129) => 'A', |
@@ -569,7 +610,9 @@ discard block |
||
569 | 610 | $ip = gethostbyname($host); |
570 | 611 | $s = socket_create(AF_INET, SOCK_STREAM, 0); |
571 | 612 | $r = @socket_connect($s, $ip, $port); |
572 | - if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n"; |
|
613 | + if (!socket_set_nonblock($s)) { |
|
614 | + echo "Unable to set nonblock on socket\n"; |
|
615 | + } |
|
573 | 616 | if ($r || socket_last_error() == 114 || socket_last_error() == 115) { |
574 | 617 | return $s; |
575 | 618 | } |
@@ -107,17 +107,23 @@ discard block |
||
107 | 107 | |
108 | 108 | /* Check that end was found and body has at least one byte. */ |
109 | 109 | if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) { |
110 | - if ($globalDebug) echo '!!! APRS invalid : '.$input."\n"; |
|
110 | + if ($globalDebug) { |
|
111 | + echo '!!! APRS invalid : '.$input."\n"; |
|
112 | + } |
|
111 | 113 | return false; |
112 | 114 | } |
113 | 115 | |
114 | - if ($debug) echo 'input : '.$input."\n"; |
|
116 | + if ($debug) { |
|
117 | + echo 'input : '.$input."\n"; |
|
118 | + } |
|
115 | 119 | /* Save header and body. */ |
116 | 120 | $body = substr($input,$splitpos+1,$input_len); |
117 | 121 | $body_len = strlen($body); |
118 | 122 | $header = substr($input,0,$splitpos); |
119 | 123 | //$header_len = strlen($header); |
120 | - if ($debug) echo 'header : '.$header."\n"; |
|
124 | + if ($debug) { |
|
125 | + echo 'header : '.$header."\n"; |
|
126 | + } |
|
121 | 127 | |
122 | 128 | /* Parse source, target and path. */ |
123 | 129 | //FLRDF0A52>APRS,qAS,LSTB |
@@ -131,10 +137,14 @@ discard block |
||
131 | 137 | $result['format_source'] = 'famaprs'; |
132 | 138 | $result['source_type'] = 'ais'; |
133 | 139 | } else { |
134 | - if ($debug) echo 'ident : '.$ident."\n"; |
|
140 | + if ($debug) { |
|
141 | + echo 'ident : '.$ident."\n"; |
|
142 | + } |
|
135 | 143 | $result['ident'] = $ident; |
136 | 144 | } |
137 | - } else return false; |
|
145 | + } else { |
|
146 | + return false; |
|
147 | + } |
|
138 | 148 | $elements = explode(',',$all_elements); |
139 | 149 | $source = end($elements); |
140 | 150 | $result['source'] = $source; |
@@ -143,7 +153,9 @@ discard block |
||
143 | 153 | //echo "ok"; |
144 | 154 | //if ($element == 'TCPIP*') return false; |
145 | 155 | } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) { |
146 | - if ($debug) echo 'element : '.$element."\n"; |
|
156 | + if ($debug) { |
|
157 | + echo 'element : '.$element."\n"; |
|
158 | + } |
|
147 | 159 | return false; |
148 | 160 | } |
149 | 161 | /* |
@@ -156,11 +168,15 @@ discard block |
||
156 | 168 | } |
157 | 169 | |
158 | 170 | $type = substr($body,0,1); |
159 | - if ($debug) echo 'type : '.$type."\n"; |
|
171 | + if ($debug) { |
|
172 | + echo 'type : '.$type."\n"; |
|
173 | + } |
|
160 | 174 | if ($type == ';') { |
161 | 175 | if (isset($result['source_type']) && $result['source_type'] == 'modes') { |
162 | 176 | $result['address'] = trim(substr($body,1,9)); |
163 | - } else $result['ident'] = trim(substr($body,1,9)); |
|
177 | + } else { |
|
178 | + $result['ident'] = trim(substr($body,1,9)); |
|
179 | + } |
|
164 | 180 | } elseif ($type == ',') { |
165 | 181 | // Invalid data or test data |
166 | 182 | return false; |
@@ -228,7 +244,9 @@ discard block |
||
228 | 244 | //$symbol_table = $matches[4]; |
229 | 245 | $lat = intval($lat_deg); |
230 | 246 | $lon = intval($lon_deg); |
231 | - if ($lat > 89 || $lon > 179) return false; |
|
247 | + if ($lat > 89 || $lon > 179) { |
|
248 | + return false; |
|
249 | + } |
|
232 | 250 | |
233 | 251 | /* |
234 | 252 | $tmp_5b = str_replace('.','',$lat_min); |
@@ -238,8 +256,12 @@ discard block |
||
238 | 256 | */ |
239 | 257 | $latitude = $lat + floatval($lat_min)/60; |
240 | 258 | $longitude = $lon + floatval($lon_min)/60; |
241 | - if ($sind == 'S') $latitude = 0-$latitude; |
|
242 | - if ($wind == 'W') $longitude = 0-$longitude; |
|
259 | + if ($sind == 'S') { |
|
260 | + $latitude = 0-$latitude; |
|
261 | + } |
|
262 | + if ($wind == 'W') { |
|
263 | + $longitude = 0-$longitude; |
|
264 | + } |
|
243 | 265 | $result['latitude'] = $latitude; |
244 | 266 | $result['longitude'] = $longitude; |
245 | 267 | $body_parse = substr($body_parse,18); |
@@ -273,7 +295,9 @@ discard block |
||
273 | 295 | $body_parse = substr($body_parse,1); |
274 | 296 | $body_parse_len = strlen($body_parse); |
275 | 297 | $result['symbol_code'] = $symbol_code; |
276 | - if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code]; |
|
298 | + if (isset($this->symbols[$symbol_code])) { |
|
299 | + $result['symbol'] = $this->symbols[$symbol_code]; |
|
300 | + } |
|
277 | 301 | if ($symbol_code != '_') { |
278 | 302 | } |
279 | 303 | //$body_parse = substr($body_parse,1); |
@@ -284,7 +308,9 @@ discard block |
||
284 | 308 | if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
285 | 309 | $course = substr($body_parse,0,3); |
286 | 310 | $tmp_s = intval($course); |
287 | - if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course); |
|
311 | + if ($tmp_s >= 1 && $tmp_s <= 360) { |
|
312 | + $result['heading'] = intval($course); |
|
313 | + } |
|
288 | 314 | $speed = substr($body_parse,4,3); |
289 | 315 | if ($speed != '...') { |
290 | 316 | $result['speed'] = round($speed*1.852); |
@@ -322,10 +348,16 @@ discard block |
||
322 | 348 | $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
323 | 349 | $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
324 | 350 | |
325 | - if ($result['latitude'] < 0) $result['latitude'] -= $lat_off; |
|
326 | - else $result['latitude'] += $lat_off; |
|
327 | - if ($result['longitude'] < 0) $result['longitude'] -= $lon_off; |
|
328 | - else $result['longitude'] += $lon_off; |
|
351 | + if ($result['latitude'] < 0) { |
|
352 | + $result['latitude'] -= $lat_off; |
|
353 | + } else { |
|
354 | + $result['latitude'] += $lat_off; |
|
355 | + } |
|
356 | + if ($result['longitude'] < 0) { |
|
357 | + $result['longitude'] -= $lon_off; |
|
358 | + } else { |
|
359 | + $result['longitude'] += $lon_off; |
|
360 | + } |
|
329 | 361 | } |
330 | 362 | $body_parse = substr($body_parse,6); |
331 | 363 | } |
@@ -360,27 +392,48 @@ discard block |
||
360 | 392 | $address = substr($id,2); |
361 | 393 | //print_r($matches); |
362 | 394 | $addressType = (intval(substr($id,0,2),16))&3; |
363 | - if ($addressType == 0) $result['addresstype'] = "RANDOM"; |
|
364 | - elseif ($addressType == 1) $result['addresstype'] = "ICAO"; |
|
365 | - elseif ($addressType == 2) $result['addresstype'] = "FLARM"; |
|
366 | - elseif ($addressType == 3) $result['addresstype'] = "OGN"; |
|
395 | + if ($addressType == 0) { |
|
396 | + $result['addresstype'] = "RANDOM"; |
|
397 | + } elseif ($addressType == 1) { |
|
398 | + $result['addresstype'] = "ICAO"; |
|
399 | + } elseif ($addressType == 2) { |
|
400 | + $result['addresstype'] = "FLARM"; |
|
401 | + } elseif ($addressType == 3) { |
|
402 | + $result['addresstype'] = "OGN"; |
|
403 | + } |
|
367 | 404 | $aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2); |
368 | 405 | $result['aircrafttype_code'] = $aircraftType; |
369 | - if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN"; |
|
370 | - elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER"; |
|
371 | - elseif ($aircraftType == 2) $result['aircrafttype'] = "TOW_PLANE"; |
|
372 | - elseif ($aircraftType == 3) $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT"; |
|
373 | - elseif ($aircraftType == 4) $result['aircrafttype'] = "PARACHUTE"; |
|
374 | - elseif ($aircraftType == 5) $result['aircrafttype'] = "DROP_PLANE"; |
|
375 | - elseif ($aircraftType == 6) $result['aircrafttype'] = "HANG_GLIDER"; |
|
376 | - elseif ($aircraftType == 7) $result['aircrafttype'] = "PARA_GLIDER"; |
|
377 | - elseif ($aircraftType == 8) $result['aircrafttype'] = "POWERED_AIRCRAFT"; |
|
378 | - elseif ($aircraftType == 9) $result['aircrafttype'] = "JET_AIRCRAFT"; |
|
379 | - elseif ($aircraftType == 10) $result['aircrafttype'] = "UFO"; |
|
380 | - elseif ($aircraftType == 11) $result['aircrafttype'] = "BALLOON"; |
|
381 | - elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP"; |
|
382 | - elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV"; |
|
383 | - elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT"; |
|
406 | + if ($aircraftType == 0) { |
|
407 | + $result['aircrafttype'] = "UNKNOWN"; |
|
408 | + } elseif ($aircraftType == 1) { |
|
409 | + $result['aircrafttype'] = "GLIDER"; |
|
410 | + } elseif ($aircraftType == 2) { |
|
411 | + $result['aircrafttype'] = "TOW_PLANE"; |
|
412 | + } elseif ($aircraftType == 3) { |
|
413 | + $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT"; |
|
414 | + } elseif ($aircraftType == 4) { |
|
415 | + $result['aircrafttype'] = "PARACHUTE"; |
|
416 | + } elseif ($aircraftType == 5) { |
|
417 | + $result['aircrafttype'] = "DROP_PLANE"; |
|
418 | + } elseif ($aircraftType == 6) { |
|
419 | + $result['aircrafttype'] = "HANG_GLIDER"; |
|
420 | + } elseif ($aircraftType == 7) { |
|
421 | + $result['aircrafttype'] = "PARA_GLIDER"; |
|
422 | + } elseif ($aircraftType == 8) { |
|
423 | + $result['aircrafttype'] = "POWERED_AIRCRAFT"; |
|
424 | + } elseif ($aircraftType == 9) { |
|
425 | + $result['aircrafttype'] = "JET_AIRCRAFT"; |
|
426 | + } elseif ($aircraftType == 10) { |
|
427 | + $result['aircrafttype'] = "UFO"; |
|
428 | + } elseif ($aircraftType == 11) { |
|
429 | + $result['aircrafttype'] = "BALLOON"; |
|
430 | + } elseif ($aircraftType == 12) { |
|
431 | + $result['aircrafttype'] = "AIRSHIP"; |
|
432 | + } elseif ($aircraftType == 13) { |
|
433 | + $result['aircrafttype'] = "UAV"; |
|
434 | + } elseif ($aircraftType == 15) { |
|
435 | + $result['aircrafttype'] = "STATIC_OBJECT"; |
|
436 | + } |
|
384 | 437 | $stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0; |
385 | 438 | $result['stealth'] = $stealth; |
386 | 439 | $result['address'] = $address; |
@@ -420,13 +473,21 @@ discard block |
||
420 | 473 | $result['temp'] = round(5/9*(($matches[1])-32),1); |
421 | 474 | } |
422 | 475 | } |
423 | - } else $result['comment'] = trim($body_parse); |
|
476 | + } else { |
|
477 | + $result['comment'] = trim($body_parse); |
|
478 | + } |
|
424 | 479 | |
425 | 480 | } |
426 | 481 | //} |
427 | - if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4); |
|
428 | - if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4); |
|
429 | - if ($debug) print_r($result); |
|
482 | + if (isset($result['latitude'])) { |
|
483 | + $result['latitude'] = round($result['latitude'],4); |
|
484 | + } |
|
485 | + if (isset($result['longitude'])) { |
|
486 | + $result['longitude'] = round($result['longitude'],4); |
|
487 | + } |
|
488 | + if ($debug) { |
|
489 | + print_r($result); |
|
490 | + } |
|
430 | 491 | return $result; |
431 | 492 | } |
432 | 493 | |
@@ -435,12 +496,21 @@ discard block |
||
435 | 496 | $aprs_connect = 0; |
436 | 497 | $aprs_keep = 120; |
437 | 498 | $aprs_last_tx = time(); |
438 | - if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion; |
|
439 | - else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName); |
|
440 | - if (isset($globalServerAPRSssid)) $aprs_ssid = $globalServerAPRSssid; |
|
441 | - else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8); |
|
442 | - if (isset($globalServerAPRSpass)) $aprs_pass = $globalServerAPRSpass; |
|
443 | - else $aprs_pass = '-1'; |
|
499 | + if (isset($globalAPRSversion)) { |
|
500 | + $aprs_version = $globalAPRSversion; |
|
501 | + } else { |
|
502 | + $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName); |
|
503 | + } |
|
504 | + if (isset($globalServerAPRSssid)) { |
|
505 | + $aprs_ssid = $globalServerAPRSssid; |
|
506 | + } else { |
|
507 | + $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8); |
|
508 | + } |
|
509 | + if (isset($globalServerAPRSpass)) { |
|
510 | + $aprs_pass = $globalServerAPRSpass; |
|
511 | + } else { |
|
512 | + $aprs_pass = '-1'; |
|
513 | + } |
|
444 | 514 | |
445 | 515 | $aprs_filter = ''; |
446 | 516 | $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n"; |
@@ -467,9 +537,13 @@ discard block |
||
467 | 537 | } |
468 | 538 | |
469 | 539 | function send($data) { |
470 | - if ($this->connected === false) $this->connect(); |
|
540 | + if ($this->connected === false) { |
|
541 | + $this->connect(); |
|
542 | + } |
|
471 | 543 | $send = socket_send( $this->socket , $data , strlen($data),0); |
472 | - if ($send === FALSE) $this->connect(); |
|
544 | + if ($send === FALSE) { |
|
545 | + $this->connect(); |
|
546 | + } |
|
473 | 547 | } |
474 | 548 | } |
475 | 549 | |
@@ -486,18 +560,26 @@ discard block |
||
486 | 560 | //$w = '00'; |
487 | 561 | $custom = ''; |
488 | 562 | if ($ident != '') { |
489 | - if ($custom != '') $custom .= '/'; |
|
563 | + if ($custom != '') { |
|
564 | + $custom .= '/'; |
|
565 | + } |
|
490 | 566 | $custom .= 'CS='.$ident; |
491 | 567 | } |
492 | 568 | if ($squawk != '') { |
493 | - if ($custom != '') $custom .= '/'; |
|
569 | + if ($custom != '') { |
|
570 | + $custom .= '/'; |
|
571 | + } |
|
494 | 572 | $custom .= 'SQ='.$squawk; |
495 | 573 | } |
496 | 574 | if ($aircraft_icao != '' && $aircraft_icao != 'NA') { |
497 | - if ($custom != '') $custom .= '/'; |
|
575 | + if ($custom != '') { |
|
576 | + $custom .= '/'; |
|
577 | + } |
|
498 | 578 | $custom .= 'AI='.$aircraft_icao; |
499 | 579 | } |
500 | - if ($custom != '') $custom = ' '.$custom; |
|
580 | + if ($custom != '') { |
|
581 | + $custom = ' '.$custom; |
|
582 | + } |
|
501 | 583 | $this->send('AIRCRAFT>APRS,TCPIP*:;'.$hex.' *'.date('His',strtotime($datetime)).'h'.$coordinate.'^'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude_real,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n"); |
502 | 584 | } |
503 | 585 | } |
@@ -515,26 +597,38 @@ discard block |
||
515 | 597 | //$w = '00'; |
516 | 598 | $custom = ''; |
517 | 599 | if ($ident != '') { |
518 | - if ($custom != '') $custom .= '/'; |
|
600 | + if ($custom != '') { |
|
601 | + $custom .= '/'; |
|
602 | + } |
|
519 | 603 | $custom .= 'CS='.$ident; |
520 | 604 | } |
521 | 605 | if ($typeid != '') { |
522 | - if ($custom != '') $custom .= '/'; |
|
606 | + if ($custom != '') { |
|
607 | + $custom .= '/'; |
|
608 | + } |
|
523 | 609 | $custom .= 'TI='.$typeid; |
524 | 610 | } |
525 | 611 | if ($imo != '') { |
526 | - if ($custom != '') $custom .= '/'; |
|
612 | + if ($custom != '') { |
|
613 | + $custom .= '/'; |
|
614 | + } |
|
527 | 615 | $custom .= 'IMO='.$imo; |
528 | 616 | } |
529 | 617 | if ($arrival_date != '') { |
530 | - if ($custom != '') $custom .= '/'; |
|
618 | + if ($custom != '') { |
|
619 | + $custom .= '/'; |
|
620 | + } |
|
531 | 621 | $custom .= 'AD='.strtotime($arrival_date); |
532 | 622 | } |
533 | 623 | if ($arrival_code != '') { |
534 | - if ($custom != '') $custom .= '/'; |
|
624 | + if ($custom != '') { |
|
625 | + $custom .= '/'; |
|
626 | + } |
|
535 | 627 | $custom .= 'AC='.$arrival_code; |
536 | 628 | } |
537 | - if ($custom != '') $custom = ' '.$custom; |
|
629 | + if ($custom != '') { |
|
630 | + $custom = ' '.$custom; |
|
631 | + } |
|
538 | 632 | $altitude = 0; |
539 | 633 | $this->send('MARINE>APRS,TCPIP*:;'.$mmsi.'*'.date('His',strtotime($datetime)).'h'.$coordinate.'s'.str_pad($heading,3,'0',STR_PAD_LEFT).'/'.str_pad($speed,3,'0',STR_PAD_LEFT).'/A='.str_pad($altitude,6,'0',STR_PAD_LEFT).' !W'.$w.'!'.$custom."\n"); |
540 | 634 | } |
@@ -13,13 +13,17 @@ discard block |
||
13 | 13 | require_once(dirname(__FILE__).'/../require/class.SBS.php'); |
14 | 14 | require_once(dirname(__FILE__).'/../require/class.Connection.php'); |
15 | 15 | require_once(dirname(__FILE__).'/../require/class.Common.php'); |
16 | -if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php'); |
|
16 | +if (isset($globalTracker) && $globalTracker) { |
|
17 | + require_once(dirname(__FILE__).'/../require/class.TrackerImport.php'); |
|
18 | +} |
|
17 | 19 | if (isset($globalMarine) && $globalMarine) { |
18 | 20 | require_once(dirname(__FILE__).'/../require/class.AIS.php'); |
19 | 21 | require_once(dirname(__FILE__).'/../require/class.MarineImport.php'); |
20 | 22 | } |
21 | 23 | |
22 | -if (!isset($globalDebug)) $globalDebug = FALSE; |
|
24 | +if (!isset($globalDebug)) { |
|
25 | + $globalDebug = FALSE; |
|
26 | +} |
|
23 | 27 | |
24 | 28 | // Check if schema is at latest version |
25 | 29 | $Connection = new Connection(); |
@@ -59,20 +63,33 @@ discard block |
||
59 | 63 | $globalSources = array(); |
60 | 64 | $globalSources[] = array('host' => $options['source']); |
61 | 65 | } |
62 | -if (isset($options['nodaemon'])) $globalDaemon = FALSE; |
|
63 | -if (isset($options['server'])) $globalServer = TRUE; |
|
64 | -if (isset($options['idsource'])) $id_source = $options['idsource']; |
|
65 | -else $id_source = 1; |
|
66 | +if (isset($options['nodaemon'])) { |
|
67 | + $globalDaemon = FALSE; |
|
68 | +} |
|
69 | +if (isset($options['server'])) { |
|
70 | + $globalServer = TRUE; |
|
71 | +} |
|
72 | +if (isset($options['idsource'])) { |
|
73 | + $id_source = $options['idsource']; |
|
74 | +} else { |
|
75 | + $id_source = 1; |
|
76 | +} |
|
66 | 77 | if (isset($globalServer) && $globalServer) { |
67 | - if ($globalDebug) echo "Using Server Mode\n"; |
|
78 | + if ($globalDebug) { |
|
79 | + echo "Using Server Mode\n"; |
|
80 | + } |
|
68 | 81 | $SI=new SpotterServer(); |
69 | 82 | /* |
70 | 83 | require_once(dirname(__FILE__).'/../require/class.APRS.php'); |
71 | 84 | $SI = new adsb2aprs(); |
72 | 85 | $SI->connect(); |
73 | 86 | */ |
74 | -} else $SI=new SpotterImport($Connection->db); |
|
75 | -if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db); |
|
87 | +} else { |
|
88 | + $SI=new SpotterImport($Connection->db); |
|
89 | +} |
|
90 | +if (isset($globalTracker) && $globalTracker) { |
|
91 | + $TI = new TrackerImport($Connection->db); |
|
92 | +} |
|
76 | 93 | if (isset($globalMarine) && $globalMarine) { |
77 | 94 | $AIS = new AIS(); |
78 | 95 | $MI = new MarineImport($Connection->db); |
@@ -94,7 +111,9 @@ discard block |
||
94 | 111 | } |
95 | 112 | |
96 | 113 | // let's try and connect |
97 | -if ($globalDebug) echo "Connecting...\n"; |
|
114 | +if ($globalDebug) { |
|
115 | + echo "Connecting...\n"; |
|
116 | +} |
|
98 | 117 | $use_aprs = false; |
99 | 118 | $aprs_full = false; |
100 | 119 | $reset = 0; |
@@ -103,7 +122,9 @@ discard block |
||
103 | 122 | //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs; |
104 | 123 | global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context; |
105 | 124 | $reset++; |
106 | - if ($globalDebug) echo 'Connect to all...'."\n"; |
|
125 | + if ($globalDebug) { |
|
126 | + echo 'Connect to all...'."\n"; |
|
127 | + } |
|
107 | 128 | foreach ($hosts as $id => $value) { |
108 | 129 | $host = $value['host']; |
109 | 130 | $globalSources[$id]['last_exec'] = 0; |
@@ -113,27 +134,37 @@ discard block |
||
113 | 134 | //$formats[$id] = 'deltadbtxt'; |
114 | 135 | $globalSources[$id]['format'] = 'deltadbtxt'; |
115 | 136 | //$last_exec['deltadbtxt'] = 0; |
116 | - if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n"; |
|
137 | + if ($globalDebug) { |
|
138 | + echo "Connect to deltadb source (".$host.")...\n"; |
|
139 | + } |
|
117 | 140 | } else if (preg_match('/vatsim-data.txt$/i',$host)) { |
118 | 141 | //$formats[$id] = 'vatsimtxt'; |
119 | 142 | $globalSources[$id]['format'] = 'vatsimtxt'; |
120 | 143 | //$last_exec['vatsimtxt'] = 0; |
121 | - if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n"; |
|
144 | + if ($globalDebug) { |
|
145 | + echo "Connect to vatsim source (".$host.")...\n"; |
|
146 | + } |
|
122 | 147 | } else if (preg_match('/aircraftlist.json$/i',$host)) { |
123 | 148 | //$formats[$id] = 'aircraftlistjson'; |
124 | 149 | $globalSources[$id]['format'] = 'aircraftlistjson'; |
125 | 150 | //$last_exec['aircraftlistjson'] = 0; |
126 | - if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n"; |
|
151 | + if ($globalDebug) { |
|
152 | + echo "Connect to aircraftlist.json source (".$host.")...\n"; |
|
153 | + } |
|
127 | 154 | } else if (preg_match('/opensky/i',$host)) { |
128 | 155 | //$formats[$id] = 'aircraftlistjson'; |
129 | 156 | $globalSources[$id]['format'] = 'opensky'; |
130 | 157 | //$last_exec['aircraftlistjson'] = 0; |
131 | - if ($globalDebug) echo "Connect to opensky source (".$host.")...\n"; |
|
158 | + if ($globalDebug) { |
|
159 | + echo "Connect to opensky source (".$host.")...\n"; |
|
160 | + } |
|
132 | 161 | } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) { |
133 | 162 | //$formats[$id] = 'radarvirtueljson'; |
134 | 163 | $globalSources[$id]['format'] = 'radarvirtueljson'; |
135 | 164 | //$last_exec['radarvirtueljson'] = 0; |
136 | - if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n"; |
|
165 | + if ($globalDebug) { |
|
166 | + echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n"; |
|
167 | + } |
|
137 | 168 | if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
138 | 169 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
139 | 170 | exit(0); |
@@ -142,7 +173,9 @@ discard block |
||
142 | 173 | //$formats[$id] = 'planeupdatefaa'; |
143 | 174 | $globalSources[$id]['format'] = 'planeupdatefaa'; |
144 | 175 | //$last_exec['planeupdatefaa'] = 0; |
145 | - if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n"; |
|
176 | + if ($globalDebug) { |
|
177 | + echo "Connect to planeUpdateFAA.php source (".$host.")...\n"; |
|
178 | + } |
|
146 | 179 | if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
147 | 180 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
148 | 181 | exit(0); |
@@ -151,26 +184,36 @@ discard block |
||
151 | 184 | //$formats[$id] = 'phpvmacars'; |
152 | 185 | $globalSources[$id]['format'] = 'phpvmacars'; |
153 | 186 | //$last_exec['phpvmacars'] = 0; |
154 | - if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n"; |
|
187 | + if ($globalDebug) { |
|
188 | + echo "Connect to phpvmacars source (".$host.")...\n"; |
|
189 | + } |
|
155 | 190 | } else if (preg_match('/VAM-json.php$/i',$host)) { |
156 | 191 | //$formats[$id] = 'phpvmacars'; |
157 | 192 | $globalSources[$id]['format'] = 'vam'; |
158 | - if ($globalDebug) echo "Connect to Vam source (".$host.")...\n"; |
|
193 | + if ($globalDebug) { |
|
194 | + echo "Connect to Vam source (".$host.")...\n"; |
|
195 | + } |
|
159 | 196 | } else if (preg_match('/whazzup/i',$host)) { |
160 | 197 | //$formats[$id] = 'whazzup'; |
161 | 198 | $globalSources[$id]['format'] = 'whazzup'; |
162 | 199 | //$last_exec['whazzup'] = 0; |
163 | - if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n"; |
|
200 | + if ($globalDebug) { |
|
201 | + echo "Connect to whazzup source (".$host.")...\n"; |
|
202 | + } |
|
164 | 203 | } else if (preg_match('/recentpireps/i',$host)) { |
165 | 204 | //$formats[$id] = 'pirepsjson'; |
166 | 205 | $globalSources[$id]['format'] = 'pirepsjson'; |
167 | 206 | //$last_exec['pirepsjson'] = 0; |
168 | - if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n"; |
|
207 | + if ($globalDebug) { |
|
208 | + echo "Connect to pirepsjson source (".$host.")...\n"; |
|
209 | + } |
|
169 | 210 | } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) { |
170 | 211 | //$formats[$id] = 'fr24json'; |
171 | 212 | $globalSources[$id]['format'] = 'fr24json'; |
172 | 213 | //$last_exec['fr24json'] = 0; |
173 | - if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n"; |
|
214 | + if ($globalDebug) { |
|
215 | + echo "Connect to fr24 source (".$host.")...\n"; |
|
216 | + } |
|
174 | 217 | if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
175 | 218 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
176 | 219 | exit(0); |
@@ -179,7 +222,9 @@ discard block |
||
179 | 222 | //$formats[$id] = 'fr24json'; |
180 | 223 | $globalSources[$id]['format'] = 'myshiptracking'; |
181 | 224 | //$last_exec['fr24json'] = 0; |
182 | - if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n"; |
|
225 | + if ($globalDebug) { |
|
226 | + echo "Connect to myshiptracking source (".$host.")...\n"; |
|
227 | + } |
|
183 | 228 | if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
184 | 229 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
185 | 230 | exit(0); |
@@ -188,17 +233,24 @@ discard block |
||
188 | 233 | } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) { |
189 | 234 | //$formats[$id] = 'tsv'; |
190 | 235 | $globalSources[$id]['format'] = 'tsv'; |
191 | - if ($globalDebug) echo "Connect to tsv source (".$host.")...\n"; |
|
236 | + if ($globalDebug) { |
|
237 | + echo "Connect to tsv source (".$host.")...\n"; |
|
238 | + } |
|
192 | 239 | } |
193 | 240 | } elseif (filter_var($host,FILTER_VALIDATE_URL)) { |
194 | 241 | if ($globalSources[$id]['format'] == 'aisnmeahttp') { |
195 | 242 | $idf = fopen($globalSources[$id]['host'],'r',false,$context); |
196 | 243 | if ($idf !== false) { |
197 | 244 | $httpfeeds[$id] = $idf; |
198 | - if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
|
245 | + if ($globalDebug) { |
|
246 | + echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
|
247 | + } |
|
248 | + } elseif ($globalDebug) { |
|
249 | + echo "Can't connect to ".$globalSources[$id]['host']."\n"; |
|
199 | 250 | } |
200 | - elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n"; |
|
201 | - } elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
|
251 | + } elseif ($globalDebug) { |
|
252 | + echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
|
253 | + } |
|
202 | 254 | } elseif (!filter_var($host,FILTER_VALIDATE_URL)) { |
203 | 255 | $hostport = explode(':',$host); |
204 | 256 | if (isset($hostport[1])) { |
@@ -238,17 +290,25 @@ discard block |
||
238 | 290 | //$formats[$id] = 'beast'; |
239 | 291 | $globalSources[$id]['format'] = 'beast'; |
240 | 292 | //} else $formats[$id] = 'sbs'; |
241 | - } else $globalSources[$id]['format'] = 'sbs'; |
|
293 | + } else { |
|
294 | + $globalSources[$id]['format'] = 'sbs'; |
|
295 | + } |
|
242 | 296 | //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n"; |
243 | 297 | } |
244 | - if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n"; |
|
298 | + if ($globalDebug) { |
|
299 | + echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n"; |
|
300 | + } |
|
245 | 301 | } else { |
246 | - if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n"; |
|
302 | + if ($globalDebug) { |
|
303 | + echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n"; |
|
304 | + } |
|
247 | 305 | } |
248 | 306 | } |
249 | 307 | } |
250 | 308 | } |
251 | -if (!isset($globalMinFetch)) $globalMinFetch = 15; |
|
309 | +if (!isset($globalMinFetch)) { |
|
310 | + $globalMinFetch = 15; |
|
311 | +} |
|
252 | 312 | |
253 | 313 | // Initialize all |
254 | 314 | $status = array(); |
@@ -257,13 +317,19 @@ discard block |
||
257 | 317 | $formats = array(); |
258 | 318 | $last_exec = array(); |
259 | 319 | $time = time(); |
260 | -if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut; |
|
261 | -else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut; |
|
262 | -else $timeout = 20; |
|
320 | +if (isset($globalSourcesTimeout)) { |
|
321 | + $timeout = $globalSourcesTimeOut; |
|
322 | +} else if (isset($globalSBS1TimeOut)) { |
|
323 | + $timeout = $globalSBS1TimeOut; |
|
324 | +} else { |
|
325 | + $timeout = 20; |
|
326 | +} |
|
263 | 327 | $errno = ''; |
264 | 328 | $errstr=''; |
265 | 329 | |
266 | -if (!isset($globalDaemon)) $globalDaemon = TRUE; |
|
330 | +if (!isset($globalDaemon)) { |
|
331 | + $globalDaemon = TRUE; |
|
332 | +} |
|
267 | 333 | /* Initiate connections to all the hosts simultaneously */ |
268 | 334 | //connect_all($hosts); |
269 | 335 | //connect_all($globalSources); |
@@ -289,7 +355,9 @@ discard block |
||
289 | 355 | if (isset($source['format']) && $source['format'] == 'aprs') { |
290 | 356 | $aprs_connect = 0; |
291 | 357 | $use_aprs = true; |
292 | - if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true; |
|
358 | + if (isset($source['port']) && $source['port'] == '10152') { |
|
359 | + $aprs_full = true; |
|
360 | + } |
|
293 | 361 | break; |
294 | 362 | } |
295 | 363 | } |
@@ -300,26 +368,49 @@ discard block |
||
300 | 368 | $aprs_connect = 0; |
301 | 369 | $aprs_keep = 120; |
302 | 370 | $aprs_last_tx = time(); |
303 | - if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion; |
|
304 | - else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName); |
|
305 | - if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid; |
|
306 | - else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8); |
|
307 | - if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter; |
|
308 | - else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0'; |
|
309 | - if ($aprs_full) $aprs_filter = ''; |
|
310 | - if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass; |
|
311 | - else $aprs_pass = '-1'; |
|
371 | + if (isset($globalAPRSversion)) { |
|
372 | + $aprs_version = $globalAPRSversion; |
|
373 | + } else { |
|
374 | + $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName); |
|
375 | + } |
|
376 | + if (isset($globalAPRSssid)) { |
|
377 | + $aprs_ssid = $globalAPRSssid; |
|
378 | + } else { |
|
379 | + $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8); |
|
380 | + } |
|
381 | + if (isset($globalAPRSfilter)) { |
|
382 | + $aprs_filter = $globalAPRSfilter; |
|
383 | + } else { |
|
384 | + $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0'; |
|
385 | + } |
|
386 | + if ($aprs_full) { |
|
387 | + $aprs_filter = ''; |
|
388 | + } |
|
389 | + if (isset($globalAPRSpass)) { |
|
390 | + $aprs_pass = $globalAPRSpass; |
|
391 | + } else { |
|
392 | + $aprs_pass = '-1'; |
|
393 | + } |
|
312 | 394 | |
313 | - if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n"; |
|
314 | - else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n"; |
|
395 | + if ($aprs_filter != '') { |
|
396 | + $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n"; |
|
397 | + } else { |
|
398 | + $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n"; |
|
399 | + } |
|
315 | 400 | echo $aprs_login."\n"; |
316 | 401 | } |
317 | 402 | |
318 | 403 | // connected - lets do some work |
319 | -if ($globalDebug) echo "Connected!\n"; |
|
404 | +if ($globalDebug) { |
|
405 | + echo "Connected!\n"; |
|
406 | +} |
|
320 | 407 | sleep(1); |
321 | -if ($globalDebug) echo "SCAN MODE \n\n"; |
|
322 | -if (!isset($globalCronEnd)) $globalCronEnd = 60; |
|
408 | +if ($globalDebug) { |
|
409 | + echo "SCAN MODE \n\n"; |
|
410 | +} |
|
411 | +if (!isset($globalCronEnd)) { |
|
412 | + $globalCronEnd = 60; |
|
413 | +} |
|
323 | 414 | $endtime = time()+$globalCronEnd; |
324 | 415 | $i = 1; |
325 | 416 | $tt = array(); |
@@ -333,10 +424,14 @@ discard block |
||
333 | 424 | |
334 | 425 | // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time. |
335 | 426 | while ($i > 0) { |
336 | - if (!$globalDaemon) $i = $endtime-time(); |
|
427 | + if (!$globalDaemon) { |
|
428 | + $i = $endtime-time(); |
|
429 | + } |
|
337 | 430 | // Delete old ATC |
338 | 431 | if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) { |
339 | - if ($globalDebug) echo 'Delete old ATC...'."\n"; |
|
432 | + if ($globalDebug) { |
|
433 | + echo 'Delete old ATC...'."\n"; |
|
434 | + } |
|
340 | 435 | $ATC->deleteOldATC(); |
341 | 436 | } |
342 | 437 | |
@@ -344,10 +439,14 @@ discard block |
||
344 | 439 | if (count($last_exec) == count($globalSources)) { |
345 | 440 | $max = $globalMinFetch; |
346 | 441 | foreach ($last_exec as $last) { |
347 | - if ((time() - $last['last']) < $max) $max = time() - $last['last']; |
|
442 | + if ((time() - $last['last']) < $max) { |
|
443 | + $max = time() - $last['last']; |
|
444 | + } |
|
348 | 445 | } |
349 | 446 | if ($max != $globalMinFetch) { |
350 | - if ($globalDebug) echo 'Sleeping...'."\n"; |
|
447 | + if ($globalDebug) { |
|
448 | + echo 'Sleeping...'."\n"; |
|
449 | + } |
|
351 | 450 | sleep($globalMinFetch-$max+2); |
352 | 451 | } |
353 | 452 | } |
@@ -356,11 +455,15 @@ discard block |
||
356 | 455 | //foreach ($formats as $id => $value) { |
357 | 456 | foreach ($globalSources as $id => $value) { |
358 | 457 | date_default_timezone_set('UTC'); |
359 | - if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0; |
|
458 | + if (!isset($last_exec[$id]['last'])) { |
|
459 | + $last_exec[$id]['last'] = 0; |
|
460 | + } |
|
360 | 461 | if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
361 | 462 | //$buffer = $Common->getData($hosts[$id]); |
362 | 463 | $buffer = $Common->getData($value['host']); |
363 | - if ($buffer != '') $reset = 0; |
|
464 | + if ($buffer != '') { |
|
465 | + $reset = 0; |
|
466 | + } |
|
364 | 467 | $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
365 | 468 | $buffer = explode('\n',$buffer); |
366 | 469 | foreach ($buffer as $line) { |
@@ -369,19 +472,38 @@ discard block |
||
369 | 472 | $data = array(); |
370 | 473 | $data['hex'] = $line[1]; // hex |
371 | 474 | $data['ident'] = $line[2]; // ident |
372 | - if (isset($line[3])) $data['altitude'] = $line[3]; // altitude |
|
373 | - if (isset($line[4])) $data['speed'] = $line[4]; // speed |
|
374 | - if (isset($line[5])) $data['heading'] = $line[5]; // heading |
|
375 | - if (isset($line[6])) $data['latitude'] = $line[6]; // lat |
|
376 | - if (isset($line[7])) $data['longitude'] = $line[7]; // long |
|
475 | + if (isset($line[3])) { |
|
476 | + $data['altitude'] = $line[3]; |
|
477 | + } |
|
478 | + // altitude |
|
479 | + if (isset($line[4])) { |
|
480 | + $data['speed'] = $line[4]; |
|
481 | + } |
|
482 | + // speed |
|
483 | + if (isset($line[5])) { |
|
484 | + $data['heading'] = $line[5]; |
|
485 | + } |
|
486 | + // heading |
|
487 | + if (isset($line[6])) { |
|
488 | + $data['latitude'] = $line[6]; |
|
489 | + } |
|
490 | + // lat |
|
491 | + if (isset($line[7])) { |
|
492 | + $data['longitude'] = $line[7]; |
|
493 | + } |
|
494 | + // long |
|
377 | 495 | $data['verticalrate'] = ''; // vertical rate |
378 | 496 | //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk |
379 | 497 | $data['emergency'] = ''; // emergency |
380 | 498 | $data['datetime'] = date('Y-m-d H:i:s'); |
381 | 499 | $data['format_source'] = 'deltadbtxt'; |
382 | 500 | $data['id_source'] = $id_source; |
383 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
384 | - if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats']; |
|
501 | + if (isset($value['name']) && $value['name'] != '') { |
|
502 | + $data['source_name'] = $value['name']; |
|
503 | + } |
|
504 | + if (isset($value['sourcestats'])) { |
|
505 | + $data['sourcestats'] = $value['sourcestats']; |
|
506 | + } |
|
385 | 507 | $SI->add($data); |
386 | 508 | unset($data); |
387 | 509 | } |
@@ -391,7 +513,9 @@ discard block |
||
391 | 513 | date_default_timezone_set('CET'); |
392 | 514 | $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host'])); |
393 | 515 | date_default_timezone_set('UTC'); |
394 | - if ($buffer != '') $reset = 0; |
|
516 | + if ($buffer != '') { |
|
517 | + $reset = 0; |
|
518 | + } |
|
395 | 519 | $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
396 | 520 | $buffer = explode('\n',$buffer); |
397 | 521 | foreach ($buffer as $line) { |
@@ -400,16 +524,36 @@ discard block |
||
400 | 524 | $add = false; |
401 | 525 | $ais_data = $AIS->parse_line(trim($line)); |
402 | 526 | $data = array(); |
403 | - if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident']; |
|
404 | - if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi']; |
|
405 | - if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed']; |
|
406 | - if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading']; |
|
407 | - if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude']; |
|
408 | - if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude']; |
|
409 | - if (isset($ais_data['status'])) $data['status'] = $ais_data['status']; |
|
410 | - if (isset($ais_data['type'])) $data['type'] = $ais_data['type']; |
|
411 | - if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo']; |
|
412 | - if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign']; |
|
527 | + if (isset($ais_data['ident'])) { |
|
528 | + $data['ident'] = $ais_data['ident']; |
|
529 | + } |
|
530 | + if (isset($ais_data['mmsi'])) { |
|
531 | + $data['mmsi'] = $ais_data['mmsi']; |
|
532 | + } |
|
533 | + if (isset($ais_data['speed'])) { |
|
534 | + $data['speed'] = $ais_data['speed']; |
|
535 | + } |
|
536 | + if (isset($ais_data['heading'])) { |
|
537 | + $data['heading'] = $ais_data['heading']; |
|
538 | + } |
|
539 | + if (isset($ais_data['latitude'])) { |
|
540 | + $data['latitude'] = $ais_data['latitude']; |
|
541 | + } |
|
542 | + if (isset($ais_data['longitude'])) { |
|
543 | + $data['longitude'] = $ais_data['longitude']; |
|
544 | + } |
|
545 | + if (isset($ais_data['status'])) { |
|
546 | + $data['status'] = $ais_data['status']; |
|
547 | + } |
|
548 | + if (isset($ais_data['type'])) { |
|
549 | + $data['type'] = $ais_data['type']; |
|
550 | + } |
|
551 | + if (isset($ais_data['imo'])) { |
|
552 | + $data['imo'] = $ais_data['imo']; |
|
553 | + } |
|
554 | + if (isset($ais_data['callsign'])) { |
|
555 | + $data['callsign'] = $ais_data['callsign']; |
|
556 | + } |
|
413 | 557 | if (isset($ais_data['timestamp'])) { |
414 | 558 | $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']); |
415 | 559 | if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) { |
@@ -424,7 +568,9 @@ discard block |
||
424 | 568 | $data['id_source'] = $id_source; |
425 | 569 | print_r($data); |
426 | 570 | echo 'Add...'."\n"; |
427 | - if ($add && $ais_data['mmsi_type'] == 'Ship') $MI->add($data); |
|
571 | + if ($add && $ais_data['mmsi_type'] == 'Ship') { |
|
572 | + $MI->add($data); |
|
573 | + } |
|
428 | 574 | unset($data); |
429 | 575 | } |
430 | 576 | } |
@@ -444,18 +590,42 @@ discard block |
||
444 | 590 | if ($line != '') { |
445 | 591 | $ais_data = $AIS->parse_line(trim($line)); |
446 | 592 | $data = array(); |
447 | - if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident']; |
|
448 | - if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi']; |
|
449 | - if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed']; |
|
450 | - if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading']; |
|
451 | - if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude']; |
|
452 | - if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude']; |
|
453 | - if (isset($ais_data['status'])) $data['status'] = $ais_data['status']; |
|
454 | - if (isset($ais_data['type'])) $data['type'] = $ais_data['type']; |
|
455 | - if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo']; |
|
456 | - if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign']; |
|
457 | - if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination']; |
|
458 | - if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']); |
|
593 | + if (isset($ais_data['ident'])) { |
|
594 | + $data['ident'] = $ais_data['ident']; |
|
595 | + } |
|
596 | + if (isset($ais_data['mmsi'])) { |
|
597 | + $data['mmsi'] = $ais_data['mmsi']; |
|
598 | + } |
|
599 | + if (isset($ais_data['speed'])) { |
|
600 | + $data['speed'] = $ais_data['speed']; |
|
601 | + } |
|
602 | + if (isset($ais_data['heading'])) { |
|
603 | + $data['heading'] = $ais_data['heading']; |
|
604 | + } |
|
605 | + if (isset($ais_data['latitude'])) { |
|
606 | + $data['latitude'] = $ais_data['latitude']; |
|
607 | + } |
|
608 | + if (isset($ais_data['longitude'])) { |
|
609 | + $data['longitude'] = $ais_data['longitude']; |
|
610 | + } |
|
611 | + if (isset($ais_data['status'])) { |
|
612 | + $data['status'] = $ais_data['status']; |
|
613 | + } |
|
614 | + if (isset($ais_data['type'])) { |
|
615 | + $data['type'] = $ais_data['type']; |
|
616 | + } |
|
617 | + if (isset($ais_data['imo'])) { |
|
618 | + $data['imo'] = $ais_data['imo']; |
|
619 | + } |
|
620 | + if (isset($ais_data['callsign'])) { |
|
621 | + $data['callsign'] = $ais_data['callsign']; |
|
622 | + } |
|
623 | + if (isset($ais_data['destination'])) { |
|
624 | + $data['arrival_code'] = $ais_data['destination']; |
|
625 | + } |
|
626 | + if (isset($ais_data['eta_ts'])) { |
|
627 | + $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']); |
|
628 | + } |
|
459 | 629 | if (isset($ais_data['timestamp'])) { |
460 | 630 | $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']); |
461 | 631 | } else { |
@@ -463,7 +633,9 @@ discard block |
||
463 | 633 | } |
464 | 634 | $data['format_source'] = 'aisnmeahttp'; |
465 | 635 | $data['id_source'] = $id_source; |
466 | - if ($ais_data['mmsi_type'] == 'Ship') $MI->add($data); |
|
636 | + if ($ais_data['mmsi_type'] == 'Ship') { |
|
637 | + $MI->add($data); |
|
638 | + } |
|
467 | 639 | unset($data); |
468 | 640 | } |
469 | 641 | } |
@@ -512,7 +684,9 @@ discard block |
||
512 | 684 | $data['callsign'] = $line['callsign']; |
513 | 685 | $data['mmsi'] = $line['mmsi']; |
514 | 686 | $data['speed'] = $line['sog']; |
515 | - if ($line['heading'] != '511') $data['heading'] = $line['heading']; |
|
687 | + if ($line['heading'] != '511') { |
|
688 | + $data['heading'] = $line['heading']; |
|
689 | + } |
|
516 | 690 | $data['latitude'] = $line['latitude']; |
517 | 691 | $data['longitude'] = $line['longitude']; |
518 | 692 | $data['type_id'] = $line['shiptype']; |
@@ -532,7 +706,9 @@ discard block |
||
532 | 706 | echo 'download...'; |
533 | 707 | $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter'); |
534 | 708 | echo 'done !'."\n"; |
535 | - if ($buffer != '') $reset = 0; |
|
709 | + if ($buffer != '') { |
|
710 | + $reset = 0; |
|
711 | + } |
|
536 | 712 | $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
537 | 713 | $buffer = explode('\n',$buffer); |
538 | 714 | foreach ($buffer as $line) { |
@@ -576,16 +752,28 @@ discard block |
||
576 | 752 | $line = explode(':', $line); |
577 | 753 | if (count($line) > 30 && $line[0] != 'callsign') { |
578 | 754 | $data = array(); |
579 | - if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37]; |
|
580 | - else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0]; |
|
755 | + if (isset($line[37]) && $line[37] != '') { |
|
756 | + $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37]; |
|
757 | + } else { |
|
758 | + $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0]; |
|
759 | + } |
|
581 | 760 | $data['pilot_id'] = $line[1]; |
582 | 761 | $data['pilot_name'] = $line[2]; |
583 | 762 | $data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT); |
584 | 763 | $data['ident'] = $line[0]; // ident |
585 | - if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude |
|
764 | + if ($line[7] != '' && $line[7] != 0) { |
|
765 | + $data['altitude'] = $line[7]; |
|
766 | + } |
|
767 | + // altitude |
|
586 | 768 | $data['speed'] = $line[8]; // speed |
587 | - if (isset($line[45])) $data['heading'] = $line[45]; // heading |
|
588 | - elseif (isset($line[38])) $data['heading'] = $line[38]; // heading |
|
769 | + if (isset($line[45])) { |
|
770 | + $data['heading'] = $line[45]; |
|
771 | + } |
|
772 | + // heading |
|
773 | + elseif (isset($line[38])) { |
|
774 | + $data['heading'] = $line[38]; |
|
775 | + } |
|
776 | + // heading |
|
589 | 777 | $data['latitude'] = $line[5]; // lat |
590 | 778 | $data['longitude'] = $line[6]; // long |
591 | 779 | $data['verticalrate'] = ''; // vertical rate |
@@ -601,7 +789,9 @@ discard block |
||
601 | 789 | $data['frequency'] = $line[4]; |
602 | 790 | $data['type'] = $line[18]; |
603 | 791 | $data['range'] = $line[19]; |
604 | - if (isset($line[35])) $data['info'] = $line[35]; |
|
792 | + if (isset($line[35])) { |
|
793 | + $data['info'] = $line[35]; |
|
794 | + } |
|
605 | 795 | $data['id_source'] = $id_source; |
606 | 796 | //$data['arrival_airport_time'] = ; |
607 | 797 | if ($line[9] != '') { |
@@ -615,24 +805,41 @@ discard block |
||
615 | 805 | elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt'; |
616 | 806 | */ |
617 | 807 | $data['format_source'] = $value['format']; |
618 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
619 | - if ($line[3] == 'PILOT') $SI->add($data); |
|
620 | - elseif ($line[3] == 'ATC') { |
|
808 | + if (isset($value['name']) && $value['name'] != '') { |
|
809 | + $data['source_name'] = $value['name']; |
|
810 | + } |
|
811 | + if ($line[3] == 'PILOT') { |
|
812 | + $SI->add($data); |
|
813 | + } elseif ($line[3] == 'ATC') { |
|
621 | 814 | //print_r($data); |
622 | 815 | $data['info'] = str_replace('^§','<br />',$data['info']); |
623 | 816 | $data['info'] = str_replace('&sect;','',$data['info']); |
624 | 817 | $typec = substr($data['ident'],-3); |
625 | - if ($typec == 'APP') $data['type'] = 'Approach'; |
|
626 | - elseif ($typec == 'TWR') $data['type'] = 'Tower'; |
|
627 | - elseif ($typec == 'OBS') $data['type'] = 'Observer'; |
|
628 | - elseif ($typec == 'GND') $data['type'] = 'Ground'; |
|
629 | - elseif ($typec == 'DEL') $data['type'] = 'Delivery'; |
|
630 | - elseif ($typec == 'DEP') $data['type'] = 'Departure'; |
|
631 | - elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station'; |
|
632 | - elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre'; |
|
633 | - elseif ($data['type'] == '') $data['type'] = 'Observer'; |
|
634 | - if (!isset($data['source_name'])) $data['source_name'] = ''; |
|
635 | - if (isset($ATC)) echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']); |
|
818 | + if ($typec == 'APP') { |
|
819 | + $data['type'] = 'Approach'; |
|
820 | + } elseif ($typec == 'TWR') { |
|
821 | + $data['type'] = 'Tower'; |
|
822 | + } elseif ($typec == 'OBS') { |
|
823 | + $data['type'] = 'Observer'; |
|
824 | + } elseif ($typec == 'GND') { |
|
825 | + $data['type'] = 'Ground'; |
|
826 | + } elseif ($typec == 'DEL') { |
|
827 | + $data['type'] = 'Delivery'; |
|
828 | + } elseif ($typec == 'DEP') { |
|
829 | + $data['type'] = 'Departure'; |
|
830 | + } elseif ($typec == 'FSS') { |
|
831 | + $data['type'] = 'Flight Service Station'; |
|
832 | + } elseif ($typec == 'CTR') { |
|
833 | + $data['type'] = 'Control Radar or Centre'; |
|
834 | + } elseif ($data['type'] == '') { |
|
835 | + $data['type'] = 'Observer'; |
|
836 | + } |
|
837 | + if (!isset($data['source_name'])) { |
|
838 | + $data['source_name'] = ''; |
|
839 | + } |
|
840 | + if (isset($ATC)) { |
|
841 | + echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']); |
|
842 | + } |
|
636 | 843 | } |
637 | 844 | unset($data); |
638 | 845 | } |
@@ -651,26 +858,55 @@ discard block |
||
651 | 858 | foreach ($all_data['acList'] as $line) { |
652 | 859 | $data = array(); |
653 | 860 | $data['hex'] = $line['Icao']; // hex |
654 | - if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident |
|
655 | - if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude |
|
656 | - if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed |
|
657 | - if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading |
|
658 | - if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat |
|
659 | - if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long |
|
861 | + if (isset($line['Call'])) { |
|
862 | + $data['ident'] = $line['Call']; |
|
863 | + } |
|
864 | + // ident |
|
865 | + if (isset($line['Alt'])) { |
|
866 | + $data['altitude'] = $line['Alt']; |
|
867 | + } |
|
868 | + // altitude |
|
869 | + if (isset($line['Spd'])) { |
|
870 | + $data['speed'] = $line['Spd']; |
|
871 | + } |
|
872 | + // speed |
|
873 | + if (isset($line['Trak'])) { |
|
874 | + $data['heading'] = $line['Trak']; |
|
875 | + } |
|
876 | + // heading |
|
877 | + if (isset($line['Lat'])) { |
|
878 | + $data['latitude'] = $line['Lat']; |
|
879 | + } |
|
880 | + // lat |
|
881 | + if (isset($line['Long'])) { |
|
882 | + $data['longitude'] = $line['Long']; |
|
883 | + } |
|
884 | + // long |
|
660 | 885 | //$data['verticalrate'] = $line['']; // verticale rate |
661 | - if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk |
|
886 | + if (isset($line['Sqk'])) { |
|
887 | + $data['squawk'] = $line['Sqk']; |
|
888 | + } |
|
889 | + // squawk |
|
662 | 890 | $data['emergency'] = ''; // emergency |
663 | - if (isset($line['Reg'])) $data['registration'] = $line['Reg']; |
|
891 | + if (isset($line['Reg'])) { |
|
892 | + $data['registration'] = $line['Reg']; |
|
893 | + } |
|
664 | 894 | /* |
665 | 895 | if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000); |
666 | 896 | else $data['datetime'] = date('Y-m-d H:i:s'); |
667 | 897 | */ |
668 | 898 | $data['datetime'] = date('Y-m-d H:i:s'); |
669 | - if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type']; |
|
899 | + if (isset($line['Type'])) { |
|
900 | + $data['aircraft_icao'] = $line['Type']; |
|
901 | + } |
|
670 | 902 | $data['format_source'] = 'aircraftlistjson'; |
671 | 903 | $data['id_source'] = $id_source; |
672 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
673 | - if (isset($data['latitude'])) $SI->add($data); |
|
904 | + if (isset($value['name']) && $value['name'] != '') { |
|
905 | + $data['source_name'] = $value['name']; |
|
906 | + } |
|
907 | + if (isset($data['latitude'])) { |
|
908 | + $SI->add($data); |
|
909 | + } |
|
674 | 910 | unset($data); |
675 | 911 | } |
676 | 912 | } elseif (is_array($all_data)) { |
@@ -690,7 +926,9 @@ discard block |
||
690 | 926 | $data['datetime'] = date('Y-m-d H:i:s'); |
691 | 927 | $data['format_source'] = 'aircraftlistjson'; |
692 | 928 | $data['id_source'] = $id_source; |
693 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
929 | + if (isset($value['name']) && $value['name'] != '') { |
|
930 | + $data['source_name'] = $value['name']; |
|
931 | + } |
|
694 | 932 | $SI->add($data); |
695 | 933 | unset($data); |
696 | 934 | } |
@@ -726,7 +964,9 @@ discard block |
||
726 | 964 | $data['datetime'] = date('Y-m-d H:i:s',$line[9]); |
727 | 965 | $data['format_source'] = 'planeupdatefaa'; |
728 | 966 | $data['id_source'] = $id_source; |
729 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
967 | + if (isset($value['name']) && $value['name'] != '') { |
|
968 | + $data['source_name'] = $value['name']; |
|
969 | + } |
|
730 | 970 | $SI->add($data); |
731 | 971 | unset($data); |
732 | 972 | } |
@@ -766,7 +1006,9 @@ discard block |
||
766 | 1006 | //$buffer = $Common->getData($hosts[$id]); |
767 | 1007 | $buffer = $Common->getData($value['host']); |
768 | 1008 | $all_data = json_decode($buffer,true); |
769 | - if (!empty($all_data)) $reset = 0; |
|
1009 | + if (!empty($all_data)) { |
|
1010 | + $reset = 0; |
|
1011 | + } |
|
770 | 1012 | foreach ($all_data as $key => $line) { |
771 | 1013 | if ($key != 'full_count' && $key != 'version' && $key != 'stats') { |
772 | 1014 | $data = array(); |
@@ -787,7 +1029,9 @@ discard block |
||
787 | 1029 | $data['datetime'] = date('Y-m-d H:i:s'); //$line[10] |
788 | 1030 | $data['format_source'] = 'fr24json'; |
789 | 1031 | $data['id_source'] = $id_source; |
790 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1032 | + if (isset($value['name']) && $value['name'] != '') { |
|
1033 | + $data['source_name'] = $value['name']; |
|
1034 | + } |
|
791 | 1035 | $SI->add($data); |
792 | 1036 | unset($data); |
793 | 1037 | } |
@@ -811,23 +1055,39 @@ discard block |
||
811 | 1055 | if (isset($line['inf'])) { |
812 | 1056 | $data = array(); |
813 | 1057 | $data['hex'] = $line['inf']['ia']; |
814 | - if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13] |
|
1058 | + if (isset($line['inf']['cs'])) { |
|
1059 | + $data['ident'] = $line['inf']['cs']; |
|
1060 | + } |
|
1061 | + //$line[13] |
|
815 | 1062 | $data['altitude'] = round($line['inf']['al']*3.28084); // altitude |
816 | - if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed |
|
817 | - if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading |
|
1063 | + if (isset($line['inf']['gs'])) { |
|
1064 | + $data['speed'] = round($line['inf']['gs']*0.539957); |
|
1065 | + } |
|
1066 | + // speed |
|
1067 | + if (isset($line['inf']['tr'])) { |
|
1068 | + $data['heading'] = $line['inf']['tr']; |
|
1069 | + } |
|
1070 | + // heading |
|
818 | 1071 | $data['latitude'] = $line['pt'][0]; // lat |
819 | 1072 | $data['longitude'] = $line['pt'][1]; // long |
820 | 1073 | //if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate |
821 | - if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk |
|
1074 | + if (isset($line['inf']['sq'])) { |
|
1075 | + $data['squawk'] = $line['inf']['sq']; |
|
1076 | + } |
|
1077 | + // squawk |
|
822 | 1078 | //$data['aircraft_icao'] = $line[8]; |
823 | - if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc']; |
|
1079 | + if (isset($line['inf']['rc'])) { |
|
1080 | + $data['registration'] = $line['inf']['rc']; |
|
1081 | + } |
|
824 | 1082 | //$data['departure_airport_iata'] = $line[11]; |
825 | 1083 | //$data['arrival_airport_iata'] = $line[12]; |
826 | 1084 | //$data['emergency'] = ''; // emergency |
827 | 1085 | $data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10] |
828 | 1086 | $data['format_source'] = 'radarvirtueljson'; |
829 | 1087 | $data['id_source'] = $id_source; |
830 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1088 | + if (isset($value['name']) && $value['name'] != '') { |
|
1089 | + $data['source_name'] = $value['name']; |
|
1090 | + } |
|
831 | 1091 | $SI->add($data); |
832 | 1092 | unset($data); |
833 | 1093 | } |
@@ -848,29 +1108,62 @@ discard block |
||
848 | 1108 | $data['id'] = $line['id']; |
849 | 1109 | $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6); |
850 | 1110 | $data['ident'] = $line['callsign']; // ident |
851 | - if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id |
|
852 | - if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name |
|
853 | - if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude |
|
854 | - if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed |
|
855 | - if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading |
|
856 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
1111 | + if (isset($line['pilotid'])) { |
|
1112 | + $data['pilot_id'] = $line['pilotid']; |
|
1113 | + } |
|
1114 | + // pilot id |
|
1115 | + if (isset($line['name'])) { |
|
1116 | + $data['pilot_name'] = $line['name']; |
|
1117 | + } |
|
1118 | + // pilot name |
|
1119 | + if (isset($line['alt'])) { |
|
1120 | + $data['altitude'] = $line['alt']; |
|
1121 | + } |
|
1122 | + // altitude |
|
1123 | + if (isset($line['gs'])) { |
|
1124 | + $data['speed'] = $line['gs']; |
|
1125 | + } |
|
1126 | + // speed |
|
1127 | + if (isset($line['heading'])) { |
|
1128 | + $data['heading'] = $line['heading']; |
|
1129 | + } |
|
1130 | + // heading |
|
1131 | + if (isset($line['route'])) { |
|
1132 | + $data['waypoints'] = $line['route']; |
|
1133 | + } |
|
1134 | + // route |
|
857 | 1135 | $data['latitude'] = $line['lat']; // lat |
858 | 1136 | $data['longitude'] = $line['lon']; // long |
859 | 1137 | //$data['verticalrate'] = $line['vrt']; // verticale rate |
860 | 1138 | //$data['squawk'] = $line['squawk']; // squawk |
861 | 1139 | //$data['emergency'] = ''; // emergency |
862 | - if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao']; |
|
863 | - if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime']; |
|
864 | - if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao']; |
|
1140 | + if (isset($line['depicao'])) { |
|
1141 | + $data['departure_airport_icao'] = $line['depicao']; |
|
1142 | + } |
|
1143 | + if (isset($line['deptime'])) { |
|
1144 | + $data['departure_airport_time'] = $line['deptime']; |
|
1145 | + } |
|
1146 | + if (isset($line['arricao'])) { |
|
1147 | + $data['arrival_airport_icao'] = $line['arricao']; |
|
1148 | + } |
|
865 | 1149 | //$data['arrival_airport_time'] = $line['arrtime']; |
866 | - if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft']; |
|
867 | - if (isset($line['transponder'])) $data['squawk'] = $line['transponder']; |
|
868 | - if (isset($line['atis'])) $data['info'] = $line['atis']; |
|
869 | - else $data['info'] = ''; |
|
1150 | + if (isset($line['aircraft'])) { |
|
1151 | + $data['aircraft_icao'] = $line['aircraft']; |
|
1152 | + } |
|
1153 | + if (isset($line['transponder'])) { |
|
1154 | + $data['squawk'] = $line['transponder']; |
|
1155 | + } |
|
1156 | + if (isset($line['atis'])) { |
|
1157 | + $data['info'] = $line['atis']; |
|
1158 | + } else { |
|
1159 | + $data['info'] = ''; |
|
1160 | + } |
|
870 | 1161 | $data['format_source'] = 'pireps'; |
871 | 1162 | $data['id_source'] = $id_source; |
872 | 1163 | $data['datetime'] = date('Y-m-d H:i:s'); |
873 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1164 | + if (isset($value['name']) && $value['name'] != '') { |
|
1165 | + $data['source_name'] = $value['name']; |
|
1166 | + } |
|
874 | 1167 | if ($line['icon'] == 'plane') { |
875 | 1168 | $SI->add($data); |
876 | 1169 | // print_r($data); |
@@ -879,16 +1172,28 @@ discard block |
||
879 | 1172 | $data['info'] = str_replace('&sect;','',$data['info']); |
880 | 1173 | $typec = substr($data['ident'],-3); |
881 | 1174 | $data['type'] = ''; |
882 | - if ($typec == 'APP') $data['type'] = 'Approach'; |
|
883 | - elseif ($typec == 'TWR') $data['type'] = 'Tower'; |
|
884 | - elseif ($typec == 'OBS') $data['type'] = 'Observer'; |
|
885 | - elseif ($typec == 'GND') $data['type'] = 'Ground'; |
|
886 | - elseif ($typec == 'DEL') $data['type'] = 'Delivery'; |
|
887 | - elseif ($typec == 'DEP') $data['type'] = 'Departure'; |
|
888 | - elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station'; |
|
889 | - elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre'; |
|
890 | - else $data['type'] = 'Observer'; |
|
891 | - if (isset($ATC)) echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']); |
|
1175 | + if ($typec == 'APP') { |
|
1176 | + $data['type'] = 'Approach'; |
|
1177 | + } elseif ($typec == 'TWR') { |
|
1178 | + $data['type'] = 'Tower'; |
|
1179 | + } elseif ($typec == 'OBS') { |
|
1180 | + $data['type'] = 'Observer'; |
|
1181 | + } elseif ($typec == 'GND') { |
|
1182 | + $data['type'] = 'Ground'; |
|
1183 | + } elseif ($typec == 'DEL') { |
|
1184 | + $data['type'] = 'Delivery'; |
|
1185 | + } elseif ($typec == 'DEP') { |
|
1186 | + $data['type'] = 'Departure'; |
|
1187 | + } elseif ($typec == 'FSS') { |
|
1188 | + $data['type'] = 'Flight Service Station'; |
|
1189 | + } elseif ($typec == 'CTR') { |
|
1190 | + $data['type'] = 'Control Radar or Centre'; |
|
1191 | + } else { |
|
1192 | + $data['type'] = 'Observer'; |
|
1193 | + } |
|
1194 | + if (isset($ATC)) { |
|
1195 | + echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']); |
|
1196 | + } |
|
892 | 1197 | } |
893 | 1198 | unset($data); |
894 | 1199 | } |
@@ -898,7 +1203,9 @@ discard block |
||
898 | 1203 | //} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) { |
899 | 1204 | } elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
900 | 1205 | //$buffer = $Common->getData($hosts[$id]); |
901 | - if ($globalDebug) echo 'Get Data...'."\n"; |
|
1206 | + if ($globalDebug) { |
|
1207 | + echo 'Get Data...'."\n"; |
|
1208 | + } |
|
902 | 1209 | $buffer = $Common->getData($value['host']); |
903 | 1210 | $all_data = json_decode($buffer,true); |
904 | 1211 | if ($buffer != '' && is_array($all_data)) { |
@@ -906,10 +1213,16 @@ discard block |
||
906 | 1213 | foreach ($all_data as $line) { |
907 | 1214 | $data = array(); |
908 | 1215 | //$data['id'] = $line['id']; // id not usable |
909 | - if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum']; |
|
1216 | + if (isset($line['pilotid'])) { |
|
1217 | + $data['id'] = $line['pilotid'].$line['flightnum']; |
|
1218 | + } |
|
910 | 1219 | $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex |
911 | - if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname']; |
|
912 | - if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; |
|
1220 | + if (isset($line['pilotname'])) { |
|
1221 | + $data['pilot_name'] = $line['pilotname']; |
|
1222 | + } |
|
1223 | + if (isset($line['pilotid'])) { |
|
1224 | + $data['pilot_id'] = $line['pilotid']; |
|
1225 | + } |
|
913 | 1226 | $data['ident'] = $line['flightnum']; // ident |
914 | 1227 | $data['altitude'] = $line['alt']; // altitude |
915 | 1228 | $data['speed'] = $line['gs']; // speed |
@@ -927,27 +1240,41 @@ discard block |
||
927 | 1240 | $data['arrival_airport_icao'] = $line['arricao']; |
928 | 1241 | $data['arrival_airport_time'] = $line['arrtime']; |
929 | 1242 | $data['registration'] = $line['aircraft']; |
930 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
1243 | + if (isset($line['route'])) { |
|
1244 | + $data['waypoints'] = $line['route']; |
|
1245 | + } |
|
1246 | + // route |
|
931 | 1247 | if (isset($line['aircraftname'])) { |
932 | 1248 | $line['aircraftname'] = strtoupper($line['aircraftname']); |
933 | 1249 | $line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']); |
934 | 1250 | $aircraft_data = explode('-',$line['aircraftname']); |
935 | - if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0]; |
|
936 | - elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1]; |
|
937 | - else { |
|
1251 | + if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) { |
|
1252 | + $data['aircraft_icao'] = $aircraft_data[0]; |
|
1253 | + } elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) { |
|
1254 | + $data['aircraft_icao'] = $aircraft_data[1]; |
|
1255 | + } else { |
|
938 | 1256 | $aircraft_data = explode(' ',$line['aircraftname']); |
939 | - if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1]; |
|
940 | - else $data['aircraft_icao'] = $line['aircraftname']; |
|
1257 | + if (isset($aircraft_data[1])) { |
|
1258 | + $data['aircraft_icao'] = $aircraft_data[1]; |
|
1259 | + } else { |
|
1260 | + $data['aircraft_icao'] = $line['aircraftname']; |
|
1261 | + } |
|
941 | 1262 | } |
942 | 1263 | } |
943 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; |
|
1264 | + if (isset($line['route'])) { |
|
1265 | + $data['waypoints'] = $line['route']; |
|
1266 | + } |
|
944 | 1267 | $data['id_source'] = $id_source; |
945 | 1268 | $data['format_source'] = 'phpvmacars'; |
946 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1269 | + if (isset($value['name']) && $value['name'] != '') { |
|
1270 | + $data['source_name'] = $value['name']; |
|
1271 | + } |
|
947 | 1272 | $SI->add($data); |
948 | 1273 | unset($data); |
949 | 1274 | } |
950 | - if ($globalDebug) echo 'No more data...'."\n"; |
|
1275 | + if ($globalDebug) { |
|
1276 | + echo 'No more data...'."\n"; |
|
1277 | + } |
|
951 | 1278 | unset($buffer); |
952 | 1279 | unset($all_data); |
953 | 1280 | } |
@@ -955,7 +1282,9 @@ discard block |
||
955 | 1282 | $last_exec[$id]['last'] = time(); |
956 | 1283 | } elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
957 | 1284 | //$buffer = $Common->getData($hosts[$id]); |
958 | - if ($globalDebug) echo 'Get Data...'."\n"; |
|
1285 | + if ($globalDebug) { |
|
1286 | + echo 'Get Data...'."\n"; |
|
1287 | + } |
|
959 | 1288 | $buffer = $Common->getData($value['host']); |
960 | 1289 | $all_data = json_decode($buffer,true); |
961 | 1290 | if ($buffer != '' && is_array($all_data)) { |
@@ -984,15 +1313,22 @@ discard block |
||
984 | 1313 | $data['arrival_airport_icao'] = $line['arrival']; |
985 | 1314 | //$data['arrival_airport_time'] = $line['arrival_time']; |
986 | 1315 | //$data['registration'] = $line['aircraft']; |
987 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
1316 | + if (isset($line['route'])) { |
|
1317 | + $data['waypoints'] = $line['route']; |
|
1318 | + } |
|
1319 | + // route |
|
988 | 1320 | $data['aircraft_icao'] = $line['plane_type']; |
989 | 1321 | $data['id_source'] = $id_source; |
990 | 1322 | $data['format_source'] = 'vam'; |
991 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1323 | + if (isset($value['name']) && $value['name'] != '') { |
|
1324 | + $data['source_name'] = $value['name']; |
|
1325 | + } |
|
992 | 1326 | $SI->add($data); |
993 | 1327 | unset($data); |
994 | 1328 | } |
995 | - if ($globalDebug) echo 'No more data...'."\n"; |
|
1329 | + if ($globalDebug) { |
|
1330 | + echo 'No more data...'."\n"; |
|
1331 | + } |
|
996 | 1332 | unset($buffer); |
997 | 1333 | unset($all_data); |
998 | 1334 | } |
@@ -1000,7 +1336,9 @@ discard block |
||
1000 | 1336 | $last_exec[$id]['last'] = time(); |
1001 | 1337 | //} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') { |
1002 | 1338 | } elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais' || $value['format'] == 'vrstcp') { |
1003 | - if (function_exists('pcntl_fork')) pcntl_signal_dispatch(); |
|
1339 | + if (function_exists('pcntl_fork')) { |
|
1340 | + pcntl_signal_dispatch(); |
|
1341 | + } |
|
1004 | 1342 | //$last_exec[$id]['last'] = time(); |
1005 | 1343 | |
1006 | 1344 | //$read = array( $sockets[$id] ); |
@@ -1008,7 +1346,9 @@ discard block |
||
1008 | 1346 | $write = NULL; |
1009 | 1347 | $e = NULL; |
1010 | 1348 | $n = socket_select($read, $write, $e, $timeout); |
1011 | - if ($e != NULL) var_dump($e); |
|
1349 | + if ($e != NULL) { |
|
1350 | + var_dump($e); |
|
1351 | + } |
|
1012 | 1352 | if ($n > 0) { |
1013 | 1353 | $reset = 0; |
1014 | 1354 | foreach ($read as $nb => $r) { |
@@ -1027,12 +1367,16 @@ discard block |
||
1027 | 1367 | //$SI::del(); |
1028 | 1368 | if ($format == 'vrstcp') { |
1029 | 1369 | $buffer = explode('},{',$buffer); |
1030 | - } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer)); |
|
1370 | + } else { |
|
1371 | + $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer)); |
|
1372 | + } |
|
1031 | 1373 | // SBS format is CSV format |
1032 | 1374 | if ($buffer != '') { |
1033 | 1375 | $tt[$format] = 0; |
1034 | 1376 | if ($format == 'acarssbs3') { |
1035 | - if ($globalDebug) echo 'ACARS : '.$buffer."\n"; |
|
1377 | + if ($globalDebug) { |
|
1378 | + echo 'ACARS : '.$buffer."\n"; |
|
1379 | + } |
|
1036 | 1380 | $ACARS->add(trim($buffer)); |
1037 | 1381 | $ACARS->deleteLiveAcarsData(); |
1038 | 1382 | } elseif ($format == 'raw') { |
@@ -1041,25 +1385,55 @@ discard block |
||
1041 | 1385 | if (is_array($data)) { |
1042 | 1386 | $data['datetime'] = date('Y-m-d H:i:s'); |
1043 | 1387 | $data['format_source'] = 'raw'; |
1044 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
1045 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1046 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
1388 | + if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') { |
|
1389 | + $data['source_name'] = $globalSources[$nb]['name']; |
|
1390 | + } |
|
1391 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
1392 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1393 | + } |
|
1394 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
1395 | + $SI->add($data); |
|
1396 | + } |
|
1047 | 1397 | } |
1048 | 1398 | } elseif ($format == 'ais') { |
1049 | 1399 | $ais_data = $AIS->parse_line(trim($buffer)); |
1050 | 1400 | $data = array(); |
1051 | - if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident']; |
|
1052 | - if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi']; |
|
1053 | - if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed']; |
|
1054 | - if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading']; |
|
1055 | - if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude']; |
|
1056 | - if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude']; |
|
1057 | - if (isset($ais_data['status'])) $data['status'] = $ais_data['status']; |
|
1058 | - if (isset($ais_data['type'])) $data['type'] = $ais_data['type']; |
|
1059 | - if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo']; |
|
1060 | - if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign']; |
|
1061 | - if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination']; |
|
1062 | - if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']); |
|
1401 | + if (isset($ais_data['ident'])) { |
|
1402 | + $data['ident'] = $ais_data['ident']; |
|
1403 | + } |
|
1404 | + if (isset($ais_data['mmsi'])) { |
|
1405 | + $data['mmsi'] = $ais_data['mmsi']; |
|
1406 | + } |
|
1407 | + if (isset($ais_data['speed'])) { |
|
1408 | + $data['speed'] = $ais_data['speed']; |
|
1409 | + } |
|
1410 | + if (isset($ais_data['heading'])) { |
|
1411 | + $data['heading'] = $ais_data['heading']; |
|
1412 | + } |
|
1413 | + if (isset($ais_data['latitude'])) { |
|
1414 | + $data['latitude'] = $ais_data['latitude']; |
|
1415 | + } |
|
1416 | + if (isset($ais_data['longitude'])) { |
|
1417 | + $data['longitude'] = $ais_data['longitude']; |
|
1418 | + } |
|
1419 | + if (isset($ais_data['status'])) { |
|
1420 | + $data['status'] = $ais_data['status']; |
|
1421 | + } |
|
1422 | + if (isset($ais_data['type'])) { |
|
1423 | + $data['type'] = $ais_data['type']; |
|
1424 | + } |
|
1425 | + if (isset($ais_data['imo'])) { |
|
1426 | + $data['imo'] = $ais_data['imo']; |
|
1427 | + } |
|
1428 | + if (isset($ais_data['callsign'])) { |
|
1429 | + $data['callsign'] = $ais_data['callsign']; |
|
1430 | + } |
|
1431 | + if (isset($ais_data['destination'])) { |
|
1432 | + $data['arrival_code'] = $ais_data['destination']; |
|
1433 | + } |
|
1434 | + if (isset($ais_data['eta_ts'])) { |
|
1435 | + $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']); |
|
1436 | + } |
|
1063 | 1437 | |
1064 | 1438 | if (isset($ais_data['timestamp'])) { |
1065 | 1439 | $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']); |
@@ -1068,7 +1442,9 @@ discard block |
||
1068 | 1442 | } |
1069 | 1443 | $data['format_source'] = 'aisnmea'; |
1070 | 1444 | $data['id_source'] = $id_source; |
1071 | - if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data); |
|
1445 | + if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') { |
|
1446 | + $MI->add($data); |
|
1447 | + } |
|
1072 | 1448 | unset($data); |
1073 | 1449 | } elseif ($format == 'flightgearsp') { |
1074 | 1450 | //echo $buffer."\n"; |
@@ -1086,11 +1462,15 @@ discard block |
||
1086 | 1462 | $data['speed'] = round($line[5]*1.94384); |
1087 | 1463 | $data['datetime'] = date('Y-m-d H:i:s'); |
1088 | 1464 | $data['format_source'] = 'flightgearsp'; |
1089 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
1465 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
1466 | + $SI->add($data); |
|
1467 | + } |
|
1090 | 1468 | $send = @ socket_send( $r , $data_aprs , strlen($data_aprs) , 0 ); |
1091 | 1469 | } |
1092 | 1470 | } elseif ($format == 'acars') { |
1093 | - if ($globalDebug) echo 'ACARS : '.$buffer."\n"; |
|
1471 | + if ($globalDebug) { |
|
1472 | + echo 'ACARS : '.$buffer."\n"; |
|
1473 | + } |
|
1094 | 1474 | $ACARS->add(trim($buffer)); |
1095 | 1475 | socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port); |
1096 | 1476 | $ACARS->deleteLiveAcarsData(); |
@@ -1111,7 +1491,9 @@ discard block |
||
1111 | 1491 | $aircraft_type = $line[10]; |
1112 | 1492 | $aircraft_type = preg_split(':/:',$aircraft_type); |
1113 | 1493 | $data['aircraft_name'] = substr(end($aircraft_type),0,-4); |
1114 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
1494 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
1495 | + $SI->add($data); |
|
1496 | + } |
|
1115 | 1497 | } |
1116 | 1498 | } |
1117 | 1499 | } elseif ($format == 'beast') { |
@@ -1121,27 +1503,59 @@ discard block |
||
1121 | 1503 | foreach($buffer as $all_data) { |
1122 | 1504 | $line = json_decode('{'.$all_data.'}',true); |
1123 | 1505 | $data = array(); |
1124 | - if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex |
|
1125 | - if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident |
|
1126 | - if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude |
|
1127 | - if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed |
|
1128 | - if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading |
|
1129 | - if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat |
|
1130 | - if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long |
|
1506 | + if (isset($line['Icao'])) { |
|
1507 | + $data['hex'] = $line['Icao']; |
|
1508 | + } |
|
1509 | + // hex |
|
1510 | + if (isset($line['Call'])) { |
|
1511 | + $data['ident'] = $line['Call']; |
|
1512 | + } |
|
1513 | + // ident |
|
1514 | + if (isset($line['Alt'])) { |
|
1515 | + $data['altitude'] = $line['Alt']; |
|
1516 | + } |
|
1517 | + // altitude |
|
1518 | + if (isset($line['Spd'])) { |
|
1519 | + $data['speed'] = $line['Spd']; |
|
1520 | + } |
|
1521 | + // speed |
|
1522 | + if (isset($line['Trak'])) { |
|
1523 | + $data['heading'] = $line['Trak']; |
|
1524 | + } |
|
1525 | + // heading |
|
1526 | + if (isset($line['Lat'])) { |
|
1527 | + $data['latitude'] = $line['Lat']; |
|
1528 | + } |
|
1529 | + // lat |
|
1530 | + if (isset($line['Long'])) { |
|
1531 | + $data['longitude'] = $line['Long']; |
|
1532 | + } |
|
1533 | + // long |
|
1131 | 1534 | //$data['verticalrate'] = $line['']; // verticale rate |
1132 | - if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk |
|
1535 | + if (isset($line['Sqk'])) { |
|
1536 | + $data['squawk'] = $line['Sqk']; |
|
1537 | + } |
|
1538 | + // squawk |
|
1133 | 1539 | $data['emergency'] = ''; // emergency |
1134 | - if (isset($line['Reg'])) $data['registration'] = $line['Reg']; |
|
1540 | + if (isset($line['Reg'])) { |
|
1541 | + $data['registration'] = $line['Reg']; |
|
1542 | + } |
|
1135 | 1543 | /* |
1136 | 1544 | if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000); |
1137 | 1545 | else $data['datetime'] = date('Y-m-d H:i:s'); |
1138 | 1546 | */ |
1139 | 1547 | $data['datetime'] = date('Y-m-d H:i:s'); |
1140 | - if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type']; |
|
1548 | + if (isset($line['Type'])) { |
|
1549 | + $data['aircraft_icao'] = $line['Type']; |
|
1550 | + } |
|
1141 | 1551 | $data['format_source'] = 'vrstcp'; |
1142 | 1552 | $data['id_source'] = $id_source; |
1143 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1144 | - if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data); |
|
1553 | + if (isset($value['name']) && $value['name'] != '') { |
|
1554 | + $data['source_name'] = $value['name']; |
|
1555 | + } |
|
1556 | + if (isset($data['latitude']) && isset($data['hex'])) { |
|
1557 | + $SI->add($data); |
|
1558 | + } |
|
1145 | 1559 | unset($data); |
1146 | 1560 | } |
1147 | 1561 | } elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') { |
@@ -1154,21 +1568,43 @@ discard block |
||
1154 | 1568 | $data['hex'] = $lined['hexid']; |
1155 | 1569 | //$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));; |
1156 | 1570 | $data['datetime'] = date('Y-m-d H:i:s');; |
1157 | - if (isset($lined['ident'])) $data['ident'] = $lined['ident']; |
|
1158 | - if (isset($lined['lat'])) $data['latitude'] = $lined['lat']; |
|
1159 | - if (isset($lined['lon'])) $data['longitude'] = $lined['lon']; |
|
1160 | - if (isset($lined['speed'])) $data['speed'] = $lined['speed']; |
|
1161 | - if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk']; |
|
1162 | - if (isset($lined['alt'])) $data['altitude'] = $lined['alt']; |
|
1163 | - if (isset($lined['heading'])) $data['heading'] = $lined['heading']; |
|
1571 | + if (isset($lined['ident'])) { |
|
1572 | + $data['ident'] = $lined['ident']; |
|
1573 | + } |
|
1574 | + if (isset($lined['lat'])) { |
|
1575 | + $data['latitude'] = $lined['lat']; |
|
1576 | + } |
|
1577 | + if (isset($lined['lon'])) { |
|
1578 | + $data['longitude'] = $lined['lon']; |
|
1579 | + } |
|
1580 | + if (isset($lined['speed'])) { |
|
1581 | + $data['speed'] = $lined['speed']; |
|
1582 | + } |
|
1583 | + if (isset($lined['squawk'])) { |
|
1584 | + $data['squawk'] = $lined['squawk']; |
|
1585 | + } |
|
1586 | + if (isset($lined['alt'])) { |
|
1587 | + $data['altitude'] = $lined['alt']; |
|
1588 | + } |
|
1589 | + if (isset($lined['heading'])) { |
|
1590 | + $data['heading'] = $lined['heading']; |
|
1591 | + } |
|
1164 | 1592 | $data['id_source'] = $id_source; |
1165 | 1593 | $data['format_source'] = 'tsv'; |
1166 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
1167 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1168 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
1594 | + if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') { |
|
1595 | + $data['source_name'] = $globalSources[$nb]['name']; |
|
1596 | + } |
|
1597 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
1598 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1599 | + } |
|
1600 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
1601 | + $SI->add($data); |
|
1602 | + } |
|
1169 | 1603 | unset($lined); |
1170 | 1604 | unset($data); |
1171 | - } else $error = true; |
|
1605 | + } else { |
|
1606 | + $error = true; |
|
1607 | + } |
|
1172 | 1608 | } elseif ($format == 'aprs' && $use_aprs) { |
1173 | 1609 | if ($aprs_connect == 0) { |
1174 | 1610 | $send = @ socket_send( $r , $aprs_login , strlen($aprs_login) , 0 ); |
@@ -1194,49 +1630,82 @@ discard block |
||
1194 | 1630 | $aprs_last_tx = time(); |
1195 | 1631 | $data = array(); |
1196 | 1632 | //print_r($line); |
1197 | - if (isset($line['address'])) $data['hex'] = $line['address']; |
|
1198 | - if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']); |
|
1199 | - else $data['datetime'] = date('Y-m-d H:i:s'); |
|
1633 | + if (isset($line['address'])) { |
|
1634 | + $data['hex'] = $line['address']; |
|
1635 | + } |
|
1636 | + if (isset($line['timestamp'])) { |
|
1637 | + $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']); |
|
1638 | + } else { |
|
1639 | + $data['datetime'] = date('Y-m-d H:i:s'); |
|
1640 | + } |
|
1200 | 1641 | //$data['datetime'] = date('Y-m-d H:i:s'); |
1201 | - if (isset($line['ident'])) $data['ident'] = $line['ident']; |
|
1642 | + if (isset($line['ident'])) { |
|
1643 | + $data['ident'] = $line['ident']; |
|
1644 | + } |
|
1202 | 1645 | $data['latitude'] = $line['latitude']; |
1203 | 1646 | $data['longitude'] = $line['longitude']; |
1204 | 1647 | //$data['verticalrate'] = $line[16]; |
1205 | - if (isset($line['speed'])) $data['speed'] = $line['speed']; |
|
1206 | - else $data['speed'] = 0; |
|
1207 | - if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; |
|
1208 | - if (isset($line['comment'])) $data['comment'] = $line['comment']; |
|
1209 | - if (isset($line['symbol'])) $data['type'] = $line['symbol']; |
|
1210 | - if (isset($line['heading'])) $data['heading'] = $line['heading']; |
|
1648 | + if (isset($line['speed'])) { |
|
1649 | + $data['speed'] = $line['speed']; |
|
1650 | + } else { |
|
1651 | + $data['speed'] = 0; |
|
1652 | + } |
|
1653 | + if (isset($line['altitude'])) { |
|
1654 | + $data['altitude'] = $line['altitude']; |
|
1655 | + } |
|
1656 | + if (isset($line['comment'])) { |
|
1657 | + $data['comment'] = $line['comment']; |
|
1658 | + } |
|
1659 | + if (isset($line['symbol'])) { |
|
1660 | + $data['type'] = $line['symbol']; |
|
1661 | + } |
|
1662 | + if (isset($line['heading'])) { |
|
1663 | + $data['heading'] = $line['heading']; |
|
1664 | + } |
|
1211 | 1665 | //else $data['heading'] = 0; |
1212 | - if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth']; |
|
1213 | - if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true; |
|
1666 | + if (isset($line['stealth'])) { |
|
1667 | + $data['aircraft_type'] = $line['stealth']; |
|
1668 | + } |
|
1669 | + if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) { |
|
1670 | + $data['noarchive'] = true; |
|
1671 | + } |
|
1214 | 1672 | $data['id_source'] = $id_source; |
1215 | - if (isset($line['format_source'])) $data['format_source'] = $line['format_source']; |
|
1216 | - else $data['format_source'] = 'aprs'; |
|
1673 | + if (isset($line['format_source'])) { |
|
1674 | + $data['format_source'] = $line['format_source']; |
|
1675 | + } else { |
|
1676 | + $data['format_source'] = 'aprs'; |
|
1677 | + } |
|
1217 | 1678 | $data['source_name'] = $line['source']; |
1218 | - if (isset($line['source_type'])) $data['source_type'] = $line['source_type']; |
|
1219 | - else $data['source_type'] = 'flarm'; |
|
1220 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1679 | + if (isset($line['source_type'])) { |
|
1680 | + $data['source_type'] = $line['source_type']; |
|
1681 | + } else { |
|
1682 | + $data['source_type'] = 'flarm'; |
|
1683 | + } |
|
1684 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
1685 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1686 | + } |
|
1221 | 1687 | $currentdate = date('Y-m-d H:i:s'); |
1222 | 1688 | $aprsdate = strtotime($data['datetime']); |
1223 | 1689 | // Accept data if time <= system time + 20s |
1224 | 1690 | if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) { |
1225 | 1691 | $send = $SI->add($data); |
1226 | 1692 | } elseif (isset($line['stealth'])) { |
1227 | - if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n"; |
|
1228 | - else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n"; |
|
1693 | + if ($line['stealth'] != 0) { |
|
1694 | + echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n"; |
|
1695 | + } else { |
|
1696 | + echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n"; |
|
1697 | + } |
|
1229 | 1698 | //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) { |
1230 | 1699 | } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') { |
1231 | 1700 | //echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n"; |
1232 | - if (isset($globalTracker) && $globalTracker) $send = $TI->add($data); |
|
1701 | + if (isset($globalTracker) && $globalTracker) { |
|
1702 | + $send = $TI->add($data); |
|
1703 | + } |
|
1233 | 1704 | } |
1234 | 1705 | unset($data); |
1235 | - } |
|
1236 | - elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') { |
|
1706 | + } elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') { |
|
1237 | 1707 | echo '!! Weather Station not yet supported'."\n"; |
1238 | - } |
|
1239 | - elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle')) { |
|
1708 | + } elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle')) { |
|
1240 | 1709 | echo '!! Car & Trucks not yet supported'."\n"; |
1241 | 1710 | } |
1242 | 1711 | //elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n"; |
@@ -1269,25 +1738,42 @@ discard block |
||
1269 | 1738 | $data['ground'] = $line[21]; |
1270 | 1739 | $data['emergency'] = $line[19]; |
1271 | 1740 | $data['format_source'] = 'sbs'; |
1272 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
1273 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1741 | + if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') { |
|
1742 | + $data['source_name'] = $globalSources[$nb]['name']; |
|
1743 | + } |
|
1744 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
1745 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1746 | + } |
|
1274 | 1747 | $data['id_source'] = $id_source; |
1275 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data); |
|
1276 | - else $error = true; |
|
1748 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
1749 | + $send = $SI->add($data); |
|
1750 | + } else { |
|
1751 | + $error = true; |
|
1752 | + } |
|
1277 | 1753 | unset($data); |
1278 | - } else $error = true; |
|
1754 | + } else { |
|
1755 | + $error = true; |
|
1756 | + } |
|
1279 | 1757 | if ($error) { |
1280 | 1758 | if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { |
1281 | - if ($globalDebug) echo "Not a message. Ignoring... \n"; |
|
1759 | + if ($globalDebug) { |
|
1760 | + echo "Not a message. Ignoring... \n"; |
|
1761 | + } |
|
1282 | 1762 | } else { |
1283 | - if ($globalDebug) echo "Wrong line format. Ignoring... \n"; |
|
1763 | + if ($globalDebug) { |
|
1764 | + echo "Wrong line format. Ignoring... \n"; |
|
1765 | + } |
|
1284 | 1766 | if ($globalDebug) { |
1285 | 1767 | echo $buffer; |
1286 | 1768 | print_r($line); |
1287 | 1769 | } |
1288 | 1770 | //socket_close($r); |
1289 | - if ($globalDebug) echo "Reconnect after an error...\n"; |
|
1290 | - if ($format == 'aprs') $aprs_connect = 0; |
|
1771 | + if ($globalDebug) { |
|
1772 | + echo "Reconnect after an error...\n"; |
|
1773 | + } |
|
1774 | + if ($format == 'aprs') { |
|
1775 | + $aprs_connect = 0; |
|
1776 | + } |
|
1291 | 1777 | $sourceer[$nb] = $globalSources[$nb]; |
1292 | 1778 | connect_all($sourceer); |
1293 | 1779 | $sourceer = array(); |
@@ -1295,10 +1781,14 @@ discard block |
||
1295 | 1781 | } |
1296 | 1782 | } |
1297 | 1783 | // Sleep for xxx microseconds |
1298 | - if (isset($globalSBSSleep)) usleep($globalSBSSleep); |
|
1784 | + if (isset($globalSBSSleep)) { |
|
1785 | + usleep($globalSBSSleep); |
|
1786 | + } |
|
1299 | 1787 | } else { |
1300 | 1788 | if ($format == 'flightgearmp') { |
1301 | - if ($globalDebug) echo "Reconnect FlightGear MP..."; |
|
1789 | + if ($globalDebug) { |
|
1790 | + echo "Reconnect FlightGear MP..."; |
|
1791 | + } |
|
1302 | 1792 | //@socket_close($r); |
1303 | 1793 | sleep($globalMinFetch); |
1304 | 1794 | $sourcefg[$nb] = $globalSources[$nb]; |
@@ -1307,10 +1797,15 @@ discard block |
||
1307 | 1797 | break; |
1308 | 1798 | |
1309 | 1799 | } elseif ($format != 'acars' && $format != 'flightgearsp') { |
1310 | - if (isset($tt[$format])) $tt[$format]++; |
|
1311 | - else $tt[$format] = 0; |
|
1800 | + if (isset($tt[$format])) { |
|
1801 | + $tt[$format]++; |
|
1802 | + } else { |
|
1803 | + $tt[$format] = 0; |
|
1804 | + } |
|
1312 | 1805 | if ($tt[$format] > 30) { |
1313 | - if ($globalDebug) echo "ERROR : Reconnect ".$format."..."; |
|
1806 | + if ($globalDebug) { |
|
1807 | + echo "ERROR : Reconnect ".$format."..."; |
|
1808 | + } |
|
1314 | 1809 | //@socket_close($r); |
1315 | 1810 | sleep(2); |
1316 | 1811 | $aprs_connect = 0; |
@@ -1327,11 +1822,17 @@ discard block |
||
1327 | 1822 | } else { |
1328 | 1823 | $error = socket_strerror(socket_last_error()); |
1329 | 1824 | if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) { |
1330 | - if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n"; |
|
1331 | - if (isset($globalDebug)) echo "Restarting...\n"; |
|
1825 | + if ($globalDebug) { |
|
1826 | + echo "ERROR : socket_select give this error ".$error . "\n"; |
|
1827 | + } |
|
1828 | + if (isset($globalDebug)) { |
|
1829 | + echo "Restarting...\n"; |
|
1830 | + } |
|
1332 | 1831 | // Restart the script if possible |
1333 | 1832 | if (is_array($sockets)) { |
1334 | - if ($globalDebug) echo "Shutdown all sockets..."; |
|
1833 | + if ($globalDebug) { |
|
1834 | + echo "Shutdown all sockets..."; |
|
1835 | + } |
|
1335 | 1836 | |
1336 | 1837 | foreach ($sockets as $sock) { |
1337 | 1838 | @socket_shutdown($sock,2); |
@@ -1339,18 +1840,24 @@ discard block |
||
1339 | 1840 | } |
1340 | 1841 | |
1341 | 1842 | } |
1342 | - if ($globalDebug) echo "Restart all connections..."; |
|
1843 | + if ($globalDebug) { |
|
1844 | + echo "Restart all connections..."; |
|
1845 | + } |
|
1343 | 1846 | sleep(2); |
1344 | 1847 | $time = time(); |
1345 | 1848 | //connect_all($hosts); |
1346 | 1849 | $aprs_connect = 0; |
1347 | - if ($reset > 40) exit('Too many attempts...'); |
|
1850 | + if ($reset > 40) { |
|
1851 | + exit('Too many attempts...'); |
|
1852 | + } |
|
1348 | 1853 | connect_all($globalSources); |
1349 | 1854 | } |
1350 | 1855 | } |
1351 | 1856 | } |
1352 | 1857 | if ($globalDaemon === false) { |
1353 | - if ($globalDebug) echo 'Check all...'."\n"; |
|
1858 | + if ($globalDebug) { |
|
1859 | + echo 'Check all...'."\n"; |
|
1860 | + } |
|
1354 | 1861 | $SI->checkAll(); |
1355 | 1862 | } |
1356 | 1863 | } |
@@ -59,7 +59,9 @@ discard block |
||
59 | 59 | $dbc = $this->db; |
60 | 60 | $this->all_flights[$id]['schedule_check'] = true; |
61 | 61 | if ($globalSchedulesFetch) { |
62 | - if ($globalDebug) echo 'Getting schedule info...'."\n"; |
|
62 | + if ($globalDebug) { |
|
63 | + echo 'Getting schedule info...'."\n"; |
|
64 | + } |
|
63 | 65 | $Spotter = new Spotter($dbc); |
64 | 66 | $Schedule = new Schedule($dbc); |
65 | 67 | $Translation = new Translation($dbc); |
@@ -70,7 +72,9 @@ discard block |
||
70 | 72 | if ($Schedule->checkSchedule($operator) == 0) { |
71 | 73 | $schedule = $Schedule->fetchSchedule($operator); |
72 | 74 | if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) { |
73 | - if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n"; |
|
75 | + if ($globalDebug) { |
|
76 | + echo "-> Schedule info for ".$operator." (".$ident.")\n"; |
|
77 | + } |
|
74 | 78 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime'])); |
75 | 79 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime'])); |
76 | 80 | // Should also check if route schedule = route from DB |
@@ -79,7 +83,9 @@ discard block |
||
79 | 83 | $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']); |
80 | 84 | if (trim($airport_icao) != '') { |
81 | 85 | $this->all_flights[$id]['departure_airport'] = $airport_icao; |
82 | - if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n"; |
|
86 | + if ($globalDebug) { |
|
87 | + echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n"; |
|
88 | + } |
|
83 | 89 | } |
84 | 90 | } |
85 | 91 | } |
@@ -88,17 +94,25 @@ discard block |
||
88 | 94 | $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']); |
89 | 95 | if (trim($airport_icao) != '') { |
90 | 96 | $this->all_flights[$id]['arrival_airport'] = $airport_icao; |
91 | - if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n"; |
|
97 | + if ($globalDebug) { |
|
98 | + echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n"; |
|
99 | + } |
|
92 | 100 | } |
93 | 101 | } |
94 | 102 | } |
95 | 103 | $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']); |
96 | 104 | } |
97 | - } else $scheduleexist = true; |
|
98 | - } else $scheduleexist = true; |
|
105 | + } else { |
|
106 | + $scheduleexist = true; |
|
107 | + } |
|
108 | + } else { |
|
109 | + $scheduleexist = true; |
|
110 | + } |
|
99 | 111 | // close connection, at least one way will work ? |
100 | 112 | if ($scheduleexist) { |
101 | - if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n"; |
|
113 | + if ($globalDebug) { |
|
114 | + echo "-> get arrival/departure airport info for ".$ident."\n"; |
|
115 | + } |
|
102 | 116 | $sch = $Schedule->getSchedule($operator); |
103 | 117 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time'])); |
104 | 118 | } |
@@ -120,7 +134,9 @@ discard block |
||
120 | 134 | |
121 | 135 | public function checkAll() { |
122 | 136 | global $globalDebug, $globalNoImport; |
123 | - if ($globalDebug) echo "Update last seen flights data...\n"; |
|
137 | + if ($globalDebug) { |
|
138 | + echo "Update last seen flights data...\n"; |
|
139 | + } |
|
124 | 140 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
125 | 141 | foreach ($this->all_flights as $key => $flight) { |
126 | 142 | if (isset($this->all_flights[$key]['id'])) { |
@@ -135,24 +151,32 @@ discard block |
||
135 | 151 | |
136 | 152 | public function arrival($key) { |
137 | 153 | global $globalClosestMinDist, $globalDebug; |
138 | - if ($globalDebug) echo 'Update arrival...'."\n"; |
|
154 | + if ($globalDebug) { |
|
155 | + echo 'Update arrival...'."\n"; |
|
156 | + } |
|
139 | 157 | $Spotter = new Spotter($this->db); |
140 | 158 | $airport_icao = ''; |
141 | 159 | $airport_time = ''; |
142 | - if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50; |
|
160 | + if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') { |
|
161 | + $globalClosestMinDist = 50; |
|
162 | + } |
|
143 | 163 | if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { |
144 | 164 | $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist); |
145 | 165 | if (isset($closestAirports[0])) { |
146 | 166 | if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) { |
147 | 167 | $airport_icao = $closestAirports[0]['icao']; |
148 | 168 | $airport_time = $this->all_flights[$key]['datetime']; |
149 | - if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
169 | + if ($globalDebug) { |
|
170 | + echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
171 | + } |
|
150 | 172 | } elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') { |
151 | 173 | foreach ($closestAirports as $airport) { |
152 | 174 | if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) { |
153 | 175 | $airport_icao = $airport['icao']; |
154 | 176 | $airport_time = $this->all_flights[$key]['datetime']; |
155 | - if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
177 | + if ($globalDebug) { |
|
178 | + echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
179 | + } |
|
156 | 180 | break; |
157 | 181 | } |
158 | 182 | } |
@@ -160,14 +184,20 @@ discard block |
||
160 | 184 | $airport_icao = $closestAirports[0]['icao']; |
161 | 185 | $airport_time = $this->all_flights[$key]['datetime']; |
162 | 186 | } else { |
163 | - if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n"; |
|
187 | + if ($globalDebug) { |
|
188 | + echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n"; |
|
189 | + } |
|
164 | 190 | } |
165 | 191 | } else { |
166 | - if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n"; |
|
192 | + if ($globalDebug) { |
|
193 | + echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n"; |
|
194 | + } |
|
167 | 195 | } |
168 | 196 | |
169 | 197 | } else { |
170 | - if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n"; |
|
198 | + if ($globalDebug) { |
|
199 | + echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n"; |
|
200 | + } |
|
171 | 201 | } |
172 | 202 | return array('airport_icao' => $airport_icao,'airport_time' => $airport_time); |
173 | 203 | } |
@@ -177,12 +207,16 @@ discard block |
||
177 | 207 | public function del() { |
178 | 208 | global $globalDebug, $globalNoImport; |
179 | 209 | // Delete old infos |
180 | - if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
|
210 | + if ($globalDebug) { |
|
211 | + echo 'Delete old values and update latest data...'."\n"; |
|
212 | + } |
|
181 | 213 | foreach ($this->all_flights as $key => $flight) { |
182 | 214 | if (isset($flight['lastupdate'])) { |
183 | 215 | if ($flight['lastupdate'] < (time()-3000)) { |
184 | 216 | if (isset($this->all_flights[$key]['id'])) { |
185 | - if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n"; |
|
217 | + if ($globalDebug) { |
|
218 | + echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n"; |
|
219 | + } |
|
186 | 220 | /* |
187 | 221 | $SpotterLive = new SpotterLive(); |
188 | 222 | $SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']); |
@@ -193,7 +227,9 @@ discard block |
||
193 | 227 | $Spotter = new Spotter($this->db); |
194 | 228 | if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { |
195 | 229 | $result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']); |
196 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
230 | + if ($globalDebug && $result != 'success') { |
|
231 | + echo '!!! ERROR : '.$result."\n"; |
|
232 | + } |
|
197 | 233 | } |
198 | 234 | // Put in archive |
199 | 235 | // $Spotter->db = null; |
@@ -208,8 +244,10 @@ discard block |
||
208 | 244 | public function add($line) { |
209 | 245 | global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights, $globalServerAPRS, $APRSSpotter, $globalNoImport; |
210 | 246 | //if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE; |
211 | - if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02'; |
|
212 | -/* |
|
247 | + if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') { |
|
248 | + $globalCoordMinChange = '0.02'; |
|
249 | + } |
|
250 | + /* |
|
213 | 251 | $Spotter = new Spotter(); |
214 | 252 | $dbc = $Spotter->db; |
215 | 253 | $SpotterLive = new SpotterLive($dbc); |
@@ -237,11 +275,15 @@ discard block |
||
237 | 275 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) { |
238 | 276 | $current_date = date('Y-m-d'); |
239 | 277 | $source = $line['source_name']; |
240 | - if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source']; |
|
278 | + if ($source == '' || $line['format_source'] == 'aprs') { |
|
279 | + $source = $line['format_source']; |
|
280 | + } |
|
241 | 281 | if (!isset($this->stats[$current_date][$source]['msg'])) { |
242 | 282 | $this->stats[$current_date][$source]['msg']['date'] = time(); |
243 | 283 | $this->stats[$current_date][$source]['msg']['nb'] = 1; |
244 | - } else $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
284 | + } else { |
|
285 | + $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
286 | + } |
|
245 | 287 | } |
246 | 288 | |
247 | 289 | /* |
@@ -257,8 +299,11 @@ discard block |
||
257 | 299 | //$this->db = $dbc; |
258 | 300 | |
259 | 301 | //$hex = trim($line['hex']); |
260 | - if (!isset($line['id'])) $id = trim($line['hex']); |
|
261 | - else $id = trim($line['id']); |
|
302 | + if (!isset($line['id'])) { |
|
303 | + $id = trim($line['hex']); |
|
304 | + } else { |
|
305 | + $id = trim($line['id']); |
|
306 | + } |
|
262 | 307 | |
263 | 308 | if (!isset($this->all_flights[$id])) { |
264 | 309 | $this->all_flights[$id] = array(); |
@@ -266,13 +311,21 @@ discard block |
||
266 | 311 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => '')); |
267 | 312 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time())); |
268 | 313 | if (!isset($line['id'])) { |
269 | - if (!isset($globalDaemon)) $globalDaemon = TRUE; |
|
270 | -// if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi'))); |
|
314 | + if (!isset($globalDaemon)) { |
|
315 | + $globalDaemon = TRUE; |
|
316 | + } |
|
317 | + // if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi'))); |
|
271 | 318 | // if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
272 | - if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
319 | + if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) { |
|
320 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
321 | + } |
|
273 | 322 | //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
274 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
275 | - if ($globalAllFlights !== FALSE) $dataFound = true; |
|
323 | + } else { |
|
324 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
325 | + } |
|
326 | + if ($globalAllFlights !== FALSE) { |
|
327 | + $dataFound = true; |
|
328 | + } |
|
276 | 329 | } |
277 | 330 | if (isset($line['source_type']) && $line['source_type'] != '') { |
278 | 331 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type'])); |
@@ -293,11 +346,19 @@ discard block |
||
293 | 346 | $aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex'])); |
294 | 347 | } |
295 | 348 | $Spotter->db = null; |
296 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
297 | - if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
349 | + if ($globalDebugTimeElapsed) { |
|
350 | + echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
351 | + } |
|
352 | + if ($aircraft_icao != '') { |
|
353 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
354 | + } |
|
355 | + } |
|
356 | + if ($globalAllFlights !== FALSE) { |
|
357 | + $dataFound = true; |
|
358 | + } |
|
359 | + if ($globalDebug) { |
|
360 | + echo "*********** New aircraft hex : ".$line['hex']." ***********\n"; |
|
298 | 361 | } |
299 | - if ($globalAllFlights !== FALSE) $dataFound = true; |
|
300 | - if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n"; |
|
301 | 362 | } |
302 | 363 | if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') { |
303 | 364 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao'])); |
@@ -307,14 +368,23 @@ discard block |
||
307 | 368 | $Spotter = new Spotter($this->db); |
308 | 369 | $aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']); |
309 | 370 | $Spotter->db = null; |
310 | - if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
371 | + if ($aircraft_icao != '') { |
|
372 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
373 | + } |
|
311 | 374 | } |
312 | 375 | if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) { |
313 | - if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID'; |
|
314 | - elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL'; |
|
315 | - elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE'; |
|
316 | - elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC'; |
|
317 | - if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
376 | + if ($line['aircraft_type'] == 'PARA_GLIDER') { |
|
377 | + $aircraft_icao = 'GLID'; |
|
378 | + } elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') { |
|
379 | + $aircraft_icao = 'UHEL'; |
|
380 | + } elseif ($line['aircraft_type'] == 'TOW_PLANE') { |
|
381 | + $aircraft_icao = 'TOWPLANE'; |
|
382 | + } elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') { |
|
383 | + $aircraft_icao = 'POWAIRC'; |
|
384 | + } |
|
385 | + if (isset($aircraft_icao)) { |
|
386 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
387 | + } |
|
318 | 388 | } |
319 | 389 | if (!isset($this->all_flights[$id]['aircraft_icao'])) { |
320 | 390 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA')); |
@@ -324,8 +394,11 @@ discard block |
||
324 | 394 | if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) { |
325 | 395 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime'])); |
326 | 396 | } else { |
327 | - if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
328 | - elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
397 | + if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) { |
|
398 | + echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
399 | + } elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) { |
|
400 | + echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
401 | + } |
|
329 | 402 | /* |
330 | 403 | echo strtotime($line['datetime']).' > '.strtotime($this->all_flights[$id]['datetime']); |
331 | 404 | print_r($this->all_flights[$id]); |
@@ -357,15 +430,25 @@ discard block |
||
357 | 430 | $timeelapsed = microtime(true); |
358 | 431 | $Spotter = new Spotter($this->db); |
359 | 432 | $fromsource = NULL; |
360 | - if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource; |
|
361 | - elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim'; |
|
362 | - elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao'; |
|
363 | - elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim'; |
|
364 | - elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao'; |
|
433 | + if (isset($globalAirlinesSource) && $globalAirlinesSource != '') { |
|
434 | + $fromsource = $globalAirlinesSource; |
|
435 | + } elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') { |
|
436 | + $fromsource = 'vatsim'; |
|
437 | + } elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') { |
|
438 | + $fromsource = 'ivao'; |
|
439 | + } elseif (isset($globalVATSIM) && $globalVATSIM) { |
|
440 | + $fromsource = 'vatsim'; |
|
441 | + } elseif (isset($globalIVAO) && $globalIVAO) { |
|
442 | + $fromsource = 'ivao'; |
|
443 | + } |
|
365 | 444 | $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource); |
366 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
445 | + if ($globalDebug && $result != 'success') { |
|
446 | + echo '!!! ERROR : '.$result."\n"; |
|
447 | + } |
|
367 | 448 | $Spotter->db = null; |
368 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
449 | + if ($globalDebugTimeElapsed) { |
|
450 | + echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
451 | + } |
|
369 | 452 | } |
370 | 453 | |
371 | 454 | /* |
@@ -376,7 +459,9 @@ discard block |
||
376 | 459 | else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
377 | 460 | } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
378 | 461 | */ |
379 | - if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
462 | + if (!isset($this->all_flights[$id]['id'])) { |
|
463 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
464 | + } |
|
380 | 465 | |
381 | 466 | //$putinarchive = true; |
382 | 467 | if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) { |
@@ -393,7 +478,9 @@ discard block |
||
393 | 478 | $line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']); |
394 | 479 | $line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']); |
395 | 480 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => '')); |
396 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
481 | + if ($globalDebugTimeElapsed) { |
|
482 | + echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
483 | + } |
|
397 | 484 | |
398 | 485 | } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') { |
399 | 486 | $timeelapsed = microtime(true); |
@@ -406,7 +493,9 @@ discard block |
||
406 | 493 | $Translation->db = null; |
407 | 494 | } |
408 | 495 | $Spotter->db = null; |
409 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
496 | + if ($globalDebugTimeElapsed) { |
|
497 | + echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
498 | + } |
|
410 | 499 | |
411 | 500 | if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) { |
412 | 501 | //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) { |
@@ -415,9 +504,13 @@ discard block |
||
415 | 504 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop'])); |
416 | 505 | } |
417 | 506 | } |
418 | - if (!isset($globalFork)) $globalFork = TRUE; |
|
507 | + if (!isset($globalFork)) { |
|
508 | + $globalFork = TRUE; |
|
509 | + } |
|
419 | 510 | if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) { |
420 | - if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident'])); |
|
511 | + if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) { |
|
512 | + $this->get_Schedule($id,trim($line['ident'])); |
|
513 | + } |
|
421 | 514 | } |
422 | 515 | } |
423 | 516 | } |
@@ -433,16 +526,23 @@ discard block |
||
433 | 526 | // use datetime |
434 | 527 | $speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']); |
435 | 528 | $speed = $speed*3.6; |
436 | - if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed))); |
|
437 | - if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
|
529 | + if ($speed < 1000) { |
|
530 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed))); |
|
531 | + } |
|
532 | + if ($globalDebug) { |
|
533 | + echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
|
534 | + } |
|
438 | 535 | } |
439 | 536 | } |
440 | 537 | |
441 | 538 | |
442 | 539 | |
443 | 540 | if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
444 | - if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']); |
|
445 | - else unset($timediff); |
|
541 | + if (isset($this->all_flights[$id]['time_last_coord'])) { |
|
542 | + $timediff = round(time()-$this->all_flights[$id]['time_last_coord']); |
|
543 | + } else { |
|
544 | + unset($timediff); |
|
545 | + } |
|
446 | 546 | if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) { |
447 | 547 | if (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude'])) { |
448 | 548 | if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) { |
@@ -451,21 +551,31 @@ discard block |
||
451 | 551 | $this->all_flights[$id]['putinarchive'] = true; |
452 | 552 | $this->tmd = 0; |
453 | 553 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
454 | - if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
|
554 | + if ($globalDebug) { |
|
555 | + echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
|
556 | + } |
|
455 | 557 | $timeelapsed = microtime(true); |
456 | 558 | $Spotter = new Spotter($this->db); |
457 | 559 | $all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
458 | - if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2']; |
|
560 | + if (!empty($all_country)) { |
|
561 | + $this->all_flights[$id]['over_country'] = $all_country['iso2']; |
|
562 | + } |
|
459 | 563 | $Spotter->db = null; |
460 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
461 | - if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n"; |
|
564 | + if ($globalDebugTimeElapsed) { |
|
565 | + echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
566 | + } |
|
567 | + if ($globalDebug) { |
|
568 | + echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n"; |
|
569 | + } |
|
462 | 570 | } |
463 | 571 | } |
464 | 572 | } |
465 | 573 | |
466 | 574 | if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
467 | 575 | //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) { |
468 | - if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude']; |
|
576 | + if (!isset($this->all_flights[$id]['archive_latitude'])) { |
|
577 | + $this->all_flights[$id]['archive_latitude'] = $line['latitude']; |
|
578 | + } |
|
469 | 579 | if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') { |
470 | 580 | $this->all_flights[$id]['livedb_latitude'] = $line['latitude']; |
471 | 581 | $dataFound = true; |
@@ -487,9 +597,13 @@ discard block |
||
487 | 597 | */ |
488 | 598 | } |
489 | 599 | if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { |
490 | - if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
600 | + if ($line['longitude'] > 180) { |
|
601 | + $line['longitude'] = $line['longitude'] - 360; |
|
602 | + } |
|
491 | 603 | //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == '' || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) { |
492 | - if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
|
604 | + if (!isset($this->all_flights[$id]['archive_longitude'])) { |
|
605 | + $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
|
606 | + } |
|
493 | 607 | if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') { |
494 | 608 | $this->all_flights[$id]['livedb_longitude'] = $line['longitude']; |
495 | 609 | $dataFound = true; |
@@ -520,7 +634,9 @@ discard block |
||
520 | 634 | } |
521 | 635 | } |
522 | 636 | if (isset($line['last_update']) && $line['last_update'] != '') { |
523 | - if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
637 | + if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) { |
|
638 | + $dataFound = true; |
|
639 | + } |
|
524 | 640 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update'])); |
525 | 641 | } |
526 | 642 | if (isset($line['verticalrate']) && $line['verticalrate'] != '') { |
@@ -542,40 +658,60 @@ discard block |
||
542 | 658 | // Here we force archive of flight because after ground it's a new one (or should be) |
543 | 659 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
544 | 660 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1)); |
545 | - if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi'))); |
|
546 | - elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
547 | - elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
661 | + if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) { |
|
662 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi'))); |
|
663 | + } elseif (isset($line['id'])) { |
|
664 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
665 | + } elseif (isset($this->all_flights[$id]['ident'])) { |
|
666 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
667 | + } |
|
668 | + } |
|
669 | + if ($line['ground'] != 1) { |
|
670 | + $line['ground'] = 0; |
|
548 | 671 | } |
549 | - if ($line['ground'] != 1) $line['ground'] = 0; |
|
550 | 672 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground'])); |
551 | 673 | //$dataFound = true; |
552 | 674 | } |
553 | 675 | if (isset($line['squawk']) && $line['squawk'] != '') { |
554 | 676 | if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) { |
555 | - if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true; |
|
677 | + if ($this->all_flights[$id]['squawk'] != $line['squawk']) { |
|
678 | + $this->all_flights[$id]['putinarchive'] = true; |
|
679 | + } |
|
556 | 680 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
557 | 681 | $highlight = ''; |
558 | - if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC'; |
|
559 | - if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC'; |
|
560 | - if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC'; |
|
682 | + if ($this->all_flights[$id]['squawk'] == '7500') { |
|
683 | + $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC'; |
|
684 | + } |
|
685 | + if ($this->all_flights[$id]['squawk'] == '7600') { |
|
686 | + $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC'; |
|
687 | + } |
|
688 | + if ($this->all_flights[$id]['squawk'] == '7700') { |
|
689 | + $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC'; |
|
690 | + } |
|
561 | 691 | if ($highlight != '') { |
562 | 692 | $timeelapsed = microtime(true); |
563 | 693 | $Spotter = new Spotter($this->db); |
564 | 694 | $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight); |
565 | 695 | $Spotter->db = null; |
566 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
696 | + if ($globalDebugTimeElapsed) { |
|
697 | + echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
698 | + } |
|
567 | 699 | |
568 | 700 | //$putinarchive = true; |
569 | 701 | //$highlight = ''; |
570 | 702 | } |
571 | 703 | |
572 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
704 | + } else { |
|
705 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
706 | + } |
|
573 | 707 | //$dataFound = true; |
574 | 708 | } |
575 | 709 | |
576 | 710 | if (isset($line['altitude']) && $line['altitude'] != '') { |
577 | 711 | //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) { |
578 | - if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true; |
|
712 | + if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) { |
|
713 | + $this->all_flights[$id]['putinarchive'] = true; |
|
714 | + } |
|
579 | 715 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100))); |
580 | 716 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude'])); |
581 | 717 | //$dataFound = true; |
@@ -587,21 +723,30 @@ discard block |
||
587 | 723 | } |
588 | 724 | |
589 | 725 | if (isset($line['heading']) && $line['heading'] != '') { |
590 | - if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true; |
|
726 | + if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) { |
|
727 | + $this->all_flights[$id]['putinarchive'] = true; |
|
728 | + } |
|
591 | 729 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading']))); |
592 | 730 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true)); |
593 | 731 | //$dataFound = true; |
594 | 732 | } elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) { |
595 | 733 | $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']); |
596 | 734 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading))); |
597 | - if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true; |
|
598 | - if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n"; |
|
735 | + if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) { |
|
736 | + $this->all_flights[$id]['putinarchive'] = true; |
|
737 | + } |
|
738 | + if ($globalDebug) { |
|
739 | + echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n"; |
|
740 | + } |
|
599 | 741 | } elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') { |
600 | 742 | // If not enough messages and ACARS set heading to 0 |
601 | 743 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0)); |
602 | 744 | } |
603 | - if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
|
604 | - elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false; |
|
745 | + if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) { |
|
746 | + $dataFound = false; |
|
747 | + } elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) { |
|
748 | + $dataFound = false; |
|
749 | + } |
|
605 | 750 | |
606 | 751 | // print_r($this->all_flights[$id]); |
607 | 752 | //gets the callsign from the last hour |
@@ -616,23 +761,36 @@ discard block |
||
616 | 761 | //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n"; |
617 | 762 | //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']); |
618 | 763 | if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) { |
619 | - if ($globalDebug) echo "Check if aircraft is already in DB..."; |
|
764 | + if ($globalDebug) { |
|
765 | + echo "Check if aircraft is already in DB..."; |
|
766 | + } |
|
620 | 767 | $timeelapsed = microtime(true); |
621 | 768 | $SpotterLive = new SpotterLive($this->db); |
622 | 769 | if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) { |
623 | 770 | $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']); |
624 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
771 | + if ($globalDebugTimeElapsed) { |
|
772 | + echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
773 | + } |
|
625 | 774 | } elseif (isset($line['id'])) { |
626 | 775 | $recent_ident = $SpotterLive->checkIdRecent($line['id']); |
627 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
776 | + if ($globalDebugTimeElapsed) { |
|
777 | + echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
778 | + } |
|
628 | 779 | } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') { |
629 | 780 | $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']); |
630 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
631 | - } else $recent_ident = ''; |
|
781 | + if ($globalDebugTimeElapsed) { |
|
782 | + echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
783 | + } |
|
784 | + } else { |
|
785 | + $recent_ident = ''; |
|
786 | + } |
|
632 | 787 | $SpotterLive->db=null; |
633 | 788 | |
634 | - if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
|
635 | - elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
|
789 | + if ($globalDebug && $recent_ident == '') { |
|
790 | + echo " Not in DB.\n"; |
|
791 | + } elseif ($globalDebug && $recent_ident != '') { |
|
792 | + echo " Already in DB.\n"; |
|
793 | + } |
|
636 | 794 | } else { |
637 | 795 | $recent_ident = ''; |
638 | 796 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0)); |
@@ -640,7 +798,9 @@ discard block |
||
640 | 798 | //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
641 | 799 | if($recent_ident == "") |
642 | 800 | { |
643 | - if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : "; |
|
801 | + if ($globalDebug) { |
|
802 | + echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : "; |
|
803 | + } |
|
644 | 804 | if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } |
645 | 805 | if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } |
646 | 806 | //adds the spotter data for the archive |
@@ -684,28 +844,46 @@ discard block |
||
684 | 844 | |
685 | 845 | if (!$ignoreImport) { |
686 | 846 | $highlight = ''; |
687 | - if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack'; |
|
688 | - if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)'; |
|
689 | - if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency'; |
|
690 | - if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
|
847 | + if ($this->all_flights[$id]['squawk'] == '7500') { |
|
848 | + $highlight = 'Squawk 7500 : Hijack'; |
|
849 | + } |
|
850 | + if ($this->all_flights[$id]['squawk'] == '7600') { |
|
851 | + $highlight = 'Squawk 7600 : Lost Comm (radio failure)'; |
|
852 | + } |
|
853 | + if ($this->all_flights[$id]['squawk'] == '7700') { |
|
854 | + $highlight = 'Squawk 7700 : Emergency'; |
|
855 | + } |
|
856 | + if (!isset($this->all_flights[$id]['id'])) { |
|
857 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
|
858 | + } |
|
691 | 859 | $timeelapsed = microtime(true); |
692 | 860 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
693 | 861 | $Spotter = new Spotter($this->db); |
694 | 862 | $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']); |
695 | 863 | $Spotter->db = null; |
696 | - if ($globalDebug && isset($result)) echo $result."\n"; |
|
864 | + if ($globalDebug && isset($result)) { |
|
865 | + echo $result."\n"; |
|
866 | + } |
|
867 | + } |
|
868 | + if ($globalDebugTimeElapsed) { |
|
869 | + echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
697 | 870 | } |
698 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
699 | 871 | |
700 | 872 | // Add source stat in DB |
701 | 873 | $Stats = new Stats($this->db); |
702 | 874 | if (!empty($this->stats)) { |
703 | - if ($globalDebug) echo 'Add source stats : '; |
|
875 | + if ($globalDebug) { |
|
876 | + echo 'Add source stats : '; |
|
877 | + } |
|
704 | 878 | foreach($this->stats as $date => $data) { |
705 | 879 | foreach($data as $source => $sourced) { |
706 | 880 | //print_r($sourced); |
707 | - if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date); |
|
708 | - if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date); |
|
881 | + if (isset($sourced['polar'])) { |
|
882 | + echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date); |
|
883 | + } |
|
884 | + if (isset($sourced['hist'])) { |
|
885 | + echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date); |
|
886 | + } |
|
709 | 887 | if (isset($sourced['msg'])) { |
710 | 888 | if (time() - $sourced['msg']['date'] > 10) { |
711 | 889 | $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
@@ -718,13 +896,17 @@ discard block |
||
718 | 896 | unset($this->stats[$date]); |
719 | 897 | } |
720 | 898 | } |
721 | - if ($globalDebug) echo 'Done'."\n"; |
|
899 | + if ($globalDebug) { |
|
900 | + echo 'Done'."\n"; |
|
901 | + } |
|
722 | 902 | |
723 | 903 | } |
724 | 904 | $Stats->db = null; |
725 | 905 | |
726 | 906 | $this->del(); |
727 | - } elseif ($globalDebug) echo 'Ignore data'."\n"; |
|
907 | + } elseif ($globalDebug) { |
|
908 | + echo 'Ignore data'."\n"; |
|
909 | + } |
|
728 | 910 | //$ignoreImport = false; |
729 | 911 | $this->all_flights[$id]['addedSpotter'] = 1; |
730 | 912 | //print_r($this->all_flights[$id]); |
@@ -741,14 +923,18 @@ discard block |
||
741 | 923 | */ |
742 | 924 | //SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']); |
743 | 925 | if ($this->last_delete == 0 || time() - $this->last_delete > 1800) { |
744 | - if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours..."; |
|
926 | + if ($globalDebug) { |
|
927 | + echo "---- Deleting Live Spotter data older than 9 hours..."; |
|
928 | + } |
|
745 | 929 | //SpotterLive->deleteLiveSpotterDataNotUpdated(); |
746 | 930 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
747 | 931 | $SpotterLive = new SpotterLive($this->db); |
748 | 932 | $SpotterLive->deleteLiveSpotterData(); |
749 | 933 | $SpotterLive->db=null; |
750 | 934 | } |
751 | - if ($globalDebug) echo " Done\n"; |
|
935 | + if ($globalDebug) { |
|
936 | + echo " Done\n"; |
|
937 | + } |
|
752 | 938 | $this->last_delete = time(); |
753 | 939 | } |
754 | 940 | } else { |
@@ -773,11 +959,17 @@ discard block |
||
773 | 959 | //echo "{$line[8]} {$line[7]} - MODES:{$line[4]} CALLSIGN:{$line[10]} ALT:{$line[11]} VEL:{$line[12]} HDG:{$line[13]} LAT:{$line[14]} LON:{$line[15]} VR:{$line[16]} SQUAWK:{$line[17]}\n"; |
774 | 960 | if ($globalDebug) { |
775 | 961 | if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) { |
776 | - if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n"; |
|
777 | - else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n"; |
|
962 | + if (isset($this->all_flights[$id]['source_name'])) { |
|
963 | + echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n"; |
|
964 | + } else { |
|
965 | + echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n"; |
|
966 | + } |
|
778 | 967 | } else { |
779 | - if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n"; |
|
780 | - else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n"; |
|
968 | + if (isset($this->all_flights[$id]['source_name'])) { |
|
969 | + echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n"; |
|
970 | + } else { |
|
971 | + echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n"; |
|
972 | + } |
|
781 | 973 | } |
782 | 974 | } |
783 | 975 | $ignoreImport = false; |
@@ -823,27 +1015,37 @@ discard block |
||
823 | 1015 | |
824 | 1016 | if (!$ignoreImport) { |
825 | 1017 | if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
826 | - if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
|
1018 | + if (!isset($this->all_flights[$id]['id'])) { |
|
1019 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
|
1020 | + } |
|
827 | 1021 | $timeelapsed = microtime(true); |
828 | 1022 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
829 | - if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : "; |
|
1023 | + if ($globalDebug) { |
|
1024 | + echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : "; |
|
1025 | + } |
|
830 | 1026 | $SpotterLive = new SpotterLive($this->db); |
831 | 1027 | $result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']); |
832 | 1028 | $SpotterLive->db = null; |
833 | - if ($globalDebug) echo $result."\n"; |
|
1029 | + if ($globalDebug) { |
|
1030 | + echo $result."\n"; |
|
1031 | + } |
|
834 | 1032 | } |
835 | 1033 | if (isset($globalServerAPRS) && $globalServerAPRS) { |
836 | 1034 | $APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']); |
837 | 1035 | } |
838 | 1036 | $this->all_flights[$id]['putinarchive'] = false; |
839 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
1037 | + if ($globalDebugTimeElapsed) { |
|
1038 | + echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
1039 | + } |
|
840 | 1040 | |
841 | 1041 | // Put statistics in $this->stats variable |
842 | 1042 | //if ($line['format_source'] != 'aprs') { |
843 | 1043 | //if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt')) { |
844 | 1044 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') { |
845 | 1045 | $source = $this->all_flights[$id]['source_name']; |
846 | - if ($source == '') $source = $this->all_flights[$id]['format_source']; |
|
1046 | + if ($source == '') { |
|
1047 | + $source = $this->all_flights[$id]['format_source']; |
|
1048 | + } |
|
847 | 1049 | if (!isset($this->source_location[$source])) { |
848 | 1050 | $Location = new Source(); |
849 | 1051 | $coord = $Location->getLocationInfobySourceName($source); |
@@ -864,7 +1066,9 @@ discard block |
||
864 | 1066 | $stats_heading = round($stats_heading/22.5); |
865 | 1067 | $stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']); |
866 | 1068 | $current_date = date('Y-m-d'); |
867 | - if ($stats_heading == 16) $stats_heading = 0; |
|
1069 | + if ($stats_heading == 16) { |
|
1070 | + $stats_heading = 0; |
|
1071 | + } |
|
868 | 1072 | if (!isset($this->stats[$current_date][$source]['polar'][1])) { |
869 | 1073 | for ($i=0;$i<=15;$i++) { |
870 | 1074 | $this->stats[$current_date][$source]['polar'][$i] = 0; |
@@ -882,7 +1086,9 @@ discard block |
||
882 | 1086 | if (isset($this->stats[$current_date][$source]['hist'][0])) { |
883 | 1087 | end($this->stats[$current_date][$source]['hist']); |
884 | 1088 | $mini = key($this->stats[$current_date][$source]['hist'])+10; |
885 | - } else $mini = 0; |
|
1089 | + } else { |
|
1090 | + $mini = 0; |
|
1091 | + } |
|
886 | 1092 | for ($i=$mini;$i<=$distance;$i+=10) { |
887 | 1093 | $this->stats[$current_date][$source]['hist'][$i] = 0; |
888 | 1094 | } |
@@ -893,19 +1099,27 @@ discard block |
||
893 | 1099 | } |
894 | 1100 | |
895 | 1101 | $this->all_flights[$id]['lastupdate'] = time(); |
896 | - if ($this->all_flights[$id]['putinarchive']) $send = true; |
|
1102 | + if ($this->all_flights[$id]['putinarchive']) { |
|
1103 | + $send = true; |
|
1104 | + } |
|
897 | 1105 | //if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
898 | - } elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
|
1106 | + } elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) { |
|
1107 | + echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
|
1108 | + } |
|
899 | 1109 | //$this->del(); |
900 | 1110 | |
901 | 1111 | if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) { |
902 | 1112 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
903 | - if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour..."; |
|
1113 | + if ($globalDebug) { |
|
1114 | + echo "---- Deleting Live Spotter data Not updated since 2 hour..."; |
|
1115 | + } |
|
904 | 1116 | $SpotterLive = new SpotterLive($this->db); |
905 | 1117 | $SpotterLive->deleteLiveSpotterDataNotUpdated(); |
906 | 1118 | $SpotterLive->db = null; |
907 | 1119 | //SpotterLive->deleteLiveSpotterData(); |
908 | - if ($globalDebug) echo " Done\n"; |
|
1120 | + if ($globalDebug) { |
|
1121 | + echo " Done\n"; |
|
1122 | + } |
|
909 | 1123 | $this->last_delete_hourly = time(); |
910 | 1124 | } else { |
911 | 1125 | $this->del(); |
@@ -917,7 +1131,9 @@ discard block |
||
917 | 1131 | //$ignoreImport = false; |
918 | 1132 | } |
919 | 1133 | //if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN); |
920 | - if ($send) return $this->all_flights[$id]; |
|
1134 | + if ($send) { |
|
1135 | + return $this->all_flights[$id]; |
|
1136 | + } |
|
921 | 1137 | } |
922 | 1138 | } |
923 | 1139 | } |