@@ -5,8 +5,8 @@ |
||
5 | 5 | |
6 | 6 | if (isset($_POST['departure_airport']) && $_POST['departure_airport'] != '') |
7 | 7 | { |
8 | - $departure_airport = filter_input(INPUT_POST,'departure_airport',FILTER_SANITIZE_STRING); |
|
9 | - $arrival_airport = filter_input(INPUT_POST,'arrival_airport',FILTER_SANITIZE_STRING); |
|
8 | + $departure_airport = filter_input(INPUT_POST, 'departure_airport', FILTER_SANITIZE_STRING); |
|
9 | + $arrival_airport = filter_input(INPUT_POST, 'arrival_airport', FILTER_SANITIZE_STRING); |
|
10 | 10 | header('Location: '.$globalURL.'/route/'.$departure_airport.'/'.$arrival_airport); |
11 | 11 | } else { |
12 | 12 | if ($globalURL == '') { |
@@ -3,17 +3,17 @@ discard block |
||
3 | 3 | require_once('require/class.Spotter.php'); |
4 | 4 | require_once('require/class.Language.php'); |
5 | 5 | |
6 | -if (!isset($_GET['country'])){ |
|
6 | +if (!isset($_GET['country'])) { |
|
7 | 7 | header('Location: '.$globalURL.''); |
8 | 8 | } else { |
9 | 9 | $Spotter = new Spotter(); |
10 | 10 | //calculuation for the pagination |
11 | - if(!isset($_GET['limit'])) |
|
11 | + if (!isset($_GET['limit'])) |
|
12 | 12 | { |
13 | 13 | $limit_start = 0; |
14 | 14 | $limit_end = 25; |
15 | 15 | $absolute_difference = 25; |
16 | - } else { |
|
16 | + } else { |
|
17 | 17 | $limit_explode = explode(",", $_GET['limit']); |
18 | 18 | if (isset($limit_explode[1])) { |
19 | 19 | $limit_start = $limit_explode[0]; |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | $limit_previous_1 = $limit_start - $absolute_difference; |
33 | 33 | $limit_previous_2 = $limit_end - $absolute_difference; |
34 | 34 | |
35 | - $country = ucwords(str_replace("-", " ", urldecode(filter_input(INPUT_GET,'country',FILTER_SANITIZE_STRING)))); |
|
35 | + $country = ucwords(str_replace("-", " ", urldecode(filter_input(INPUT_GET, 'country', FILTER_SANITIZE_STRING)))); |
|
36 | 36 | |
37 | 37 | $page_url = $globalURL.'/country/'.$_GET['country']; |
38 | - $sort = filter_input(INPUT_GET,'sort',FILTER_SANITIZE_STRING); |
|
38 | + $sort = filter_input(INPUT_GET, 'sort', FILTER_SANITIZE_STRING); |
|
39 | 39 | if ($country == 'Na') { |
40 | 40 | $spotter_array = array(); |
41 | 41 | } else { |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | |
49 | 49 | if (!empty($spotter_array)) |
50 | 50 | { |
51 | - $title = sprintf(_("Detailed View for Airports & Airlines from %s"),$country); |
|
51 | + $title = sprintf(_("Detailed View for Airports & Airlines from %s"), $country); |
|
52 | 52 | |
53 | 53 | require_once('header.php'); |
54 | 54 | print '<div class="select-item">'; |
@@ -56,9 +56,9 @@ discard block |
||
56 | 56 | print '<select name="country" class="selectpicker" data-live-search="true">'; |
57 | 57 | print '<option></option>'; |
58 | 58 | $all_countries = $Spotter->getAllCountries(); |
59 | - foreach($all_countries as $all_country) |
|
59 | + foreach ($all_countries as $all_country) |
|
60 | 60 | { |
61 | - if($country == $all_country['country']) |
|
61 | + if ($country == $all_country['country']) |
|
62 | 62 | { |
63 | 63 | print '<option value="'.strtolower(str_replace(" ", "-", $all_country['country'])).'" selected="selected">'.$all_country['country'].'</option>'; |
64 | 64 | } else { |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | if ($_GET['country'] != "NA") |
74 | 74 | { |
75 | 75 | print '<div class="info column">'; |
76 | - print '<h1>'.sprintf(_("Airports & Airlines from %s"),$country).'</h1>'; |
|
76 | + print '<h1>'.sprintf(_("Airports & Airlines from %s"), $country).'</h1>'; |
|
77 | 77 | print '</div>'; |
78 | 78 | } else { |
79 | 79 | print '<div class="alert alert-warning">'._("This special country profile shows all flights that do <u>not</u> have a country of a airline or departure/arrival airport associated with them.").'</div>'; |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | |
82 | 82 | include('country-sub-menu.php'); |
83 | 83 | print '<div class="table column">'; |
84 | - print '<p>'.sprintf(_("The table below shows the detailed information of all flights of airports (both departure & arrival) OR airlines from <strong>%s</strong>."),$country).'</p>'; |
|
84 | + print '<p>'.sprintf(_("The table below shows the detailed information of all flights of airports (both departure & arrival) OR airlines from <strong>%s</strong>."), $country).'</p>'; |
|
85 | 85 | |
86 | 86 | include('table-output.php'); |
87 | 87 | print '<div class="pagination">'; |
@@ -13,7 +13,7 @@ |
||
13 | 13 | $limit_start = 0; |
14 | 14 | $limit_end = 25; |
15 | 15 | $absolute_difference = 25; |
16 | - } else { |
|
16 | + } else { |
|
17 | 17 | $limit_explode = explode(",", $_GET['limit']); |
18 | 18 | if (isset($limit_explode[1])) { |
19 | 19 | $limit_start = $limit_explode[0]; |
@@ -43,7 +43,9 @@ discard block |
||
43 | 43 | } |
44 | 44 | $Stats = new Stats($Spotter->db); |
45 | 45 | $airline_names = $Stats->getAllAirlineNames(); |
46 | - if (empty($airline_names)) $airline_names = $Spotter->getAllAirlineNames(); |
|
46 | + if (empty($airline_names)) { |
|
47 | + $airline_names = $Spotter->getAllAirlineNames(); |
|
48 | + } |
|
47 | 49 | foreach($airline_names as $airline_name) |
48 | 50 | { |
49 | 51 | if($airline == $airline_name['airline_icao']) |
@@ -66,8 +68,7 @@ discard block |
||
66 | 68 | if ($globalIVAO && @getimagesize($globalURL.'/images/airlines/'.$spotter_array[0]['airline_icao'].'.gif')) |
67 | 69 | { |
68 | 70 | print '<img src="'.$globalURL.'/images/airlines/'.$spotter_array[0]['airline_icao'].'.gif" alt="'.$spotter_array[0]['airline_name'].' ('.$spotter_array[0]['airline_icao'].')" title="'.$spotter_array[0]['airline_name'].' ('.$spotter_array[0]['airline_icao'].')" class="logo" />'; |
69 | - } |
|
70 | - elseif (@getimagesize($globalURL.'/images/airlines/'.$spotter_array[0]['airline_icao'].'.png')) |
|
71 | + } elseif (@getimagesize($globalURL.'/images/airlines/'.$spotter_array[0]['airline_icao'].'.png')) |
|
71 | 72 | { |
72 | 73 | print '<img src="'.$globalURL.'/images/airlines/'.$spotter_array[0]['airline_icao'].'.png" alt="'.$spotter_array[0]['airline_name'].' ('.$spotter_array[0]['airline_icao'].')" title="'.$spotter_array[0]['airline_name'].' ('.$spotter_array[0]['airline_icao'].')" class="logo" />'; |
73 | 74 | } |
@@ -131,7 +132,9 @@ discard block |
||
131 | 132 | $images = $Image->getSpotterImage($aircraft_item['registration']); |
132 | 133 | if (isset($images['image_thumbnail'])) { |
133 | 134 | $aircraft_item['image_thumbnail'] = $images['image_thumbnail']; |
134 | - } else $aircraft_item['image_thumbnail'] = ''; |
|
135 | + } else { |
|
136 | + $aircraft_item['image_thumbnail'] = ''; |
|
137 | + } |
|
135 | 138 | } |
136 | 139 | if ($aircraft_item['image_thumbnail'] != "") |
137 | 140 | { |
@@ -8,21 +8,21 @@ discard block |
||
8 | 8 | header('Location: '.$globalURL.'/airline'); |
9 | 9 | die(); |
10 | 10 | } |
11 | -$airline = urldecode(filter_input(INPUT_GET,'airline',FILTER_SANITIZE_STRING)); |
|
11 | +$airline = urldecode(filter_input(INPUT_GET, 'airline', FILTER_SANITIZE_STRING)); |
|
12 | 12 | $Spotter = new Spotter(); |
13 | 13 | $alliance = false; |
14 | -if (strpos($airline,'alliance_') !== FALSE) { |
|
14 | +if (strpos($airline, 'alliance_') !== FALSE) { |
|
15 | 15 | $alliance = true; |
16 | 16 | } else { |
17 | - $spotter_array = $Spotter->getSpotterDataByAirline($airline,"0,1",""); |
|
17 | + $spotter_array = $Spotter->getSpotterDataByAirline($airline, "0,1", ""); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | if (!empty($spotter_array) || $alliance === true) |
21 | 21 | { |
22 | 22 | if ($alliance) { |
23 | - $title = sprintf(_("Most Common Aircraft by Registration from %s"),str_replace('_',' ',str_replace('alliance_','',$airline))); |
|
23 | + $title = sprintf(_("Most Common Aircraft by Registration from %s"), str_replace('_', ' ', str_replace('alliance_', '', $airline))); |
|
24 | 24 | } else { |
25 | - $title = sprintf(_("Most Common Aircraft by Registration from %s (%s)"),$spotter_array[0]['airline_name'],$spotter_array[0]['airline_icao']); |
|
25 | + $title = sprintf(_("Most Common Aircraft by Registration from %s (%s)"), $spotter_array[0]['airline_name'], $spotter_array[0]['airline_icao']); |
|
26 | 26 | } |
27 | 27 | require_once('header.php'); |
28 | 28 | |
@@ -33,10 +33,10 @@ discard block |
||
33 | 33 | $alliances = $Spotter->getAllAllianceNames(); |
34 | 34 | if (!empty($alliances)) { |
35 | 35 | foreach ($alliances as $al) { |
36 | - if ($alliance && str_replace('_',' ',str_replace('alliance_','',$airline)) == $al['alliance']) { |
|
37 | - print '<option value="alliance_'.str_replace(' ','_',$al['alliance']).'" selected>'.$al['alliance'].'</option>'; |
|
36 | + if ($alliance && str_replace('_', ' ', str_replace('alliance_', '', $airline)) == $al['alliance']) { |
|
37 | + print '<option value="alliance_'.str_replace(' ', '_', $al['alliance']).'" selected>'.$al['alliance'].'</option>'; |
|
38 | 38 | } else { |
39 | - print '<option value="alliance_'.str_replace(' ','_',$al['alliance']).'">'.$al['alliance'].'</option>'; |
|
39 | + print '<option value="alliance_'.str_replace(' ', '_', $al['alliance']).'">'.$al['alliance'].'</option>'; |
|
40 | 40 | } |
41 | 41 | } |
42 | 42 | print '<option disabled>──────────────────</option>'; |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | $Stats = new Stats($Spotter->db); |
45 | 45 | $airline_names = $Stats->getAllAirlineNames(); |
46 | 46 | if (empty($airline_names)) $airline_names = $Spotter->getAllAirlineNames(); |
47 | - foreach($airline_names as $airline_name) |
|
47 | + foreach ($airline_names as $airline_name) |
|
48 | 48 | { |
49 | - if($airline == $airline_name['airline_icao']) |
|
49 | + if ($airline == $airline_name['airline_icao']) |
|
50 | 50 | { |
51 | 51 | print '<option value="'.$airline_name['airline_icao'].'" selected="selected">'.$airline_name['airline_name'].' ('.$airline_name['airline_icao'].')</option>'; |
52 | 52 | } else { |
@@ -81,12 +81,12 @@ discard block |
||
81 | 81 | print '</div>'; |
82 | 82 | } else { |
83 | 83 | print '<div class="info column">'; |
84 | - print '<h1>'.str_replace('_',' ',str_replace('alliance_','',$airline)).'</h1>'; |
|
85 | - if (@getimagesize($globalURL.'/images/airlines/'.str_replace('alliance_','',$airline).'.png') || @getimagesize('images/airlines/'.str_replace('alliance_','',$airline).'.png')) |
|
84 | + print '<h1>'.str_replace('_', ' ', str_replace('alliance_', '', $airline)).'</h1>'; |
|
85 | + if (@getimagesize($globalURL.'/images/airlines/'.str_replace('alliance_', '', $airline).'.png') || @getimagesize('images/airlines/'.str_replace('alliance_', '', $airline).'.png')) |
|
86 | 86 | { |
87 | - print '<img src="'.$globalURL.'/images/airlines/'.str_replace('alliance_','',$airline).'.png" alt="'.str_replace('_',' ',str_replace('alliance_','',$airline)).'" title="'.str_replace('_',' ',str_replace('alliance_','',$airline)).'" class="logo" />'; |
|
87 | + print '<img src="'.$globalURL.'/images/airlines/'.str_replace('alliance_', '', $airline).'.png" alt="'.str_replace('_', ' ', str_replace('alliance_', '', $airline)).'" title="'.str_replace('_', ' ', str_replace('alliance_', '', $airline)).'" class="logo" />'; |
|
88 | 88 | } |
89 | - print '<div><span class="label">'._("Name").'</span>'.str_replace('_',' ',str_replace('alliance_','',$airline)).'</div>'; |
|
89 | + print '<div><span class="label">'._("Name").'</span>'.str_replace('_', ' ', str_replace('alliance_', '', $airline)).'</div>'; |
|
90 | 90 | print '</div>'; |
91 | 91 | } |
92 | 92 | } else { |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | print '<div class="column">'; |
98 | 98 | print '<h2>'._("Most Common Aircraft by Registration").'</h2>'; |
99 | 99 | if ($alliance) { |
100 | - print '<p>'.sprintf(_("The statistic below shows the most common aircraft by their registration of flights from <strong>%s</strong>."),str_replace('_',' ',str_replace('alliance_','',$airline))).'</p>'; |
|
100 | + print '<p>'.sprintf(_("The statistic below shows the most common aircraft by their registration of flights from <strong>%s</strong>."), str_replace('_', ' ', str_replace('alliance_', '', $airline))).'</p>'; |
|
101 | 101 | } else { |
102 | - print '<p>'.sprintf(_("The statistic below shows the most common aircraft by their registration of flights from <strong>%s</strong>."),$spotter_array[0]['airline_name']).'</p>'; |
|
102 | + print '<p>'.sprintf(_("The statistic below shows the most common aircraft by their registration of flights from <strong>%s</strong>."), $spotter_array[0]['airline_name']).'</p>'; |
|
103 | 103 | } |
104 | 104 | /* |
105 | 105 | if ($alliance) { |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | $aircraft_array = $Spotter->countAllAircraftRegistrationByAirline($airline); |
109 | 109 | } |
110 | 110 | */ |
111 | - $aircraft_array = $Stats->countAllAircraftRegistrations(true,$airline); |
|
111 | + $aircraft_array = $Stats->countAllAircraftRegistrations(true, $airline); |
|
112 | 112 | if (!empty($aircraft_array)) |
113 | 113 | { |
114 | 114 | print '<div class="table-responsive">'; |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | print '</thead>'; |
124 | 124 | print '<tbody>'; |
125 | 125 | $i = 1; |
126 | - foreach($aircraft_array as $aircraft_item) |
|
126 | + foreach ($aircraft_array as $aircraft_item) |
|
127 | 127 | { |
128 | 128 | print '<tr>'; |
129 | 129 | print '<td><strong>'.$i.'</strong></td>'; |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | return ($dec); |
58 | 58 | } |
59 | 59 | |
60 | - /* |
|
60 | + /* |
|
61 | 61 | $ais_map64 = array( |
62 | 62 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', // 48 |
63 | 63 | ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C', |
@@ -97,13 +97,13 @@ discard block |
||
97 | 97 | // ' ' --- '?', // 0x20 - 0x3F |
98 | 98 | // '@' --- '_', // 0x40 - 0x5F |
99 | 99 | $ais_chars = array( |
100 | - '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', |
|
101 | - 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', |
|
102 | - 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', |
|
103 | - '^', '_', ' ', '!', '\"', '#', '$', '%', '&', '\'', |
|
104 | - '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', |
|
105 | - '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', |
|
106 | - '<', '=', '>', '?' |
|
100 | + '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', |
|
101 | + 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', |
|
102 | + 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', |
|
103 | + '^', '_', ' ', '!', '\"', '#', '$', '%', '&', '\'', |
|
104 | + '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', |
|
105 | + '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', |
|
106 | + '<', '=', '>', '?' |
|
107 | 107 | ); |
108 | 108 | // " |
109 | 109 | $rv = ''; |
@@ -421,8 +421,8 @@ discard block |
||
421 | 421 | } |
422 | 422 | if ($num_seq > 1) { // for multipart messages |
423 | 423 | if ($cmsg_sid != $msg_sid // different msg_sid |
424 | - || $msg_sid == -1 // invalid initial msg_sid |
|
425 | - || ($seq - $pseq) != 1 // not insequence |
|
424 | + || $msg_sid == -1 // invalid initial msg_sid |
|
425 | + || ($seq - $pseq) != 1 // not insequence |
|
426 | 426 | ) { // invalid for multipart message |
427 | 427 | $msg_sid = -1; |
428 | 428 | $cmsg_sid = -1; |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | $itu = $itu.$pcs[5]; // get itu message |
436 | 436 | $filler += (int)$pcs[6][0]; // get filler |
437 | 437 | if ($num_seq == 1 // valid single message |
438 | - || $num_seq == $pseq // valid multi-part message |
|
438 | + || $num_seq == $pseq // valid multi-part message |
|
439 | 439 | ) { |
440 | 440 | /* |
441 | 441 | if ($num_seq != 1) { // test |
@@ -520,13 +520,13 @@ discard block |
||
520 | 520 | else $pad = ''; |
521 | 521 | $rv = ''; |
522 | 522 | $ais_chars = array( |
523 | - '@'=>0, 'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 'I'=>9, |
|
524 | - 'J'=>10, 'K'=>11, 'L'=>12, 'M'=>13, 'N'=>14, 'O'=>15, 'P'=>16, 'Q'=>17, 'R'=>18, 'S'=>19, |
|
525 | - 'T'=>20, 'U'=>21, 'V'=>22, 'W'=>23, 'X'=>24, 'Y'=>25, 'Z'=>26, '['=>27, '\\'=>28, ']'=>29, |
|
526 | - '^'=>30, '_'=>31, ' '=>32, '!'=>33, '\"'=>34, '#'=>35, '$'=>36, '%'=>37, '&'=>38, '\''=>39, |
|
527 | - '('=>40, ')'=>41, '*'=>42, '+'=>43, ','=>44, '-'=>45, '.'=>46, '/'=>47, '0'=>48, '1'=>49, |
|
528 | - '2'=>50, '3'=>51, '4'=>52, '5'=>53, '6'=>54, '7'=>55, '8'=>56, '9'=>57, ':'=>58, ';'=>59, |
|
529 | - '<'=>60, '='=>61, '>'=>62, '?'=>63 |
|
523 | + '@'=>0, 'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 'I'=>9, |
|
524 | + 'J'=>10, 'K'=>11, 'L'=>12, 'M'=>13, 'N'=>14, 'O'=>15, 'P'=>16, 'Q'=>17, 'R'=>18, 'S'=>19, |
|
525 | + 'T'=>20, 'U'=>21, 'V'=>22, 'W'=>23, 'X'=>24, 'Y'=>25, 'Z'=>26, '['=>27, '\\'=>28, ']'=>29, |
|
526 | + '^'=>30, '_'=>31, ' '=>32, '!'=>33, '\"'=>34, '#'=>35, '$'=>36, '%'=>37, '&'=>38, '\''=>39, |
|
527 | + '('=>40, ')'=>41, '*'=>42, '+'=>43, ','=>44, '-'=>45, '.'=>46, '/'=>47, '0'=>48, '1'=>49, |
|
528 | + '2'=>50, '3'=>51, '4'=>52, '5'=>53, '6'=>54, '7'=>55, '8'=>56, '9'=>57, ':'=>58, ';'=>59, |
|
529 | + '<'=>60, '='=>61, '>'=>62, '?'=>63 |
|
530 | 530 | ); |
531 | 531 | // " |
532 | 532 | $_a = str_split($name); |
@@ -156,6 +156,10 @@ discard block |
||
156 | 156 | 't', 'u', 'v', 'w' // 119 |
157 | 157 | ); // char 64 |
158 | 158 | */ |
159 | + |
|
160 | + /** |
|
161 | + * @param integer $ascii |
|
162 | + */ |
|
159 | 163 | private function asciidec_2_8bit($ascii) { |
160 | 164 | //only process in the following range: 48-87, 96-119 |
161 | 165 | if ($ascii < 48) { } |
@@ -181,6 +185,10 @@ discard block |
||
181 | 185 | return(substr($bin, -6)); |
182 | 186 | } |
183 | 187 | |
188 | + /** |
|
189 | + * @param integer $_start |
|
190 | + * @param integer $_size |
|
191 | + */ |
|
184 | 192 | private function binchar($_str, $_start, $_size) { |
185 | 193 | // ' ' --- '?', // 0x20 - 0x3F |
186 | 194 | // '@' --- '_', // 0x40 - 0x5F |
@@ -206,6 +214,10 @@ discard block |
||
206 | 214 | } |
207 | 215 | |
208 | 216 | // function for decoding the AIS Message ITU Payload |
217 | + |
|
218 | + /** |
|
219 | + * @param string $_aisdata |
|
220 | + */ |
|
209 | 221 | private function decode_ais($_aisdata) { |
210 | 222 | $ro = new stdClass(); // return object |
211 | 223 | $ro->cls = 0; // AIS class undefined, also indicate unparsed msg |
@@ -378,6 +390,12 @@ discard block |
||
378 | 390 | else return 0; |
379 | 391 | } |
380 | 392 | |
393 | + /** |
|
394 | + * @param string $_itu |
|
395 | + * @param integer $_len |
|
396 | + * @param integer $_filler |
|
397 | + * @param string $aux |
|
398 | + */ |
|
381 | 399 | public function process_ais_itu($_itu, $_len, $_filler, $aux /*, $ais_ch*/) { |
382 | 400 | global $port; // tcpip port... |
383 | 401 | static $debug_counter = 0; |
@@ -397,6 +415,10 @@ discard block |
||
397 | 415 | |
398 | 416 | // char* - AIS \r terminated string |
399 | 417 | // TCP based streams which send messages in full can use this instead of calling process_ais_buf |
418 | + |
|
419 | + /** |
|
420 | + * @param string $rawdata |
|
421 | + */ |
|
400 | 422 | public function process_ais_raw($rawdata, $aux = '') { // return int |
401 | 423 | static $num_seq; // 1 to 9 |
402 | 424 | static $seq; // 1 to 9 |
@@ -622,6 +644,9 @@ discard block |
||
622 | 644 | return $result; |
623 | 645 | } |
624 | 646 | |
647 | + /** |
|
648 | + * @param string $mmsi |
|
649 | + */ |
|
625 | 650 | public function mmsitype($mmsi) { |
626 | 651 | if (strlen($mmsi) == 9) { |
627 | 652 | if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS'; |
@@ -117,31 +117,31 @@ discard block |
||
117 | 117 | |
118 | 118 | private function make_latf($temp) { // unsigned long |
119 | 119 | $flat = 0.0; // float |
120 | - $temp = $temp & 0x07FFFFFF; |
|
121 | - if ($temp & 0x04000000) { |
|
122 | - $temp = $temp ^ 0x07FFFFFF; |
|
120 | + $temp = $temp&0x07FFFFFF; |
|
121 | + if ($temp&0x04000000) { |
|
122 | + $temp = $temp^0x07FFFFFF; |
|
123 | 123 | $temp += 1; |
124 | - $flat = (float)($temp / (60.0 * 10000.0)); |
|
124 | + $flat = (float) ($temp/(60.0*10000.0)); |
|
125 | 125 | $flat *= -1.0; |
126 | - } else $flat = (float)($temp / (60.0 * 10000.0)); |
|
126 | + } else $flat = (float) ($temp/(60.0*10000.0)); |
|
127 | 127 | return $flat; // float |
128 | 128 | } |
129 | 129 | |
130 | 130 | private function make_lonf($temp) { // unsigned long |
131 | 131 | $flon = 0.0; // float |
132 | - $temp = $temp & 0x0FFFFFFF; |
|
133 | - if ($temp & 0x08000000) { |
|
134 | - $temp = $temp ^ 0x0FFFFFFF; |
|
132 | + $temp = $temp&0x0FFFFFFF; |
|
133 | + if ($temp&0x08000000) { |
|
134 | + $temp = $temp^0x0FFFFFFF; |
|
135 | 135 | $temp += 1; |
136 | - $flon = (float)($temp / (60.0 * 10000.0)); |
|
136 | + $flon = (float) ($temp/(60.0*10000.0)); |
|
137 | 137 | $flon *= -1.0; |
138 | - } else $flon = (float)($temp / (60.0 * 10000.0)); |
|
138 | + } else $flon = (float) ($temp/(60.0*10000.0)); |
|
139 | 139 | return $flon; |
140 | 140 | } |
141 | 141 | |
142 | 142 | private function ascii_2_dec($chr) { |
143 | - $dec=ord($chr);//get decimal ascii code |
|
144 | - $hex=dechex($dec);//convert decimal to hex |
|
143 | + $dec = ord($chr); //get decimal ascii code |
|
144 | + $hex = dechex($dec); //convert decimal to hex |
|
145 | 145 | return ($dec); |
146 | 146 | } |
147 | 147 | |
@@ -160,15 +160,15 @@ discard block |
||
160 | 160 | //only process in the following range: 48-87, 96-119 |
161 | 161 | if ($ascii < 48) { } |
162 | 162 | else { |
163 | - if($ascii>119) { } |
|
163 | + if ($ascii > 119) { } |
|
164 | 164 | else { |
165 | - if ($ascii>87 && $ascii<96) ; |
|
165 | + if ($ascii > 87 && $ascii < 96); |
|
166 | 166 | else { |
167 | - $ascii=$ascii+40; |
|
168 | - if ($ascii>128){ |
|
169 | - $ascii=$ascii+32; |
|
167 | + $ascii = $ascii + 40; |
|
168 | + if ($ascii > 128) { |
|
169 | + $ascii = $ascii + 32; |
|
170 | 170 | } else { |
171 | - $ascii=$ascii+40; |
|
171 | + $ascii = $ascii + 40; |
|
172 | 172 | } |
173 | 173 | } |
174 | 174 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | } |
178 | 178 | |
179 | 179 | private function dec_2_6bit($dec) { |
180 | - $bin=decbin($dec); |
|
180 | + $bin = decbin($dec); |
|
181 | 181 | return(substr($bin, -6)); |
182 | 182 | } |
183 | 183 | |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | ); |
196 | 196 | // " |
197 | 197 | $rv = ''; |
198 | - if ($_size % 6 == 0) { |
|
199 | - $len = $_size / 6; |
|
200 | - for ($i=0; $i<$len; $i++) { |
|
201 | - $offset = $i * 6; |
|
202 | - $rv .= $ais_chars[ bindec(substr($_str,$_start + $offset,6)) ]; |
|
198 | + if ($_size%6 == 0) { |
|
199 | + $len = $_size/6; |
|
200 | + for ($i = 0; $i < $len; $i++) { |
|
201 | + $offset = $i*6; |
|
202 | + $rv .= $ais_chars[bindec(substr($_str, $_start + $offset, 6))]; |
|
203 | 203 | } |
204 | 204 | } |
205 | 205 | return $rv; |
@@ -226,93 +226,93 @@ discard block |
||
226 | 226 | $ro->eta_hour = ''; |
227 | 227 | $ro->eta_minute = ''; |
228 | 228 | $ro->ts = time(); |
229 | - $ro->id = bindec(substr($_aisdata,0,6)); |
|
230 | - $ro->mmsi = bindec(substr($_aisdata,8,30)); |
|
229 | + $ro->id = bindec(substr($_aisdata, 0, 6)); |
|
230 | + $ro->mmsi = bindec(substr($_aisdata, 8, 30)); |
|
231 | 231 | if ($ro->id >= 1 && $ro->id <= 3) { |
232 | - $ro->cog = bindec(substr($_aisdata,116,12))/10; |
|
233 | - $ro->sog = bindec(substr($_aisdata,50,10))/10; |
|
234 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,61,28))); |
|
235 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,89,27))); |
|
232 | + $ro->cog = bindec(substr($_aisdata, 116, 12))/10; |
|
233 | + $ro->sog = bindec(substr($_aisdata, 50, 10))/10; |
|
234 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 61, 28))); |
|
235 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 89, 27))); |
|
236 | 236 | $ro->cls = 1; // class A |
237 | 237 | } else if ($ro->id == 4) { |
238 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,79,28))); |
|
239 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,107,27))); |
|
238 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 79, 28))); |
|
239 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 107, 27))); |
|
240 | 240 | $ro->cls = 1; // class A |
241 | 241 | } else if ($ro->id == 5) { |
242 | - $ro->imo = bindec(substr($_aisdata,40,30)); |
|
243 | - $ro->callsign = $this->binchar($_aisdata,70,42); |
|
244 | - $ro->name = $this->binchar($_aisdata,112,120); |
|
245 | - $ro->typeid = bindec(substr($_aisdata,232,8)); |
|
242 | + $ro->imo = bindec(substr($_aisdata, 40, 30)); |
|
243 | + $ro->callsign = $this->binchar($_aisdata, 70, 42); |
|
244 | + $ro->name = $this->binchar($_aisdata, 112, 120); |
|
245 | + $ro->typeid = bindec(substr($_aisdata, 232, 8)); |
|
246 | 246 | $ro->type = $this->getShipType($ro->typeid); |
247 | 247 | //$ro->to_bow = bindec(substr($_aisdata,240,9)); |
248 | 248 | //$ro->to_stern = bindec(substr($_aisdata,249,9)); |
249 | 249 | //$ro->to_port = bindec(substr($_aisdata,258,6)); |
250 | 250 | //$ro->to_starboard = bindec(substr($_aisdata,264,6)); |
251 | - $ro->eta_month = bindec(substr($_aisdata,274,4)); |
|
252 | - $ro->eta_day = bindec(substr($_aisdata,278,5)); |
|
253 | - $ro->eta_hour = bindec(substr($_aisdata,283,5)); |
|
254 | - $ro->eta_minute = bindec(substr($_aisdata,288,6)); |
|
251 | + $ro->eta_month = bindec(substr($_aisdata, 274, 4)); |
|
252 | + $ro->eta_day = bindec(substr($_aisdata, 278, 5)); |
|
253 | + $ro->eta_hour = bindec(substr($_aisdata, 283, 5)); |
|
254 | + $ro->eta_minute = bindec(substr($_aisdata, 288, 6)); |
|
255 | 255 | //$ro->draught = bindec(substr($_aisdata,294,8)); |
256 | - $ro->destination = $this->binchar($_aisdata,302,120); |
|
256 | + $ro->destination = $this->binchar($_aisdata, 302, 120); |
|
257 | 257 | $ro->cls = 1; // class A |
258 | 258 | } else if ($ro->id == 9) { |
259 | 259 | // Search and Rescue aircraft position report |
260 | 260 | } else if ($ro->id == 18) { |
261 | - $ro->cog = bindec(substr($_aisdata,112,12))/10; |
|
262 | - $ro->sog = bindec(substr($_aisdata,46,10))/10; |
|
263 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,57,28))); |
|
264 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,85,27))); |
|
265 | - $ro->heading = bindec(substr($_aisdata,124,9)); |
|
261 | + $ro->cog = bindec(substr($_aisdata, 112, 12))/10; |
|
262 | + $ro->sog = bindec(substr($_aisdata, 46, 10))/10; |
|
263 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 57, 28))); |
|
264 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 85, 27))); |
|
265 | + $ro->heading = bindec(substr($_aisdata, 124, 9)); |
|
266 | 266 | if ($ro->heading == 511) $ro->heading = ''; |
267 | 267 | $ro->cls = 2; // class B |
268 | 268 | } else if ($ro->id == 19) { |
269 | - $ro->cog = bindec(substr($_aisdata,112,12))/10; |
|
270 | - $ro->sog = bindec(substr($_aisdata,46,10))/10; |
|
271 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,61,28))); |
|
272 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,89,27))); |
|
273 | - $ro->name = $this->binchar($_aisdata,143,120); |
|
269 | + $ro->cog = bindec(substr($_aisdata, 112, 12))/10; |
|
270 | + $ro->sog = bindec(substr($_aisdata, 46, 10))/10; |
|
271 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 61, 28))); |
|
272 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 89, 27))); |
|
273 | + $ro->name = $this->binchar($_aisdata, 143, 120); |
|
274 | 274 | $ro->cls = 2; // class B |
275 | - $ro->heading = bindec(substr($_aisdata,124,9)); |
|
275 | + $ro->heading = bindec(substr($_aisdata, 124, 9)); |
|
276 | 276 | if ($ro->heading == 511) $ro->heading = ''; |
277 | - $ro->typeid = bindec(substr($_aisdata,263,8)); |
|
277 | + $ro->typeid = bindec(substr($_aisdata, 263, 8)); |
|
278 | 278 | $ro->type = $this->getShipType($ro->typeid); |
279 | 279 | //$ro->to_bow = bindec(substr($_aisdata,271,9)); |
280 | 280 | //$ro->to_stern = bindec(substr($_aisdata,280,9)); |
281 | 281 | //$ro->to_port = bindec(substr($_aisdata,289,6)); |
282 | 282 | //$ro->to_starboard = bindec(substr($_aisdata,295,6)); |
283 | 283 | } else if ($ro->id == 21) { |
284 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,164,28))); |
|
285 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,192,27))); |
|
286 | - $ro->name = $this->binchar($_aisdata,43,120); |
|
284 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 164, 28))); |
|
285 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 192, 27))); |
|
286 | + $ro->name = $this->binchar($_aisdata, 43, 120); |
|
287 | 287 | //$ro->to_bow = bindec(substr($_aisdata,219,9)); |
288 | 288 | //$ro->to_stern = bindec(substr($_aisdata,228,9)); |
289 | 289 | //$ro->to_port = bindec(substr($_aisdata,237,6)); |
290 | 290 | //$ro->to_starboard = bindec(substr($_aisdata,243,6)); |
291 | 291 | $ro->cls = 2; // class B |
292 | 292 | } else if ($ro->id == 24) { |
293 | - $pn = bindec(substr($_aisdata,38,2)); |
|
293 | + $pn = bindec(substr($_aisdata, 38, 2)); |
|
294 | 294 | if ($pn == 0) { |
295 | - $ro->name = $this->binchar($_aisdata,40,120); |
|
295 | + $ro->name = $this->binchar($_aisdata, 40, 120); |
|
296 | 296 | } |
297 | - $ro->typeid = bindec(substr($_aisdata,40,8)); |
|
297 | + $ro->typeid = bindec(substr($_aisdata, 40, 8)); |
|
298 | 298 | $ro->type = $this->getShipType($ro->typeid); |
299 | - $ro->callsign = $this->binchar($_aisdata,90,42); |
|
299 | + $ro->callsign = $this->binchar($_aisdata, 90, 42); |
|
300 | 300 | //$ro->to_bow = bindec(substr($_aisdata,132,9)); |
301 | 301 | //$ro->to_stern = bindec(substr($_aisdata,141,9)); |
302 | 302 | //$ro->to_port = bindec(substr($_aisdata,150,6)); |
303 | 303 | //$ro->to_starboard = bindec(substr($_aisdata,156,6)); |
304 | 304 | $ro->cls = 2; // class B |
305 | 305 | } else if ($ro->id == 27) { |
306 | - $ro->cog = bindec(substr($_aisdata,85,9)); |
|
306 | + $ro->cog = bindec(substr($_aisdata, 85, 9)); |
|
307 | 307 | if ($ro->cog == 511) $ro->cog = 0.0; |
308 | - $ro->sog = bindec(substr($_aisdata,79,6)); |
|
308 | + $ro->sog = bindec(substr($_aisdata, 79, 6)); |
|
309 | 309 | if ($ro->sog == 63) $ro->sog = 0.0; |
310 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,44,18))*10); |
|
311 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,62,17))*10); |
|
310 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 44, 18))*10); |
|
311 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 62, 17))*10); |
|
312 | 312 | $ro->cls = 1; // class A |
313 | 313 | |
314 | 314 | } |
315 | - $ro->statusid = bindec(substr($_aisdata,38,4)); |
|
315 | + $ro->statusid = bindec(substr($_aisdata, 38, 4)); |
|
316 | 316 | $ro->status = $this->getStatus($ro->statusid); |
317 | 317 | return $ro; |
318 | 318 | } |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | } |
360 | 360 | |
361 | 361 | public function getShipTypeID($type) { |
362 | - $typeid = array_search($type,$this->shiptype); |
|
362 | + $typeid = array_search($type, $this->shiptype); |
|
363 | 363 | if ($typeid !== FALSE) return $typeid; |
364 | 364 | elseif ($type == 'Cargo' || $type == 'General Cargo' || $type == 'Bulk Carrier' || $type == 'Container Ship' || $type == 'Cargo A' || $type == 'Reefer' || $type == 'Vehicles Carrier' || $type == 'Ro-Ro Cargo') return 70; |
365 | 365 | elseif ($type == 'Passengers Ship' || $type == 'Passenger' || $type == 'Ro-Ro/Passenger Ship' || $type == 'Motor Passenger') return 60; |
@@ -381,14 +381,14 @@ discard block |
||
381 | 381 | public function process_ais_itu($_itu, $_len, $_filler, $aux /*, $ais_ch*/) { |
382 | 382 | global $port; // tcpip port... |
383 | 383 | static $debug_counter = 0; |
384 | - $aisdata168='';//six bit array of ascii characters |
|
384 | + $aisdata168 = ''; //six bit array of ascii characters |
|
385 | 385 | $ais_nmea_array = str_split($_itu); // convert to an array |
386 | 386 | foreach ($ais_nmea_array as $value) { |
387 | 387 | $dec = $this->ascii_2_dec($value); |
388 | 388 | $bit8 = $this->asciidec_2_8bit($dec); |
389 | 389 | $bit6 = $this->dec_2_6bit($bit8); |
390 | 390 | //echo $value ."-" .$bit6 .""; |
391 | - $aisdata168 .=$bit6; |
|
391 | + $aisdata168 .= $bit6; |
|
392 | 392 | } |
393 | 393 | //echo $aisdata168 . "<br/>"; |
394 | 394 | //return $this->decode_ais($aisdata168, $aux); |
@@ -411,24 +411,24 @@ discard block |
||
411 | 411 | // calculate checksum after ! till * |
412 | 412 | // assume 1st ! is valid |
413 | 413 | // find * ensure that it is at correct position |
414 | - $end = strrpos ( $rawdata , '*' ); |
|
414 | + $end = strrpos($rawdata, '*'); |
|
415 | 415 | if ($end === FALSE) return -1; // check for NULLS!!! |
416 | - $cs = substr( $rawdata, $end + 1 ); |
|
417 | - if ( strlen($cs) != 2 ) return -1; // correct cs length |
|
418 | - $dcs = (int)hexdec( $cs ); |
|
419 | - for ( $alias=1; $alias<$end; $alias++) $chksum ^= ord( $rawdata[$alias] ); // perform XOR for NMEA checksum |
|
420 | - if ( $chksum == $dcs ) { // NMEA checksum pass |
|
416 | + $cs = substr($rawdata, $end + 1); |
|
417 | + if (strlen($cs) != 2) return -1; // correct cs length |
|
418 | + $dcs = (int) hexdec($cs); |
|
419 | + for ($alias = 1; $alias < $end; $alias++) $chksum ^= ord($rawdata[$alias]); // perform XOR for NMEA checksum |
|
420 | + if ($chksum == $dcs) { // NMEA checksum pass |
|
421 | 421 | $pcs = explode(',', $rawdata); |
422 | 422 | // !AI??? identifier |
423 | 423 | if (!isset($pcs[1])) { |
424 | 424 | echo "ERROR,INVALID_DATA ".time()." $rawdata\n"; |
425 | 425 | return -1; |
426 | 426 | } |
427 | - $num_seq = (int)$pcs[1]; // number of sequences |
|
428 | - $seq = (int)$pcs[2]; // get sequence |
|
427 | + $num_seq = (int) $pcs[1]; // number of sequences |
|
428 | + $seq = (int) $pcs[2]; // get sequence |
|
429 | 429 | // get msg sequence id |
430 | 430 | if ($pcs[3] == '') $msg_sid = -1; // non-multipart message, set to -1 |
431 | - else $msg_sid = (int)$pcs[3]; // multipart message |
|
431 | + else $msg_sid = (int) $pcs[3]; // multipart message |
|
432 | 432 | $ais_ch = $pcs[4]; // get AIS channel |
433 | 433 | // message sequence checking |
434 | 434 | if ($num_seq < 1 || $num_seq > 9) { |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | } |
462 | 462 | } |
463 | 463 | $itu = $itu.$pcs[5]; // get itu message |
464 | - $filler += (int)$pcs[6][0]; // get filler |
|
464 | + $filler += (int) $pcs[6][0]; // get filler |
|
465 | 465 | if ($num_seq == 1 // valid single message |
466 | 466 | || $num_seq == $pseq // valid multi-part message |
467 | 467 | ) { |
@@ -483,13 +483,13 @@ discard block |
||
483 | 483 | $cbuf = $cbuf.$ibuf; |
484 | 484 | $last_pos = 0; |
485 | 485 | $result = new stdClass(); |
486 | - while ( ($start = strpos($cbuf,"VDM",$last_pos)) !== FALSE) { |
|
486 | + while (($start = strpos($cbuf, "VDM", $last_pos)) !== FALSE) { |
|
487 | 487 | //while ( ($start = strpos($cbuf,"!AI",$last_pos)) !== FALSE) { |
488 | 488 | //DEBUG echo $cbuf; |
489 | - if ( ($end = strpos($cbuf,"\r\n", $start)) !== FALSE) { //TBD need to trim? |
|
489 | + if (($end = strpos($cbuf, "\r\n", $start)) !== FALSE) { //TBD need to trim? |
|
490 | 490 | $tst = substr($cbuf, $start - 3, ($end - $start + 3)); |
491 | 491 | //DEBUG echo "[$start $end $tst]\n"; |
492 | - $result = $this->process_ais_raw( $tst, "" ); |
|
492 | + $result = $this->process_ais_raw($tst, ""); |
|
493 | 493 | $last_pos = $end + 1; |
494 | 494 | } else break; |
495 | 495 | } |
@@ -501,41 +501,41 @@ discard block |
||
501 | 501 | // incoming data from serial or IP comms |
502 | 502 | public function process_ais_line($cbuf) { |
503 | 503 | $result = new stdClass(); |
504 | - $start = strpos($cbuf,"VDM"); |
|
504 | + $start = strpos($cbuf, "VDM"); |
|
505 | 505 | $tst = substr($cbuf, $start - 3); |
506 | - $result = $this->process_ais_raw( $tst, "" ); |
|
506 | + $result = $this->process_ais_raw($tst, ""); |
|
507 | 507 | return $result; |
508 | 508 | } |
509 | 509 | |
510 | 510 | /* AIS Encoding |
511 | 511 | */ |
512 | - private function mk_ais_lat( $lat ) { |
|
512 | + private function mk_ais_lat($lat) { |
|
513 | 513 | //$lat = 1.2569; |
514 | - if ($lat<0.0) { |
|
514 | + if ($lat < 0.0) { |
|
515 | 515 | $lat = -$lat; |
516 | - $neg=true; |
|
517 | - } else $neg=false; |
|
516 | + $neg = true; |
|
517 | + } else $neg = false; |
|
518 | 518 | $latd = 0x00000000; |
519 | - $latd = intval ($lat * 600000.0); |
|
520 | - if ($neg==true) { |
|
519 | + $latd = intval($lat*600000.0); |
|
520 | + if ($neg == true) { |
|
521 | 521 | $latd = ~$latd; |
522 | - $latd+=1; |
|
522 | + $latd += 1; |
|
523 | 523 | $latd &= 0x07FFFFFF; |
524 | 524 | } |
525 | 525 | return $latd; |
526 | 526 | } |
527 | 527 | |
528 | - private function mk_ais_lon( $lon ) { |
|
528 | + private function mk_ais_lon($lon) { |
|
529 | 529 | //$lon = 103.851; |
530 | - if ($lon<0.0) { |
|
530 | + if ($lon < 0.0) { |
|
531 | 531 | $lon = -$lon; |
532 | - $neg=true; |
|
533 | - } else $neg=false; |
|
532 | + $neg = true; |
|
533 | + } else $neg = false; |
|
534 | 534 | $lond = 0x00000000; |
535 | - $lond = intval ($lon * 600000.0); |
|
536 | - if ($neg==true) { |
|
535 | + $lond = intval($lon*600000.0); |
|
536 | + if ($neg == true) { |
|
537 | 537 | $lond = ~$lond; |
538 | - $lond+=1; |
|
538 | + $lond += 1; |
|
539 | 539 | $lond &= 0x0FFFFFFF; |
540 | 540 | } |
541 | 541 | return $lond; |
@@ -543,8 +543,8 @@ discard block |
||
543 | 543 | |
544 | 544 | private function char2bin($name, $max_len) { |
545 | 545 | $len = strlen($name); |
546 | - if ($len > $max_len) $name = substr($name,0,$max_len); |
|
547 | - if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len) * 6); |
|
546 | + if ($len > $max_len) $name = substr($name, 0, $max_len); |
|
547 | + if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len)*6); |
|
548 | 548 | else $pad = ''; |
549 | 549 | $rv = ''; |
550 | 550 | $ais_chars = array( |
@@ -562,7 +562,7 @@ discard block |
||
562 | 562 | foreach ($_a as $_1) { |
563 | 563 | if (isset($ais_chars[$_1])) $dec = $ais_chars[$_1]; |
564 | 564 | else $dec = 0; |
565 | - $bin = str_pad(decbin( $dec ), 6, '0', STR_PAD_LEFT); |
|
565 | + $bin = str_pad(decbin($dec), 6, '0', STR_PAD_LEFT); |
|
566 | 566 | $rv .= $bin; |
567 | 567 | //echo "$_1 $dec ($bin)<br/>"; |
568 | 568 | } |
@@ -570,19 +570,19 @@ discard block |
||
570 | 570 | return $rv.$pad; |
571 | 571 | } |
572 | 572 | |
573 | - private function mk_ais($_enc, $_part=1,$_total=1,$_seq='',$_ch='A') { |
|
573 | + private function mk_ais($_enc, $_part = 1, $_total = 1, $_seq = '', $_ch = 'A') { |
|
574 | 574 | $len_bit = strlen($_enc); |
575 | - $rem6 = $len_bit % 6; |
|
575 | + $rem6 = $len_bit%6; |
|
576 | 576 | $pad6_len = 0; |
577 | 577 | if ($rem6) $pad6_len = 6 - $rem6; |
578 | 578 | //echo $pad6_len.'<br>'; |
579 | 579 | $_enc .= str_repeat("0", $pad6_len); // pad the text... |
580 | - $len_enc = strlen($_enc) / 6; |
|
580 | + $len_enc = strlen($_enc)/6; |
|
581 | 581 | //echo $_enc.' '.$len_enc.'<br/>'; |
582 | 582 | $itu = ''; |
583 | - for ($i=0; $i<$len_enc; $i++) { |
|
584 | - $offset = $i * 6; |
|
585 | - $dec = bindec(substr($_enc,$offset,6)); |
|
583 | + for ($i = 0; $i < $len_enc; $i++) { |
|
584 | + $offset = $i*6; |
|
585 | + $dec = bindec(substr($_enc, $offset, 6)); |
|
586 | 586 | if ($dec < 40) $dec += 48; |
587 | 587 | else $dec += 56; |
588 | 588 | //echo chr($dec)." $dec<br/>"; |
@@ -592,15 +592,15 @@ discard block |
||
592 | 592 | $chksum = 0; |
593 | 593 | $itu = "AIVDM,$_part,$_total,$_seq,$_ch,".$itu.",0"; |
594 | 594 | $len_itu = strlen($itu); |
595 | - for ($i=0; $i<$len_itu; $i++) { |
|
596 | - $chksum ^= ord( $itu[$i] ); |
|
595 | + for ($i = 0; $i < $len_itu; $i++) { |
|
596 | + $chksum ^= ord($itu[$i]); |
|
597 | 597 | } |
598 | - $hex_arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); |
|
599 | - $lsb = $chksum & 0x0F; |
|
600 | - if ($lsb >=0 && $lsb <= 15 ) $lsbc = $hex_arr[$lsb]; |
|
598 | + $hex_arr = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); |
|
599 | + $lsb = $chksum&0x0F; |
|
600 | + if ($lsb >= 0 && $lsb <= 15) $lsbc = $hex_arr[$lsb]; |
|
601 | 601 | else $lsbc = '0'; |
602 | - $msb = (($chksum & 0xF0) >> 4) & 0x0F; |
|
603 | - if ($msb >=0 && $msb <= 15 ) $msbc = $hex_arr[$msb]; |
|
602 | + $msb = (($chksum&0xF0) >> 4)&0x0F; |
|
603 | + if ($msb >= 0 && $msb <= 15) $msbc = $hex_arr[$msb]; |
|
604 | 604 | else $msbc = '0'; |
605 | 605 | $itu = '!'.$itu."*{$msbc}{$lsbc}\r\n"; |
606 | 606 | return $itu; |
@@ -626,14 +626,14 @@ discard block |
||
626 | 626 | |
627 | 627 | public function mmsitype($mmsi) { |
628 | 628 | if (strlen($mmsi) == 9) { |
629 | - if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS'; |
|
630 | - elseif (substr($mmsi,0,3) == '972') return 'MOB (Man Overboard) device'; |
|
631 | - elseif (substr($mmsi,0,3) == '970') return 'AIS SART (Search and Rescue Transmitter)'; |
|
632 | - elseif (substr($mmsi,0,3) == '111') return 'SAR (Search and Rescue) aircraft'; |
|
633 | - elseif (substr($mmsi,0,2) == '98') return 'Auxiliary craft associated with a parent ship'; |
|
634 | - elseif (substr($mmsi,0,2) == '99') return 'Aids to Navigation'; |
|
635 | - elseif (substr($mmsi,0,2) == '00') return 'Coastal stations'; |
|
636 | - elseif (substr($mmsi,0,1) == '0') return 'Group of ships'; |
|
629 | + if (substr($mmsi, 0, 3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS'; |
|
630 | + elseif (substr($mmsi, 0, 3) == '972') return 'MOB (Man Overboard) device'; |
|
631 | + elseif (substr($mmsi, 0, 3) == '970') return 'AIS SART (Search and Rescue Transmitter)'; |
|
632 | + elseif (substr($mmsi, 0, 3) == '111') return 'SAR (Search and Rescue) aircraft'; |
|
633 | + elseif (substr($mmsi, 0, 2) == '98') return 'Auxiliary craft associated with a parent ship'; |
|
634 | + elseif (substr($mmsi, 0, 2) == '99') return 'Aids to Navigation'; |
|
635 | + elseif (substr($mmsi, 0, 2) == '00') return 'Coastal stations'; |
|
636 | + elseif (substr($mmsi, 0, 1) == '0') return 'Group of ships'; |
|
637 | 637 | else return 'Ship'; |
638 | 638 | } |
639 | 639 | |
@@ -643,19 +643,19 @@ discard block |
||
643 | 643 | public function parse_line($buffer) { |
644 | 644 | global $globalDebug; |
645 | 645 | $result = array(); |
646 | - $start = strpos($buffer,"VDM"); |
|
646 | + $start = strpos($buffer, "VDM"); |
|
647 | 647 | $tst = substr($buffer, $start - 3); |
648 | - $data = $this->process_ais_raw( $tst, "" ); |
|
648 | + $data = $this->process_ais_raw($tst, ""); |
|
649 | 649 | if (!is_object($data)) { |
650 | 650 | //if ($globalDebug) echo '==== Line format not supported : '.$buffer."\n"; |
651 | 651 | return array(); |
652 | 652 | } |
653 | 653 | if ($data->lon != 0) $result['longitude'] = $data->lon; |
654 | 654 | if ($data->lat != 0) $result['latitude'] = $data->lat; |
655 | - $result['ident'] = trim(str_replace('@','',$data->name)); |
|
655 | + $result['ident'] = trim(str_replace('@', '', $data->name)); |
|
656 | 656 | $result['timestamp'] = $data->ts; |
657 | 657 | $result['mmsi'] = $data->mmsi; |
658 | - if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') $result['mmsi'] = '3'.$result['mmsi']; |
|
658 | + if (strlen($result['mmsi']) == 8 && substr($result['mmsi'], 0, 3) == '669') $result['mmsi'] = '3'.$result['mmsi']; |
|
659 | 659 | $result['mmsi_type'] = $this->mmsitype($result['mmsi']); |
660 | 660 | if ($data->sog != -1.0) $result['speed'] = $data->sog; |
661 | 661 | if ($data->heading !== '') $result['heading'] = $data->heading; |
@@ -665,16 +665,16 @@ discard block |
||
665 | 665 | if ($data->type !== '') $result['type'] = $data->type; |
666 | 666 | if ($data->typeid !== '') $result['typeid'] = $data->typeid; |
667 | 667 | if ($data->imo !== '') $result['imo'] = $data->imo; |
668 | - if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@','',$data->callsign)); |
|
668 | + if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@', '', $data->callsign)); |
|
669 | 669 | if (is_numeric($data->eta_month) && $data->eta_month != 0 && is_numeric($data->eta_day) && $data->eta_day != 0 && $data->eta_hour !== '' && $data->eta_minute !== '') { |
670 | - $eta_ts = strtotime(date('Y').'-'.sprintf("%02d",$data->eta_month).'-'.sprintf("%02d",$data->eta_day).' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00'); |
|
670 | + $eta_ts = strtotime(date('Y').'-'.sprintf("%02d", $data->eta_month).'-'.sprintf("%02d", $data->eta_day).' '.sprintf("%02d", $data->eta_hour).':'.sprintf("%02d", $data->eta_minute).':00'); |
|
671 | 671 | if ($eta_ts != '') $result['eta_ts'] = $eta_ts; |
672 | 672 | } elseif (is_numeric($data->eta_hour) && is_numeric($data->eta_minute)) { |
673 | - $eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00'); |
|
673 | + $eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d", $data->eta_hour).':'.sprintf("%02d", $data->eta_minute).':00'); |
|
674 | 674 | if ($eta_ts != '') $result['eta_ts'] = $eta_ts; |
675 | 675 | } |
676 | 676 | if ($data->destination != '') { |
677 | - $dest = trim(str_replace('@','',$data->destination)); |
|
677 | + $dest = trim(str_replace('@', '', $data->destination)); |
|
678 | 678 | if ($dest != '') $result['destination'] = $dest; |
679 | 679 | } |
680 | 680 | $result['all'] = (array) $data; |
@@ -123,7 +123,9 @@ discard block |
||
123 | 123 | $temp += 1; |
124 | 124 | $flat = (float)($temp / (60.0 * 10000.0)); |
125 | 125 | $flat *= -1.0; |
126 | - } else $flat = (float)($temp / (60.0 * 10000.0)); |
|
126 | + } else { |
|
127 | + $flat = (float)($temp / (60.0 * 10000.0)); |
|
128 | + } |
|
127 | 129 | return $flat; // float |
128 | 130 | } |
129 | 131 | |
@@ -135,7 +137,9 @@ discard block |
||
135 | 137 | $temp += 1; |
136 | 138 | $flon = (float)($temp / (60.0 * 10000.0)); |
137 | 139 | $flon *= -1.0; |
138 | - } else $flon = (float)($temp / (60.0 * 10000.0)); |
|
140 | + } else { |
|
141 | + $flon = (float)($temp / (60.0 * 10000.0)); |
|
142 | + } |
|
139 | 143 | return $flon; |
140 | 144 | } |
141 | 145 | |
@@ -158,10 +162,8 @@ discard block |
||
158 | 162 | */ |
159 | 163 | private function asciidec_2_8bit($ascii) { |
160 | 164 | //only process in the following range: 48-87, 96-119 |
161 | - if ($ascii < 48) { } |
|
162 | - else { |
|
163 | - if($ascii>119) { } |
|
164 | - else { |
|
165 | + if ($ascii < 48) { } else { |
|
166 | + if($ascii>119) { } else { |
|
165 | 167 | if ($ascii>87 && $ascii<96) ; |
166 | 168 | else { |
167 | 169 | $ascii=$ascii+40; |
@@ -263,7 +265,9 @@ discard block |
||
263 | 265 | $ro->lon = $this->make_lonf(bindec(substr($_aisdata,57,28))); |
264 | 266 | $ro->lat = $this->make_latf(bindec(substr($_aisdata,85,27))); |
265 | 267 | $ro->heading = bindec(substr($_aisdata,124,9)); |
266 | - if ($ro->heading == 511) $ro->heading = ''; |
|
268 | + if ($ro->heading == 511) { |
|
269 | + $ro->heading = ''; |
|
270 | + } |
|
267 | 271 | $ro->cls = 2; // class B |
268 | 272 | } else if ($ro->id == 19) { |
269 | 273 | $ro->cog = bindec(substr($_aisdata,112,12))/10; |
@@ -273,7 +277,9 @@ discard block |
||
273 | 277 | $ro->name = $this->binchar($_aisdata,143,120); |
274 | 278 | $ro->cls = 2; // class B |
275 | 279 | $ro->heading = bindec(substr($_aisdata,124,9)); |
276 | - if ($ro->heading == 511) $ro->heading = ''; |
|
280 | + if ($ro->heading == 511) { |
|
281 | + $ro->heading = ''; |
|
282 | + } |
|
277 | 283 | $ro->typeid = bindec(substr($_aisdata,263,8)); |
278 | 284 | $ro->type = $this->getShipType($ro->typeid); |
279 | 285 | //$ro->to_bow = bindec(substr($_aisdata,271,9)); |
@@ -304,9 +310,13 @@ discard block |
||
304 | 310 | $ro->cls = 2; // class B |
305 | 311 | } else if ($ro->id == 27) { |
306 | 312 | $ro->cog = bindec(substr($_aisdata,85,9)); |
307 | - if ($ro->cog == 511) $ro->cog = 0.0; |
|
313 | + if ($ro->cog == 511) { |
|
314 | + $ro->cog = 0.0; |
|
315 | + } |
|
308 | 316 | $ro->sog = bindec(substr($_aisdata,79,6)); |
309 | - if ($ro->sog == 63) $ro->sog = 0.0; |
|
317 | + if ($ro->sog == 63) { |
|
318 | + $ro->sog = 0.0; |
|
319 | + } |
|
310 | 320 | $ro->lon = $this->make_lonf(bindec(substr($_aisdata,44,18))*10); |
311 | 321 | $ro->lat = $this->make_latf(bindec(substr($_aisdata,62,17))*10); |
312 | 322 | $ro->cls = 1; // class A |
@@ -354,28 +364,48 @@ discard block |
||
354 | 364 | } |
355 | 365 | |
356 | 366 | public function getShipType($code) { |
357 | - if (isset($this->shiptype[$code])) return $this->shiptype[$code]; |
|
358 | - else return ''; |
|
367 | + if (isset($this->shiptype[$code])) { |
|
368 | + return $this->shiptype[$code]; |
|
369 | + } else { |
|
370 | + return ''; |
|
371 | + } |
|
359 | 372 | } |
360 | 373 | |
361 | 374 | public function getShipTypeID($type) { |
362 | 375 | $typeid = array_search($type,$this->shiptype); |
363 | - if ($typeid !== FALSE) return $typeid; |
|
364 | - elseif ($type == 'Cargo' || $type == 'General Cargo' || $type == 'Bulk Carrier' || $type == 'Container Ship' || $type == 'Cargo A' || $type == 'Reefer' || $type == 'Vehicles Carrier' || $type == 'Ro-Ro Cargo') return 70; |
|
365 | - elseif ($type == 'Passengers Ship' || $type == 'Passenger' || $type == 'Ro-Ro/Passenger Ship' || $type == 'Motor Passenger') return 60; |
|
366 | - elseif ($type == 'Tanker' || $type == 'Crude Oil Tanker' || $type == 'Oil Products Tanker' || $type == 'Oil/Chemical Tanker' || $type == 'Bunkering Tanker') return 80; |
|
367 | - elseif ($type == 'Lpg Tanker' || $type == 'Lng Tanker') return 84; |
|
368 | - elseif ($type == 'Sailing Vessel') return 36; |
|
369 | - elseif ($type == 'Yacht') return 37; |
|
370 | - elseif ($type == 'Trailing Suction Hopper Dredger' || $type == 'Drilling Jack Up' || $type == 'Suction Dredger' || $type == 'Hopper Dredger') return 33; |
|
371 | - elseif ($type == 'High speed craft') return 40; |
|
372 | - elseif ($type == 'Crew Boat') return 53; |
|
373 | - elseif ($type == 'Icebreaker') return 52; |
|
374 | - elseif ($type == 'Pollution Control Vessel') return 54; |
|
375 | - elseif ($type == 'Other Type') return 90; |
|
376 | - elseif ($type == 'Anchor Handling Vessel' || $type == 'Offshore Supply Ship' || $type == 'Research/Survey Vessel' || $type == 'Utility Vessel' || $type == 'Pipe Burying Vessel' || $type == 'Heavy Lift Vessel' || $type == 'Crane Ship' || $type == 'Buoy-laying Vessel') return 59; |
|
377 | - elseif ($type == 'Fish Carrier' || $type == 'Trawler' || $type == 'Trawlers' || $type == 'Fishing Vessel' || $type == 'Trawlers|unknown Not Fishing' || $type == 'Purse Seines|trawlers' || $type == 'Purse Seines' || $type == 'Trollers' || $type == 'Set Longlines' || $type == 'Set Gillnets|trawlers') return 30; |
|
378 | - else return 0; |
|
376 | + if ($typeid !== FALSE) { |
|
377 | + return $typeid; |
|
378 | + } elseif ($type == 'Cargo' || $type == 'General Cargo' || $type == 'Bulk Carrier' || $type == 'Container Ship' || $type == 'Cargo A' || $type == 'Reefer' || $type == 'Vehicles Carrier' || $type == 'Ro-Ro Cargo') { |
|
379 | + return 70; |
|
380 | + } elseif ($type == 'Passengers Ship' || $type == 'Passenger' || $type == 'Ro-Ro/Passenger Ship' || $type == 'Motor Passenger') { |
|
381 | + return 60; |
|
382 | + } elseif ($type == 'Tanker' || $type == 'Crude Oil Tanker' || $type == 'Oil Products Tanker' || $type == 'Oil/Chemical Tanker' || $type == 'Bunkering Tanker') { |
|
383 | + return 80; |
|
384 | + } elseif ($type == 'Lpg Tanker' || $type == 'Lng Tanker') { |
|
385 | + return 84; |
|
386 | + } elseif ($type == 'Sailing Vessel') { |
|
387 | + return 36; |
|
388 | + } elseif ($type == 'Yacht') { |
|
389 | + return 37; |
|
390 | + } elseif ($type == 'Trailing Suction Hopper Dredger' || $type == 'Drilling Jack Up' || $type == 'Suction Dredger' || $type == 'Hopper Dredger') { |
|
391 | + return 33; |
|
392 | + } elseif ($type == 'High speed craft') { |
|
393 | + return 40; |
|
394 | + } elseif ($type == 'Crew Boat') { |
|
395 | + return 53; |
|
396 | + } elseif ($type == 'Icebreaker') { |
|
397 | + return 52; |
|
398 | + } elseif ($type == 'Pollution Control Vessel') { |
|
399 | + return 54; |
|
400 | + } elseif ($type == 'Other Type') { |
|
401 | + return 90; |
|
402 | + } elseif ($type == 'Anchor Handling Vessel' || $type == 'Offshore Supply Ship' || $type == 'Research/Survey Vessel' || $type == 'Utility Vessel' || $type == 'Pipe Burying Vessel' || $type == 'Heavy Lift Vessel' || $type == 'Crane Ship' || $type == 'Buoy-laying Vessel') { |
|
403 | + return 59; |
|
404 | + } elseif ($type == 'Fish Carrier' || $type == 'Trawler' || $type == 'Trawlers' || $type == 'Fishing Vessel' || $type == 'Trawlers|unknown Not Fishing' || $type == 'Purse Seines|trawlers' || $type == 'Purse Seines' || $type == 'Trollers' || $type == 'Set Longlines' || $type == 'Set Gillnets|trawlers') { |
|
405 | + return 30; |
|
406 | + } else { |
|
407 | + return 0; |
|
408 | + } |
|
379 | 409 | } |
380 | 410 | |
381 | 411 | public function process_ais_itu($_itu, $_len, $_filler, $aux /*, $ais_ch*/) { |
@@ -412,11 +442,20 @@ discard block |
||
412 | 442 | // assume 1st ! is valid |
413 | 443 | // find * ensure that it is at correct position |
414 | 444 | $end = strrpos ( $rawdata , '*' ); |
415 | - if ($end === FALSE) return -1; // check for NULLS!!! |
|
445 | + if ($end === FALSE) { |
|
446 | + return -1; |
|
447 | + } |
|
448 | + // check for NULLS!!! |
|
416 | 449 | $cs = substr( $rawdata, $end + 1 ); |
417 | - if ( strlen($cs) != 2 ) return -1; // correct cs length |
|
450 | + if ( strlen($cs) != 2 ) { |
|
451 | + return -1; |
|
452 | + } |
|
453 | + // correct cs length |
|
418 | 454 | $dcs = (int)hexdec( $cs ); |
419 | - for ( $alias=1; $alias<$end; $alias++) $chksum ^= ord( $rawdata[$alias] ); // perform XOR for NMEA checksum |
|
455 | + for ( $alias=1; $alias<$end; $alias++) { |
|
456 | + $chksum ^= ord( $rawdata[$alias] ); |
|
457 | + } |
|
458 | + // perform XOR for NMEA checksum |
|
420 | 459 | if ( $chksum == $dcs ) { // NMEA checksum pass |
421 | 460 | $pcs = explode(',', $rawdata); |
422 | 461 | // !AI??? identifier |
@@ -427,8 +466,14 @@ discard block |
||
427 | 466 | $num_seq = (int)$pcs[1]; // number of sequences |
428 | 467 | $seq = (int)$pcs[2]; // get sequence |
429 | 468 | // get msg sequence id |
430 | - if ($pcs[3] == '') $msg_sid = -1; // non-multipart message, set to -1 |
|
431 | - else $msg_sid = (int)$pcs[3]; // multipart message |
|
469 | + if ($pcs[3] == '') { |
|
470 | + $msg_sid = -1; |
|
471 | + } |
|
472 | + // non-multipart message, set to -1 |
|
473 | + else { |
|
474 | + $msg_sid = (int)$pcs[3]; |
|
475 | + } |
|
476 | + // multipart message |
|
432 | 477 | $ais_ch = $pcs[4]; // get AIS channel |
433 | 478 | // message sequence checking |
434 | 479 | if ($num_seq < 1 || $num_seq > 9) { |
@@ -491,10 +536,18 @@ discard block |
||
491 | 536 | //DEBUG echo "[$start $end $tst]\n"; |
492 | 537 | $result = $this->process_ais_raw( $tst, "" ); |
493 | 538 | $last_pos = $end + 1; |
494 | - } else break; |
|
539 | + } else { |
|
540 | + break; |
|
541 | + } |
|
542 | + } |
|
543 | + if ($last_pos > 0) { |
|
544 | + $cbuf = substr($cbuf, $last_pos); |
|
495 | 545 | } |
496 | - if ($last_pos > 0) $cbuf = substr($cbuf, $last_pos); // move... |
|
497 | - if (strlen($cbuf) > 1024) $cbuf = ""; // prevent overflow simple mode... |
|
546 | + // move... |
|
547 | + if (strlen($cbuf) > 1024) { |
|
548 | + $cbuf = ""; |
|
549 | + } |
|
550 | + // prevent overflow simple mode... |
|
498 | 551 | return $result; |
499 | 552 | } |
500 | 553 | |
@@ -514,7 +567,9 @@ discard block |
||
514 | 567 | if ($lat<0.0) { |
515 | 568 | $lat = -$lat; |
516 | 569 | $neg=true; |
517 | - } else $neg=false; |
|
570 | + } else { |
|
571 | + $neg=false; |
|
572 | + } |
|
518 | 573 | $latd = 0x00000000; |
519 | 574 | $latd = intval ($lat * 600000.0); |
520 | 575 | if ($neg==true) { |
@@ -530,7 +585,9 @@ discard block |
||
530 | 585 | if ($lon<0.0) { |
531 | 586 | $lon = -$lon; |
532 | 587 | $neg=true; |
533 | - } else $neg=false; |
|
588 | + } else { |
|
589 | + $neg=false; |
|
590 | + } |
|
534 | 591 | $lond = 0x00000000; |
535 | 592 | $lond = intval ($lon * 600000.0); |
536 | 593 | if ($neg==true) { |
@@ -543,9 +600,14 @@ discard block |
||
543 | 600 | |
544 | 601 | private function char2bin($name, $max_len) { |
545 | 602 | $len = strlen($name); |
546 | - if ($len > $max_len) $name = substr($name,0,$max_len); |
|
547 | - if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len) * 6); |
|
548 | - else $pad = ''; |
|
603 | + if ($len > $max_len) { |
|
604 | + $name = substr($name,0,$max_len); |
|
605 | + } |
|
606 | + if ($len < $max_len) { |
|
607 | + $pad = str_repeat('0', ($max_len - $len) * 6); |
|
608 | + } else { |
|
609 | + $pad = ''; |
|
610 | + } |
|
549 | 611 | $rv = ''; |
550 | 612 | $ais_chars = array( |
551 | 613 | '@'=>0, 'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 'I'=>9, |
@@ -560,8 +622,11 @@ discard block |
||
560 | 622 | $_a = str_split($name); |
561 | 623 | if (!empty($_a)) { |
562 | 624 | foreach ($_a as $_1) { |
563 | - if (isset($ais_chars[$_1])) $dec = $ais_chars[$_1]; |
|
564 | - else $dec = 0; |
|
625 | + if (isset($ais_chars[$_1])) { |
|
626 | + $dec = $ais_chars[$_1]; |
|
627 | + } else { |
|
628 | + $dec = 0; |
|
629 | + } |
|
565 | 630 | $bin = str_pad(decbin( $dec ), 6, '0', STR_PAD_LEFT); |
566 | 631 | $rv .= $bin; |
567 | 632 | //echo "$_1 $dec ($bin)<br/>"; |
@@ -574,7 +639,9 @@ discard block |
||
574 | 639 | $len_bit = strlen($_enc); |
575 | 640 | $rem6 = $len_bit % 6; |
576 | 641 | $pad6_len = 0; |
577 | - if ($rem6) $pad6_len = 6 - $rem6; |
|
642 | + if ($rem6) { |
|
643 | + $pad6_len = 6 - $rem6; |
|
644 | + } |
|
578 | 645 | //echo $pad6_len.'<br>'; |
579 | 646 | $_enc .= str_repeat("0", $pad6_len); // pad the text... |
580 | 647 | $len_enc = strlen($_enc) / 6; |
@@ -583,8 +650,11 @@ discard block |
||
583 | 650 | for ($i=0; $i<$len_enc; $i++) { |
584 | 651 | $offset = $i * 6; |
585 | 652 | $dec = bindec(substr($_enc,$offset,6)); |
586 | - if ($dec < 40) $dec += 48; |
|
587 | - else $dec += 56; |
|
653 | + if ($dec < 40) { |
|
654 | + $dec += 48; |
|
655 | + } else { |
|
656 | + $dec += 56; |
|
657 | + } |
|
588 | 658 | //echo chr($dec)." $dec<br/>"; |
589 | 659 | $itu .= chr($dec); |
590 | 660 | } |
@@ -597,26 +667,42 @@ discard block |
||
597 | 667 | } |
598 | 668 | $hex_arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); |
599 | 669 | $lsb = $chksum & 0x0F; |
600 | - if ($lsb >=0 && $lsb <= 15 ) $lsbc = $hex_arr[$lsb]; |
|
601 | - else $lsbc = '0'; |
|
670 | + if ($lsb >=0 && $lsb <= 15 ) { |
|
671 | + $lsbc = $hex_arr[$lsb]; |
|
672 | + } else { |
|
673 | + $lsbc = '0'; |
|
674 | + } |
|
602 | 675 | $msb = (($chksum & 0xF0) >> 4) & 0x0F; |
603 | - if ($msb >=0 && $msb <= 15 ) $msbc = $hex_arr[$msb]; |
|
604 | - else $msbc = '0'; |
|
676 | + if ($msb >=0 && $msb <= 15 ) { |
|
677 | + $msbc = $hex_arr[$msb]; |
|
678 | + } else { |
|
679 | + $msbc = '0'; |
|
680 | + } |
|
605 | 681 | $itu = '!'.$itu."*{$msbc}{$lsbc}\r\n"; |
606 | 682 | return $itu; |
607 | 683 | } |
608 | 684 | |
609 | 685 | public function parse($buffer) { |
610 | 686 | $data = $this->process_ais_buf($buffer); |
611 | - if (!is_object($data)) return array(); |
|
687 | + if (!is_object($data)) { |
|
688 | + return array(); |
|
689 | + } |
|
612 | 690 | $result = array(); |
613 | - if ($data->lon != 0) $result['longitude'] = $data->lon; |
|
614 | - if ($data->lat != 0) $result['latitude'] = $data->lat; |
|
691 | + if ($data->lon != 0) { |
|
692 | + $result['longitude'] = $data->lon; |
|
693 | + } |
|
694 | + if ($data->lat != 0) { |
|
695 | + $result['latitude'] = $data->lat; |
|
696 | + } |
|
615 | 697 | $result['ident'] = trim($data->name); |
616 | 698 | $result['timestamp'] = $data->ts; |
617 | 699 | $result['mmsi'] = $data->mmsi; |
618 | - if ($data->sog != -1.0) $result['speed'] = $data->sog; |
|
619 | - if ($data->cog != 0) $result['heading'] = $data->cog; |
|
700 | + if ($data->sog != -1.0) { |
|
701 | + $result['speed'] = $data->sog; |
|
702 | + } |
|
703 | + if ($data->cog != 0) { |
|
704 | + $result['heading'] = $data->cog; |
|
705 | + } |
|
620 | 706 | /* |
621 | 707 | $ro->cls = 0; // AIS class undefined, also indicate unparsed msg |
622 | 708 | $ro->id = bindec(substr($_aisdata,0,6)); |
@@ -626,15 +712,25 @@ discard block |
||
626 | 712 | |
627 | 713 | public function mmsitype($mmsi) { |
628 | 714 | if (strlen($mmsi) == 9) { |
629 | - if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS'; |
|
630 | - elseif (substr($mmsi,0,3) == '972') return 'MOB (Man Overboard) device'; |
|
631 | - elseif (substr($mmsi,0,3) == '970') return 'AIS SART (Search and Rescue Transmitter)'; |
|
632 | - elseif (substr($mmsi,0,3) == '111') return 'SAR (Search and Rescue) aircraft'; |
|
633 | - elseif (substr($mmsi,0,2) == '98') return 'Auxiliary craft associated with a parent ship'; |
|
634 | - elseif (substr($mmsi,0,2) == '99') return 'Aids to Navigation'; |
|
635 | - elseif (substr($mmsi,0,2) == '00') return 'Coastal stations'; |
|
636 | - elseif (substr($mmsi,0,1) == '0') return 'Group of ships'; |
|
637 | - else return 'Ship'; |
|
715 | + if (substr($mmsi,0,3) == '974') { |
|
716 | + return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS'; |
|
717 | + } elseif (substr($mmsi,0,3) == '972') { |
|
718 | + return 'MOB (Man Overboard) device'; |
|
719 | + } elseif (substr($mmsi,0,3) == '970') { |
|
720 | + return 'AIS SART (Search and Rescue Transmitter)'; |
|
721 | + } elseif (substr($mmsi,0,3) == '111') { |
|
722 | + return 'SAR (Search and Rescue) aircraft'; |
|
723 | + } elseif (substr($mmsi,0,2) == '98') { |
|
724 | + return 'Auxiliary craft associated with a parent ship'; |
|
725 | + } elseif (substr($mmsi,0,2) == '99') { |
|
726 | + return 'Aids to Navigation'; |
|
727 | + } elseif (substr($mmsi,0,2) == '00') { |
|
728 | + return 'Coastal stations'; |
|
729 | + } elseif (substr($mmsi,0,1) == '0') { |
|
730 | + return 'Group of ships'; |
|
731 | + } else { |
|
732 | + return 'Ship'; |
|
733 | + } |
|
638 | 734 | } |
639 | 735 | |
640 | 736 | |
@@ -650,32 +746,61 @@ discard block |
||
650 | 746 | //if ($globalDebug) echo '==== Line format not supported : '.$buffer."\n"; |
651 | 747 | return array(); |
652 | 748 | } |
653 | - if ($data->lon != 0) $result['longitude'] = $data->lon; |
|
654 | - if ($data->lat != 0) $result['latitude'] = $data->lat; |
|
749 | + if ($data->lon != 0) { |
|
750 | + $result['longitude'] = $data->lon; |
|
751 | + } |
|
752 | + if ($data->lat != 0) { |
|
753 | + $result['latitude'] = $data->lat; |
|
754 | + } |
|
655 | 755 | $result['ident'] = trim(str_replace('@','',$data->name)); |
656 | 756 | $result['timestamp'] = $data->ts; |
657 | 757 | $result['mmsi'] = $data->mmsi; |
658 | - if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') $result['mmsi'] = '3'.$result['mmsi']; |
|
758 | + if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') { |
|
759 | + $result['mmsi'] = '3'.$result['mmsi']; |
|
760 | + } |
|
659 | 761 | $result['mmsi_type'] = $this->mmsitype($result['mmsi']); |
660 | - if ($data->sog != -1.0) $result['speed'] = $data->sog; |
|
661 | - if ($data->heading !== '') $result['heading'] = $data->heading; |
|
662 | - elseif ($data->cog != 0) $result['heading'] = $data->cog; |
|
663 | - if ($data->status != '') $result['status'] = $data->status; |
|
664 | - if ($data->statusid !== '') $result['statusid'] = $data->statusid; |
|
665 | - if ($data->type !== '') $result['type'] = $data->type; |
|
666 | - if ($data->typeid !== '') $result['typeid'] = $data->typeid; |
|
667 | - if ($data->imo !== '') $result['imo'] = $data->imo; |
|
668 | - if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@','',$data->callsign)); |
|
762 | + if ($data->sog != -1.0) { |
|
763 | + $result['speed'] = $data->sog; |
|
764 | + } |
|
765 | + if ($data->heading !== '') { |
|
766 | + $result['heading'] = $data->heading; |
|
767 | + } elseif ($data->cog != 0) { |
|
768 | + $result['heading'] = $data->cog; |
|
769 | + } |
|
770 | + if ($data->status != '') { |
|
771 | + $result['status'] = $data->status; |
|
772 | + } |
|
773 | + if ($data->statusid !== '') { |
|
774 | + $result['statusid'] = $data->statusid; |
|
775 | + } |
|
776 | + if ($data->type !== '') { |
|
777 | + $result['type'] = $data->type; |
|
778 | + } |
|
779 | + if ($data->typeid !== '') { |
|
780 | + $result['typeid'] = $data->typeid; |
|
781 | + } |
|
782 | + if ($data->imo !== '') { |
|
783 | + $result['imo'] = $data->imo; |
|
784 | + } |
|
785 | + if ($data->callsign !== '') { |
|
786 | + $result['callsign'] = trim(str_replace('@','',$data->callsign)); |
|
787 | + } |
|
669 | 788 | if (is_numeric($data->eta_month) && $data->eta_month != 0 && is_numeric($data->eta_day) && $data->eta_day != 0 && $data->eta_hour !== '' && $data->eta_minute !== '') { |
670 | 789 | $eta_ts = strtotime(date('Y').'-'.sprintf("%02d",$data->eta_month).'-'.sprintf("%02d",$data->eta_day).' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00'); |
671 | - if ($eta_ts != '') $result['eta_ts'] = $eta_ts; |
|
790 | + if ($eta_ts != '') { |
|
791 | + $result['eta_ts'] = $eta_ts; |
|
792 | + } |
|
672 | 793 | } elseif (is_numeric($data->eta_hour) && is_numeric($data->eta_minute)) { |
673 | 794 | $eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00'); |
674 | - if ($eta_ts != '') $result['eta_ts'] = $eta_ts; |
|
795 | + if ($eta_ts != '') { |
|
796 | + $result['eta_ts'] = $eta_ts; |
|
797 | + } |
|
675 | 798 | } |
676 | 799 | if ($data->destination != '') { |
677 | 800 | $dest = trim(str_replace('@','',$data->destination)); |
678 | - if ($dest != '') $result['destination'] = $dest; |
|
801 | + if ($dest != '') { |
|
802 | + $result['destination'] = $dest; |
|
803 | + } |
|
679 | 804 | } |
680 | 805 | $result['all'] = (array) $data; |
681 | 806 | /* |
@@ -14,7 +14,7 @@ |
||
14 | 14 | $limit_start = 0; |
15 | 15 | $limit_end = 25; |
16 | 16 | $absolute_difference = 25; |
17 | - } else { |
|
17 | + } else { |
|
18 | 18 | $limit_explode = explode(",", $_GET['limit']); |
19 | 19 | $limit_start = $limit_explode[0]; |
20 | 20 | $limit_end = $limit_explode[1]; |
@@ -5,16 +5,16 @@ discard block |
||
5 | 5 | require_once('require/class.Language.php'); |
6 | 6 | $Marine = new Marine(); |
7 | 7 | $type = 'marine'; |
8 | -if (!isset($_GET['type'])){ |
|
8 | +if (!isset($_GET['type'])) { |
|
9 | 9 | header('Location: '.$globalURL.'/'); |
10 | 10 | } else { |
11 | 11 | //calculuation for the pagination |
12 | - if(!isset($_GET['limit']) || count(explode(",", $_GET['limit'])) < 2) |
|
12 | + if (!isset($_GET['limit']) || count(explode(",", $_GET['limit'])) < 2) |
|
13 | 13 | { |
14 | 14 | $limit_start = 0; |
15 | 15 | $limit_end = 25; |
16 | 16 | $absolute_difference = 25; |
17 | - } else { |
|
17 | + } else { |
|
18 | 18 | $limit_explode = explode(",", $_GET['limit']); |
19 | 19 | $limit_start = $limit_explode[0]; |
20 | 20 | $limit_end = $limit_explode[1]; |
@@ -28,14 +28,14 @@ discard block |
||
28 | 28 | $limit_previous_1 = $limit_start - $absolute_difference; |
29 | 29 | $limit_previous_2 = $limit_end - $absolute_difference; |
30 | 30 | |
31 | - $marine_type = filter_input(INPUT_GET,'type',FILTER_SANITIZE_STRING); |
|
31 | + $marine_type = filter_input(INPUT_GET, 'type', FILTER_SANITIZE_STRING); |
|
32 | 32 | $page_url = $globalURL.'/marine/type/'.$marine_type; |
33 | - $sort = htmlspecialchars(filter_input(INPUT_GET,'sort',FILTER_SANITIZE_STRING)); |
|
34 | - $spotter_array = $Marine->getMarineDataByType($marine_type,$limit_start.",".$absolute_difference, $sort); |
|
33 | + $sort = htmlspecialchars(filter_input(INPUT_GET, 'sort', FILTER_SANITIZE_STRING)); |
|
34 | + $spotter_array = $Marine->getMarineDataByType($marine_type, $limit_start.",".$absolute_difference, $sort); |
|
35 | 35 | |
36 | 36 | if (!empty($spotter_array)) |
37 | 37 | { |
38 | - $title = sprintf(_("Detailed View for %s"),$spotter_array[0]['type']); |
|
38 | + $title = sprintf(_("Detailed View for %s"), $spotter_array[0]['type']); |
|
39 | 39 | require_once('header.php'); |
40 | 40 | |
41 | 41 | print '<div class="info column">'; |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | |
45 | 45 | //include('aircraft-sub-menu.php'); |
46 | 46 | print '<div class="table column">'; |
47 | - print '<p>'.sprintf(_("The table below shows the detailed information of all marine of type <strong>%s</strong>."),$spotter_array[0]['type']).'</p>'; |
|
47 | + print '<p>'.sprintf(_("The table below shows the detailed information of all marine of type <strong>%s</strong>."), $spotter_array[0]['type']).'</p>'; |
|
48 | 48 | |
49 | 49 | include('table-output.php'); |
50 | 50 |
@@ -7,8 +7,8 @@ discard block |
||
7 | 7 | |
8 | 8 | $type = 'marine'; |
9 | 9 | if (!isset($filter_name)) $filter_name = ''; |
10 | -$year = filter_input(INPUT_GET,'year',FILTER_SANITIZE_NUMBER_INT); |
|
11 | -$month = filter_input(INPUT_GET,'month',FILTER_SANITIZE_NUMBER_INT); |
|
10 | +$year = filter_input(INPUT_GET, 'year', FILTER_SANITIZE_NUMBER_INT); |
|
11 | +$month = filter_input(INPUT_GET, 'month', FILTER_SANITIZE_NUMBER_INT); |
|
12 | 12 | |
13 | 13 | require_once('header.php'); |
14 | 14 | |
@@ -20,10 +20,10 @@ discard block |
||
20 | 20 | </div> |
21 | 21 | <p>'._("Below are the <strong>Top 10</strong> most common vessel types.").'</p>'; |
22 | 22 | |
23 | -$type_array = $Marine->countAllMarineTypes(true,0,'',$filter_name,$year,$month); |
|
23 | +$type_array = $Marine->countAllMarineTypes(true, 0, '', $filter_name, $year, $month); |
|
24 | 24 | print '<div id="chart" class="chart" width="100%"></div><script>'; |
25 | 25 | $type_data = ''; |
26 | -foreach($type_array as $type_item) |
|
26 | +foreach ($type_array as $type_item) |
|
27 | 27 | { |
28 | 28 | $type_data .= '["'.$type_item['marine_type'].'",'.$type_item['marine_type_count'].'],'; |
29 | 29 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | print '</thead>'; |
49 | 49 | print '<tbody>'; |
50 | 50 | $i = 1; |
51 | - foreach($type_array as $type_item) |
|
51 | + foreach ($type_array as $type_item) |
|
52 | 52 | { |
53 | 53 | print '<tr>'; |
54 | 54 | print '<td><strong>'.$i.'</strong></td>'; |
@@ -6,7 +6,9 @@ |
||
6 | 6 | $title = _("Statistics").' - '._("Most common Vessel Type"); |
7 | 7 | |
8 | 8 | $type = 'marine'; |
9 | -if (!isset($filter_name)) $filter_name = ''; |
|
9 | +if (!isset($filter_name)) { |
|
10 | + $filter_name = ''; |
|
11 | +} |
|
10 | 12 | $year = filter_input(INPUT_GET,'year',FILTER_SANITIZE_NUMBER_INT); |
11 | 13 | $month = filter_input(INPUT_GET,'month',FILTER_SANITIZE_NUMBER_INT); |
12 | 14 |
@@ -5,11 +5,11 @@ |
||
5 | 5 | |
6 | 6 | if (isset($_POST['aircraft_manufacturer']) && $_POST['aircraft_manufacturer'] != '') |
7 | 7 | { |
8 | - $aircraft_manufacturer = filter_input(INPUT_POST,'aircraft_manufacturer',FILTER_SANITIZE_STRING); |
|
8 | + $aircraft_manufacturer = filter_input(INPUT_POST, 'aircraft_manufacturer', FILTER_SANITIZE_STRING); |
|
9 | 9 | header('Location: '.$globalURL.'/manufacturer/'.$aircraft_manufacturer); |
10 | 10 | } elseif (isset($_GET['aircraft_manufacturer']) && $_GET['aircraft_manufacturer'] != '') |
11 | 11 | { |
12 | - $aircraft_manufacturer = filter_input(INPUT_GET,'aircraft_manufacturer',FILTER_SANITIZE_STRING); |
|
12 | + $aircraft_manufacturer = filter_input(INPUT_GET, 'aircraft_manufacturer', FILTER_SANITIZE_STRING); |
|
13 | 13 | header('Location: '.$globalURL.'/manufacturer/'.$aircraft_manufacturer); |
14 | 14 | } else { |
15 | 15 | if ($globalURL == '') { |
@@ -5,14 +5,14 @@ |
||
5 | 5 | require_once('require/class.Language.php'); |
6 | 6 | |
7 | 7 | header('Content-Type: text/javascript'); |
8 | -$q = filter_input(INPUT_GET,'q',FILTER_SANITIZE_STRING); |
|
8 | +$q = filter_input(INPUT_GET, 'q', FILTER_SANITIZE_STRING); |
|
9 | 9 | $SpotterLive = new SpotterLive(); |
10 | 10 | $spotter_array = $SpotterLive->getRealTimeData($q); |
11 | 11 | |
12 | 12 | $output = '{'; |
13 | 13 | $output .= '"flights": ['; |
14 | 14 | if (!empty($spotter_array)) { |
15 | - foreach($spotter_array as $spotter_item) |
|
15 | + foreach ($spotter_array as $spotter_item) |
|
16 | 16 | { |
17 | 17 | $output .= '{'; |
18 | 18 | $output .= '"flight_id": "'.$spotter_item['spotter_id'].'",'; |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | <?php |
30 | 30 | if (isset($_GET['q'])) |
31 | 31 | { |
32 | - $q = filter_input(INPUT_GET,'q',FILTER_SANITIZE_STRING); |
|
32 | + $q = filter_input(INPUT_GET, 'q', FILTER_SANITIZE_STRING); |
|
33 | 33 | $spotter_array = $Spotter->searchSpotterData($q, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "0,10", "", ""); |
34 | 34 | } else { |
35 | 35 | $spotter_array = $Spotter->getLatestSpotterData("0,10", ""); |
@@ -148,18 +148,18 @@ discard block |
||
148 | 148 | |
149 | 149 | <?php |
150 | 150 | if (isset($_GET['image']) && isset($_GET['q'])) { |
151 | - $image = filter_input(INPUT_GET,'image',FILTER_SANITIZE_STRING); |
|
152 | - $q = filter_input(INPUT_GET,'q',FILTER_SANITIZE_STRING); |
|
151 | + $image = filter_input(INPUT_GET, 'image', FILTER_SANITIZE_STRING); |
|
152 | + $q = filter_input(INPUT_GET, 'q', FILTER_SANITIZE_STRING); |
|
153 | 153 | ?> |
154 | 154 | $.getJSON( "<?php print $globalURL; ?>/getLatestData-tv.php?other_i="+other_i+"&image=<?php print $image; ?>&q=<?php print $q; ?>", function( data ) { |
155 | 155 | <?php |
156 | 156 | } elseif (isset($_GET['image'])) { |
157 | - $image = filter_input(INPUT_GET,'image',FILTER_SANITIZE_STRING); |
|
157 | + $image = filter_input(INPUT_GET, 'image', FILTER_SANITIZE_STRING); |
|
158 | 158 | ?> |
159 | 159 | $.getJSON( "<?php print $globalURL; ?>/getLatestData-tv.php?other_i="+other_i+"&image=<?php print $image; ?>", function( data ) { |
160 | 160 | <?php |
161 | 161 | } elseif (isset($_GET['q'])) { |
162 | - $q = filter_input(INPUT_GET,'q',FILTER_SANITIZE_STRING); |
|
162 | + $q = filter_input(INPUT_GET, 'q', FILTER_SANITIZE_STRING); |
|
163 | 163 | ?> |
164 | 164 | $.getJSON( "<?php print $globalURL; ?>/getLatestData-tv.php?other_i="+other_i+"&q=<?php print $q; ?>", function( data ) { |
165 | 165 | <?php |