@@ -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,14 +63,25 @@ discard block |
||
59 | 63 | $globalSources = array(); |
60 | 64 | $globalSources[] = array('host' => $options['source']); |
61 | 65 | } |
62 | -if (isset($options['server'])) $globalServer = TRUE; |
|
63 | -if (isset($options['idsource'])) $id_source = $options['idsource']; |
|
64 | -else $id_source = 1; |
|
66 | +if (isset($options['server'])) { |
|
67 | + $globalServer = TRUE; |
|
68 | +} |
|
69 | +if (isset($options['idsource'])) { |
|
70 | + $id_source = $options['idsource']; |
|
71 | +} else { |
|
72 | + $id_source = 1; |
|
73 | +} |
|
65 | 74 | if (isset($globalServer) && $globalServer) { |
66 | - if ($globalDebug) echo "Using Server Mode\n"; |
|
75 | + if ($globalDebug) { |
|
76 | + echo "Using Server Mode\n"; |
|
77 | + } |
|
67 | 78 | $SI=new SpotterServer(); |
68 | -} else $SI=new SpotterImport($Connection->db); |
|
69 | -if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db); |
|
79 | +} else { |
|
80 | + $SI=new SpotterImport($Connection->db); |
|
81 | +} |
|
82 | +if (isset($globalTracker) && $globalTracker) { |
|
83 | + $TI = new TrackerImport($Connection->db); |
|
84 | +} |
|
70 | 85 | if (isset($globalMarine) && $globalMarine) { |
71 | 86 | $AIS = new AIS(); |
72 | 87 | $MI = new MarineImport($Connection->db); |
@@ -88,7 +103,9 @@ discard block |
||
88 | 103 | } |
89 | 104 | |
90 | 105 | // let's try and connect |
91 | -if ($globalDebug) echo "Connecting...\n"; |
|
106 | +if ($globalDebug) { |
|
107 | + echo "Connecting...\n"; |
|
108 | +} |
|
92 | 109 | $use_aprs = false; |
93 | 110 | $aprs_full = false; |
94 | 111 | $reset = 0; |
@@ -97,7 +114,9 @@ discard block |
||
97 | 114 | $ip = gethostbyname($host); |
98 | 115 | $s = socket_create(AF_INET, SOCK_STREAM, 0); |
99 | 116 | $r = @socket_connect($s, $ip, $port); |
100 | - if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n"; |
|
117 | + if (!socket_set_nonblock($s)) { |
|
118 | + echo "Unable to set nonblock on socket\n"; |
|
119 | + } |
|
101 | 120 | if ($r || socket_last_error() == 114 || socket_last_error() == 115) { |
102 | 121 | return $s; |
103 | 122 | } |
@@ -125,7 +144,9 @@ discard block |
||
125 | 144 | //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs; |
126 | 145 | global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context; |
127 | 146 | $reset++; |
128 | - if ($globalDebug) echo 'Connect to all...'."\n"; |
|
147 | + if ($globalDebug) { |
|
148 | + echo 'Connect to all...'."\n"; |
|
149 | + } |
|
129 | 150 | foreach ($hosts as $id => $value) { |
130 | 151 | $host = $value['host']; |
131 | 152 | $globalSources[$id]['last_exec'] = 0; |
@@ -135,27 +156,37 @@ discard block |
||
135 | 156 | //$formats[$id] = 'deltadbtxt'; |
136 | 157 | $globalSources[$id]['format'] = 'deltadbtxt'; |
137 | 158 | //$last_exec['deltadbtxt'] = 0; |
138 | - if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n"; |
|
159 | + if ($globalDebug) { |
|
160 | + echo "Connect to deltadb source (".$host.")...\n"; |
|
161 | + } |
|
139 | 162 | } else if (preg_match('/vatsim-data.txt$/i',$host)) { |
140 | 163 | //$formats[$id] = 'vatsimtxt'; |
141 | 164 | $globalSources[$id]['format'] = 'vatsimtxt'; |
142 | 165 | //$last_exec['vatsimtxt'] = 0; |
143 | - if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n"; |
|
166 | + if ($globalDebug) { |
|
167 | + echo "Connect to vatsim source (".$host.")...\n"; |
|
168 | + } |
|
144 | 169 | } else if (preg_match('/aircraftlist.json$/i',$host)) { |
145 | 170 | //$formats[$id] = 'aircraftlistjson'; |
146 | 171 | $globalSources[$id]['format'] = 'aircraftlistjson'; |
147 | 172 | //$last_exec['aircraftlistjson'] = 0; |
148 | - if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n"; |
|
173 | + if ($globalDebug) { |
|
174 | + echo "Connect to aircraftlist.json source (".$host.")...\n"; |
|
175 | + } |
|
149 | 176 | } else if (preg_match('/opensky/i',$host)) { |
150 | 177 | //$formats[$id] = 'aircraftlistjson'; |
151 | 178 | $globalSources[$id]['format'] = 'opensky'; |
152 | 179 | //$last_exec['aircraftlistjson'] = 0; |
153 | - if ($globalDebug) echo "Connect to opensky source (".$host.")...\n"; |
|
180 | + if ($globalDebug) { |
|
181 | + echo "Connect to opensky source (".$host.")...\n"; |
|
182 | + } |
|
154 | 183 | } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) { |
155 | 184 | //$formats[$id] = 'radarvirtueljson'; |
156 | 185 | $globalSources[$id]['format'] = 'radarvirtueljson'; |
157 | 186 | //$last_exec['radarvirtueljson'] = 0; |
158 | - if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n"; |
|
187 | + if ($globalDebug) { |
|
188 | + echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n"; |
|
189 | + } |
|
159 | 190 | if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
160 | 191 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
161 | 192 | exit(0); |
@@ -164,7 +195,9 @@ discard block |
||
164 | 195 | //$formats[$id] = 'planeupdatefaa'; |
165 | 196 | $globalSources[$id]['format'] = 'planeupdatefaa'; |
166 | 197 | //$last_exec['planeupdatefaa'] = 0; |
167 | - if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n"; |
|
198 | + if ($globalDebug) { |
|
199 | + echo "Connect to planeUpdateFAA.php source (".$host.")...\n"; |
|
200 | + } |
|
168 | 201 | if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
169 | 202 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
170 | 203 | exit(0); |
@@ -173,26 +206,36 @@ discard block |
||
173 | 206 | //$formats[$id] = 'phpvmacars'; |
174 | 207 | $globalSources[$id]['format'] = 'phpvmacars'; |
175 | 208 | //$last_exec['phpvmacars'] = 0; |
176 | - if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n"; |
|
209 | + if ($globalDebug) { |
|
210 | + echo "Connect to phpvmacars source (".$host.")...\n"; |
|
211 | + } |
|
177 | 212 | } else if (preg_match('/VAM-json.php$/i',$host)) { |
178 | 213 | //$formats[$id] = 'phpvmacars'; |
179 | 214 | $globalSources[$id]['format'] = 'vam'; |
180 | - if ($globalDebug) echo "Connect to Vam source (".$host.")...\n"; |
|
215 | + if ($globalDebug) { |
|
216 | + echo "Connect to Vam source (".$host.")...\n"; |
|
217 | + } |
|
181 | 218 | } else if (preg_match('/whazzup/i',$host)) { |
182 | 219 | //$formats[$id] = 'whazzup'; |
183 | 220 | $globalSources[$id]['format'] = 'whazzup'; |
184 | 221 | //$last_exec['whazzup'] = 0; |
185 | - if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n"; |
|
222 | + if ($globalDebug) { |
|
223 | + echo "Connect to whazzup source (".$host.")...\n"; |
|
224 | + } |
|
186 | 225 | } else if (preg_match('/recentpireps/i',$host)) { |
187 | 226 | //$formats[$id] = 'pirepsjson'; |
188 | 227 | $globalSources[$id]['format'] = 'pirepsjson'; |
189 | 228 | //$last_exec['pirepsjson'] = 0; |
190 | - if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n"; |
|
229 | + if ($globalDebug) { |
|
230 | + echo "Connect to pirepsjson source (".$host.")...\n"; |
|
231 | + } |
|
191 | 232 | } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) { |
192 | 233 | //$formats[$id] = 'fr24json'; |
193 | 234 | $globalSources[$id]['format'] = 'fr24json'; |
194 | 235 | //$last_exec['fr24json'] = 0; |
195 | - if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n"; |
|
236 | + if ($globalDebug) { |
|
237 | + echo "Connect to fr24 source (".$host.")...\n"; |
|
238 | + } |
|
196 | 239 | if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
197 | 240 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
198 | 241 | exit(0); |
@@ -201,17 +244,24 @@ discard block |
||
201 | 244 | } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) { |
202 | 245 | //$formats[$id] = 'tsv'; |
203 | 246 | $globalSources[$id]['format'] = 'tsv'; |
204 | - if ($globalDebug) echo "Connect to tsv source (".$host.")...\n"; |
|
247 | + if ($globalDebug) { |
|
248 | + echo "Connect to tsv source (".$host.")...\n"; |
|
249 | + } |
|
205 | 250 | } |
206 | 251 | } elseif (filter_var($host,FILTER_VALIDATE_URL)) { |
207 | 252 | if ($globalSources[$id]['format'] == 'aisnmeahttp') { |
208 | 253 | $idf = fopen($globalSources[$id]['host'],'r',false,$context); |
209 | 254 | if ($idf !== false) { |
210 | 255 | $httpfeeds[$id] = $idf; |
211 | - if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
|
256 | + if ($globalDebug) { |
|
257 | + echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
|
258 | + } |
|
259 | + } elseif ($globalDebug) { |
|
260 | + echo "Can't connect to ".$globalSources[$id]['host']."\n"; |
|
212 | 261 | } |
213 | - elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n"; |
|
214 | - } elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
|
262 | + } elseif ($globalDebug) { |
|
263 | + echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
|
264 | + } |
|
215 | 265 | } elseif (!filter_var($host,FILTER_VALIDATE_URL)) { |
216 | 266 | $hostport = explode(':',$host); |
217 | 267 | if (isset($hostport[1])) { |
@@ -248,17 +298,25 @@ discard block |
||
248 | 298 | //$formats[$id] = 'beast'; |
249 | 299 | $globalSources[$id]['format'] = 'beast'; |
250 | 300 | //} else $formats[$id] = 'sbs'; |
251 | - } else $globalSources[$id]['format'] = 'sbs'; |
|
301 | + } else { |
|
302 | + $globalSources[$id]['format'] = 'sbs'; |
|
303 | + } |
|
252 | 304 | //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n"; |
253 | 305 | } |
254 | - if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n"; |
|
306 | + if ($globalDebug) { |
|
307 | + echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n"; |
|
308 | + } |
|
255 | 309 | } else { |
256 | - if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n"; |
|
310 | + if ($globalDebug) { |
|
311 | + echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n"; |
|
312 | + } |
|
257 | 313 | } |
258 | 314 | } |
259 | 315 | } |
260 | 316 | } |
261 | -if (!isset($globalMinFetch)) $globalMinFetch = 15; |
|
317 | +if (!isset($globalMinFetch)) { |
|
318 | + $globalMinFetch = 15; |
|
319 | +} |
|
262 | 320 | |
263 | 321 | // Initialize all |
264 | 322 | $status = array(); |
@@ -267,13 +325,19 @@ discard block |
||
267 | 325 | $formats = array(); |
268 | 326 | $last_exec = array(); |
269 | 327 | $time = time(); |
270 | -if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut; |
|
271 | -else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut; |
|
272 | -else $timeout = 20; |
|
328 | +if (isset($globalSourcesTimeout)) { |
|
329 | + $timeout = $globalSourcesTimeOut; |
|
330 | +} else if (isset($globalSBS1TimeOut)) { |
|
331 | + $timeout = $globalSBS1TimeOut; |
|
332 | +} else { |
|
333 | + $timeout = 20; |
|
334 | +} |
|
273 | 335 | $errno = ''; |
274 | 336 | $errstr=''; |
275 | 337 | |
276 | -if (!isset($globalDaemon)) $globalDaemon = TRUE; |
|
338 | +if (!isset($globalDaemon)) { |
|
339 | + $globalDaemon = TRUE; |
|
340 | +} |
|
277 | 341 | /* Initiate connections to all the hosts simultaneously */ |
278 | 342 | //connect_all($hosts); |
279 | 343 | //connect_all($globalSources); |
@@ -299,7 +363,9 @@ discard block |
||
299 | 363 | if (isset($source['format']) && $source['format'] == 'aprs') { |
300 | 364 | $aprs_connect = 0; |
301 | 365 | $use_aprs = true; |
302 | - if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true; |
|
366 | + if (isset($source['port']) && $source['port'] == '10152') { |
|
367 | + $aprs_full = true; |
|
368 | + } |
|
303 | 369 | break; |
304 | 370 | } |
305 | 371 | } |
@@ -310,23 +376,43 @@ discard block |
||
310 | 376 | $aprs_connect = 0; |
311 | 377 | $aprs_keep = 120; |
312 | 378 | $aprs_last_tx = time(); |
313 | - if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion; |
|
314 | - else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName); |
|
315 | - if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid; |
|
316 | - else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8); |
|
317 | - if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter; |
|
318 | - else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0'; |
|
319 | - if ($aprs_full) $aprs_filter = ''; |
|
379 | + if (isset($globalAPRSversion)) { |
|
380 | + $aprs_version = $globalAPRSversion; |
|
381 | + } else { |
|
382 | + $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName); |
|
383 | + } |
|
384 | + if (isset($globalAPRSssid)) { |
|
385 | + $aprs_ssid = $globalAPRSssid; |
|
386 | + } else { |
|
387 | + $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8); |
|
388 | + } |
|
389 | + if (isset($globalAPRSfilter)) { |
|
390 | + $aprs_filter = $globalAPRSfilter; |
|
391 | + } else { |
|
392 | + $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0'; |
|
393 | + } |
|
394 | + if ($aprs_full) { |
|
395 | + $aprs_filter = ''; |
|
396 | + } |
|
320 | 397 | |
321 | - if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version} filter {$aprs_filter}\n"; |
|
322 | - else $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version}\n"; |
|
323 | -} |
|
398 | + if ($aprs_filter != '') { |
|
399 | + $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version} filter {$aprs_filter}\n"; |
|
400 | + } else { |
|
401 | + $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version}\n"; |
|
402 | + } |
|
403 | + } |
|
324 | 404 | |
325 | 405 | // connected - lets do some work |
326 | -if ($globalDebug) echo "Connected!\n"; |
|
406 | +if ($globalDebug) { |
|
407 | + echo "Connected!\n"; |
|
408 | +} |
|
327 | 409 | sleep(1); |
328 | -if ($globalDebug) echo "SCAN MODE \n\n"; |
|
329 | -if (!isset($globalCronEnd)) $globalCronEnd = 60; |
|
410 | +if ($globalDebug) { |
|
411 | + echo "SCAN MODE \n\n"; |
|
412 | +} |
|
413 | +if (!isset($globalCronEnd)) { |
|
414 | + $globalCronEnd = 60; |
|
415 | +} |
|
330 | 416 | $endtime = time()+$globalCronEnd; |
331 | 417 | $i = 1; |
332 | 418 | $tt = array(); |
@@ -340,10 +426,14 @@ discard block |
||
340 | 426 | |
341 | 427 | // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time. |
342 | 428 | while ($i > 0) { |
343 | - if (!$globalDaemon) $i = $endtime-time(); |
|
429 | + if (!$globalDaemon) { |
|
430 | + $i = $endtime-time(); |
|
431 | + } |
|
344 | 432 | // Delete old ATC |
345 | 433 | if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) { |
346 | - if ($globalDebug) echo 'Delete old ATC...'."\n"; |
|
434 | + if ($globalDebug) { |
|
435 | + echo 'Delete old ATC...'."\n"; |
|
436 | + } |
|
347 | 437 | $ATC->deleteOldATC(); |
348 | 438 | } |
349 | 439 | |
@@ -351,10 +441,14 @@ discard block |
||
351 | 441 | if (count($last_exec) == count($globalSources)) { |
352 | 442 | $max = $globalMinFetch; |
353 | 443 | foreach ($last_exec as $last) { |
354 | - if ((time() - $last['last']) < $max) $max = time() - $last['last']; |
|
444 | + if ((time() - $last['last']) < $max) { |
|
445 | + $max = time() - $last['last']; |
|
446 | + } |
|
355 | 447 | } |
356 | 448 | if ($max != $globalMinFetch) { |
357 | - if ($globalDebug) echo 'Sleeping...'."\n"; |
|
449 | + if ($globalDebug) { |
|
450 | + echo 'Sleeping...'."\n"; |
|
451 | + } |
|
358 | 452 | sleep($globalMinFetch-$max+2); |
359 | 453 | } |
360 | 454 | } |
@@ -363,11 +457,15 @@ discard block |
||
363 | 457 | //foreach ($formats as $id => $value) { |
364 | 458 | foreach ($globalSources as $id => $value) { |
365 | 459 | date_default_timezone_set('UTC'); |
366 | - if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0; |
|
460 | + if (!isset($last_exec[$id]['last'])) { |
|
461 | + $last_exec[$id]['last'] = 0; |
|
462 | + } |
|
367 | 463 | if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
368 | 464 | //$buffer = $Common->getData($hosts[$id]); |
369 | 465 | $buffer = $Common->getData($value['host']); |
370 | - if ($buffer != '') $reset = 0; |
|
466 | + if ($buffer != '') { |
|
467 | + $reset = 0; |
|
468 | + } |
|
371 | 469 | $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
372 | 470 | $buffer = explode('\n',$buffer); |
373 | 471 | foreach ($buffer as $line) { |
@@ -376,19 +474,38 @@ discard block |
||
376 | 474 | $data = array(); |
377 | 475 | $data['hex'] = $line[1]; // hex |
378 | 476 | $data['ident'] = $line[2]; // ident |
379 | - if (isset($line[3])) $data['altitude'] = $line[3]; // altitude |
|
380 | - if (isset($line[4])) $data['speed'] = $line[4]; // speed |
|
381 | - if (isset($line[5])) $data['heading'] = $line[5]; // heading |
|
382 | - if (isset($line[6])) $data['latitude'] = $line[6]; // lat |
|
383 | - if (isset($line[7])) $data['longitude'] = $line[7]; // long |
|
477 | + if (isset($line[3])) { |
|
478 | + $data['altitude'] = $line[3]; |
|
479 | + } |
|
480 | + // altitude |
|
481 | + if (isset($line[4])) { |
|
482 | + $data['speed'] = $line[4]; |
|
483 | + } |
|
484 | + // speed |
|
485 | + if (isset($line[5])) { |
|
486 | + $data['heading'] = $line[5]; |
|
487 | + } |
|
488 | + // heading |
|
489 | + if (isset($line[6])) { |
|
490 | + $data['latitude'] = $line[6]; |
|
491 | + } |
|
492 | + // lat |
|
493 | + if (isset($line[7])) { |
|
494 | + $data['longitude'] = $line[7]; |
|
495 | + } |
|
496 | + // long |
|
384 | 497 | $data['verticalrate'] = ''; // vertical rate |
385 | 498 | //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk |
386 | 499 | $data['emergency'] = ''; // emergency |
387 | 500 | $data['datetime'] = date('Y-m-d H:i:s'); |
388 | 501 | $data['format_source'] = 'deltadbtxt'; |
389 | 502 | $data['id_source'] = $id_source; |
390 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
391 | - if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats']; |
|
503 | + if (isset($value['name']) && $value['name'] != '') { |
|
504 | + $data['source_name'] = $value['name']; |
|
505 | + } |
|
506 | + if (isset($value['sourcestats'])) { |
|
507 | + $data['sourcestats'] = $value['sourcestats']; |
|
508 | + } |
|
392 | 509 | $SI->add($data); |
393 | 510 | unset($data); |
394 | 511 | } |
@@ -398,7 +515,9 @@ discard block |
||
398 | 515 | date_default_timezone_set('CET'); |
399 | 516 | $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host'])); |
400 | 517 | date_default_timezone_set('UTC'); |
401 | - if ($buffer != '') $reset = 0; |
|
518 | + if ($buffer != '') { |
|
519 | + $reset = 0; |
|
520 | + } |
|
402 | 521 | $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
403 | 522 | $buffer = explode('\n',$buffer); |
404 | 523 | foreach ($buffer as $line) { |
@@ -407,16 +526,36 @@ discard block |
||
407 | 526 | $add = false; |
408 | 527 | $ais_data = $AIS->parse_line(trim($line)); |
409 | 528 | $data = array(); |
410 | - if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident']; |
|
411 | - if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi']; |
|
412 | - if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed']; |
|
413 | - if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading']; |
|
414 | - if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude']; |
|
415 | - if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude']; |
|
416 | - if (isset($ais_data['status'])) $data['status'] = $ais_data['status']; |
|
417 | - if (isset($ais_data['type'])) $data['type'] = $ais_data['type']; |
|
418 | - if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo']; |
|
419 | - if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign']; |
|
529 | + if (isset($ais_data['ident'])) { |
|
530 | + $data['ident'] = $ais_data['ident']; |
|
531 | + } |
|
532 | + if (isset($ais_data['mmsi'])) { |
|
533 | + $data['mmsi'] = $ais_data['mmsi']; |
|
534 | + } |
|
535 | + if (isset($ais_data['speed'])) { |
|
536 | + $data['speed'] = $ais_data['speed']; |
|
537 | + } |
|
538 | + if (isset($ais_data['heading'])) { |
|
539 | + $data['heading'] = $ais_data['heading']; |
|
540 | + } |
|
541 | + if (isset($ais_data['latitude'])) { |
|
542 | + $data['latitude'] = $ais_data['latitude']; |
|
543 | + } |
|
544 | + if (isset($ais_data['longitude'])) { |
|
545 | + $data['longitude'] = $ais_data['longitude']; |
|
546 | + } |
|
547 | + if (isset($ais_data['status'])) { |
|
548 | + $data['status'] = $ais_data['status']; |
|
549 | + } |
|
550 | + if (isset($ais_data['type'])) { |
|
551 | + $data['type'] = $ais_data['type']; |
|
552 | + } |
|
553 | + if (isset($ais_data['imo'])) { |
|
554 | + $data['imo'] = $ais_data['imo']; |
|
555 | + } |
|
556 | + if (isset($ais_data['callsign'])) { |
|
557 | + $data['callsign'] = $ais_data['callsign']; |
|
558 | + } |
|
420 | 559 | if (isset($ais_data['timestamp'])) { |
421 | 560 | $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']); |
422 | 561 | if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) { |
@@ -431,7 +570,9 @@ discard block |
||
431 | 570 | $data['id_source'] = $id_source; |
432 | 571 | print_r($data); |
433 | 572 | echo 'Add...'."\n"; |
434 | - if ($add) $MI->add($data); |
|
573 | + if ($add) { |
|
574 | + $MI->add($data); |
|
575 | + } |
|
435 | 576 | unset($data); |
436 | 577 | } |
437 | 578 | } |
@@ -451,16 +592,36 @@ discard block |
||
451 | 592 | if ($line != '') { |
452 | 593 | $ais_data = $AIS->parse_line(trim($line)); |
453 | 594 | $data = array(); |
454 | - if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident']; |
|
455 | - if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi']; |
|
456 | - if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed']; |
|
457 | - if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading']; |
|
458 | - if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude']; |
|
459 | - if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude']; |
|
460 | - if (isset($ais_data['status'])) $data['status'] = $ais_data['status']; |
|
461 | - if (isset($ais_data['type'])) $data['type'] = $ais_data['type']; |
|
462 | - if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo']; |
|
463 | - if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign']; |
|
595 | + if (isset($ais_data['ident'])) { |
|
596 | + $data['ident'] = $ais_data['ident']; |
|
597 | + } |
|
598 | + if (isset($ais_data['mmsi'])) { |
|
599 | + $data['mmsi'] = $ais_data['mmsi']; |
|
600 | + } |
|
601 | + if (isset($ais_data['speed'])) { |
|
602 | + $data['speed'] = $ais_data['speed']; |
|
603 | + } |
|
604 | + if (isset($ais_data['heading'])) { |
|
605 | + $data['heading'] = $ais_data['heading']; |
|
606 | + } |
|
607 | + if (isset($ais_data['latitude'])) { |
|
608 | + $data['latitude'] = $ais_data['latitude']; |
|
609 | + } |
|
610 | + if (isset($ais_data['longitude'])) { |
|
611 | + $data['longitude'] = $ais_data['longitude']; |
|
612 | + } |
|
613 | + if (isset($ais_data['status'])) { |
|
614 | + $data['status'] = $ais_data['status']; |
|
615 | + } |
|
616 | + if (isset($ais_data['type'])) { |
|
617 | + $data['type'] = $ais_data['type']; |
|
618 | + } |
|
619 | + if (isset($ais_data['imo'])) { |
|
620 | + $data['imo'] = $ais_data['imo']; |
|
621 | + } |
|
622 | + if (isset($ais_data['callsign'])) { |
|
623 | + $data['callsign'] = $ais_data['callsign']; |
|
624 | + } |
|
464 | 625 | if (isset($ais_data['timestamp'])) { |
465 | 626 | $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']); |
466 | 627 | } else { |
@@ -479,7 +640,9 @@ discard block |
||
479 | 640 | echo 'download...'; |
480 | 641 | $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter'); |
481 | 642 | echo 'done !'."\n"; |
482 | - if ($buffer != '') $reset = 0; |
|
643 | + if ($buffer != '') { |
|
644 | + $reset = 0; |
|
645 | + } |
|
483 | 646 | $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
484 | 647 | $buffer = explode('\n',$buffer); |
485 | 648 | foreach ($buffer as $line) { |
@@ -523,16 +686,28 @@ discard block |
||
523 | 686 | $line = explode(':', $line); |
524 | 687 | if (count($line) > 30 && $line[0] != 'callsign') { |
525 | 688 | $data = array(); |
526 | - if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37]; |
|
527 | - else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0]; |
|
689 | + if (isset($line[37]) && $line[37] != '') { |
|
690 | + $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37]; |
|
691 | + } else { |
|
692 | + $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0]; |
|
693 | + } |
|
528 | 694 | $data['pilot_id'] = $line[1]; |
529 | 695 | $data['pilot_name'] = $line[2]; |
530 | 696 | $data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT); |
531 | 697 | $data['ident'] = $line[0]; // ident |
532 | - if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude |
|
698 | + if ($line[7] != '' && $line[7] != 0) { |
|
699 | + $data['altitude'] = $line[7]; |
|
700 | + } |
|
701 | + // altitude |
|
533 | 702 | $data['speed'] = $line[8]; // speed |
534 | - if (isset($line[45])) $data['heading'] = $line[45]; // heading |
|
535 | - elseif (isset($line[38])) $data['heading'] = $line[38]; // heading |
|
703 | + if (isset($line[45])) { |
|
704 | + $data['heading'] = $line[45]; |
|
705 | + } |
|
706 | + // heading |
|
707 | + elseif (isset($line[38])) { |
|
708 | + $data['heading'] = $line[38]; |
|
709 | + } |
|
710 | + // heading |
|
536 | 711 | $data['latitude'] = $line[5]; // lat |
537 | 712 | $data['longitude'] = $line[6]; // long |
538 | 713 | $data['verticalrate'] = ''; // vertical rate |
@@ -548,7 +723,9 @@ discard block |
||
548 | 723 | $data['frequency'] = $line[4]; |
549 | 724 | $data['type'] = $line[18]; |
550 | 725 | $data['range'] = $line[19]; |
551 | - if (isset($line[35])) $data['info'] = $line[35]; |
|
726 | + if (isset($line[35])) { |
|
727 | + $data['info'] = $line[35]; |
|
728 | + } |
|
552 | 729 | $data['id_source'] = $id_source; |
553 | 730 | //$data['arrival_airport_time'] = ; |
554 | 731 | if ($line[9] != '') { |
@@ -562,24 +739,41 @@ discard block |
||
562 | 739 | elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt'; |
563 | 740 | */ |
564 | 741 | $data['format_source'] = $value['format']; |
565 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
566 | - if ($line[3] == 'PILOT') $SI->add($data); |
|
567 | - elseif ($line[3] == 'ATC') { |
|
742 | + if (isset($value['name']) && $value['name'] != '') { |
|
743 | + $data['source_name'] = $value['name']; |
|
744 | + } |
|
745 | + if ($line[3] == 'PILOT') { |
|
746 | + $SI->add($data); |
|
747 | + } elseif ($line[3] == 'ATC') { |
|
568 | 748 | //print_r($data); |
569 | 749 | $data['info'] = str_replace('^§','<br />',$data['info']); |
570 | 750 | $data['info'] = str_replace('&sect;','',$data['info']); |
571 | 751 | $typec = substr($data['ident'],-3); |
572 | - if ($typec == 'APP') $data['type'] = 'Approach'; |
|
573 | - elseif ($typec == 'TWR') $data['type'] = 'Tower'; |
|
574 | - elseif ($typec == 'OBS') $data['type'] = 'Observer'; |
|
575 | - elseif ($typec == 'GND') $data['type'] = 'Ground'; |
|
576 | - elseif ($typec == 'DEL') $data['type'] = 'Delivery'; |
|
577 | - elseif ($typec == 'DEP') $data['type'] = 'Departure'; |
|
578 | - elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station'; |
|
579 | - elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre'; |
|
580 | - elseif ($data['type'] == '') $data['type'] = 'Observer'; |
|
581 | - if (!isset($data['source_name'])) $data['source_name'] = ''; |
|
582 | - 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']); |
|
752 | + if ($typec == 'APP') { |
|
753 | + $data['type'] = 'Approach'; |
|
754 | + } elseif ($typec == 'TWR') { |
|
755 | + $data['type'] = 'Tower'; |
|
756 | + } elseif ($typec == 'OBS') { |
|
757 | + $data['type'] = 'Observer'; |
|
758 | + } elseif ($typec == 'GND') { |
|
759 | + $data['type'] = 'Ground'; |
|
760 | + } elseif ($typec == 'DEL') { |
|
761 | + $data['type'] = 'Delivery'; |
|
762 | + } elseif ($typec == 'DEP') { |
|
763 | + $data['type'] = 'Departure'; |
|
764 | + } elseif ($typec == 'FSS') { |
|
765 | + $data['type'] = 'Flight Service Station'; |
|
766 | + } elseif ($typec == 'CTR') { |
|
767 | + $data['type'] = 'Control Radar or Centre'; |
|
768 | + } elseif ($data['type'] == '') { |
|
769 | + $data['type'] = 'Observer'; |
|
770 | + } |
|
771 | + if (!isset($data['source_name'])) { |
|
772 | + $data['source_name'] = ''; |
|
773 | + } |
|
774 | + if (isset($ATC)) { |
|
775 | + 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']); |
|
776 | + } |
|
583 | 777 | } |
584 | 778 | unset($data); |
585 | 779 | } |
@@ -598,26 +792,55 @@ discard block |
||
598 | 792 | foreach ($all_data['acList'] as $line) { |
599 | 793 | $data = array(); |
600 | 794 | $data['hex'] = $line['Icao']; // hex |
601 | - if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident |
|
602 | - if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude |
|
603 | - if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed |
|
604 | - if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading |
|
605 | - if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat |
|
606 | - if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long |
|
795 | + if (isset($line['Call'])) { |
|
796 | + $data['ident'] = $line['Call']; |
|
797 | + } |
|
798 | + // ident |
|
799 | + if (isset($line['Alt'])) { |
|
800 | + $data['altitude'] = $line['Alt']; |
|
801 | + } |
|
802 | + // altitude |
|
803 | + if (isset($line['Spd'])) { |
|
804 | + $data['speed'] = $line['Spd']; |
|
805 | + } |
|
806 | + // speed |
|
807 | + if (isset($line['Trak'])) { |
|
808 | + $data['heading'] = $line['Trak']; |
|
809 | + } |
|
810 | + // heading |
|
811 | + if (isset($line['Lat'])) { |
|
812 | + $data['latitude'] = $line['Lat']; |
|
813 | + } |
|
814 | + // lat |
|
815 | + if (isset($line['Long'])) { |
|
816 | + $data['longitude'] = $line['Long']; |
|
817 | + } |
|
818 | + // long |
|
607 | 819 | //$data['verticalrate'] = $line['']; // verticale rate |
608 | - if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk |
|
820 | + if (isset($line['Sqk'])) { |
|
821 | + $data['squawk'] = $line['Sqk']; |
|
822 | + } |
|
823 | + // squawk |
|
609 | 824 | $data['emergency'] = ''; // emergency |
610 | - if (isset($line['Reg'])) $data['registration'] = $line['Reg']; |
|
825 | + if (isset($line['Reg'])) { |
|
826 | + $data['registration'] = $line['Reg']; |
|
827 | + } |
|
611 | 828 | /* |
612 | 829 | if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000); |
613 | 830 | else $data['datetime'] = date('Y-m-d H:i:s'); |
614 | 831 | */ |
615 | 832 | $data['datetime'] = date('Y-m-d H:i:s'); |
616 | - if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type']; |
|
833 | + if (isset($line['Type'])) { |
|
834 | + $data['aircraft_icao'] = $line['Type']; |
|
835 | + } |
|
617 | 836 | $data['format_source'] = 'aircraftlistjson'; |
618 | 837 | $data['id_source'] = $id_source; |
619 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
620 | - if (isset($data['datetime'])) $SI->add($data); |
|
838 | + if (isset($value['name']) && $value['name'] != '') { |
|
839 | + $data['source_name'] = $value['name']; |
|
840 | + } |
|
841 | + if (isset($data['datetime'])) { |
|
842 | + $SI->add($data); |
|
843 | + } |
|
621 | 844 | unset($data); |
622 | 845 | } |
623 | 846 | } else { |
@@ -637,7 +860,9 @@ discard block |
||
637 | 860 | $data['datetime'] = date('Y-m-d H:i:s'); |
638 | 861 | $data['format_source'] = 'aircraftlistjson'; |
639 | 862 | $data['id_source'] = $id_source; |
640 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
863 | + if (isset($value['name']) && $value['name'] != '') { |
|
864 | + $data['source_name'] = $value['name']; |
|
865 | + } |
|
641 | 866 | $SI->add($data); |
642 | 867 | unset($data); |
643 | 868 | } |
@@ -673,7 +898,9 @@ discard block |
||
673 | 898 | $data['datetime'] = date('Y-m-d H:i:s',$line[9]); |
674 | 899 | $data['format_source'] = 'planeupdatefaa'; |
675 | 900 | $data['id_source'] = $id_source; |
676 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
901 | + if (isset($value['name']) && $value['name'] != '') { |
|
902 | + $data['source_name'] = $value['name']; |
|
903 | + } |
|
677 | 904 | $SI->add($data); |
678 | 905 | unset($data); |
679 | 906 | } |
@@ -713,7 +940,9 @@ discard block |
||
713 | 940 | //$buffer = $Common->getData($hosts[$id]); |
714 | 941 | $buffer = $Common->getData($value['host']); |
715 | 942 | $all_data = json_decode($buffer,true); |
716 | - if (!empty($all_data)) $reset = 0; |
|
943 | + if (!empty($all_data)) { |
|
944 | + $reset = 0; |
|
945 | + } |
|
717 | 946 | foreach ($all_data as $key => $line) { |
718 | 947 | if ($key != 'full_count' && $key != 'version' && $key != 'stats') { |
719 | 948 | $data = array(); |
@@ -734,7 +963,9 @@ discard block |
||
734 | 963 | $data['datetime'] = date('Y-m-d H:i:s'); //$line[10] |
735 | 964 | $data['format_source'] = 'fr24json'; |
736 | 965 | $data['id_source'] = $id_source; |
737 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
966 | + if (isset($value['name']) && $value['name'] != '') { |
|
967 | + $data['source_name'] = $value['name']; |
|
968 | + } |
|
738 | 969 | $SI->add($data); |
739 | 970 | unset($data); |
740 | 971 | } |
@@ -758,23 +989,39 @@ discard block |
||
758 | 989 | if (isset($line['inf'])) { |
759 | 990 | $data = array(); |
760 | 991 | $data['hex'] = $line['inf']['ia']; |
761 | - if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13] |
|
992 | + if (isset($line['inf']['cs'])) { |
|
993 | + $data['ident'] = $line['inf']['cs']; |
|
994 | + } |
|
995 | + //$line[13] |
|
762 | 996 | $data['altitude'] = round($line['inf']['al']*3.28084); // altitude |
763 | - if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed |
|
764 | - if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading |
|
997 | + if (isset($line['inf']['gs'])) { |
|
998 | + $data['speed'] = round($line['inf']['gs']*0.539957); |
|
999 | + } |
|
1000 | + // speed |
|
1001 | + if (isset($line['inf']['tr'])) { |
|
1002 | + $data['heading'] = $line['inf']['tr']; |
|
1003 | + } |
|
1004 | + // heading |
|
765 | 1005 | $data['latitude'] = $line['pt'][0]; // lat |
766 | 1006 | $data['longitude'] = $line['pt'][1]; // long |
767 | 1007 | //if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate |
768 | - if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk |
|
1008 | + if (isset($line['inf']['sq'])) { |
|
1009 | + $data['squawk'] = $line['inf']['sq']; |
|
1010 | + } |
|
1011 | + // squawk |
|
769 | 1012 | //$data['aircraft_icao'] = $line[8]; |
770 | - if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc']; |
|
1013 | + if (isset($line['inf']['rc'])) { |
|
1014 | + $data['registration'] = $line['inf']['rc']; |
|
1015 | + } |
|
771 | 1016 | //$data['departure_airport_iata'] = $line[11]; |
772 | 1017 | //$data['arrival_airport_iata'] = $line[12]; |
773 | 1018 | //$data['emergency'] = ''; // emergency |
774 | 1019 | $data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10] |
775 | 1020 | $data['format_source'] = 'radarvirtueljson'; |
776 | 1021 | $data['id_source'] = $id_source; |
777 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1022 | + if (isset($value['name']) && $value['name'] != '') { |
|
1023 | + $data['source_name'] = $value['name']; |
|
1024 | + } |
|
778 | 1025 | $SI->add($data); |
779 | 1026 | unset($data); |
780 | 1027 | } |
@@ -795,29 +1042,62 @@ discard block |
||
795 | 1042 | $data['id'] = $line['id']; |
796 | 1043 | $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6); |
797 | 1044 | $data['ident'] = $line['callsign']; // ident |
798 | - if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id |
|
799 | - if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name |
|
800 | - if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude |
|
801 | - if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed |
|
802 | - if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading |
|
803 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
1045 | + if (isset($line['pilotid'])) { |
|
1046 | + $data['pilot_id'] = $line['pilotid']; |
|
1047 | + } |
|
1048 | + // pilot id |
|
1049 | + if (isset($line['name'])) { |
|
1050 | + $data['pilot_name'] = $line['name']; |
|
1051 | + } |
|
1052 | + // pilot name |
|
1053 | + if (isset($line['alt'])) { |
|
1054 | + $data['altitude'] = $line['alt']; |
|
1055 | + } |
|
1056 | + // altitude |
|
1057 | + if (isset($line['gs'])) { |
|
1058 | + $data['speed'] = $line['gs']; |
|
1059 | + } |
|
1060 | + // speed |
|
1061 | + if (isset($line['heading'])) { |
|
1062 | + $data['heading'] = $line['heading']; |
|
1063 | + } |
|
1064 | + // heading |
|
1065 | + if (isset($line['route'])) { |
|
1066 | + $data['waypoints'] = $line['route']; |
|
1067 | + } |
|
1068 | + // route |
|
804 | 1069 | $data['latitude'] = $line['lat']; // lat |
805 | 1070 | $data['longitude'] = $line['lon']; // long |
806 | 1071 | //$data['verticalrate'] = $line['vrt']; // verticale rate |
807 | 1072 | //$data['squawk'] = $line['squawk']; // squawk |
808 | 1073 | //$data['emergency'] = ''; // emergency |
809 | - if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao']; |
|
810 | - if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime']; |
|
811 | - if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao']; |
|
1074 | + if (isset($line['depicao'])) { |
|
1075 | + $data['departure_airport_icao'] = $line['depicao']; |
|
1076 | + } |
|
1077 | + if (isset($line['deptime'])) { |
|
1078 | + $data['departure_airport_time'] = $line['deptime']; |
|
1079 | + } |
|
1080 | + if (isset($line['arricao'])) { |
|
1081 | + $data['arrival_airport_icao'] = $line['arricao']; |
|
1082 | + } |
|
812 | 1083 | //$data['arrival_airport_time'] = $line['arrtime']; |
813 | - if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft']; |
|
814 | - if (isset($line['transponder'])) $data['squawk'] = $line['transponder']; |
|
815 | - if (isset($line['atis'])) $data['info'] = $line['atis']; |
|
816 | - else $data['info'] = ''; |
|
1084 | + if (isset($line['aircraft'])) { |
|
1085 | + $data['aircraft_icao'] = $line['aircraft']; |
|
1086 | + } |
|
1087 | + if (isset($line['transponder'])) { |
|
1088 | + $data['squawk'] = $line['transponder']; |
|
1089 | + } |
|
1090 | + if (isset($line['atis'])) { |
|
1091 | + $data['info'] = $line['atis']; |
|
1092 | + } else { |
|
1093 | + $data['info'] = ''; |
|
1094 | + } |
|
817 | 1095 | $data['format_source'] = 'pireps'; |
818 | 1096 | $data['id_source'] = $id_source; |
819 | 1097 | $data['datetime'] = date('Y-m-d H:i:s'); |
820 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1098 | + if (isset($value['name']) && $value['name'] != '') { |
|
1099 | + $data['source_name'] = $value['name']; |
|
1100 | + } |
|
821 | 1101 | if ($line['icon'] == 'plane') { |
822 | 1102 | $SI->add($data); |
823 | 1103 | // print_r($data); |
@@ -826,16 +1106,28 @@ discard block |
||
826 | 1106 | $data['info'] = str_replace('&sect;','',$data['info']); |
827 | 1107 | $typec = substr($data['ident'],-3); |
828 | 1108 | $data['type'] = ''; |
829 | - if ($typec == 'APP') $data['type'] = 'Approach'; |
|
830 | - elseif ($typec == 'TWR') $data['type'] = 'Tower'; |
|
831 | - elseif ($typec == 'OBS') $data['type'] = 'Observer'; |
|
832 | - elseif ($typec == 'GND') $data['type'] = 'Ground'; |
|
833 | - elseif ($typec == 'DEL') $data['type'] = 'Delivery'; |
|
834 | - elseif ($typec == 'DEP') $data['type'] = 'Departure'; |
|
835 | - elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station'; |
|
836 | - elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre'; |
|
837 | - else $data['type'] = 'Observer'; |
|
838 | - 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']); |
|
1109 | + if ($typec == 'APP') { |
|
1110 | + $data['type'] = 'Approach'; |
|
1111 | + } elseif ($typec == 'TWR') { |
|
1112 | + $data['type'] = 'Tower'; |
|
1113 | + } elseif ($typec == 'OBS') { |
|
1114 | + $data['type'] = 'Observer'; |
|
1115 | + } elseif ($typec == 'GND') { |
|
1116 | + $data['type'] = 'Ground'; |
|
1117 | + } elseif ($typec == 'DEL') { |
|
1118 | + $data['type'] = 'Delivery'; |
|
1119 | + } elseif ($typec == 'DEP') { |
|
1120 | + $data['type'] = 'Departure'; |
|
1121 | + } elseif ($typec == 'FSS') { |
|
1122 | + $data['type'] = 'Flight Service Station'; |
|
1123 | + } elseif ($typec == 'CTR') { |
|
1124 | + $data['type'] = 'Control Radar or Centre'; |
|
1125 | + } else { |
|
1126 | + $data['type'] = 'Observer'; |
|
1127 | + } |
|
1128 | + if (isset($ATC)) { |
|
1129 | + 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']); |
|
1130 | + } |
|
839 | 1131 | } |
840 | 1132 | unset($data); |
841 | 1133 | } |
@@ -845,7 +1137,9 @@ discard block |
||
845 | 1137 | //} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) { |
846 | 1138 | } elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
847 | 1139 | //$buffer = $Common->getData($hosts[$id]); |
848 | - if ($globalDebug) echo 'Get Data...'."\n"; |
|
1140 | + if ($globalDebug) { |
|
1141 | + echo 'Get Data...'."\n"; |
|
1142 | + } |
|
849 | 1143 | $buffer = $Common->getData($value['host']); |
850 | 1144 | $all_data = json_decode($buffer,true); |
851 | 1145 | if ($buffer != '' && is_array($all_data)) { |
@@ -853,10 +1147,16 @@ discard block |
||
853 | 1147 | foreach ($all_data as $line) { |
854 | 1148 | $data = array(); |
855 | 1149 | //$data['id'] = $line['id']; // id not usable |
856 | - if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum']; |
|
1150 | + if (isset($line['pilotid'])) { |
|
1151 | + $data['id'] = $line['pilotid'].$line['flightnum']; |
|
1152 | + } |
|
857 | 1153 | $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex |
858 | - if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname']; |
|
859 | - if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; |
|
1154 | + if (isset($line['pilotname'])) { |
|
1155 | + $data['pilot_name'] = $line['pilotname']; |
|
1156 | + } |
|
1157 | + if (isset($line['pilotid'])) { |
|
1158 | + $data['pilot_id'] = $line['pilotid']; |
|
1159 | + } |
|
860 | 1160 | $data['ident'] = $line['flightnum']; // ident |
861 | 1161 | $data['altitude'] = $line['alt']; // altitude |
862 | 1162 | $data['speed'] = $line['gs']; // speed |
@@ -874,27 +1174,41 @@ discard block |
||
874 | 1174 | $data['arrival_airport_icao'] = $line['arricao']; |
875 | 1175 | $data['arrival_airport_time'] = $line['arrtime']; |
876 | 1176 | $data['registration'] = $line['aircraft']; |
877 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
1177 | + if (isset($line['route'])) { |
|
1178 | + $data['waypoints'] = $line['route']; |
|
1179 | + } |
|
1180 | + // route |
|
878 | 1181 | if (isset($line['aircraftname'])) { |
879 | 1182 | $line['aircraftname'] = strtoupper($line['aircraftname']); |
880 | 1183 | $line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']); |
881 | 1184 | $aircraft_data = explode('-',$line['aircraftname']); |
882 | - if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0]; |
|
883 | - elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1]; |
|
884 | - else { |
|
1185 | + if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) { |
|
1186 | + $data['aircraft_icao'] = $aircraft_data[0]; |
|
1187 | + } elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) { |
|
1188 | + $data['aircraft_icao'] = $aircraft_data[1]; |
|
1189 | + } else { |
|
885 | 1190 | $aircraft_data = explode(' ',$line['aircraftname']); |
886 | - if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1]; |
|
887 | - else $data['aircraft_icao'] = $line['aircraftname']; |
|
1191 | + if (isset($aircraft_data[1])) { |
|
1192 | + $data['aircraft_icao'] = $aircraft_data[1]; |
|
1193 | + } else { |
|
1194 | + $data['aircraft_icao'] = $line['aircraftname']; |
|
1195 | + } |
|
888 | 1196 | } |
889 | 1197 | } |
890 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; |
|
1198 | + if (isset($line['route'])) { |
|
1199 | + $data['waypoints'] = $line['route']; |
|
1200 | + } |
|
891 | 1201 | $data['id_source'] = $id_source; |
892 | 1202 | $data['format_source'] = 'phpvmacars'; |
893 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1203 | + if (isset($value['name']) && $value['name'] != '') { |
|
1204 | + $data['source_name'] = $value['name']; |
|
1205 | + } |
|
894 | 1206 | $SI->add($data); |
895 | 1207 | unset($data); |
896 | 1208 | } |
897 | - if ($globalDebug) echo 'No more data...'."\n"; |
|
1209 | + if ($globalDebug) { |
|
1210 | + echo 'No more data...'."\n"; |
|
1211 | + } |
|
898 | 1212 | unset($buffer); |
899 | 1213 | unset($all_data); |
900 | 1214 | } |
@@ -902,7 +1216,9 @@ discard block |
||
902 | 1216 | $last_exec[$id]['last'] = time(); |
903 | 1217 | } elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { |
904 | 1218 | //$buffer = $Common->getData($hosts[$id]); |
905 | - if ($globalDebug) echo 'Get Data...'."\n"; |
|
1219 | + if ($globalDebug) { |
|
1220 | + echo 'Get Data...'."\n"; |
|
1221 | + } |
|
906 | 1222 | $buffer = $Common->getData($value['host']); |
907 | 1223 | $all_data = json_decode($buffer,true); |
908 | 1224 | if ($buffer != '' && is_array($all_data)) { |
@@ -931,15 +1247,22 @@ discard block |
||
931 | 1247 | $data['arrival_airport_icao'] = $line['arrival']; |
932 | 1248 | //$data['arrival_airport_time'] = $line['arrival_time']; |
933 | 1249 | //$data['registration'] = $line['aircraft']; |
934 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
1250 | + if (isset($line['route'])) { |
|
1251 | + $data['waypoints'] = $line['route']; |
|
1252 | + } |
|
1253 | + // route |
|
935 | 1254 | $data['aircraft_icao'] = $line['plane_type']; |
936 | 1255 | $data['id_source'] = $id_source; |
937 | 1256 | $data['format_source'] = 'vam'; |
938 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1257 | + if (isset($value['name']) && $value['name'] != '') { |
|
1258 | + $data['source_name'] = $value['name']; |
|
1259 | + } |
|
939 | 1260 | $SI->add($data); |
940 | 1261 | unset($data); |
941 | 1262 | } |
942 | - if ($globalDebug) echo 'No more data...'."\n"; |
|
1263 | + if ($globalDebug) { |
|
1264 | + echo 'No more data...'."\n"; |
|
1265 | + } |
|
943 | 1266 | unset($buffer); |
944 | 1267 | unset($all_data); |
945 | 1268 | } |
@@ -947,7 +1270,9 @@ discard block |
||
947 | 1270 | $last_exec[$id]['last'] = time(); |
948 | 1271 | //} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') { |
949 | 1272 | } 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') { |
950 | - if (function_exists('pcntl_fork')) pcntl_signal_dispatch(); |
|
1273 | + if (function_exists('pcntl_fork')) { |
|
1274 | + pcntl_signal_dispatch(); |
|
1275 | + } |
|
951 | 1276 | //$last_exec[$id]['last'] = time(); |
952 | 1277 | |
953 | 1278 | //$read = array( $sockets[$id] ); |
@@ -955,7 +1280,9 @@ discard block |
||
955 | 1280 | $write = NULL; |
956 | 1281 | $e = NULL; |
957 | 1282 | $n = socket_select($read, $write, $e, $timeout); |
958 | - if ($e != NULL) var_dump($e); |
|
1283 | + if ($e != NULL) { |
|
1284 | + var_dump($e); |
|
1285 | + } |
|
959 | 1286 | if ($n > 0) { |
960 | 1287 | $reset = 0; |
961 | 1288 | foreach ($read as $nb => $r) { |
@@ -977,7 +1304,9 @@ discard block |
||
977 | 1304 | if ($buffer != '') { |
978 | 1305 | $tt[$format] = 0; |
979 | 1306 | if ($format == 'acarssbs3') { |
980 | - if ($globalDebug) echo 'ACARS : '.$buffer."\n"; |
|
1307 | + if ($globalDebug) { |
|
1308 | + echo 'ACARS : '.$buffer."\n"; |
|
1309 | + } |
|
981 | 1310 | $ACARS->add(trim($buffer)); |
982 | 1311 | $ACARS->deleteLiveAcarsData(); |
983 | 1312 | } elseif ($format == 'raw') { |
@@ -986,23 +1315,49 @@ discard block |
||
986 | 1315 | if (is_array($data)) { |
987 | 1316 | $data['datetime'] = date('Y-m-d H:i:s'); |
988 | 1317 | $data['format_source'] = 'raw'; |
989 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
990 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
991 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
1318 | + if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') { |
|
1319 | + $data['source_name'] = $globalSources[$nb]['name']; |
|
1320 | + } |
|
1321 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
1322 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1323 | + } |
|
1324 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
1325 | + $SI->add($data); |
|
1326 | + } |
|
992 | 1327 | } |
993 | 1328 | } elseif ($format == 'ais') { |
994 | 1329 | $ais_data = $AIS->parse_line(trim($buffer)); |
995 | 1330 | $data = array(); |
996 | - if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident']; |
|
997 | - if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi']; |
|
998 | - if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed']; |
|
999 | - if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading']; |
|
1000 | - if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude']; |
|
1001 | - if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude']; |
|
1002 | - if (isset($ais_data['status'])) $data['status'] = $ais_data['status']; |
|
1003 | - if (isset($ais_data['type'])) $data['type'] = $ais_data['type']; |
|
1004 | - if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo']; |
|
1005 | - if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign']; |
|
1331 | + if (isset($ais_data['ident'])) { |
|
1332 | + $data['ident'] = $ais_data['ident']; |
|
1333 | + } |
|
1334 | + if (isset($ais_data['mmsi'])) { |
|
1335 | + $data['mmsi'] = $ais_data['mmsi']; |
|
1336 | + } |
|
1337 | + if (isset($ais_data['speed'])) { |
|
1338 | + $data['speed'] = $ais_data['speed']; |
|
1339 | + } |
|
1340 | + if (isset($ais_data['heading'])) { |
|
1341 | + $data['heading'] = $ais_data['heading']; |
|
1342 | + } |
|
1343 | + if (isset($ais_data['latitude'])) { |
|
1344 | + $data['latitude'] = $ais_data['latitude']; |
|
1345 | + } |
|
1346 | + if (isset($ais_data['longitude'])) { |
|
1347 | + $data['longitude'] = $ais_data['longitude']; |
|
1348 | + } |
|
1349 | + if (isset($ais_data['status'])) { |
|
1350 | + $data['status'] = $ais_data['status']; |
|
1351 | + } |
|
1352 | + if (isset($ais_data['type'])) { |
|
1353 | + $data['type'] = $ais_data['type']; |
|
1354 | + } |
|
1355 | + if (isset($ais_data['imo'])) { |
|
1356 | + $data['imo'] = $ais_data['imo']; |
|
1357 | + } |
|
1358 | + if (isset($ais_data['callsign'])) { |
|
1359 | + $data['callsign'] = $ais_data['callsign']; |
|
1360 | + } |
|
1006 | 1361 | |
1007 | 1362 | if (isset($ais_data['timestamp'])) { |
1008 | 1363 | $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']); |
@@ -1029,11 +1384,15 @@ discard block |
||
1029 | 1384 | $data['speed'] = round($line[5]*1.94384); |
1030 | 1385 | $data['datetime'] = date('Y-m-d H:i:s'); |
1031 | 1386 | $data['format_source'] = 'flightgearsp'; |
1032 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
1387 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
1388 | + $SI->add($data); |
|
1389 | + } |
|
1033 | 1390 | $send = @ socket_send( $r , $data_aprs , strlen($data_aprs) , 0 ); |
1034 | 1391 | } |
1035 | 1392 | } elseif ($format == 'acars') { |
1036 | - if ($globalDebug) echo 'ACARS : '.$buffer."\n"; |
|
1393 | + if ($globalDebug) { |
|
1394 | + echo 'ACARS : '.$buffer."\n"; |
|
1395 | + } |
|
1037 | 1396 | $ACARS->add(trim($buffer)); |
1038 | 1397 | socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port); |
1039 | 1398 | $ACARS->deleteLiveAcarsData(); |
@@ -1054,7 +1413,9 @@ discard block |
||
1054 | 1413 | $aircraft_type = $line[10]; |
1055 | 1414 | $aircraft_type = preg_split(':/:',$aircraft_type); |
1056 | 1415 | $data['aircraft_name'] = substr(end($aircraft_type),0,-4); |
1057 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
1416 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
1417 | + $SI->add($data); |
|
1418 | + } |
|
1058 | 1419 | } |
1059 | 1420 | } |
1060 | 1421 | } elseif ($format == 'beast') { |
@@ -1070,21 +1431,43 @@ discard block |
||
1070 | 1431 | $data['hex'] = $lined['hexid']; |
1071 | 1432 | //$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));; |
1072 | 1433 | $data['datetime'] = date('Y-m-d H:i:s');; |
1073 | - if (isset($lined['ident'])) $data['ident'] = $lined['ident']; |
|
1074 | - if (isset($lined['lat'])) $data['latitude'] = $lined['lat']; |
|
1075 | - if (isset($lined['lon'])) $data['longitude'] = $lined['lon']; |
|
1076 | - if (isset($lined['speed'])) $data['speed'] = $lined['speed']; |
|
1077 | - if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk']; |
|
1078 | - if (isset($lined['alt'])) $data['altitude'] = $lined['alt']; |
|
1079 | - if (isset($lined['heading'])) $data['heading'] = $lined['heading']; |
|
1434 | + if (isset($lined['ident'])) { |
|
1435 | + $data['ident'] = $lined['ident']; |
|
1436 | + } |
|
1437 | + if (isset($lined['lat'])) { |
|
1438 | + $data['latitude'] = $lined['lat']; |
|
1439 | + } |
|
1440 | + if (isset($lined['lon'])) { |
|
1441 | + $data['longitude'] = $lined['lon']; |
|
1442 | + } |
|
1443 | + if (isset($lined['speed'])) { |
|
1444 | + $data['speed'] = $lined['speed']; |
|
1445 | + } |
|
1446 | + if (isset($lined['squawk'])) { |
|
1447 | + $data['squawk'] = $lined['squawk']; |
|
1448 | + } |
|
1449 | + if (isset($lined['alt'])) { |
|
1450 | + $data['altitude'] = $lined['alt']; |
|
1451 | + } |
|
1452 | + if (isset($lined['heading'])) { |
|
1453 | + $data['heading'] = $lined['heading']; |
|
1454 | + } |
|
1080 | 1455 | $data['id_source'] = $id_source; |
1081 | 1456 | $data['format_source'] = 'tsv'; |
1082 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
1083 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1084 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
1457 | + if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') { |
|
1458 | + $data['source_name'] = $globalSources[$nb]['name']; |
|
1459 | + } |
|
1460 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
1461 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1462 | + } |
|
1463 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
1464 | + $SI->add($data); |
|
1465 | + } |
|
1085 | 1466 | unset($lined); |
1086 | 1467 | unset($data); |
1087 | - } else $error = true; |
|
1468 | + } else { |
|
1469 | + $error = true; |
|
1470 | + } |
|
1088 | 1471 | } elseif ($format == 'aprs' && $use_aprs) { |
1089 | 1472 | if ($aprs_connect == 0) { |
1090 | 1473 | $send = @ socket_send( $r , $aprs_login , strlen($aprs_login) , 0 ); |
@@ -1109,47 +1492,72 @@ discard block |
||
1109 | 1492 | $aprs_last_tx = time(); |
1110 | 1493 | $data = array(); |
1111 | 1494 | //print_r($line); |
1112 | - if (isset($line['address'])) $data['hex'] = $line['address']; |
|
1113 | - if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']); |
|
1114 | - else $data['datetime'] = date('Y-m-d H:i:s'); |
|
1495 | + if (isset($line['address'])) { |
|
1496 | + $data['hex'] = $line['address']; |
|
1497 | + } |
|
1498 | + if (isset($line['timestamp'])) { |
|
1499 | + $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']); |
|
1500 | + } else { |
|
1501 | + $data['datetime'] = date('Y-m-d H:i:s'); |
|
1502 | + } |
|
1115 | 1503 | //$data['datetime'] = date('Y-m-d H:i:s'); |
1116 | 1504 | $data['ident'] = $line['ident']; |
1117 | 1505 | $data['latitude'] = $line['latitude']; |
1118 | 1506 | $data['longitude'] = $line['longitude']; |
1119 | 1507 | //$data['verticalrate'] = $line[16]; |
1120 | - if (isset($line['speed'])) $data['speed'] = $line['speed']; |
|
1121 | - else $data['speed'] = 0; |
|
1122 | - if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; |
|
1123 | - if (isset($line['comment'])) $data['comment'] = $line['comment']; |
|
1124 | - if (isset($line['symbol'])) $data['type'] = $line['symbol']; |
|
1125 | - if (isset($line['heading'])) $data['heading'] = $line['heading']; |
|
1508 | + if (isset($line['speed'])) { |
|
1509 | + $data['speed'] = $line['speed']; |
|
1510 | + } else { |
|
1511 | + $data['speed'] = 0; |
|
1512 | + } |
|
1513 | + if (isset($line['altitude'])) { |
|
1514 | + $data['altitude'] = $line['altitude']; |
|
1515 | + } |
|
1516 | + if (isset($line['comment'])) { |
|
1517 | + $data['comment'] = $line['comment']; |
|
1518 | + } |
|
1519 | + if (isset($line['symbol'])) { |
|
1520 | + $data['type'] = $line['symbol']; |
|
1521 | + } |
|
1522 | + if (isset($line['heading'])) { |
|
1523 | + $data['heading'] = $line['heading']; |
|
1524 | + } |
|
1126 | 1525 | //else $data['heading'] = 0; |
1127 | - if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth']; |
|
1128 | - if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true; |
|
1526 | + if (isset($line['stealth'])) { |
|
1527 | + $data['aircraft_type'] = $line['stealth']; |
|
1528 | + } |
|
1529 | + if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) { |
|
1530 | + $data['noarchive'] = true; |
|
1531 | + } |
|
1129 | 1532 | $data['id_source'] = $id_source; |
1130 | 1533 | $data['format_source'] = 'aprs'; |
1131 | 1534 | $data['source_name'] = $line['source']; |
1132 | 1535 | $data['source_type'] = 'flarm'; |
1133 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1536 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
1537 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1538 | + } |
|
1134 | 1539 | $currentdate = date('Y-m-d H:i:s'); |
1135 | 1540 | $aprsdate = strtotime($data['datetime']); |
1136 | 1541 | // Accept data if time <= system time + 20s |
1137 | 1542 | if (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'])))) { |
1138 | 1543 | $send = $SI->add($data); |
1139 | 1544 | } elseif (isset($line['stealth'])) { |
1140 | - if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n"; |
|
1141 | - else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n"; |
|
1545 | + if ($line['stealth'] != 0) { |
|
1546 | + echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n"; |
|
1547 | + } else { |
|
1548 | + echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n"; |
|
1549 | + } |
|
1142 | 1550 | //} 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')) { |
1143 | 1551 | } 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') { |
1144 | 1552 | //echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n"; |
1145 | - if (isset($globalTracker) && $globalTracker) $send = $TI->add($data); |
|
1553 | + if (isset($globalTracker) && $globalTracker) { |
|
1554 | + $send = $TI->add($data); |
|
1555 | + } |
|
1146 | 1556 | } |
1147 | 1557 | unset($data); |
1148 | - } |
|
1149 | - elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') { |
|
1558 | + } elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') { |
|
1150 | 1559 | echo '!! Weather Station not yet supported'."\n"; |
1151 | - } |
|
1152 | - 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')) { |
|
1560 | + } 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')) { |
|
1153 | 1561 | echo '!! Car & Trucks not yet supported'."\n"; |
1154 | 1562 | } |
1155 | 1563 | //elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n"; |
@@ -1182,25 +1590,42 @@ discard block |
||
1182 | 1590 | $data['ground'] = $line[21]; |
1183 | 1591 | $data['emergency'] = $line[19]; |
1184 | 1592 | $data['format_source'] = 'sbs'; |
1185 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
1186 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1593 | + if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') { |
|
1594 | + $data['source_name'] = $globalSources[$nb]['name']; |
|
1595 | + } |
|
1596 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
1597 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1598 | + } |
|
1187 | 1599 | $data['id_source'] = $id_source; |
1188 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data); |
|
1189 | - else $error = true; |
|
1600 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
1601 | + $send = $SI->add($data); |
|
1602 | + } else { |
|
1603 | + $error = true; |
|
1604 | + } |
|
1190 | 1605 | unset($data); |
1191 | - } else $error = true; |
|
1606 | + } else { |
|
1607 | + $error = true; |
|
1608 | + } |
|
1192 | 1609 | if ($error) { |
1193 | 1610 | if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { |
1194 | - if ($globalDebug) echo "Not a message. Ignoring... \n"; |
|
1611 | + if ($globalDebug) { |
|
1612 | + echo "Not a message. Ignoring... \n"; |
|
1613 | + } |
|
1195 | 1614 | } else { |
1196 | - if ($globalDebug) echo "Wrong line format. Ignoring... \n"; |
|
1615 | + if ($globalDebug) { |
|
1616 | + echo "Wrong line format. Ignoring... \n"; |
|
1617 | + } |
|
1197 | 1618 | if ($globalDebug) { |
1198 | 1619 | echo $buffer; |
1199 | 1620 | print_r($line); |
1200 | 1621 | } |
1201 | 1622 | //socket_close($r); |
1202 | - if ($globalDebug) echo "Reconnect after an error...\n"; |
|
1203 | - if ($format == 'aprs') $aprs_connect = 0; |
|
1623 | + if ($globalDebug) { |
|
1624 | + echo "Reconnect after an error...\n"; |
|
1625 | + } |
|
1626 | + if ($format == 'aprs') { |
|
1627 | + $aprs_connect = 0; |
|
1628 | + } |
|
1204 | 1629 | $sourceer[$nb] = $globalSources[$nb]; |
1205 | 1630 | connect_all($sourceer); |
1206 | 1631 | $sourceer = array(); |
@@ -1208,10 +1633,14 @@ discard block |
||
1208 | 1633 | } |
1209 | 1634 | } |
1210 | 1635 | // Sleep for xxx microseconds |
1211 | - if (isset($globalSBSSleep)) usleep($globalSBSSleep); |
|
1636 | + if (isset($globalSBSSleep)) { |
|
1637 | + usleep($globalSBSSleep); |
|
1638 | + } |
|
1212 | 1639 | } else { |
1213 | 1640 | if ($format == 'flightgearmp') { |
1214 | - if ($globalDebug) echo "Reconnect FlightGear MP..."; |
|
1641 | + if ($globalDebug) { |
|
1642 | + echo "Reconnect FlightGear MP..."; |
|
1643 | + } |
|
1215 | 1644 | //@socket_close($r); |
1216 | 1645 | sleep($globalMinFetch); |
1217 | 1646 | $sourcefg[$nb] = $globalSources[$nb]; |
@@ -1220,10 +1649,15 @@ discard block |
||
1220 | 1649 | break; |
1221 | 1650 | |
1222 | 1651 | } elseif ($format != 'acars' && $format != 'flightgearsp') { |
1223 | - if (isset($tt[$format])) $tt[$format]++; |
|
1224 | - else $tt[$format] = 0; |
|
1652 | + if (isset($tt[$format])) { |
|
1653 | + $tt[$format]++; |
|
1654 | + } else { |
|
1655 | + $tt[$format] = 0; |
|
1656 | + } |
|
1225 | 1657 | if ($tt[$format] > 30) { |
1226 | - if ($globalDebug) echo "ERROR : Reconnect ".$format."..."; |
|
1658 | + if ($globalDebug) { |
|
1659 | + echo "ERROR : Reconnect ".$format."..."; |
|
1660 | + } |
|
1227 | 1661 | //@socket_close($r); |
1228 | 1662 | sleep(2); |
1229 | 1663 | $aprs_connect = 0; |
@@ -1240,11 +1674,17 @@ discard block |
||
1240 | 1674 | } else { |
1241 | 1675 | $error = socket_strerror(socket_last_error()); |
1242 | 1676 | if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) { |
1243 | - if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n"; |
|
1244 | - if (isset($globalDebug)) echo "Restarting...\n"; |
|
1677 | + if ($globalDebug) { |
|
1678 | + echo "ERROR : socket_select give this error ".$error . "\n"; |
|
1679 | + } |
|
1680 | + if (isset($globalDebug)) { |
|
1681 | + echo "Restarting...\n"; |
|
1682 | + } |
|
1245 | 1683 | // Restart the script if possible |
1246 | 1684 | if (is_array($sockets)) { |
1247 | - if ($globalDebug) echo "Shutdown all sockets..."; |
|
1685 | + if ($globalDebug) { |
|
1686 | + echo "Shutdown all sockets..."; |
|
1687 | + } |
|
1248 | 1688 | |
1249 | 1689 | foreach ($sockets as $sock) { |
1250 | 1690 | @socket_shutdown($sock,2); |
@@ -1252,18 +1692,24 @@ discard block |
||
1252 | 1692 | } |
1253 | 1693 | |
1254 | 1694 | } |
1255 | - if ($globalDebug) echo "Restart all connections..."; |
|
1695 | + if ($globalDebug) { |
|
1696 | + echo "Restart all connections..."; |
|
1697 | + } |
|
1256 | 1698 | sleep(2); |
1257 | 1699 | $time = time(); |
1258 | 1700 | //connect_all($hosts); |
1259 | 1701 | $aprs_connect = 0; |
1260 | - if ($reset > 40) exit('Too many attempts...'); |
|
1702 | + if ($reset > 40) { |
|
1703 | + exit('Too many attempts...'); |
|
1704 | + } |
|
1261 | 1705 | connect_all($globalSources); |
1262 | 1706 | } |
1263 | 1707 | } |
1264 | 1708 | } |
1265 | 1709 | if ($globalDaemon === false) { |
1266 | - if ($globalDebug) echo 'Check all...'."\n"; |
|
1710 | + if ($globalDebug) { |
|
1711 | + echo 'Check all...'."\n"; |
|
1712 | + } |
|
1267 | 1713 | $SI->checkAll(); |
1268 | 1714 | } |
1269 | 1715 | } |
@@ -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 |
@@ -661,8 +703,12 @@ discard block |
||
661 | 703 | $latitude = 0; |
662 | 704 | $longitude = 0; |
663 | 705 | } |
664 | - if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0; |
|
665 | - if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0; |
|
706 | + if ($heading == '' || $Common->isInteger($heading) === false) { |
|
707 | + $heading = 0; |
|
708 | + } |
|
709 | + if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) { |
|
710 | + $groundspeed = 0; |
|
711 | + } |
|
666 | 712 | $query = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo) |
667 | 713 | VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:speed,:date,:format_source, :source_name,:mmsi,:type,:status,:imo)"; |
668 | 714 | |
@@ -827,12 +873,18 @@ discard block |
||
827 | 873 | $query = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count |
828 | 874 | FROM marine_output".$filter_query." marine_output.ident <> ''"; |
829 | 875 | if ($olderthanmonths > 0) { |
830 | - if ($globalDBdriver == 'mysql') $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)'; |
|
831 | - else $query .= " AND marine_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
|
876 | + if ($globalDBdriver == 'mysql') { |
|
877 | + $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)'; |
|
878 | + } else { |
|
879 | + $query .= " AND marine_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; |
|
880 | + } |
|
832 | 881 | } |
833 | 882 | if ($sincedate != '') { |
834 | - if ($globalDBdriver == 'mysql') $query .= " AND marine_output.date > '".$sincedate."'"; |
|
835 | - else $query .= " AND marine_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
|
883 | + if ($globalDBdriver == 'mysql') { |
|
884 | + $query .= " AND marine_output.date > '".$sincedate."'"; |
|
885 | + } else { |
|
886 | + $query .= " AND marine_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; |
|
887 | + } |
|
836 | 888 | } |
837 | 889 | $query_values = array(); |
838 | 890 | if ($year != '') { |
@@ -863,7 +915,9 @@ discard block |
||
863 | 915 | } |
864 | 916 | } |
865 | 917 | $query .= " GROUP BY marine_output.ident ORDER BY callsign_icao_count DESC"; |
866 | - if ($limit) $query .= " LIMIT 10 OFFSET 0"; |
|
918 | + if ($limit) { |
|
919 | + $query .= " LIMIT 10 OFFSET 0"; |
|
920 | + } |
|
867 | 921 | |
868 | 922 | $sth = $this->db->prepare($query); |
869 | 923 | $sth->execute($query_values); |
@@ -898,7 +952,9 @@ discard block |
||
898 | 952 | date_default_timezone_set($globalTimezone); |
899 | 953 | $datetime = new DateTime(); |
900 | 954 | $offset = $datetime->format('P'); |
901 | - } else $offset = '+00:00'; |
|
955 | + } else { |
|
956 | + $offset = '+00:00'; |
|
957 | + } |
|
902 | 958 | |
903 | 959 | if ($globalDBdriver == 'mysql') { |
904 | 960 | $query = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count |
@@ -948,7 +1004,9 @@ discard block |
||
948 | 1004 | date_default_timezone_set($globalTimezone); |
949 | 1005 | $datetime = new DateTime(); |
950 | 1006 | $offset = $datetime->format('P'); |
951 | - } else $offset = '+00:00'; |
|
1007 | + } else { |
|
1008 | + $offset = '+00:00'; |
|
1009 | + } |
|
952 | 1010 | $filter_query = $this->getFilter($filters,true,true); |
953 | 1011 | if ($globalDBdriver == 'mysql') { |
954 | 1012 | $query = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count |
@@ -994,7 +1052,9 @@ discard block |
||
994 | 1052 | date_default_timezone_set($globalTimezone); |
995 | 1053 | $datetime = new DateTime(); |
996 | 1054 | $offset = $datetime->format('P'); |
997 | - } else $offset = '+00:00'; |
|
1055 | + } else { |
|
1056 | + $offset = '+00:00'; |
|
1057 | + } |
|
998 | 1058 | $filter_query = $this->getFilter($filters,true,true); |
999 | 1059 | if ($globalDBdriver == 'mysql') { |
1000 | 1060 | $query = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count |
@@ -1042,7 +1102,9 @@ discard block |
||
1042 | 1102 | date_default_timezone_set($globalTimezone); |
1043 | 1103 | $datetime = new DateTime(); |
1044 | 1104 | $offset = $datetime->format('P'); |
1045 | - } else $offset = '+00:00'; |
|
1105 | + } else { |
|
1106 | + $offset = '+00:00'; |
|
1107 | + } |
|
1046 | 1108 | |
1047 | 1109 | if ($globalDBdriver == 'mysql') { |
1048 | 1110 | $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 |
@@ -1091,7 +1153,9 @@ discard block |
||
1091 | 1153 | date_default_timezone_set($globalTimezone); |
1092 | 1154 | $datetime = new DateTime(); |
1093 | 1155 | $offset = $datetime->format('P'); |
1094 | - } else $offset = '+00:00'; |
|
1156 | + } else { |
|
1157 | + $offset = '+00:00'; |
|
1158 | + } |
|
1095 | 1159 | $filter_query = $this->getFilter($filters,true,true); |
1096 | 1160 | if ($globalDBdriver == 'mysql') { |
1097 | 1161 | $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 |
@@ -1140,7 +1204,9 @@ discard block |
||
1140 | 1204 | date_default_timezone_set($globalTimezone); |
1141 | 1205 | $datetime = new DateTime(); |
1142 | 1206 | $offset = $datetime->format('P'); |
1143 | - } else $offset = '+00:00'; |
|
1207 | + } else { |
|
1208 | + $offset = '+00:00'; |
|
1209 | + } |
|
1144 | 1210 | |
1145 | 1211 | $orderby_sql = ''; |
1146 | 1212 | if ($orderby == "hour") |
@@ -1209,7 +1275,9 @@ discard block |
||
1209 | 1275 | date_default_timezone_set($globalTimezone); |
1210 | 1276 | $datetime = new DateTime($date); |
1211 | 1277 | $offset = $datetime->format('P'); |
1212 | - } else $offset = '+00:00'; |
|
1278 | + } else { |
|
1279 | + $offset = '+00:00'; |
|
1280 | + } |
|
1213 | 1281 | |
1214 | 1282 | if ($globalDBdriver == 'mysql') { |
1215 | 1283 | $query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
@@ -1257,7 +1325,9 @@ discard block |
||
1257 | 1325 | date_default_timezone_set($globalTimezone); |
1258 | 1326 | $datetime = new DateTime(); |
1259 | 1327 | $offset = $datetime->format('P'); |
1260 | - } else $offset = '+00:00'; |
|
1328 | + } else { |
|
1329 | + $offset = '+00:00'; |
|
1330 | + } |
|
1261 | 1331 | |
1262 | 1332 | if ($globalDBdriver == 'mysql') { |
1263 | 1333 | $query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
@@ -1321,8 +1391,11 @@ discard block |
||
1321 | 1391 | $query_values = array_merge($query_values,array(':month' => $month)); |
1322 | 1392 | } |
1323 | 1393 | } |
1324 | - if (empty($query_values)) $queryi .= $this->getFilter($filters); |
|
1325 | - else $queryi .= $this->getFilter($filters,true,true).substr($query,4); |
|
1394 | + if (empty($query_values)) { |
|
1395 | + $queryi .= $this->getFilter($filters); |
|
1396 | + } else { |
|
1397 | + $queryi .= $this->getFilter($filters,true,true).substr($query,4); |
|
1398 | + } |
|
1326 | 1399 | |
1327 | 1400 | $sth = $this->db->prepare($queryi); |
1328 | 1401 | $sth->execute($query_values); |
@@ -1344,7 +1417,9 @@ discard block |
||
1344 | 1417 | date_default_timezone_set($globalTimezone); |
1345 | 1418 | $datetime = new DateTime(); |
1346 | 1419 | $offset = $datetime->format('P'); |
1347 | - } else $offset = '+00:00'; |
|
1420 | + } else { |
|
1421 | + $offset = '+00:00'; |
|
1422 | + } |
|
1348 | 1423 | |
1349 | 1424 | if ($globalDBdriver == 'mysql') { |
1350 | 1425 | $query = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count |
@@ -1448,7 +1523,9 @@ discard block |
||
1448 | 1523 | */ |
1449 | 1524 | public function parseDirection($direction = 0) |
1450 | 1525 | { |
1451 | - if ($direction == '') $direction = 0; |
|
1526 | + if ($direction == '') { |
|
1527 | + $direction = 0; |
|
1528 | + } |
|
1452 | 1529 | $direction_array = array(); |
1453 | 1530 | $temp_array = array(); |
1454 | 1531 | |
@@ -1537,7 +1614,9 @@ discard block |
||
1537 | 1614 | $longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); |
1538 | 1615 | |
1539 | 1616 | $Connection = new Connection($this->db); |
1540 | - if (!$Connection->tableExists('countries')) return ''; |
|
1617 | + if (!$Connection->tableExists('countries')) { |
|
1618 | + return ''; |
|
1619 | + } |
|
1541 | 1620 | |
1542 | 1621 | try { |
1543 | 1622 | /* |
@@ -1557,9 +1636,13 @@ discard block |
||
1557 | 1636 | $sth->closeCursor(); |
1558 | 1637 | if (count($row) > 0) { |
1559 | 1638 | return $row; |
1560 | - } else return ''; |
|
1639 | + } else { |
|
1640 | + return ''; |
|
1641 | + } |
|
1561 | 1642 | } catch (PDOException $e) { |
1562 | - if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n"; |
|
1643 | + if (isset($globalDebug) && $globalDebug) { |
|
1644 | + echo 'Error : '.$e->getMessage()."\n"; |
|
1645 | + } |
|
1563 | 1646 | return ''; |
1564 | 1647 | } |
1565 | 1648 | |
@@ -1577,7 +1660,9 @@ discard block |
||
1577 | 1660 | $iso2 = filter_var($iso2,FILTER_SANITIZE_STRING); |
1578 | 1661 | |
1579 | 1662 | $Connection = new Connection($this->db); |
1580 | - if (!$Connection->tableExists('countries')) return ''; |
|
1663 | + if (!$Connection->tableExists('countries')) { |
|
1664 | + return ''; |
|
1665 | + } |
|
1581 | 1666 | |
1582 | 1667 | try { |
1583 | 1668 | $query = "SELECT name,iso2,iso3 FROM countries WHERE iso2 = :iso2 LIMIT 1"; |
@@ -1589,9 +1674,13 @@ discard block |
||
1589 | 1674 | $sth->closeCursor(); |
1590 | 1675 | if (count($row) > 0) { |
1591 | 1676 | return $row; |
1592 | - } else return ''; |
|
1677 | + } else { |
|
1678 | + return ''; |
|
1679 | + } |
|
1593 | 1680 | } catch (PDOException $e) { |
1594 | - if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n"; |
|
1681 | + if (isset($globalDebug) && $globalDebug) { |
|
1682 | + echo 'Error : '.$e->getMessage()."\n"; |
|
1683 | + } |
|
1595 | 1684 | return ''; |
1596 | 1685 | } |
1597 | 1686 | |
@@ -1609,7 +1698,9 @@ discard block |
||
1609 | 1698 | { |
1610 | 1699 | global $globalBitlyAccessToken; |
1611 | 1700 | |
1612 | - if ($globalBitlyAccessToken == '') return $url; |
|
1701 | + if ($globalBitlyAccessToken == '') { |
|
1702 | + return $url; |
|
1703 | + } |
|
1613 | 1704 | |
1614 | 1705 | $google_url = 'https://api-ssl.bitly.com/v3/shorten?access_token='.$globalBitlyAccessToken.'&longUrl='.$url; |
1615 | 1706 |
@@ -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); |
@@ -835,8 +868,12 @@ discard block |
||
835 | 868 | $imo = filter_var($imo,FILTER_SANITIZE_STRING); |
836 | 869 | $callsign = filter_var($callsign,FILTER_SANITIZE_STRING); |
837 | 870 | |
838 | - if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0; |
|
839 | - if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0; |
|
871 | + if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) { |
|
872 | + $groundspeed = 0; |
|
873 | + } |
|
874 | + if ($heading == '' || $Common->isInteger($heading) === false ) { |
|
875 | + $heading = 0; |
|
876 | + } |
|
840 | 877 | |
841 | 878 | $query = 'INSERT INTO marine_live (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, over_country, mmsi, type,status,imo) |
842 | 879 | VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:groundspeed,:date,:format_source, :source_name, :over_country,:mmsi,:type,:status,:imo)'; |
@@ -44,7 +44,9 @@ discard block |
||
44 | 44 | |
45 | 45 | public function checkAll() { |
46 | 46 | global $globalDebug; |
47 | - if ($globalDebug) echo "Update last seen tracked data...\n"; |
|
47 | + if ($globalDebug) { |
|
48 | + echo "Update last seen tracked data...\n"; |
|
49 | + } |
|
48 | 50 | foreach ($this->all_tracked as $key => $flight) { |
49 | 51 | if (isset($this->all_tracked[$key]['id'])) { |
50 | 52 | //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].' '.$this->all_tracked[$key]['longitude']."\n"; |
@@ -57,12 +59,16 @@ discard block |
||
57 | 59 | public function del() { |
58 | 60 | global $globalDebug; |
59 | 61 | // Delete old infos |
60 | - if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
|
62 | + if ($globalDebug) { |
|
63 | + echo 'Delete old values and update latest data...'."\n"; |
|
64 | + } |
|
61 | 65 | foreach ($this->all_tracked as $key => $flight) { |
62 | 66 | if (isset($flight['lastupdate'])) { |
63 | 67 | if ($flight['lastupdate'] < (time()-3000)) { |
64 | 68 | if (isset($this->all_tracked[$key]['id'])) { |
65 | - if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
|
69 | + if ($globalDebug) { |
|
70 | + echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
|
71 | + } |
|
66 | 72 | /* |
67 | 73 | $MarineLive = new MarineLive(); |
68 | 74 | $MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']); |
@@ -72,7 +78,9 @@ discard block |
||
72 | 78 | $Marine = new Marine($this->db); |
73 | 79 | if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') { |
74 | 80 | $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']); |
75 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
81 | + if ($globalDebug && $result != 'success') { |
|
82 | + echo '!!! ERROR : '.$result."\n"; |
|
83 | + } |
|
76 | 84 | } |
77 | 85 | // Put in archive |
78 | 86 | // $Marine->db = null; |
@@ -85,7 +93,9 @@ discard block |
||
85 | 93 | |
86 | 94 | public function add($line) { |
87 | 95 | global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked; |
88 | - if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02'; |
|
96 | + if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') { |
|
97 | + $globalCoordMinChange = '0.02'; |
|
98 | + } |
|
89 | 99 | date_default_timezone_set('UTC'); |
90 | 100 | $dataFound = false; |
91 | 101 | $send = false; |
@@ -109,8 +119,11 @@ discard block |
||
109 | 119 | */ |
110 | 120 | |
111 | 121 | $Common = new Common(); |
112 | - if (!isset($line['id'])) $id = trim($line['mmsi']); |
|
113 | - else $id = trim($line['id']); |
|
122 | + if (!isset($line['id'])) { |
|
123 | + $id = trim($line['mmsi']); |
|
124 | + } else { |
|
125 | + $id = trim($line['id']); |
|
126 | + } |
|
114 | 127 | |
115 | 128 | if (!isset($this->all_tracked[$id])) { |
116 | 129 | $this->all_tracked[$id] = array(); |
@@ -118,10 +131,16 @@ discard block |
||
118 | 131 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','imo' => '','callsign' => '')); |
119 | 132 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time())); |
120 | 133 | if (!isset($line['id'])) { |
121 | - if (!isset($globalDaemon)) $globalDaemon = TRUE; |
|
134 | + if (!isset($globalDaemon)) { |
|
135 | + $globalDaemon = TRUE; |
|
136 | + } |
|
122 | 137 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi'))); |
123 | - } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
124 | - if ($globalAllTracked !== FALSE) $dataFound = true; |
|
138 | + } else { |
|
139 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
140 | + } |
|
141 | + if ($globalAllTracked !== FALSE) { |
|
142 | + $dataFound = true; |
|
143 | + } |
|
125 | 144 | } |
126 | 145 | |
127 | 146 | if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) { |
@@ -155,11 +174,17 @@ discard block |
||
155 | 174 | $Marine = new Marine($this->db); |
156 | 175 | $fromsource = NULL; |
157 | 176 | $result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource); |
158 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
177 | + if ($globalDebug && $result != 'success') { |
|
178 | + echo '!!! ERROR : '.$result."\n"; |
|
179 | + } |
|
159 | 180 | $Marine->db = null; |
160 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
181 | + if ($globalDebugTimeElapsed) { |
|
182 | + echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
183 | + } |
|
184 | + } |
|
185 | + if (!isset($this->all_tracked[$id]['id'])) { |
|
186 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
161 | 187 | } |
162 | - if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
163 | 188 | } |
164 | 189 | |
165 | 190 | if (isset($line['speed']) && $line['speed'] != '') { |
@@ -170,14 +195,21 @@ discard block |
||
170 | 195 | if ($distance > 1000 && $distance < 10000) { |
171 | 196 | $speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']); |
172 | 197 | $speed = $speed*3.6; |
173 | - if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed))); |
|
174 | - if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
|
198 | + if ($speed < 1000) { |
|
199 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed))); |
|
200 | + } |
|
201 | + if ($globalDebug) { |
|
202 | + echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
|
203 | + } |
|
175 | 204 | } |
176 | 205 | } |
177 | 206 | |
178 | 207 | if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
179 | - if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
180 | - else unset($timediff); |
|
208 | + if (isset($this->all_tracked[$id]['time_last_coord'])) { |
|
209 | + $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
210 | + } else { |
|
211 | + unset($timediff); |
|
212 | + } |
|
181 | 213 | 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')))) { |
182 | 214 | 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'])) { |
183 | 215 | 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'])) { |
@@ -185,20 +217,30 @@ discard block |
||
185 | 217 | $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
186 | 218 | $this->all_tracked[$id]['putinarchive'] = true; |
187 | 219 | |
188 | - if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
|
220 | + if ($globalDebug) { |
|
221 | + echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
|
222 | + } |
|
189 | 223 | $timeelapsed = microtime(true); |
190 | 224 | $Marine = new Marine($this->db); |
191 | 225 | $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
192 | - if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
|
226 | + if (!empty($all_country)) { |
|
227 | + $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
|
228 | + } |
|
193 | 229 | $Marine->db = null; |
194 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
230 | + if ($globalDebugTimeElapsed) { |
|
231 | + echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
232 | + } |
|
195 | 233 | $this->tmd = 0; |
196 | - if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n"; |
|
234 | + if ($globalDebug) { |
|
235 | + echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n"; |
|
236 | + } |
|
197 | 237 | } |
198 | 238 | } |
199 | 239 | |
200 | 240 | if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
201 | - if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
|
241 | + if (!isset($this->all_tracked[$id]['archive_latitude'])) { |
|
242 | + $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
|
243 | + } |
|
202 | 244 | 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') { |
203 | 245 | $this->all_tracked[$id]['livedb_latitude'] = $line['latitude']; |
204 | 246 | $dataFound = true; |
@@ -207,8 +249,12 @@ discard block |
||
207 | 249 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude'])); |
208 | 250 | } |
209 | 251 | if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { |
210 | - if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
211 | - if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
|
252 | + if ($line['longitude'] > 180) { |
|
253 | + $line['longitude'] = $line['longitude'] - 360; |
|
254 | + } |
|
255 | + if (!isset($this->all_tracked[$id]['archive_longitude'])) { |
|
256 | + $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
|
257 | + } |
|
212 | 258 | 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') { |
213 | 259 | $this->all_tracked[$id]['livedb_longitude'] = $line['longitude']; |
214 | 260 | $dataFound = true; |
@@ -226,7 +272,9 @@ discard block |
||
226 | 272 | } |
227 | 273 | } |
228 | 274 | if (isset($line['last_update']) && $line['last_update'] != '') { |
229 | - if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
275 | + if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) { |
|
276 | + $dataFound = true; |
|
277 | + } |
|
230 | 278 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update'])); |
231 | 279 | } |
232 | 280 | if (isset($line['format_source']) && $line['format_source'] != '') { |
@@ -244,15 +292,21 @@ discard block |
||
244 | 292 | } |
245 | 293 | |
246 | 294 | if (isset($line['heading']) && $line['heading'] != '') { |
247 | - if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
295 | + if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) { |
|
296 | + $this->all_tracked[$id]['putinarchive'] = true; |
|
297 | + } |
|
248 | 298 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading']))); |
249 | 299 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true)); |
250 | 300 | //$dataFound = true; |
251 | 301 | } 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']) { |
252 | 302 | $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']); |
253 | 303 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading))); |
254 | - if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
255 | - if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
|
304 | + if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) { |
|
305 | + $this->all_tracked[$id]['putinarchive'] = true; |
|
306 | + } |
|
307 | + if ($globalDebug) { |
|
308 | + echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
|
309 | + } |
|
256 | 310 | } |
257 | 311 | //if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
258 | 312 | |
@@ -260,8 +314,11 @@ discard block |
||
260 | 314 | if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) { |
261 | 315 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime'])); |
262 | 316 | } else { |
263 | - 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"; |
|
264 | - 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"; |
|
317 | + if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) { |
|
318 | + echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n"; |
|
319 | + } elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) { |
|
320 | + echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
321 | + } |
|
265 | 322 | return ''; |
266 | 323 | } |
267 | 324 | } else { |
@@ -275,22 +332,35 @@ discard block |
||
275 | 332 | if ($this->all_tracked[$id]['addedMarine'] == 0) { |
276 | 333 | 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'])) { |
277 | 334 | if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) { |
278 | - if ($globalDebug) echo "Check if aircraft is already in DB..."; |
|
335 | + if ($globalDebug) { |
|
336 | + echo "Check if aircraft is already in DB..."; |
|
337 | + } |
|
279 | 338 | $timeelapsed = microtime(true); |
280 | 339 | $MarineLive = new MarineLive($this->db); |
281 | 340 | if (isset($line['id'])) { |
282 | 341 | $recent_ident = $MarineLive->checkIdRecent($line['id']); |
283 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
342 | + if ($globalDebugTimeElapsed) { |
|
343 | + echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
344 | + } |
|
284 | 345 | } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') { |
285 | 346 | $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']); |
286 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
347 | + if ($globalDebugTimeElapsed) { |
|
348 | + echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
349 | + } |
|
287 | 350 | } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') { |
288 | 351 | $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']); |
289 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
290 | - } else $recent_ident = ''; |
|
352 | + if ($globalDebugTimeElapsed) { |
|
353 | + echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
354 | + } |
|
355 | + } else { |
|
356 | + $recent_ident = ''; |
|
357 | + } |
|
291 | 358 | $MarineLive->db=null; |
292 | - if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
|
293 | - elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
|
359 | + if ($globalDebug && $recent_ident == '') { |
|
360 | + echo " Not in DB.\n"; |
|
361 | + } elseif ($globalDebug && $recent_ident != '') { |
|
362 | + echo " Already in DB.\n"; |
|
363 | + } |
|
294 | 364 | } else { |
295 | 365 | $recent_ident = ''; |
296 | 366 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0)); |
@@ -298,16 +368,24 @@ discard block |
||
298 | 368 | //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
299 | 369 | if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') |
300 | 370 | { |
301 | - if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : "; |
|
371 | + if ($globalDebug) { |
|
372 | + echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : "; |
|
373 | + } |
|
302 | 374 | //adds the spotter data for the archive |
303 | 375 | $highlight = ''; |
304 | - 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'))); |
|
376 | + if (!isset($this->all_tracked[$id]['id'])) { |
|
377 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi'))); |
|
378 | + } |
|
305 | 379 | $timeelapsed = microtime(true); |
306 | 380 | $Marine = new Marine($this->db); |
307 | 381 | $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]['imo'],$this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['status'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']); |
308 | 382 | $Marine->db = null; |
309 | - if ($globalDebug && isset($result)) echo $result."\n"; |
|
310 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
383 | + if ($globalDebug && isset($result)) { |
|
384 | + echo $result."\n"; |
|
385 | + } |
|
386 | + if ($globalDebugTimeElapsed) { |
|
387 | + echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
388 | + } |
|
311 | 389 | |
312 | 390 | /* |
313 | 391 | // Add source stat in DB |
@@ -341,12 +419,16 @@ discard block |
||
341 | 419 | $this->all_tracked[$id]['addedMarine'] = 1; |
342 | 420 | //print_r($this->all_tracked[$id]); |
343 | 421 | if ($this->last_delete == 0 || time() - $this->last_delete > 1800) { |
344 | - if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours..."; |
|
422 | + if ($globalDebug) { |
|
423 | + echo "---- Deleting Live Marine data older than 9 hours..."; |
|
424 | + } |
|
345 | 425 | //MarineLive->deleteLiveMarineDataNotUpdated(); |
346 | 426 | $MarineLive = new MarineLive($this->db); |
347 | 427 | $MarineLive->deleteLiveMarineData(); |
348 | 428 | $MarineLive->db=null; |
349 | - if ($globalDebug) echo " Done\n"; |
|
429 | + if ($globalDebug) { |
|
430 | + echo " Done\n"; |
|
431 | + } |
|
350 | 432 | $this->last_delete = time(); |
351 | 433 | } |
352 | 434 | } elseif ($recent_ident != '') { |
@@ -369,13 +451,17 @@ discard block |
||
369 | 451 | |
370 | 452 | if (!$ignoreImport) { |
371 | 453 | 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'])) { |
372 | - if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : "; |
|
454 | + if ($globalDebug) { |
|
455 | + echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : "; |
|
456 | + } |
|
373 | 457 | $timeelapsed = microtime(true); |
374 | 458 | $MarineLive = new MarineLive($this->db); |
375 | 459 | $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]['imo'],$this->all_tracked[$id]['callsign'],$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']); |
376 | 460 | $MarineLive->db = null; |
377 | 461 | $this->all_tracked[$id]['putinarchive'] = false; |
378 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
462 | + if ($globalDebugTimeElapsed) { |
|
463 | + echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
464 | + } |
|
379 | 465 | |
380 | 466 | // Put statistics in $this->stats variable |
381 | 467 | /* |
@@ -432,19 +518,29 @@ discard block |
||
432 | 518 | */ |
433 | 519 | |
434 | 520 | $this->all_tracked[$id]['lastupdate'] = time(); |
435 | - if ($this->all_tracked[$id]['putinarchive']) $send = true; |
|
436 | - if ($globalDebug) echo $result."\n"; |
|
437 | - } 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"; |
|
521 | + if ($this->all_tracked[$id]['putinarchive']) { |
|
522 | + $send = true; |
|
523 | + } |
|
524 | + if ($globalDebug) { |
|
525 | + echo $result."\n"; |
|
526 | + } |
|
527 | + } elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) { |
|
528 | + echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
|
529 | + } |
|
438 | 530 | //$this->del(); |
439 | 531 | |
440 | 532 | |
441 | 533 | if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) { |
442 | - if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour..."; |
|
534 | + if ($globalDebug) { |
|
535 | + echo "---- Deleting Live Marine data Not updated since 2 hour..."; |
|
536 | + } |
|
443 | 537 | $MarineLive = new MarineLive($this->db); |
444 | 538 | $MarineLive->deleteLiveMarineDataNotUpdated(); |
445 | 539 | $MarineLive->db = null; |
446 | 540 | //MarineLive->deleteLiveMarineData(); |
447 | - if ($globalDebug) echo " Done\n"; |
|
541 | + if ($globalDebug) { |
|
542 | + echo " Done\n"; |
|
543 | + } |
|
448 | 544 | $this->last_delete_hourly = time(); |
449 | 545 | } |
450 | 546 | |
@@ -452,7 +548,9 @@ discard block |
||
452 | 548 | //$ignoreImport = false; |
453 | 549 | } |
454 | 550 | //if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN); |
455 | - if ($send) return $this->all_tracked[$id]; |
|
551 | + if ($send) { |
|
552 | + return $this->all_tracked[$id]; |
|
553 | + } |
|
456 | 554 | } |
457 | 555 | } |
458 | 556 | } |
@@ -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; |
@@ -169,7 +171,9 @@ discard block |
||
169 | 171 | $ro->lon = $this->make_lonf(bindec(substr($_aisdata,57,28))); |
170 | 172 | $ro->lat = $this->make_latf(bindec(substr($_aisdata,85,27))); |
171 | 173 | $ro->heading = bindec(substr($_aisdata,124,9)); |
172 | - if ($ro->heading == 511) $ro->heading = ''; |
|
174 | + if ($ro->heading == 511) { |
|
175 | + $ro->heading = ''; |
|
176 | + } |
|
173 | 177 | $ro->cls = 2; // class B |
174 | 178 | } else if ($ro->id == 19) { |
175 | 179 | $ro->cog = bindec(substr($_aisdata,112,12))/10; |
@@ -179,7 +183,9 @@ discard block |
||
179 | 183 | $ro->name = $this->binchar($_aisdata,143,120); |
180 | 184 | $ro->cls = 2; // class B |
181 | 185 | $ro->heading = bindec(substr($_aisdata,124,9)); |
182 | - if ($ro->heading == 511) $ro->heading = ''; |
|
186 | + if ($ro->heading == 511) { |
|
187 | + $ro->heading = ''; |
|
188 | + } |
|
183 | 189 | $ro->typeid = bindec(substr($_aisdata,263,8)); |
184 | 190 | $ro->type = $this->getShipType($ro->typeid); |
185 | 191 | //$ro->to_bow = bindec(substr($_aisdata,271,9)); |
@@ -210,9 +216,13 @@ discard block |
||
210 | 216 | $ro->cls = 2; // class B |
211 | 217 | } else if ($ro->id == 27) { |
212 | 218 | $ro->cog = bindec(substr($_aisdata,85,9)); |
213 | - if ($ro->cog == 511) $ro->cog = 0.0; |
|
219 | + if ($ro->cog == 511) { |
|
220 | + $ro->cog = 0.0; |
|
221 | + } |
|
214 | 222 | $ro->sog = bindec(substr($_aisdata,79,6)); |
215 | - if ($ro->sog == 63) $ro->sog = 0.0; |
|
223 | + if ($ro->sog == 63) { |
|
224 | + $ro->sog = 0.0; |
|
225 | + } |
|
216 | 226 | $ro->lon = $this->make_lonf(bindec(substr($_aisdata,44,18))*10); |
217 | 227 | $ro->lat = $this->make_latf(bindec(substr($_aisdata,62,17))*10); |
218 | 228 | $ro->cls = 1; // class A |
@@ -261,88 +271,171 @@ discard block |
||
261 | 271 | } |
262 | 272 | |
263 | 273 | public function getShipType($code) { |
264 | - if ($code == 0) return 'Not available (default)'; |
|
265 | - elseif ($code >= 1 && $code <= 19) return 'Reserved for future use'; |
|
266 | - elseif ($code == 20) return 'Wing in ground (WIG), all ships of this type'; |
|
267 | - elseif ($code == 21) return 'Wing in ground (WIG), Hazardous category A'; |
|
268 | - elseif ($code == 22) return 'Wing in ground (WIG), Hazardous category B'; |
|
269 | - elseif ($code == 23) return 'Wing in ground (WIG), Hazardous category C'; |
|
270 | - elseif ($code == 24) return 'Wing in ground (WIG), Hazardous category D'; |
|
271 | - elseif ($code == 25) return 'Wing in ground (WIG), Reserved for future use'; |
|
272 | - elseif ($code == 26) return 'Wing in ground (WIG), Reserved for future use'; |
|
273 | - elseif ($code == 27) return 'Wing in ground (WIG), Reserved for future use'; |
|
274 | - elseif ($code == 28) return 'Wing in ground (WIG), Reserved for future use'; |
|
275 | - elseif ($code == 29) return 'Wing in ground (WIG), Reserved for future use'; |
|
276 | - elseif ($code == 30) return 'Fishing'; |
|
277 | - elseif ($code == 31) return 'Towing'; |
|
278 | - elseif ($code == 32) return 'Towing: length exceeds 200m or breadth exceeds 25m'; |
|
279 | - elseif ($code == 33) return 'Dredging or underwater ops'; |
|
280 | - elseif ($code == 34) return 'Diving ops'; |
|
281 | - elseif ($code == 35) return 'Military ops'; |
|
282 | - elseif ($code == 36) return 'Sailing'; |
|
283 | - elseif ($code == 37) return 'Pleasure Craft'; |
|
284 | - elseif ($code == 38) return 'Reserved'; |
|
285 | - elseif ($code == 39) return 'Reserved'; |
|
286 | - elseif ($code == 40) return 'High speed craft (HSC), all ships of this type'; |
|
287 | - elseif ($code == 41) return 'High speed craft (HSC), Hazardous category A'; |
|
288 | - elseif ($code == 42) return 'High speed craft (HSC), Hazardous category B'; |
|
289 | - elseif ($code == 43) return 'High speed craft (HSC), Hazardous category C'; |
|
290 | - elseif ($code == 44) return 'High speed craft (HSC), Hazardous category D'; |
|
291 | - elseif ($code == 45) return 'High speed craft (HSC), Reserved for future use'; |
|
292 | - elseif ($code == 46) return 'High speed craft (HSC), Reserved for future use'; |
|
293 | - elseif ($code == 47) return 'High speed craft (HSC), Reserved for future use'; |
|
294 | - elseif ($code == 48) return 'High speed craft (HSC), Reserved for future use'; |
|
295 | - elseif ($code == 49) return 'High speed craft (HSC), No additional information'; |
|
296 | - elseif ($code == 50) return 'Pilot Vessel'; |
|
297 | - elseif ($code == 51) return 'Search and Rescue vessel'; |
|
298 | - elseif ($code == 52) return 'Tug'; |
|
299 | - elseif ($code == 53) return 'Port Tender'; |
|
300 | - elseif ($code == 54) return 'Anti-pollution equipment'; |
|
301 | - elseif ($code == 55) return 'Law Enforcement'; |
|
302 | - elseif ($code == 56) return 'Spare - Local Vessel'; |
|
303 | - elseif ($code == 57) return 'Spare - Local Vessel'; |
|
304 | - elseif ($code == 58) return 'Medical Transport'; |
|
305 | - elseif ($code == 59) return 'Noncombatant ship according to RR Resolution No. 18'; |
|
306 | - elseif ($code == 60) return 'Passenger, all ships of this type'; |
|
307 | - elseif ($code == 61) return 'Passenger, Hazardous category A'; |
|
308 | - elseif ($code == 62) return 'Passenger, Hazardous category B'; |
|
309 | - elseif ($code == 63) return 'Passenger, Hazardous category C'; |
|
310 | - elseif ($code == 64) return 'Passenger, Hazardous category D'; |
|
311 | - elseif ($code == 65) return 'Passenger, Reserved for future use'; |
|
312 | - elseif ($code == 66) return 'Passenger, Reserved for future use'; |
|
313 | - elseif ($code == 67) return 'Passenger, Reserved for future use'; |
|
314 | - elseif ($code == 68) return 'Passenger, Reserved for future use'; |
|
315 | - elseif ($code == 69) return 'Passenger, No additional information'; |
|
316 | - elseif ($code == 70) return 'Cargo, all ships of this type'; |
|
317 | - elseif ($code == 71) return 'Cargo, Hazardous category A'; |
|
318 | - elseif ($code == 72) return 'Cargo, Hazardous category B'; |
|
319 | - elseif ($code == 73) return 'Cargo, Hazardous category C'; |
|
320 | - elseif ($code == 74) return 'Cargo, Hazardous category D'; |
|
321 | - elseif ($code == 75) return 'Cargo, Reserved for future use'; |
|
322 | - elseif ($code == 76) return 'Cargo, Reserved for future use'; |
|
323 | - elseif ($code == 77) return 'Cargo, Reserved for future use'; |
|
324 | - elseif ($code == 78) return 'Cargo, Reserved for future use'; |
|
325 | - elseif ($code == 79) return 'Cargo, No additional information'; |
|
326 | - elseif ($code == 80) return 'Tanker, all ships of this type'; |
|
327 | - elseif ($code == 81) return 'Tanker, Hazardous category A'; |
|
328 | - elseif ($code == 82) return 'Tanker, Hazardous category B'; |
|
329 | - elseif ($code == 83) return 'Tanker, Hazardous category C'; |
|
330 | - elseif ($code == 84) return 'Tanker, Hazardous category D'; |
|
331 | - elseif ($code == 85) return 'Tanker, Reserved for future use'; |
|
332 | - elseif ($code == 86) return 'Tanker, Reserved for future use'; |
|
333 | - elseif ($code == 87) return 'Tanker, Reserved for future use'; |
|
334 | - elseif ($code == 88) return 'Tanker, Reserved for future use'; |
|
335 | - elseif ($code == 89) return 'Tanker, No additional information'; |
|
336 | - elseif ($code == 90) return 'Other Type, all ships of this type'; |
|
337 | - elseif ($code == 91) return 'Other Type, Hazardous category A'; |
|
338 | - elseif ($code == 92) return 'Other Type, Hazardous category B'; |
|
339 | - elseif ($code == 93) return 'Other Type, Hazardous category C'; |
|
340 | - elseif ($code == 94) return 'Other Type, Hazardous category D'; |
|
341 | - elseif ($code == 95) return 'Other Type, Reserved for future use'; |
|
342 | - elseif ($code == 96) return 'Other Type, Reserved for future use'; |
|
343 | - elseif ($code == 97) return 'Other Type, Reserved for future use'; |
|
344 | - elseif ($code == 98) return 'Other Type, Reserved for future use'; |
|
345 | - elseif ($code == 99) return 'Other Type, no additional information'; |
|
274 | + if ($code == 0) { |
|
275 | + return 'Not available (default)'; |
|
276 | + } elseif ($code >= 1 && $code <= 19) { |
|
277 | + return 'Reserved for future use'; |
|
278 | + } elseif ($code == 20) { |
|
279 | + return 'Wing in ground (WIG), all ships of this type'; |
|
280 | + } elseif ($code == 21) { |
|
281 | + return 'Wing in ground (WIG), Hazardous category A'; |
|
282 | + } elseif ($code == 22) { |
|
283 | + return 'Wing in ground (WIG), Hazardous category B'; |
|
284 | + } elseif ($code == 23) { |
|
285 | + return 'Wing in ground (WIG), Hazardous category C'; |
|
286 | + } elseif ($code == 24) { |
|
287 | + return 'Wing in ground (WIG), Hazardous category D'; |
|
288 | + } elseif ($code == 25) { |
|
289 | + return 'Wing in ground (WIG), Reserved for future use'; |
|
290 | + } elseif ($code == 26) { |
|
291 | + return 'Wing in ground (WIG), Reserved for future use'; |
|
292 | + } elseif ($code == 27) { |
|
293 | + return 'Wing in ground (WIG), Reserved for future use'; |
|
294 | + } elseif ($code == 28) { |
|
295 | + return 'Wing in ground (WIG), Reserved for future use'; |
|
296 | + } elseif ($code == 29) { |
|
297 | + return 'Wing in ground (WIG), Reserved for future use'; |
|
298 | + } elseif ($code == 30) { |
|
299 | + return 'Fishing'; |
|
300 | + } elseif ($code == 31) { |
|
301 | + return 'Towing'; |
|
302 | + } elseif ($code == 32) { |
|
303 | + return 'Towing: length exceeds 200m or breadth exceeds 25m'; |
|
304 | + } elseif ($code == 33) { |
|
305 | + return 'Dredging or underwater ops'; |
|
306 | + } elseif ($code == 34) { |
|
307 | + return 'Diving ops'; |
|
308 | + } elseif ($code == 35) { |
|
309 | + return 'Military ops'; |
|
310 | + } elseif ($code == 36) { |
|
311 | + return 'Sailing'; |
|
312 | + } elseif ($code == 37) { |
|
313 | + return 'Pleasure Craft'; |
|
314 | + } elseif ($code == 38) { |
|
315 | + return 'Reserved'; |
|
316 | + } elseif ($code == 39) { |
|
317 | + return 'Reserved'; |
|
318 | + } elseif ($code == 40) { |
|
319 | + return 'High speed craft (HSC), all ships of this type'; |
|
320 | + } elseif ($code == 41) { |
|
321 | + return 'High speed craft (HSC), Hazardous category A'; |
|
322 | + } elseif ($code == 42) { |
|
323 | + return 'High speed craft (HSC), Hazardous category B'; |
|
324 | + } elseif ($code == 43) { |
|
325 | + return 'High speed craft (HSC), Hazardous category C'; |
|
326 | + } elseif ($code == 44) { |
|
327 | + return 'High speed craft (HSC), Hazardous category D'; |
|
328 | + } elseif ($code == 45) { |
|
329 | + return 'High speed craft (HSC), Reserved for future use'; |
|
330 | + } elseif ($code == 46) { |
|
331 | + return 'High speed craft (HSC), Reserved for future use'; |
|
332 | + } elseif ($code == 47) { |
|
333 | + return 'High speed craft (HSC), Reserved for future use'; |
|
334 | + } elseif ($code == 48) { |
|
335 | + return 'High speed craft (HSC), Reserved for future use'; |
|
336 | + } elseif ($code == 49) { |
|
337 | + return 'High speed craft (HSC), No additional information'; |
|
338 | + } elseif ($code == 50) { |
|
339 | + return 'Pilot Vessel'; |
|
340 | + } elseif ($code == 51) { |
|
341 | + return 'Search and Rescue vessel'; |
|
342 | + } elseif ($code == 52) { |
|
343 | + return 'Tug'; |
|
344 | + } elseif ($code == 53) { |
|
345 | + return 'Port Tender'; |
|
346 | + } elseif ($code == 54) { |
|
347 | + return 'Anti-pollution equipment'; |
|
348 | + } elseif ($code == 55) { |
|
349 | + return 'Law Enforcement'; |
|
350 | + } elseif ($code == 56) { |
|
351 | + return 'Spare - Local Vessel'; |
|
352 | + } elseif ($code == 57) { |
|
353 | + return 'Spare - Local Vessel'; |
|
354 | + } elseif ($code == 58) { |
|
355 | + return 'Medical Transport'; |
|
356 | + } elseif ($code == 59) { |
|
357 | + return 'Noncombatant ship according to RR Resolution No. 18'; |
|
358 | + } elseif ($code == 60) { |
|
359 | + return 'Passenger, all ships of this type'; |
|
360 | + } elseif ($code == 61) { |
|
361 | + return 'Passenger, Hazardous category A'; |
|
362 | + } elseif ($code == 62) { |
|
363 | + return 'Passenger, Hazardous category B'; |
|
364 | + } elseif ($code == 63) { |
|
365 | + return 'Passenger, Hazardous category C'; |
|
366 | + } elseif ($code == 64) { |
|
367 | + return 'Passenger, Hazardous category D'; |
|
368 | + } elseif ($code == 65) { |
|
369 | + return 'Passenger, Reserved for future use'; |
|
370 | + } elseif ($code == 66) { |
|
371 | + return 'Passenger, Reserved for future use'; |
|
372 | + } elseif ($code == 67) { |
|
373 | + return 'Passenger, Reserved for future use'; |
|
374 | + } elseif ($code == 68) { |
|
375 | + return 'Passenger, Reserved for future use'; |
|
376 | + } elseif ($code == 69) { |
|
377 | + return 'Passenger, No additional information'; |
|
378 | + } elseif ($code == 70) { |
|
379 | + return 'Cargo, all ships of this type'; |
|
380 | + } elseif ($code == 71) { |
|
381 | + return 'Cargo, Hazardous category A'; |
|
382 | + } elseif ($code == 72) { |
|
383 | + return 'Cargo, Hazardous category B'; |
|
384 | + } elseif ($code == 73) { |
|
385 | + return 'Cargo, Hazardous category C'; |
|
386 | + } elseif ($code == 74) { |
|
387 | + return 'Cargo, Hazardous category D'; |
|
388 | + } elseif ($code == 75) { |
|
389 | + return 'Cargo, Reserved for future use'; |
|
390 | + } elseif ($code == 76) { |
|
391 | + return 'Cargo, Reserved for future use'; |
|
392 | + } elseif ($code == 77) { |
|
393 | + return 'Cargo, Reserved for future use'; |
|
394 | + } elseif ($code == 78) { |
|
395 | + return 'Cargo, Reserved for future use'; |
|
396 | + } elseif ($code == 79) { |
|
397 | + return 'Cargo, No additional information'; |
|
398 | + } elseif ($code == 80) { |
|
399 | + return 'Tanker, all ships of this type'; |
|
400 | + } elseif ($code == 81) { |
|
401 | + return 'Tanker, Hazardous category A'; |
|
402 | + } elseif ($code == 82) { |
|
403 | + return 'Tanker, Hazardous category B'; |
|
404 | + } elseif ($code == 83) { |
|
405 | + return 'Tanker, Hazardous category C'; |
|
406 | + } elseif ($code == 84) { |
|
407 | + return 'Tanker, Hazardous category D'; |
|
408 | + } elseif ($code == 85) { |
|
409 | + return 'Tanker, Reserved for future use'; |
|
410 | + } elseif ($code == 86) { |
|
411 | + return 'Tanker, Reserved for future use'; |
|
412 | + } elseif ($code == 87) { |
|
413 | + return 'Tanker, Reserved for future use'; |
|
414 | + } elseif ($code == 88) { |
|
415 | + return 'Tanker, Reserved for future use'; |
|
416 | + } elseif ($code == 89) { |
|
417 | + return 'Tanker, No additional information'; |
|
418 | + } elseif ($code == 90) { |
|
419 | + return 'Other Type, all ships of this type'; |
|
420 | + } elseif ($code == 91) { |
|
421 | + return 'Other Type, Hazardous category A'; |
|
422 | + } elseif ($code == 92) { |
|
423 | + return 'Other Type, Hazardous category B'; |
|
424 | + } elseif ($code == 93) { |
|
425 | + return 'Other Type, Hazardous category C'; |
|
426 | + } elseif ($code == 94) { |
|
427 | + return 'Other Type, Hazardous category D'; |
|
428 | + } elseif ($code == 95) { |
|
429 | + return 'Other Type, Reserved for future use'; |
|
430 | + } elseif ($code == 96) { |
|
431 | + return 'Other Type, Reserved for future use'; |
|
432 | + } elseif ($code == 97) { |
|
433 | + return 'Other Type, Reserved for future use'; |
|
434 | + } elseif ($code == 98) { |
|
435 | + return 'Other Type, Reserved for future use'; |
|
436 | + } elseif ($code == 99) { |
|
437 | + return 'Other Type, no additional information'; |
|
438 | + } |
|
346 | 439 | } |
347 | 440 | |
348 | 441 | public function process_ais_itu($_itu, $_len, $_filler, $aux /*, $ais_ch*/) { |
@@ -380,19 +473,34 @@ discard block |
||
380 | 473 | // assume 1st ! is valid |
381 | 474 | // find * ensure that it is at correct position |
382 | 475 | $end = strrpos ( $rawdata , '*' ); |
383 | - if ($end === FALSE) return -1; // check for NULLS!!! |
|
476 | + if ($end === FALSE) { |
|
477 | + return -1; |
|
478 | + } |
|
479 | + // check for NULLS!!! |
|
384 | 480 | $cs = substr( $rawdata, $end + 1 ); |
385 | - if ( strlen($cs) != 2 ) return -1; // correct cs length |
|
481 | + if ( strlen($cs) != 2 ) { |
|
482 | + return -1; |
|
483 | + } |
|
484 | + // correct cs length |
|
386 | 485 | $dcs = (int)hexdec( $cs ); |
387 | - for ( $alias=1; $alias<$end; $alias++) $chksum ^= ord( $rawdata[$alias] ); // perform XOR for NMEA checksum |
|
486 | + for ( $alias=1; $alias<$end; $alias++) { |
|
487 | + $chksum ^= ord( $rawdata[$alias] ); |
|
488 | + } |
|
489 | + // perform XOR for NMEA checksum |
|
388 | 490 | if ( $chksum == $dcs ) { // NMEA checksum pass |
389 | 491 | $pcs = explode(',', $rawdata); |
390 | 492 | // !AI??? identifier |
391 | 493 | $num_seq = (int)$pcs[1]; // number of sequences |
392 | 494 | $seq = (int)$pcs[2]; // get sequence |
393 | 495 | // get msg sequence id |
394 | - if ($pcs[3] == '') $msg_sid = -1; // non-multipart message, set to -1 |
|
395 | - else $msg_sid = (int)$pcs[3]; // multipart message |
|
496 | + if ($pcs[3] == '') { |
|
497 | + $msg_sid = -1; |
|
498 | + } |
|
499 | + // non-multipart message, set to -1 |
|
500 | + else { |
|
501 | + $msg_sid = (int)$pcs[3]; |
|
502 | + } |
|
503 | + // multipart message |
|
396 | 504 | $ais_ch = $pcs[4]; // get AIS channel |
397 | 505 | // message sequence checking |
398 | 506 | if ($num_seq < 1 || $num_seq > 9) { |
@@ -453,10 +561,18 @@ discard block |
||
453 | 561 | //DEBUG echo "[$start $end $tst]\n"; |
454 | 562 | $result = $this->process_ais_raw( $tst, "" ); |
455 | 563 | $last_pos = $end + 1; |
456 | - } else break; |
|
564 | + } else { |
|
565 | + break; |
|
566 | + } |
|
567 | + } |
|
568 | + if ($last_pos > 0) { |
|
569 | + $cbuf = substr($cbuf, $last_pos); |
|
570 | + } |
|
571 | + // move... |
|
572 | + if (strlen($cbuf) > 1024) { |
|
573 | + $cbuf = ""; |
|
457 | 574 | } |
458 | - if ($last_pos > 0) $cbuf = substr($cbuf, $last_pos); // move... |
|
459 | - if (strlen($cbuf) > 1024) $cbuf = ""; // prevent overflow simple mode... |
|
575 | + // prevent overflow simple mode... |
|
460 | 576 | return $result; |
461 | 577 | } |
462 | 578 | |
@@ -476,7 +592,9 @@ discard block |
||
476 | 592 | if ($lat<0.0) { |
477 | 593 | $lat = -$lat; |
478 | 594 | $neg=true; |
479 | - } else $neg=false; |
|
595 | + } else { |
|
596 | + $neg=false; |
|
597 | + } |
|
480 | 598 | $latd = 0x00000000; |
481 | 599 | $latd = intval ($lat * 600000.0); |
482 | 600 | if ($neg==true) { |
@@ -492,7 +610,9 @@ discard block |
||
492 | 610 | if ($lon<0.0) { |
493 | 611 | $lon = -$lon; |
494 | 612 | $neg=true; |
495 | - } else $neg=false; |
|
613 | + } else { |
|
614 | + $neg=false; |
|
615 | + } |
|
496 | 616 | $lond = 0x00000000; |
497 | 617 | $lond = intval ($lon * 600000.0); |
498 | 618 | if ($neg==true) { |
@@ -505,9 +625,14 @@ discard block |
||
505 | 625 | |
506 | 626 | private function char2bin($name, $max_len) { |
507 | 627 | $len = strlen($name); |
508 | - if ($len > $max_len) $name = substr($name,0,$max_len); |
|
509 | - if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len) * 6); |
|
510 | - else $pad = ''; |
|
628 | + if ($len > $max_len) { |
|
629 | + $name = substr($name,0,$max_len); |
|
630 | + } |
|
631 | + if ($len < $max_len) { |
|
632 | + $pad = str_repeat('0', ($max_len - $len) * 6); |
|
633 | + } else { |
|
634 | + $pad = ''; |
|
635 | + } |
|
511 | 636 | $rv = ''; |
512 | 637 | $ais_chars = array( |
513 | 638 | '@'=>0, 'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 'I'=>9, |
@@ -519,9 +644,12 @@ discard block |
||
519 | 644 | '<'=>60, '='=>61, '>'=>62, '?'=>63 |
520 | 645 | ); |
521 | 646 | $_a = str_split($name); |
522 | - if ($_a) foreach ($_a as $_1) { |
|
647 | + if ($_a) { |
|
648 | + foreach ($_a as $_1) { |
|
523 | 649 | if (isset($ais_chars[$_1])) $dec = $ais_chars[$_1]; |
524 | - else $dec = 0; |
|
650 | + } else { |
|
651 | + $dec = 0; |
|
652 | + } |
|
525 | 653 | $bin = str_pad(decbin( $dec ), 6, '0', STR_PAD_LEFT); |
526 | 654 | $rv .= $bin; |
527 | 655 | //echo "$_1 $dec ($bin)<br/>"; |
@@ -533,7 +661,9 @@ discard block |
||
533 | 661 | $len_bit = strlen($_enc); |
534 | 662 | $rem6 = $len_bit % 6; |
535 | 663 | $pad6_len = 0; |
536 | - if ($rem6) $pad6_len = 6 - $rem6; |
|
664 | + if ($rem6) { |
|
665 | + $pad6_len = 6 - $rem6; |
|
666 | + } |
|
537 | 667 | //echo $pad6_len.'<br>'; |
538 | 668 | $_enc .= str_repeat("0", $pad6_len); // pad the text... |
539 | 669 | $len_enc = strlen($_enc) / 6; |
@@ -542,8 +672,11 @@ discard block |
||
542 | 672 | for ($i=0; $i<$len_enc; $i++) { |
543 | 673 | $offset = $i * 6; |
544 | 674 | $dec = bindec(substr($_enc,$offset,6)); |
545 | - if ($dec < 40) $dec += 48; |
|
546 | - else $dec += 56; |
|
675 | + if ($dec < 40) { |
|
676 | + $dec += 48; |
|
677 | + } else { |
|
678 | + $dec += 56; |
|
679 | + } |
|
547 | 680 | //echo chr($dec)." $dec<br/>"; |
548 | 681 | $itu .= chr($dec); |
549 | 682 | } |
@@ -556,25 +689,41 @@ discard block |
||
556 | 689 | } |
557 | 690 | $hex_arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); |
558 | 691 | $lsb = $chksum & 0x0F; |
559 | - if ($lsb >=0 && $lsb <= 15 ) $lsbc = $hex_arr[$lsb]; |
|
560 | - else $lsbc = '0'; |
|
692 | + if ($lsb >=0 && $lsb <= 15 ) { |
|
693 | + $lsbc = $hex_arr[$lsb]; |
|
694 | + } else { |
|
695 | + $lsbc = '0'; |
|
696 | + } |
|
561 | 697 | $msb = (($chksum & 0xF0) >> 4) & 0x0F; |
562 | - if ($msb >=0 && $msb <= 15 ) $msbc = $hex_arr[$msb]; |
|
563 | - else $msbc = '0'; |
|
698 | + if ($msb >=0 && $msb <= 15 ) { |
|
699 | + $msbc = $hex_arr[$msb]; |
|
700 | + } else { |
|
701 | + $msbc = '0'; |
|
702 | + } |
|
564 | 703 | $itu = '!'.$itu."*{$msbc}{$lsbc}\r\n"; |
565 | 704 | return $itu; |
566 | 705 | } |
567 | 706 | |
568 | 707 | public function parse($buffer) { |
569 | 708 | $data = $this->process_ais_buf($buffer); |
570 | - if (!is_object($data)) return array(); |
|
571 | - if ($data->lon != 0) $result['longitude'] = $data->lon; |
|
572 | - if ($data->lat != 0) $result['latitude'] = $data->lat; |
|
709 | + if (!is_object($data)) { |
|
710 | + return array(); |
|
711 | + } |
|
712 | + if ($data->lon != 0) { |
|
713 | + $result['longitude'] = $data->lon; |
|
714 | + } |
|
715 | + if ($data->lat != 0) { |
|
716 | + $result['latitude'] = $data->lat; |
|
717 | + } |
|
573 | 718 | $result['ident'] = trim($data->name); |
574 | 719 | $result['timestamp'] = $data->ts; |
575 | 720 | $result['mmsi'] = $data->mmsi; |
576 | - if ($data->sog != -1.0) $result['speed'] = $data->sog; |
|
577 | - if ($data->cog != 0) $result['heading'] = $data->cog; |
|
721 | + if ($data->sog != -1.0) { |
|
722 | + $result['speed'] = $data->sog; |
|
723 | + } |
|
724 | + if ($data->cog != 0) { |
|
725 | + $result['heading'] = $data->cog; |
|
726 | + } |
|
578 | 727 | /* |
579 | 728 | $ro->cls = 0; // AIS class undefined, also indicate unparsed msg |
580 | 729 | $ro->id = bindec(substr($_aisdata,0,6)); |
@@ -588,19 +737,38 @@ discard block |
||
588 | 737 | $start = strpos($buffer,"VDM"); |
589 | 738 | $tst = substr($buffer, $start - 3); |
590 | 739 | $data = $this->process_ais_raw( $tst, "" ); |
591 | - if (!is_object($data)) return array(); |
|
592 | - if ($data->lon != 0) $result['longitude'] = $data->lon; |
|
593 | - if ($data->lat != 0) $result['latitude'] = $data->lat; |
|
740 | + if (!is_object($data)) { |
|
741 | + return array(); |
|
742 | + } |
|
743 | + if ($data->lon != 0) { |
|
744 | + $result['longitude'] = $data->lon; |
|
745 | + } |
|
746 | + if ($data->lat != 0) { |
|
747 | + $result['latitude'] = $data->lat; |
|
748 | + } |
|
594 | 749 | $result['ident'] = trim(str_replace('@','',$data->name)); |
595 | 750 | $result['timestamp'] = $data->ts; |
596 | 751 | $result['mmsi'] = $data->mmsi; |
597 | - if ($data->sog != -1.0) $result['speed'] = $data->sog; |
|
598 | - if ($data->heading != '') $result['heading'] = $data->heading; |
|
599 | - elseif ($data->cog != 0) $result['heading'] = $data->cog; |
|
600 | - if ($data->status != '') $result['status'] = $data->status; |
|
601 | - if ($data->type != '') $result['type'] = $data->type; |
|
602 | - if ($data->imo != '') $result['imo'] = $data->imo; |
|
603 | - if ($data->callsign != '') $result['callsign'] = $data->callsign; |
|
752 | + if ($data->sog != -1.0) { |
|
753 | + $result['speed'] = $data->sog; |
|
754 | + } |
|
755 | + if ($data->heading != '') { |
|
756 | + $result['heading'] = $data->heading; |
|
757 | + } elseif ($data->cog != 0) { |
|
758 | + $result['heading'] = $data->cog; |
|
759 | + } |
|
760 | + if ($data->status != '') { |
|
761 | + $result['status'] = $data->status; |
|
762 | + } |
|
763 | + if ($data->type != '') { |
|
764 | + $result['type'] = $data->type; |
|
765 | + } |
|
766 | + if ($data->imo != '') { |
|
767 | + $result['imo'] = $data->imo; |
|
768 | + } |
|
769 | + if ($data->callsign != '') { |
|
770 | + $result['callsign'] = $data->callsign; |
|
771 | + } |
|
604 | 772 | $result['all'] = (array) $data; |
605 | 773 | /* |
606 | 774 | $ro->cls = 0; // AIS class undefined, also indicate unparsed msg |